~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/gameengine/GameLogic/SCA_MouseSensor.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kevin Roy
  • Date: 2011-02-08 22:20:54 UTC
  • mfrom: (1.4.2 upstream)
  • mto: (14.2.6 sid) (1.5.1)
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: james.westby@ubuntu.com-20110208222054-kk0gwa4bu8h5lyq4
Tags: upstream-2.56.1-beta-svn34076
ImportĀ upstreamĀ versionĀ 2.56.1-beta-svn34076

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * Sensor for mouse input
3
3
 *
4
4
 *
5
 
 * $Id: SCA_MouseSensor.cpp 22701 2009-08-22 10:51:21Z campbellbarton $
 
5
 * $Id: SCA_MouseSensor.cpp 32788 2010-10-31 04:11:39Z campbellbarton $
6
6
 *
7
7
 * ***** BEGIN GPL LICENSE BLOCK *****
8
8
 *
18
18
 *
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.
22
22
 *
23
23
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24
24
 * All rights reserved.
38
38
#include "ConstExpr.h"
39
39
#include <iostream>
40
40
 
41
 
#ifdef HAVE_CONFIG_H
42
 
#include <config.h>
43
 
#endif
44
 
 
45
41
/* ------------------------------------------------------------------------- */
46
42
/* Native functions                                                          */
47
43
/* ------------------------------------------------------------------------- */
49
45
SCA_MouseSensor::SCA_MouseSensor(SCA_MouseManager* eventmgr, 
50
46
                                                                 int startx,int starty,
51
47
                                                                 short int mousemode,
52
 
                                                                 SCA_IObject* gameobj, 
53
 
                                                                 PyTypeObject* T)
54
 
    : SCA_ISensor(gameobj,eventmgr, T),
 
48
                                                                 SCA_IObject* gameobj)
 
49
    : SCA_ISensor(gameobj,eventmgr),
55
50
        m_x(startx),
56
51
        m_y(starty)
57
52
{
58
53
        m_mousemode   = mousemode;
59
54
        m_triggermode = true;
60
55
 
61
 
        UpdateHotkey(this, NULL);
 
56
        UpdateHotkey(this);
62
57
        Init();
63
58
}
64
59
 
73
68
    /* Nothing to be done here. */
74
69
}
75
70
 
76
 
int SCA_MouseSensor::UpdateHotkey(void *self, const PyAttributeDef*)
 
71
void SCA_MouseSensor::UpdateHotkey(void *self)
77
72
{
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
101
96
        default:
102
97
                ; /* ignore, no hotkey */
103
98
        }
104
 
        // return value is used in py_setattro(), 
105
 
        // 0=attribute checked ok (see Attributes array definition)
106
 
        return 0;
107
99
}
108
100
 
109
101
CValue* SCA_MouseSensor::GetReplica()
240
232
        return ((m > KX_MOUSESENSORMODE_NODEF) && (m < KX_MOUSESENSORMODE_MAX));
241
233
}
242
234
 
 
235
#ifdef WITH_PYTHON
 
236
 
243
237
/* ------------------------------------------------------------------------- */
244
238
/* Python functions                                                          */
245
239
/* ------------------------------------------------------------------------- */
246
240
 
247
 
//Deprecated functions ------>
248
 
/* get x position ---------------------------------------------------------- */
249
 
const char SCA_MouseSensor::GetXPosition_doc[] = 
250
 
"getXPosition\n"
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"
253
 
"\tpixels\n";
254
 
PyObject* SCA_MouseSensor::PyGetXPosition() {
255
 
        ShowDeprecationWarning("getXPosition()", "the position property");
256
 
        return PyInt_FromLong(m_x);
257
 
}
258
 
 
259
 
/* get y position ---------------------------------------------------------- */
260
 
const char SCA_MouseSensor::GetYPosition_doc[] = 
261
 
"getYPosition\n"
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"
264
 
"\tpixels\n";
265
 
PyObject* SCA_MouseSensor::PyGetYPosition() {
266
 
        ShowDeprecationWarning("getYPosition()", "the position property");
267
 
        return PyInt_FromLong(m_y);
268
 
}
269
 
//<----- Deprecated
270
 
 
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")
274
244
{
275
 
        if (PyInt_Check(value))
 
245
        if (PyLong_Check(value))
276
246
        {
277
 
                int button = PyInt_AsLong(value);
 
247
                int button = PyLong_AsSsize_t(value);
278
248
                
279
249
                if ((button < SCA_IInputDevice::KX_LEFTMOUSE)
280
250
                        || (button > SCA_IInputDevice::KX_RIGHTMOUSE)){
284
254
                
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);
288
258
        }
289
259
        
290
260
        Py_RETURN_NONE;
295
265
/* ------------------------------------------------------------------------- */
296
266
 
297
267
PyTypeObject SCA_MouseSensor::Type = {
298
 
#if (PY_VERSION_HEX >= 0x02060000)
299
268
        PyVarObject_HEAD_INIT(NULL, 0)
300
 
#else
301
 
        /* python 2.5 and below */
302
 
        PyObject_HEAD_INIT( NULL )  /* required py macro */
303
 
        0,                          /* ob_size */
304
 
#endif
305
269
        "SCA_MouseSensor",
306
270
        sizeof(PyObjectPlus_Proxy),
307
271
        0,
311
275
        0,
312
276
        0,
313
277
        py_base_repr,
314
 
        0,0,0,0,0,0,
315
 
        py_base_getattro,
316
 
        py_base_setattro,
317
278
        0,0,0,0,0,0,0,0,0,
318
 
        Methods
319
 
};
320
 
 
321
 
PyParentObject SCA_MouseSensor::Parents[] = {
322
 
        &SCA_MouseSensor::Type,
 
279
        Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
 
280
        0,0,0,0,0,0,0,
 
281
        Methods,
 
282
        0,
 
283
        0,
323
284
        &SCA_ISensor::Type,
324
 
        &SCA_ILogicBrick::Type,
325
 
        &CValue::Type,
326
 
        NULL
 
285
        0,0,0,0,0,0,
 
286
        py_base_new
327
287
};
328
288
 
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},
333
 
        //<----- Deprecated
334
290
        KX_PYMETHODTABLE_O(SCA_MouseSensor, getButtonStatus),
335
291
        {NULL,NULL} //Sentinel
336
292
};
337
293
 
 
294
int SCA_MouseSensor::UpdateHotkeyPy(void *self, const PyAttributeDef*)
 
295
{
 
296
        UpdateHotkey(self);
 
297
        // return value is used in py_setattro(),
 
298
        // 0=attribute checked ok (see Attributes array definition)
 
299
        return 0;
 
300
}
 
301
 
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
342
306
};
343
307
 
344
 
PyObject* SCA_MouseSensor::py_getattro(PyObject *attr) 
345
 
{
346
 
        py_getattro_up(SCA_ISensor);
347
 
}
348
 
 
349
 
PyObject* SCA_MouseSensor::py_getattro_dict() {
350
 
        py_getattro_dict_up(SCA_ISensor);
351
 
}
352
 
 
353
 
int SCA_MouseSensor::py_setattro(PyObject *attr, PyObject *value)
354
 
{
355
 
        py_setattro_up(SCA_ISensor);
356
 
}
 
308
#endif // WITH_PYTHON
357
309
 
358
310
/* eof */