src/Graphics/Display.cc
branchnew_graphics
changeset 411 106aaf6eadfe
parent 410 41fd46cffc52
child 412 721c60072091
--- a/src/Graphics/Display.cc	Wed Jan 21 01:57:24 2009 +0200
+++ b/src/Graphics/Display.cc	Wed Jan 21 03:33:35 2009 +0200
@@ -4,11 +4,33 @@
 namespace graphics
 {
 
-const std::vector<CL_DisplayMode> & Graphics::getDisplayModes (void) {
+Display::Display (const DisplayConfig &config) :
+    CL_DisplayWindow(GRAPHICS_WINDOW_TITLE, config.resolution.width, config.resolution.height, config.fullscreen, true),
+    config(config), 
+    fullscreen_resolution(0, 0),
+    update_timer(GRAPHICS_UPDATE_INTERVAL_MS), 
+    target(NULL)
+{
+    // connect timer signal
+    slots.connect(update_timer.sig_tick(), this, &Display::on_update);
+    slots.connect(this->sig_resize(), this, &Display::on_window_resize);
+
+    // set correct fullscreen resolution
+    if (config.fullscreen) {
+        fullscreen_resolution = config.resolution;
+
+    } else {
+        CL_DisplayMode best_mode = getBestMode();
+
+        fullscreen_resolution = PixelCoordinate(best_mode.get_resolution().width, best_mode.get_resolution().height);
+    }
+}
+
+const std::vector<CL_DisplayMode> & Display::getDisplayModes (void) {
     return CL_DisplayMode::get_display_modes();
 }
 
-const CL_DisplayMode Graphics::getBestMode (void) {
+const CL_DisplayMode Display::getBestMode (void) {
     const std::vector<CL_DisplayMode> &modes = Graphics::getDisplayModes();
 
     const CL_DisplayMode *best_mode = NULL;
@@ -26,5 +48,36 @@
     return *best_mode;
 }
 
+void Display::toggle_fullscreen (void) {
+    if (is_fullscreen()) {
+        // enter windowed mode
+        set_windowed();
+
+    } else {
+        // enter fullscreen mode
+        set_fullscreen(fullscreen_resolution.width, fullscreen_resolution.height);
+    }
 }
 
+void Display::on_update (TimeMS dt) {
+    (void) dt;
+
+    // do we have something to draw?
+    if (target) {
+        // draw it
+        target->draw(this);
+
+        // flip buffers, sync
+        flip(1);
+    }
+}
+
+void Display::on_window_resize (int new_x, int new_y) {
+    // ignore resize in fullscreen mode
+    if (is_fullscreen())
+        return;
+}
+
+
+}
+