src/Graphics/Display.hh
branchnew_graphics
changeset 410 41fd46cffc52
child 411 106aaf6eadfe
equal deleted inserted replaced
409:1a03ff151abc 410:41fd46cffc52
       
     1 #ifndef GRAPHICS_DISPLAY_HH
       
     2 #define GRAPHICS_DISPLAY_HH
       
     3 
       
     4 #include "../Types.hh"
       
     5 #include "../Config.hh"
       
     6 #include "../Timer.hh"
       
     7 
       
     8 #include <ClanLib/display.h>
       
     9 
       
    10 namespace graphics
       
    11 {
       
    12 
       
    13 struct DisplayConfig {
       
    14     /** Display resolution */
       
    15     PixelDimensions resolution;
       
    16 
       
    17     /** Fullscreen mode? */
       
    18     bool fullscreen;
       
    19 };
       
    20 
       
    21 /**
       
    22  * We wrap ClanLib's DisplayWindow for our own functionality. This is the core of the graphics code
       
    23  */
       
    24 class Display : public CL_DisplayWindow {
       
    25 private:
       
    26     /**
       
    27      * Our engine reference
       
    28      */
       
    29     Engine &engine;
       
    30 
       
    31     /**
       
    32      * Our configuration
       
    33      */
       
    34     DisplayConfig config;
       
    35     
       
    36     /**
       
    37      * Our timer that drives redraws
       
    38      */
       
    39     Timer update_timer;
       
    40 
       
    41     CL_SlotContainer slots;
       
    42 
       
    43 public:
       
    44     /**
       
    45      * Construct default display, empty window unless otherwise build
       
    46      */
       
    47     Display (Engine &engine, const DisplayConfig &config) :
       
    48         engine(engine), config(config), update_timer(GRAPHICS_UPDATE_INTERVAL_MS)
       
    49     {
       
    50         // connect timer signal
       
    51         slots.connect(update_timer.sig_tick(), this, &Display::on_update);
       
    52         slots.connect(this->sig_resize(), this, &Display::on_window_resize);
       
    53 
       
    54     }
       
    55 
       
    56     /**
       
    57      * Returns a vector of CL_DisplayModes that lists possible display modes to use for fullscreen mode.
       
    58      */
       
    59     static const std::vector<CL_DisplayMode> & getDisplayModes (void);
       
    60 
       
    61     /**
       
    62      * Returns the "best" CL_DisplayMode to use for fullscreen mode.
       
    63      *
       
    64      * Currently, this just means the largest resolution.
       
    65      */
       
    66     static const CL_DisplayMode getBestMode (void);
       
    67 
       
    68     /**
       
    69      * Get current resolution
       
    70      *
       
    71      * XXX: should be PixelDimensions...
       
    72      */
       
    73     PixelCoordinate getResolution (void) { 
       
    74         return PixelCoordinate(get_width(), get_height());
       
    75     }
       
    76 
       
    77 private:
       
    78     /**
       
    79      * Draw next frame
       
    80      */
       
    81     void on_update (TimeMS dt);
       
    82 
       
    83     /**
       
    84      * Handles window resize. This just updates resolution
       
    85      */
       
    86     void on_window_resize (int new_x, int new_y);
       
    87 
       
    88 };
       
    89 
       
    90 }
       
    91 
       
    92 #endif