-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathdmecontrolgroup.cpp
More file actions
855 lines (714 loc) · 28.4 KB
/
dmecontrolgroup.cpp
File metadata and controls
855 lines (714 loc) · 28.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
//====== Copyright © 1996-2008, Valve Corporation, All rights reserved. =======
//
// Purpose: Implementation of the CDmeControlGroup class. The CDmeControlGroup
// class provides hierarchical grouping of animation controls and used for
// selection of the animation set controls.
//
//=============================================================================
#include "movieobjects/dmecontrolgroup.h"
#include "movieobjects/dmetransform.h"
#include "movieobjects/dmetransformcontrol.h"
#include "movieobjects/dmeanimationset.h"
#include "datamodel/dmelementfactoryhelper.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-------------------------------------------------------------------------------------------------
// Expose this class to the scene database
//-------------------------------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmeControlGroup, CDmeControlGroup );
//-------------------------------------------------------------------------------------------------
// Purpose: Provide post construction processing.
//-------------------------------------------------------------------------------------------------
void CDmeControlGroup::OnConstruction()
{
m_Children.Init( this, "children" );
m_Controls.Init( this, "controls" );
m_GroupColor.InitAndSet( this, "groupColor", Color( 200, 200, 200, 255 ) );
m_ControlColor.InitAndSet( this, "controlColor", Color( 200, 200, 200, 255 ) );
m_Visible.InitAndSet( this, "visible", true );
m_Selectable.InitAndSet( this, "selectable", true );
m_Snappable.InitAndSet( this, "snappable", true );
}
//-------------------------------------------------------------------------------------------------
// Purpose: Provide processing and cleanup before shutdown
//-------------------------------------------------------------------------------------------------
void CDmeControlGroup::OnDestruction()
{
}
//-------------------------------------------------------------------------------------------------
// Purpose: Add a the provided control to the group, if the control is currently in another group
// it will be removed from the other group first.
//-------------------------------------------------------------------------------------------------
void CDmeControlGroup::AddControl( CDmElement *pControl, const CDmElement *pInsertBeforeControl )
{
if ( pControl == NULL )
return;
// Remove the control from any group it is currently in.
CDmeControlGroup *pCurrentGroup = FindGroupContainingControl( pControl );
if ( pCurrentGroup )
{
pCurrentGroup->RemoveControl( pControl );
}
// If a insert location control was specified find it in the list of controls
int nInsertLocation = m_Controls.InvalidIndex();
if ( pInsertBeforeControl )
{
nInsertLocation = m_Controls.Find( pInsertBeforeControl );
}
// Add the control to the group
if ( nInsertLocation != m_Controls.InvalidIndex() )
{
m_Controls.InsertBefore( nInsertLocation, pControl );
}
else
{
m_Controls.AddToTail( pControl );
}
}
//-------------------------------------------------------------------------------------------------
// Purpose: Remove a control from the group. This will only search the immediate group for the
// specified control and remove it. It will not remove the control if it is in a child of this
// group. Returns false if the control was not found.
//-------------------------------------------------------------------------------------------------
bool CDmeControlGroup::RemoveControl( const CDmElement *pControl )
{
if ( pControl == NULL )
return false;
int nControls = m_Controls.Count();
for ( int iControl = 0; iControl < nControls; ++iControl )
{
if ( pControl == m_Controls[ iControl ] )
{
m_Controls.Remove( iControl );
return true;
}
}
return false;
}
//-------------------------------------------------------------------------------------------------
// Purpose: Get a flat list of all of the controls in the group. If the recursive flag is true
// a flat list of all of the controls in the entire sub-tree of the group will be returned. If
// the recursive flag is false on
//-------------------------------------------------------------------------------------------------
void CDmeControlGroup::GetControlsInGroup( CUtlVector< CDmElement* > &controlList, bool recursive ) const
{
// If the recursive flag is set add all of the controls
// of the entire tree of each child group within the group.
if ( recursive )
{
int nChildren = m_Children.Count();
for ( int iChild = 0; iChild < nChildren; ++iChild )
{
CDmeControlGroup *pChild = m_Children[ iChild ];
if ( pChild )
{
pChild->GetControlsInGroup( controlList, true );
}
}
}
// Add the controls from this group.
int nControls = m_Controls.Count();
for ( int iControl = 0; iControl < nControls; ++iControl )
{
CDmElement *pControl = m_Controls[ iControl ];
if ( pControl )
{
controlList.AddToTail( pControl );
}
}
}
//-------------------------------------------------------------------------------------------------
// Purpose: Find a control with the specified name within the group. If the recursive flag is true
// the entire sub-tree of the group will be searched, otherwise only the immediate control will
// be searched for the group. If the parent group pointer is provided it will be returned with the
// group to which the control belongs directly.
//-------------------------------------------------------------------------------------------------
CDmElement *CDmeControlGroup::FindControlByName( const char *pchName, bool recursive, CDmeControlGroup **pParentGroup )
{
// Search the controls contained directly by the group for one with the specified name.
int nControls = m_Controls.Count();
for ( int iControl = 0; iControl < nControls; ++iControl )
{
CDmElement *pControl = m_Controls[ iControl ];
if ( pControl )
{
if ( V_stricmp( pControl->GetName(), pchName ) == 0 )
{
if ( pParentGroup )
{
*pParentGroup = this;
}
return pControl;
}
}
}
// If the control was not found in the controls contained directly by the group
// search the children and their sub-trees if the recursive flag is true.
if ( recursive )
{
int nChildren = m_Children.Count();
for ( int iChild = 0; iChild < nChildren; ++iChild )
{
CDmeControlGroup *pChild = m_Children[ iChild ];
if ( pChild )
{
CDmElement *pControl = pChild->FindControlByName( pchName, true, pParentGroup );
if ( pControl )
return pControl;
}
}
}
return NULL;
}
//-------------------------------------------------------------------------------------------------
// Purpose: Find the group to which the specified control belongs, if any. This function searches
// for any control groups which reference the specified control. It simply returns the first one
// it finds, as a control should only every belong to a single control group.
//-------------------------------------------------------------------------------------------------
CDmeControlGroup *CDmeControlGroup::FindGroupContainingControl( const CDmElement* pControl )
{
return FindReferringElement< CDmeControlGroup >( pControl, "controls" );
}
//-------------------------------------------------------------------------------------------------
// Purpose: Make the specified group a child of this group. The group will be removed from the
// child list of any other group to which it may currently belong.
//-------------------------------------------------------------------------------------------------
void CDmeControlGroup::AddChild( CDmeControlGroup *pGroup, const CDmeControlGroup *pInsertBeforeGroup )
{
// Can't make a group its own child
Assert( pGroup != this );
if ( pGroup == this )
return;
// Remove the group from its current control group if it belongs one.
CDmeControlGroup *pParentGroup = pGroup->FindParent();
if ( pParentGroup )
{
pParentGroup->RemoveChild( pGroup );
}
// If a insert location group was specified find it in the list of children
int nInsertLocation = m_Children.InvalidIndex();
if ( pInsertBeforeGroup )
{
nInsertLocation = m_Children.Find( pInsertBeforeGroup );
}
// Add the specified group as child of this group.
if ( nInsertLocation != m_Children.InvalidIndex() )
{
m_Children.InsertBefore( nInsertLocation, pGroup );
}
else
{
m_Children.AddToTail( pGroup );
}
}
//-------------------------------------------------------------------------------------------------
// Purpose: Remove the specified child group. Searches the immediate children of the node for the
// specified group and removes it from the child list if the group is found. Returns true if the
// group is found, false if the group is not found.
//-------------------------------------------------------------------------------------------------
bool CDmeControlGroup::RemoveChild( const CDmeControlGroup *pGroup )
{
int nChildren = m_Children.Count();
for ( int iChild = 0; iChild < nChildren; ++iChild )
{
if ( m_Children[ iChild ] == pGroup )
{
m_Children.Remove( iChild );
return true;
}
}
return false;
}
//-------------------------------------------------------------------------------------------------
// Purpose: Move the specified child group to the top of the list
//-------------------------------------------------------------------------------------------------
void CDmeControlGroup::MoveChildToTop( const CDmeControlGroup *pGroup )
{
// Make sure the group is actually a child, and move it
// to the top of the list if it is not already there.
int nChildren = m_Children.Count();
for ( int iChild = 1; iChild < nChildren; ++iChild )
{
if ( m_Children[ iChild ] == pGroup )
{
CDmeControlGroup *pChild = m_Children[ iChild ];
m_Children.Remove( iChild );
m_Children.InsertBefore( 0, pChild );
break;
}
}
}
//-------------------------------------------------------------------------------------------------
// Purpose: Move the specified child group to the bottom of the list
//-------------------------------------------------------------------------------------------------
void CDmeControlGroup::MoveChildToBottom( const CDmeControlGroup *pGroup )
{
// Make sure the group is actually a child, and move it
// to the bottom of the list if it is not already there.
int nChildren = m_Children.Count();
for ( int iChild = 0; iChild < (nChildren - 1); ++iChild )
{
if ( m_Children[ iChild ] == pGroup )
{
CDmeControlGroup *pChild = m_Children[ iChild ];
m_Children.Remove( iChild );
m_Children.AddToTail( pChild );
break;
}
}
}
//-----------------------------------------------------------------------------
// Compare the two groups by name for an ascending sort
//-----------------------------------------------------------------------------
int CDmeControlGroup::CompareByNameAscending( CDmeControlGroup * const *pGroupA, CDmeControlGroup * const *pGroupB )
{
return V_stricmp( (*pGroupA)->GetName(), (*pGroupB)->GetName() );
}
//-----------------------------------------------------------------------------
// Compare the two groups by name for a descending sort
//-----------------------------------------------------------------------------
int CDmeControlGroup::CompareByNameDecending( CDmeControlGroup * const *pGroupA, CDmeControlGroup * const *pGroupB )
{
return V_stricmp( (*pGroupB)->GetName(), (*pGroupA)->GetName() );
}
//-------------------------------------------------------------------------------------------------
// Sore the children by name
//-------------------------------------------------------------------------------------------------
void CDmeControlGroup::SortChildrenByName( bool bAscending )
{
// Copy the children into a temporary array to be sorted.
int nNumChildren = m_Children.Count();
CUtlVector< CDmeControlGroup * > sortedList( 0, nNumChildren );
for ( int iChild = 0; iChild < nNumChildren; ++iChild )
{
CDmeControlGroup *pGroup = m_Children[ iChild ];
if ( pGroup )
{
sortedList.AddToTail( pGroup );
}
}
// Sort the temporary array in ascending or descending order
if ( bAscending )
{
sortedList.Sort( CompareByNameAscending );
}
else
{
sortedList.Sort( CompareByNameDecending );
}
// Remove all of the children from the original list and then add them back in sorted order
m_Children.RemoveAll();
int nNumSorted = sortedList.Count();
for ( int iChild = 0; iChild < nNumSorted; ++iChild )
{
CDmeControlGroup *pGroup = sortedList[ iChild ];
if ( pGroup )
{
m_Children.AddToTail( pGroup );
}
}
}
//-------------------------------------------------------------------------------------------------
// Determine if the group has child of the specified name
//-------------------------------------------------------------------------------------------------
bool CDmeControlGroup::HasChildGroup( const char *pchName, bool recursive )
{
if ( FindChildByName( pchName, recursive ) == NULL )
return false;
return true;
}
//-------------------------------------------------------------------------------------------------
// Purpose: Find the child group with the specified name. If the recursive flag is true the entire
// sub-tree of the group will be searched, otherwise only the immediate children of the group will
// be searched for the specified child. If a parent group pointer is provided it will be returned
// with the immediate parent in which the child was located.
//-------------------------------------------------------------------------------------------------
CDmeControlGroup *CDmeControlGroup::FindChildByName( const char *pchName, bool recursive, CDmeControlGroup **pParentGroup )
{
// Search the immediate children for a group with the specified name.
int nChildren = m_Children.Count();
for ( int iChild = 0; iChild < nChildren; ++iChild )
{
CDmeControlGroup *pChild = m_Children[ iChild ];
if ( pChild )
{
if ( V_stricmp( pChild->GetName(), pchName ) == 0 )
{
if ( pParentGroup )
{
*pParentGroup = this;
}
return pChild;
}
}
}
// If the group was not found in the immediate children of the current group and the recursive
// flag is set, search the sub-trees of all the children for the specified group.
if ( recursive )
{
for ( int iChild = 0; iChild < nChildren; ++iChild )
{
CDmeControlGroup *pChild = m_Children[ iChild ];
if ( pChild )
{
CDmeControlGroup *pGroup = pChild->FindChildByName( pchName, true, pParentGroup );
if ( pGroup )
return pGroup;
}
}
}
return NULL;
}
//-------------------------------------------------------------------------------------------------
// Purpose: Find the parent of the group. Searches for groups which reference this group as a
// child. Each group is allowed to be the child of only one group, so the first group found is
// returned.
//-------------------------------------------------------------------------------------------------
CDmeControlGroup *CDmeControlGroup::FindParent() const
{
const static CUtlSymbolLarge symChildren = g_pDataModel->GetSymbol( "children" );
CDmeControlGroup *pParent = FindReferringElement< CDmeControlGroup >( this, symChildren );
return pParent;
}
//-------------------------------------------------------------------------------------------------
// Determine if this group is an ancestor of the specified group
//-------------------------------------------------------------------------------------------------
bool CDmeControlGroup::IsAncestorOfGroup( const CDmeControlGroup *pGroup ) const
{
if ( pGroup == NULL )
return false;
const CDmeControlGroup *pCurrentGroup = pGroup;
const CDmeControlGroup *pParent = pGroup->FindParent();
while ( pParent )
{
if ( pParent == this )
return true;
pCurrentGroup = pParent;
pParent = pParent->FindParent();
Assert( pCurrentGroup != pParent );
if ( pCurrentGroup == pParent )
break;
}
return false;
}
//-------------------------------------------------------------------------------------------------
// Create a control group with the provided name and add it to the specified parent. If a child of
// the specified name already exists it will be returned and no new group will be created.
//-------------------------------------------------------------------------------------------------
CDmeControlGroup *CDmeControlGroup::CreateControlGroup( const char *pchName )
{
CDmeControlGroup *pExistingGroup = FindChildByName( pchName, false );
if ( pExistingGroup )
return pExistingGroup;
// Create the new control group with the specified name
CDmeControlGroup *pNewGroup = CreateElement< CDmeControlGroup >( pchName, GetFileId() );
// Add the group to as a child of this group
AddChild( pNewGroup );
return pNewGroup;
}
//-------------------------------------------------------------------------------------------------
// Purpose: Get a flat list of all of the groups in sub-tree of the group
//-------------------------------------------------------------------------------------------------
void CDmeControlGroup::GetAllChildren( CUtlVector< DmElementHandle_t > &childGroupList ) const
{
int nChildren = m_Children.Count();
for ( int iChild = 0; iChild < nChildren; ++iChild )
{
CDmeControlGroup *pChild = m_Children[ iChild ];
if ( pChild )
{
childGroupList.AddToTail( pChild->GetHandle() );
pChild->GetAllChildren( childGroupList );
}
}
}
//-------------------------------------------------------------------------------------------------
// Recursively destroy the children of the specified group which have no controls or sub groups
//-------------------------------------------------------------------------------------------------
bool CDmeControlGroup::DestroyEmptyChildren_R( CDmeControlGroup *pGroup )
{
int nNumChildren = pGroup->m_Children.Count();
// Build a list of the children which are empty and should be destroyed. This
// process will recursively remove empty children of the children so that if
// a child has only empty sub-children then it will still be removed.
CUtlVector< CDmeControlGroup * > childrenToDestroy( 0, nNumChildren );
for ( int iChild = 0; iChild < nNumChildren; ++iChild )
{
CDmeControlGroup *pChild = pGroup->m_Children[ iChild ];
if ( pChild )
{
if ( DestroyEmptyChildren_R( pChild ) )
{
childrenToDestroy.AddToTail( pChild );
}
}
}
// Destroy the empty children
int nNumToDestroy = childrenToDestroy.Count();
for ( int iChild = 0; iChild < nNumToDestroy; ++iChild )
{
CDmeControlGroup *pChild = childrenToDestroy[ iChild ];
pGroup->RemoveChild( pChild );
}
// If this node is now empty return true indicating that it may be destroyed
return ( ( pGroup->m_Children.Count() == 0 ) && ( pGroup->m_Controls.Count() == 0 ) );
}
//-------------------------------------------------------------------------------------------------
// Destroy all of the empty children of the group, will not destroy this group even it is empty.
//-------------------------------------------------------------------------------------------------
void CDmeControlGroup::DestroyEmptyChildren()
{
DestroyEmptyChildren_R( this );
}
//-------------------------------------------------------------------------------------------------
// Purpose: Destroy the control group, moving all of its children and controls into this node
//-------------------------------------------------------------------------------------------------
void CDmeControlGroup::DestroyGroup( CDmeControlGroup *pGroup, CDmeControlGroup *pRecipient, bool recursive )
{
if ( pGroup == NULL )
return;
// Remove the group from its parent
CDmeControlGroup *pParent = pGroup->FindParent();
if ( pParent )
{
pParent->RemoveChild( pGroup );
if ( pRecipient == NULL )
{
pRecipient = pParent;
}
}
// Destroy the group and all of its children if specified
DestroyGroup_R( pGroup, pRecipient, recursive );
}
//-------------------------------------------------------------------------------------------------
// Purpose: Recursively destroy the child groups of the specified group and and the controls to the
// specified recipient group
//-------------------------------------------------------------------------------------------------
void CDmeControlGroup::DestroyGroup_R( CDmeControlGroup *pGroup, CDmeControlGroup *pRecipient, bool recursive )
{
if ( pGroup == NULL )
return;
// If the group is not empty there must be a recipient to receive its controls and groups
if ( pRecipient == NULL && !pGroup->IsEmpty() )
{
Assert( pGroup->IsEmpty() || pRecipient );
return;
}
// Iterate through the children, if recursive destroy the
// children otherwise copy the children to the recipient.
int nChildren = pGroup->m_Children.Count();
for ( int iChild = 0; iChild < nChildren; ++iChild )
{
CDmeControlGroup *pChild = pGroup->m_Children[ iChild ];
if ( pChild )
{
if ( recursive )
{
DestroyGroup_R( pChild, pRecipient, true );
}
else
{
pRecipient->m_Children.AddToTail( pChild );
}
}
}
// Copy all the controls of the node into the recipient
int nControls = pGroup->m_Controls.Count();
for ( int iControl = 0; iControl < nControls; ++iControl )
{
CDmElement *pControl = pGroup->m_Controls[ iControl ];
pRecipient->m_Controls.AddToTail( pControl );
}
// Destroy the group
DestroyElement( pGroup );
}
//-------------------------------------------------------------------------------------------------
// Remove all of the children and controls from the group
//-------------------------------------------------------------------------------------------------
void CDmeControlGroup::RemoveAllChildrenAndControls()
{
m_Children.RemoveAll();
m_Controls.RemoveAll();
}
//-------------------------------------------------------------------------------------------------
// Purpose: Set the color of the group, this is the color that is used when displaying the group in
// the user interface.
//-------------------------------------------------------------------------------------------------
void CDmeControlGroup::SetGroupColor( const Color &groupColor, bool bRecursive )
{
m_GroupColor = groupColor;
if ( !bRecursive )
return;
int nChildren = m_Children.Count();
for ( int iChild = 0; iChild < nChildren; ++iChild )
{
if ( m_Children[ iChild ] )
{
m_Children[ iChild ]->SetGroupColor( groupColor, true );
}
}
}
//-------------------------------------------------------------------------------------------------
// Purpose: Set the color to be used on the controls of the group
//-------------------------------------------------------------------------------------------------
void CDmeControlGroup::SetControlColor( const Color &controlColor, bool bRecursive )
{
m_ControlColor = controlColor;
if ( !bRecursive )
return;
int nChildren = m_Children.Count();
for ( int iChild = 0; iChild < nChildren; ++iChild )
{
if ( m_Children[ iChild ] )
{
m_Children[ iChild ]->SetControlColor( controlColor, true );
}
}
}
//-----------------------------------------------------------------------------
// Set the visible state of the group
//-----------------------------------------------------------------------------
void CDmeControlGroup::SetVisible( bool bVisible )
{
m_Visible = bVisible;
}
//-----------------------------------------------------------------------------
// Enable or disable selection of the controls
//-----------------------------------------------------------------------------
void CDmeControlGroup::SetSelectable( bool bSelectable )
{
m_Selectable = bSelectable;
}
//-----------------------------------------------------------------------------
// Enable or disable control snapping
//-----------------------------------------------------------------------------
void CDmeControlGroup::SetSnappable( bool bSnappable )
{
m_Snappable = bSnappable;
}
//-----------------------------------------------------------------------------
// Purpose: Determine if there are any controls or children in the group
//-----------------------------------------------------------------------------
bool CDmeControlGroup::IsEmpty() const
{
if ( m_Controls.Count() > 0 ) return false;
if ( m_Children.Count() > 0 ) return false;
return true;
}
//-----------------------------------------------------------------------------
// Is the group visible
//-----------------------------------------------------------------------------
bool CDmeControlGroup::IsVisible() const
{
CDmeControlGroup *pParent = FindParent();
if ( pParent && !pParent->IsVisible() )
return false;
return m_Visible;
}
//-----------------------------------------------------------------------------
// Can controls in the group be selected in the viewport
//-----------------------------------------------------------------------------
bool CDmeControlGroup::IsSelectable() const
{
CDmeControlGroup *pParent = FindParent();
if ( pParent && !pParent->IsSelectable() )
return false;
return m_Selectable;
}
//-----------------------------------------------------------------------------
// Can controls in the group be snapped to in the viewport
//-----------------------------------------------------------------------------
bool CDmeControlGroup::IsSnappable() const
{
CDmeControlGroup *pParent = FindParent();
if ( pParent && !pParent->IsSnappable() )
return false;
return m_Snappable;
}
//-----------------------------------------------------------------------------
// Find the shared ancestor between this control group and the specified control
// group. Will return NULL if groups are not in the same tree and do not share a
// common ancestor. If one group is an ancestor of the other group then that
// group will be returned, so result may be one of the nodes which is not
// technically an ancestor of that node.
//-----------------------------------------------------------------------------
CDmeControlGroup *CDmeControlGroup::FindCommonAncestor( CDmeControlGroup *pControlGroupB )
{
CDmeControlGroup *pControlGroupA = this;
// If the specified group is this group then
// the common ancestor is the group itself.
if ( pControlGroupA == pControlGroupB )
return pControlGroupA;
// Build the path from each group to the root
CUtlVector< CDmeControlGroup * > pathToGroupA;
CUtlVector< CDmeControlGroup * > pathToGroupB;
pControlGroupA->BuildPathFromRoot( pathToGroupA );
pControlGroupB->BuildPathFromRoot( pathToGroupB );
// Now walk each of the the paths until they diverge
CDmeControlGroup *pCommonGroup = NULL;
int nNumSteps = MIN( pathToGroupA.Count(), pathToGroupB.Count() );
int iStep = 0;
while ( iStep < nNumSteps )
{
if ( pathToGroupA[ iStep ] != pathToGroupB[ iStep ] )
break;
pCommonGroup = pathToGroupA[ iStep ];
++iStep;
}
return pCommonGroup;
}
//-----------------------------------------------------------------------------
// Find the root control group which this control group is in the sub tree of.
//-----------------------------------------------------------------------------
CDmeControlGroup *CDmeControlGroup::FindRootControlGroup()
{
CDmeControlGroup *pCurrent = this;
CDmeControlGroup *pParent = pCurrent->FindParent();
while ( pParent )
{
pCurrent = pParent;
pParent = pParent->FindParent();
}
return pCurrent;
}
//-----------------------------------------------------------------------------
// Build a list of the control group that form the path to the root of the tree
// to which the control group belongs
//-----------------------------------------------------------------------------
void CDmeControlGroup::BuildPathFromRoot( CUtlVector< CDmeControlGroup * > &pathToGroup )
{
CUtlVector< CDmeControlGroup * > pathToRoot( 0, 16 );
CDmeControlGroup *pCurrent = this;
while ( pCurrent )
{
pathToRoot.AddToTail( pCurrent );
pCurrent = pCurrent->FindParent();
}
int nNumGroups = pathToRoot.Count();
pathToGroup.SetCount( nNumGroups );
for ( int iGroup = 0; iGroup < nNumGroups; ++iGroup )
{
pathToGroup[ iGroup ] = pathToRoot[ nNumGroups - 1 - iGroup ];
}
}
//-----------------------------------------------------------------------------
// Find the animation set associated with the control group
//-----------------------------------------------------------------------------
CDmeAnimationSet *CDmeControlGroup::FindAnimationSet( bool bSearchAncestors ) const
{
const static CUtlSymbolLarge symRootControlGroup = g_pDataModel->GetSymbol( "rootControlGroup" );
const CDmeControlGroup *pCurrent = this;
while ( pCurrent )
{
CDmeAnimationSet *pAnimationSet = FindReferringElement< CDmeAnimationSet >( pCurrent, symRootControlGroup );
if ( pAnimationSet != NULL )
return pAnimationSet;
if ( bSearchAncestors == false )
break;
const CDmeControlGroup *pParent = pCurrent->FindParent();
if ( pCurrent == pParent )
break;
pCurrent = pParent;
}
return NULL;
}