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.

1132 lines
44 KiB

  1. //===== Copyright 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef PANEL_H
  8. #define PANEL_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "tier1/utlflags.h"
  13. #include "vgui/vgui.h"
  14. #include "vgui/Dar.h"
  15. #include "vgui_controls/MessageMap.h"
  16. #if defined( VGUI_USEKEYBINDINGMAPS )
  17. #include "vgui_controls/KeyBindingMap.h"
  18. #endif
  19. #include "vgui/IClientPanel.h"
  20. #include "vgui/IScheme.h"
  21. #include "vgui_controls/Controls.h"
  22. #include "vgui_controls/PHandle.h"
  23. #include "vgui_controls/PanelAnimationVar.h"
  24. #include "color.h"
  25. #include "tier1/keyvalues.h"
  26. #include "vstdlib/ikeyvaluessystem.h"
  27. #include "tier1/utlsymbol.h"
  28. #include "vgui_controls/BuildGroup.h"
  29. #include "dmxloader/dmxelement.h"
  30. // undefine windows function macros that overlap
  31. #ifdef PostMessage
  32. #undef PostMessage
  33. #endif
  34. #ifdef SetCursor
  35. #undef SetCursor
  36. #endif
  37. //-----------------------------------------------------------------------------
  38. // Forward declarations
  39. //-----------------------------------------------------------------------------
  40. class CUtlBuffer;
  41. struct DmxElementUnpackStructure_t;
  42. namespace vgui
  43. {
  44. #if !defined( _GAMECONSOLE )
  45. #define VGUI_USEDRAGDROP 1
  46. #endif
  47. #if defined( VGUI_USEKEYBINDINGMAPS )
  48. struct PanelKeyBindingMap;
  49. #endif
  50. //-----------------------------------------------------------------------------
  51. // Purpose: Helper functions to construct vgui panels
  52. //
  53. // SETUP_PANEL - will make a panel ready for use right now (i.e setup its colors, borders, fonts, etc)
  54. //
  55. template< class T >
  56. inline T *SETUP_PANEL(T *panel)
  57. {
  58. panel->MakeReadyForUse();
  59. return panel;
  60. }
  61. //
  62. // CREATE_PANEL - creates a panel that is ready to use right now
  63. //
  64. // example of use = to set the FG Color of a panel inside of a constructor (i.e before ApplySchemeSettings() has been run on the child)
  65. //
  66. #define CREATE_PANEL(type, parent, name) (SETUP_PANEL(new type(parent, name)))
  67. //-----------------------------------------------------------------------------
  68. // Purpose: Drag/drop support context info (could defined within Panel...)
  69. //-----------------------------------------------------------------------------
  70. #if defined( VGUI_USEDRAGDROP )
  71. struct DragDrop_t;
  72. class Menu;
  73. #endif
  74. class Panel;
  75. struct SizerAddArgs_t
  76. {
  77. SizerAddArgs_t()
  78. {
  79. m_flExpandFactor = 0.0f;
  80. m_nPadding = 5;
  81. m_bMinorExpand = true;
  82. m_nMinX = -1;
  83. m_nMinY = -1;
  84. m_bIgnoreMemberMin = false;
  85. }
  86. SizerAddArgs_t& Expand( float flExpandFactor ) { m_flExpandFactor = flExpandFactor; return *this; }
  87. SizerAddArgs_t& Padding( int nPadding ) { m_nPadding = nPadding; return *this; }
  88. SizerAddArgs_t& MinorExpand( bool bMinorExpand ) { m_bMinorExpand = bMinorExpand; return *this; }
  89. SizerAddArgs_t& MinSize( int nMinX, int nMinY ) { m_nMinX = nMinX; m_nMinY = nMinY; return *this; }
  90. SizerAddArgs_t& MinX( int nMinX ) { m_nMinX = nMinX; return *this; }
  91. SizerAddArgs_t& MinY( int nMinY ) { m_nMinY = nMinY; return *this; }
  92. // IgnoreMemberMin --> MinX and MinY (when set) are the only criteria for minimum size; member-requested min size is ignored
  93. SizerAddArgs_t& IgnoreMemberMin( bool bIgnoreMemberMin = true ) { m_bIgnoreMemberMin = bIgnoreMemberMin; return *this; }
  94. SizerAddArgs_t& FixedSize( int nX, int nY )
  95. {
  96. IgnoreMemberMin( true );
  97. MinSize( nX, nY );
  98. Expand( 0.f );
  99. MinorExpand( false );
  100. return *this;
  101. }
  102. float m_flExpandFactor;
  103. int m_nPadding;
  104. bool m_bMinorExpand;
  105. int m_nMinX;
  106. int m_nMinY;
  107. bool m_bIgnoreMemberMin;
  108. };
  109. enum SizerLayoutDirection_t
  110. {
  111. ESLD_HORIZONTAL, // major axis = X
  112. ESLD_VERTICAL // major axis = Y
  113. };
  114. enum SizerElementType_t
  115. {
  116. ESET_SIZER,
  117. ESET_PANEL,
  118. ESET_SPACER,
  119. };
  120. class CSizerBase
  121. {
  122. public:
  123. CSizerBase( );
  124. virtual ~CSizerBase( );
  125. int GetElementCount() { return m_Members.Count(); }
  126. SizerElementType_t GetElementType( int i );
  127. Panel *GetPanel( int i );
  128. void SetElementArgs( int nIndex, const SizerAddArgs_t& args ) { m_Members[nIndex].Fill( args ); }
  129. // The containing panel's layout should be invalidated if members are added to this sizer.
  130. // Inserts a panel/sizer/spacer at the specified index and shifts remaining elements down
  131. void InsertPanel( int nIndex, Panel *pPanel, const SizerAddArgs_t& args );
  132. void InsertSizer( int nIndex, CSizerBase *pSizer, const SizerAddArgs_t& args );
  133. void InsertSpacer( int nIndex, const SizerAddArgs_t& args );
  134. void AddPanel( Panel *pPanel, const SizerAddArgs_t& args ) { InsertPanel( GetElementCount(), pPanel, args ); }
  135. void AddSizer( CSizerBase *pSizer, const SizerAddArgs_t& args ) { InsertSizer( GetElementCount(), pSizer, args ); }
  136. void AddSpacer( const SizerAddArgs_t& args ) { InsertSpacer( GetElementCount(), args ); }
  137. void RemoveElement( int i, bool bDelete );
  138. void RemoveAllMembers( bool bDelete );
  139. void GetMinSize( int &OutX, int &OutY );
  140. // Called by Panel on PerformLayout() so that sizer client size computations are up-to-date
  141. void RecursiveInvalidateCachedSize();
  142. virtual void DoLayout( int BaseX, int BaseY, int SizeX, int SizeY ) = 0;
  143. virtual void CalculateSize() = 0;
  144. protected:
  145. class CSizerMember
  146. {
  147. friend class CSizerBase; // allow CSizerBase to populate the private members directly
  148. public:
  149. SizerElementType_t GetElementType() const;
  150. Panel *GetPanel() const;
  151. void GetMemberMinSize( int &OutX, int &OutY );
  152. void RecursiveInvalidateCachedSize();
  153. void Place( int BaseX, int BaseY, int SizeX, int SizeY );
  154. float GetExpandFactor() { return m_flExpandFactor; }
  155. bool GetMinorExpand() { return m_bMinorExpand; }
  156. void DiscardOwnedSizer();
  157. bool IsVisible();
  158. void Fill( const SizerAddArgs_t& args );
  159. private:
  160. void RecursiveRemove( bool bDelete );
  161. Panel *m_pPanel;
  162. CSizerBase *m_pSizer;
  163. int m_nPadding; // if m_pPanel and m_pSizer are both NULL, this is the spacer min size
  164. float m_flExpandFactor;
  165. bool m_bMinorExpand;
  166. bool m_bIgnoreMemberMin;
  167. int m_nMinX;
  168. int m_nMinY;
  169. };
  170. CUtlVector<CSizerMember> m_Members;
  171. int m_nMinXSize;
  172. int m_nMinYSize;
  173. };
  174. inline int SizerMajorAxis( SizerLayoutDirection_t Dir, int X, int Y ) { return (Dir == ESLD_HORIZONTAL) ? X : Y; }
  175. inline int SizerMinorAxis( SizerLayoutDirection_t Dir, int X, int Y ) { return (Dir == ESLD_VERTICAL) ? X : Y; }
  176. inline int SizerXAxis( SizerLayoutDirection_t Dir, int MajorAxis, int MinorAxis ) { return (Dir == ESLD_HORIZONTAL) ? MajorAxis : MinorAxis; }
  177. inline int SizerYAxis( SizerLayoutDirection_t Dir, int MajorAxis, int MinorAxis ) { return (Dir == ESLD_VERTICAL) ? MajorAxis : MinorAxis; }
  178. class CBoxSizer: public CSizerBase
  179. {
  180. public:
  181. CBoxSizer( SizerLayoutDirection_t LayoutDirection );
  182. virtual void CalculateSize();
  183. virtual void DoLayout( int BaseX, int BaseY, int SizeX, int SizeY );
  184. protected:
  185. SizerLayoutDirection_t m_LayoutDirection;
  186. };
  187. //-----------------------------------------------------------------------------
  188. // Purpose: Macro to handle Colors that can be overridden in .res files
  189. //-----------------------------------------------------------------------------
  190. struct OverridableColorEntry
  191. {
  192. char const *name() { return m_pszScriptName; }
  193. char const *m_pszScriptName;
  194. Color *m_pColor;
  195. Color m_colFromScript;
  196. UtlSymId_t m_sColorNameFromScript;
  197. bool m_bOverridden;
  198. };
  199. #define REGISTER_COLOR_AS_OVERRIDABLE( name, scriptname ) \
  200. AddToOverridableColors( &name, scriptname );
  201. //-----------------------------------------------------------------------------
  202. // Macros for unpacking vgui panels
  203. //-----------------------------------------------------------------------------
  204. #define DECLARE_VGUI_UNPACK() \
  205. DECLARE_DMXELEMENT_UNPACK() \
  206. private: \
  207. static DmxElementUnpackStructure_t *s_pUnpackParams; \
  208. public: \
  209. virtual const DmxElementUnpackStructure_t* GetUnpackStructure() const { return s_pUnpackParams; }
  210. #define DECLARE_VGUI_UNPACK_NAMESPACE( _namespace ) \
  211. template <typename T> friend DmxElementUnpackStructure_t *DmxElementUnpackInit##_namespace(T *); \
  212. private: \
  213. static DmxElementUnpackStructure_t *s_pUnpackParams; \
  214. public: \
  215. virtual const DmxElementUnpackStructure_t* GetUnpackStructure() const { return s_pUnpackParams; }
  216. #define BEGIN_VGUI_UNPACK( _structName ) BEGIN_DMXELEMENT_UNPACK( _structName )
  217. #define END_VGUI_UNPACK( _structName ) \
  218. END_DMXELEMENT_UNPACK( _structName, s_pUnpackParams ) \
  219. DmxElementUnpackStructure_t *_structName::s_pUnpackParams = _structName##_UnpackInit::s_pUnpack;
  220. #define BEGIN_VGUI_UNPACK_NAMESPACE( _nameSpace, _structName ) BEGIN_DMXELEMENT_UNPACK_NAMESPACE( _nameSpace, _structName )
  221. #define END_VGUI_UNPACK_NAMESPACE( _nameSpace, _structName ) \
  222. END_DMXELEMENT_UNPACK_NAMESPACE( _nameSpace, _structName, s_pUnpackParams ) \
  223. DmxElementUnpackStructure_t *_structName::s_pUnpackParams = _namespace##_structName##_UnpackInit::s_pUnpack;
  224. //-----------------------------------------------------------------------------
  225. // Purpose: For hudanimations.txt scripting of vars
  226. //-----------------------------------------------------------------------------
  227. class IPanelAnimationPropertyConverter
  228. {
  229. public:
  230. virtual void GetData( Panel *panel, KeyValues *kv, PanelAnimationMapEntry *entry ) = 0;
  231. virtual void SetData( Panel *panel, KeyValues *kv, PanelAnimationMapEntry *entry ) = 0;
  232. virtual void InitFromDefault( Panel *panel, PanelAnimationMapEntry *entry ) = 0;
  233. };
  234. #if defined( VGUI_USEKEYBINDINGMAPS )
  235. enum KeyBindingContextHandle_t
  236. {
  237. INVALID_KEYBINDINGCONTEXT_HANDLE = 0xffffffff,
  238. };
  239. #endif
  240. //=============================================================================
  241. // HPE_BEGIN:
  242. // [tj] bitwise defines for rounded corners
  243. //=============================================================================
  244. #define PANEL_ROUND_CORNER_TOP_LEFT (1 << 0)
  245. #define PANEL_ROUND_CORNER_TOP_RIGHT (1 << 1)
  246. #define PANEL_ROUND_CORNER_BOTTOM_LEFT (1 << 2)
  247. #define PANEL_ROUND_CORNER_BOTTOM_RIGHT (1 << 3)
  248. #define PANEL_ROUND_CORNER_ALL PANEL_ROUND_CORNER_TOP_LEFT | PANEL_ROUND_CORNER_TOP_RIGHT | PANEL_ROUND_CORNER_BOTTOM_LEFT | PANEL_ROUND_CORNER_BOTTOM_RIGHT
  249. //=============================================================================
  250. // HPE_END
  251. //=============================================================================//-----------------------------------------------------------------------------
  252. // Purpose: Base interface to all vgui windows
  253. // All vgui controls that receive message and/or have a physical presence
  254. // on screen are be derived from Panel.
  255. // This is designed as an easy-access to the vgui-functionality; for more
  256. // low-level access to vgui functions use the IPanel/IClientPanel interfaces directly
  257. //-----------------------------------------------------------------------------
  258. class Panel : public IClientPanel
  259. {
  260. DECLARE_CLASS_SIMPLE_NOBASE( Panel );
  261. DECLARE_DMXELEMENT_UNPACK_NAMESPACE(vgui);
  262. public:
  263. // For property mapping
  264. static void InitPropertyConverters( void );
  265. static void AddPropertyConverter( char const *typeName, IPanelAnimationPropertyConverter *converter );
  266. //-----------------------------------------------------------------------------
  267. // CONSTRUCTORS
  268. // these functions deal with the creation of the Panel
  269. // the Panel automatically gets a handle to a vgui-internal panel, the ipanel(), upon construction
  270. // vgui interfaces deal only with ipanel(), not Panel directly
  271. Panel();
  272. Panel(Panel *parent);
  273. Panel(Panel *parent, const char *panelName);
  274. Panel(Panel *parent, const char *panelName, HScheme scheme);
  275. virtual ~Panel();
  276. // returns pointer to Panel's vgui VPanel interface handle
  277. virtual VPANEL GetVPanel() { return _vpanel; }
  278. HPanel ToHandle() const;
  279. //-----------------------------------------------------------------------------
  280. // PANEL METHODS
  281. // these functions all manipulate panels
  282. // they cannot be derived from
  283. void SetName(const char *panelName); // sets the name of the panel - used as an identifier
  284. const char *GetName(); // returns the name of this panel... never NULL
  285. const char *GetClassName(); // returns the class name of the panel (eg. Panel, Label, Button, etc.)
  286. void MakeReadyForUse(); // fully construct this panel so its ready for use right now (i.e fonts loaded, colors set, default label text set, ...)
  287. // panel position & size
  288. // all units are in pixels
  289. void SetPos(int x,int y); // sets position of panel, in local space (ie. relative to parent's position)
  290. void GetPos(int &x,int &y); // gets local position of panel
  291. void SetSize(int wide,int tall); // sets size of panel
  292. void GetSize(int &wide, int &tall); // gets size of panel
  293. void SetBounds(int x, int y, int wide, int tall); // combination of SetPos/SetSize
  294. void GetBounds(int &x, int &y, int &wide, int &tall); // combination of GetPos/GetSize
  295. int GetWide(); // returns width of panel
  296. void SetWide(int wide); // sets width of panel
  297. int GetTall(); // returns height of panel
  298. void SetTall(int tall); // sets height of panel
  299. void SetMinimumSize(int wide,int tall); // sets the minimum size the panel can go
  300. void GetMinimumSize(int& wide,int& tall); // gets the minimum size
  301. bool IsBuildModeEditable(); // editable in the buildModeDialog?
  302. void SetBuildModeEditable(bool state); // set buildModeDialog editable
  303. bool IsBuildModeDeletable(); // deletable in the buildModeDialog?
  304. void SetBuildModeDeletable(bool state); // set buildModeDialog deletable
  305. bool IsBuildModeActive(); // true if we're currently in edit mode
  306. void SetZPos(int z); // sets Z ordering - lower numbers are always behind higher z's
  307. int GetZPos( void );
  308. void SetAlpha(int alpha); // sets alpha modifier for panel and all child panels [0..255]
  309. int GetAlpha(); // returns the current alpha
  310. // panel visibility
  311. // invisible panels and their children do not drawn, updated, or receive input messages
  312. virtual void SetVisible(bool state);
  313. virtual bool IsVisible();
  314. virtual bool IsFullyVisible(); // checks parent panels are IsVisible too
  315. // painting
  316. virtual VPANEL IsWithinTraverse(int x, int y, bool traversePopups); // recursive; returns a pointer to the panel at those coordinates
  317. MESSAGE_FUNC( Repaint, "Repaint" ); // marks the panel as needing to be repainted
  318. virtual void PostMessage(VPANEL target, KeyValues *message, float delaySeconds = 0.0f);
  319. bool IsWithin(int x, int y); //in screen space
  320. void LocalToScreen(int &x, int &y);
  321. void ScreenToLocal(int &x, int &y);
  322. void ParentLocalToScreen(int &x, int &y);
  323. void MakePopup(bool showTaskbarIcon = true,bool disabled = false); // turns the panel into a popup window (ie. can draw outside of it's parents space)
  324. virtual void OnMove();
  325. // panel hierarchy
  326. virtual Panel *GetParent();
  327. virtual VPANEL GetVParent();
  328. virtual void SetParent(Panel *newParent);
  329. virtual void SetParent(VPANEL newParent);
  330. virtual bool HasParent(VPANEL potentialParent);
  331. int GetChildCount();
  332. Panel *GetChild(int index);
  333. int FindChildIndexByName( const char *childName );
  334. Panel *FindChildByName(const char *childName, bool recurseDown = false);
  335. Panel *FindSiblingByName(const char *siblingName);
  336. void CallParentFunction(KeyValues *message);
  337. virtual bool LookupElementBounds( const char *elementName, int &x, int &y, int &wide, int &tall ) { return false; }
  338. virtual void SetAutoDelete(bool state); // if set to true, panel automatically frees itself when parent is deleted
  339. virtual bool IsAutoDeleteSet();
  340. virtual void DeletePanel(); // simply does a { delete this; }
  341. // messaging
  342. virtual void AddActionSignalTarget(Panel *messageTarget);
  343. virtual void AddActionSignalTarget(VPANEL messageTarget);
  344. virtual void RemoveActionSignalTarget(Panel *oldTarget);
  345. virtual void PostActionSignal(KeyValues *message); // sends a message to the current actionSignalTarget(s)
  346. virtual bool RequestInfoFromChild(const char *childName, KeyValues *outputData);
  347. virtual void PostMessageToChild(const char *childName, KeyValues *messsage);
  348. virtual void PostMessage(Panel *target, KeyValues *message, float delaySeconds = 0.0f);
  349. virtual bool RequestInfo(KeyValues *outputData); // returns true if output is successfully written. You should always chain back to the base class if info request is not handled
  350. virtual bool SetInfo(KeyValues *inputData); // sets a specified value in the control - inverse of the above
  351. virtual void SetSilentMode( bool bSilent ); //change the panel's silent mode; if silent, the panel will not post any action signals
  352. // install a mouse handler
  353. virtual void InstallMouseHandler( Panel *pHandler ); // mouse events will be send to handler panel instead of this panel
  354. // drawing state
  355. virtual void SetEnabled(bool state);
  356. virtual bool IsEnabled();
  357. virtual bool IsPopup(); // has a parent, but is in it's own space
  358. virtual void GetClipRect(int &x0, int &y0, int &x1, int &y1);
  359. virtual void MoveToFront();
  360. // pin positions for auto-layout
  361. enum PinCorner_e
  362. {
  363. PIN_TOPLEFT = 0,
  364. PIN_TOPRIGHT,
  365. PIN_BOTTOMLEFT,
  366. PIN_BOTTOMRIGHT,
  367. PIN_NO,
  368. // For sibling pinning
  369. PIN_CENTER_TOP,
  370. PIN_CENTER_RIGHT,
  371. PIN_CENTER_BOTTOM,
  372. PIN_CENTER_LEFT,
  373. };
  374. // specifies the auto-resize directions for the panel
  375. enum AutoResize_e
  376. {
  377. AUTORESIZE_NO = 0,
  378. AUTORESIZE_RIGHT,
  379. AUTORESIZE_DOWN,
  380. AUTORESIZE_DOWNANDRIGHT,
  381. };
  382. // Sets the pin corner for non-resizing panels
  383. void SetPinCorner( PinCorner_e pinCorner, int nOffsetX, int nOffsetY );
  384. // Sets the pin corner + resize mode for resizing panels
  385. void SetAutoResize( PinCorner_e pinCorner, AutoResize_e resizeDir, int nPinOffsetX, int nPinOffsetY, int nUnpinnedCornerOffsetX, int nUnpinnedCornerOffsetY );
  386. AutoResize_e GetAutoResize();
  387. PinCorner_e GetPinCorner();
  388. // Gets the relative offset of the control from the pinned + non-pinned corner (for resizing)
  389. void GetPinOffset( int &dx, int &dy );
  390. void GetResizeOffset( int &dx, int &dy );
  391. void PinToSibling( const char *pszSibling, PinCorner_e pinOurCorner, PinCorner_e pinSibling );
  392. void UpdateSiblingPin( void );
  393. // colors
  394. virtual void SetBgColor(Color color);
  395. virtual void SetFgColor(Color color);
  396. virtual Color GetBgColor();
  397. virtual Color GetFgColor();
  398. virtual void SetCursor(HCursor cursor);
  399. virtual HCursor GetCursor();
  400. virtual void RequestFocus(int direction = 0);
  401. virtual bool HasFocus();
  402. virtual void InvalidateLayout(bool layoutNow = false, bool reloadScheme = false);
  403. virtual bool RequestFocusPrev(VPANEL panel = NULL);
  404. virtual bool RequestFocusNext(VPANEL panel = NULL);
  405. // tab positioning
  406. virtual void SetTabPosition(int position);
  407. virtual int GetTabPosition();
  408. // border
  409. virtual void SetBorder(IBorder *border);
  410. virtual IBorder *GetBorder();
  411. virtual void SetPaintBorderEnabled(bool state);
  412. virtual void SetPaintBackgroundEnabled(bool state);
  413. virtual void SetPaintEnabled(bool state);
  414. virtual void SetPostChildPaintEnabled(bool state);
  415. virtual void SetPaintBackgroundType(int type); // 0 for normal(opaque), 1 for single texture from Texture1, and 2 for rounded box w/ four corner textures
  416. virtual void GetInset(int &left, int &top, int &right, int &bottom);
  417. virtual void GetPaintSize(int &wide, int &tall);
  418. virtual void SetBuildGroup(BuildGroup *buildGroup);
  419. virtual bool IsBuildGroupEnabled();
  420. virtual bool IsCursorNone();
  421. virtual bool IsCursorOver(); // returns true if the cursor is currently over the panel
  422. virtual void MarkForDeletion(); // object will free it's memory next tick
  423. virtual bool IsLayoutInvalid(); // does this object require a perform layout?
  424. virtual Panel *HasHotkey(wchar_t key); // returns the panel that has this hotkey
  425. virtual bool IsOpaque();
  426. bool IsRightAligned(); // returns true if the settings are aligned to the right of the screen
  427. bool IsBottomAligned(); // returns true if the settings are aligned to the bottom of the screen
  428. bool IsPercentage(); // returns true if the settings are a percentage of screen size
  429. // scheme access functions
  430. virtual HScheme GetScheme();
  431. virtual void SetScheme(const char *tag);
  432. virtual void SetScheme(HScheme scheme);
  433. virtual Color GetSchemeColor(const char *keyName,IScheme *pScheme);
  434. virtual Color GetSchemeColor(const char *keyName, Color defaultColor,IScheme *pScheme);
  435. // called when scheme settings need to be applied; called the first time before the panel is painted
  436. virtual void ApplySchemeSettings(IScheme *pScheme);
  437. // interface to build settings
  438. // takes a group of settings and applies them to the control
  439. virtual void ApplySettings(KeyValues *inResourceData);
  440. virtual void OnUnserialized( CDmxElement *pElement );
  441. // records the settings into the resource data
  442. virtual void GetSettings(KeyValues *outResourceData);
  443. // gets a description of the resource for use in the UI
  444. // format: <type><whitespace | punctuation><keyname><whitespace| punctuation><type><whitespace | punctuation><keyname>...
  445. // unknown types as just displayed as strings in the UI (for future UI expansion)
  446. virtual const char *GetDescription();
  447. // returns the name of the module that this instance of panel was compiled into
  448. virtual const char *GetModuleName();
  449. // user configuration settings
  450. // this is used for any control details the user wants saved between sessions
  451. // eg. dialog positions, last directory opened, list column width
  452. virtual void ApplyUserConfigSettings(KeyValues *userConfig);
  453. // returns user config settings for this control
  454. virtual void GetUserConfigSettings(KeyValues *userConfig);
  455. // optimization, return true if this control has any user config settings
  456. virtual bool HasUserConfigSettings();
  457. // message handlers
  458. // override to get access to the message
  459. // override to get access to the message
  460. virtual void OnMessage(const KeyValues *params, VPANEL fromPanel); // called when panel receives message; must chain back
  461. MESSAGE_FUNC_CHARPTR( OnCommand, "Command", command ); // called when a panel receives a command
  462. MESSAGE_FUNC( OnMouseCaptureLost, "MouseCaptureLost" ); // called after the panel loses mouse capture
  463. MESSAGE_FUNC( OnSetFocus, "SetFocus" ); // called after the panel receives the keyboard focus
  464. MESSAGE_FUNC( OnKillFocus, "KillFocus" ); // called after the panel loses the keyboard focus
  465. MESSAGE_FUNC( OnDelete, "Delete" ); // called to delete the panel; Panel::OnDelete() does simply { delete this; }
  466. virtual void OnThink(); // called every frame before painting, but only if panel is visible
  467. virtual void OnChildAdded(VPANEL child); // called when a child has been added to this panel
  468. virtual void OnSizeChanged(int newWide, int newTall); // called after the size of a panel has been changed
  469. // called every frame if ivgui()->AddTickSignal() is called
  470. virtual void OnTick();
  471. // input messages
  472. MESSAGE_FUNC_INT_INT( OnCursorMoved, "OnCursorMoved", x, y );
  473. virtual void OnCursorEntered();
  474. virtual void OnCursorExited();
  475. virtual void OnMousePressed(MouseCode code);
  476. virtual void OnMouseDoublePressed(MouseCode code);
  477. virtual void OnMouseReleased(MouseCode code);
  478. virtual void OnMouseWheeled(int delta);
  479. // Trip pressing (e.g., select all text in a TextEntry) requires this to be enabled
  480. virtual void SetTriplePressAllowed( bool state );
  481. virtual bool IsTriplePressAllowed() const;
  482. virtual void OnMouseTriplePressed( MouseCode code );
  483. static char const *KeyCodeToString( KeyCode code );
  484. static wchar_t const *KeyCodeToDisplayString( KeyCode code );
  485. static wchar_t const *KeyCodeModifiersToDisplayString( KeyCode code, int modifiers ); // L"Ctrl+Alt+Shift+Backspace"
  486. static KeyCode StringToKeyCode( char const *str );
  487. #if defined( VGUI_USEKEYBINDINGMAPS )
  488. static KeyBindingContextHandle_t CreateKeyBindingsContext( char const *filename, char const *pathID = 0 );
  489. virtual void SetKeyBindingsContext( KeyBindingContextHandle_t handle );
  490. virtual KeyBindingContextHandle_t GetKeyBindingsContext() const;
  491. virtual bool IsValidKeyBindingsContext() const;
  492. static int GetPanelsWithKeyBindingsCount( KeyBindingContextHandle_t handle );
  493. static Panel *GetPanelWithKeyBindings( KeyBindingContextHandle_t handle, int index );
  494. static void RevertKeyBindings( KeyBindingContextHandle_t handle );
  495. static void ReloadKeyBindings( KeyBindingContextHandle_t handle );
  496. static void SaveKeyBindings( KeyBindingContextHandle_t handle );
  497. static void SaveKeyBindingsToFile( KeyBindingContextHandle_t handle, char const *filename, char const *pathID = 0 );
  498. static void LoadKeyBindings( KeyBindingContextHandle_t handle );
  499. static void LoadKeyBindingsForOnePanel( KeyBindingContextHandle_t handle, Panel *panelOfInterest );
  500. // OnKeyCodeTyped hooks into here for action
  501. virtual bool IsKeyRebound( KeyCode code, int modifiers );
  502. // If a panel implements this and returns true, then the IsKeyRebound check will fail and OnKeyCodeTyped messages will pass through..
  503. // sort of like setting the SetAllowKeyBindingChainToParent flag to false for specific keys
  504. virtual bool IsKeyOverridden( KeyCode code, int modifiers );
  505. virtual void AddKeyBinding( char const *bindingName, int keycode, int modifiers );
  506. KeyBindingMap_t *LookupBinding( char const *bindingName );
  507. KeyBindingMap_t *LookupBindingByKeyCode( KeyCode code, int modifiers );
  508. void LookupBoundKeys( char const *bindingName, CUtlVector< BoundKey_t * >& list );
  509. BoundKey_t *LookupDefaultKey( char const *bindingName );
  510. PanelKeyBindingMap *LookupMapForBinding( char const *bindingName );
  511. // Returns the number of keybindings
  512. int GetKeyMappingCount( );
  513. void RevertKeyBindingsToDefault();
  514. void RemoveAllKeyBindings();
  515. void ReloadKeyBindings();
  516. virtual void EditKeyBindings();
  517. // calls RevertKeyBindingsToDefault() and then LoadKeyBindingsForOnePanel( GetKeyBindingsContext(), this );
  518. void SaveKeyBindingsToBuffer( int level, CUtlBuffer& buf );
  519. bool ParseKeyBindings( KeyValues *kv );
  520. virtual char const *GetKeyBindingsFile() const;
  521. virtual char const *GetKeyBindingsFilePathID() const;
  522. // Set this to false to disallow IsKeyRebound chaining to GetParent() Panels...
  523. void SetAllowKeyBindingChainToParent( bool state );
  524. bool IsKeyBindingChainToParentAllowed() const;
  525. #endif // VGUI_USEKEYBINDINGMAPS
  526. // base implementation forwards Key messages to the Panel's parent
  527. // - override to 'swallow' the input
  528. virtual void OnKeyCodePressed(KeyCode code);
  529. virtual void OnKeyCodeTyped(KeyCode code);
  530. virtual void OnKeyTyped(wchar_t unichar);
  531. virtual void OnKeyCodeReleased(KeyCode code);
  532. virtual void OnKeyFocusTicked(); // every window gets key ticked events
  533. // forwards mouse messages to the panel's parent
  534. MESSAGE_FUNC( OnMouseFocusTicked, "OnMouseFocusTicked" );
  535. // message handlers that don't go through the message pump
  536. virtual void PaintBackground();
  537. virtual void Paint();
  538. virtual void PaintBorder();
  539. virtual void PaintBuildOverlay(); // the extra drawing for when in build mode
  540. virtual void PostChildPaint();
  541. virtual void PerformLayout();
  542. // this enables message mapping for this class - requires matching IMPLEMENT_PANELDESC() in the .cpp file
  543. DECLARE_PANELMAP();
  544. virtual VPANEL GetCurrentKeyFocus();
  545. // returns a pointer to the tooltip object associated with the panel
  546. // creates a new one if none yet exists
  547. BaseTooltip *GetTooltip();
  548. void SetTooltip( BaseTooltip *pToolTip, const char *pszText );
  549. // proportional mode settings
  550. virtual bool IsProportional() { return _flags.IsFlagSet( IS_PROPORTIONAL ); }
  551. virtual void SetProportional(bool state);
  552. // input interest
  553. virtual void SetMouseInputEnabled( bool state );
  554. virtual void SetKeyBoardInputEnabled( bool state );
  555. virtual bool IsMouseInputEnabled();
  556. virtual bool IsKeyBoardInputEnabled();
  557. // allows you to disable for this panel but not children
  558. void DisableMouseInputForThisPanel( bool bDisable );
  559. bool IsMouseInputDisabledForThisPanel() const;
  560. virtual void DrawTexturedBox( int x, int y, int wide, int tall, Color color, float normalizedAlpha );
  561. virtual void DrawBox(int x, int y, int wide, int tall, Color color, float normalizedAlpha, bool hollow = false );
  562. virtual void DrawBoxFade(int x, int y, int wide, int tall, Color color, float normalizedAlpha, unsigned int alpha0, unsigned int alpha1, bool bHorizontal, bool hollow = false );
  563. virtual void DrawHollowBox(int x, int y, int wide, int tall, Color color, float normalizedAlpha );
  564. //=============================================================================
  565. // HPE_BEGIN:
  566. //=============================================================================
  567. // [menglish] Draws a hollow box similar to the already existing draw hollow box function, but takes the indents as params
  568. virtual void DrawHollowBox( int x, int y, int wide, int tall, Color color, float normalizedAlpha, int cornerWide, int cornerTall );
  569. // [tj] Simple getters and setters to decide which corners to draw rounded
  570. unsigned char GetRoundedCorners() { return m_roundedCorners; }
  571. void SetRoundedCorners (unsigned char cornerFlags) { m_roundedCorners = cornerFlags; }
  572. bool ShouldDrawTopLeftCornerRounded() { return 0 != ( m_roundedCorners & PANEL_ROUND_CORNER_TOP_LEFT ); }
  573. bool ShouldDrawTopRightCornerRounded() { return 0 != ( m_roundedCorners & PANEL_ROUND_CORNER_TOP_RIGHT ); }
  574. bool ShouldDrawBottomLeftCornerRounded() { return 0 != ( m_roundedCorners & PANEL_ROUND_CORNER_BOTTOM_LEFT ); }
  575. bool ShouldDrawBottomRightCornerRounded() { return 0 != ( m_roundedCorners & PANEL_ROUND_CORNER_BOTTOM_RIGHT ); }
  576. //=============================================================================
  577. // HPE_END
  578. //=============================================================================
  579. // Drag Drop Public interface
  580. virtual void SetDragEnabled( bool enabled );
  581. virtual bool IsDragEnabled() const;
  582. virtual void SetShowDragHelper( bool enabled );
  583. // Called if drag drop is started but not dropped on top of droppable panel...
  584. virtual void OnDragFailed( CUtlVector< KeyValues * >& msglist );
  585. // Use this to prevent chaining up from a parent which can mess with mouse functionality if you don't want to chain up from a child panel to the best
  586. // draggable parent.
  587. virtual void SetBlockDragChaining( bool block );
  588. virtual bool IsBlockingDragChaining() const;
  589. virtual int GetDragStartTolerance() const;
  590. virtual void SetDragSTartTolerance( int nTolerance );
  591. // If hover context time is non-zero, then after the drop cursor is hovering over the panel for that amount of time
  592. // the Show hover context menu function will be invoked
  593. virtual void SetDropEnabled( bool enabled, float m_flHoverContextTime = 0.0f );
  594. virtual bool IsDropEnabled() const;
  595. // Called if m_flHoverContextTime was non-zero, allows droppee to preview the drop data and show an appropriate menu
  596. // Return false if not using context menu
  597. virtual bool GetDropContextMenu( Menu *menu, CUtlVector< KeyValues * >& msglist );
  598. virtual void OnDropContextHoverShow( CUtlVector< KeyValues * >& msglist );
  599. virtual void OnDropContextHoverHide( CUtlVector< KeyValues * >& msglist );
  600. #if defined( VGUI_USEDRAGDROP )
  601. virtual DragDrop_t *GetDragDropInfo();
  602. #endif
  603. // For handling multiple selections...
  604. virtual void OnGetAdditionalDragPanels( CUtlVector< Panel * >& dragabbles );
  605. virtual void OnCreateDragData( KeyValues *msg );
  606. // Called to see if a drop enabled panel can accept the specified data blob
  607. virtual bool IsDroppable( CUtlVector< KeyValues * >& msglist );
  608. // Mouse is on draggable panel and has started moving, but is not over a droppable panel yet
  609. virtual void OnDraggablePanelPaint();
  610. // Mouse is now over a droppable panel
  611. virtual void OnDroppablePanelPaint( CUtlVector< KeyValues * >& msglist, CUtlVector< Panel * >& dragPanels );
  612. virtual void OnPanelDropped( CUtlVector< KeyValues * >& msglist );
  613. // called on droptarget when draggable panel entered/exited droptarget
  614. virtual void OnPanelEnteredDroppablePanel( CUtlVector< KeyValues * >& msglist );
  615. virtual void OnPanelExitedDroppablePanel ( CUtlVector< KeyValues * >& msglist );
  616. // Chains up to any parent marked DropEnabled
  617. virtual Panel *GetDropTarget( CUtlVector< KeyValues * >& msglist );
  618. // Chains up to first parent marked DragEnabled
  619. virtual Panel *GetDragPanel();
  620. virtual bool IsBeingDragged();
  621. virtual HCursor GetDropCursor( CUtlVector< KeyValues * >& msglist );
  622. virtual HCursor GetDragFailCursor( CUtlVector< KeyValues * >& msglist ) { return dc_no; }
  623. Color GetDropFrameColor();
  624. Color GetDragFrameColor();
  625. // Can override to require custom behavior to start the drag state
  626. virtual bool CanStartDragging( int startx, int starty, int mx, int my );
  627. // Draws a filled rect of specified bounds, but omits the bounds of the skip panel from those bounds
  628. virtual void FillRectSkippingPanel( const Color clr, int x, int y, int w, int h, Panel *skipPanel );
  629. virtual int GetPaintBackgroundType();
  630. virtual void GetCornerTextureSize( int& w, int& h );
  631. bool IsChildOfModalSubTree();
  632. bool IsChildOfSurfaceModalPanel();
  633. bool ShouldHandleInputMessage();
  634. virtual void SetSkipChildDuringPainting( Panel *child );
  635. // If this is set, then the drag drop won't occur until the mouse leaves the drag panels current rectangle
  636. void SetStartDragWhenMouseExitsPanel( bool state );
  637. bool IsStartDragWhenMouseExitsPanel() const;
  638. // Forces context ID for this panel and all children below it
  639. void SetMessageContextId_R( int nContextID );
  640. void PostMessageToAllSiblings( KeyValues *msg, float delaySeconds = 0.0f );
  641. template< class S >
  642. void PostMessageToAllSiblingsOfType( KeyValues *msg, float delaySeconds = 0.0f );
  643. void SetConsoleStylePanel( bool bConsoleStyle );
  644. bool IsConsoleStylePanel() const;
  645. // For 360: support directional navigation between UI controls via dpad
  646. enum NAV_DIRECTION { ND_UP, ND_DOWN, ND_LEFT, ND_RIGHT, ND_BACK, ND_NONE };
  647. virtual Panel* NavigateUp();
  648. virtual Panel* NavigateDown();
  649. virtual Panel* NavigateLeft();
  650. virtual Panel* NavigateRight();
  651. virtual void NavigateTo();
  652. virtual void NavigateFrom();
  653. virtual void NavigateToChild( Panel *pNavigateTo ); //mouse support
  654. Panel* SetNavUp( Panel* navUp );
  655. Panel* SetNavDown( Panel* navDown );
  656. Panel* SetNavLeft( Panel* navLeft );
  657. Panel* SetNavRight( Panel* navRight );
  658. NAV_DIRECTION GetLastNavDirection();
  659. MESSAGE_FUNC_CHARPTR( OnNavigateTo, "OnNavigateTo", panelName );
  660. MESSAGE_FUNC_CHARPTR( OnNavigateFrom, "OnNavigateFrom", panelName );
  661. // Drag Drop protected/internal interface
  662. protected:
  663. virtual void OnStartDragging();
  664. virtual void OnContinueDragging();
  665. virtual void OnFinishDragging( bool mousereleased, MouseCode code, bool aborted = false );
  666. virtual void DragDropStartDragging();
  667. virtual void GetDragData( CUtlVector< KeyValues * >& list );
  668. virtual void CreateDragData();
  669. virtual void PaintTraverse(bool Repaint, bool allowForce = true);
  670. protected:
  671. MESSAGE_FUNC_ENUM_ENUM( OnRequestFocus, "OnRequestFocus", VPANEL, subFocus, VPANEL, defaultPanel);
  672. MESSAGE_FUNC_INT_INT( OnScreenSizeChanged, "OnScreenSizeChanged", oldwide, oldtall );
  673. virtual void *QueryInterface(EInterfaceID id);
  674. void AddToOverridableColors( Color *pColor, char const *scriptname )
  675. {
  676. int iIdx = m_OverridableColorEntries.AddToTail();
  677. m_OverridableColorEntries[iIdx].m_pszScriptName = scriptname;
  678. m_OverridableColorEntries[iIdx].m_pColor = pColor;
  679. m_OverridableColorEntries[iIdx].m_bOverridden = false;
  680. }
  681. void ApplyOverridableColors( IScheme *pScheme );
  682. void SetOverridableColor( Color *pColor, const Color &newColor );
  683. protected:
  684. void SetNavUp( const char* controlName );
  685. void SetNavDown( const char* controlName );
  686. void SetNavLeft( const char* controlName );
  687. void SetNavRight( const char* controlName );
  688. public:
  689. /*
  690. Will recursively look for the next visible panel in the navigation chain, parameters are for internal use.
  691. It will stop looking if first == nextpanel (to prevent infinite looping).
  692. */
  693. Panel* GetNavUp( Panel *first = NULL );
  694. Panel* GetNavDown( Panel *first = NULL );
  695. Panel* GetNavLeft( Panel *first = NULL );
  696. Panel* GetNavRight( Panel *first = NULL );
  697. // if set, Panel gets PerformLayout called after the camera and the renderer's m_matrixWorldToScreen has been setup, so panels can be correctly attached to entities in the world
  698. inline void SetWorldPositionCurrentFrame( bool bWorldPositionCurrentFrame ) { m_bWorldPositionCurrentFrame = bWorldPositionCurrentFrame; }
  699. inline bool GetWorldPositionCurrentFrame() { return m_bWorldPositionCurrentFrame; }
  700. protected:
  701. //this will return m_NavDown and will not look for the next visible panel
  702. Panel* GetNavUpPanel();
  703. Panel* GetNavDownPanel();
  704. Panel* GetNavLeftPanel();
  705. Panel* GetNavRightPanel();
  706. bool m_PassUnhandledInput;
  707. NAV_DIRECTION m_LastNavDirection;
  708. void InternalInitDefaultValues( PanelAnimationMap *map );
  709. private:
  710. enum BuildModeFlags_t
  711. {
  712. BUILDMODE_EDITABLE = 0x01,
  713. BUILDMODE_DELETABLE = 0x02,
  714. BUILDMODE_SAVE_XPOS_RIGHTALIGNED = 0x04,
  715. BUILDMODE_SAVE_XPOS_CENTERALIGNED = 0x08,
  716. BUILDMODE_SAVE_YPOS_BOTTOMALIGNED = 0x10,
  717. BUILDMODE_SAVE_YPOS_CENTERALIGNED = 0x20,
  718. BUILDMODE_SAVE_WIDE_FULL = 0x40,
  719. BUILDMODE_SAVE_TALL_FULL = 0x80,
  720. BUILDMODE_SAVE_PROPORTIONAL_TO_PARENT = 0x100,
  721. BUILDMODE_SAVE_PERCENTAGE = 0x200,
  722. };
  723. enum PanelFlags_t
  724. {
  725. MARKED_FOR_DELETION = 0x0001,
  726. NEEDS_REPAINT = 0x0002,
  727. PAINT_BORDER_ENABLED = 0x0004,
  728. PAINT_BACKGROUND_ENABLED = 0x0008,
  729. PAINT_ENABLED = 0x0010,
  730. POST_CHILD_PAINT_ENABLED = 0x0020,
  731. AUTODELETE_ENABLED = 0x0040,
  732. NEEDS_LAYOUT = 0x0080,
  733. NEEDS_SCHEME_UPDATE = 0x0100,
  734. NEEDS_DEFAULT_SETTINGS_APPLIED = 0x0200,
  735. #if defined( VGUI_USEKEYBINDINGMAPS )
  736. ALLOW_CHAIN_KEYBINDING_TO_PARENT = 0x0400,
  737. #endif
  738. IN_PERFORM_LAYOUT = 0x0800,
  739. IS_PROPORTIONAL = 0x1000,
  740. TRIPLE_PRESS_ALLOWED = 0x2000,
  741. DRAG_REQUIRES_PANEL_EXIT = 0x4000,
  742. IS_MOUSE_DISABLED_FOR_THIS_PANEL_ONLY = 0x8000,
  743. ALL_FLAGS = 0xFFFF,
  744. };
  745. // used to get the Panel * for users with only IClientPanel
  746. virtual Panel *GetPanel() { return this; }
  747. // private methods
  748. void Think();
  749. void PerformApplySchemeSettings();
  750. void InternalPerformLayout();
  751. void InternalSetCursor();
  752. MESSAGE_FUNC_INT_INT( InternalCursorMoved, "CursorMoved", xpos, ypos );
  753. MESSAGE_FUNC( InternalCursorEntered, "CursorEntered" );
  754. MESSAGE_FUNC( InternalCursorExited, "CursorExited" );
  755. MESSAGE_FUNC_INT( InternalMousePressed, "MousePressed", code );
  756. MESSAGE_FUNC_INT( InternalMouseDoublePressed, "MouseDoublePressed", code );
  757. // Triple presses are synthesized
  758. MESSAGE_FUNC_INT( InternalMouseTriplePressed, "MouseTriplePressed", code );
  759. MESSAGE_FUNC_INT( InternalMouseReleased, "MouseReleased", code );
  760. MESSAGE_FUNC_INT( InternalMouseWheeled, "MouseWheeled", delta );
  761. MESSAGE_FUNC_INT( InternalKeyCodePressed, "KeyCodePressed", code );
  762. MESSAGE_FUNC_INT( InternalKeyCodeTyped, "KeyCodeTyped", code );
  763. MESSAGE_FUNC_INT( InternalKeyTyped, "KeyTyped", unichar );
  764. MESSAGE_FUNC_INT( InternalKeyCodeReleased, "KeyCodeReleased", code );
  765. MESSAGE_FUNC( InternalKeyFocusTicked, "KeyFocusTicked" );
  766. MESSAGE_FUNC( InternalMouseFocusTicked, "MouseFocusTicked" );
  767. MESSAGE_FUNC( InternalInvalidateLayout, "Invalidate" );
  768. MESSAGE_FUNC( InternalMove, "Move" );
  769. virtual void InternalFocusChanged(bool lost); // called when the focus gets changed
  770. void Init( int x, int y, int wide, int tall );
  771. void PreparePanelMap( PanelMap_t *panelMap );
  772. bool InternalRequestInfo( PanelAnimationMap *map, KeyValues *outputData );
  773. bool InternalSetInfo( PanelAnimationMap *map, KeyValues *inputData );
  774. PanelAnimationMapEntry *FindPanelAnimationEntry( char const *scriptname, PanelAnimationMap *map );
  775. // Recursively invoke settings for PanelAnimationVars
  776. void InternalApplySettings( PanelAnimationMap *map, KeyValues *inResourceData);
  777. // Purpose: Loads panel details related to autoresize from the resource info
  778. void ApplyAutoResizeSettings(KeyValues *inResourceData);
  779. void FindDropTargetPanel_R( CUtlVector< VPANEL >& panelList, int x, int y, VPANEL check );
  780. Panel *FindDropTargetPanel();
  781. int GetProportionalScaledValue( int rootTall, int normalizedValue );
  782. #if defined( VGUI_USEDRAGDROP )
  783. DragDrop_t *m_pDragDrop;
  784. Color m_clrDragFrame;
  785. Color m_clrDropFrame;
  786. #endif
  787. BaseTooltip *m_pTooltips;
  788. bool m_bToolTipOverridden;
  789. PHandle m_SkipChild;
  790. long m_lLastDoublePressTime;
  791. HFont m_infoFont; // this is used exclusively by drag drop panels
  792. #if defined( VGUI_USEKEYBINDINGMAPS )
  793. KeyBindingContextHandle_t m_hKeyBindingsContext;
  794. #endif
  795. // data
  796. VPANEL _vpanel; // handle to a vgui panel
  797. CUtlString _panelName; // string name of the panel - only unique within the current context
  798. IBorder *_border;
  799. CUtlFlags< unsigned short > _flags; // see PanelFlags_t
  800. Dar<HPanel> _actionSignalTargetDar; // the panel to direct notify messages to ("Command", "TextChanged", etc.)
  801. CUtlVector<OverridableColorEntry> m_OverridableColorEntries;
  802. Color _fgColor; // foreground color
  803. Color _bgColor; // background color
  804. HBuildGroup _buildGroup;
  805. short m_nPinDeltaX; // Relative position of the pinned corner to the edge
  806. short m_nPinDeltaY;
  807. short m_nResizeDeltaX; // Relative position of the non-pinned corner to the edge
  808. short m_nResizeDeltaY;
  809. HCursor _cursor;
  810. unsigned short _buildModeFlags; // flags that control how the build mode dialog handles this panel
  811. byte _pinCorner : 4; // the corner of the dialog this panel is pinned to
  812. byte _autoResizeDirection : 4; // the directions in which the panel will auto-resize to
  813. GCC_DIAG_PUSH_OFF(overflow)
  814. DECLARE_DMXELEMENT_BITFIELD( _pinCorner, byte, Panel )
  815. DECLARE_DMXELEMENT_BITFIELD( _autoResizeDirection, byte, Panel )
  816. GCC_DIAG_POP()
  817. unsigned char _tabPosition; // the panel's place in the tab ordering
  818. HScheme m_iScheme; // handle to the scheme to use
  819. bool m_bIsDMXSerialized : 1; // Is this a DMX panel?
  820. bool m_bUseSchemeColors : 1; // Should we use colors from the scheme?
  821. bool m_bIsSilent : 1; // should this panel PostActionSignals?
  822. bool m_bIsConsoleStylePanel : 1;
  823. DECLARE_DMXELEMENT_BITFIELD( m_bUseSchemeColors, bool, Panel )
  824. DECLARE_DMXELEMENT_BITFIELD( m_bIsSilent, bool, Panel )
  825. // Sibling pinning
  826. char *_pinToSibling; // string name of the sibling panel we're pinned to
  827. byte _pinToSiblingCorner; // the corner of the sibling panel we're pinned to
  828. byte _pinCornerToSibling; // the corner of our panel that we're pinning to our sibling
  829. PHandle m_pinSibling;
  830. char *_tooltipText; // Tool tip text for panels that share tooltip panels with other panels
  831. PHandle m_hMouseEventHandler;
  832. bool m_bWorldPositionCurrentFrame; // if set, Panel gets PerformLayout called after the camera and the renderer's m_matrixWorldToScreen has been setup, so panels can be correctly attached to entities in the world
  833. CUtlSymbol m_sBorderName;
  834. protected:
  835. CUtlString m_sNavUpName;
  836. PHandle m_NavUp;
  837. CUtlString m_sNavDownName;
  838. PHandle m_NavDown;
  839. CUtlString m_sNavLeftName;
  840. PHandle m_NavLeft;
  841. CUtlString m_sNavRightName;
  842. PHandle m_NavRight;
  843. protected:
  844. static int s_NavLock;
  845. private:
  846. CPanelAnimationVar( float, m_flAlpha, "alpha", "255" );
  847. // 1 == Textured (TextureId1 only)
  848. // 2 == Rounded Corner Box
  849. CPanelAnimationVar( int, m_nPaintBackgroundType, "PaintBackgroundType", "0" );
  850. CPanelAnimationVarAliasType( int, m_nBgTextureId1, "Texture1", "vgui/hud/800corner1", "textureid" );
  851. CPanelAnimationVarAliasType( int, m_nBgTextureId2, "Texture2", "vgui/hud/800corner2", "textureid" );
  852. CPanelAnimationVarAliasType( int, m_nBgTextureId3, "Texture3", "vgui/hud/800corner3", "textureid" );
  853. CPanelAnimationVarAliasType( int, m_nBgTextureId4, "Texture4", "vgui/hud/800corner4", "textureid" );
  854. //=============================================================================
  855. // HPE_BEGIN:
  856. // [tj] A bitset of flags to determine which corners should be rounded
  857. //=============================================================================
  858. unsigned char m_roundedCorners;
  859. //=============================================================================
  860. // HPE_END
  861. //=============================================================================
  862. friend class BuildGroup;
  863. friend class BuildModeDialog;
  864. friend class PHandle;
  865. // obselete, remove soon
  866. void OnOldMessage(KeyValues *params, VPANEL ifromPanel);
  867. public:
  868. virtual void GetSizerMinimumSize(int &wide, int &tall);
  869. virtual void GetSizerClientArea(int &x, int &y, int &wide, int &tall);
  870. CSizerBase *GetSizer();
  871. void SetSizer( CSizerBase* pSizer );
  872. protected:
  873. CSizerBase *m_pSizer;
  874. };
  875. inline void Panel::DisableMouseInputForThisPanel( bool bDisable )
  876. {
  877. _flags.SetFlag( IS_MOUSE_DISABLED_FOR_THIS_PANEL_ONLY, bDisable );
  878. }
  879. inline bool Panel::IsMouseInputDisabledForThisPanel() const
  880. {
  881. return _flags.IsFlagSet( IS_MOUSE_DISABLED_FOR_THIS_PANEL_ONLY );
  882. }
  883. template< class S >
  884. inline void Panel::PostMessageToAllSiblingsOfType( KeyValues *msg, float delaySeconds /*= 0.0f*/ )
  885. {
  886. Panel *parent = GetParent();
  887. if ( parent )
  888. {
  889. int nChildCount = parent->GetChildCount();
  890. for ( int i = 0; i < nChildCount; ++i )
  891. {
  892. Panel *sibling = parent->GetChild( i );
  893. if ( sibling == this )
  894. continue;
  895. if ( dynamic_cast< S * >( sibling ) )
  896. {
  897. PostMessage( sibling->GetVPanel(), msg->MakeCopy(), delaySeconds );
  898. }
  899. }
  900. }
  901. msg->deleteThis();
  902. }
  903. } // namespace vgui
  904. #endif // PANEL_H