forked from bartvdbraak/blender
BGE python api for get/setting the joystick index, minor cleanup also.
This commit is contained in:
parent
234b616078
commit
e8049903ac
@ -295,6 +295,8 @@ PyParentObject SCA_JoystickSensor::Parents[] = {
|
||||
|
||||
|
||||
PyMethodDef SCA_JoystickSensor::Methods[] = {
|
||||
{"getIndex", (PyCFunction) SCA_JoystickSensor::sPyGetIndex, METH_NOARGS, GetIndex_doc},
|
||||
{"setIndex", (PyCFunction) SCA_JoystickSensor::sPySetIndex, METH_O, SetIndex_doc},
|
||||
{"getAxis", (PyCFunction) SCA_JoystickSensor::sPyGetAxis, METH_NOARGS, GetAxis_doc},
|
||||
{"setAxis", (PyCFunction) SCA_JoystickSensor::sPySetAxis, METH_VARARGS, SetAxis_doc},
|
||||
{"getAxisValue", (PyCFunction) SCA_JoystickSensor::sPyGetRealAxis, METH_NOARGS, GetRealAxis_doc},
|
||||
@ -316,14 +318,36 @@ PyObject* SCA_JoystickSensor::_getattr(const STR_String& attr) {
|
||||
}
|
||||
|
||||
|
||||
/* get index ---------------------------------------------------------- */
|
||||
char SCA_JoystickSensor::GetIndex_doc[] =
|
||||
"getIndex\n"
|
||||
"\tReturns the joystick index to use.\n";
|
||||
PyObject* SCA_JoystickSensor::PyGetIndex( PyObject* self ) {
|
||||
return PyInt_FromLong(m_joyindex);
|
||||
}
|
||||
|
||||
|
||||
/* set index ---------------------------------------------------------- */
|
||||
char SCA_JoystickSensor::SetIndex_doc[] =
|
||||
"setIndex\n"
|
||||
"\tSets the joystick index to use.\n";
|
||||
PyObject* SCA_JoystickSensor::PySetIndex( PyObject* self, PyObject* value ) {
|
||||
int index = PyInt_AsLong( value ); /* -1 on error, will raise an error in this case */
|
||||
if (index < 0 or index >= JOYINDEX_MAX) {
|
||||
PyErr_SetString(PyExc_ValueError, "joystick index out of range or not an int");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
m_joyindex = index;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/* get axis ---------------------------------------------------------- */
|
||||
char SCA_JoystickSensor::GetAxis_doc[] =
|
||||
"getAxis\n"
|
||||
"\tReturns the current state of the axis.\n";
|
||||
PyObject* SCA_JoystickSensor::PyGetAxis( PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds) {
|
||||
return Py_BuildValue("[ii]",m_axis, m_axisf);
|
||||
PyObject* SCA_JoystickSensor::PyGetAxis( PyObject* self) {
|
||||
return PyInt_FromLong(m_joyindex);
|
||||
}
|
||||
|
||||
|
||||
@ -331,9 +355,7 @@ PyObject* SCA_JoystickSensor::PyGetAxis( PyObject* self,
|
||||
char SCA_JoystickSensor::SetAxis_doc[] =
|
||||
"setAxis\n"
|
||||
"\tSets the current state of the axis.\n";
|
||||
PyObject* SCA_JoystickSensor::PySetAxis( PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds) {
|
||||
PyObject* SCA_JoystickSensor::PySetAxis( PyObject* self, PyObject* args ) {
|
||||
|
||||
int axis,axisflag;
|
||||
if(!PyArg_ParseTuple(args, "ii", &axis, &axisflag)){
|
||||
@ -341,7 +363,7 @@ PyObject* SCA_JoystickSensor::PySetAxis( PyObject* self,
|
||||
}
|
||||
m_axis = axis;
|
||||
m_axisf = axisflag;
|
||||
Py_Return;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
@ -349,16 +371,9 @@ PyObject* SCA_JoystickSensor::PySetAxis( PyObject* self,
|
||||
char SCA_JoystickSensor::GetRealAxis_doc[] =
|
||||
"getAxisValue\n"
|
||||
"\tReturns a list of the values for each axis .\n";
|
||||
PyObject* SCA_JoystickSensor::PyGetRealAxis( PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds) {
|
||||
int a,b,c,d;
|
||||
PyObject* SCA_JoystickSensor::PyGetRealAxis( PyObject* self) {
|
||||
SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
|
||||
a = joy->GetAxis10();
|
||||
b = joy->GetAxis11();
|
||||
c = joy->GetAxis20();
|
||||
d = joy->GetAxis21();
|
||||
return Py_BuildValue("[iiii]",a,b,c,d);
|
||||
return Py_BuildValue("[iiii]", joy->GetAxis10(), joy->GetAxis11(), joy->GetAxis20(), joy->GetAxis21());
|
||||
}
|
||||
|
||||
|
||||
@ -366,10 +381,8 @@ PyObject* SCA_JoystickSensor::PyGetRealAxis( PyObject* self,
|
||||
char SCA_JoystickSensor::GetThreshold_doc[] =
|
||||
"getThreshold\n"
|
||||
"\tReturns the threshold of the axis.\n";
|
||||
PyObject* SCA_JoystickSensor::PyGetThreshold( PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds) {
|
||||
return Py_BuildValue("i", m_precision);
|
||||
PyObject* SCA_JoystickSensor::PyGetThreshold( PyObject* self) {
|
||||
return PyInt_FromLong(m_precision);
|
||||
}
|
||||
|
||||
|
||||
@ -377,15 +390,13 @@ PyObject* SCA_JoystickSensor::PyGetThreshold( PyObject* self,
|
||||
char SCA_JoystickSensor::SetThreshold_doc[] =
|
||||
"setThreshold\n"
|
||||
"\tSets the threshold of the axis.\n";
|
||||
PyObject* SCA_JoystickSensor::PySetThreshold( PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds) {
|
||||
PyObject* SCA_JoystickSensor::PySetThreshold( PyObject* self, PyObject* args ) {
|
||||
int thresh;
|
||||
if(!PyArg_ParseTuple(args, "i", &thresh)){
|
||||
return NULL;
|
||||
}
|
||||
m_precision = thresh;
|
||||
Py_Return;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
@ -393,9 +404,7 @@ PyObject* SCA_JoystickSensor::PySetThreshold( PyObject* self,
|
||||
char SCA_JoystickSensor::GetButton_doc[] =
|
||||
"getButton\n"
|
||||
"\tReturns the currently pressed button.\n";
|
||||
PyObject* SCA_JoystickSensor::PyGetButton( PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds) {
|
||||
PyObject* SCA_JoystickSensor::PyGetButton( PyObject* self) {
|
||||
return Py_BuildValue("[ii]",m_button, m_buttonf);
|
||||
}
|
||||
|
||||
@ -404,16 +413,14 @@ PyObject* SCA_JoystickSensor::PyGetButton( PyObject* self,
|
||||
char SCA_JoystickSensor::SetButton_doc[] =
|
||||
"setButton\n"
|
||||
"\tSets the button the sensor reacts to.\n";
|
||||
PyObject* SCA_JoystickSensor::PySetButton( PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds) {
|
||||
PyObject* SCA_JoystickSensor::PySetButton( PyObject* self, PyObject* args ) {
|
||||
int button,buttonflag;
|
||||
if(!PyArg_ParseTuple(args, "ii", &button, &buttonflag)){
|
||||
return NULL;
|
||||
}
|
||||
m_button = button;
|
||||
m_buttonf = buttonflag;
|
||||
Py_Return;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
@ -421,9 +428,7 @@ PyObject* SCA_JoystickSensor::PySetButton( PyObject* self,
|
||||
char SCA_JoystickSensor::GetHat_doc[] =
|
||||
"getHat\n"
|
||||
"\tReturns the current direction of the hat.\n";
|
||||
PyObject* SCA_JoystickSensor::PyGetHat( PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds) {
|
||||
PyObject* SCA_JoystickSensor::PyGetHat( PyObject* self ) {
|
||||
return Py_BuildValue("[ii]",m_hat, m_hatf);
|
||||
}
|
||||
|
||||
@ -432,16 +437,14 @@ PyObject* SCA_JoystickSensor::PyGetHat( PyObject* self,
|
||||
char SCA_JoystickSensor::SetHat_doc[] =
|
||||
"setHat\n"
|
||||
"\tSets the hat the sensor reacts to.\n";
|
||||
PyObject* SCA_JoystickSensor::PySetHat( PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds) {
|
||||
PyObject* SCA_JoystickSensor::PySetHat( PyObject* self, PyObject* args ) {
|
||||
int hat,hatflag;
|
||||
if(!PyArg_ParseTuple(args, "ii", &hat, &hatflag)){
|
||||
return NULL;
|
||||
}
|
||||
m_hat = hat;
|
||||
m_hatf = hatflag;
|
||||
Py_Return;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
@ -449,37 +452,25 @@ PyObject* SCA_JoystickSensor::PySetHat( PyObject* self,
|
||||
char SCA_JoystickSensor::NumberOfAxes_doc[] =
|
||||
"getNumAxes\n"
|
||||
"\tReturns the number of axes .\n";
|
||||
PyObject* SCA_JoystickSensor::PyNumberOfAxes( PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds) {
|
||||
int num;
|
||||
PyObject* SCA_JoystickSensor::PyNumberOfAxes( PyObject* self ) {
|
||||
SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
|
||||
num = joy->GetNumberOfAxes();
|
||||
return Py_BuildValue("i",num);
|
||||
return PyInt_FromLong( joy->GetNumberOfAxes() );
|
||||
}
|
||||
|
||||
|
||||
char SCA_JoystickSensor::NumberOfButtons_doc[] =
|
||||
"getNumButtons\n"
|
||||
"\tReturns the number of buttons .\n";
|
||||
PyObject* SCA_JoystickSensor::PyNumberOfButtons( PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds) {
|
||||
int num;
|
||||
PyObject* SCA_JoystickSensor::PyNumberOfButtons( PyObject* self ) {
|
||||
SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
|
||||
num = joy->GetNumberOfButtons();
|
||||
return Py_BuildValue("i",num);
|
||||
return PyInt_FromLong( joy->GetNumberOfButtons() );
|
||||
}
|
||||
|
||||
|
||||
char SCA_JoystickSensor::NumberOfHats_doc[] =
|
||||
"getNumHats\n"
|
||||
"\tReturns the number of hats .\n";
|
||||
PyObject* SCA_JoystickSensor::PyNumberOfHats( PyObject* self,
|
||||
PyObject* args,
|
||||
PyObject* kwds) {
|
||||
int num;
|
||||
PyObject* SCA_JoystickSensor::PyNumberOfHats( PyObject* self ) {
|
||||
SCA_Joystick *joy = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
|
||||
num = joy->GetNumberOfHats();
|
||||
return Py_BuildValue("i",num);
|
||||
return PyInt_FromLong( joy->GetNumberOfHats() );
|
||||
}
|
||||
|
@ -112,22 +112,25 @@ public:
|
||||
|
||||
virtual PyObject* _getattr(const STR_String& attr);
|
||||
|
||||
/* Joystick Index */
|
||||
KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,GetIndex);
|
||||
KX_PYMETHOD_DOC_O(SCA_JoystickSensor,SetIndex);
|
||||
/* Axes*/
|
||||
KX_PYMETHOD_DOC(SCA_JoystickSensor,GetAxis);
|
||||
KX_PYMETHOD_DOC(SCA_JoystickSensor,SetAxis);
|
||||
KX_PYMETHOD_DOC(SCA_JoystickSensor,GetRealAxis);
|
||||
KX_PYMETHOD_DOC(SCA_JoystickSensor,GetThreshold);
|
||||
KX_PYMETHOD_DOC(SCA_JoystickSensor,SetThreshold);
|
||||
KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,GetAxis);
|
||||
KX_PYMETHOD_DOC_VARARGS(SCA_JoystickSensor,SetAxis);
|
||||
KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,GetRealAxis);
|
||||
KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,GetThreshold);
|
||||
KX_PYMETHOD_DOC_VARARGS(SCA_JoystickSensor,SetThreshold);
|
||||
/* Buttons */
|
||||
KX_PYMETHOD_DOC(SCA_JoystickSensor,GetButton);
|
||||
KX_PYMETHOD_DOC(SCA_JoystickSensor,SetButton);
|
||||
KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,GetButton);
|
||||
KX_PYMETHOD_DOC_VARARGS(SCA_JoystickSensor,SetButton);
|
||||
/* Hats */
|
||||
KX_PYMETHOD_DOC(SCA_JoystickSensor,GetHat);
|
||||
KX_PYMETHOD_DOC(SCA_JoystickSensor,SetHat);
|
||||
KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,GetHat);
|
||||
KX_PYMETHOD_DOC_VARARGS(SCA_JoystickSensor,SetHat);
|
||||
/* number of */
|
||||
KX_PYMETHOD_DOC(SCA_JoystickSensor,NumberOfAxes);
|
||||
KX_PYMETHOD_DOC(SCA_JoystickSensor,NumberOfButtons);
|
||||
KX_PYMETHOD_DOC(SCA_JoystickSensor,NumberOfHats);
|
||||
KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,NumberOfAxes);
|
||||
KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,NumberOfButtons);
|
||||
KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,NumberOfHats);
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user