rename and negate DISABLE_PYTHON --> WITH_PYTHON
[blender.git] / source / gameengine / GameLogic / SCA_PythonMouse.cpp
index 405c41103012f88e23232eb33fe7337e58e8fd43..7267eb74594d5f83820d14ed1c59fd15346c5084 100644 (file)
@@ -1,6 +1,4 @@
 /**
- * Python Mouse Object
- *
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
  * Contributor(s): none yet.
  *
  * ***** END GPL LICENSE BLOCK *****
  */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include "SCA_PythonMouse.h"
 #include "SCA_IInputDevice.h"
 #include "RAS_ICanvas.h"
 
 SCA_PythonMouse::SCA_PythonMouse(SCA_IInputDevice* mouse, RAS_ICanvas* canvas)
 : PyObjectPlus(),
-m_canvas(canvas),
-m_mouse(mouse)
+m_mouse(mouse),
+m_canvas(canvas)
 {
+#ifdef WITH_PYTHON
+       m_event_dict = PyDict_New();
+#endif
 }
 
 SCA_PythonMouse::~SCA_PythonMouse()
 {
-       /* intentionally empty */
+#ifdef WITH_PYTHON
+       PyDict_Clear(m_event_dict);
+       Py_DECREF(m_event_dict);
+#endif
 }
 
-#ifndef DISABLE_PYTHON
+#ifdef WITH_PYTHON
 
 /* ------------------------------------------------------------------------- */
 /* Python functions                                                          */
@@ -83,7 +78,6 @@ PyTypeObject SCA_PythonMouse::Type = {
 };
 
 PyMethodDef SCA_PythonMouse::Methods[] = {
-//     KX_PYMETHODTABLE(SCA_PythonMouse, show),
        {NULL,NULL} //Sentinel
 };
 
@@ -97,39 +91,35 @@ PyAttributeDef SCA_PythonMouse::Attributes[] = {
 PyObject* SCA_PythonMouse::pyattr_get_events(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
        SCA_PythonMouse* self = static_cast<SCA_PythonMouse*>(self_v);
-
-       PyObject* resultlist = PyList_New(0);
-
+       
        for (int i=SCA_IInputDevice::KX_BEGINMOUSE; i<=SCA_IInputDevice::KX_ENDMOUSE; i++)
        {
                const SCA_InputEvent & inevent = self->m_mouse->GetEventValue((SCA_IInputDevice::KX_EnumInputs)i);
                
-               
-               if (inevent.m_status != SCA_InputEvent::KX_NO_INPUTSTATUS)
-               {
-                       PyObject* keypair = PyList_New(2);
-                       PyList_SET_ITEM(keypair, 0, PyLong_FromSsize_t(i));
-                       PyList_SET_ITEM(keypair, 1, PyLong_FromSsize_t(inevent.m_status));
-                       PyList_Append(resultlist, keypair);
-               }
+               PyDict_SetItem(self->m_event_dict, PyLong_FromSsize_t(i), PyLong_FromSsize_t(inevent.m_status));
        }
-
-       return resultlist;
+       Py_INCREF(self->m_event_dict);
+       return self->m_event_dict;
 }
 
+
 PyObject* SCA_PythonMouse::pyattr_get_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
        SCA_PythonMouse* self = static_cast<SCA_PythonMouse*>(self_v);
        const SCA_InputEvent & xevent = self->m_mouse->GetEventValue(SCA_IInputDevice::KX_MOUSEX);
        const SCA_InputEvent & yevent = self->m_mouse->GetEventValue(SCA_IInputDevice::KX_MOUSEY);
 
-       PyObject* resultlist = PyList_New(2);
+       float x_coord, y_coord;
 
-       PyList_SET_ITEM(resultlist, 0, PyFloat_FromDouble(float(xevent.m_eventval)/self->m_canvas->GetWidth()));
-       
-       PyList_SET_ITEM(resultlist, 1, PyFloat_FromDouble(float(yevent.m_eventval)/self->m_canvas->GetHeight()));
+       x_coord = self->m_canvas->GetMouseNormalizedX(xevent.m_eventval);
+       y_coord = self->m_canvas->GetMouseNormalizedY(yevent.m_eventval);
+
+       PyObject* ret = PyTuple_New(2);
+
+       PyTuple_SET_ITEM(ret, 0, PyFloat_FromDouble(x_coord));
+       PyTuple_SET_ITEM(ret, 1, PyFloat_FromDouble(y_coord));
 
-       return resultlist;
+       return ret;
 }
 
 int SCA_PythonMouse::pyattr_set_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)