src/Graphics/Display.hh
author Tero Marttila <terom@fixme.fi>
Wed, 21 Jan 2009 01:57:24 +0200
branchnew_graphics
changeset 410 41fd46cffc52
child 411 106aaf6eadfe
permissions -rw-r--r--
start working out the Graphics/* code, this is a long way from compiling, let alone working
#ifndef GRAPHICS_DISPLAY_HH
#define GRAPHICS_DISPLAY_HH

#include "../Types.hh"
#include "../Config.hh"
#include "../Timer.hh"

#include <ClanLib/display.h>

namespace graphics
{

struct DisplayConfig {
    /** Display resolution */
    PixelDimensions resolution;

    /** Fullscreen mode? */
    bool fullscreen;
};

/**
 * We wrap ClanLib's DisplayWindow for our own functionality. This is the core of the graphics code
 */
class Display : public CL_DisplayWindow {
private:
    /**
     * Our engine reference
     */
    Engine &engine;

    /**
     * Our configuration
     */
    DisplayConfig config;
    
    /**
     * Our timer that drives redraws
     */
    Timer update_timer;

    CL_SlotContainer slots;

public:
    /**
     * Construct default display, empty window unless otherwise build
     */
    Display (Engine &engine, const DisplayConfig &config) :
        engine(engine), config(config), update_timer(GRAPHICS_UPDATE_INTERVAL_MS)
    {
        // connect timer signal
        slots.connect(update_timer.sig_tick(), this, &Display::on_update);
        slots.connect(this->sig_resize(), this, &Display::on_window_resize);

    }

    /**
     * Returns a vector of CL_DisplayModes that lists possible display modes to use for fullscreen mode.
     */
    static const std::vector<CL_DisplayMode> & getDisplayModes (void);

    /**
     * Returns the "best" CL_DisplayMode to use for fullscreen mode.
     *
     * Currently, this just means the largest resolution.
     */
    static const CL_DisplayMode getBestMode (void);

    /**
     * Get current resolution
     *
     * XXX: should be PixelDimensions...
     */
    PixelCoordinate getResolution (void) { 
        return PixelCoordinate(get_width(), get_height());
    }

private:
    /**
     * Draw next frame
     */
    void on_update (TimeMS dt);

    /**
     * Handles window resize. This just updates resolution
     */
    void on_window_resize (int new_x, int new_y);

};

}

#endif