2 #include "Display.hh" |
2 #include "Display.hh" |
3 |
3 |
4 namespace graphics |
4 namespace graphics |
5 { |
5 { |
6 |
6 |
7 const std::vector<CL_DisplayMode> & Graphics::getDisplayModes (void) { |
7 Display::Display (const DisplayConfig &config) : |
|
8 CL_DisplayWindow(GRAPHICS_WINDOW_TITLE, config.resolution.width, config.resolution.height, config.fullscreen, true), |
|
9 config(config), |
|
10 fullscreen_resolution(0, 0), |
|
11 update_timer(GRAPHICS_UPDATE_INTERVAL_MS), |
|
12 target(NULL) |
|
13 { |
|
14 // connect timer signal |
|
15 slots.connect(update_timer.sig_tick(), this, &Display::on_update); |
|
16 slots.connect(this->sig_resize(), this, &Display::on_window_resize); |
|
17 |
|
18 // set correct fullscreen resolution |
|
19 if (config.fullscreen) { |
|
20 fullscreen_resolution = config.resolution; |
|
21 |
|
22 } else { |
|
23 CL_DisplayMode best_mode = getBestMode(); |
|
24 |
|
25 fullscreen_resolution = PixelCoordinate(best_mode.get_resolution().width, best_mode.get_resolution().height); |
|
26 } |
|
27 } |
|
28 |
|
29 const std::vector<CL_DisplayMode> & Display::getDisplayModes (void) { |
8 return CL_DisplayMode::get_display_modes(); |
30 return CL_DisplayMode::get_display_modes(); |
9 } |
31 } |
10 |
32 |
11 const CL_DisplayMode Graphics::getBestMode (void) { |
33 const CL_DisplayMode Display::getBestMode (void) { |
12 const std::vector<CL_DisplayMode> &modes = Graphics::getDisplayModes(); |
34 const std::vector<CL_DisplayMode> &modes = Graphics::getDisplayModes(); |
13 |
35 |
14 const CL_DisplayMode *best_mode = NULL; |
36 const CL_DisplayMode *best_mode = NULL; |
15 |
37 |
16 for (std::vector<CL_DisplayMode>::const_iterator it = modes.begin(); it != modes.end(); it++) |
38 for (std::vector<CL_DisplayMode>::const_iterator it = modes.begin(); it != modes.end(); it++) |
24 throw Error("No available video modes!"); |
46 throw Error("No available video modes!"); |
25 |
47 |
26 return *best_mode; |
48 return *best_mode; |
27 } |
49 } |
28 |
50 |
|
51 void Display::toggle_fullscreen (void) { |
|
52 if (is_fullscreen()) { |
|
53 // enter windowed mode |
|
54 set_windowed(); |
|
55 |
|
56 } else { |
|
57 // enter fullscreen mode |
|
58 set_fullscreen(fullscreen_resolution.width, fullscreen_resolution.height); |
|
59 } |
29 } |
60 } |
30 |
61 |
|
62 void Display::on_update (TimeMS dt) { |
|
63 (void) dt; |
|
64 |
|
65 // do we have something to draw? |
|
66 if (target) { |
|
67 // draw it |
|
68 target->draw(this); |
|
69 |
|
70 // flip buffers, sync |
|
71 flip(1); |
|
72 } |
|
73 } |
|
74 |
|
75 void Display::on_window_resize (int new_x, int new_y) { |
|
76 // ignore resize in fullscreen mode |
|
77 if (is_fullscreen()) |
|
78 return; |
|
79 } |
|
80 |
|
81 |
|
82 } |
|
83 |