src/Graphics.hh
author Tero Marttila <terom@fixme.fi>
Tue, 13 Jan 2009 23:15:47 +0200
changeset 393 5dd4d782cf3a
parent 392 6c4dc68360eb
child 394 82def222fe7d
permissions -rw-r--r--
a basic implementation of game messages, plus some weird GameStateEvent stuff
#ifndef GRAPHICS_HH
#define GRAPHICS_HH

#include "GraphicsPointer.hh"

#include "GameState.hh"
#include "Input.hh"
#include "Timer.hh"
#include "Engine.hh"
#include "Config.hh"

#include "GameMessageView.hh"

#include <ClanLib/core.h>
#include <ClanLib/gl.h>
#include <ClanLib/display.h>

/**
 * This handles drawing the GameState with an appropriate camera view each frame, loading fonts, and currently,
 * handling the input from Input to GameState.
 */
class Graphics : public GameStateEventHandler, public CL_DisplayWindow {
private:
    Engine &engine;
    GameState &state;

    PixelCoordinate resolution;
    
    CL_SlotContainer slots;
    
    Timer update_timer;

    Input input;

    // current GUI input state
    GuiInput flags;
    
    // basic fonts
    CL_Font simple_font;

    // view components
    GameMessageView message_view;

public:
    Graphics (Engine &engine, GameState &state, PixelCoordinate resolution, bool fullscreen);
    
    /**
     * Returns a CL_Font that can be used for drawing text
     */
    CL_Font& getSimpleFont (void) { return simple_font; }
    
    /**
     * 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);
    
private:
    /**
     * Reads current input events from Input and applies them, using LocalPlayer::handleInput and
     * Graphics::handle_input.
     */
    void check_input (void);
    
    /**
     * Handles GuiInput flags read from Input.
     */
    void handle_input (GuiInput flags);

    void do_redraw (void);
    
    void on_update (TimeMS tick_length);
    
    void draw_player_info(CL_GraphicContext *gc, Player *p);
        
protected:
    /* GameStateEventHandler */    
    virtual void on_player_joined (Player *p);
    virtual void on_player_left (Player *p);
};

#endif /* GRAPHICS_HH */