Team Fortress 2 Source Code as on 22/4/2020
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.

190 lines
6.0 KiB

  1. //========= Copyright 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/utldict.h"
  14. #include "tier1/utlsymbol.h"
  15. #include <vgui/VGUI.h>
  16. #include <vgui/Dar.h>
  17. #include <vgui/Cursor.h>
  18. #include <vgui/IScheme.h>
  19. #include <vgui_controls/Controls.h>
  20. #include <vgui_controls/PHandle.h>
  21. #include "tier1/utlhandletable.h"
  22. class KeyValues;
  23. namespace vgui
  24. {
  25. //-----------------------------------------------------------------------------
  26. // Purpose: a BuildGroup is a list of panels contained in a window (the contextPanel)
  27. // Members of this group are viewable and editable in Build Mode, via the BuildModeDialog wizard
  28. //-----------------------------------------------------------------------------
  29. class BuildGroup
  30. {
  31. DECLARE_HANDLES( BuildGroup, 20 );
  32. public:
  33. BuildGroup(Panel *parentPanel, Panel *contextPanel);
  34. ~BuildGroup();
  35. // Toggle build mode on/off
  36. virtual void SetEnabled(bool state);
  37. // Check if buildgroup is enabled
  38. virtual bool IsEnabled();
  39. // Return the currently selected panel
  40. virtual Panel *GetCurrentPanel();
  41. // Load the control settings from file
  42. virtual void LoadControlSettings(const char *controlResourceName, const char *pathID = NULL, KeyValues *pPreloadedKeyValues = NULL, KeyValues *pConditions = NULL );
  43. // Reload the control settings from file
  44. void ReloadControlSettings();
  45. // changes which control settings are currently loaded
  46. void ChangeControlSettingsFile(const char *controlResourceName);
  47. // Save control settings from file, using the same resource
  48. // name as what LoadControlSettings() was called with
  49. virtual bool SaveControlSettings();
  50. // Serialize settings from a resource data container
  51. virtual void ApplySettings(KeyValues *resourceData);
  52. // Serialize settings to a resource data container
  53. virtual void GetSettings(KeyValues *resourceData);
  54. // Remove all objects in the current control group
  55. virtual void RemoveSettings();
  56. // Get a new unique fieldname for a new control
  57. void GetNewFieldName(char *newFieldName, int newFieldNameSize, Panel *newPanel);
  58. // Check if a control name is already taken
  59. Panel *FieldNameTaken(const char *fieldName);
  60. // Add a new control (via the BuildModeDialog)
  61. Panel *NewControl( KeyValues *controlKeys, int x=0, int y=0);
  62. Panel *NewControl( const char *name, int x=0, int y=0);
  63. // Set the panel from which the build group gets all it's object creation information
  64. virtual void SetContextPanel(Panel *contextPanel);
  65. //Get the panel that build group is pointed at.
  66. virtual Panel *GetContextPanel();
  67. // Get the list of panels in the buildgroup
  68. CUtlVector<PHandle> *GetPanelList();
  69. // Get the resource file name used
  70. virtual const char *GetResourceName(void) { return m_pResourceName; }
  71. virtual void PanelAdded(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. static bool PrecacheResFile( const char* pszResFileName );
  95. static void ClearResFileCache();
  96. protected:
  97. virtual bool CursorMoved(int x, int y, Panel *panel);
  98. virtual bool MouseDoublePressed(MouseCode code, Panel *panel);
  99. virtual bool KeyCodeTyped(KeyCode code, Panel *panel);
  100. virtual bool KeyCodeReleased(KeyCode code, Panel *panel );
  101. virtual void ApplySchemeSettings(IScheme *pScheme);
  102. virtual bool KeyTyped( wchar_t unichar, Panel *panel );
  103. virtual HCursor GetCursor(Panel *panel);
  104. private:
  105. void ApplySnap(Panel* panel);
  106. Panel *CreateBuildDialog();
  107. void ActivateBuildDialog();
  108. void DeleteAllControlsCreatedByControlSettingsFile();
  109. bool _enabled;
  110. int _snapX;
  111. int _snapY;
  112. HCursor _cursor_sizenwse;
  113. HCursor _cursor_sizenesw;
  114. HCursor _cursor_sizewe;
  115. HCursor _cursor_sizens;
  116. HCursor _cursor_sizeall;
  117. bool _dragging;
  118. MouseCode _dragMouseCode;
  119. int _dragStartPanelPos[2];
  120. int _dragStartCursorPos[2];
  121. int _dragStartPanelSize[ 2 ];
  122. Panel * _currentPanel;
  123. CUtlVector<PHandle> _panelDar;
  124. char *m_pResourceName;
  125. char *m_pResourcePathID;
  126. PHandle m_hBuildDialog;
  127. Panel *m_pBuildContext; // the panel from which the build dialog gets all the information it needs
  128. Panel *m_pParentPanel; // panel to create new controls in
  129. CUtlVector<PHandle> _controlGroup; // grouped panels
  130. CUtlVector<int> _groupDeltaX; // x offsets of panels in group from the selected panel
  131. CUtlVector<int> _groupDeltaY; // y offsets of panels in group from the selected panel
  132. Label *_rulerNumber[4]; // 4 numbers to label rulers with
  133. bool _showRulers; // toggles ruler display
  134. CUtlVector<CUtlSymbol> m_RegisteredControlSettingsFiles;
  135. friend class Panel;
  136. static CUtlDict< KeyValues* > m_dictCachedResFiles;
  137. };
  138. //-----------------------------------------------------------------------------
  139. // Handle to a build group
  140. //-----------------------------------------------------------------------------
  141. typedef CUtlHandle<BuildGroup> HBuildGroup;
  142. } // namespace vgui
  143. #endif // VGUI_BUILDGROUP_H