19 * This handles drawing the GameState with an appropriate camera view each frame, loading fonts, and currently, |
19 * This handles drawing the GameState with an appropriate camera view each frame, loading fonts, and currently, |
20 * handling the input from Input to GameState. |
20 * handling the input from Input to GameState. |
21 */ |
21 */ |
22 class Graphics : public GameStateEventHandler, public CL_DisplayWindow { |
22 class Graphics : public GameStateEventHandler, public CL_DisplayWindow { |
23 private: |
23 private: |
|
24 /** |
|
25 * Our engine reference |
|
26 */ |
24 Engine &engine; |
27 Engine &engine; |
|
28 |
|
29 /** |
|
30 * GameState we are associated with |
|
31 */ |
25 GameState &state; |
32 GameState &state; |
|
33 |
|
34 /** |
|
35 * Current window resolution |
|
36 */ |
|
37 PixelCoordinate resolution; |
26 |
38 |
27 PixelCoordinate resolution; |
39 /** |
|
40 * Target resolution in fullscreen/windowed mode |
|
41 */ |
|
42 PixelCoordinate fullscreen_resolution, window_resolution; |
28 |
43 |
|
44 /** |
|
45 * ClanLib signal slots |
|
46 */ |
29 CL_SlotContainer slots; |
47 CL_SlotContainer slots; |
30 |
48 |
|
49 /** |
|
50 * Our timer that drives redraws |
|
51 */ |
31 Timer update_timer; |
52 Timer update_timer; |
32 |
53 |
|
54 /** |
|
55 * Our input handler for GUI and Player input |
|
56 */ |
33 Input input; |
57 Input input; |
34 |
58 |
35 // current GUI input state |
59 /** |
|
60 * Current GUI input state |
|
61 */ |
36 GuiInput flags; |
62 GuiInput flags; |
37 |
63 |
38 // basic fonts |
64 /** |
|
65 * A basic font |
|
66 */ |
39 CL_Font simple_font; |
67 CL_Font simple_font; |
40 |
68 |
41 // view components |
69 /** |
|
70 * View components |
|
71 */ |
42 GameMessageView message_view; |
72 GameMessageView message_view; |
43 |
73 |
44 public: |
74 public: |
|
75 /** |
|
76 * |
|
77 */ |
45 Graphics (Engine &engine, GameState &state, PixelCoordinate resolution, bool fullscreen); |
78 Graphics (Engine &engine, GameState &state, PixelCoordinate resolution, bool fullscreen); |
46 |
79 |
47 /** |
80 /** |
48 * Returns a CL_Font that can be used for drawing text |
81 * Returns a CL_Font that can be used for drawing text |
49 */ |
82 */ |
61 */ |
94 */ |
62 static const CL_DisplayMode getBestMode (void); |
95 static const CL_DisplayMode getBestMode (void); |
63 |
96 |
64 private: |
97 private: |
65 /** |
98 /** |
|
99 * Shift back and forth between fullscreen and windowed mode, retaining resolutions |
|
100 */ |
|
101 void toggle_fullscreen (void); |
|
102 |
|
103 /** |
66 * Reads current input events from Input and applies them, using LocalPlayer::handleInput and |
104 * Reads current input events from Input and applies them, using LocalPlayer::handleInput and |
67 * Graphics::handle_input. |
105 * Graphics::handle_input. |
68 */ |
106 */ |
69 void check_input (void); |
107 void check_input (void); |
70 |
108 |
71 /** |
109 /** |
72 * Handles GuiInput flags read from Input. |
110 * Handles GuiInput flags read from Input. |
73 */ |
111 */ |
74 void handle_input (GuiInput flags); |
112 void handle_input (GuiInput flags); |
75 |
113 |
|
114 /** |
|
115 * Redraws entire screen |
|
116 */ |
76 void do_redraw (void); |
117 void do_redraw (void); |
77 |
118 |
|
119 /** |
|
120 * Handles input and redraws screen |
|
121 */ |
78 void on_update (TimeMS tick_length); |
122 void on_update (TimeMS tick_length); |
79 |
123 |
80 void draw_player_info(CL_GraphicContext *gc, Player *p); |
124 /** |
|
125 * Draws status view |
|
126 */ |
|
127 void draw_player_info (CL_GraphicContext *gc, Player *p); |
|
128 |
|
129 /** |
|
130 * Handles window resize. This just updates resolution |
|
131 */ |
|
132 void on_window_resize (int new_x, int new_y); |
81 |
133 |
82 protected: |
134 protected: |
83 /* GameStateEventHandler */ |
135 /* GameStateEventHandler */ |
84 virtual void on_player_joined (Player *p); |
136 virtual void on_player_joined (Player *p); |
85 virtual void on_player_left (Player *p); |
137 virtual void on_player_left (Player *p); |