Blender  V2.59
SCA_JoystickSensor.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): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00033 #ifndef __JOYSENSOR_H_
00034 #define __JOYSENSOR_H
00035 
00036 #include "SCA_ISensor.h"
00037 #include "./Joystick/SCA_JoystickDefines.h"
00038 
00039 class SCA_JoystickSensor :public SCA_ISensor
00040 {
00041         Py_Header;
00042         
00046         int     m_axis;
00050         int     m_axisf;
00054         int     m_button;
00058         int     m_buttonf;
00062         int     m_hat;
00066         int     m_hatf;
00070         int     m_precision;
00074         bool    m_istrig;
00080         bool    m_istrig_prev;
00084         short int m_joymode;
00088         short int m_joyindex;
00089 
00093         bool m_bAllEvents;
00094 
00095         enum KX_JOYSENSORMODE {
00096                 KX_JOYSENSORMODE_NODEF = 0,
00097                 KX_JOYSENSORMODE_AXIS,
00098                 KX_JOYSENSORMODE_BUTTON,
00099                 KX_JOYSENSORMODE_HAT,
00100                 KX_JOYSENSORMODE_AXIS_SINGLE,
00101                 KX_JOYSENSORMODE_MAX
00102         };
00103         bool isValid(KX_JOYSENSORMODE);
00104 
00105 public:
00106         SCA_JoystickSensor(class SCA_JoystickManager* eventmgr,
00107                                            SCA_IObject* gameobj,
00108                                            short int joyindex,
00109                                            short int joymode,
00110                                            int axis, int axisf,int prec,
00111                                            int button,
00112                                            int hat, int hatf, bool allevents);
00113         virtual ~SCA_JoystickSensor();
00114         virtual CValue* GetReplica();
00115         
00116         virtual bool Evaluate();
00117         virtual bool IsPositiveTrigger();
00118         virtual void Init();
00119         
00120         short int GetJoyIndex(void){
00121                 return m_joyindex;
00122         }
00123 
00124 #ifdef WITH_PYTHON
00125 
00126         /* --------------------------------------------------------------------- */
00127         /* Python interface ---------------------------------------------------- */
00128         /* --------------------------------------------------------------------- */
00129 
00130         /* Joystick Index */
00131         KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,GetButtonActiveList);
00132         KX_PYMETHOD_DOC_VARARGS(SCA_JoystickSensor,GetButtonStatus);
00133 
00134         static PyObject*        pyattr_get_axis_values(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00135         static PyObject*        pyattr_get_axis_single(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00136         static PyObject*        pyattr_get_hat_values(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00137         static PyObject*        pyattr_get_hat_single(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00138         static PyObject*        pyattr_get_num_axis(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00139         static PyObject*        pyattr_get_num_buttons(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00140         static PyObject*        pyattr_get_num_hats(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00141         static PyObject*        pyattr_get_connected(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00142         
00143 
00144         /* attribute check */
00145         static int CheckAxis(void *self, const PyAttributeDef*)
00146         {
00147                 SCA_JoystickSensor* sensor = reinterpret_cast<SCA_JoystickSensor*>(self);
00148                 if (sensor->m_axis < 1)
00149                         sensor->m_axis = 1;
00150                 else if (sensor->m_axis > JOYAXIS_MAX)
00151                         sensor->m_axis = JOYAXIS_MAX;
00152                 return 0;
00153         }
00154         static int CheckHat(void *self, const PyAttributeDef*)
00155         {
00156                 SCA_JoystickSensor* sensor = reinterpret_cast<SCA_JoystickSensor*>(self);
00157                 if (sensor->m_hat < 1)
00158                         sensor->m_hat = 1;
00159                 else if (sensor->m_hat > JOYHAT_MAX)
00160                         sensor->m_hat = JOYHAT_MAX;
00161                 return 0;
00162         }
00163         
00164 #endif // WITH_PYTHON
00165 
00166 };
00167 
00168 #endif