Panda3D
Loading...
Searching...
No Matches
winGraphicsWindow.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file winGraphicsWindow.h
10 * @author drose
11 * @date 2002-12-20
12 */
13
14#ifndef WINGRAPHICSWINDOW_H
15#define WINGRAPHICSWINDOW_H
16
17#include "pandabase.h"
18#include "graphicsWindow.h"
19#ifndef WIN32_LEAN_AND_MEAN
20 #define WIN32_LEAN_AND_MEAN 1
21#endif
22#include <windows.h>
23
24class WinGraphicsPipe;
25
26#define PM_ACTIVE (WM_APP+123)
27
28#define PM_INACTIVE (WM_APP+124)
29
30#define MAX_TOUCHES 20
31
32typedef struct {
33 int x;
34 int y;
35 int width;
36 int height;
37} WINDOW_METRICS;
38
39#if WINVER < 0x0601
40// Not used on Windows XP, but we still need to define it.
41typedef struct tagTOUCHINPUT {
42 LONG x;
43 LONG y;
44 HANDLE hSource;
45 DWORD dwID;
46 DWORD dwFlags;
47 DWORD dwMask;
48 DWORD dwTime;
49 ULONG_PTR dwExtraInfo;
50 DWORD cxContact;
51 DWORD cyContact;
52} TOUCHINPUT, *PTOUCHINPUT;
53#endif
54
55/**
56 * An abstract base class for glGraphicsWindow and dxGraphicsWindow (and, in
57 * general, graphics windows that interface with the Microsoft Windows API).
58 *
59 * This class includes all the code for manipulating windows themselves:
60 * opening them, closing them, responding to user keyboard and mouse input,
61 * and so on. It does not make any 3-D rendering calls into the window; that
62 * is the province of the GraphicsStateGuardian.
63 */
64class EXPCL_PANDAWIN WinGraphicsWindow : public GraphicsWindow {
65public:
67 const std::string &name,
68 const FrameBufferProperties &fb_prop,
69 const WindowProperties &win_prop,
70 int flags,
72 GraphicsOutput *host);
73 virtual ~WinGraphicsWindow();
74
75 virtual MouseData get_pointer(int device) const;
76 virtual bool move_pointer(int device, int x, int y);
77
78 virtual void close_ime();
79
80 virtual void begin_flip();
81
82 virtual void process_events();
83 virtual void set_properties_now(WindowProperties &properties);
84 void receive_windows_message(unsigned int msg, int wparam, int lparam);
85 virtual LONG window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
86 static LONG WINAPI static_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
87 virtual bool handle_mouse_motion(int x, int y);
88 virtual void handle_mouse_exit();
89
90 INLINE HWND get_ime_hwnd();
91
92 virtual void add_window_proc( const GraphicsWindowProc* wnd_proc_object );
93 virtual void remove_window_proc( const GraphicsWindowProc* wnd_proc_object );
94 virtual void clear_window_procs();
95 virtual bool supports_window_procs() const;
96
97 virtual bool is_touch_event(GraphicsWindowProcCallbackData* callbackData);
98 virtual int get_num_touches();
99 virtual TouchInfo get_touch_info(int index);
100
101protected:
102 void trigger_flip();
103 virtual void close_window();
104 virtual bool open_window();
105 virtual void fullscreen_minimized(WindowProperties &properties);
106 virtual void fullscreen_restored(WindowProperties &properties);
107
108 virtual bool do_reshape_request(int x_origin, int y_origin, bool has_origin,
109 int x_size, int y_size);
110
111 virtual void handle_reshape();
112 virtual bool do_fullscreen_resize(int x_size, int y_size);
113
114 bool do_fullscreen_switch(int x_size, int y_size);
115 virtual bool do_fullscreen_switch();
116 virtual bool do_windowed_switch();
117 bool do_fullscreen_enable(int x_size, int y_size);
118 virtual bool do_fullscreen_enable();
119 virtual bool do_fullscreen_disable();
120
121 virtual bool calculate_metrics(bool fullscreen, DWORD style,
122 WINDOW_METRICS &metrics, bool &has_origin);
123
124 DWORD make_style(const WindowProperties &properties);
125
126 virtual void reconsider_fullscreen_size(DWORD &x_size, DWORD &y_size,
127 DWORD &bitdepth);
128
129 virtual void support_overlay_window(bool flag);
130
131private:
132 bool open_graphic_window();
133 void adjust_z_order();
134 void adjust_z_order(WindowProperties::ZOrder last_z_order,
135 WindowProperties::ZOrder this_z_order);
136 void initialize_input_devices();
137 void handle_raw_input(HRAWINPUT hraw);
138 void track_mouse_leaving(HWND hwnd);
139 bool confine_cursor();
140 void set_focus();
141
142 static void process_1_event();
143
144 void handle_keypress(ButtonHandle key, int x, int y, double time);
145 void handle_keyresume(ButtonHandle key, double time);
146 void handle_keyrelease(ButtonHandle key, double time);
147 void handle_raw_keypress(ButtonHandle key, double time);
148 void handle_raw_keyrelease(ButtonHandle key, double time);
149 ButtonHandle lookup_key(WPARAM wparam) const;
150 ButtonHandle lookup_raw_key(LPARAM lparam) const;
151 virtual ButtonMap *get_keyboard_map() const;
152 INLINE int translate_mouse(int pos) const;
153 INLINE void set_cursor_in_window();
154 INLINE void set_cursor_out_of_window();
155
156 INLINE static double get_message_time();
157
158 void resend_lost_keypresses();
159 void release_all_buttons();
160 static void update_cursor_window(WinGraphicsWindow *to_window);
161 static void hide_or_show_cursor(bool hide_cursor);
162
163 static bool find_acceptable_display_mode(DWORD dwWidth, DWORD dwHeight,
164 DWORD bpp, DEVMODE &dm);
165 static void show_error_message(DWORD message_id = 0);
166
167protected:
168 HWND _hWnd;
169 HWND _hparent;
170
171private:
172 HWND _ime_hWnd;
173 bool _ime_open;
174 bool _ime_active;
175 bool _tracking_mouse_leaving;
176 bool _bCursor_in_WindowClientArea;
177 HANDLE _input_device_handle[32];
178 HCURSOR _cursor;
179 DEVMODE _fullscreen_display_mode;
180
181 bool _lost_keypresses;
182
183 // These are used to store the status of the individual left and right
184 // shift, control, and alt keys. Keyboard events are not sent for these
185 // individual keys, but for each pair as a whole. The status of each key
186 // must be checked as keypress and keyrelease events are received.
187 bool _lshift_down;
188 bool _rshift_down;
189 bool _lcontrol_down;
190 bool _rcontrol_down;
191 bool _lalt_down;
192 bool _ralt_down;
193
195
196 // following adds support platform specfic window processing functions.
198 WinProcClasses _window_proc_classes;
199
200 UINT _num_touches;
201 TOUCHINPUT _touches[MAX_TOUCHES];
202
203private:
204 // We need this map to support per-window calls to window_proc().
205 typedef std::map<HWND, WinGraphicsWindow *> WindowHandles;
206 static WindowHandles _window_handles;
207
208 // And we need a static pointer to the current WinGraphicsWindow we are
209 // creating at the moment, since CreateWindow() starts generating window
210 // events before it gives us the window handle.
211 static WinGraphicsWindow *_creating_window;
212
213/*
214 * This tracks the current GraphicsWindow whose client area contains the
215 * mouse. There will only be one of these at a time, and storing the pointer
216 * here allows us to handle ambiguities in the order in which messages are
217 * passed from Windows to the various windows we manage. This pointer is used
218 * by set_cursor_in_window() to determine when it is time to call
219 * update_cursor() to hide the cursor (or do other related operations).
220 */
221 static WinGraphicsWindow *_cursor_window;
222 static bool _cursor_hidden;
223 static bool _got_saved_params;
224 static int _saved_mouse_trails;
225 static BOOL _saved_cursor_shadow;
226 static BOOL _saved_mouse_vanish;
227
228 // The mouse constraints before applying mouse mode M_confined.
229 static RECT _mouse_unconfined_cliprect;
230
231 // Since the Panda API requests icons and cursors by filename, we need a
232 // table mapping filenames to handles, so we can avoid re-reading the file
233 // each time we change icons.
235 static IconFilenames _icon_filenames;
236 static IconFilenames _cursor_filenames;
237
238 static HICON get_icon(const Filename &filename);
239 static HCURSOR get_cursor(const Filename &filename);
240
241 // The table of window classes we have registered. We need to register a
242 // different window class for each different window icon (the cursor we can
243 // specify dynamically, later). We might have other requirements too,
244 // later.
245 class WindowClass {
246 public:
247 INLINE WindowClass(const WindowProperties &props);
248 INLINE bool operator < (const WindowClass &other) const;
249
250 std::wstring _name;
251 HICON _icon;
252 };
253
255 static WindowClasses _window_classes;
256 static int _window_class_index;
257
258 static const WindowClass &register_window_class(const WindowProperties &props);
259private:
260 // This subclass of WindowHandle is stored in _window_handle to represent
261 // this particular window. We use it to add hooks for communicating with
262 // the parent window, in particular to receive keyboard events from the
263 // parent window when necessary.
264 class WinWindowHandle : public WindowHandle {
265 public:
266 WinWindowHandle(WinGraphicsWindow *window,
267 const WindowHandle &copy);
268 void clear_window();
269
270 protected:
271 virtual void receive_windows_message(unsigned int msg, int wparam, int lparam);
272
273 private:
274 // Not reference-counted, to avoid a circular reference count.
275 WinGraphicsWindow *_window;
276
277 public:
278 static TypeHandle get_class_type() {
279 return _type_handle;
280 }
281 static void init_type() {
282 WindowHandle::init_type();
283 register_type(_type_handle, "WinWindowHandle",
284 WindowHandle::get_class_type());
285 }
286 virtual TypeHandle get_type() const {
287 return get_class_type();
288 }
289 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
290
291 private:
292 static TypeHandle _type_handle;
293 };
294
295public:
296 static TypeHandle get_class_type() {
297 return _type_handle;
298 }
299 static void init_type() {
300 GraphicsWindow::init_type();
301 register_type(_type_handle, "WinGraphicsWindow",
302 GraphicsWindow::get_class_type());
303 WinWindowHandle::init_type();
304 }
305 virtual TypeHandle get_type() const {
306 return get_class_type();
307 }
308 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
309
310private:
311 static TypeHandle _type_handle;
312};
313
314#define PRINT_LAST_ERROR 0
315extern EXPCL_PANDAWIN void PrintErrorMessage(DWORD msgID);
316extern EXPCL_PANDAWIN void ClearToBlack(HWND hWnd, const WindowProperties &props);
317extern EXPCL_PANDAWIN void get_client_rect_screen(HWND hwnd, RECT *view_rect);
318
319#include "winGraphicsWindow.I"
320
321#endif
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
This class represents a map containing all of the buttons of a (keyboard) device, though it can also ...
Definition buttonMap.h:30
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
This class is the main interface to controlling the render process.
This is a base class for the various different classes that represent the result of a frame of render...
virtual void begin_flip()
This function will be called within the draw thread after end_frame() has been called on all windows,...
An object to create GraphicsOutputs that share a particular 3-D API.
Encapsulates all the communication with a particular instance of a given rendering backend.
This is a virtual input device that represents the keyboard and mouse pair that is associated with a ...
This specialization on CallbackData is passed when the callback is initiated from from an implementat...
Defines an interface for storing platform-specific window processor methods.
A window, fullscreen or on a desktop, into which a graphics device sends its output for interactive d...
virtual bool is_touch_event(GraphicsWindowProcCallbackData *callbackData)
Returns whether the specified event msg is a touch message.
virtual bool move_pointer(int device, int x, int y)
Forces the pointer to the indicated position within the window, if possible.
virtual MouseData get_pointer(int device) const
See GraphicsWindowInputDevice::enable_pointer_mode.
virtual void close_ime()
Forces the ime window to close if any.
virtual int get_num_touches()
Returns the current number of touches on this window.
virtual void process_events()
Do whatever processing is necessary to ensure that the window responds to user events.
virtual bool supports_window_procs() const
Returns whether this window supports adding of Windows proc handlers.
virtual void set_properties_now(WindowProperties &properties)
Applies the requested set of properties to the window, if possible, for instance to request a change ...
virtual TouchInfo get_touch_info(int index)
Returns the TouchInfo object describing the specified touch.
virtual ButtonMap * get_keyboard_map() const
Returns a ButtonMap containing the association between raw buttons and virtual buttons.
Stores information for a single touch event.
Definition touchInfo.h:22
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
This is an abstract base class for wglGraphicsPipe and wdxGraphicsPipe; that is, those graphics pipes...
An abstract base class for glGraphicsWindow and dxGraphicsWindow (and, in general,...
This object represents a window on the desktop, not necessarily a Panda window.
A container for the various kinds of properties we might ask to have on a graphics window before we o...
This is our own Panda specialization on the default STL map.
Definition pmap.h:49
This is our own Panda specialization on the default STL set.
Definition pset.h:49
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
BEGIN_PUBLISH typedef PointerData MouseData
Deprecated alias for PointerData.
Definition mouseData.h:23
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
EXPCL_PANDAWIN void get_client_rect_screen(HWND hwnd, RECT *view_rect)
Fills view_rect with the coordinates of the client area of the indicated window, converted to screen ...