display: Migrate the Python window func stuff to an extension.

This commit is contained in:
Sam Edwards 2014-10-11 20:38:48 -07:00
parent 3bd9750439
commit eaa323aa65
7 changed files with 114 additions and 68 deletions

View File

@ -3276,6 +3276,7 @@ if (not RUNTIME):
TargetAdd('libp3display.in', opts=['IMOD:panda3d.core', 'ILIB:libp3display', 'SRCDIR:panda/src/display'])
TargetAdd('libp3display_igate.obj', input='libp3display.in', opts=["DEPENDENCYONLY"])
TargetAdd('p3display_graphicsStateGuardian_ext.obj', opts=OPTS, input='graphicsStateGuardian_ext.cxx')
TargetAdd('p3display_graphicsWindow_ext.obj', opts=OPTS, input='graphicsWindow_ext.cxx')
if RTDIST and GetTarget() == 'darwin':
OPTS=['DIR:panda/src/display']
@ -3551,6 +3552,7 @@ if (not RUNTIME):
TargetAdd('libpanda.dll', input='p3gobj_internalName_ext.obj')
TargetAdd('libpanda.dll', input='p3pgraph_ext_composite.obj')
TargetAdd('libpanda.dll', input='p3display_graphicsStateGuardian_ext.obj')
TargetAdd('libpanda.dll', input='p3display_graphicsWindow_ext.obj')
if PkgSkip("FREETYPE")==0:
TargetAdd('libpanda.dll', input="p3pnmtext_composite1.obj")

View File

@ -71,19 +71,12 @@ set(P3DISPLAY_SOURCES
set(P3DISPLAY_IGATEEXT
graphicsStateGuardian_ext.cxx
graphicsStateGuardian_ext.h
graphicsWindow_ext.cxx
graphicsWindow_ext.h
pythonGraphicsWindowProc.cxx
pythonGraphicsWindowProc.h
)
if(HAVE_PYTHON)
set(P3DISPLAY_HEADERS
${P3DISPLAY_HEADERS}
pythonGraphicsWindowProc.h
)
set(P3DISPLAY_SOURCES
${P3DISPLAY_SOURCES}
pythonGraphicsWindowProc.cxx
)
endif()
if(APPLE)
set(P3DISPLAY_HEADERS
${P3DISPLAY_HEADERS}

View File

@ -31,6 +31,7 @@
graphicsStateGuardian_ext.cxx graphicsStateGuardian_ext.h \
graphicsThreadingModel.I graphicsThreadingModel.h \
graphicsWindow.I graphicsWindow.h \
graphicsWindow_ext.cxx graphicsWindow_ext.h \
graphicsWindowInputDevice.I \
graphicsWindowInputDevice.h \
graphicsWindowProc.h \

View File

@ -903,54 +903,6 @@ mouse_mode_absolute() {
}
#ifdef HAVE_PYTHON
////////////////////////////////////////////////////////////////////
// Function: GraphicsWindow::add_custom_event_handler
// Access: Published
// Description: Adds a python event handler to be called
// when a window event occurs.
//
////////////////////////////////////////////////////////////////////
void GraphicsWindow::
add_python_event_handler(PyObject* handler, PyObject* name){
PythonGraphicsWindowProc* pgwp = new PythonGraphicsWindowProc(handler, name);
_python_window_proc_classes.insert(pgwp);
add_window_proc(pgwp);
}
////////////////////////////////////////////////////////////////////
// Function: GraphicsWindow::remove_custom_event_handler
// Access: Published
// Description: Removes the specified python event handler.
//
////////////////////////////////////////////////////////////////////
void GraphicsWindow::
remove_python_event_handler(PyObject* name){
list<PythonGraphicsWindowProc*> toRemove;
PythonWinProcClasses::iterator iter;
for (iter = _python_window_proc_classes.begin(); iter != _python_window_proc_classes.end(); ++iter) {
PythonGraphicsWindowProc* pgwp = *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<PythonGraphicsWindowProc*>::iterator iter2;
for (iter2 = toRemove.begin(); iter2 != toRemove.end(); ++iter2) {
PythonGraphicsWindowProc* pgwp = *iter2;
remove_window_proc(pgwp);
_python_window_proc_classes.erase(pgwp);
delete pgwp;
}
}
#endif // HAVE_PYTHON
////////////////////////////////////////////////////////////////////
// Function: GraphicsWindow::is_touch_event
// Access: Published, Virtual

View File

@ -21,9 +21,6 @@
#include "graphicsWindowInputDevice.h"
#include "graphicsWindowProc.h"
#include "graphicsWindowProcCallbackData.h"
#ifdef HAVE_PYTHON
#include "pythonGraphicsWindowProc.h"
#endif
#include "windowProperties.h"
#include "mouseData.h"
#include "modifierButtons.h"
@ -94,11 +91,6 @@ PUBLISHED:
virtual bool move_pointer(int device, int x, int y);
virtual void close_ime();
#ifdef HAVE_PYTHON
void add_python_event_handler(PyObject* handler, PyObject* name);
void remove_python_event_handler(PyObject* name);
#endif
public:
// No need to publish these.
bool has_button_event(int device) const;
@ -169,7 +161,7 @@ private:
bool _unexposed_draw;
#ifdef HAVE_PYTHON
typedef pset<PythonGraphicsWindowProc*> PythonWinProcClasses;
typedef pset<GraphicsWindowProc*> PythonWinProcClasses;
PythonWinProcClasses _python_window_proc_classes;
#endif
@ -191,6 +183,7 @@ private:
static TypeHandle _type_handle;
friend class GraphicsEngine;
friend class Extension<GraphicsWindow>;
};
#include "graphicsWindow.I"

View File

@ -0,0 +1,63 @@
// 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<GraphicsWindow>::add_custom_event_handler
// Access: Published
// Description: Adds a python event handler to be called
// when a window event occurs.
//
////////////////////////////////////////////////////////////////////
void Extension<GraphicsWindow>::
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<GraphicsWindow>::remove_custom_event_handler
// Access: Published
// Description: Removes the specified python event handler.
//
////////////////////////////////////////////////////////////////////
void Extension<GraphicsWindow>::
remove_python_event_handler(PyObject* name){
list<PythonGraphicsWindowProc*> 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<PythonGraphicsWindowProc*>::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

View File

@ -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<GraphicsWindow>
// Description : This class defines the extension methods for
// GraphicsWindow, which are called instead of
// any C++ methods with the same prototype.
////////////////////////////////////////////////////////////////////
template<>
class Extension<GraphicsWindow> : public ExtensionBase<GraphicsWindow> {
public:
void add_python_event_handler(PyObject* handler, PyObject* name);
void remove_python_event_handler(PyObject* name);
};
#endif // HAVE_PYTHON
#endif // GRAPHICSWINDOW_EXT_H