]> git.tdb.fi Git - libs/gui.git/blob - source/graphics/window.cpp
8c9d1748a199648b3ae5b1e232c99066399c0882
[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         resizing = (opts.width!=options.width || opts.height!=options.height);
64
65         if(visible)
66         {
67                 if(opts.fullscreen)
68                         display.set_mode(VideoMode(opts.width, opts.height));
69                 else if(fullscreen_changed)
70                         display.restore_mode();
71         }
72
73         options = opts;
74         platform_reconfigure(fullscreen_changed);
75 }
76
77 void Window::set_keyboard_autorepeat(bool r)
78 {
79         kbd_autorepeat = r;
80 }
81
82 void Window::show()
83 {
84         platform_show();
85         visible = true;
86
87         if(options.fullscreen)
88         {
89                 display.set_mode(VideoMode(options.width, options.height), true);
90                 warp_pointer(options.width/2, options.height/2);
91         }
92 }
93
94 void Window::hide()
95 {
96         platform_hide();
97         visible = false;
98
99         if(options.fullscreen)
100                 display.restore_mode();
101 }
102
103 } // namespace Graphics
104 } // namespace Msp