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.

268 lines
7.7 KiB

  1. //========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include <stdarg.h>
  8. #include <stdio.h>
  9. #include <vgui/ISurface.h>
  10. #include <vgui/IScheme.h>
  11. #include <keyvalues.h>
  12. #include <vgui_controls/Image.h>
  13. #include <vgui_controls/CheckButton.h>
  14. #include <vgui_controls/TextImage.h>
  15. // memdbgon must be the last include file in a .cpp file!!!
  16. #include <tier0/memdbgon.h>
  17. using namespace vgui;
  18. //-----------------------------------------------------------------------------
  19. // Purpose: Check box image
  20. //-----------------------------------------------------------------------------
  21. class CheckImage : public TextImage
  22. {
  23. public:
  24. CheckImage(CheckButton *CheckButton) : TextImage( "g" )
  25. {
  26. _CheckButton = CheckButton;
  27. _drawMode = 0;
  28. SetSize(20, 13);
  29. }
  30. virtual void Paint()
  31. {
  32. DrawSetTextFont(GetFont());
  33. if ( !_drawMode )
  34. {
  35. // draw background
  36. if (_CheckButton->IsEnabled() && _CheckButton->IsCheckButtonCheckable() )
  37. {
  38. DrawSetTextColor(_bgColor);
  39. }
  40. else
  41. {
  42. DrawSetTextColor(_CheckButton->GetDisabledBgColor());
  43. }
  44. DrawPrintChar(0, 1, 'g');
  45. // draw border box
  46. DrawSetTextColor(_borderColor1);
  47. DrawPrintChar(0, 1, 'e');
  48. DrawSetTextColor(_borderColor2);
  49. DrawPrintChar(0, 1, 'f');
  50. }
  51. else
  52. {
  53. // Left4Dead custom background/border:
  54. // always 1-pixel thick border, for proportional in-game menus
  55. // slightly rounded corners to match our visuals
  56. int x, y;
  57. GetPos( x, y );
  58. int wide, tall;
  59. GetContentSize( wide, tall );
  60. x += 1;
  61. wide -= 2;
  62. y += 1;
  63. tall -= 2;
  64. // draw background
  65. if (_CheckButton->IsEnabled() && _CheckButton->IsCheckButtonCheckable() )
  66. {
  67. surface()->DrawSetColor(_bgColor);
  68. surface()->DrawSetTextColor(_bgColor);
  69. }
  70. else
  71. {
  72. surface()->DrawSetColor(_CheckButton->GetDisabledBgColor());
  73. surface()->DrawSetTextColor(_CheckButton->GetDisabledBgColor());
  74. }
  75. surface()->DrawFilledRect( x+1, y+1, x+wide-1, y+tall-1 );
  76. // draw border box
  77. surface()->DrawSetColor(_borderColor1);
  78. surface()->DrawSetTextColor(_borderColor1);
  79. surface()->DrawFilledRect( x+1, y, x+wide-1, y+1 );
  80. surface()->DrawFilledRect( x, y+1, x+1, y+tall-1 );
  81. surface()->DrawSetColor(_borderColor2);
  82. surface()->DrawSetTextColor(_borderColor2);
  83. surface()->DrawFilledRect( x+1, y+tall-1, x+wide-1, y+tall );
  84. surface()->DrawFilledRect( x+wide-1, y+1, x+wide, y+tall-1 );
  85. }
  86. // draw selected check
  87. if (_CheckButton->IsSelected())
  88. {
  89. if ( !_CheckButton->IsEnabled() )
  90. {
  91. DrawSetTextColor( _CheckButton->GetDisabledFgColor() );
  92. }
  93. else
  94. {
  95. DrawSetTextColor(_checkColor);
  96. }
  97. DrawPrintChar(0, 2, 'b');
  98. }
  99. }
  100. Color _borderColor1;
  101. Color _borderColor2;
  102. Color _checkColor;
  103. Color _bgColor;
  104. int _drawMode;
  105. private:
  106. CheckButton *_CheckButton;
  107. };
  108. DECLARE_BUILD_FACTORY_DEFAULT_TEXT( CheckButton, CheckButton );
  109. //-----------------------------------------------------------------------------
  110. // Purpose: Constructor
  111. //-----------------------------------------------------------------------------
  112. CheckButton::CheckButton(Panel *parent, const char *panelName, const char *text) : ToggleButton(parent, panelName, text)
  113. {
  114. SetContentAlignment(a_west);
  115. m_bCheckButtonCheckable = true;
  116. // create the image
  117. _checkBoxImage = new CheckImage(this);
  118. SetTextImageIndex(1);
  119. SetImageAtIndex(0, _checkBoxImage, CHECK_INSET);
  120. _selectedFgColor = Color( 196, 181, 80, 255 );
  121. _disabledFgColor = Color(130, 130, 130, 255);
  122. _disabledBgColor = Color(62, 70, 55, 255);
  123. }
  124. //-----------------------------------------------------------------------------
  125. // Purpose: Destructor
  126. //-----------------------------------------------------------------------------
  127. CheckButton::~CheckButton()
  128. {
  129. delete _checkBoxImage;
  130. }
  131. //-----------------------------------------------------------------------------
  132. // Purpose:
  133. //-----------------------------------------------------------------------------
  134. void CheckButton::SetCheckDrawMode( int mode )
  135. {
  136. _checkBoxImage->_drawMode = mode;
  137. }
  138. //-----------------------------------------------------------------------------
  139. // Purpose:
  140. //-----------------------------------------------------------------------------
  141. void CheckButton::ApplySchemeSettings(IScheme *pScheme)
  142. {
  143. BaseClass::ApplySchemeSettings(pScheme);
  144. SetDefaultColor( GetSchemeColor("CheckButton.TextColor", pScheme), GetBgColor() );
  145. _checkBoxImage->_bgColor = GetSchemeColor("CheckButton.BgColor", Color(62, 70, 55, 255), pScheme);
  146. _checkBoxImage->_borderColor1 = GetSchemeColor("CheckButton.Border1", Color(20, 20, 20, 255), pScheme);
  147. _checkBoxImage->_borderColor2 = GetSchemeColor("CheckButton.Border2", Color(90, 90, 90, 255), pScheme);
  148. _checkBoxImage->_checkColor = GetSchemeColor("CheckButton.Check", Color(20, 20, 20, 255), pScheme);
  149. _selectedFgColor = GetSchemeColor("CheckButton.SelectedTextColor", GetSchemeColor("ControlText", pScheme), pScheme);
  150. _disabledFgColor = GetSchemeColor("CheckButton.DisabledFgColor", Color(130, 130, 130, 255), pScheme);
  151. _disabledBgColor = GetSchemeColor("CheckButton.DisabledBgColor", Color(62, 70, 55, 255), pScheme);
  152. Color bgArmedColor = GetSchemeColor( "CheckButton.ArmedBgColor", Color(62, 70, 55, 255), pScheme);
  153. SetArmedColor( GetFgColor(), bgArmedColor );
  154. Color bgDepressedColor = GetSchemeColor( "CheckButton.DepressedBgColor", Color(62, 70, 55, 255), pScheme);
  155. SetDepressedColor( GetFgColor(), bgDepressedColor );
  156. _highlightFgColor = GetSchemeColor( "CheckButton.HighlightFgColor", Color(62, 70, 55, 255), pScheme);
  157. SetContentAlignment(Label::a_west);
  158. _checkBoxImage->SetFont( pScheme->GetFont("Marlett", IsProportional()) );
  159. _checkBoxImage->ResizeImageToContent();
  160. SetImageAtIndex(0, _checkBoxImage, CHECK_INSET);
  161. // don't draw a background
  162. SetPaintBackgroundEnabled(false);
  163. }
  164. //-----------------------------------------------------------------------------
  165. // Purpose:
  166. //-----------------------------------------------------------------------------
  167. IBorder *CheckButton::GetBorder(bool depressed, bool armed, bool selected, bool keyfocus)
  168. {
  169. return NULL;
  170. }
  171. //-----------------------------------------------------------------------------
  172. // Purpose: Check the button
  173. //-----------------------------------------------------------------------------
  174. void CheckButton::SetSelected(bool state )
  175. {
  176. if (m_bCheckButtonCheckable)
  177. {
  178. // send a message saying we've been checked
  179. KeyValues *msg = new KeyValues("CheckButtonChecked", "state", (int)state);
  180. PostActionSignal(msg);
  181. BaseClass::SetSelected(state);
  182. }
  183. }
  184. //-----------------------------------------------------------------------------
  185. // Purpose: sets whether or not the state of the check can be changed
  186. //-----------------------------------------------------------------------------
  187. void CheckButton::SetCheckButtonCheckable(bool state)
  188. {
  189. m_bCheckButtonCheckable = state;
  190. Repaint();
  191. }
  192. //-----------------------------------------------------------------------------
  193. // Purpose: Gets a different foreground text color if we are selected
  194. //-----------------------------------------------------------------------------
  195. #ifdef _GAMECONSOLE
  196. Color CheckButton::GetButtonFgColor()
  197. {
  198. if (HasFocus())
  199. {
  200. return _selectedFgColor;
  201. }
  202. return BaseClass::GetButtonFgColor();
  203. }
  204. #else
  205. Color CheckButton::GetButtonFgColor()
  206. {
  207. if ( IsArmed() )
  208. {
  209. return _highlightFgColor;
  210. }
  211. if (IsSelected())
  212. {
  213. return _selectedFgColor;
  214. }
  215. return BaseClass::GetButtonFgColor();
  216. }
  217. #endif
  218. //-----------------------------------------------------------------------------
  219. // Purpose:
  220. //-----------------------------------------------------------------------------
  221. void CheckButton::OnCheckButtonChecked(Panel *panel)
  222. {
  223. }