Blender V2.61 - r43446

SCA_Joystick.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): snailrose.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00032 #ifndef _SCA_JOYSTICK_H_
00033 #define _SCA_JOYSTICK_H_
00034 
00035 #include "SCA_JoystickDefines.h"
00036 #ifdef WITH_SDL
00037 #  include "SDL.h"
00038 #endif
00039 
00047 class SCA_Joystick
00048 
00049 {
00050     static SCA_Joystick *m_instance[JOYINDEX_MAX];
00051     static int m_joynum;
00052     static int m_refCount;
00053 
00054     class PrivateData;
00055 #ifdef WITH_SDL
00056     PrivateData     *m_private;
00057 #endif
00058     int             m_joyindex;
00059 
00063     int m_axis_array[JOYAXIS_MAX];
00064 
00068     int m_hat_array[JOYHAT_MAX];    
00069     
00073     int             m_prec;
00074 
00079     int             m_axismax;
00080     int             m_buttonmax;
00081     int             m_hatmax;
00082     
00084     bool            m_isinit;
00085 
00086     
00088     bool            m_istrig_axis;
00089     bool            m_istrig_button;
00090     bool            m_istrig_hat;
00091 
00092 #ifdef WITH_SDL
00093 
00096     void OnAxisMotion(SDL_Event *sdl_event);
00097     void OnHatMotion(SDL_Event *sdl_event);
00098     void OnButtonUp(SDL_Event *sdl_event);
00099     void OnButtonDown(SDL_Event *sdl_event);
00100     void OnNothing(SDL_Event *sdl_event);
00101 #if 0 /* not used yet */
00102     void OnBallMotion(SDL_Event *sdl_event){}
00103 #endif
00104         
00105 #endif /* WITH_SDL */
00106 
00109     bool CreateJoystickDevice(void);
00110 
00114     void DestroyJoystickDevice(void);
00115 
00119     void pFillButtons(void);
00120 
00125     int pAxisTest(int axisnum);
00129     int pGetAxis(int axisnum, int udlr);
00130 
00131     SCA_Joystick(short int index);
00132 
00133     ~SCA_Joystick();
00134     
00135 public:
00136 
00137     static SCA_Joystick *GetInstance( short int joyindex );
00138     static void HandleEvents( void );
00139     void ReleaseInstance();
00140     
00141 
00142     /*
00143      */
00144     bool aAxisPairIsPositive(int axis);
00145     bool aAxisPairDirectionIsPositive(int axis, int dir); /* function assumes joysticks are in axis pairs */
00146     bool aAxisIsPositive(int axis_single); /* check a single axis only */
00147 
00148     bool aAnyButtonPressIsPositive(void);
00149     bool aButtonPressIsPositive(int button);
00150     bool aButtonReleaseIsPositive(int button);
00151     bool aHatIsPositive(int hatnum, int dir);
00152 
00157     void cSetPrecision(int val);
00158 
00159     int GetAxisPosition(int index){
00160         return m_axis_array[index];
00161     }
00162 
00163     int GetHat(int index){
00164         return m_hat_array[index];
00165     }
00166 
00167     int GetThreshold(void){
00168         return m_prec;
00169     }
00170 
00171     bool IsTrigAxis(void){
00172         return m_istrig_axis;
00173     }
00174     
00175     bool IsTrigButton(void){
00176         return m_istrig_button;
00177     }
00178     
00179     bool IsTrigHat(void){
00180         return m_istrig_hat;
00181     }
00182 
00187     int GetNumberOfAxes(void);
00188     int GetNumberOfButtons(void);
00189     int GetNumberOfHats(void);
00190     
00194     int Connected(void);
00195 };
00196 #ifdef WITH_SDL
00197 void Joystick_HandleEvents( void );
00198 #endif
00199 
00200 #endif
00201