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