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.

234 lines
6.2 KiB

  1. //===== Copyright 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: Implementation of the VGUI ISurface interface using the
  4. // material system to implement it
  5. //
  6. //===========================================================================//
  7. #if defined( WIN32 ) && !defined( _X360 )
  8. #include <windows.h>
  9. #include <zmouse.h>
  10. #endif
  11. #include "inputsystem/iinputsystem.h"
  12. #include "tier2/tier2.h"
  13. #include "Input.h"
  14. #include "vguimatsurface.h"
  15. #include "../vgui2/src/VPanel.h"
  16. #include <vgui/KeyCode.h>
  17. #include <vgui/MouseCode.h>
  18. #include <vgui/IVGui.h>
  19. #include <vgui/IPanel.h>
  20. #include <vgui/ISurface.h>
  21. #include <vgui/IClientPanel.h>
  22. #include "inputsystem/ButtonCode.h"
  23. #include "Cursor.h"
  24. #include "tier0/dbg.h"
  25. #include "../vgui2/src/vgui_key_translation.h"
  26. #include <vgui/IInputInternal.h>
  27. #include "tier0/icommandline.h"
  28. #ifdef _X360
  29. #include "xbox/xbox_win32stubs.h"
  30. #endif
  31. // memdbgon must be the last include file in a .cpp file!!!
  32. #include "tier0/memdbgon.h"
  33. using namespace vgui;
  34. //-----------------------------------------------------------------------------
  35. // Converts an input system button code to a vgui key code
  36. // FIXME: Remove notion of vgui::KeyCode + vgui::MouseCode altogether
  37. //-----------------------------------------------------------------------------
  38. static vgui::KeyCode ButtonCodeToKeyCode( ButtonCode_t buttonCode )
  39. {
  40. return ( vgui::KeyCode )buttonCode;
  41. }
  42. static vgui::MouseCode ButtonCodeToMouseCode( ButtonCode_t buttonCode )
  43. {
  44. return ( vgui::MouseCode )buttonCode;
  45. }
  46. //-----------------------------------------------------------------------------
  47. // Handles an input event, returns true if the event should be filtered
  48. // from the rest of the game
  49. //-----------------------------------------------------------------------------
  50. bool InputHandleInputEvent( InputContextHandle_t hContext, const InputEvent_t &event )
  51. {
  52. switch( event.m_nType )
  53. {
  54. case IE_ButtonPressed:
  55. {
  56. // NOTE: data2 is the virtual key code (data1 contains the scan-code one)
  57. ButtonCode_t code = (ButtonCode_t)event.m_nData2;
  58. if ( IsKeyCode( code ) || IsJoystickCode( code ) )
  59. {
  60. vgui::KeyCode keyCode = ButtonCodeToKeyCode( code );
  61. return g_pIInput->InternalKeyCodePressed( keyCode );
  62. }
  63. if ( IsJoystickCode( code ) )
  64. {
  65. vgui::KeyCode keyCode = ButtonCodeToKeyCode( code );
  66. return g_pIInput->InternalKeyCodePressed( keyCode );
  67. }
  68. if ( IsMouseCode( code ) )
  69. {
  70. vgui::MouseCode mouseCode = ButtonCodeToMouseCode( code );
  71. return g_pIInput->InternalMousePressed( mouseCode );
  72. }
  73. }
  74. break;
  75. case IE_ButtonReleased:
  76. {
  77. // NOTE: data2 is the virtual key code (data1 contains the scan-code one)
  78. ButtonCode_t code = (ButtonCode_t)event.m_nData2;
  79. if ( IsKeyCode( code ) || IsJoystickCode( code ) )
  80. {
  81. vgui::KeyCode keyCode = ButtonCodeToKeyCode( code );
  82. return g_pIInput->InternalKeyCodeReleased( keyCode );
  83. }
  84. if ( IsJoystickCode( code ) )
  85. {
  86. vgui::KeyCode keyCode = ButtonCodeToKeyCode( code );
  87. return g_pIInput->InternalKeyCodeReleased( keyCode );
  88. }
  89. if ( IsMouseCode( code ) )
  90. {
  91. vgui::MouseCode mouseCode = ButtonCodeToMouseCode( code );
  92. return g_pIInput->InternalMouseReleased( mouseCode );
  93. }
  94. }
  95. break;
  96. case IE_ButtonDoubleClicked:
  97. {
  98. // NOTE: data2 is the virtual key code (data1 contains the scan-code one)
  99. ButtonCode_t code = (ButtonCode_t)event.m_nData2;
  100. if ( IsMouseCode( code ) )
  101. {
  102. vgui::MouseCode mouseCode = ButtonCodeToMouseCode( code );
  103. return g_pIInput->InternalMouseDoublePressed( mouseCode );
  104. }
  105. }
  106. break;
  107. case IE_AnalogValueChanged:
  108. {
  109. if ( event.m_nData == MOUSE_WHEEL )
  110. return g_pIInput->InternalMouseWheeled( event.m_nData3 );
  111. if ( event.m_nData == MOUSE_XY )
  112. return g_pIInput->InternalCursorMoved( event.m_nData2, event.m_nData3 );
  113. //=============================================================================
  114. // HPE_BEGIN
  115. // [dwenger] Handle gamepad joystick movement.
  116. //=============================================================================
  117. if ( event.m_nData == JOYSTICK_AXIS(0, JOY_AXIS_X ))
  118. {
  119. return g_pIInput->InternalJoystickMoved ( 0, event.m_nData2 );
  120. }
  121. if ( event.m_nData == JOYSTICK_AXIS(0, JOY_AXIS_Y ) )
  122. {
  123. return g_pIInput->InternalJoystickMoved ( 1, event.m_nData2 );
  124. }
  125. if ( event.m_nData == JOYSTICK_AXIS(0, JOY_AXIS_U ))
  126. {
  127. return g_pIInput->InternalJoystickMoved ( 2, event.m_nData2 );
  128. }
  129. if ( event.m_nData == JOYSTICK_AXIS(0, JOY_AXIS_R ) )
  130. {
  131. return g_pIInput->InternalJoystickMoved ( 3, event.m_nData2 );
  132. }
  133. //=============================================================================
  134. // HPE_END
  135. //=============================================================================
  136. }
  137. break;
  138. case IE_KeyCodeTyped:
  139. {
  140. vgui::KeyCode code = (vgui::KeyCode)event.m_nData;
  141. g_pIInput->InternalKeyCodeTyped( code );
  142. }
  143. return true;
  144. case IE_KeyTyped:
  145. {
  146. wchar_t code = (wchar_t)event.m_nData;
  147. g_pIInput->InternalKeyTyped( code );
  148. }
  149. // return false so scaleform can use this
  150. break;
  151. case IE_Quit:
  152. g_pVGui->Stop();
  153. #if defined( USE_SDL ) || defined( OSX )
  154. return false; // also let higher layers consume it
  155. #else
  156. return true;
  157. #endif
  158. case IE_Close:
  159. // FIXME: Change this so we don't stop until 'save' occurs, etc.
  160. g_pVGui->Stop();
  161. return true;
  162. case IE_SetCursor:
  163. ActivateCurrentCursor( hContext );
  164. return true;
  165. case IE_IMESetWindow:
  166. g_pIInput->SetIMEWindow( (void *)event.m_nData );
  167. return true;
  168. case IE_LocateMouseClick:
  169. g_pIInput->InternalCursorMoved( event.m_nData, event.m_nData2 );
  170. return true;
  171. case IE_InputLanguageChanged:
  172. g_pIInput->OnInputLanguageChanged();
  173. return true;
  174. case IE_IMEStartComposition:
  175. g_pIInput->OnIMEStartComposition();
  176. return true;
  177. case IE_IMEComposition:
  178. g_pIInput->OnIMEComposition( event.m_nData );
  179. return true;
  180. case IE_IMEEndComposition:
  181. g_pIInput->OnIMEEndComposition();
  182. return true;
  183. case IE_IMEShowCandidates:
  184. g_pIInput->OnIMEShowCandidates();
  185. return true;
  186. case IE_IMEChangeCandidates:
  187. g_pIInput->OnIMEChangeCandidates();
  188. return true;
  189. case IE_IMECloseCandidates:
  190. g_pIInput->OnIMECloseCandidates();
  191. return true;
  192. case IE_IMERecomputeModes:
  193. g_pIInput->OnIMERecomputeModes();
  194. return true;
  195. }
  196. return false;
  197. }