📄 group.cpp
字号:
/****************************************************************************************/
/* Group.cpp */
/* */
/* Author: Jim Mischel, Ken Baird, Jeff Lomax */
/* Description: Brush/entity group ui handling code. */
/* */
/* The contents of this file are subject to the Genesis3D Public License */
/* Version 1.01 (the "License"); you may not use this file except in */
/* compliance with the License. You may obtain a copy of the License at */
/* http://www.genesis3d.com */
/* */
/* Software distributed under the License is distributed on an "AS IS" */
/* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See */
/* the License for the specific language governing rights and limitations */
/* under the License. */
/* */
/* The Original Code is Genesis3D, released March 25, 1999. */
/*Genesis3D Version 1.1 released November 15, 1999 */
/* Copyright (C) 1999 WildTangent, Inc. All Rights Reserved */
/* */
/* Modified by Tom Morris for GenEdit-Classic ver. 0.5, Dec. 15, 2000 */
/****************************************************************************************/
#include "stdafx.h"
#include "group.h"
#include "resource.h"
#include <assert.h>
#include "ram.h"
#include "util.h"
struct tag_Group
{
BOOL Visible;
BOOL Locked;
int GroupId;
char * GroupName;
GE_RGBA Color ;
tag_Group *Next;
};
typedef struct tagCompare
{
Group * pGroup ;
} SCompare, *PCompare ;
static int compare( const void * arg1, const void * arg2 )
{
PCompare pLeft ;
PCompare pRight ;
pLeft = (PCompare)arg1 ;
pRight = (PCompare)arg2 ;
if( pLeft->pGroup->GroupId == 0 ) // "Default" group always 1st
return -1 ;
if( pRight->pGroup->GroupId == 0 ) // "Default" group always 1st
return 1 ;
return strcmp( pLeft->pGroup->GroupName, pRight->pGroup->GroupName ) ;
}/* ::compare */
Group *Group_Create
(
int id,
char const *pName
)
{
Group *pGroup;
assert (pName != NULL);
pGroup = (Group *)geRam_Allocate (sizeof (Group));
if (pGroup != NULL)
{
pGroup->Visible = TRUE;
pGroup->Locked = FALSE ;
pGroup->GroupId = id;
pGroup->GroupName = Util_Strdup (pName);
pGroup->Color.r = 255.0 ;
pGroup->Color.g = 255.0 ;
pGroup->Color.b = 255.0 ;
pGroup->Color.a = 255.0 ;
pGroup->Next = NULL;
}
return pGroup;
}
void Group_Destroy
(
Group **ppGroup
)
// Sets all brushes and entities GroupId fields to 0,
// and deallocates the list structure
{
Group *pGroup;
assert (ppGroup != NULL);
assert (*ppGroup != NULL);
pGroup = *ppGroup;
if (pGroup->GroupName != NULL)
{
geRam_Free (pGroup->GroupName);
}
geRam_Free (*ppGroup);
*ppGroup = NULL;
}
struct tag_GroupListType
{
Group *First;
};
GroupListType *Group_CreateList
(
void
)
{
GroupListType *pList;
pList = (GroupListType *)geRam_Allocate (sizeof (GroupListType));
if (pList != NULL)
{
pList->First = NULL;
}
return pList;
}
void Group_DestroyList
(
GroupListType **ppList
)
{
GroupListType *pList;
Group *p, *q;
assert (ppList != NULL);
assert (*ppList != NULL);
pList = *ppList;
// destroy all of the nodes
p = pList->First;
while (p != NULL)
{
q = p;
p = p->Next;
Group_Destroy (&q);
}
geRam_Free (pList);
*ppList = NULL;
}
int Group_AddToList
(
GroupListType *pList
)
{
Group *pGroup;
Group *p, *g;
int GroupId;
char GroupName[100];
assert (pList != NULL);
// find first available group number
g = pList->First;
p = g;
GroupId = 0;
while ((g != NULL) && (g->GroupId == GroupId))
{
p = g;
g = g->Next;
++GroupId;
}
// create a new group with this id
sprintf (GroupName, "Group%d", GroupId);
pGroup = Group_Create (GroupId, GroupName);
if (pGroup != NULL)
{
// link to parent
if (p == NULL)
{
// it's the first node...
pList->First = pGroup;
}
else
{
assert (p->Next == g);
p->Next = pGroup;
pGroup->Next = g;
}
return GroupId;
}
return 0;
}
void Group_RemoveFromList
(
GroupListType *pList,
int GroupId,
BrushList *BrushList,
CEntityArray *Entities
)
{
Group *g, *p;
assert (pList != NULL);
g = pList->First;
p = g;
// search the list looking for this group ID.
// keep track of the parent so we can delete...
while (g != NULL)
{
if (g->GroupId == GroupId)
{
if (g == pList->First)
{
// deleting first node
pList->First = g->Next;
}
else
{
// link next to parent
p->Next = g->Next;
}
// go through brush list and set group number
// to 0 for those brushes that are in this group
{
BrushIterator bi;
Brush *b;
b = BrushList_GetFirst (BrushList, &bi);
while (b != NULL)
{
if (Brush_GetGroupId (b) == GroupId)
{
Brush_SetGroupId (b, 0);
}
b = BrushList_GetNext (&bi);
}
}
{
// remove entities from group
for (int i = 0; i < Entities->GetSize (); i++)
{
if ((*Entities)[i].GetGroupId () == GroupId)
{
(*Entities)[i].SetGroupId (0);
}
}
}
Group_Destroy (&g);
return;
}
p = g;
g = g->Next;
}
}
geBoolean GroupList_IsValidId
(
const GroupListType *pList,
int GroupId
)
{
Group *g;
assert (pList != NULL);
g = pList->First;
while ((g != NULL) && (g->GroupId != GroupId))
{
g = g->Next;
}
if( g != NULL )
return GE_TRUE ;
else
return GE_FALSE ;
}/* GroupList_IsValidId */
static Group *Group_FindById
(
GroupListType const *pList,
int GroupId
)
{
Group *g;
assert (pList != NULL);
g = pList->First;
while ((g != NULL) && (g->GroupId != GroupId))
{
g = g->Next;
}
return g;
}
const char * Group_GetNameFromId
(
GroupListType *pList,
int GroupId
)
{
Group *g;
assert (pList != NULL);
g = Group_FindById (pList, GroupId);
if (g != NULL)
{
return g->GroupName;
}
return NULL;
}
void Group_SetGroupName (Group *g, const char *pName)
{
assert (g != NULL);
assert (pName != NULL);
if (g->GroupName != NULL)
{
geRam_Free (g->GroupName);
}
g->GroupName = Util_Strdup (pName);
}
void Group_SetName
(
GroupListType *pList,
int GroupId,
const char *pName
)
{
assert (pList != NULL);
assert (pName != NULL);
Group *g;
g = Group_FindById (pList, GroupId);
assert (g != NULL);
Group_SetGroupName (g, pName);
}
int Group_GetIdFromName
(
GroupListType *pList,
char const *pName
)
{
Group *g;
assert (pList != NULL);
assert (pName != NULL);
g = pList->First;
while (g != NULL)
{
if (stricmp (g->GroupName, pName) == 0)
{
return g->GroupId;
}
g = g->Next;
}
return NO_MORE_GROUPS;
}
#pragma warning (disable:4100)
void Group_AddBrush
(
GroupListType *pList,
int GroupId,
Brush *pBrush
)
{
assert (pList != NULL);
assert (pBrush != NULL);
// just making sure it's a good group...
assert (Group_FindById (pList, GroupId) != NULL);
Brush_SetGroupId (pBrush, GroupId);
}
#pragma warning (default:4100)
#pragma warning (disable:4100)
void Group_RemoveBrush
(
GroupListType *pList,
int GroupId,
Brush *pBrush
)
{
assert (pList != NULL);
assert (pBrush != NULL);
// just making sure it's a good group
assert (Group_FindById (pList, GroupId) != NULL);
Brush_SetGroupId (pBrush, 0);
}
#pragma warning (default:4100)
#pragma warning (disable:4100)
void Group_AddEntity
(
GroupListType *pList,
int GroupId,
CEntity *pEntity
)
{
assert (pList != NULL);
assert (pEntity != NULL);
// just making sure it's a good group
assert (Group_FindById (pList, GroupId) != NULL);
pEntity->SetGroupId (GroupId);
}
#pragma warning (default:4100)
#pragma warning (disable:4100)
void Group_RemoveEntity
(
GroupListType *pList,
int GroupId,
CEntity *pEntity
)
{
assert (pList != NULL);
assert (pEntity != NULL);
// just making sure it's a good group
assert (Group_FindById (pList, GroupId) != NULL);
#pragma message( "See if this entity is really in this group?" )
pEntity->SetGroupId (0);
}
#pragma warning (default:4100)
BOOL Group_IsVisible
(
GroupListType *pList,
int GroupId
)
{
Group *pGroup;
assert (pList != NULL);
pGroup = Group_FindById (pList, GroupId);
// just a nice little check here...
assert (pGroup != NULL);
return pGroup->Visible;
}
static void Group_SetVisible
(
Group *pGroup,
BOOL Visible,
BrushList *BrushList,
CEntityArray *Entities
)
{
assert (pGroup != NULL);
assert (BrushList != NULL);
assert (Entities != NULL);
pGroup->Visible = Visible;
// HACK! HACK! Don't set local attributes to invisible, use only group attributes
// I'm letting this set to visible though--in case there are invisible items we need
// to get access to...
if( Visible == GE_FALSE )
return ;
// END HACK
// iterate all brushes and entities, setting visible flag
{
BrushIterator bi;
Brush *b;
b = BrushList_GetFirst (BrushList, &bi);
while (b != NULL)
{
if (Brush_GetGroupId (b) == pGroup->GroupId)
{
Brush_SetVisible (b, Visible);
}
b = BrushList_GetNext (&bi);
}
}
{
for (int i = 0; i < Entities->GetSize (); i++)
{
if ((*Entities)[i].GetGroupId () == pGroup->GroupId)
{
(*Entities)[i].SetVisible (Visible);
}
}
}
}
void Group_Hide
(
GroupListType *pList,
int GroupId,
BrushList *BrushList,
CEntityArray *Entities
)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -