Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 lines
6.9 KiB

  1. //====== Copyright � 1996-2008, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: Contains the declaration of the CDmeControlGroup class. The
  4. // CDmeControlGroup class is a grouping of animation controls that is used for
  5. // selection.
  6. //
  7. //=============================================================================
  8. #ifndef DMECONTROLGROUP_H
  9. #define DMECONTROLGROUP_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "datamodel/dmattributevar.h"
  14. class CDmeTransform;
  15. class CDmeAnimationSet;
  16. //-----------------------------------------------------------------------------
  17. // CDmeControlGroup: A class representing a grouping of controls used for
  18. // selection. Contains a list of controls as well as a list of child groups
  19. // which are used to for a group hierarchy.
  20. //-----------------------------------------------------------------------------
  21. class CDmeControlGroup : public CDmElement
  22. {
  23. DEFINE_ELEMENT( CDmeControlGroup, CDmElement );
  24. public:
  25. //---------------------------------
  26. // Control functions
  27. //---------------------------------
  28. // Add a control to the group
  29. void AddControl( CDmElement *pControl, const CDmElement *pInsertBeforeControl = NULL );
  30. // Remove a control from the group
  31. bool RemoveControl( const CDmElement *pControl );
  32. // Get a flat list of all of the controls in the group
  33. void GetControlsInGroup( CUtlVector< CDmElement* > &controlList, bool recursive ) const;
  34. // Find a control with the specified name within the group
  35. CDmElement *FindControlByName( const char *pchName, bool recursive, CDmeControlGroup **pParentGroup = NULL );
  36. // Find the group to which the specified control belongs, if any.
  37. static CDmeControlGroup *FindGroupContainingControl( const CDmElement* pControl );
  38. //---------------------------------
  39. // Group functions
  40. //---------------------------------
  41. // Make the specified group a child of this group
  42. void AddChild( CDmeControlGroup *pGroup, const CDmeControlGroup *pInsertBeforeGroup = NULL );
  43. // Remove the specified child group
  44. bool RemoveChild( const CDmeControlGroup *pGroup );
  45. // Move the specified child group to the top of the list
  46. void MoveChildToTop( const CDmeControlGroup *pGroup );
  47. // Move the specified child group to the bottom of the list
  48. void MoveChildToBottom( const CDmeControlGroup *pGroup );
  49. // Sore the children by name
  50. void SortChildrenByName( bool bAscending );
  51. // Determine if the group has child of the specified name
  52. bool HasChildGroup( const char *pchName, bool recursive );
  53. // Find the child group with the specified name
  54. CDmeControlGroup *FindChildByName( const char *pchName, bool recursive, CDmeControlGroup **pParentGroup = NULL );
  55. // Find the parent of the group
  56. CDmeControlGroup *FindParent() const;
  57. // Determine if this group is an ancestor of the specified group
  58. bool IsAncestorOfGroup( const CDmeControlGroup *pGroup ) const;
  59. // Create a control group with the provided name and make it a child of this group
  60. CDmeControlGroup *CreateControlGroup( const char *pchName );
  61. // Get a flat list of all of the groups in sub-tree of the group
  62. void GetAllChildren( CUtlVector< DmElementHandle_t > &childGroupList ) const;
  63. // Destroy all of the empty children of the group, will not destroy this group even it is empty.
  64. void DestroyEmptyChildren();
  65. // Destroy the control group, moving all of its children and controls into this node
  66. static void DestroyGroup( CDmeControlGroup *pGroup, CDmeControlGroup *pRecipient, bool recursive );
  67. // Remove all of the children and controls from the group
  68. void RemoveAllChildrenAndControls();
  69. // Set the color of the group
  70. void SetGroupColor( const Color &groupColor, bool recursive );
  71. // Set the color to be used on the controls of the group
  72. void SetControlColor( const Color &controlColor, bool recursive );
  73. // Set the visible state of the group
  74. void SetVisible( bool bVisible );
  75. // Enable or disable selection of the controls
  76. void SetSelectable( bool bEnable );
  77. // Enable or disable control snapping
  78. void SetSnappable( bool bEnable );
  79. // Determine if there are any controls or children in the group
  80. bool IsEmpty() const;
  81. // Is the group visible, will return false if any parent of the group is not visible
  82. bool IsVisible() const;
  83. // Can controls in the group be selected in the viewport, check includes parents
  84. bool IsSelectable() const;
  85. // Can controls in the group be snapped to in the viewport, check includes parents
  86. bool IsSnappable() const;
  87. // Find the animation set associated with the control group
  88. CDmeAnimationSet *FindAnimationSet( bool bSearchAncestors ) const;
  89. // Find the shared ancestor between this control group and the specified control group
  90. CDmeControlGroup *FindCommonAncestor( CDmeControlGroup *pControlGroup );
  91. // Find the root control group which this control group is in the sub tree of.
  92. CDmeControlGroup *FindRootControlGroup();
  93. // Compare the two groups by name for an ascending sort
  94. static int CDmeControlGroup::CompareByNameAscending( CDmeControlGroup * const *pGroupA, CDmeControlGroup * const *pGroupB );
  95. // Compare the two groups by name for a descending sort
  96. static int CDmeControlGroup::CompareByNameDecending( CDmeControlGroup * const *pGroupA, CDmeControlGroup * const *pGroupB );
  97. // Accessors
  98. const CDmaElementArray< CDmeControlGroup > &Children() const { return m_Children; }
  99. const CDmaElementArray< CDmElement > &Controls() const { return m_Controls; }
  100. const Color &GroupColor() const { return m_GroupColor; }
  101. const Color &ControlColor() const { return m_ControlColor; }
  102. bool Visible() const { return m_Visible; }
  103. bool Selectable() const { return m_Selectable; }
  104. bool Snappable() const { return m_Snappable; }
  105. private:
  106. // Recursively destroy the children of the specified group which have no controls or sub groups
  107. static bool DestroyEmptyChildren_R( CDmeControlGroup *pGroup );
  108. // Recursively destroy the child groups of the specified group and and the controls to the specified recipient group
  109. static void DestroyGroup_R( CDmeControlGroup *pGroup, CDmeControlGroup *pRecipient, bool recursive );
  110. // Build a list of the control group that form the path to the root of the tree to which the control group belongs
  111. void BuildPathFromRoot( CUtlVector< CDmeControlGroup * > &path );
  112. CDmaElementArray< CDmeControlGroup > m_Children; // "children" : Child groups of this control group
  113. CDmaElementArray< CDmElement > m_Controls; // "controls" : Controls within the group
  114. CDmaVar< Color > m_GroupColor; // "groupColor" : Color which the group is to be displayed with
  115. CDmaVar< Color > m_ControlColor; // "controlColor" : Color in which the controls of the group are to be displayed
  116. CDmaVar< bool > m_Visible; // "visible" : Is the group visible in animation set editor
  117. CDmaVar< bool > m_Selectable; // "selectable" : Can the group be selected
  118. CDmaVar< bool > m_Snappable; // "snapping" : Can controls in the group be snapped to
  119. };
  120. #endif // DMECONTROLGROUP_H