Panda3D
pythonGraphicsWindowProc.cxx
1 // Filename: customGraphicsWindowProc.cxx
2 // Created by: Walt Destler (May 2010)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "pythonGraphicsWindowProc.h"
16 #include "graphicsWindowProcCallbackData.h"
17 
18 #ifdef HAVE_PYTHON
19 
20 TypeHandle PythonGraphicsWindowProc::_type_handle;
21 
22 ////////////////////////////////////////////////////////////////////
23 // Function: PythonGraphicWindowProc::Constructor
24 // Access: Public
25 // Description: Initializes this PythonGraphicsWindowProc to use the
26 // specified callback handler and name.
27 ////////////////////////////////////////////////////////////////////
28 PythonGraphicsWindowProc::
29 PythonGraphicsWindowProc(PyObject* function, PyObject* name) :
30  PythonCallbackObject(function)
31 {
32  _name = name;
33  Py_INCREF(_name);
34 }
35 
36 ////////////////////////////////////////////////////////////////////
37 // Function: PythonGraphicWindowProc::Constructor
38 // Access: Public, Virtual
39 // Description: Decrements references to the handler and name objects.
40 ////////////////////////////////////////////////////////////////////
41 PythonGraphicsWindowProc::
42 ~PythonGraphicsWindowProc(){
43  Py_DECREF(_name);
44 }
45 
46 #ifdef WIN32
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: PythonGraphicWindowProc::wnd_proc
50 // Access: Public, Virtual
51 // Description: A WIN32-specific method that is called when a Window
52 // proc event occurrs. Calls the python handler.
53 ////////////////////////////////////////////////////////////////////
54 LONG PythonGraphicsWindowProc::
55 wnd_proc(GraphicsWindow* graphicsWindow, HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam){
56  GraphicsWindowProcCallbackData cdata(graphicsWindow);
57  cdata.set_hwnd((int)hwnd);
58  cdata.set_msg(msg);
59  cdata.set_wparam(wparam);
60  cdata.set_lparam(lparam);
61  do_callback(&cdata);
62 
63  return 0;
64 }
65 
66 #endif // WIN32
67 
68 ////////////////////////////////////////////////////////////////////
69 // Function: PythonGraphicWindowProc::get_name
70 // Access: Public
71 // Description: Returns the python name object.
72 ////////////////////////////////////////////////////////////////////
73 PyObject* PythonGraphicsWindowProc::
74 get_name(){
75  return _name;
76 }
77 
78 #endif // HAVE_PYTHON
This specialization on CallbackData is passed when the callback is initiated from from an implementat...
A window, fullscreen or on a desktop, into which a graphics device sends its output for interactive d...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85