#ifndef GRAPHICS_HH
#define GRAPHICS_HH
#include "GraphicsPointer.hh"
#include "Types.hh"
#include "Config.hh"
/**
* Parameters used by Graphics
*/
struct GraphicsConfig {
/** Initial resolution to use */
PixelCoordinate resolution;
/* Use fullscreen mode at startup */
bool fullscreen;
/** Defaults */
GraphicsConfig (void) : resolution(GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT), fullscreen(GRAPHICS_FULLSCREEN) { }
};
#include "GameState.hh"
#include "Input.hh"
#include "Timer.hh"
#include "Engine.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:
/**
* Our engine reference
*/
Engine &engine;
/**
* GameState we are associated with
*/
GameState &state;
/**
* Current window resolution
*/
PixelCoordinate resolution;
/**
* Target resolution in fullscreen/windowed mode
*/
PixelCoordinate fullscreen_resolution, window_resolution;
/**
* ClanLib signal slots
*/
CL_SlotContainer slots;
/**
* Our timer that drives redraws
*/
Timer update_timer;
/**
* Our input handler for GUI and Player input
*/
Input input;
/**
* Current GUI input state
*/
GuiInput flags;
/**
* A basic font
*/
CL_Font simple_font;
/**
* View components
*/
GameMessageView message_view;
public:
/**
*
*/
Graphics (Engine &engine, GameState &state, const GraphicsConfig &config);
/**
* 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:
/**
* Shift back and forth between fullscreen and windowed mode, retaining resolutions
*/
void toggle_fullscreen (void);
/**
* 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);
/**
* Redraws entire screen
*/
void do_redraw (void);
/**
* Handles input and redraws screen
*/
void on_update (TimeMS tick_length);
/**
* Draws status view
*/
void draw_player_info (CL_GraphicContext *gc, Player *p);
/**
* Handles window resize. This just updates resolution
*/
void on_window_resize (int new_x, int new_y);
protected:
/* GameStateEventHandler */
virtual void on_player_joined (Player *p);
virtual void on_player_left (Player *p);
};
#endif /* GRAPHICS_HH */