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.

185 lines
5.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef VGUI_BUILDGROUP_H
  8. #define VGUI_BUILDGROUP_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "tier1/utlvector.h"
  13. #include "tier1/utlsymbol.h"
  14. #include <vgui/vgui.h>
  15. #include <vgui/Dar.h>
  16. #include <vgui/Cursor.h>
  17. #include <vgui/IScheme.h>
  18. #include <vgui_controls/Controls.h>
  19. #include <vgui_controls/PHandle.h>
  20. #include "tier1/utlhandletable.h"
  21. class KeyValues;
  22. namespace vgui
  23. {
  24. //-----------------------------------------------------------------------------
  25. // Purpose: a BuildGroup is a list of panels contained in a window (the contextPanel)
  26. // Members of this group are viewable and editable in Build Mode, via the BuildModeDialog wizard
  27. //-----------------------------------------------------------------------------
  28. class BuildGroup
  29. {
  30. DECLARE_HANDLES( BuildGroup, 20 );
  31. public:
  32. BuildGroup(Panel *parentPanel, Panel *contextPanel);
  33. ~BuildGroup();
  34. // Toggle build mode on/off
  35. virtual void SetEnabled(bool state);
  36. // Check if buildgroup is enabled
  37. virtual bool IsEnabled();
  38. // Return the currently selected panel
  39. virtual Panel *GetCurrentPanel();
  40. // Load the control settings from file
  41. virtual void LoadControlSettings(const char *controlResourceName, const char *pathID = NULL, KeyValues *pPreloadedKeyValues = NULL, KeyValues *pConditions = NULL);
  42. // Reload the control settings from file
  43. void ReloadControlSettings();
  44. // changes which control settings are currently loaded
  45. void ChangeControlSettingsFile(const char *controlResourceName);
  46. // Save control settings from file, using the same resource
  47. // name as what LoadControlSettings() was called with
  48. virtual bool SaveControlSettings();
  49. // Serialize settings from a resource data container
  50. virtual void ApplySettings(KeyValues *resourceData);
  51. // Serialize settings to a resource data container
  52. virtual void GetSettings(KeyValues *resourceData);
  53. // Remove all objects in the current control group
  54. virtual void RemoveSettings();
  55. // Get a new unique fieldname for a new control
  56. void GetNewFieldName(char *newFieldName, int newFieldNameSize, Panel *newPanel);
  57. // Check if a control name is already taken
  58. Panel *FieldNameTaken(const char *fieldName);
  59. // Add a new control (via the BuildModeDialog)
  60. Panel *NewControl( KeyValues *controlKeys, int x=0, int y=0);
  61. Panel *NewControl( const char *name, int x=0, int y=0);
  62. // Set the panel from which the build group gets all it's object creation information
  63. virtual void SetContextPanel(Panel *contextPanel);
  64. //Get the panel that build group is pointed at.
  65. virtual Panel *GetContextPanel();
  66. // Get the list of panels in the buildgroup
  67. CUtlVector<PHandle> *GetPanelList();
  68. // Get the resource file name used
  69. virtual const char *GetResourceName(void) { return m_pResourceName; }
  70. void PanelAdded(Panel* panel);
  71. void PanelRemoved(Panel *panel);
  72. virtual bool MousePressed(MouseCode code,Panel* panel);
  73. virtual bool MouseReleased(MouseCode code,Panel* panel);
  74. // Get the list of panels that are currently selected
  75. virtual CUtlVector<PHandle> *GetControlGroup();
  76. // Toggle ruler display on/off
  77. virtual void ToggleRulerDisplay();
  78. // Toggle visibility of ruler number labels
  79. virtual void SetRulerLabelsVisible(bool state);
  80. // Check if ruler display is activated
  81. virtual bool HasRulersOn();
  82. // Draw Rulers on screen
  83. virtual void DrawRulers();
  84. // registers that a control settings file may be loaded
  85. // use when the dialog may have multiple states and the editor will need to be able to switch between them
  86. void RegisterControlSettingsFile(const char *controlResourceName, const char *pathID = NULL);
  87. // iterator for registered files
  88. int GetRegisteredControlSettingsFileCount();
  89. const char *GetRegisteredControlSettingsFileByIndex(int index);
  90. // dialog variables
  91. KeyValues *GetDialogVariables();
  92. // conditional keys for selectively reading keyvalues
  93. void ProcessConditionalKeys( KeyValues *pDat, KeyValues *pConditions );
  94. protected:
  95. virtual bool CursorMoved(int x, int y, Panel *panel);
  96. virtual bool MouseDoublePressed(MouseCode code, Panel *panel);
  97. virtual bool KeyCodeTyped(KeyCode code, Panel *panel);
  98. virtual bool KeyCodeReleased(KeyCode code, Panel *panel );
  99. virtual void ApplySchemeSettings(IScheme *pScheme);
  100. virtual bool KeyTyped( wchar_t unichar, Panel *panel );
  101. virtual HCursor GetCursor(Panel *panel);
  102. private:
  103. void ApplySnap(Panel* panel);
  104. Panel *CreateBuildDialog();
  105. void ActivateBuildDialog();
  106. void DeleteAllControlsCreatedByControlSettingsFile();
  107. bool _enabled;
  108. int _snapX;
  109. int _snapY;
  110. HCursor _cursor_sizenwse;
  111. HCursor _cursor_sizenesw;
  112. HCursor _cursor_sizewe;
  113. HCursor _cursor_sizens;
  114. HCursor _cursor_sizeall;
  115. bool _dragging;
  116. MouseCode _dragMouseCode;
  117. int _dragStartPanelPos[2];
  118. int _dragStartCursorPos[2];
  119. int _dragStartPanelSize[ 2 ];
  120. Panel * _currentPanel;
  121. CUtlVector<PHandle> _panelDar;
  122. char *m_pResourceName;
  123. char *m_pResourcePathID;
  124. PHandle m_hBuildDialog;
  125. Panel *m_pBuildContext; // the panel from which the build dialog gets all the information it needs
  126. Panel *m_pParentPanel; // panel to create new controls in
  127. CUtlVector<PHandle> _controlGroup; // grouped panels
  128. CUtlVector<int> _groupDeltaX; // x offsets of panels in group from the selected panel
  129. CUtlVector<int> _groupDeltaY; // y offsets of panels in group from the selected panel
  130. Label *_rulerNumber[4]; // 4 numbers to label rulers with
  131. bool _showRulers; // toggles ruler display
  132. CUtlVector<CUtlSymbol> m_RegisteredControlSettingsFiles;
  133. friend class Panel;
  134. };
  135. //-----------------------------------------------------------------------------
  136. // Handle to a build group
  137. //-----------------------------------------------------------------------------
  138. typedef CUtlHandle<BuildGroup> HBuildGroup;
  139. } // namespace vgui
  140. #endif // VGUI_BUILDGROUP_H