doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / gameengine / GameLogic / SCA_PythonKeyboard.cpp
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * Contributor(s): none yet.
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 #include "SCA_PythonKeyboard.h"
26 #include "SCA_IInputDevice.h"
27
28 /* ------------------------------------------------------------------------- */
29 /* Native functions                                                          */
30 /* ------------------------------------------------------------------------- */
31
32 SCA_PythonKeyboard::SCA_PythonKeyboard(SCA_IInputDevice* keyboard)
33 : PyObjectPlus(),
34 m_keyboard(keyboard)
35 {
36 #ifdef WITH_PYTHON
37         m_event_dict = PyDict_New();
38 #endif
39 }
40
41 SCA_PythonKeyboard::~SCA_PythonKeyboard()
42 {
43 #ifdef WITH_PYTHON
44         PyDict_Clear(m_event_dict);
45         Py_DECREF(m_event_dict);
46 #endif
47 }
48
49 #ifdef WITH_PYTHON
50
51 /* ------------------------------------------------------------------------- */
52 /* Python functions                                                          */
53 /* ------------------------------------------------------------------------- */
54
55 /* Integration hooks ------------------------------------------------------- */
56 PyTypeObject SCA_PythonKeyboard::Type = {
57         PyVarObject_HEAD_INIT(NULL, 0)
58         "SCA_PythonKeyboard",
59         sizeof(PyObjectPlus_Proxy),
60         0,
61         py_base_dealloc,
62         0,
63         0,
64         0,
65         0,
66         py_base_repr,
67         0,0,0,0,0,0,0,0,0,
68         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
69         0,0,0,0,0,0,0,
70         Methods,
71         0,
72         0,
73         &PyObjectPlus::Type,
74         0,0,0,0,0,0,
75         py_base_new
76 };
77
78 PyMethodDef SCA_PythonKeyboard::Methods[] = {
79         {NULL,NULL} //Sentinel
80 };
81
82 PyAttributeDef SCA_PythonKeyboard::Attributes[] = {
83         KX_PYATTRIBUTE_RO_FUNCTION("events", SCA_PythonKeyboard, pyattr_get_events),
84         { NULL }        //Sentinel
85 };
86
87 PyObject* SCA_PythonKeyboard::pyattr_get_events(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
88 {
89         SCA_PythonKeyboard* self = static_cast<SCA_PythonKeyboard*>(self_v);
90         
91         for (int i=SCA_IInputDevice::KX_BEGINKEY; i<=SCA_IInputDevice::KX_ENDKEY; i++)
92         {
93                 const SCA_InputEvent & inevent = self->m_keyboard->GetEventValue((SCA_IInputDevice::KX_EnumInputs)i);
94                 
95                 PyDict_SetItem(self->m_event_dict, PyLong_FromSsize_t(i), PyLong_FromSsize_t(inevent.m_status));
96         }
97         Py_INCREF(self->m_event_dict);
98         return self->m_event_dict;
99 }
100
101 #endif