Blender V2.61 - r43446

SCA_PythonKeyboard.cpp

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * Contributor(s): none yet.
00019  *
00020  * ***** END GPL LICENSE BLOCK *****
00021  */
00022 
00028 #include "SCA_PythonKeyboard.h"
00029 #include "SCA_IInputDevice.h"
00030 
00031 /* ------------------------------------------------------------------------- */
00032 /* Native functions                                                          */
00033 /* ------------------------------------------------------------------------- */
00034 
00035 SCA_PythonKeyboard::SCA_PythonKeyboard(SCA_IInputDevice* keyboard)
00036 : PyObjectPlus(),
00037 m_keyboard(keyboard)
00038 {
00039 #ifdef WITH_PYTHON
00040     m_event_dict = PyDict_New();
00041 #endif
00042 }
00043 
00044 SCA_PythonKeyboard::~SCA_PythonKeyboard()
00045 {
00046 #ifdef WITH_PYTHON
00047     PyDict_Clear(m_event_dict);
00048     Py_DECREF(m_event_dict);
00049 #endif
00050 }
00051 
00052 #ifdef WITH_PYTHON
00053 
00054 /* ------------------------------------------------------------------------- */
00055 /* Python functions                                                          */
00056 /* ------------------------------------------------------------------------- */
00057 
00058 /* Integration hooks ------------------------------------------------------- */
00059 PyTypeObject SCA_PythonKeyboard::Type = {
00060     PyVarObject_HEAD_INIT(NULL, 0)
00061     "SCA_PythonKeyboard",
00062     sizeof(PyObjectPlus_Proxy),
00063     0,
00064     py_base_dealloc,
00065     0,
00066     0,
00067     0,
00068     0,
00069     py_base_repr,
00070     0,0,0,0,0,0,0,0,0,
00071     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
00072     0,0,0,0,0,0,0,
00073     Methods,
00074     0,
00075     0,
00076     &PyObjectPlus::Type,
00077     0,0,0,0,0,0,
00078     py_base_new
00079 };
00080 
00081 PyMethodDef SCA_PythonKeyboard::Methods[] = {
00082     {NULL,NULL} //Sentinel
00083 };
00084 
00085 PyAttributeDef SCA_PythonKeyboard::Attributes[] = {
00086     KX_PYATTRIBUTE_RO_FUNCTION("events", SCA_PythonKeyboard, pyattr_get_events),
00087     { NULL }    //Sentinel
00088 };
00089 
00090 PyObject* SCA_PythonKeyboard::pyattr_get_events(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
00091 {
00092     SCA_PythonKeyboard* self = static_cast<SCA_PythonKeyboard*>(self_v);
00093     
00094     for (int i=SCA_IInputDevice::KX_BEGINKEY; i<=SCA_IInputDevice::KX_ENDKEY; i++)
00095     {
00096         const SCA_InputEvent & inevent = self->m_keyboard->GetEventValue((SCA_IInputDevice::KX_EnumInputs)i);
00097         
00098         PyDict_SetItem(self->m_event_dict, PyLong_FromSsize_t(i), PyLong_FromSsize_t(inevent.m_status));
00099     }
00100     Py_INCREF(self->m_event_dict);
00101     return self->m_event_dict;
00102 }
00103 
00104 #endif