diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2010-04-18 06:03:19 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2010-04-18 06:03:19 +0400 |
commit | dfe2f8dc03267e041102837e92f547fb04881510 (patch) | |
tree | d9582c4667ce5b9e39e2adce40832aa4f44b4fe7 /source/gameengine/GameLogic | |
parent | d7e08f2d33207fdf76b1b597ef0de9dec26e3987 (diff) | |
parent | 00e46ef739cf2bfddb8805af056aa59fd3b3c71c (diff) |
Merged changes in the trunk up to revision 28247.
Diffstat (limited to 'source/gameengine/GameLogic')
-rw-r--r-- | source/gameengine/GameLogic/Makefile | 4 | ||||
-rw-r--r-- | source/gameengine/GameLogic/SCA_PythonKeyboard.cpp | 108 | ||||
-rw-r--r-- | source/gameengine/GameLogic/SCA_PythonKeyboard.h | 44 | ||||
-rw-r--r-- | source/gameengine/GameLogic/SCA_PythonMouse.cpp | 177 | ||||
-rw-r--r-- | source/gameengine/GameLogic/SCA_PythonMouse.h | 53 |
5 files changed, 384 insertions, 2 deletions
diff --git a/source/gameengine/GameLogic/Makefile b/source/gameengine/GameLogic/Makefile index a1794a60452..ba1e1c25ee7 100644 --- a/source/gameengine/GameLogic/Makefile +++ b/source/gameengine/GameLogic/Makefile @@ -38,10 +38,10 @@ include nan_compile.mk CCFLAGS += $(LEVEL_1_CPP_WARNINGS) -CPPFLAGS += -I../Expressions +CPPFLAGS += -I../Expressions CPPFLAGS += -I../SceneGraph CPPFLAGS += -I../Rasterizer -CPPFLAGS += -I$(NAN_STRING)/include +CPPFLAGS += -I$(NAN_STRING)/include CPPFLAGS += -I$(NAN_MOTO)/include CPPFLAGS += -I../../blender/makesdna CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION) diff --git a/source/gameengine/GameLogic/SCA_PythonKeyboard.cpp b/source/gameengine/GameLogic/SCA_PythonKeyboard.cpp new file mode 100644 index 00000000000..3b4cdd701a6 --- /dev/null +++ b/source/gameengine/GameLogic/SCA_PythonKeyboard.cpp @@ -0,0 +1,108 @@ +/** + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "SCA_PythonKeyboard.h" +#include "SCA_IInputDevice.h" + +/* ------------------------------------------------------------------------- */ +/* Native functions */ +/* ------------------------------------------------------------------------- */ + +SCA_PythonKeyboard::SCA_PythonKeyboard(SCA_IInputDevice* keyboard) +: PyObjectPlus(), +m_keyboard(keyboard) +{ +} + +SCA_PythonKeyboard::~SCA_PythonKeyboard() +{ + /* intentionally empty */ +} + +#ifndef DISABLE_PYTHON + +/* ------------------------------------------------------------------------- */ +/* Python functions */ +/* ------------------------------------------------------------------------- */ + +/* Integration hooks ------------------------------------------------------- */ +PyTypeObject SCA_PythonKeyboard::Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "SCA_PythonKeyboard", + sizeof(PyObjectPlus_Proxy), + 0, + py_base_dealloc, + 0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0,0,0,0, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + 0,0,0,0,0,0,0, + Methods, + 0, + 0, + &PyObjectPlus::Type, + 0,0,0,0,0,0, + py_base_new +}; + +PyMethodDef SCA_PythonKeyboard::Methods[] = { + {NULL,NULL} //Sentinel +}; + +PyAttributeDef SCA_PythonKeyboard::Attributes[] = { + KX_PYATTRIBUTE_RO_FUNCTION("events", SCA_PythonKeyboard, pyattr_get_events), + { NULL } //Sentinel +}; + +PyObject* SCA_PythonKeyboard::pyattr_get_events(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_PythonKeyboard* self = static_cast<SCA_PythonKeyboard*>(self_v); + + PyObject* resultlist = PyList_New(0); + + for (int i=SCA_IInputDevice::KX_BEGINKEY; i<=SCA_IInputDevice::KX_ENDKEY; i++) + { + const SCA_InputEvent & inevent = self->m_keyboard->GetEventValue((SCA_IInputDevice::KX_EnumInputs)i); + + + if (inevent.m_status != SCA_InputEvent::KX_NO_INPUTSTATUS) + { + PyObject* keypair = PyTuple_New(2); + PyTuple_SET_ITEM(keypair, 0, PyLong_FromSsize_t(i)); + PyTuple_SET_ITEM(keypair, 1, PyLong_FromSsize_t(inevent.m_status)); + PyList_Append(resultlist, keypair); + } + } + + return resultlist; +} + +#endif diff --git a/source/gameengine/GameLogic/SCA_PythonKeyboard.h b/source/gameengine/GameLogic/SCA_PythonKeyboard.h new file mode 100644 index 00000000000..0b353ac444c --- /dev/null +++ b/source/gameengine/GameLogic/SCA_PythonKeyboard.h @@ -0,0 +1,44 @@ +/** + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __KX_PYKEYBOARD +#define __KX_PYKEYBOARD + +#include "PyObjectPlus.h" + +class SCA_PythonKeyboard : public PyObjectPlus +{ + Py_Header; + class SCA_IInputDevice *m_keyboard; +public: + SCA_PythonKeyboard(class SCA_IInputDevice* keyboard); + virtual ~SCA_PythonKeyboard(); + +#ifndef DISABLE_PYTHON + static PyObject* pyattr_get_events(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); +#endif +}; + +#endif //__KX_PYKEYBOARD + diff --git a/source/gameengine/GameLogic/SCA_PythonMouse.cpp b/source/gameengine/GameLogic/SCA_PythonMouse.cpp new file mode 100644 index 00000000000..278b967355b --- /dev/null +++ b/source/gameengine/GameLogic/SCA_PythonMouse.cpp @@ -0,0 +1,177 @@ +/** + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * 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" + +/* ------------------------------------------------------------------------- */ +/* Native functions */ +/* ------------------------------------------------------------------------- */ + +SCA_PythonMouse::SCA_PythonMouse(SCA_IInputDevice* mouse, RAS_ICanvas* canvas) +: PyObjectPlus(), +m_canvas(canvas), +m_mouse(mouse) +{ +} + +SCA_PythonMouse::~SCA_PythonMouse() +{ + /* intentionally empty */ +} + +#ifndef DISABLE_PYTHON + +/* ------------------------------------------------------------------------- */ +/* Python functions */ +/* ------------------------------------------------------------------------- */ + +/* Integration hooks ------------------------------------------------------- */ +PyTypeObject SCA_PythonMouse::Type = { + PyVarObject_HEAD_INIT(NULL, 0) + "SCA_PythonMouse", + sizeof(PyObjectPlus_Proxy), + 0, + py_base_dealloc, + 0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0,0,0,0, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + 0,0,0,0,0,0,0, + Methods, + 0, + 0, + &PyObjectPlus::Type, + 0,0,0,0,0,0, + py_base_new +}; + +PyMethodDef SCA_PythonMouse::Methods[] = { +// KX_PYMETHODTABLE(SCA_PythonMouse, show), + {NULL,NULL} //Sentinel +}; + +PyAttributeDef SCA_PythonMouse::Attributes[] = { + KX_PYATTRIBUTE_RO_FUNCTION("events", SCA_PythonMouse, pyattr_get_events), + KX_PYATTRIBUTE_RW_FUNCTION("position", SCA_PythonMouse, pyattr_get_position, pyattr_set_position), + KX_PYATTRIBUTE_RW_FUNCTION("visible", SCA_PythonMouse, pyattr_get_visible, pyattr_set_visible), + { NULL } //Sentinel +}; + +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 = PyTuple_New(2); + PyTuple_SET_ITEM(keypair, 0, PyLong_FromSsize_t(i)); + PyTuple_SET_ITEM(keypair, 1, PyLong_FromSsize_t(inevent.m_status)); + PyList_Append(resultlist, keypair); + } + } + + return resultlist; +} + +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* ret = PyTuple_New(2); + + PyTuple_SET_ITEM(ret, 0, PyFloat_FromDouble(float(xevent.m_eventval)/self->m_canvas->GetWidth())); + PyTuple_SET_ITEM(ret, 1, PyFloat_FromDouble(float(yevent.m_eventval)/self->m_canvas->GetHeight())); + + return ret; +} + +int SCA_PythonMouse::pyattr_set_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + SCA_PythonMouse* self = static_cast<SCA_PythonMouse*>(self_v); + int x, y; + float pyx, pyy; + if (!PyArg_ParseTuple(value, "ff:position", &pyx, &pyy)) + return PY_SET_ATTR_FAIL; + + x = (int)(pyx*self->m_canvas->GetWidth()); + y = (int)(pyy*self->m_canvas->GetHeight()); + + self->m_canvas->SetMousePosition(x, y); + + return PY_SET_ATTR_SUCCESS; +} + +PyObject* SCA_PythonMouse::pyattr_get_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) +{ + SCA_PythonMouse* self = static_cast<SCA_PythonMouse*>(self_v); + + int visible; + + if (self->m_canvas->GetMouseState() == RAS_ICanvas::MOUSE_INVISIBLE) + visible = 0; + else + visible = 1; + + return PyBool_FromLong(visible); +} + +int SCA_PythonMouse::pyattr_set_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + SCA_PythonMouse* self = static_cast<SCA_PythonMouse*>(self_v); + + int visible = PyObject_IsTrue(value); + + if (visible == -1) + { + PyErr_SetString(PyExc_AttributeError, "SCA_PythonMouse.visible = bool: SCA_PythonMouse, expected True or False"); + return PY_SET_ATTR_FAIL; + } + + if (visible) + self->m_canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL); + else + self->m_canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE); + + return PY_SET_ATTR_SUCCESS; +} + +#endif diff --git a/source/gameengine/GameLogic/SCA_PythonMouse.h b/source/gameengine/GameLogic/SCA_PythonMouse.h new file mode 100644 index 00000000000..c73e6683fc8 --- /dev/null +++ b/source/gameengine/GameLogic/SCA_PythonMouse.h @@ -0,0 +1,53 @@ +/** + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __KX_PYMOUSE +#define __KX_PYMOUSE + +#include "PyObjectPlus.h" + +class SCA_PythonMouse : public PyObjectPlus +{ + Py_Header; + class SCA_IInputDevice *m_mouse; + class RAS_ICanvas *m_canvas; +public: + SCA_PythonMouse(class SCA_IInputDevice* mouse, class RAS_ICanvas* canvas); + virtual ~SCA_PythonMouse(); + + void Show(bool visible); + +#ifndef DISABLE_PYTHON + KX_PYMETHOD_DOC(SCA_PythonMouse, show); + + static PyObject* pyattr_get_events(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject* pyattr_get_position(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_position(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject* value); + static PyObject* pyattr_get_visible(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static int pyattr_set_visible(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject* value); +#endif +}; + +#endif //__KX_PYMOUSE + |