Torque3D Documentation / _generateds / windowInputGenerator.h

windowInputGenerator.h

Engine/source/windowManager/windowInputGenerator.h

More...

Classes:

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      bool mNotifyPosition;
 42      
 43   protected:
 44
 45      PlatformWindow *mWindow;
 46      IProcessInput  *mInputController;
 47      Point2I         mLastCursorPos;
 48      bool            mClampToWindow;
 49      bool            mFocused; ///< We store this off to avoid polling the OS constantly
 50
 51      ///  This is the scale factor which relates  mouse movement in pixels
 52      /// (one unit of mouse movement is a mickey) to units in the GUI.
 53      F32             mPixelsPerMickey;
 54
 55      /// This tells us if the last key we pressed was used from the global action map.
 56      bool mLastPressWasGlobalActionMap;
 57
 58      // Event Handlers
 59      void handleMouseButton(WindowId did, U32 modifier,  U32 action, U16 button);
 60      void handleMouseWheel (WindowId did, U32 modifier,  S32 wheelDeltaX, S32 wheelDeltaY);
 61      void handleMouseMove  (WindowId did, U32 modifier,  S32 x,      S32 y, bool isRelative);
 62      void handleKeyboard   (WindowId did, U32 modifier,  U32 action, U16 key);
 63      void handleCharInput  (WindowId did, U32 modifier,  U16 key);
 64      void handleAppEvent   (WindowId did, S32 event);
 65      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);
 66
 67      void generateInputEvent( InputEventInfo &inputEvent );
 68
 69      /// Accelerator key map
 70       struct AccKeyMap
 71       {
 72          void *hnd;
 73          String cmd;
 74          U32 keyCode;
 75          U32 modifier;
 76       };
 77       Vector <AccKeyMap> mAcceleratorMap;
 78      
 79   public:
 80   
 81      WindowInputGenerator( PlatformWindow *window );
 82      virtual ~WindowInputGenerator();
 83
 84      void setInputController( IProcessInput *inputController ) { mInputController = inputController; };
 85      
 86      /// Returns true if the given keypress event should be send as a raw keyboard
 87      /// event even if it maps to a character input event.
 88      bool wantAsKeyboardEvent( U32 modifiers, U32 key );
 89
 90      /// Tells us if the last key was used within the global action map.
 91      /// @return true if the key was a global action map key, false otherwise.
 92      /// @note Useful and currently used to tell if we just opened the console 
 93      ///  by using the console key. Currently this is used to fix a bug in SDL
 94      ///  but it is not limited to that use.
 95      bool lastKeyWasGlobalActionMap() const { return mLastPressWasGlobalActionMap; }
 96
 97    void addAcceleratorKey( void *hnd, const String &cmd, U32 keycode, U32 modifier)
 98    {
 99        AccKeyMap acc;
100        acc.hnd = hnd;
101        acc.cmd = cmd;
102        acc.keyCode = keycode;
103        acc.modifier = modifier;
104        mAcceleratorMap.push_back(acc);
105    }
106
107    void removeAcceleratorKeys( void *hnd )
108    {
109         for( int i = 0; i < mAcceleratorMap.size(); )
110         {
111            if( mAcceleratorMap[i].hnd == hnd )
112            {
113                mAcceleratorMap.erase( i, 1 );
114                continue;
115            }
116
117             ++i;
118         }
119    }
120
121    void removeAcceleratorKey( void *hnd, U32 keycode, U32 modifier )
122    {
123         for( int i = 0; i < mAcceleratorMap.size(); ++i )
124         {
125            if( mAcceleratorMap[i].hnd == hnd && mAcceleratorMap[i].keyCode == keycode && mAcceleratorMap[i].modifier == modifier )
126            {
127                mAcceleratorMap.erase( i, 1 );
128                return;
129            }
130         }
131    }
132};
133
134#endif // _WINDOW_INPUTGENERATOR_H_
135