From 3ce705519dc8f998c092b24b9a52f2930c996540 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 20 Oct 2014 11:02:42 +0000 Subject: [PATCH] Oops, forgot these two files. Part of cfsworks' patch --- panda/src/display/graphicsWindow_ext.cxx | 61 ++++++++++++++++++++++++ panda/src/display/graphicsWindow_ext.h | 42 ++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 panda/src/display/graphicsWindow_ext.cxx create mode 100644 panda/src/display/graphicsWindow_ext.h diff --git a/panda/src/display/graphicsWindow_ext.cxx b/panda/src/display/graphicsWindow_ext.cxx new file mode 100644 index 0000000000..5bbd4a0107 --- /dev/null +++ b/panda/src/display/graphicsWindow_ext.cxx @@ -0,0 +1,61 @@ +// Filename: graphicsWindow_ext.cxx +// Created by: CFSworks (11Oct14) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "graphicsWindow_ext.h" + +#ifdef HAVE_PYTHON + +//////////////////////////////////////////////////////////////////// +// Function: Extension::add_custom_event_handler +// Access: Published +// Description: Adds a python event handler to be called +// when a window event occurs. +//////////////////////////////////////////////////////////////////// +void Extension:: +add_python_event_handler(PyObject* handler, PyObject* name){ + PythonGraphicsWindowProc* pgwp = new PythonGraphicsWindowProc(handler, name); + _this->_python_window_proc_classes.insert(pgwp); + _this->add_window_proc(pgwp); +} + +//////////////////////////////////////////////////////////////////// +// Function: Extension::remove_custom_event_handler +// Access: Published +// Description: Removes the specified python event handler. +//////////////////////////////////////////////////////////////////// +void Extension:: +remove_python_event_handler(PyObject* name){ + list toRemove; + GraphicsWindow::PythonWinProcClasses::iterator iter; + for (iter = _this->_python_window_proc_classes.begin(); iter != _this->_python_window_proc_classes.end(); ++iter) { + PythonGraphicsWindowProc* pgwp = (PythonGraphicsWindowProc*)*iter; + if (PyObject_RichCompareBool(pgwp->get_name(), name, Py_EQ) == 1) { + toRemove.push_back(pgwp); + } +#if PY_MAJOR_VERSION < 3 + else if (PyObject_Compare(pgwp->get_name(), name) == 0) { + toRemove.push_back(pgwp); + } +#endif + } + list::iterator iter2; + for (iter2 = toRemove.begin(); iter2 != toRemove.end(); ++iter2) { + PythonGraphicsWindowProc* pgwp = *iter2; + _this->remove_window_proc(pgwp); + _this->_python_window_proc_classes.erase(pgwp); + delete pgwp; + } +} + +#endif // HAVE_PYTHON diff --git a/panda/src/display/graphicsWindow_ext.h b/panda/src/display/graphicsWindow_ext.h new file mode 100644 index 0000000000..c96ce3c445 --- /dev/null +++ b/panda/src/display/graphicsWindow_ext.h @@ -0,0 +1,42 @@ +// Filename: renderState_ext.h +// Created by: CFSworks (11Oct14) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef GRAPHICSWINDOW_EXT_H +#define GRAPHICSWINDOW_EXT_H + +#include "dtoolbase.h" + +#ifdef HAVE_PYTHON + +#include "extension.h" +#include "graphicsWindow.h" +#include "pythonGraphicsWindowProc.h" +#include "py_panda.h" + +//////////////////////////////////////////////////////////////////// +// Class : Extension +// Description : This class defines the extension methods for +// GraphicsWindow, which are called instead of +// any C++ methods with the same prototype. +//////////////////////////////////////////////////////////////////// +template<> +class Extension : public ExtensionBase { +public: + void add_python_event_handler(PyObject* handler, PyObject* name); + void remove_python_event_handler(PyObject* name); +}; + +#endif // HAVE_PYTHON + +#endif // GRAPHICSWINDOW_EXT_H