terom@185: #ifndef GRAPHICS_HH terom@185: #define GRAPHICS_HH terom@185: terom@233: #include "GraphicsPointer.hh" terom@408: #include "Types.hh" terom@409: #include "Config.hh" terom@408: terom@408: /** terom@408: * Parameters used by Graphics terom@408: */ terom@409: struct GraphicsConfig { terom@408: /** Initial resolution to use */ terom@408: PixelCoordinate resolution; terom@408: terom@408: /* Use fullscreen mode at startup */ terom@408: bool fullscreen; terom@409: terom@409: /** Defaults */ terom@409: GraphicsConfig (void) : resolution(GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT), fullscreen(GRAPHICS_FULLSCREEN) { } terom@408: }; terom@185: terom@185: #include "GameState.hh" terom@233: #include "Input.hh" terom@205: #include "Timer.hh" terom@185: #include "Engine.hh" terom@185: terom@393: #include "GameMessageView.hh" terom@393: terom@185: #include terom@185: #include terom@185: #include terom@185: terom@283: /** terom@283: * This handles drawing the GameState with an appropriate camera view each frame, loading fonts, and currently, terom@283: * handling the input from Input to GameState. terom@283: */ terom@393: class Graphics : public GameStateEventHandler, public CL_DisplayWindow { terom@185: private: terom@394: /** terom@394: * Our engine reference terom@394: */ terom@185: Engine &engine; terom@394: terom@394: /** terom@394: * GameState we are associated with terom@394: */ terom@185: GameState &state; terom@394: terom@394: /** terom@394: * Current window resolution terom@394: */ terom@394: PixelCoordinate resolution; terom@266: terom@394: /** terom@394: * Target resolution in fullscreen/windowed mode terom@394: */ terom@394: PixelCoordinate fullscreen_resolution, window_resolution; terom@185: terom@394: /** terom@394: * ClanLib signal slots terom@394: */ terom@185: CL_SlotContainer slots; terom@185: terom@394: /** terom@394: * Our timer that drives redraws terom@394: */ terom@205: Timer update_timer; terom@394: terom@394: /** terom@394: * Our input handler for GUI and Player input terom@394: */ terom@235: Input input; terom@233: terom@394: /** terom@394: * Current GUI input state terom@394: */ terom@233: GuiInput flags; terom@185: terom@394: /** terom@394: * A basic font terom@394: */ terom@233: CL_Font simple_font; terom@233: terom@394: /** terom@394: * View components terom@394: */ terom@393: GameMessageView message_view; terom@393: terom@185: public: terom@394: /** terom@394: * terom@394: */ terom@409: Graphics (Engine &engine, GameState &state, const GraphicsConfig &config); terom@392: terom@392: /** terom@392: * Returns a CL_Font that can be used for drawing text terom@392: */ terom@233: CL_Font& getSimpleFont (void) { return simple_font; } terom@392: terom@392: /** terom@392: * Returns a vector of CL_DisplayModes that lists possible display modes to use for fullscreen mode. terom@392: */ terom@392: static const std::vector & getDisplayModes (void); terom@389: terom@392: /** terom@392: * Returns the "best" CL_DisplayMode to use for fullscreen mode. terom@392: * terom@392: * Currently, this just means the largest resolution. terom@392: */ terom@392: static const CL_DisplayMode getBestMode (void); terom@185: terom@185: private: terom@389: /** terom@394: * Shift back and forth between fullscreen and windowed mode, retaining resolutions terom@394: */ terom@394: void toggle_fullscreen (void); terom@394: terom@394: /** terom@389: * Reads current input events from Input and applies them, using LocalPlayer::handleInput and terom@389: * Graphics::handle_input. terom@389: */ terom@311: void check_input (void); terom@389: terom@389: /** terom@389: * Handles GuiInput flags read from Input. terom@389: */ terom@389: void handle_input (GuiInput flags); terom@394: terom@394: /** terom@394: * Redraws entire screen terom@394: */ terom@185: void do_redraw (void); terom@185: terom@394: /** terom@394: * Handles input and redraws screen terom@394: */ terom@205: void on_update (TimeMS tick_length); terom@185: terom@394: /** terom@394: * Draws status view terom@394: */ terom@394: void draw_player_info (CL_GraphicContext *gc, Player *p); terom@394: terom@394: /** terom@394: * Handles window resize. This just updates resolution terom@394: */ terom@394: void on_window_resize (int new_x, int new_y); terom@393: terom@393: protected: terom@393: /* GameStateEventHandler */ terom@393: virtual void on_player_joined (Player *p); terom@393: virtual void on_player_left (Player *p); terom@185: }; terom@185: terom@185: #endif /* GRAPHICS_HH */