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.

112 lines
3.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef RADIOBUTTON_H
  8. #define RADIOBUTTON_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <vgui/VGUI.h>
  13. #include <vgui_controls/ToggleButton.h>
  14. #include <vgui_controls/TextImage.h>
  15. namespace vgui
  16. {
  17. //-----------------------------------------------------------------------------
  18. // Purpose: Radio buton image
  19. //-----------------------------------------------------------------------------
  20. class RadioImage : public TextImage
  21. {
  22. public:
  23. RadioImage(RadioButton *radioButton) : TextImage( "n" )
  24. {
  25. _radioButton = radioButton;
  26. SetSize(20, 13);
  27. }
  28. virtual void Paint();
  29. virtual void SetColor(Color color)
  30. {
  31. _borderColor1 = color;
  32. _borderColor2 = color;
  33. _checkColor = color;
  34. }
  35. Color _borderColor1;
  36. Color _borderColor2;
  37. Color _checkColor;
  38. Color _bgColor;
  39. private:
  40. RadioButton *_radioButton;
  41. };
  42. //-----------------------------------------------------------------------------
  43. // Purpose: Radio buttons are automatically selected into groups by who their
  44. // parent is. At most one radio button is active at any time.
  45. //-----------------------------------------------------------------------------
  46. class RadioButton : public ToggleButton
  47. {
  48. DECLARE_CLASS_SIMPLE( RadioButton, ToggleButton );
  49. public:
  50. RadioButton(Panel *parent, const char *panelName, const char *text);
  51. ~RadioButton();
  52. // Set the radio button checked. When a radio button is checked, a
  53. // message is sent to all other radio buttons in the same group so
  54. // they will become unchecked.
  55. virtual void SetSelected(bool state);
  56. // Get the tab position of the radio button with the set of radio buttons
  57. // A group of RadioButtons must have the same TabPosition, with [1, n] subtabpositions
  58. virtual int GetSubTabPosition();
  59. virtual void SetSubTabPosition(int position);
  60. // Return the RadioButton's real tab position (its Panel one changes)
  61. virtual int GetRadioTabPosition();
  62. // Set the selection state of the radio button, but don't fire
  63. // any action signals or messages to other radio buttons
  64. virtual void SilentSetSelected(bool state);
  65. protected:
  66. virtual void DoClick();
  67. virtual void Paint();
  68. virtual void ApplySchemeSettings(IScheme *pScheme);
  69. MESSAGE_FUNC_INT( OnRadioButtonChecked, "RadioButtonChecked", tabposition);
  70. virtual void OnKeyCodeTyped(KeyCode code);
  71. virtual IBorder *GetBorder(bool depressed, bool armed, bool selected, bool keyfocus);
  72. virtual void ApplySettings(KeyValues *inResourceData);
  73. virtual void GetSettings(KeyValues *outResourceData);
  74. virtual const char *GetDescription();
  75. virtual void PerformLayout();
  76. RadioButton *FindBestRadioButton(int direction);
  77. private:
  78. RadioImage *_radioBoxImage;
  79. int _oldTabPosition;
  80. Color _selectedFgColor;
  81. int _subTabPosition; // tab position with the radio button list
  82. void InternalSetSelected(bool state, bool bFireEvents);
  83. };
  84. }; // namespace vgui
  85. #endif // RADIOBUTTON_H