19
19
* You should have received a copy of the GNU General Public License
20
20
* along with this program; if not, write to the Free Software Foundation,
21
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
23
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24
24
* All rights reserved.
49
45
SCA_MouseSensor::SCA_MouseSensor(SCA_MouseManager* eventmgr,
50
46
int startx,int starty,
51
47
short int mousemode,
54
: SCA_ISensor(gameobj,eventmgr, T),
49
: SCA_ISensor(gameobj,eventmgr),
58
53
m_mousemode = mousemode;
59
54
m_triggermode = true;
61
UpdateHotkey(this, NULL);
73
68
/* Nothing to be done here. */
76
int SCA_MouseSensor::UpdateHotkey(void *self, const PyAttributeDef*)
71
void SCA_MouseSensor::UpdateHotkey(void *self)
78
73
// gosh, this function is so damn stupid
79
74
// its here because of a design mistake in the mouse sensor, it should only
102
97
; /* ignore, no hotkey */
104
// return value is used in py_setattro(),
105
// 0=attribute checked ok (see Attributes array definition)
109
101
CValue* SCA_MouseSensor::GetReplica()
240
232
return ((m > KX_MOUSESENSORMODE_NODEF) && (m < KX_MOUSESENSORMODE_MAX));
243
237
/* ------------------------------------------------------------------------- */
244
238
/* Python functions */
245
239
/* ------------------------------------------------------------------------- */
247
//Deprecated functions ------>
248
/* get x position ---------------------------------------------------------- */
249
const char SCA_MouseSensor::GetXPosition_doc[] =
251
"\tReturns the x-coordinate of the mouse sensor, in frame coordinates.\n"
252
"\tThe lower-left corner is the origin. The coordinate is given in\n"
254
PyObject* SCA_MouseSensor::PyGetXPosition() {
255
ShowDeprecationWarning("getXPosition()", "the position property");
256
return PyInt_FromLong(m_x);
259
/* get y position ---------------------------------------------------------- */
260
const char SCA_MouseSensor::GetYPosition_doc[] =
262
"\tReturns the y-coordinate of the mouse sensor, in frame coordinates.\n"
263
"\tThe lower-left corner is the origin. The coordinate is given in\n"
265
PyObject* SCA_MouseSensor::PyGetYPosition() {
266
ShowDeprecationWarning("getYPosition()", "the position property");
267
return PyInt_FromLong(m_y);
271
241
KX_PYMETHODDEF_DOC_O(SCA_MouseSensor, getButtonStatus,
272
242
"getButtonStatus(button)\n"
273
243
"\tGet the given button's status (KX_INPUT_NONE, KX_INPUT_NONE, KX_INPUT_JUST_ACTIVATED, KX_INPUT_ACTIVE, KX_INPUT_JUST_RELEASED).\n")
275
if (PyInt_Check(value))
245
if (PyLong_Check(value))
277
int button = PyInt_AsLong(value);
247
int button = PyLong_AsSsize_t(value);
279
249
if ((button < SCA_IInputDevice::KX_LEFTMOUSE)
280
250
|| (button > SCA_IInputDevice::KX_RIGHTMOUSE)){
285
255
SCA_IInputDevice* mousedev = ((SCA_MouseManager *)m_eventmgr)->GetInputDevice();
286
256
const SCA_InputEvent& event = mousedev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) button);
287
return PyInt_FromLong(event.m_status);
257
return PyLong_FromSsize_t(event.m_status);
295
265
/* ------------------------------------------------------------------------- */
297
267
PyTypeObject SCA_MouseSensor::Type = {
298
#if (PY_VERSION_HEX >= 0x02060000)
299
268
PyVarObject_HEAD_INIT(NULL, 0)
301
/* python 2.5 and below */
302
PyObject_HEAD_INIT( NULL ) /* required py macro */
305
269
"SCA_MouseSensor",
306
270
sizeof(PyObjectPlus_Proxy),
317
278
0,0,0,0,0,0,0,0,0,
321
PyParentObject SCA_MouseSensor::Parents[] = {
322
&SCA_MouseSensor::Type,
279
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
323
284
&SCA_ISensor::Type,
324
&SCA_ILogicBrick::Type,
329
289
PyMethodDef SCA_MouseSensor::Methods[] = {
330
//Deprecated functions ------>
331
{"getXPosition", (PyCFunction) SCA_MouseSensor::sPyGetXPosition, METH_VARARGS, (PY_METHODCHAR)GetXPosition_doc},
332
{"getYPosition", (PyCFunction) SCA_MouseSensor::sPyGetYPosition, METH_VARARGS, (PY_METHODCHAR)GetYPosition_doc},
334
290
KX_PYMETHODTABLE_O(SCA_MouseSensor, getButtonStatus),
335
291
{NULL,NULL} //Sentinel
294
int SCA_MouseSensor::UpdateHotkeyPy(void *self, const PyAttributeDef*)
297
// return value is used in py_setattro(),
298
// 0=attribute checked ok (see Attributes array definition)
338
302
PyAttributeDef SCA_MouseSensor::Attributes[] = {
339
KX_PYATTRIBUTE_SHORT_RW_CHECK("mode",KX_MOUSESENSORMODE_NODEF,KX_MOUSESENSORMODE_MAX-1,true,SCA_MouseSensor,m_mousemode,UpdateHotkey),
303
KX_PYATTRIBUTE_SHORT_RW_CHECK("mode",KX_MOUSESENSORMODE_NODEF,KX_MOUSESENSORMODE_MAX-1,true,SCA_MouseSensor,m_mousemode,UpdateHotkeyPy),
340
304
KX_PYATTRIBUTE_SHORT_LIST_RO("position",SCA_MouseSensor,m_x,2),
341
305
{ NULL } //Sentinel
344
PyObject* SCA_MouseSensor::py_getattro(PyObject *attr)
346
py_getattro_up(SCA_ISensor);
349
PyObject* SCA_MouseSensor::py_getattro_dict() {
350
py_getattro_dict_up(SCA_ISensor);
353
int SCA_MouseSensor::py_setattro(PyObject *attr, PyObject *value)
355
py_setattro_up(SCA_ISensor);
308
#endif // WITH_PYTHON