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.

117 lines
2.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "keytogglecheckbutton.h"
  8. #include "engineinterface.h"
  9. #include <vgui/IVGui.h>
  10. #include "IGameUIFuncs.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include <tier0/memdbgon.h>
  13. using namespace vgui;
  14. CKeyToggleCheckButton::CKeyToggleCheckButton( Panel *parent, const char *panelName, const char *text,
  15. char const *key, char const *cmdname )
  16. : CheckButton( parent, panelName, text )
  17. {
  18. m_pszKeyName = key ? strdup( key ) : NULL;
  19. m_pszCmdName = cmdname ? strdup( cmdname ) : NULL;
  20. if (m_pszKeyName)
  21. {
  22. Reset();
  23. }
  24. //m_bNoCommand = false;
  25. }
  26. CKeyToggleCheckButton::~CKeyToggleCheckButton()
  27. {
  28. free( m_pszKeyName );
  29. free( m_pszCmdName );
  30. }
  31. //-----------------------------------------------------------------------------
  32. // Purpose:
  33. //-----------------------------------------------------------------------------
  34. void CKeyToggleCheckButton::Paint()
  35. {
  36. BaseClass::Paint();
  37. if ( !m_pszKeyName )
  38. return;
  39. // Fixme, look up key state
  40. bool isdown;
  41. if ( gameuifuncs->IsKeyDown( m_pszKeyName, isdown ) )
  42. {
  43. // if someone changed the value using the consoel
  44. if ( m_bStartValue != isdown )
  45. {
  46. SetSelected( isdown );
  47. m_bStartValue = isdown;
  48. }
  49. }
  50. }
  51. //-----------------------------------------------------------------------------
  52. // Purpose:
  53. // Input : *panel -
  54. //-----------------------------------------------------------------------------
  55. /*
  56. void CKeyToggleCheckButton::SetSelected( bool state )
  57. {
  58. BaseClass::SetSelected( state );
  59. if ( !m_pszCmdName || !m_pszCmdName[ 0 ] )
  60. return;
  61. if ( m_bNoCommand )
  62. return;
  63. char szCommand[ 256 ];
  64. Q_snprintf( szCommand, sizeof( szCommand ), "%c%s\n", IsSelected() ? '+' : '-',
  65. m_pszCmdName );
  66. engine->pfnClientCmd( szCommand );
  67. }*/
  68. //-----------------------------------------------------------------------------
  69. // Purpose:
  70. //-----------------------------------------------------------------------------
  71. void CKeyToggleCheckButton::Reset()
  72. {
  73. gameuifuncs->IsKeyDown( m_pszKeyName, m_bStartValue );
  74. if ( IsSelected() != m_bStartValue)
  75. {
  76. SetSelected( m_bStartValue );
  77. }
  78. }
  79. //-----------------------------------------------------------------------------
  80. // Purpose:
  81. //-----------------------------------------------------------------------------
  82. void CKeyToggleCheckButton::ApplyChanges()
  83. {
  84. if ( !m_pszCmdName || !m_pszCmdName[ 0 ] )
  85. return;
  86. char szCommand[ 256 ];
  87. Q_snprintf( szCommand, sizeof( szCommand ), "%c%s\n", IsSelected() ? '+' : '-',
  88. m_pszCmdName );
  89. engine->ClientCmd_Unrestricted( szCommand );
  90. }
  91. //-----------------------------------------------------------------------------
  92. // Purpose:
  93. //-----------------------------------------------------------------------------
  94. bool CKeyToggleCheckButton::HasBeenModified()
  95. {
  96. return IsSelected() != m_bStartValue;
  97. }