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.

102 lines
2.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include <vgui/KeyCode.h>
  8. #include <vgui_controls/ToggleButton.h>
  9. #include <keyvalues.h>
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include <tier0/memdbgon.h>
  12. using namespace vgui;
  13. DECLARE_BUILD_FACTORY_DEFAULT_TEXT( ToggleButton, ToggleButton );
  14. //-----------------------------------------------------------------------------
  15. // Purpose: Constructor
  16. //-----------------------------------------------------------------------------
  17. ToggleButton::ToggleButton(Panel *parent, const char *panelName, const char* text) : Button(parent, panelName, text)
  18. {
  19. SetButtonActivationType(ACTIVATE_ONPRESSED);
  20. }
  21. //-----------------------------------------------------------------------------
  22. // Purpose: Turns double-click into normal click
  23. //-----------------------------------------------------------------------------
  24. void ToggleButton::OnMouseDoublePressed(MouseCode code)
  25. {
  26. OnMousePressed(code);
  27. }
  28. //-----------------------------------------------------------------------------
  29. // Purpose:
  30. //-----------------------------------------------------------------------------
  31. Color ToggleButton::GetButtonFgColor()
  32. {
  33. if (IsSelected())
  34. {
  35. // highlight the text when depressed
  36. return _selectedColor;
  37. }
  38. else
  39. {
  40. return BaseClass::GetButtonFgColor();
  41. }
  42. }
  43. //-----------------------------------------------------------------------------
  44. // Purpose:
  45. //-----------------------------------------------------------------------------
  46. bool ToggleButton::CanBeDefaultButton(void)
  47. {
  48. return false;
  49. }
  50. //-----------------------------------------------------------------------------
  51. // Purpose: Toggles the state of the button
  52. //-----------------------------------------------------------------------------
  53. void ToggleButton::DoClick()
  54. {
  55. if (IsSelected())
  56. {
  57. ForceDepressed(false);
  58. }
  59. else if (!IsSelected())
  60. {
  61. ForceDepressed(true);
  62. }
  63. SetSelected(!IsSelected());
  64. FireActionSignal();
  65. // post a button toggled message
  66. KeyValues *msg = new KeyValues("ButtonToggled");
  67. msg->SetInt("state", (int)IsSelected());
  68. PostActionSignal(msg);
  69. Repaint();
  70. }
  71. //-----------------------------------------------------------------------------
  72. // Purpose:
  73. //-----------------------------------------------------------------------------
  74. void ToggleButton::ApplySchemeSettings(IScheme *pScheme)
  75. {
  76. BaseClass::ApplySchemeSettings(pScheme);
  77. _selectedColor = GetSchemeColor("ToggleButton.SelectedTextColor", pScheme);
  78. }
  79. void ToggleButton::OnKeyCodePressed(KeyCode code)
  80. {
  81. if (code != KEY_ENTER)
  82. {
  83. BaseClass::OnKeyCodePressed(code);
  84. }
  85. }