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.

216 lines
6.4 KiB

  1. //========= Copyright 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. // memdbgon must be the last include file in a .cpp file!!!
  15. #include <tier0/memdbgon.h>
  16. using namespace vgui;
  17. void CheckImage::Paint()
  18. {
  19. DrawSetTextFont(GetFont());
  20. // draw background
  21. if (_CheckButton->IsEnabled() && _CheckButton->IsCheckButtonCheckable() )
  22. {
  23. DrawSetTextColor(_bgColor);
  24. }
  25. else
  26. {
  27. DrawSetTextColor(_CheckButton->GetDisabledBgColor());
  28. }
  29. DrawPrintChar(0, 1, 'g');
  30. // draw border box
  31. DrawSetTextColor(_borderColor1);
  32. DrawPrintChar(0, 1, 'e');
  33. DrawSetTextColor(_borderColor2);
  34. DrawPrintChar(0, 1, 'f');
  35. // draw selected check
  36. if (_CheckButton->IsSelected())
  37. {
  38. if ( !_CheckButton->IsEnabled() )
  39. {
  40. DrawSetTextColor( _CheckButton->GetDisabledFgColor() );
  41. }
  42. else
  43. {
  44. DrawSetTextColor(_checkColor);
  45. }
  46. DrawPrintChar(0, 2, 'b');
  47. }
  48. }
  49. DECLARE_BUILD_FACTORY_DEFAULT_TEXT( CheckButton, CheckButton );
  50. //-----------------------------------------------------------------------------
  51. // Purpose: Constructor
  52. //-----------------------------------------------------------------------------
  53. CheckButton::CheckButton(Panel *parent, const char *panelName, const char *text) : ToggleButton(parent, panelName, text)
  54. {
  55. SetContentAlignment(a_west);
  56. m_bCheckButtonCheckable = true;
  57. m_bUseSmallCheckImage = false;
  58. // create the image
  59. _checkBoxImage = new CheckImage(this);
  60. SetTextImageIndex(1);
  61. SetImageAtIndex(0, _checkBoxImage, CHECK_INSET);
  62. _selectedFgColor = Color( 196, 181, 80, 255 );
  63. _disabledFgColor = Color(130, 130, 130, 255);
  64. _disabledBgColor = Color(62, 70, 55, 255);
  65. }
  66. //-----------------------------------------------------------------------------
  67. // Purpose: Destructor
  68. //-----------------------------------------------------------------------------
  69. CheckButton::~CheckButton()
  70. {
  71. delete _checkBoxImage;
  72. }
  73. //-----------------------------------------------------------------------------
  74. // Purpose:
  75. //-----------------------------------------------------------------------------
  76. void CheckButton::ApplySettings( KeyValues *inResourceData )
  77. {
  78. BaseClass::ApplySettings( inResourceData );
  79. m_bUseSmallCheckImage = inResourceData->GetBool( "smallcheckimage", false );
  80. }
  81. //-----------------------------------------------------------------------------
  82. // Purpose:
  83. //-----------------------------------------------------------------------------
  84. void CheckButton::ApplySchemeSettings(IScheme *pScheme)
  85. {
  86. BaseClass::ApplySchemeSettings(pScheme);
  87. SetDefaultColor( GetSchemeColor("CheckButton.TextColor", pScheme), GetBgColor() );
  88. _checkBoxImage->_bgColor = GetSchemeColor("CheckButton.BgColor", Color(62, 70, 55, 255), pScheme);
  89. _checkBoxImage->_borderColor1 = GetSchemeColor("CheckButton.Border1", Color(20, 20, 20, 255), pScheme);
  90. _checkBoxImage->_borderColor2 = GetSchemeColor("CheckButton.Border2", Color(90, 90, 90, 255), pScheme);
  91. _checkBoxImage->_checkColor = GetSchemeColor("CheckButton.Check", Color(20, 20, 20, 255), pScheme);
  92. _selectedFgColor = GetSchemeColor("CheckButton.SelectedTextColor", GetSchemeColor("ControlText", pScheme), pScheme);
  93. _disabledFgColor = GetSchemeColor("CheckButton.DisabledFgColor", Color(130, 130, 130, 255), pScheme);
  94. _disabledBgColor = GetSchemeColor("CheckButton.DisabledBgColor", Color(62, 70, 55, 255), pScheme);
  95. Color bgArmedColor = GetSchemeColor( "CheckButton.ArmedBgColor", Color(62, 70, 55, 255), pScheme);
  96. SetArmedColor( GetFgColor(), bgArmedColor );
  97. Color bgDepressedColor = GetSchemeColor( "CheckButton.DepressedBgColor", Color(62, 70, 55, 255), pScheme);
  98. SetDepressedColor( GetFgColor(), bgDepressedColor );
  99. _highlightFgColor = GetSchemeColor( "CheckButton.HighlightFgColor", Color(62, 70, 55, 255), pScheme);
  100. SetContentAlignment(Label::a_west);
  101. _checkBoxImage->SetFont( pScheme->GetFont( m_bUseSmallCheckImage ? "MarlettSmall" : "Marlett", IsProportional()) );
  102. _checkBoxImage->ResizeImageToContent();
  103. SetImageAtIndex(0, _checkBoxImage, CHECK_INSET);
  104. // don't draw a background
  105. SetPaintBackgroundEnabled(false);
  106. }
  107. //-----------------------------------------------------------------------------
  108. // Purpose:
  109. //-----------------------------------------------------------------------------
  110. IBorder *CheckButton::GetBorder(bool depressed, bool armed, bool selected, bool keyfocus)
  111. {
  112. return NULL;
  113. }
  114. //-----------------------------------------------------------------------------
  115. // Purpose: Check the button
  116. //-----------------------------------------------------------------------------
  117. void CheckButton::SetSelected(bool state )
  118. {
  119. if (m_bCheckButtonCheckable)
  120. {
  121. // send a message saying we've been checked
  122. KeyValues *msg = new KeyValues("CheckButtonChecked", "state", (int)state);
  123. PostActionSignal(msg);
  124. BaseClass::SetSelected(state);
  125. }
  126. }
  127. //-----------------------------------------------------------------------------
  128. // Purpose: sets whether or not the state of the check can be changed
  129. //-----------------------------------------------------------------------------
  130. void CheckButton::SetCheckButtonCheckable(bool state)
  131. {
  132. m_bCheckButtonCheckable = state;
  133. Repaint();
  134. }
  135. //-----------------------------------------------------------------------------
  136. // Purpose: Gets a different foreground text color if we are selected
  137. //-----------------------------------------------------------------------------
  138. #ifdef _X360
  139. Color CheckButton::GetButtonFgColor()
  140. {
  141. if (HasFocus())
  142. {
  143. return _selectedFgColor;
  144. }
  145. return BaseClass::GetButtonFgColor();
  146. }
  147. #else
  148. Color CheckButton::GetButtonFgColor()
  149. {
  150. if ( IsArmed() )
  151. {
  152. return _highlightFgColor;
  153. }
  154. if (IsSelected())
  155. {
  156. return _selectedFgColor;
  157. }
  158. return BaseClass::GetButtonFgColor();
  159. }
  160. #endif
  161. //-----------------------------------------------------------------------------
  162. // Purpose:
  163. //-----------------------------------------------------------------------------
  164. void CheckButton::OnCheckButtonChecked(Panel *panel)
  165. {
  166. }
  167. //-----------------------------------------------------------------------------
  168. // Purpose:
  169. //-----------------------------------------------------------------------------
  170. void CheckButton::SetHighlightColor(Color fgColor)
  171. {
  172. if ( _highlightFgColor != fgColor )
  173. {
  174. _highlightFgColor = fgColor;
  175. InvalidateLayout(false);
  176. }
  177. }