windowInputGenerator.h
Engine/source/windowManager/windowInputGenerator.h
Classes:
class
class
Accelerator key map.
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _WINDOW_INPUTGENERATOR_H_ 25#define _WINDOW_INPUTGENERATOR_H_ 26 27#ifndef _PLATFORMINPUT_H_ 28 #include "platform/platformInput.h" 29#endif 30#ifndef _MPOINT2_H_ 31 #include "math/mPoint2.h" 32#endif 33 34 35class IProcessInput; 36class PlatformWindow; 37 38 39class WindowInputGenerator 40{ 41 protected: 42 43 PlatformWindow *mWindow; 44 IProcessInput *mInputController; 45 Point2I mLastCursorPos; 46 bool mClampToWindow; 47 bool mFocused; ///< We store this off to avoid polling the OS constantly 48 49 /// This is the scale factor which relates mouse movement in pixels 50 /// (one unit of mouse movement is a mickey) to units in the GUI. 51 F32 mPixelsPerMickey; 52 53 /// This tells us if the last key we pressed was used from the global action map. 54 bool mLastPressWasGlobalActionMap; 55 56 // Event Handlers 57 void handleMouseButton(WindowId did, U32 modifier, U32 action, U16 button); 58 void handleMouseWheel (WindowId did, U32 modifier, S32 wheelDeltaX, S32 wheelDeltaY); 59 void handleMouseMove (WindowId did, U32 modifier, S32 x, S32 y, bool isRelative); 60 void handleKeyboard (WindowId did, U32 modifier, U32 action, U16 key); 61 void handleCharInput (WindowId did, U32 modifier, U16 key); 62 void handleAppEvent (WindowId did, S32 event); 63 void handleInputEvent (U32 deviceInst, F32 fValue, F32 fValue2, F32 fValue3, F32 fValue4, S32 iValue, U16 deviceType, U16 objType, U16 ascii, U16 objInst, U8 action, U8 modifier); 64 65 void generateInputEvent( InputEventInfo &inputEvent ); 66 67 /// Accelerator key map 68 struct AccKeyMap 69 { 70 void *hnd; 71 String cmd; 72 U32 keyCode; 73 U32 modifier; 74 }; 75 Vector <AccKeyMap> mAcceleratorMap; 76 77 public: 78 79 WindowInputGenerator( PlatformWindow *window ); 80 virtual ~WindowInputGenerator(); 81 82 void setInputController( IProcessInput *inputController ) { mInputController = inputController; }; 83 84 /// Returns true if the given keypress event should be send as a raw keyboard 85 /// event even if it maps to a character input event. 86 bool wantAsKeyboardEvent( U32 modifiers, U32 key ); 87 88 /// Tells us if the last key was used within the global action map. 89 /// @return true if the key was a global action map key, false otherwise. 90 /// @note Useful and currently used to tell if we just opened the console 91 /// by using the console key. Currently this is used to fix a bug in SDL 92 /// but it is not limited to that use. 93 bool lastKeyWasGlobalActionMap() const { return mLastPressWasGlobalActionMap; } 94 95 void addAcceleratorKey( void *hnd, const String &cmd, U32 keycode, U32 modifier) 96 { 97 AccKeyMap acc; 98 acc.hnd = hnd; 99 acc.cmd = cmd; 100 acc.keyCode = keycode; 101 acc.modifier = modifier; 102 mAcceleratorMap.push_back(acc); 103 } 104 105 void removeAcceleratorKeys( void *hnd ) 106 { 107 for( int i = 0; i < mAcceleratorMap.size(); ) 108 { 109 if( mAcceleratorMap[i].hnd == hnd ) 110 { 111 mAcceleratorMap.erase( i, 1 ); 112 continue; 113 } 114 115 ++i; 116 } 117 } 118 119 void removeAcceleratorKey( void *hnd, U32 keycode, U32 modifier ) 120 { 121 for( int i = 0; i < mAcceleratorMap.size(); ++i ) 122 { 123 if( mAcceleratorMap[i].hnd == hnd && mAcceleratorMap[i].keyCode == keycode && mAcceleratorMap[i].modifier == modifier ) 124 { 125 mAcceleratorMap.erase( i, 1 ); 126 return; 127 } 128 } 129 } 130}; 131 132#endif // _WINDOW_INPUTGENERATOR_H_ 133