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.

97 lines
2.4 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "vgui_controls/pch_vgui_controls.h"
  8. #include <vgui_controls/keyrepeat.h>
  9. // memdbgon must be the last include file in a .cpp file
  10. #include "tier0/memdbgon.h"
  11. using namespace vgui;
  12. vgui::KeyCode g_iCodesForAliases[FM_NUM_KEYREPEAT_ALIASES] =
  13. {
  14. KEY_XBUTTON_UP,
  15. KEY_XBUTTON_DOWN,
  16. KEY_XBUTTON_LEFT,
  17. KEY_XBUTTON_RIGHT,
  18. };
  19. //-----------------------------------------------------------------------------
  20. // Purpose:
  21. //-----------------------------------------------------------------------------
  22. void CKeyRepeatHandler::KeyDown( vgui::KeyCode code )
  23. {
  24. int iIndex = GetIndexForCode(code);
  25. if ( iIndex == -1 )
  26. return;
  27. if ( m_bAliasDown[ iIndex ] )
  28. return;
  29. Reset();
  30. m_bAliasDown[ iIndex ] = true;
  31. m_flNextKeyRepeat = system()->GetCurrentTime() + 0.4;
  32. m_bHaveKeyDown = true;
  33. }
  34. //-----------------------------------------------------------------------------
  35. // Purpose:
  36. //-----------------------------------------------------------------------------
  37. void CKeyRepeatHandler::KeyUp( vgui::KeyCode code )
  38. {
  39. int iIndex = GetIndexForCode(code);
  40. if ( iIndex == -1 )
  41. return;
  42. m_bAliasDown[ GetIndexForCode(code) ] = false;
  43. m_bHaveKeyDown = false;
  44. for ( int i = 0; i < FM_NUM_KEYREPEAT_ALIASES; i++ )
  45. {
  46. if ( m_bAliasDown[i] )
  47. {
  48. m_bHaveKeyDown = true;
  49. break;
  50. }
  51. }
  52. }
  53. //-----------------------------------------------------------------------------
  54. // Purpose:
  55. //-----------------------------------------------------------------------------
  56. vgui::KeyCode CKeyRepeatHandler::KeyRepeated( void )
  57. {
  58. if ( IsPC() )
  59. return BUTTON_CODE_NONE;
  60. if ( !m_bHaveKeyDown )
  61. return BUTTON_CODE_NONE;
  62. if ( m_flNextKeyRepeat < system()->GetCurrentTime() )
  63. {
  64. for ( int i = 0; i < FM_NUM_KEYREPEAT_ALIASES; i++ )
  65. {
  66. if ( m_bAliasDown[i] )
  67. {
  68. m_flNextKeyRepeat = system()->GetCurrentTime() + m_flRepeatTimes[i];
  69. return g_iCodesForAliases[i];
  70. }
  71. }
  72. }
  73. return BUTTON_CODE_NONE;
  74. }
  75. //-----------------------------------------------------------------------------
  76. // Purpose:
  77. //-----------------------------------------------------------------------------
  78. void CKeyRepeatHandler::SetKeyRepeatTime( vgui::KeyCode code, float flRepeat )
  79. {
  80. int iIndex = GetIndexForCode(code);
  81. Assert( iIndex != -1 );
  82. m_flRepeatTimes[ iIndex ] = flRepeat;
  83. }