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.

260 lines
8.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef VGUI_FRAME_H
  8. #define VGUI_FRAME_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <vgui/VGUI.h>
  13. #include <vgui/Dar.h>
  14. #include <vgui_controls/Panel.h>
  15. #include <vgui_controls/EditablePanel.h>
  16. #include <vgui_controls/FocusNavGroup.h>
  17. namespace vgui
  18. {
  19. class FrameButton;
  20. class FrameSystemButton;
  21. //-----------------------------------------------------------------------------
  22. // Purpose: Windowed frame
  23. //-----------------------------------------------------------------------------
  24. class Frame : public EditablePanel
  25. {
  26. DECLARE_CLASS_SIMPLE( Frame, EditablePanel );
  27. public:
  28. Frame(Panel *parent, const char *panelName, bool showTaskbarIcon = true, bool bPopup = true );
  29. virtual ~Frame();
  30. // Set the text in the title bar. Set surfaceTitle=true if you want this to be the taskbar text as well.
  31. virtual void SetTitle(const char *title, bool surfaceTitle);
  32. virtual void SetTitle(const wchar_t *title, bool surfaceTitle);
  33. // Bring the frame to the front and requests focus, ensures it's not minimized
  34. virtual void Activate();
  35. // activates the dialog; if dialog is not currently visible it starts it minimized and flashing in the taskbar
  36. virtual void ActivateMinimized();
  37. // closes the dialog
  38. MESSAGE_FUNC( Close, "Close" );
  39. MESSAGE_FUNC( CloseModal, "CloseModal" );
  40. // sets the dialog to delete self on close
  41. virtual void SetDeleteSelfOnClose( bool state );
  42. // Move the dialog to the center of the screen
  43. virtual void MoveToCenterOfScreen();
  44. // Set the movability of the panel
  45. virtual void SetMoveable(bool state);
  46. // Check the movability of the panel
  47. virtual bool IsMoveable();
  48. // Set the resizability of the panel
  49. virtual void SetSizeable(bool state);
  50. // Check the resizability of the panel
  51. virtual bool IsSizeable();
  52. // Toggle visibility of the system menu button
  53. virtual void SetMenuButtonVisible(bool state);
  54. void SetMenuButtonResponsive(bool state);
  55. // Toggle visibility of the minimize button
  56. virtual void SetMinimizeButtonVisible(bool state);
  57. // Toggle visibility of the maximize button
  58. virtual void SetMaximizeButtonVisible(bool state);
  59. // Toggles visibility of the minimize-to-systray icon (defaults to false)
  60. virtual void SetMinimizeToSysTrayButtonVisible(bool state);
  61. // Toggle visibility of the close button
  62. virtual void SetCloseButtonVisible(bool state);
  63. // returns true if the dialog is currently minimized
  64. virtual bool IsMinimized();
  65. // Flash the window system tray button until the frame gets focus
  66. virtual void FlashWindow();
  67. // Stops any window flashing
  68. virtual void FlashWindowStop();
  69. // command handling
  70. virtual void OnCommand(const char *command);
  71. // Get the system menu
  72. virtual Menu *GetSysMenu();
  73. // Set the system menu
  74. virtual void SetSysMenu(Menu *menu);
  75. // Set the system menu images
  76. void SetImages( const char *pEnabledImage, const char *pDisabledImage = NULL );
  77. // set whether the title bar should be rendered
  78. virtual void SetTitleBarVisible( bool state );
  79. // When moving via caption, don't let any part of window go outside parent's bounds
  80. virtual void SetClipToParent( bool state );
  81. virtual bool GetClipToParent() const;
  82. // Set to true to make the caption height small
  83. virtual void SetSmallCaption( bool state );
  84. virtual bool IsSmallCaption() const;
  85. virtual int GetDraggerSize();
  86. virtual int GetCornerSize();
  87. virtual int GetBottomRightSize();
  88. virtual int GetCaptionHeight();
  89. /* CUSTOM MESSAGE HANDLING
  90. "SetTitle"
  91. input: "text" - string to set the title to be
  92. */
  93. // Load the control settings
  94. virtual void LoadControlSettings( const char *dialogResourceName, const char *pathID = NULL, KeyValues *pPreloadedKeyValues = NULL, KeyValues *pConditions = NULL );
  95. void SetChainKeysToParent( bool state );
  96. bool CanChainKeysToParent() const;
  97. // Shows the dialog in a modal fashion
  98. virtual void DoModal();
  99. void PlaceUnderCursor( );
  100. // Disables the fade-in/out-effect even if configured in the scheme settings
  101. void DisableFadeEffect( void );
  102. // Temporarily enables or disables the fade effect rather than zeroing the fade times as done in DisableFadeEffect
  103. void SetFadeEffectDisableOverride( bool disabled );
  104. protected:
  105. // Respond to mouse presses
  106. virtual void OnMousePressed(MouseCode code);
  107. // Respond to Key typing
  108. virtual void OnKeyCodeTyped(KeyCode code);
  109. virtual void OnKeyTyped(wchar_t unichar);
  110. // Respond to Key releases
  111. virtual void OnKeyCodeReleased(KeyCode code);
  112. // Respond to Key focus ticks
  113. virtual void OnKeyFocusTicked();
  114. virtual void ApplySchemeSettings(IScheme *pScheme);
  115. // Recalculate the position of all items
  116. virtual void PerformLayout();
  117. // Respond when a close message is recieved. Can be called directly to close a frame.
  118. virtual void OnClose();
  119. // Respond to a window finishing its closure. i.e. when a fading window has fully finished its fadeout.
  120. virtual void OnFinishedClose();
  121. // Minimize the window on the taskbar.
  122. MESSAGE_FUNC( OnMinimize, "Minimize" );
  123. // Called when minimize-to-systray button is pressed (does nothing by default)
  124. virtual void OnMinimizeToSysTray();
  125. // the frame close button was pressed
  126. MESSAGE_FUNC( OnCloseFrameButtonPressed, "CloseFrameButtonPressed" );
  127. // Add the child to the focus nav group
  128. virtual void OnChildAdded(VPANEL child);
  129. // settings
  130. virtual void ApplySettings(KeyValues *inResourceData);
  131. // records the settings into the resource data
  132. virtual void GetSettings(KeyValues *outResourceData);
  133. virtual const char *GetDescription( void );
  134. // gets the default position and size on the screen to appear the first time (defaults to centered)
  135. virtual bool GetDefaultScreenPosition(int &x, int &y, int &wide, int &tall);
  136. // painting
  137. virtual void PaintBackground();
  138. // per-frame thinking, used for transition effects
  139. virtual void OnThink();
  140. // screen size
  141. virtual void OnScreenSizeChanged(int iOldWide, int iOldTall);
  142. // Get the size of the panel inside the frame edges.
  143. virtual void GetClientArea(int &x, int &y, int &wide, int &tall);
  144. // user configuration settings
  145. // this is used for any control details the user wants saved between sessions
  146. // eg. dialog positions, last directory opened, list column width
  147. virtual void ApplyUserConfigSettings(KeyValues *userConfig);
  148. // returns user config settings for this control
  149. virtual void GetUserConfigSettings(KeyValues *userConfig);
  150. // optimization, return true if this control has any user config settings
  151. virtual bool HasUserConfigSettings();
  152. private:
  153. MESSAGE_FUNC_CHARPTR( InternalSetTitle, "SetTitle", text );
  154. MESSAGE_FUNC( InternalFlashWindow, "FlashWindow" );
  155. MESSAGE_FUNC_PARAMS( OnDialogVariablesChanged, "DialogVariables", dialogVariables );
  156. void SetupResizeCursors();
  157. void LayoutProportional( FrameButton *bt);
  158. void FinishClose();
  159. void OnFrameFocusChanged(bool bHasFocus);
  160. Color _titleBarBgColor;
  161. Color _titleBarDisabledBgColor;
  162. Color _titleBarFgColor;
  163. Color _titleBarDisabledFgColor;
  164. Color m_InFocusBgColor;
  165. Color m_OutOfFocusBgColor;
  166. TextImage *_title;
  167. #if !defined( _X360 )
  168. Panel *_topGrip;
  169. Panel *_bottomGrip;
  170. Panel *_leftGrip;
  171. Panel *_rightGrip;
  172. Panel *_topLeftGrip;
  173. Panel *_topRightGrip;
  174. Panel *_bottomLeftGrip;
  175. Panel *_bottomRightGrip;
  176. Panel *_captionGrip;
  177. FrameButton *_minimizeButton;
  178. FrameButton *_maximizeButton;
  179. FrameButton *_minimizeToSysTrayButton;
  180. FrameButton *_closeButton;
  181. FrameSystemButton *_menuButton;
  182. Menu *_sysMenu;
  183. #endif
  184. float m_flTransitionEffectTime;
  185. float m_flFocusTransitionEffectTime;
  186. int m_iClientInsetX;
  187. int m_iClientInsetY;
  188. int m_iTitleTextInsetX;
  189. int m_nGripperWidth;
  190. VPANEL m_hPreviousModal;
  191. HFont m_hCustomTitleFont;
  192. bool _sizeable : 1;
  193. bool _moveable : 1;
  194. bool m_bHasFocus : 1;
  195. bool _flashWindow : 1;
  196. bool _nextFlashState : 1;
  197. bool _drawTitleBar : 1;
  198. bool m_bPreviouslyVisible : 1;
  199. bool m_bFadingOut : 1;
  200. bool m_bDeleteSelfOnClose : 1;
  201. bool m_bDisableFadeEffect : 1;
  202. bool m_bClipToParent : 1;
  203. bool m_bSmallCaption : 1;
  204. bool m_bChainKeysToParent : 1;
  205. bool m_bPrimed : 1;
  206. bool m_iClientInsetXOverridden : 1;
  207. CPanelAnimationVarAliasType( int, m_iTitleTextInsetXOverride, "titletextinsetX", "0", "proportional_int" );
  208. CPanelAnimationVar( int, m_iTitleTextInsetYOverride, "titletextinsetY", "0" );
  209. };
  210. } // namespace vgui
  211. #endif // VGUI_FRAME_H