Panda3D

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