📄 group.cpp
字号:
{
Group *pGroup;
assert (pList != NULL);
pGroup = Group_FindById (pList, GroupId);
assert (pGroup != NULL);
Group_SetVisible (pGroup, FALSE, BrushList, Entities);
}
void Group_Show
(
GroupListType *pList,
int GroupId,
BrushList *BrushList,
CEntityArray *Entities
)
{
Group *pGroup;
assert (pList != NULL);
pGroup = Group_FindById (pList, GroupId);
assert (pGroup != NULL);
Group_SetVisible (pGroup, TRUE, BrushList, Entities);
}
BOOL Group_IsLocked
(
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->Locked;
}
static void Group_SetLock
(
Group *pGroup,
BOOL Locked,
BrushList *BrushList,
CEntityArray *Entities
)
{
assert (pGroup != NULL);
assert (BrushList != NULL);
assert (Entities != NULL);
pGroup->Locked = Locked;
// iterate all brushes and entities, setting Locked flag
{
BrushIterator bi;
Brush *b;
b = BrushList_GetFirst (BrushList, &bi);
while (b != NULL)
{
if (Brush_GetGroupId (b) == pGroup->GroupId)
{
Brush_SetLocked (b, Locked);
}
b = BrushList_GetNext (&bi);
}
}
{
for (int i = 0; i < Entities->GetSize (); i++)
{
if ((*Entities)[i].GetGroupId () == pGroup->GroupId)
{
(*Entities)[i].SetLock (Locked);
}
}
}
}
void Group_Lock
(
GroupListType *pList,
int GroupId,
BrushList *BrushList,
CEntityArray *Entities
)
{
Group *pGroup;
assert (pList != NULL);
pGroup = Group_FindById (pList, GroupId);
assert (pGroup != NULL);
Group_SetLock (pGroup, TRUE, BrushList, Entities);
}
void Group_Unlock
(
GroupListType *pList,
int GroupId,
BrushList *BrushList,
CEntityArray *Entities
)
{
Group *pGroup;
assert (pList != NULL);
pGroup = Group_FindById (pList, GroupId);
assert (pGroup != NULL);
Group_SetLock (pGroup, FALSE, BrushList, Entities);
}
// returns group ID. NO_MORE_GROUPS if done.
// 0 is the immutable default id!!
int Group_GetFirstId
(
GroupListType const *pList,
GroupIterator *gi
)
{
assert (pList != NULL);
assert (gi != NULL);
*gi = pList->First;
if (*gi != NULL)
{
return (*gi)->GroupId;
}
else
{
return NO_MORE_GROUPS ;
}
}
#pragma warning (disable:4100)
int Group_GetNextId
(
GroupListType const *pList,
GroupIterator *gi
)
{
assert (pList != NULL);
assert (gi != NULL);
assert (*gi != NULL);
*gi = (*gi)->Next;
if (*gi != NULL)
{
return (*gi)->GroupId;
}
else
{
return NO_MORE_GROUPS ;
}
}
#pragma warning (default:4100)
geBoolean Group_WriteList
(
GroupListType const *pList,
FILE *f
)
{
Group const *g;
assert (pList != NULL);
assert (f != NULL);
g = pList->First;
while (g != NULL)
{
char Name[300];
Util_QuoteString (g->GroupName, Name);
if (fprintf (f, "Group %s\n", Name) < 0) return GE_FALSE;
if (fprintf (f, "\tGroupId %d\n", g->GroupId) < 0) return GE_FALSE;
if (fprintf (f, "\tVisible %d\n", (g->Visible ? 1 : 0)) < 0) return GE_FALSE;
if (fprintf (f, "\tLocked %d\n", (g->Locked ? 1 : 0)) < 0) return GE_FALSE;
if (fprintf (f, "Color %f %f %f\n", g->Color.r, g->Color.g, g->Color.b ) < 0) return GE_FALSE;
g = g->Next;
}
return GE_TRUE;
}
geBoolean Group_ReadList
(
GroupListType *pList,
int nGroups, // so we know how many to read
Parse3dt *Parser,
int VersionMajor,
int VersionMinor,
const char **Expected
)
{
int Count;
char GroupName[MAX_PATH];
int GroupId;
assert (pList != NULL);
// list end pointer for fast append
for (Count = 0; Count < nGroups; Count++)
{
Group *g;
if ((VersionMajor == 1) && (VersionMinor < 19))
{
if (!Parse3dt_GetIdentifier (Parser, (*Expected = "Group"), GroupName)) return GE_FALSE;
}
else
{
if (!Parse3dt_GetLiteral (Parser, (*Expected = "Group"), GroupName)) return GE_FALSE;
}
if (!Parse3dt_GetInt (Parser, (*Expected = "GroupId"), &GroupId)) return GE_FALSE;
// create the group structure
g = Group_Create (GroupId, GroupName);
if (g == NULL)
{
return 0;
}
// read the rest of the group data...
int TempInt;
if (!Parse3dt_GetInt (Parser, (*Expected = "Visible"), &TempInt)) return GE_FALSE;
g->Visible = !(!TempInt);
if (!Parse3dt_GetInt (Parser, (*Expected = "Locked"), &TempInt)) return GE_FALSE;
g->Locked = !(!TempInt);
if ((VersionMajor > 1) || ((VersionMajor == 1) && (VersionMinor >= 9)))
{
if (!Parse3dt_GetFloat (Parser, (*Expected = "Color"), &g->Color.r)) return GE_FALSE;
if (!Parse3dt_GetFloat (Parser, NULL, &g->Color.g)) return GE_FALSE;
if (!Parse3dt_GetFloat (Parser, NULL, &g->Color.b)) return GE_FALSE;
}
else
{
g->Color.r = g->Color.g = g->Color.b = 255.0f ;
}
g->Color.a = 255.0f ;
// If this group id already exists, then get rid of it...
if (Group_FindById (pList, g->GroupId) != NULL)
{
Group_Destroy (&g);
}
else
{
GroupList_Add (pList, g);
}
}
return GE_TRUE;
}
int Group_GetCount
(
GroupListType const *pList
)
{
Group const *g;
int Count;
assert (pList != NULL);
Count = 0;
g = pList->First;
while (g != NULL)
{
++Count;
g = g->Next;
}
return Count;
}
const GE_RGBA * Group_GetColor
(
const 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->Color ;
}
void Group_SetColor
(
GroupListType *pList,
int GroupId,
const GE_RGBA * pColor
)
{
assert (pList != NULL);
assert (pColor != NULL);
Group *g;
g = Group_FindById (pList, GroupId);
assert (g != NULL);
g->Color = *pColor ;
}
void GroupList_FillCombobox( const GroupListType *pList, CComboBox * pCombo, int GroupId )
{
Group * g;
PCompare pSortArray ;
int i ;
int Count ;
int Index ;
pCombo->ResetContent() ;
Count = Group_GetCount( pList ) ;
assert( Count ) ;
pSortArray = (PCompare)geRam_Allocate ( sizeof(SCompare) * Count ) ;
if( pSortArray == NULL )
return ;
g = pList->First;
i = 0 ;
while (g != NULL)
{
pSortArray[i].pGroup = g ;
i++ ;
g = g->Next;
}
qsort( pSortArray, Count, sizeof( SCompare ), compare ) ;
for( i=0; i < Count; i++ )
{
Index = pCombo->AddString( pSortArray[i].pGroup->GroupName );
pCombo->SetItemData( Index, pSortArray[i].pGroup->GroupId );
if( pSortArray[i].pGroup->GroupId == GroupId )
{
pCombo->SetCurSel( Index );
}
}// Fill the list
geRam_Free ( pSortArray ) ;
}/* GroupList_FillCombobox */
Group *GroupList_GetFromId (GroupListType *pList, int GroupId)
{
return Group_FindById (pList, GroupId);
}
Group *Group_Clone (const Group *OldGroup)
{
Group *pGroup;
assert (OldGroup != NULL);
pGroup = Group_Create (OldGroup->GroupId, OldGroup->GroupName);
if (pGroup != NULL)
{
pGroup->Visible = OldGroup->Visible;
pGroup->Locked = OldGroup->Locked;
pGroup->Color = OldGroup->Color;
}
return pGroup;
}
void GroupList_Add (GroupListType *Groups, Group *pGroup)
{
Group *p, *q;
// find the insertion spot
p = Groups->First;
q = NULL;
while (p != NULL)
{
if (p->GroupId > pGroup->GroupId)
{
break;
}
q = p;
p = p->Next;
}
if (q == NULL)
{
Groups->First = pGroup;
}
else
{
pGroup->Next = q->Next;
q->Next = pGroup;
}
}
const char *Group_GetName (const Group *pGroup)
{
assert (pGroup != NULL);
return pGroup->GroupName;
}
typedef struct
{
int OldId;
int NewId;
} Group_MapEntry;
static geBoolean Group_RenumBrush (Brush *pBrush, void *lParam)
{
Group_MapEntry *Mappings;
int i, GroupId;
Mappings = (Group_MapEntry *)lParam;
GroupId = Brush_GetGroupId (pBrush);
for (i = 0; Mappings[i].OldId != 0; ++i)
{
if (Mappings[i].OldId == GroupId)
{
Brush_SetGroupId (pBrush, Mappings[i].NewId);
break;
}
}
return GE_TRUE;
}
static geBoolean Group_RenumEntity (CEntity &Ent, void *lParam)
{
Group_MapEntry *Mappings;
int i, GroupId;
Mappings = (Group_MapEntry *)lParam;
GroupId = Ent.GetGroupId ();
for (i = 0; Mappings[i].OldId != 0; ++i)
{
if (Mappings[i].OldId == GroupId)
{
Ent.SetGroupId ( Mappings[i].NewId);
break;
}
}
return GE_TRUE;
}
void GroupList_Collapse (GroupListType *Groups, int StartingId, BrushList *Brushes, CEntityArray *Entities)
{
int nEntries;
assert (Groups != NULL);
assert (StartingId > 0);
assert (Brushes != NULL);
assert (Entities != NULL);
nEntries = Group_GetCount (Groups);
if (nEntries > 1)
{
Group_MapEntry *Mappings;
Mappings = (Group_MapEntry *)geRam_Allocate (nEntries * sizeof (Group_MapEntry));
if (Mappings != NULL)
{
int i;
Group *pGroup;
pGroup = Groups->First;
assert (pGroup->GroupId == 0);
pGroup = pGroup->Next;
i = 0;
while (pGroup != NULL)
{
assert (pGroup->GroupId != 0);
Mappings[i].OldId = pGroup->GroupId;
Mappings[i].NewId = i+StartingId;
pGroup->GroupId = Mappings[i].NewId;
++i;
pGroup = pGroup->Next;
}
Mappings[i].OldId = 0; // stop sentinel
Mappings[i].NewId = 0;
BrushList_Enum (Brushes, Mappings, Group_RenumBrush);
EntityList_Enum (*Entities, Mappings, Group_RenumEntity);
geRam_Free (Mappings);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -