Torque3D Documentation / _generateds / x86UNIXInputManager.h

x86UNIXInputManager.h

Engine/source/platformX86UNIX/x86UNIXInputManager.h

More...

Classes:

Public Defines

define
define
NUM_KEYS() (  + 1 )

Detailed Description

Public Defines

KEY_FIRST() 
NUM_KEYS() (  + 1 )
  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 _X86UNIXINPUTMANAGER_H_
 25#define _X86UNIXINPUTMANAGER_H_
 26
 27#include "core/util/tVector.h"
 28#include "platform/platformInput.h"
 29#include "platformX86UNIX/platformX86UNIX.h"
 30
 31#include <SDL/SDL_events.h>
 32
 33#define NUM_KEYS ( KEY_OEM_102 + 1 )
 34#define KEY_FIRST KEY_ESCAPE
 35
 36struct AsciiData
 37{
 38   struct KeyData
 39   {
 40      U16   ascii;
 41      bool  isDeadChar;
 42   };
 43
 44   KeyData upper;
 45   KeyData lower;
 46   KeyData goofy;
 47};
 48
 49struct _SDL_Joystick;
 50
 51struct JoystickAxisInfo
 52{
 53      S32 type;
 54      S32 minValue;
 55      S32 maxValue;
 56};
 57
 58//------------------------------------------------------------------------------
 59class JoystickInputDevice : public InputDevice
 60{   
 61  public:
 62    JoystickInputDevice(U8 deviceID);
 63    ~JoystickInputDevice();
 64    
 65    bool activate();
 66    bool deactivate();
 67    bool isActive() { return( mActive ); }
 68    
 69    U8 getDeviceType() { return( JoystickDeviceType ); }
 70    U8 getDeviceID() { return( mDeviceID ); }
 71    const char* getName();
 72    const char* getJoystickAxesString();
 73
 74    void loadJoystickInfo();
 75    void loadAxisInfo();
 76    JoystickAxisInfo& getAxisInfo(int axisNum) { return mAxisList[axisNum]; }
 77
 78    bool process();
 79    void reset();
 80    
 81  private:
 82    bool mActive;
 83    U8 mDeviceID;
 84    SDL_Joystick* mStick;
 85    Vector<JoystickAxisInfo> mAxisList;
 86    Vector<bool> mButtonState;
 87    Vector<U8> mHatState;
 88
 89    S32 mNumAxes; 
 90    S32 mNumButtons;
 91    S32 mNumHats;
 92    S32 mNumBalls;
 93};
 94
 95//------------------------------------------------------------------------------
 96class UInputManager : public InputManager
 97{
 98   friend bool JoystickInputDevice::process(); // for joystick event funcs
 99   friend void JoystickInputDevice::reset(); 
100
101   public:
102      UInputManager();
103
104      void init();
105      bool enable();
106      void disable();
107      void activate();
108      void deactivate();
109      void setWindowLocked(bool locked);
110      bool isActive()               { return( mActive ); }
111
112      void onDeleteNotify( SimObject* object );
113      bool onAdd();
114      void onRemove();
115
116      void process();
117
118      bool enableKeyboard();
119      void disableKeyboard();
120      bool isKeyboardEnabled()      { return( mKeyboardEnabled ); }
121      bool activateKeyboard();
122      void deactivateKeyboard();
123      bool isKeyboardActive()       { return( mKeyboardActive ); }
124
125      bool enableMouse();
126      void disableMouse();
127      bool isMouseEnabled()         { return( mMouseEnabled ); }
128      bool activateMouse();
129      void deactivateMouse();
130      bool isMouseActive()          { return( mMouseActive ); }          
131
132      bool enableJoystick();
133      void disableJoystick();
134      bool isJoystickEnabled()      { return( mJoystickEnabled ); }
135      bool activateJoystick();
136      void deactivateJoystick();
137      bool isJoystickActive()       { return( mJoystickActive ); }          
138
139      void setLocking(bool enabled);
140      bool getLocking() { return mLocking; }
141
142      const char* getJoystickAxesString( U32 deviceID );
143      bool joystickDetected()       { return mJoystickList.size() > 0; }
144   private:
145      typedef SimGroup Parent;
146      // the following vector is just for quick access during event processing.
147      // it does not manage the cleanup of the JoystickInputDevice objects
148      Vector<JoystickInputDevice*> mJoystickList;
149
150      bool mKeyboardEnabled;
151      bool mMouseEnabled;
152      bool mJoystickEnabled;
153
154      bool mKeyboardActive;
155      bool mMouseActive;
156      bool mJoystickActive;
157
158      bool mActive;
159
160      // Device state variables
161      S32 mModifierKeys;
162      bool mKeyboardState[256];
163      bool mMouseButtonState[3];
164
165      // last mousex and y are maintained when window is unlocked
166      S32 mLastMouseX;
167      S32 mLastMouseY;
168
169      void initJoystick();
170
171      void resetKeyboardState();
172      void resetMouseState();
173      void resetInputState();
174
175      void lockInput();
176      void unlockInput();
177      bool mLocking;
178
179      void joyHatEvent(U8 deviceID, U8 hatNum, 
180          U8 prevHatState, U8 currHatState);
181      void joyButtonEvent(U8 deviceID, U8 buttonNum, bool pressed);
182      void joyButtonEvent(const SDL_Event& event);
183      void joyAxisEvent(const SDL_Event& event);
184      void joyAxisEvent(U8 deviceID, U8 axisNum, S16 axisValue);
185      void mouseButtonEvent(const SDL_Event& event);
186      void mouseMotionEvent(const SDL_Event& event);
187      void keyEvent(const SDL_Event& event);
188      bool processKeyEvent(InputEventInfo &event);
189};
190
191#endif  // _H_X86UNIXINPUTMANAGER_
192