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