Added Joystick sensor (from snailrose)
[blender.git] / source / gameengine / GameLogic / SCA_JoystickSensor.h
1 /**
2  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. The Blender
8  * Foundation also sells licenses for use in proprietary software under
9  * the Blender License.  See http://www.blender.org/BL/ for information
10  * about this.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20  *
21  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
22  * All rights reserved.
23  *
24  * The Original Code is: all of this file.
25  *
26  * Contributor(s): none yet.
27  *
28  * ***** END GPL/BL DUAL LICENSE BLOCK *****
29  */
30
31
32 #ifndef __JOYSENSOR_H_
33 #define __JOYSENSOR_H
34
35 #include "SCA_ISensor.h"
36
37 class SCA_JoystickSensor :public SCA_ISensor
38 {
39         Py_Header;
40         class SCA_JoystickManager*      m_pJoystickMgr;
41         
42         /**
43          * Axis 1-or-2
44          */
45         int     m_axis;
46         /**
47          * Axis flag to find direction
48          */
49         int     m_axisf;
50         /**
51          * The actual button
52          */
53         int     m_button;
54         /**
55          * Flag for a pressed or released button
56          */
57         int     m_buttonf;
58         /**
59          * The actual hat
60          */
61         int     m_hat;
62         /**
63          * Flag to find direction 1-12
64          */
65         int     m_hatf;
66         /**
67          * The threshold value the axis acts opon
68          */
69         int     m_precision;
70         /**
71          * Is an event triggered ?
72          */
73         bool    m_istrig;
74         /**
75          * The mode to determine axis,button or hat
76          */
77         short int m_joymode;
78
79         enum KX_JOYSENSORMODE {
80                 KX_JOYSENSORMODE_NODEF = 0,
81                 KX_JOYSENSORMODE_AXIS,
82                 KX_JOYSENSORMODE_BUTTON,
83                 KX_JOYSENSORMODE_HAT,
84                 KX_JOYSENSORMODE_MAX
85         };
86         bool isValid(KX_JOYSENSORMODE);
87
88 public:
89         SCA_JoystickSensor(class SCA_JoystickManager* eventmgr,
90                                            SCA_IObject* gameobj,
91                                            short int joymode,
92                                            int axis, int axisf,int prec,
93                                            int button, int buttonf,
94                                            int hat, int hatf,
95                                            PyTypeObject* T=&Type );
96         virtual ~SCA_JoystickSensor();
97         virtual CValue* GetReplica();
98         
99         virtual bool Evaluate(CValue* event);
100         virtual bool IsPositiveTrigger();
101         
102         /* --------------------------------------------------------------------- */
103         /* Python interface ---------------------------------------------------- */
104         /* --------------------------------------------------------------------- */
105
106         virtual PyObject* _getattr(const STR_String& attr);
107
108         /* Axes*/
109         KX_PYMETHOD_DOC(SCA_JoystickSensor,GetAxis);
110         KX_PYMETHOD_DOC(SCA_JoystickSensor,SetAxis);
111         KX_PYMETHOD_DOC(SCA_JoystickSensor,GetRealAxis);
112         KX_PYMETHOD_DOC(SCA_JoystickSensor,GetThreshold);
113         KX_PYMETHOD_DOC(SCA_JoystickSensor,SetThreshold);
114         /* Buttons */
115         KX_PYMETHOD_DOC(SCA_JoystickSensor,GetButton);
116         KX_PYMETHOD_DOC(SCA_JoystickSensor,SetButton);
117         /* Hats */
118         KX_PYMETHOD_DOC(SCA_JoystickSensor,GetHat);
119         KX_PYMETHOD_DOC(SCA_JoystickSensor,SetHat);
120         /* number of */
121         KX_PYMETHOD_DOC(SCA_JoystickSensor,NumberOfAxes);
122         KX_PYMETHOD_DOC(SCA_JoystickSensor,NumberOfButtons);
123         KX_PYMETHOD_DOC(SCA_JoystickSensor,NumberOfHats);
124         
125 };
126
127 #endif