2 #include "Graphics.hh" |
2 #include "Graphics.hh" |
3 #include "GameState.hh" |
3 #include "GameState.hh" |
4 #include <cmath> |
4 #include <cmath> |
5 #include <sstream> |
5 #include <sstream> |
6 |
6 |
7 Graphics::Graphics (Engine &engine, GameState &state) : |
7 Graphics::Graphics (Engine &engine, GameState &state, PixelCoordinate resolution, bool fullscreen) : |
8 CL_DisplayWindow(GRAPHICS_WINDOW_TITLE, GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT), |
8 CL_DisplayWindow(GRAPHICS_WINDOW_TITLE, resolution.x, resolution.y, fullscreen), |
9 engine(engine), |
9 engine(engine), |
10 state(state), |
10 state(state), |
11 resolution(GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT), |
11 resolution(resolution), |
12 update_timer(GRAPHICS_UPDATE_INTERVAL_MS), |
12 update_timer(GRAPHICS_UPDATE_INTERVAL_MS), |
13 input(get_ic()->get_keyboard()), |
13 input(get_ic()->get_keyboard()), |
14 simple_font("Font2", engine.getResourceManager()) |
14 simple_font("Font2", engine.getResourceManager()) |
15 { |
15 { |
16 |
16 |
19 |
19 |
20 // enable |
20 // enable |
21 update_timer.start(); |
21 update_timer.start(); |
22 } |
22 } |
23 |
23 |
|
24 const std::vector<CL_DisplayMode> & Graphics::getDisplayModes (void) { |
|
25 return CL_DisplayMode::get_display_modes(); |
|
26 } |
|
27 |
24 void Graphics::check_input (void) { |
28 void Graphics::check_input (void) { |
25 LocalPlayer *player; |
29 LocalPlayer *player; |
26 PlayerInput input_mask; |
30 PlayerInput input_mask; |
27 TimeMS input_dt; |
31 TimeMS input_dt; |
28 |
32 |
29 // update gui flags |
33 // update gui flags |
30 this->flags = input.readGuiInput(); |
34 handle_input(input.readGuiInput()); |
|
35 |
|
36 // stop here if we don't have a local player |
|
37 if ((player = state.getLocalPlayer()) == NULL) |
|
38 return; |
|
39 |
|
40 // build input_mask |
|
41 input.readPlayerInput(input_mask, input_dt); |
|
42 |
|
43 // apply input if there was any |
|
44 if (input_mask) |
|
45 player->handleInput(input_mask, input_dt); |
|
46 } |
|
47 |
|
48 void Graphics::handle_input (GuiInput flags) { |
|
49 // update flags |
|
50 this->flags = flags; |
31 |
51 |
32 // quit? |
52 // quit? |
33 if (flags & GUI_INPUT_QUIT) { |
53 if (flags & GUI_INPUT_QUIT) { |
34 engine.stop(); |
54 engine.stop(); |
35 |
55 |
36 return; |
56 return; |
37 } |
57 } |
38 |
58 |
39 // stop here if we don't have a local player |
59 // dump player debug info on stderr |
40 if ((player = state.getLocalPlayer()) == NULL) |
60 if ((flags & GUI_INPUT_DEBUG_PLAYER) && state.getLocalPlayer()) |
41 return; |
61 state.getLocalPlayer()->printDebugInfo(); |
42 |
62 |
43 // dump debug info on stderr |
63 // toggle fullscreen? |
44 if (flags & GUI_INPUT_DEBUG_PLAYER) |
64 if (flags & GUI_INPUT_TOGGLE_FULLSCREEN) { |
45 player->printDebugInfo(); |
65 if (is_fullscreen()) |
46 |
66 set_windowed(); |
47 // build input_mask |
67 else |
48 input.readPlayerInput(input_mask, input_dt); |
68 set_fullscreen(); |
49 |
69 } |
50 // apply input if there was any |
|
51 if (input_mask) |
|
52 player->handleInput(input_mask, input_dt); |
|
53 } |
70 } |
54 |
71 |
55 static PixelDimension value_between (PixelDimension low, PixelDimension value, PixelDimension high) { |
72 static PixelDimension value_between (PixelDimension low, PixelDimension value, PixelDimension high) { |
56 if (high < low) |
73 if (high < low) |
57 return (high + low) / 2; |
74 return (high + low) / 2; |
112 // redraw display |
129 // redraw display |
113 do_redraw(); |
130 do_redraw(); |
114 } |
131 } |
115 |
132 |
116 void Graphics::draw_player_info(CL_GraphicContext *gc, Player *p) { |
133 void Graphics::draw_player_info(CL_GraphicContext *gc, Player *p) { |
117 int box_top = GRAPHICS_RESOLUTION_HEIGHT - 100; |
134 int box_top = resolution.y - 100; |
118 int box_left = 0; |
135 int box_left = 0; |
119 int box_right = GRAPHICS_RESOLUTION_WIDTH; |
136 int box_right = resolution.x; |
120 int box_bottom = GRAPHICS_RESOLUTION_HEIGHT; |
137 int box_bottom = resolution.y; |
121 int bar_length = 3; // *100 |
138 int bar_length = 3; // *100 |
122 |
139 |
123 // draw status info at bottom of display |
140 // draw status info at bottom of display |
124 gc->fill_rect( |
141 gc->fill_rect( |
125 CL_Rect( |
142 CL_Rect( |