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.

171 lines
5.0 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef URLBUTTON_H
  8. #define URLBUTTON_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <vgui/VGUI.h>
  13. #include <vgui/Dar.h>
  14. #include <Color.h>
  15. #include <vgui_controls/Label.h>
  16. #include "vgui/mousecode.h"
  17. namespace vgui
  18. {
  19. //-----------------------------------------------------------------------------
  20. // Purpose: A control that looks like a hyperlink, but behaves like a button.
  21. //-----------------------------------------------------------------------------
  22. class URLButton : public Label
  23. {
  24. DECLARE_CLASS_SIMPLE( URLButton, Label );
  25. public:
  26. // You can optionally pass in the panel to send the click message to and the name of the command to send to that panel.
  27. URLButton(Panel *parent, const char *panelName, const char *text, Panel *pActionSignalTarget=NULL, const char *pCmd=NULL);
  28. URLButton(Panel *parent, const char *panelName, const wchar_t *text, Panel *pActionSignalTarget=NULL, const char *pCmd=NULL);
  29. ~URLButton();
  30. private:
  31. void Init();
  32. public:
  33. // Set armed state.
  34. virtual void SetArmed(bool state);
  35. // Check armed state
  36. virtual bool IsArmed( void );
  37. // Check depressed state
  38. virtual bool IsDepressed();
  39. // Set button force depressed state.
  40. virtual void ForceDepressed(bool state);
  41. // Set button depressed state with respect to the force depressed state.
  42. virtual void RecalculateDepressedState( void );
  43. // Set button selected state.
  44. virtual void SetSelected(bool state);
  45. // Check selected state
  46. virtual bool IsSelected( void );
  47. //Set whether or not the button captures all mouse input when depressed.
  48. virtual void SetUseCaptureMouse( bool state );
  49. // Check if mouse capture is enabled.
  50. virtual bool IsUseCaptureMouseEnabled( void );
  51. // Activate a button click.
  52. MESSAGE_FUNC( DoClick, "PressButton" );
  53. MESSAGE_FUNC( OnHotkey, "Hotkey" )
  54. {
  55. DoClick();
  56. }
  57. // Set button to be mouse clickable or not.
  58. virtual void SetMouseClickEnabled( MouseCode code, bool state );
  59. // sets the how this button activates
  60. enum ActivationType_t
  61. {
  62. ACTIVATE_ONPRESSEDANDRELEASED, // normal button behaviour
  63. ACTIVATE_ONPRESSED, // menu buttons, toggle buttons
  64. ACTIVATE_ONRELEASED, // menu items
  65. };
  66. virtual void SetButtonActivationType(ActivationType_t activationType);
  67. // Message targets that the button has been pressed
  68. virtual void FireActionSignal( void );
  69. // Perform graphical layout of button
  70. virtual void PerformLayout();
  71. virtual bool RequestInfo(KeyValues *data);
  72. // Respond when key focus is received
  73. virtual void OnSetFocus();
  74. // Respond when focus is killed
  75. virtual void OnKillFocus();
  76. // Set button border attribute enabled, controls display of button.
  77. virtual void SetButtonBorderEnabled( bool state );
  78. // Get button foreground color
  79. virtual Color GetButtonFgColor();
  80. // Get button background color
  81. virtual Color GetButtonBgColor();
  82. // Set the command to send when the button is pressed
  83. // Set the panel to send the command to with AddActionSignalTarget()
  84. virtual void SetCommand( const char *command );
  85. // Set the message to send when the button is pressed
  86. virtual void SetCommand( KeyValues *message );
  87. /* CUSTOM MESSAGE HANDLING
  88. "PressButton" - makes the button act as if it had just been pressed by the user (just like DoClick())
  89. input: none
  90. */
  91. virtual void OnCursorEntered();
  92. virtual void OnCursorExited();
  93. virtual void SizeToContents();
  94. virtual KeyValues *GetCommand();
  95. bool IsDrawingFocusBox();
  96. void DrawFocusBox( bool bEnable );
  97. protected:
  98. // Paint button on screen
  99. virtual void Paint(void);
  100. // Get button border attributes.
  101. virtual void ApplySchemeSettings(IScheme *pScheme);
  102. MESSAGE_FUNC_INT( OnSetState, "SetState", state );
  103. virtual void OnMousePressed(MouseCode code);
  104. virtual void OnMouseDoublePressed(MouseCode code);
  105. virtual void OnMouseReleased(MouseCode code);
  106. virtual void OnKeyCodePressed(KeyCode code);
  107. virtual void OnKeyCodeReleased(KeyCode code);
  108. // Get control settings for editing
  109. virtual void GetSettings( KeyValues *outResourceData );
  110. virtual void ApplySettings( KeyValues *inResourceData );
  111. virtual const char *GetDescription( void );
  112. KeyValues *GetActionMessage();
  113. private:
  114. enum ButtonFlags_t
  115. {
  116. ARMED = 0x0001,
  117. DEPRESSED = 0x0002,
  118. FORCE_DEPRESSED = 0x0004,
  119. BUTTON_BORDER_ENABLED = 0x0008,
  120. USE_CAPTURE_MOUSE = 0x0010,
  121. BUTTON_KEY_DOWN = 0x0020,
  122. DEFAULT_BUTTON = 0x0040,
  123. SELECTED = 0x0080,
  124. DRAW_FOCUS_BOX = 0x0100,
  125. BLINK = 0x0200,
  126. ALL_FLAGS = 0xFFFF,
  127. };
  128. CUtlFlags< unsigned short > _buttonFlags; // see ButtonFlags_t
  129. int _mouseClickMask;
  130. KeyValues *_actionMessage;
  131. ActivationType_t _activationType;
  132. Color _defaultFgColor, _defaultBgColor;
  133. bool m_bSelectionStateSaved;
  134. };
  135. } // namespace vgui
  136. #endif // URLBUTTON_H