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.

326 lines
10 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef INPUTGAMEUI_H
  8. #define INPUTGAMEUI_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #if !defined( _GAMECONSOLE )
  13. #include <windows.h>
  14. #include <imm.h>
  15. #endif
  16. #include "vgui/iinput.h"
  17. #include "hitarea.h"
  18. #include "keyrepeat.h"
  19. #include "utlvector.h"
  20. #include "utllinkedlist.h"
  21. #include "keyvalues.h"
  22. #include "inputsystem/buttoncode.h"
  23. #include "vgui/cursor.h"
  24. #include "vstdlib/ieventsystem.h"
  25. enum GameUIMouseCodeState_t
  26. {
  27. BUTTON_RELEASED = 0,
  28. BUTTON_PRESSED,
  29. BUTTON_DOUBLECLICKED,
  30. };
  31. namespace vgui
  32. {
  33. typedef unsigned int HInputContext;
  34. #define DEFAULT_INPUT_CONTEXT ((vgui::HInputContext)~0)
  35. }
  36. using namespace vgui;
  37. class CInputGameUI
  38. {
  39. public:
  40. CInputGameUI();
  41. ~CInputGameUI();
  42. struct LanguageItem
  43. {
  44. wchar_t shortname[ 4 ];
  45. wchar_t menuname[ 128 ];
  46. int handleValue;
  47. bool active; // true if this is the active language
  48. };
  49. struct ConversionModeItem
  50. {
  51. wchar_t menuname[ 128 ];
  52. int handleValue;
  53. bool active; // true if this is the active conversion mode
  54. };
  55. struct SentenceModeItem
  56. {
  57. wchar_t menuname[ 128 ];
  58. int handleValue;
  59. bool active; // true if this is the active sentence mode
  60. };
  61. void Init();
  62. void RunFrame();
  63. void ProcessEvents();
  64. void Shutdown();
  65. void SetWindowSize( int width, int height );
  66. void PanelDeleted( CHitArea *panel );
  67. void GraphicHidden( CHitArea *focus );
  68. void ForceInputFocusUpdate();
  69. void UpdateMouseFocus(int x, int y);
  70. void SetMouseFocus( CHitArea *newMouseFocus );
  71. // Temp testing until event system can handle destinations.
  72. void OnCursorEnter( CHitArea* const & pTarget );
  73. void OnCursorExit( CHitArea * const & pTarget );
  74. void OnCursorMove( CHitArea * const & pTarget, const int &x, const int &y );
  75. void OnMouseDown( CHitArea * const & pTarget, const ButtonCode_t &code );
  76. void OnMouseUp( CHitArea * const & pTarget, CHitArea * const & pTrap, const ButtonCode_t &code );
  77. void OnMouseDoubleClick( CHitArea * const & pTarget, const ButtonCode_t &code );
  78. void OnMouseWheel( CHitArea * const & pTarget, const int &delta );
  79. void OnKeyDown( CHitArea * const & pTarget, const ButtonCode_t &code );
  80. void OnKeyUp( CHitArea * const & pTarget, const ButtonCode_t &code );
  81. void OnKeyCodeTyped( CHitArea * const & pTarget, const ButtonCode_t &code );
  82. void OnKeyTyped( CHitArea * const & pTarget, const wchar_t &unichar );
  83. void OnLoseKeyFocus( CHitArea * const & pTarget );
  84. void OnGainKeyFocus( CHitArea * const & pTarget );
  85. void SetCursorPos( int x, int y );
  86. void UpdateCursorPosInternal( const int &x, const int &y );
  87. void GetCursorPos( int &x, int &y );
  88. void SetCursorOveride( vgui::HCursor cursor );
  89. vgui::HCursor GetCursorOveride();
  90. void SetKeyFocus( CHitArea *pFocus ); // note this will not post any messages.
  91. CHitArea *GetKeyFocus();
  92. CHitArea *GetCalculatedKeyFocus();
  93. CHitArea *GetMouseOver();
  94. bool WasMousePressed( ButtonCode_t code );
  95. bool WasMouseDoublePressed( ButtonCode_t code );
  96. bool IsMouseDown( ButtonCode_t code );
  97. bool WasMouseReleased( ButtonCode_t code );
  98. bool WasKeyPressed( ButtonCode_t code );
  99. bool IsKeyDown( ButtonCode_t code );
  100. bool WasKeyTyped( ButtonCode_t code );
  101. bool WasKeyReleased( ButtonCode_t code );
  102. void GetKeyCodeText( ButtonCode_t code, char *buf, int buflen );
  103. bool InternalCursorMoved( int x,int y ); //expects input in surface space
  104. bool InternalMousePressed( ButtonCode_t code );
  105. bool InternalMouseDoublePressed( ButtonCode_t code );
  106. bool InternalMouseReleased( ButtonCode_t code );
  107. bool InternalMouseWheeled( int delta );
  108. bool InternalKeyCodePressed( ButtonCode_t code );
  109. void InternalKeyCodeTyped( ButtonCode_t code );
  110. void InternalKeyTyped( wchar_t unichar );
  111. bool InternalKeyCodeReleased( ButtonCode_t code );
  112. void SetKeyCodeState( ButtonCode_t code, bool bPressed );
  113. void SetMouseCodeState( ButtonCode_t code, GameUIMouseCodeState_t state );
  114. void UpdateButtonState( const InputEvent_t &event );
  115. // Creates/ destroys "input" contexts, which contains information
  116. // about which controls have mouse + key focus, for example.
  117. virtual vgui::HInputContext CreateInputContext();
  118. virtual void DestroyInputContext( vgui::HInputContext context );
  119. // Activates a particular input context, use DEFAULT_INPUT_CONTEXT
  120. // to get the one normally used by VGUI
  121. virtual void ActivateInputContext( vgui::HInputContext context );
  122. virtual void PostCursorMessage();
  123. virtual void HandleExplicitSetCursor();
  124. virtual void ResetInputContext( vgui::HInputContext context );
  125. virtual void GetCursorPosition( int &x, int &y );
  126. virtual void SetIMEWindow( void *hwnd );
  127. virtual void *GetIMEWindow();
  128. // Change keyboard layout type
  129. virtual void OnChangeIME( bool forward );
  130. virtual int GetCurrentIMEHandle();
  131. virtual int GetEnglishIMEHandle();
  132. // Returns the Language Bar label (Chinese, Korean, Japanese, Russion, Thai, etc.)
  133. virtual void GetIMELanguageName( wchar_t *buf, int unicodeBufferSizeInBytes );
  134. // Returns the short code for the language (EN, CH, KO, JP, RU, TH, etc. ).
  135. virtual void GetIMELanguageShortCode( wchar_t *buf, int unicodeBufferSizeInBytes );
  136. // Call with NULL dest to get item count
  137. virtual int GetIMELanguageList( LanguageItem *dest, int destcount );
  138. virtual int GetIMEConversionModes( ConversionModeItem *dest, int destcount );
  139. virtual int GetIMESentenceModes( SentenceModeItem *dest, int destcount );
  140. virtual void OnChangeIMEByHandle( int handleValue );
  141. virtual void OnChangeIMEConversionModeByHandle( int handleValue );
  142. virtual void OnChangeIMESentenceModeByHandle( int handleValue );
  143. virtual void OnInputLanguageChanged();
  144. virtual void OnIMEStartComposition();
  145. virtual void OnIMEComposition( int flags );
  146. virtual void OnIMEEndComposition();
  147. virtual void OnIMEShowCandidates();
  148. virtual void OnIMEChangeCandidates();
  149. virtual void OnIMECloseCandidates();
  150. virtual void OnIMERecomputeModes();
  151. virtual int GetCandidateListCount();
  152. virtual void GetCandidate( int num, wchar_t *dest, int destSizeBytes );
  153. virtual int GetCandidateListSelectedItem();
  154. virtual int GetCandidateListPageSize();
  155. virtual int GetCandidateListPageStart();
  156. virtual void SetCandidateWindowPos( int x, int y );
  157. virtual bool GetShouldInvertCompositionString();
  158. virtual bool CandidateListStartsAtOne();
  159. virtual void SetCandidateListPageStart( int start );
  160. // Passes in a keycode which allows hitting other mouse buttons w/o cancelling capture mode
  161. virtual void SetMouseCaptureEx( CHitArea *panel, ButtonCode_t captureStartMouseCode );
  162. // Passes in a keycode which allows hitting other mouse buttons w/o cancelling capture mode
  163. virtual void SetMouseCapture( CHitArea *panel );
  164. virtual CHitArea *GetMouseCapture();
  165. virtual CHitArea *GetMouseFocus();
  166. private:
  167. void InternalSetCompositionString( const wchar_t *compstr );
  168. void InternalShowCandidateWindow();
  169. void InternalHideCandidateWindow();
  170. void InternalUpdateCandidateWindow();
  171. bool PostKeyMessage( KeyValues *message );
  172. void DestroyCandidateList();
  173. void CreateNewCandidateList();
  174. CHitArea *CalculateNewKeyFocus();
  175. void SurfaceSetCursorPos( int x, int y );
  176. void SurfaceGetCursorPos( int &x, int &y );
  177. struct InputContext_t
  178. {
  179. bool _mousePressed[MOUSE_COUNT];
  180. bool _mouseDoublePressed[MOUSE_COUNT];
  181. bool _mouseDown[MOUSE_COUNT];
  182. bool _mouseReleased[MOUSE_COUNT];
  183. bool _keyPressed[BUTTON_CODE_COUNT];
  184. bool _keyTyped[BUTTON_CODE_COUNT];
  185. bool _keyDown[BUTTON_CODE_COUNT];
  186. bool _keyReleased[BUTTON_CODE_COUNT];
  187. CHitArea *_keyFocus;
  188. bool _bKeyTrap; // true if the graphic with keyfocus recieved a down event. Send the up if it got a down.
  189. CHitArea *_oldMouseFocus;
  190. CHitArea *_mouseFocus; // the panel that has the current mouse focus - same as _mouseOver unless _mouseCapture is set
  191. CHitArea *_mouseOver; // the panel that the mouse is currently over, NULL if not over any vgui item
  192. CHitArea *_mouseCapture; // the panel that has currently captured mouse focus
  193. ButtonCode_t m_MouseCaptureStartCode; // The Mouse button which was pressed to initiate mouse capture
  194. CHitArea *_mouseLeftTrap; // the panel that should receive the next mouse left up
  195. CHitArea *_mouseMiddleTrap; // the panel that should receive the next mouse middle up
  196. CHitArea *_mouseRightTrap; // the panel that should receive the next mouse right up
  197. int m_nCursorX;
  198. int m_nCursorY;
  199. int m_nLastPostedCursorX;
  200. int m_nLastPostedCursorY;
  201. int m_nExternallySetCursorX;
  202. int m_nExternallySetCursorY;
  203. bool m_bSetCursorExplicitly;
  204. CUtlVector< CHitArea * > m_KeyCodeUnhandledListeners;
  205. CHitArea *m_pUnhandledMouseClickListener;
  206. bool m_bRestrictMessagesToModalSubTree;
  207. CKeyRepeatHandler m_keyRepeater;
  208. };
  209. void InitInputContext( InputContext_t *pContext );
  210. InputContext_t *GetInputContext( vgui::HInputContext context );
  211. void PanelDeleted( CHitArea *focus, InputContext_t &context);
  212. void GraphicHidden( CHitArea *focus, InputContext_t &context );
  213. vgui::HCursor _cursorOverride;
  214. char *_keyTrans[KEY_LAST];
  215. InputContext_t m_DefaultInputContext;
  216. vgui::HInputContext m_hContext; // current input context
  217. CUtlLinkedList< InputContext_t, vgui::HInputContext > m_Contexts;
  218. #ifndef _GAMECONSOLE
  219. void *_imeWnd;
  220. CANDIDATELIST *_imeCandidates;
  221. #endif
  222. int m_nDebugMessages;
  223. EventQueue_t m_hEventChannel;
  224. int m_nWindowWidth, m_nWindowHeight;
  225. };
  226. extern CInputGameUI *g_pInputGameUI;
  227. bool InputGameUIHandleInputEvent( const InputEvent_t &event );
  228. DEFINE_EVENT1_WITHNAMES( CursorEnterEvent, CHitArea *, pTarget );
  229. DEFINE_EVENT1_WITHNAMES( CursorExitEvent, CHitArea *, pTarget );
  230. DEFINE_EVENT3_WITHNAMES( CursorMoveEvent, CHitArea *, pTarget, int, x, int, y );
  231. DEFINE_EVENT2_WITHNAMES( InternalCursorMoveEvent, int, x, int, y );
  232. DEFINE_EVENT2_WITHNAMES( MouseDownEvent, CHitArea *, pTarget, ButtonCode_t, code );
  233. DEFINE_EVENT3_WITHNAMES( MouseUpEvent, CHitArea *, pTarget, CHitArea *, pTrap, ButtonCode_t, code );
  234. DEFINE_EVENT2_WITHNAMES( MouseDoubleClickEvent, CHitArea *, pTarget, ButtonCode_t, code );
  235. DEFINE_EVENT2_WITHNAMES( MouseWheelEvent, CHitArea *, pTarget, int, delta );
  236. DEFINE_EVENT2_WITHNAMES( KeyDownEvent, CHitArea *, pTarget, ButtonCode_t, code );
  237. DEFINE_EVENT2_WITHNAMES( KeyUpEvent, CHitArea *, pTarget, ButtonCode_t, code );
  238. DEFINE_EVENT2_WITHNAMES( KeyCodeTypedEvent, CHitArea *, pTarget, ButtonCode_t, code );
  239. DEFINE_EVENT2_WITHNAMES( KeyTypedEvent, CHitArea *, pTarget, wchar_t, unichar );
  240. DEFINE_EVENT1_WITHNAMES( GainKeyFocusEvent, CHitArea *, pTarget );
  241. DEFINE_EVENT1_WITHNAMES( LoseKeyFocusEvent, CHitArea *, pTarget );
  242. #endif // INPUTGAMEUI_H