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.

114 lines
3.2 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/ExpandButton.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. DECLARE_BUILD_FACTORY( ExpandButton );
  19. //-----------------------------------------------------------------------------
  20. // Purpose: Constructor
  21. //-----------------------------------------------------------------------------
  22. ExpandButton::ExpandButton( Panel *parent, const char *panelName ) : ToggleButton( parent, panelName, "" )
  23. {
  24. m_bExpandable = true;
  25. m_hFont = INVALID_FONT;
  26. }
  27. //-----------------------------------------------------------------------------
  28. // Purpose: Destructor
  29. //-----------------------------------------------------------------------------
  30. ExpandButton::~ExpandButton()
  31. {
  32. }
  33. //-----------------------------------------------------------------------------
  34. // Purpose:
  35. //-----------------------------------------------------------------------------
  36. void ExpandButton::ApplySchemeSettings(IScheme *pScheme)
  37. {
  38. BaseClass::ApplySchemeSettings(pScheme);
  39. m_Color = GetSchemeColor( "ExpandButton.Color", pScheme );
  40. m_hFont = pScheme->GetFont("Marlett", IsProportional() );
  41. // don't draw a background
  42. SetPaintBackgroundEnabled(false);
  43. }
  44. //-----------------------------------------------------------------------------
  45. // Purpose:
  46. //-----------------------------------------------------------------------------
  47. IBorder *ExpandButton::GetBorder(bool depressed, bool armed, bool selected, bool keyfocus)
  48. {
  49. return NULL;
  50. }
  51. //-----------------------------------------------------------------------------
  52. // Purpose: Expand the button
  53. //-----------------------------------------------------------------------------
  54. void ExpandButton::SetSelected(bool state)
  55. {
  56. if ( m_bExpandable && ( state != IsSelected() ) )
  57. {
  58. // send a message saying we've been checked
  59. KeyValues *msg = new KeyValues("Expanded", "state", (int)state);
  60. PostActionSignal(msg);
  61. BaseClass::SetSelected(state);
  62. }
  63. }
  64. //-----------------------------------------------------------------------------
  65. // Purpose: sets whether or not the state of the check can be changed
  66. //-----------------------------------------------------------------------------
  67. void ExpandButton::SetExpandable(bool state)
  68. {
  69. m_bExpandable = state;
  70. Repaint();
  71. }
  72. void ExpandButton::Paint()
  73. {
  74. surface()->DrawSetTextFont( m_hFont );
  75. wchar_t code = IsSelected( ) ? L'6' : L'4';
  76. wchar_t pString[2] = { code, 0 };
  77. // draw selected check
  78. int tw, th, w, h;
  79. GetSize( w, h );
  80. surface()->GetTextSize( m_hFont, pString, tw, th );
  81. surface()->DrawSetTextColor( m_Color );
  82. surface()->DrawSetTextPos( ( w - tw ) / 2, ( h - th ) / 2 );
  83. surface()->DrawUnicodeChar( code );
  84. }
  85. //-----------------------------------------------------------------------------
  86. // Purpose:
  87. //-----------------------------------------------------------------------------
  88. void ExpandButton::OnExpanded(Panel *panel)
  89. {
  90. }