20130313
[gdash.git] / src / cave / gamerender.hpp
blob3bc5150fb33817b02d01383f2a04f103eb7ecbdd
1 /*
2 * Copyright (c) 2007-2013, Czirkos Zoltan http://code.google.com/p/gdash/
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #ifndef _GD_GAMERENDERER
18 #define _GD_GAMERENDERER
20 #include "config.h"
22 #include <vector>
23 #include <string>
25 #include "cave/cavetypes.hpp"
26 #include "cave/helper/colors.hpp"
28 class Screen;
29 class CellRenderer;
30 class FontManager;
31 class GameControl;
32 class Pixbuf;
33 class Pixmap;
34 class PixbufFactory;
36 #define GAME_RENDERER_SCREEN_SIZE_X (20)
37 #define GAME_RENDERER_SCREEN_SIZE_Y (12.5)
39 enum GdStatusBarType {
40 GD_STATUS_BAR_ORIGINAL,
41 GD_STATUS_BAR_1STB,
42 GD_STATUS_BAR_CRLI,
43 GD_STATUS_BAR_FINAL,
44 GD_STATUS_BAR_ATARI_ORIGINAL,
46 enum {
47 // should be the last from the status bar type
48 GD_STATUS_BAR_MAX=int(GD_STATUS_BAR_ATARI_ORIGINAL)
50 const char **gd_status_bar_colors_get_names();
53 /// @ingroup Cave
54 ///
55 /// @brief This class manages drawing the cave and scrolling on the screen; it also
56 /// receives keypresses (controls) from the user and passes it to the game
57 /// controlling class GameControl.
58 ///
59 /// The GameRenderer class can be used the following way:
60 /// - Creating an object, and assigning it a CellRenderer, a FontManager, a Screen
61 /// for the graphics stuff, and a GameControl object to control the game.
62 /// - The GameRenderer::main_int() function is to be called regurarly, and passed
63 /// the number of milliseconds elapsed (that can be 20 or 40), and the user
64 /// controls.
65 /// The object will then control the game and also draw it. And that's all.
66 /// Showing the story, scrolling the cave, drawing the status bar, enabling and
67 /// disabling game pause and everything is handled inside.
68 class GameRenderer {
69 Screen &screen;
70 CellRenderer &cells;
71 FontManager &font_manager;
72 GameControl &game;
74 int play_area_w;
75 int play_area_h;
76 int statusbar_height;
77 int statusbar_y1;
78 int statusbar_y2;
79 int statusbar_mid;
81 bool out_of_window;
83 bool show_replay_sign;
85 int scroll_x, scroll_y;
86 int scroll_desired_x, scroll_desired_y;
88 // for showing the story
89 std::vector<std::string> wrapped_story;
90 int story_y, story_max_y;
91 unsigned linesavailable;
92 Pixmap *story_background;
93 bool toggle;
95 void drawstory();
96 void drawcave(bool force_draw);
97 static bool cave_scroll(int logical_size, int physical_size, int center, bool exact, int start, int to, int &current, int &desired, int speed, int cell_size);
98 bool scroll(int ms, bool exact_scroll);
99 void scroll_to_origin();
101 void clear_header();
102 bool showheader_firstline(bool in_game);
103 void showheader_uncover();
104 void showheader_game(bool alternate_status_bar, bool fast_forward);
105 void showheader_gameover();
106 void showheader_pause();
108 void set_colors_from_cave();
109 void select_status_bar_colors();
111 struct StatusBarColors {
112 GdColor background;
113 GdColor diamond_needed;
114 GdColor diamond_value;
115 GdColor diamond_collected;
116 GdColor score;
117 GdColor default_color;
119 StatusBarColors cols;
121 public:
122 int statusbar_since;
124 GameRenderer(Screen &screen_, CellRenderer &cells_, FontManager &font_manager_, GameControl &game_);
125 ~GameRenderer();
127 enum State {
128 CaveLoaded,
129 Nothing,
130 Iterated,
131 Stop,
132 GameOver
135 State main_int(int ms, GdDirectionEnum player_move, bool fire, bool &suicide, bool &restart, bool paused, bool alternate_status, bool fast_forward);
138 * Show replay sign means that for non-real-game game types,
139 * the status bar can show the type ("PLAYING REPLAY" or "TESTING CAVE").
140 * By default, it is turned on.
142 void set_show_replay_sign(bool srs);
145 * The user can request some random colors if he does not like the
146 * ones from the cave. */
147 void set_random_colors();
150 * Call this to redraw everything.
152 void redraw();
156 #endif