1 #ifndef GRAPHICS_HH |
|
2 #define GRAPHICS_HH |
|
3 |
|
4 #include "GraphicsPointer.hh" |
|
5 #include "Types.hh" |
|
6 #include "Config.hh" |
|
7 |
|
8 /** |
|
9 * Parameters used by Graphics |
|
10 */ |
|
11 struct GraphicsConfig { |
|
12 /** Initial resolution to use */ |
|
13 PixelCoordinate resolution; |
|
14 |
|
15 /* Use fullscreen mode at startup */ |
|
16 bool fullscreen; |
|
17 |
|
18 /** Defaults */ |
|
19 GraphicsConfig (void) : resolution(GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT), fullscreen(GRAPHICS_FULLSCREEN) { } |
|
20 }; |
|
21 |
|
22 #include "GameState.hh" |
|
23 #include "Input.hh" |
|
24 #include "Timer.hh" |
|
25 #include "Engine.hh" |
|
26 |
|
27 #include "GameMessageView.hh" |
|
28 |
|
29 #include <ClanLib/core.h> |
|
30 #include <ClanLib/gl.h> |
|
31 #include <ClanLib/display.h> |
|
32 |
|
33 /** |
|
34 * This handles drawing the GameState with an appropriate camera view each frame, loading fonts, and currently, |
|
35 * handling the input from Input to GameState. |
|
36 */ |
|
37 class Graphics : public GameStateEventHandler, public CL_DisplayWindow { |
|
38 private: |
|
39 /** |
|
40 * Our engine reference |
|
41 */ |
|
42 Engine &engine; |
|
43 |
|
44 /** |
|
45 * GameState we are associated with |
|
46 */ |
|
47 GameState &state; |
|
48 |
|
49 /** |
|
50 * Current window resolution |
|
51 */ |
|
52 PixelCoordinate resolution; |
|
53 |
|
54 /** |
|
55 * Target resolution in fullscreen/windowed mode |
|
56 */ |
|
57 PixelCoordinate fullscreen_resolution, window_resolution; |
|
58 |
|
59 /** |
|
60 * ClanLib signal slots |
|
61 */ |
|
62 CL_SlotContainer slots; |
|
63 |
|
64 /** |
|
65 * Our timer that drives redraws |
|
66 */ |
|
67 Timer update_timer; |
|
68 |
|
69 /** |
|
70 * Our input handler for GUI and Player input |
|
71 */ |
|
72 Input input; |
|
73 |
|
74 /** |
|
75 * Current GUI input state |
|
76 */ |
|
77 GuiInput flags; |
|
78 |
|
79 /** |
|
80 * A basic font |
|
81 */ |
|
82 CL_Font simple_font; |
|
83 |
|
84 /** |
|
85 * View components |
|
86 */ |
|
87 GameMessageView message_view; |
|
88 |
|
89 public: |
|
90 /** |
|
91 * |
|
92 */ |
|
93 Graphics (Engine &engine, GameState &state, const GraphicsConfig &config); |
|
94 |
|
95 /** |
|
96 * Returns a CL_Font that can be used for drawing text |
|
97 */ |
|
98 CL_Font& getSimpleFont (void) { return simple_font; } |
|
99 |
|
100 /** |
|
101 * Returns a vector of CL_DisplayModes that lists possible display modes to use for fullscreen mode. |
|
102 */ |
|
103 static const std::vector<CL_DisplayMode> & getDisplayModes (void); |
|
104 |
|
105 /** |
|
106 * Returns the "best" CL_DisplayMode to use for fullscreen mode. |
|
107 * |
|
108 * Currently, this just means the largest resolution. |
|
109 */ |
|
110 static const CL_DisplayMode getBestMode (void); |
|
111 |
|
112 private: |
|
113 /** |
|
114 * Shift back and forth between fullscreen and windowed mode, retaining resolutions |
|
115 */ |
|
116 void toggle_fullscreen (void); |
|
117 |
|
118 /** |
|
119 * Reads current input events from Input and applies them, using LocalPlayer::handleInput and |
|
120 * Graphics::handle_input. |
|
121 */ |
|
122 void check_input (void); |
|
123 |
|
124 /** |
|
125 * Handles GuiInput flags read from Input. |
|
126 */ |
|
127 void handle_input (GuiInput flags); |
|
128 |
|
129 /** |
|
130 * Redraws entire screen |
|
131 */ |
|
132 void do_redraw (void); |
|
133 |
|
134 /** |
|
135 * Handles input and redraws screen |
|
136 */ |
|
137 void on_update (TimeMS tick_length); |
|
138 |
|
139 /** |
|
140 * Draws status view |
|
141 */ |
|
142 void draw_player_info (CL_GraphicContext *gc, Player *p); |
|
143 |
|
144 /** |
|
145 * Handles window resize. This just updates resolution |
|
146 */ |
|
147 void on_window_resize (int new_x, int new_y); |
|
148 |
|
149 protected: |
|
150 /* GameStateEventHandler */ |
|
151 virtual void on_player_joined (Player *p); |
|
152 virtual void on_player_left (Player *p); |
|
153 }; |
|
154 |
|
155 #endif /* GRAPHICS_HH */ |
|