diff --git a/makepanda/makepandacore.py b/makepanda/makepandacore.py index 40dc350e45..1bbc5c904d 100644 --- a/makepanda/makepandacore.py +++ b/makepanda/makepandacore.py @@ -1412,10 +1412,11 @@ def SdkLocateVisualStudio(): def SdkLocateMSPlatform(): if (sys.platform != "win32"): return platsdk = GetRegistryKey("SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v7.0", "InstallationFolder") - if (platsdk and not os.path.isdir(platsdk)): - platsdk = 0 - else: - print "Windows 7 SDK detected. Enabling special features (multi-touch)." + if (platsdk): + if os.path.isdir(platsdk): + print "Windows 7 SDK detected. Enabling special features (multi-touch)." + else: + platsdk = 0 if (platsdk == 0): platsdk = GetRegistryKey("SOFTWARE\\Microsoft\\MicrosoftSDK\\InstalledSDKs\\D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1", "Install Dir") if (platsdk and not os.path.isdir(platsdk)): platsdk = 0 diff --git a/panda/src/display/Sources.pp b/panda/src/display/Sources.pp index 7b79637379..2b1a7d5818 100644 --- a/panda/src/display/Sources.pp +++ b/panda/src/display/Sources.pp @@ -13,7 +13,7 @@ #define SOURCES \ standardMunger.I standardMunger.h \ config_display.h \ - customGraphicsWindowProc.h \ + $[if $[HAVE_PYTHON], pythonGraphicsWindowProc.h] \ drawableRegion.I drawableRegion.h \ displayRegion.I displayRegion.h \ displayRegionCullCallbackData.I displayRegionCullCallbackData.h \ @@ -32,6 +32,7 @@ graphicsWindowInputDevice.I \ graphicsWindowInputDevice.h \ graphicsWindowProc.h \ + graphicsWindowProcCallbackData.I graphicsWindowProcCallbackData.h \ lru.h \ nativeWindowHandle.I nativeWindowHandle.h \ parasiteBuffer.I parasiteBuffer.h \ @@ -50,7 +51,7 @@ #define INCLUDED_SOURCES \ standardMunger.cxx \ config_display.cxx \ - customGraphicsWindowProc.cxx \ + $[if $[HAVE_PYTHON], pythonGraphicsWindowProc.cxx] \ drawableRegion.cxx \ displayRegion.cxx \ displayRegionCullCallbackData.cxx \ @@ -67,6 +68,7 @@ graphicsThreadingModel.cxx \ graphicsWindow.cxx graphicsWindowInputDevice.cxx \ graphicsWindowProc.cxx \ + graphicsWindowProcCalbackData.cxx \ graphicsDevice.cxx \ lru.cxx \ nativeWindowHandle.cxx \ @@ -81,7 +83,7 @@ #define INSTALL_HEADERS \ standardMunger.I standardMunger.h \ config_display.h \ - customGraphicsWindowProc.h \ + $[if $[HAVE_PYTHON], pythonGraphicsWindowProc.h] \ drawableRegion.I drawableRegion.h \ displayInformation.h \ displayRegion.I displayRegion.h \ @@ -98,6 +100,7 @@ graphicsStateGuardian.h \ graphicsWindow.I graphicsWindow.h \ graphicsWindowProc.h \ + graphicsWindowProcCallbackData.I graphicsWindowProcCallbackData.h \ graphicsThreadingModel.I graphicsThreadingModel.h \ graphicsWindowInputDevice.I graphicsWindowInputDevice.h \ graphicsDevice.I graphicsDevice.h \ diff --git a/panda/src/display/config_display.cxx b/panda/src/display/config_display.cxx index adeac3bb9d..caf897d445 100644 --- a/panda/src/display/config_display.cxx +++ b/panda/src/display/config_display.cxx @@ -23,6 +23,10 @@ #include "graphicsBuffer.h" #include "graphicsWindow.h" #include "graphicsDevice.h" +#ifdef HAVE_PYTHON +#include "pythonGraphicsWindowProc.h" +#endif +#include "graphicsWindowProcCallbackData.h" #include "nativeWindowHandle.h" #include "parasiteBuffer.h" #include "pandaSystem.h" @@ -435,6 +439,10 @@ init_libdisplay() { GraphicsPipe::init_type(); GraphicsStateGuardian::init_type(); GraphicsWindow::init_type(); +#ifdef HAVE_PYTHON + PythonGraphicsWindowProc::init_type(); +#endif + GraphicsWindowProcCallbackData::init_type(); NativeWindowHandle::init_type(); ParasiteBuffer::init_type(); StandardMunger::init_type(); diff --git a/panda/src/display/customGraphicsWindowProc.cxx b/panda/src/display/customGraphicsWindowProc.cxx deleted file mode 100644 index 6450d27fff..0000000000 --- a/panda/src/display/customGraphicsWindowProc.cxx +++ /dev/null @@ -1,44 +0,0 @@ -// Filename: customGraphicsWindowProc.cxx -// Created by: Walt Destler (May 2010) -// -//////////////////////////////////////////////////////////////////// -// -// 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 "customGraphicsWindowProc.h" - -CustomGraphicsWindowProc::CustomGraphicsWindowProc(PyObject* handler, PyObject* name){ - _handler = handler; - _name = name; - Py_INCREF(_handler); - Py_INCREF(_name); -} - -CustomGraphicsWindowProc::~CustomGraphicsWindowProc(){ - Py_DECREF(_name); - Py_DECREF(_handler); -} - -#ifdef WIN32 -LONG CustomGraphicsWindowProc::wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam){ - PyObject* ret = PyObject_CallFunction(_handler, "IIII", hwnd, msg, wparam, lparam); - Py_XDECREF(ret); - - return 0; -} -#endif - -PyObject* CustomGraphicsWindowProc::get_handler(){ - return _handler; -} - -PyObject* CustomGraphicsWindowProc::get_name(){ - return _name; -} diff --git a/panda/src/display/customGraphicsWindowProc.h b/panda/src/display/customGraphicsWindowProc.h deleted file mode 100644 index 28bcdad9d4..0000000000 --- a/panda/src/display/customGraphicsWindowProc.h +++ /dev/null @@ -1,38 +0,0 @@ -// Filename: customGgraphicswindowProc.h -// Created by: Walt Destler (May 2010) -// -//////////////////////////////////////////////////////////////////// -// -// 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 CUSTOMGRAPHICSWINDOWPROC_H -#define CUSTOMGRAPHICSWINDOWPROC_H - -#include "pandabase.h" -#include "graphicsWindowProc.h" - -class CustomGraphicsWindowProc: public GraphicsWindowProc{ -public: - CustomGraphicsWindowProc(PyObject* handler, PyObject* name); - virtual ~CustomGraphicsWindowProc(); - -#ifdef WIN32 - virtual LONG wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); -#endif - - PyObject* get_handler(); - PyObject* get_name(); - -private: - PyObject* _handler; - PyObject* _name; -}; - -#endif //CUSTOMGRAPHICSWINDOWPROC_H diff --git a/panda/src/display/display_composite2.cxx b/panda/src/display/display_composite2.cxx index c1bb7ca216..35755515f4 100644 --- a/panda/src/display/display_composite2.cxx +++ b/panda/src/display/display_composite2.cxx @@ -3,7 +3,10 @@ #include "graphicsThreadingModel.cxx" #include "graphicsWindow.cxx" #include "graphicsWindowProc.cxx" -#include "customGraphicsWindowProc.cxx" +#include "graphicsWindowProcCallbackData.cxx" +#ifdef HAVE_PYTHON +#include "pythonGraphicsWindowProc.cxx" +#endif #include "graphicsWindowInputDevice.cxx" #include "lru.cxx" #include "nativeWindowHandle.cxx" diff --git a/panda/src/display/graphicsWindow.cxx b/panda/src/display/graphicsWindow.cxx index daee7201de..6a7585f0f9 100644 --- a/panda/src/display/graphicsWindow.cxx +++ b/panda/src/display/graphicsWindow.cxx @@ -77,12 +77,13 @@ GraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, //////////////////////////////////////////////////////////////////// GraphicsWindow:: ~GraphicsWindow() { - - // Clean up custom event handlers. - CustomWinProcClasses::iterator iter; - for(iter = _custom_window_proc_classes.begin(); iter != _custom_window_proc_classes.end(); ++iter){ +#ifdef HAVE_PYTHON + // Clean up python event handlers. + PythonWinProcClasses::iterator iter; + for(iter = _python_window_proc_classes.begin(); iter != _python_window_proc_classes.end(); ++iter){ delete *iter; } +#endif } //////////////////////////////////////////////////////////////////// @@ -927,64 +928,56 @@ mouse_mode_absolute() { } +#ifdef HAVE_PYTHON + //////////////////////////////////////////////////////////////////// // Function: GraphicsWindow::add_custom_event_handler // Access: Published -// Description: Adds a custom python event handler to be called +// Description: Adds a python event handler to be called // when a window event occurs. // //////////////////////////////////////////////////////////////////// void GraphicsWindow:: -add_custom_event_handler(PyObject* handler, PyObject* name){ - CustomGraphicsWindowProc* cgwp = new CustomGraphicsWindowProc(handler, name); - _custom_window_proc_classes.insert(cgwp); - add_window_proc(cgwp); +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 custom python event handler. +// Description: Removes the specified python event handler. // //////////////////////////////////////////////////////////////////// void GraphicsWindow:: -remove_custom_event_handler(PyObject* name){ - //nassertv(wnd_proc != NULL); - //_window_proc_classes.erase( (GraphicsWindowProc*)wnd_proc ); - list toRemove; - CustomWinProcClasses::iterator iter; - for(iter = _custom_window_proc_classes.begin(); iter != _custom_window_proc_classes.end(); ++iter){ - CustomGraphicsWindowProc* cgwp = *iter; - if(PyObject_Compare(cgwp->get_name(), name) == 0) - toRemove.push_back(cgwp); +remove_python_event_handler(PyObject* name){ + list toRemove; + PythonWinProcClasses::iterator iter; + for(iter = _python_window_proc_classes.begin(); iter != _python_window_proc_classes.end(); ++iter){ + PythonGraphicsWindowProc* pgwp = *iter; + if(PyObject_Compare(pgwp->get_name(), name) == 0) + toRemove.push_back(pgwp); } - list::iterator iter2; + list::iterator iter2; for(iter2 = toRemove.begin(); iter2 != toRemove.end(); ++iter2){ - CustomGraphicsWindowProc* cgwp = *iter2; - remove_window_proc(cgwp); - _custom_window_proc_classes.erase(cgwp); - delete cgwp; + PythonGraphicsWindowProc* pgwp = *iter2; + remove_window_proc(pgwp); + _python_window_proc_classes.erase(pgwp); + delete pgwp; } } -//////////////////////////////////////////////////////////////////// -// Function: GraphicsWindow::supports_window_procs -// Access: Published, Virtual -// Description: Returns whether this window supports adding of Windows proc handlers. -// -//////////////////////////////////////////////////////////////////// -bool GraphicsWindow::supports_window_procs() const{ - return false; -} +#endif // HAVE_PYTHON //////////////////////////////////////////////////////////////////// -// Function: GraphicsWindow::is_touch_msg +// Function: GraphicsWindow::is_touch_event // Access: Published, Virtual // Description: Returns whether the specified event msg is a touch message. // //////////////////////////////////////////////////////////////////// bool GraphicsWindow:: -is_touch_msg(int msg){ +is_touch_event(GraphicsWindowProcCallbackData* callbackData){ return false; } @@ -1009,3 +1002,13 @@ TouchInfo GraphicsWindow:: get_touch_info(int index){ return TouchInfo(); } + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsWindow::supports_window_procs +// Access: Published, Virtual +// Description: Returns whether this window supports adding of Windows proc handlers. +// +//////////////////////////////////////////////////////////////////// +bool GraphicsWindow::supports_window_procs() const{ + return false; +} diff --git a/panda/src/display/graphicsWindow.h b/panda/src/display/graphicsWindow.h index 4dccaa7f91..a8873bf8f1 100644 --- a/panda/src/display/graphicsWindow.h +++ b/panda/src/display/graphicsWindow.h @@ -20,7 +20,10 @@ #include "graphicsOutput.h" #include "graphicsWindowInputDevice.h" #include "graphicsWindowProc.h" -#include "customGraphicsWindowProc.h" +#include "graphicsWindowProcCallbackData.h" +#ifdef HAVE_PYTHON +#include "pythonGraphicsWindowProc.h" +#endif #include "windowProperties.h" #include "mouseData.h" #include "modifierButtons.h" @@ -87,12 +90,10 @@ PUBLISHED: virtual bool move_pointer(int device, int x, int y); virtual void close_ime(); - void add_custom_event_handler(PyObject* handler, PyObject* name); - void remove_custom_event_handler(PyObject* name); - - virtual bool is_touch_msg(int msg); - virtual int get_num_touches(); - virtual TouchInfo get_touch_info(int index); +#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. @@ -108,6 +109,10 @@ public: virtual int verify_window_sizes(int numsizes, int *dimen); + virtual bool is_touch_event(GraphicsWindowProcCallbackData* callbackData); + virtual int get_num_touches(); + virtual TouchInfo get_touch_info(int index); + public: virtual void request_open(); virtual void request_close(); @@ -159,9 +164,11 @@ private: string _window_event; string _close_request_event; - typedef pset CustomWinProcClasses; - CustomWinProcClasses _custom_window_proc_classes; - +#ifdef HAVE_PYTHON + typedef pset PythonWinProcClasses; + PythonWinProcClasses _python_window_proc_classes; +#endif + public: static TypeHandle get_class_type() { return _type_handle; diff --git a/panda/src/display/graphicsWindowProc.cxx b/panda/src/display/graphicsWindowProc.cxx index 93bfd79e08..35e4b2f202 100644 --- a/panda/src/display/graphicsWindowProc.cxx +++ b/panda/src/display/graphicsWindowProc.cxx @@ -14,13 +14,28 @@ #include "graphicsWindowProc.h" -TypeHandle GraphicsWindowProc::_type_handle; - -GraphicsWindowProc::GraphicsWindowProc(){ +//////////////////////////////////////////////////////////////////// +// Function: GraphicWindowProc::Constructor +// Access: Public +// Description: Does nothing. +//////////////////////////////////////////////////////////////////// +GraphicsWindowProc:: +GraphicsWindowProc(){ } + #if defined(__WIN32__) || defined(_WIN32) -LONG GraphicsWindowProc::wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam){ + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsWindowProc::wnd_proc +// Access: Public, Virtual +// Description: A WIN32-specific method that is called when a Window +// proc event occurrs. Should be overridden by a derived +// class. +//////////////////////////////////////////////////////////////////// +LONG GraphicsWindowProc:: +wnd_proc(GraphicsWindow* graphicsWindow, HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam){ return 0; } + #endif //most an empty file. \ No newline at end of file diff --git a/panda/src/display/graphicsWindowProc.h b/panda/src/display/graphicsWindowProc.h index 8034131544..88df028bfd 100644 --- a/panda/src/display/graphicsWindowProc.h +++ b/panda/src/display/graphicsWindowProc.h @@ -17,7 +17,6 @@ #define GRAPHICSWINDOWPROC_H #include "pandabase.h" -#include "typedReferenceCount.h" #ifdef WIN32 #ifndef WIN32_LEAN_AND_MEAN @@ -26,38 +25,18 @@ #include #endif -/* -Defines a little interface for storing a platform specific window -processor methods. Since this is a purely virtual class, it never -really gets instaniated so this even though this is type reference -counted, it doesn't need to registered. -*/ -class EXPCL_PANDA_DISPLAY GraphicsWindowProc: public TypedReferenceCount{ +//////////////////////////////////////////////////////////////////// +// Class : GraphicsWindowProc +// Description : Defines an interface for storing platform-specific +// window processor methods. +//////////////////////////////////////////////////////////////////// +class GraphicsWindowProc{ public: GraphicsWindowProc(); #if defined(__WIN32__) || defined(_WIN32) - virtual LONG wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); + virtual LONG wnd_proc(GraphicsWindow* graphicsWindow, HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); #endif //purely virtual class - - // In theory, this stuff below never gets used since it's purely virtual - // class that can't be instaniated anyways -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - TypedReferenceCount::init_type(); - register_type(_type_handle, "GraphicsWindowProc", - TypedReferenceCount::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; }; #endif //GRAPHICSWINDOWPROC_H diff --git a/panda/src/display/graphicsWindowProcCallbackData.I b/panda/src/display/graphicsWindowProcCallbackData.I new file mode 100644 index 0000000000..90eb6e5669 --- /dev/null +++ b/panda/src/display/graphicsWindowProcCallbackData.I @@ -0,0 +1,117 @@ +// Filename: graphicsWindowProcCallbackData.I +// Created by: Walt Destler (June 2010) +// +//////////////////////////////////////////////////////////////////// +// +// 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." +// +//////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsWindowProcCallbackData::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE GraphicsWindowProcCallbackData:: +GraphicsWindowProcCallbackData(GraphicsWindow* graphicsWindow){ + _graphicsWindow = graphicsWindow; +} + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsWindowProcCallbackData::get_hwnd +// Access: Published +// Description: Returns the GraphicsWindow that generated this event. +//////////////////////////////////////////////////////////////////// +INLINE GraphicsWindow* GraphicsWindowProcCallbackData:: +get_graphics_window() const { + return _graphicsWindow; +} + +#ifdef WIN32 + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsWindowProcCallbackData::get_hwnd +// Access: Published +// Description: Returns the Windows proc hwnd parameter. +//////////////////////////////////////////////////////////////////// +INLINE int GraphicsWindowProcCallbackData:: +get_hwnd() const { + return _hwnd; +} + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsWindowProcCallbackData::get_msg +// Access: Published +// Description: Returns the Windows proc msg parameter. +//////////////////////////////////////////////////////////////////// +INLINE int GraphicsWindowProcCallbackData:: +get_msg() const { + return _msg; +} + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsWindowProcCallbackData::get_wparam +// Access: Published +// Description: Returns the Windows proc wparam parameter. +//////////////////////////////////////////////////////////////////// +INLINE int GraphicsWindowProcCallbackData:: +get_wparam() const { + return _wparam; +} + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsWindowProcCallbackData::get_lparam +// Access: Published +// Description: Returns the Windows proc lparam parameter. +//////////////////////////////////////////////////////////////////// +INLINE int GraphicsWindowProcCallbackData:: +get_lparam() const { + return _lparam; +} + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsWindowProcCallbackData::set_hwnd +// Access: Published +// Description: Sets the Windows proc hwnd parameter. +//////////////////////////////////////////////////////////////////// +INLINE void GraphicsWindowProcCallbackData:: +set_hwnd(int hwnd) { + _hwnd = hwnd; +} + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsWindowProcCallbackData::set_msg +// Access: Published +// Description: Sets the Windows proc msg parameter. +//////////////////////////////////////////////////////////////////// +INLINE void GraphicsWindowProcCallbackData:: +set_msg(int msg) { + _msg = msg; +} + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsWindowProcCallbackData::set_wparam +// Access: Published +// Description: Sets the Windows proc wparam parameter. +//////////////////////////////////////////////////////////////////// +INLINE void GraphicsWindowProcCallbackData:: +set_wparam(int wparam) { + _wparam = wparam; +} + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsWindowProcCallbackData::set_lparam +// Access: Published +// Description: Sets the Windows proc lparam parameter. +//////////////////////////////////////////////////////////////////// +INLINE void GraphicsWindowProcCallbackData:: +set_lparam(int lparam) { + _lparam = lparam; +} + +#endif diff --git a/panda/src/display/graphicsWindowProcCallbackData.cxx b/panda/src/display/graphicsWindowProcCallbackData.cxx new file mode 100644 index 0000000000..684efcbcfb --- /dev/null +++ b/panda/src/display/graphicsWindowProcCallbackData.cxx @@ -0,0 +1,64 @@ +// Filename: graphicsWindowProcCallbackData.cxx +// Created by: Walt Destler (June 2010) +// +//////////////////////////////////////////////////////////////////// +// +// 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 "graphicsWindowProcCallbackData.h" + +TypeHandle GraphicsWindowProcCallbackData::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsWindowProcCallbackData::output +// Access: Published, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +void GraphicsWindowProcCallbackData:: +output(ostream &out) const { +#ifdef WIN32 + out << get_type() << "(" << (void*)_graphicsWindow << ", " << _hwnd << ", " + << _msg << ", " << _wparam << ", " << _lparam << ")"; +#else + out << get_type() << "()"; +#endif +} +//////////////////////////////////////////////////////////////////// +// Function: GraphicsWindowProcCallbackData::is_touch_event +// Access: Public, Virtual +// Description: Returns whether the event is a touch event. +// +//////////////////////////////////////////////////////////////////// +bool GraphicsWindowProcCallbackData:: +is_touch_event(){ + return _graphicsWindow->is_touch_event(this); +} + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsWindowProcCallbackData::get_num_touches +// Access: Public, Virtual +// Description: Returns the current number of touches on the window. +// +//////////////////////////////////////////////////////////////////// +int GraphicsWindowProcCallbackData:: +get_num_touches(){ + return _graphicsWindow->get_num_touches(); +} + +//////////////////////////////////////////////////////////////////// +// Function: GraphicsWindowProcCallbackData::get_touch_info +// Access: Public, Virtual +// Description: Returns the TouchInfo object describing the specified touch. +// +//////////////////////////////////////////////////////////////////// +TouchInfo GraphicsWindowProcCallbackData:: +get_touch_info(int index){ + return _graphicsWindow->get_touch_info(index); +} diff --git a/panda/src/display/graphicsWindowProcCallbackData.h b/panda/src/display/graphicsWindowProcCallbackData.h new file mode 100644 index 0000000000..810d9e2fb6 --- /dev/null +++ b/panda/src/display/graphicsWindowProcCallbackData.h @@ -0,0 +1,85 @@ +// Filename: graphicsWindowProcCallbackData.h +// Created by: Walt Destler (June 2010) +// +//////////////////////////////////////////////////////////////////// +// +// 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 GRAPHICSWINDOWPROCCALLBACKDATA_H +#define GRAPHICSWINDOWPROCCALLBACKDATA_H + +#include "pandabase.h" +#include "callbackData.h" +#include "graphicsWindow.h" +#include "touchInfo.h" + +//////////////////////////////////////////////////////////////////// +// Class : GraphicsWindowProcCallbackData +// Description : This specialization on CallbackData is passed when +// the callback is initiated from from an implementation +// of the GraphicsWindowProc class, such as PythonGraphicsWindowProc. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDA_DISPLAY GraphicsWindowProcCallbackData : public CallbackData { +public: + INLINE GraphicsWindowProcCallbackData(GraphicsWindow* graphicsWindow); + + INLINE GraphicsWindow* get_graphics_window() const; + +#ifdef WIN32 + INLINE void set_hwnd(int hwnd); + INLINE void set_msg(int msg); + INLINE void set_wparam(int wparam); + INLINE void set_lparam(int lparam); +#endif + +PUBLISHED: + virtual void output(ostream &out) const; + +#ifdef WIN32 + INLINE int get_hwnd() const; + INLINE int get_msg() const; + INLINE int get_wparam() const; + INLINE int get_lparam() const; +#endif + + bool is_touch_event(); + int get_num_touches(); + TouchInfo get_touch_info(int index); + +private: + GraphicsWindow* _graphicsWindow; +#ifdef WIN32 + int _hwnd; + int _msg; + int _wparam; + int _lparam; +#endif + +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + CallbackData::init_type(); + register_type(_type_handle, "GraphicsWindowProcCallbackData", + CallbackData::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() {init_type(); return get_class_type();} + +private: + static TypeHandle _type_handle; +}; + +#include "graphicsWindowProcCallbackData.I" + +#endif // GRAPHICSWINDOWPROCCALLBACKDATA_H diff --git a/panda/src/display/pythonGraphicsWindowProc.cxx b/panda/src/display/pythonGraphicsWindowProc.cxx new file mode 100644 index 0000000000..0037641a50 --- /dev/null +++ b/panda/src/display/pythonGraphicsWindowProc.cxx @@ -0,0 +1,74 @@ +// Filename: customGraphicsWindowProc.cxx +// Created by: Walt Destler (May 2010) +// +//////////////////////////////////////////////////////////////////// +// +// 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 "pythonGraphicsWindowProc.h" +#include "graphicsWindowProcCallbackData.h" + +TypeHandle PythonGraphicsWindowProc::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: PythonGraphicWindowProc::Constructor +// Access: Public +// Description: Initializes this PythonGraphicsWindowProc to use the +// specified callback handler and name. +//////////////////////////////////////////////////////////////////// +PythonGraphicsWindowProc:: +PythonGraphicsWindowProc(PyObject* function, PyObject* name) : + PythonCallbackObject(function) +{ + _name = name; + Py_INCREF(_name); +} + +//////////////////////////////////////////////////////////////////// +// Function: PythonGraphicWindowProc::Constructor +// Access: Public, Virtual +// Description: Decrements references to the handler and name objects. +//////////////////////////////////////////////////////////////////// +PythonGraphicsWindowProc:: +~PythonGraphicsWindowProc(){ + Py_DECREF(_name); +} + +#ifdef WIN32 + +//////////////////////////////////////////////////////////////////// +// Function: PythonGraphicWindowProc::wnd_proc +// Access: Public, Virtual +// Description: A WIN32-specific method that is called when a Window +// proc event occurrs. Calls the python handler. +//////////////////////////////////////////////////////////////////// +LONG PythonGraphicsWindowProc:: +wnd_proc(GraphicsWindow* graphicsWindow, HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam){ + GraphicsWindowProcCallbackData cdata(graphicsWindow); + cdata.set_hwnd((int)hwnd); + cdata.set_msg(msg); + cdata.set_wparam(wparam); + cdata.set_lparam(lparam); + do_callback(&cdata); + + return 0; +} + +#endif // WIN32 + +//////////////////////////////////////////////////////////////////// +// Function: PythonGraphicWindowProc::get_name +// Access: Public +// Description: Returns the python name object. +//////////////////////////////////////////////////////////////////// +PyObject* PythonGraphicsWindowProc:: +get_name(){ + return _name; +} diff --git a/panda/src/display/pythonGraphicsWindowProc.h b/panda/src/display/pythonGraphicsWindowProc.h new file mode 100644 index 0000000000..6ce1c7c5be --- /dev/null +++ b/panda/src/display/pythonGraphicsWindowProc.h @@ -0,0 +1,60 @@ +// Filename: customGgraphicswindowProc.h +// Created by: Walt Destler (May 2010) +// +//////////////////////////////////////////////////////////////////// +// +// 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 PYTHONGRAPHICSWINDOWPROC_H +#define PYTHONGRAPHICSWINDOWPROC_H + +#include "pandabase.h" +#include "graphicsWindowProc.h" +#include "pythonCallbackObject.h" + +//////////////////////////////////////////////////////////////////// +// Class : PythonGraphicsWindowProc +// Description : Extends GraphicsWindowProc to provde callback functionality +// to a python program. +//////////////////////////////////////////////////////////////////// +class PythonGraphicsWindowProc: public GraphicsWindowProc, public PythonCallbackObject{ +public: + PythonGraphicsWindowProc(PyObject *function, PyObject* name); + virtual ~PythonGraphicsWindowProc(); + ALLOC_DELETED_CHAIN(PythonGraphicsWindowProc); + +#ifdef WIN32 + virtual LONG wnd_proc(GraphicsWindow* graphicsWindow, HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); +#endif + + PyObject* get_name(); + +private: + PyObject* _name; + +public: + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + TypedReferenceCount::init_type(); + register_type(_type_handle, "PythonGraphicsWindowProc", + TypedReferenceCount::get_class_type()); + } + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() {init_type(); return get_class_type();} + +private: + static TypeHandle _type_handle; +}; + +#endif //PYTHONGRAPHICSWINDOWPROC_H diff --git a/panda/src/display/touchInfo.h b/panda/src/display/touchInfo.h index 0fe84ae689..b449c4bc50 100644 --- a/panda/src/display/touchInfo.h +++ b/panda/src/display/touchInfo.h @@ -28,7 +28,7 @@ PUBLISHED: { TIF_move = 0x0001, TIF_down = 0x0002, - TIF_UP = 0x0004, + TIF_up = 0x0004, }; public: diff --git a/panda/src/windisplay/winGraphicsWindow.cxx b/panda/src/windisplay/winGraphicsWindow.cxx index e39a2baf4a..52c26f4b1d 100644 --- a/panda/src/windisplay/winGraphicsWindow.cxx +++ b/panda/src/windisplay/winGraphicsWindow.cxx @@ -2092,7 +2092,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { //do custom messages processing if any has been set for ( WinProcClasses::iterator it=_window_proc_classes.begin() ; it != _window_proc_classes.end(); it++ ){ - (*it)->wnd_proc(hwnd, msg, wparam, lparam); + (*it)->wnd_proc(this, hwnd, msg, wparam, lparam); } return DefWindowProc(hwnd, msg, wparam, lparam); @@ -2860,14 +2860,15 @@ bool WinGraphicsWindow::supports_window_procs() const{ } //////////////////////////////////////////////////////////////////// -// Function: WinGraphicsWindow::is_touch_msg +// Function: WinGraphicsWindow::is_touch_event // Access: Public, Virtual // Description: Returns whether the specified event msg is a touch message. // //////////////////////////////////////////////////////////////////// -bool WinGraphicsWindow::is_touch_msg(UINT msg){ +bool WinGraphicsWindow:: +is_touch_event(GraphicsWindowProcCallbackData* callbackData){ #ifdef PANDA_WIN7 - return msg == WM_TOUCH; + return callbackData->get_msg() == WM_TOUCH; #else return false; #endif diff --git a/panda/src/windisplay/winGraphicsWindow.h b/panda/src/windisplay/winGraphicsWindow.h index 9732903e01..f7029f7c1a 100644 --- a/panda/src/windisplay/winGraphicsWindow.h +++ b/panda/src/windisplay/winGraphicsWindow.h @@ -83,7 +83,7 @@ public: virtual void clear_window_procs(); virtual bool supports_window_procs() const; - virtual bool is_touch_msg(UINT msg); + virtual bool is_touch_event(GraphicsWindowProcCallbackData* callbackData); virtual int get_num_touches(); virtual TouchInfo get_touch_info(int index);