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