Panda3D
 All Classes Functions Variables Enumerations
windowProperties.cxx
1 // Filename: windowProperties.cxx
2 // Created by: drose (13Aug02)
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 "windowProperties.h"
16 #include "config_display.h"
17 #include "nativeWindowHandle.h"
18 
19 WindowProperties *WindowProperties::_default_properties = NULL;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: WindowProperties::Constructor
23 // Access: Published
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 WindowProperties::
27 WindowProperties() {
28  clear();
29 }
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: WindowProperties::Copy Assignment Operator
33 // Access: Published
34 // Description:
35 ////////////////////////////////////////////////////////////////////
36 void WindowProperties::
37 operator = (const WindowProperties &copy) {
38  _specified = copy._specified;
39  _origin = copy._origin;
40  _size = copy._size;
41  _title = copy._title;
42  _icon_filename = copy._icon_filename;
43  _cursor_filename = copy._cursor_filename;
44  _z_order = copy._z_order;
45  _flags = copy._flags;
46  _mouse_mode = copy._mouse_mode;
47  _parent_window = copy._parent_window;
48 }
49 
50 ////////////////////////////////////////////////////////////////////
51 // Function: WindowProperties::get_config_properties
52 // Access: Published, Static
53 // Description: Returns a WindowProperties structure with all of the
54 // default values filled in according to the user's
55 // config file.
56 ////////////////////////////////////////////////////////////////////
59  WindowProperties props;
60 
61  props.set_open(true);
62 
63  if (win_size.get_num_words() == 1) {
64  props.set_size(win_size[0], win_size[0]);
65  } else if (win_size.get_num_words() >= 2) {
66  props.set_size(win_size[0], win_size[1]);
67  }
68 
69  if (win_origin.get_num_words() >= 2) {
70  props.set_origin(win_origin[0], win_origin[1]);
71  }
72 
73  props.set_fullscreen(fullscreen);
74  props.set_undecorated(undecorated);
75  props.set_fixed_size(win_fixed_size);
76  props.set_cursor_hidden(cursor_hidden);
77  if (!icon_filename.empty()) {
78  props.set_icon_filename(icon_filename);
79  }
80  if (!cursor_filename.empty()) {
81  props.set_cursor_filename(cursor_filename);
82  }
83  if (z_order.has_value()) {
84  props.set_z_order(z_order);
85  }
86  props.set_title(window_title);
87  if (parent_window_handle.get_value() != 0) {
88  props.set_parent_window(NativeWindowHandle::make_int(parent_window_handle));
89  } else if (!subprocess_window.empty()) {
90  props.set_parent_window(NativeWindowHandle::make_subprocess(subprocess_window));
91  }
92  props.set_mouse_mode(M_absolute);
93 
94  return props;
95 }
96 
97 ////////////////////////////////////////////////////////////////////
98 // Function: WindowProperties::get_default
99 // Access: Published, Static
100 // Description: Returns the "default" WindowProperties. If
101 // set_default() has been called, this returns that
102 // WindowProperties structure; otherwise, this returns
103 // get_config_properties().
104 ////////////////////////////////////////////////////////////////////
107  if (_default_properties != NULL) {
108  return *_default_properties;
109  } else {
110  return get_config_properties();
111  }
112 }
113 
114 ////////////////////////////////////////////////////////////////////
115 // Function: WindowProperties::set_default
116 // Access: Published, Static
117 // Description: Replaces the "default" WindowProperties with the
118 // specified structure. The specified WindowProperties
119 // will be returned by future calls to get_default(),
120 // until clear_default() is called.
121 //
122 // Note that this completely replaces the default
123 // properties; it is not additive.
124 ////////////////////////////////////////////////////////////////////
126 set_default(const WindowProperties &default_properties) {
127  if (_default_properties == NULL) {
128  _default_properties = new WindowProperties;
129  }
130  (*_default_properties) = default_properties;
131 }
132 
133 ////////////////////////////////////////////////////////////////////
134 // Function: WindowProperties::clear_default
135 // Access: Published, Static
136 // Description: Returns the "default" WindowProperties to whatever
137 // is specified in the user's config file.
138 ////////////////////////////////////////////////////////////////////
141  if (_default_properties != NULL) {
142  delete _default_properties;
143  _default_properties = NULL;
144  }
145 }
146 
147 ////////////////////////////////////////////////////////////////////
148 // Function: WindowProperties::size
149 // Access: Published, Static
150 // Description: Returns a WindowProperties structure with only the
151 // size specified. The size is the only property that
152 // matters to buffers.
153 ////////////////////////////////////////////////////////////////////
155 size(int x_size, int y_size) {
156  WindowProperties props;
157  props.set_size(x_size, y_size);
158  return props;
159 }
160 
161 ////////////////////////////////////////////////////////////////////
162 // Function: WindowProperties::operator ==
163 // Access: Published
164 // Description:
165 ////////////////////////////////////////////////////////////////////
166 bool WindowProperties::
167 operator == (const WindowProperties &other) const {
168  return (_specified == other._specified &&
169  _flags == other._flags &&
170  _origin == other._origin &&
171  _size == other._size &&
172  _z_order == other._z_order &&
173  _title == other._title &&
174  _icon_filename == other._icon_filename &&
175  _cursor_filename == other._cursor_filename &&
176  _mouse_mode == other._mouse_mode &&
177  _parent_window == other._parent_window);
178 }
179 
180 ////////////////////////////////////////////////////////////////////
181 // Function: WindowProperties::clear
182 // Access: Published
183 // Description: Unsets all properties that have been specified so
184 // far, and resets the WindowProperties structure to its
185 // initial empty state.
186 ////////////////////////////////////////////////////////////////////
188 clear() {
189  _specified = 0;
190  _origin = LPoint2i::zero();
191  _size = LVector2i::zero();
192  _title = string();
193  _icon_filename = Filename();
194  _cursor_filename = Filename();
195  _z_order = Z_normal;
196  _flags = 0;
197  _mouse_mode = M_absolute;
198  _parent_window = NULL;
199 }
200 
201 ////////////////////////////////////////////////////////////////////
202 // Function: WindowProperties::set_parent_window
203 // Access: Published
204 // Description: Specifies the window that this window should be
205 // attached to.
206 //
207 // This is a deprecated variant on this method, and
208 // exists only for backward compatibility. Future code
209 // should use the version of set_parent_window() below
210 // that receives a WindowHandle object; that interface
211 // is much more robust.
212 //
213 // In this deprecated variant, the actual value for
214 // "parent" is platform-specific. On Windows, it is the
215 // HWND of the parent window, cast to an unsigned
216 // integer. On X11, it is the Window pointer of the
217 // parent window, similarly cast. On OSX, this is the
218 // NSWindow pointer, which doesn't appear to work at
219 // all.
220 ////////////////////////////////////////////////////////////////////
222 set_parent_window(size_t parent) {
223  if (parent == 0) {
225  } else {
226  PT(WindowHandle) handle = NativeWindowHandle::make_int(parent);
227  set_parent_window(handle);
228  }
229 }
230 
231 ////////////////////////////////////////////////////////////////////
232 // Function: WindowProperties::add_properties
233 // Access: Published
234 // Description: Sets any properties that are explicitly specified in
235 // other on this object. Leaves other properties
236 // unchanged.
237 ////////////////////////////////////////////////////////////////////
240  if (other.has_origin()) {
241  set_origin(other.get_origin());
242  }
243  if (other.has_size()) {
244  set_size(other.get_size());
245  }
246  if (other.has_title()) {
247  set_title(other.get_title());
248  }
249  if (other.has_undecorated()) {
251  }
252  if (other.has_fixed_size()) {
254  }
255  if (other.has_fullscreen()) {
257  }
258  if (other.has_foreground()) {
260  }
261  if (other.has_minimized()) {
262  set_minimized(other.get_minimized());
263  }
264  if (other.has_raw_mice()) {
265  set_raw_mice(other.get_raw_mice());
266  }
267  if (other.has_open()) {
268  set_open(other.get_open());
269  }
270  if (other.has_cursor_hidden()) {
272  }
273  if (other.has_icon_filename()) {
275  }
276  if (other.has_cursor_filename()) {
278  }
279  if (other.has_z_order()) {
280  set_z_order(other.get_z_order());
281  }
282  if (other.has_mouse_mode()) {
284  }
285  if (other.has_parent_window()) {
287  }
288 }
289 
290 ////////////////////////////////////////////////////////////////////
291 // Function: WindowProperties::output
292 // Access: Published
293 // Description: Sets any properties that are explicitly specified in
294 // other on this object. Leaves other properties
295 // unchanged.
296 ////////////////////////////////////////////////////////////////////
298 output(ostream &out) const {
299  if (has_origin()) {
300  out << "origin=(" << get_x_origin() << ", " << get_y_origin() << ") ";
301  }
302  if (has_size()) {
303  out << "size=(" << get_x_size() << ", " << get_y_size() << ") ";
304  }
305  if (has_title()) {
306  out << "title=\"" << get_title() << "\"" << " ";
307  }
308  if (has_undecorated()) {
309  out << (get_undecorated() ? "undecorated " : "!undecorated ");
310  }
311  if (has_fixed_size()) {
312  out << (get_fixed_size() ? "fixed_size " : "!fixed_size ");
313  }
314  if (has_fullscreen()) {
315  out << (get_fullscreen() ? "fullscreen " : "!fullscreen ");
316  }
317  if (has_foreground()) {
318  out << (get_foreground() ? "foreground " : "!foreground ");
319  }
320  if (has_minimized()) {
321  out << (get_minimized() ? "minimized " : "!minimized ");
322  }
323  if (has_raw_mice()) {
324  out << (get_raw_mice() ? "raw_mice " : "!raw_mice ");
325  }
326  if (has_open()) {
327  out << (get_open() ? "open " : "!open ");
328  }
329  if (has_cursor_hidden()) {
330  out << (get_cursor_hidden() ? "cursor_hidden " : "!cursor_hidden ");
331  }
332  if (has_icon_filename()) {
333  out << "icon:" << get_icon_filename() << " ";
334  }
335  if (has_cursor_filename()) {
336  out << "cursor:" << get_cursor_filename() << " ";
337  }
338  if (has_z_order()) {
339  out << get_z_order() << " ";
340  }
341  if (has_mouse_mode()) {
342  out << get_mouse_mode() << " ";
343  }
344  if (has_parent_window()) {
345  if (get_parent_window() == NULL) {
346  out << "parent:none ";
347  } else {
348  out << "parent:" << *get_parent_window() << " ";
349  }
350  }
351 }
352 
353 ostream &
354 operator << (ostream &out, WindowProperties::ZOrder z_order) {
355  switch (z_order) {
356  case WindowProperties::Z_bottom:
357  return out << "bottom";
358 
359  case WindowProperties::Z_normal:
360  return out << "normal";
361 
362  case WindowProperties::Z_top:
363  return out << "top";
364  }
365 
366  return out << "**invalid WindowProperties::ZOrder(" << (int)z_order << ")**";
367 }
368 
369 istream &
370 operator >> (istream &in, WindowProperties::ZOrder &z_order) {
371  string word;
372  in >> word;
373 
374  if (word == "bottom") {
375  z_order = WindowProperties::Z_bottom;
376 
377  } else if (word == "top") {
378  z_order = WindowProperties::Z_top;
379 
380  } else if (word == "normal") {
381  z_order = WindowProperties::Z_normal;
382 
383  } else {
384  display_cat.warning()
385  << "Unknown z-order: " << word << "\n";
386  z_order = WindowProperties::Z_normal;
387  }
388 
389  return in;
390 }
391 
392 //
393 // MouseMode operators
394 //
395 
396 ostream &
397 operator << (ostream &out, WindowProperties::MouseMode mode) {
398  switch (mode) {
399  case WindowProperties::M_absolute:
400  return out << "absolute";
401  case WindowProperties::M_relative:
402  return out << "relative";
403  case WindowProperties::M_confined:
404  return out << "confined";
405  }
406  return out << "**invalid WindowProperties::MouseMode(" << (int)mode << ")**";
407 }
408 
409 istream &
410 operator >> (istream &in, WindowProperties::MouseMode &mode) {
411  string word;
412  in >> word;
413 
414  if (word == "absolute") {
415  mode = WindowProperties::M_absolute;
416  } else if (word == "relative") {
417  mode = WindowProperties::M_relative;
418  } else if (word == "confined") {
419  mode = WindowProperties::M_confined;
420  } else {
421  display_cat.warning()
422  << "Unknown mouse mode: " << word << "\n";
423  mode = WindowProperties::M_absolute;
424  }
425 
426  return in;
427 }
int get_x_origin() const
Returns the x coordinate of the window&#39;s top-left corner, not including decorations.
void clear()
Unsets all properties that have been specified so far, and resets the WindowProperties structure to i...
void set_cursor_hidden(bool cursor_hidden)
Specifies whether the mouse cursor should be visible.
bool has_cursor_filename() const
Returns true if set_cursor_filename() has been specified.
This object represents a window on the desktop, not necessarily a Panda window.
Definition: windowHandle.h:40
int get_num_words() const
Returns the number of words in the variable&#39;s value.
const Filename & get_icon_filename() const
Returns the icon filename associated with the window.
static WindowProperties size(int x_size, int y_size)
Returns a WindowProperties structure with only the size specified.
bool has_cursor_hidden() const
Returns true if set_cursor_hidden() has been specified.
const string & get_title() const
Returns the window&#39;s title.
static WindowProperties get_config_properties()
Returns a WindowProperties structure with all of the default values filled in according to the user&#39;s...
bool get_open() const
Returns true if the window is open.
void set_parent_window(size_t parent)
Specifies the window that this window should be attached to.
void set_raw_mice(bool raw_mice)
Specifies whether the window should read the raw mouse devices.
bool get_minimized() const
Returns true if the window is minimized.
bool has_icon_filename() const
Returns true if set_icon_filename() has been specified.
static const LPoint2i & zero()
Returns a zero-length point.
Definition: lpoint2.h:813
void set_fixed_size(bool fixed_size)
Specifies whether the window should be resizable by the user.
void set_mouse_mode(MouseMode mode)
Specifies the mode in which the window is to operate its mouse pointer.
static void set_default(const WindowProperties &default_properties)
Replaces the &quot;default&quot; WindowProperties with the specified structure.
int get_y_size() const
Returns size in pixels in the y dimension of the useful part of the window, not including decorations...
void set_size(const LVector2i &size)
Specifies the requested size of the window, in pixels.
int get_y_origin() const
Returns the y coordinate of the window&#39;s top-left corner, not including decorations.
void output(ostream &out) const
Sets any properties that are explicitly specified in other on this object.
const LPoint2i & get_origin() const
Returns the coordinates of the window&#39;s top-left corner, not including decorations.
void set_fullscreen(bool fullscreen)
Specifies whether the window should be opened in fullscreen mode (true) or normal windowed mode (fals...
bool has_z_order() const
Returns true if the window z_order has been specified, false otherwise.
void set_icon_filename(const Filename &icon_filename)
Specifies the file that contains the icon to associate with the window when it is minimized...
bool get_fullscreen() const
Returns true if the window is in fullscreen mode.
bool has_parent_window() const
Checks the S_parent_window specification from the properties.
void set_undecorated(bool undecorated)
Specifies whether the window should be created with a visible title and border (false, the default) or not (true).
static void clear_default()
Returns the &quot;default&quot; WindowProperties to whatever is specified in the user&#39;s config file...
const LVector2i & get_size() const
Returns size in pixels of the useful part of the window, not including decorations.
MouseMode get_mouse_mode() const
See set_mouse_mode().
A container for the various kinds of properties we might ask to have on a graphics window before we o...
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
void set_z_order(ZOrder z_order)
Specifies the relative ordering of the window with respect to other windows.
static WindowProperties get_default()
Returns the &quot;default&quot; WindowProperties.
bool has_raw_mice() const
Returns true if set_raw_mice() has been specified.
const Filename & get_cursor_filename() const
Returns the icon filename associated with the mouse cursor.
bool has_title() const
Returns true if the window title has been specified, false otherwise.
bool get_foreground() const
Returns true if the window is in the foreground.
void set_origin(const LPoint2i &origin)
Specifies the origin on the screen (in pixels, relative to the top-left corner) at which the window s...
bool has_foreground() const
Returns true if set_foreground() has been specified.
static const LVector2i & zero()
Returns a zero-length vector.
Definition: lvector2.h:819
WindowHandle * get_parent_window() const
Returns the parent window specification, or NULL if there is no parent window specified.
bool has_minimized() const
Returns true if set_minimized() has been specified.
bool has_origin() const
Returns true if the window origin has been specified, false otherwise.
bool get_fixed_size() const
Returns true if the window cannot be resized by the user, false otherwise.
bool get_raw_mice() const
Returns true if the window reads the raw mice.
void set_cursor_filename(const Filename &cursor_filename)
Specifies the file that contains the icon to associate with the mouse cursor when it is within the wi...
bool has_size() const
Returns true if the window size has been specified, false otherwise.
bool get_cursor_hidden() const
Returns true if the mouse cursor is invisible.
void set_foreground(bool foreground)
Specifies whether the window should be opened in the foreground (true), or left in the background (fa...
int get_x_size() const
Returns size in pixels in the x dimension of the useful part of the window, not including decorations...
void add_properties(const WindowProperties &other)
Sets any properties that are explicitly specified in other on this object.
void set_minimized(bool minimized)
Specifies whether the window should be created minimized (true), or normal (false).
bool has_fixed_size() const
Returns true if set_fixed_size() has been specified.
void set_title(const string &title)
Specifies the title that should be assigned to the window.
bool has_undecorated() const
Returns true if set_undecorated() has been specified.
ZOrder get_z_order() const
Returns the window&#39;s z_order.
bool get_undecorated() const
Returns true if the window has no border.
void set_open(bool open)
Specifies whether the window should be open.
bool has_open() const
Returns true if set_open() has been specified.
bool has_fullscreen() const
Returns true if set_fullscreen() has been specified.
int get_value() const
Returns the variable&#39;s value.