]> git.tdb.fi Git - libs/gui.git/blob - source/graphics/window.cpp
Only set resizing flag to true in Window::reconfigure
[libs/gui.git] / source / graphics / window.cpp
1 #include "display.h"
2 #include "window.h"
3 #include "window_private.h"
4
5 using namespace std;
6
7 namespace Msp {
8 namespace Graphics {
9
10 WindowOptions::WindowOptions():
11         width(640),
12         height(480),
13         fullscreen(false),
14         resizable(false)
15 { }
16
17
18 Window::Window(Display &dpy, unsigned w, unsigned h, bool fs):
19         display(dpy)
20 {
21         options.width = w;
22         options.height = h;
23         options.fullscreen = fs;
24
25         init();
26 }
27
28 Window::Window(Display &dpy, const WindowOptions &opts):
29         display(dpy),
30         options(opts)
31 {
32         init();
33 }
34
35 void Window::init()
36 {
37         visible = false;
38         kbd_autorepeat = true;
39         resizing = false;
40         priv = new Private;
41
42         platform_init();
43
44         display.add_window(*this);
45         display.check_error();
46 }
47
48 Window::~Window()
49 {
50         platform_cleanup();
51
52         display.remove_window(*this);
53
54         if(options.fullscreen && visible)
55                 display.restore_mode();
56
57         delete priv;
58 }
59
60 void Window::reconfigure(const WindowOptions &opts)
61 {
62         bool fullscreen_changed = (opts.fullscreen!=options.fullscreen);
63         if(opts.width!=options.width || opts.height!=options.height)
64                 resizing = true;
65
66         if(visible)
67         {
68                 if(opts.fullscreen)
69                         display.set_mode(VideoMode(opts.width, opts.height));
70                 else if(fullscreen_changed)
71                         display.restore_mode();
72         }
73
74         options = opts;
75         platform_reconfigure(fullscreen_changed);
76 }
77
78 void Window::set_keyboard_autorepeat(bool r)
79 {
80         kbd_autorepeat = r;
81 }
82
83 void Window::show()
84 {
85         platform_show();
86         visible = true;
87
88         if(options.fullscreen)
89         {
90                 display.set_mode(VideoMode(options.width, options.height), true);
91                 warp_pointer(options.width/2, options.height/2);
92         }
93 }
94
95 void Window::hide()
96 {
97         platform_hide();
98         visible = false;
99
100         if(options.fullscreen)
101                 display.restore_mode();
102 }
103
104 } // namespace Graphics
105 } // namespace Msp