1 /*
2  * Bomb-her-man
3  * Copyright (C) Sardem FF7 2010 <sardemff7.pub@gmail.com>
4  * Copyright (C) Marc-Antoine Perennou 2010 <Marc-Antoine@Perennou.com>
5  *
6  * Bomb-her-man is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Bomb-her-man is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef _DISPLAY_HPP_
21 #define _DISPLAY_HPP_
22 
23 #include <SDL.h>
24 #include <SDL_ttf.h>
25 #include <librsvg/rsvg.h>
26 #include <map>
27 
28 #include "bombherman.hpp"
29 #include "game/menu.hpp"
30 #include "map/map.hpp"
31 #include "exceptions/display/nosdl-exception.hpp"
32 #include "exceptions/display/nosvg-exception.hpp"
33 
34 namespace bombherman
35 {
36 	#define NB_BONUSES map::LASTBONUS - map::FIRSTBONUS + 1
37 
38 	/// Class used to manage all the graphical things
39 	class Display
40 	{
41 	public:
42 		/// To initialize the video
43 		static void init();
44 
45 		/// Inform the display we quit the game (it can free some surfaces)
46 		static void quitGame();
47 
48 		/// To stop the video
49 		static void quit();
50 
51 		/// Set the window mode (window/fullscreen)
52 		static void setMode();
53 		/// Set the window size (width/height)
54 		/**
55 		 * @param mode The index of the mode in the vector
56 		 */
57 		static void setMode(Uint8 mode);
58 
59 		/// Display the menu
60 		/**
61 		 * @param menu The pointer the menu to display
62 		 */
63 		static void displayMenu(Menu * menu);
64 
65 		/// Get the video modes
66 		/**
67 		 * @return A vector of pair width/height
68 		 */
69 		static std::vector< std::pair< Uint16, Uint16 > > getModes();
70 
71 		/// Update the map
72 		static void updateMap();
73 
74 		/// Move a player
75 		/**
76 		 * @param player The player who moves (Player *)
77 		 * @param moveResult The result of the move (map::MoveResult)
78 		 */
79 		static void movePlayer(Player * player, map::MoveResult moveResult);
80 
81 		/// Plant a bomb
82 		/**
83 		 * @param player (Pointer to the) Player who plant the bomb
84 		 */
85 		static void plantBomb(Player * player);
86 
87 		/// Show the bomb explosing
88 		/**
89 		 * @param coords Where the bomb was placed
90 		 * @param cells Which cells (a vector of Coords) the bomb destroyed
91 		 */
92 		static void explode(map::Coords coords, std::vector< map::Coords > cells);
93 
94 		/// Show the final scores screen
95 		static void displayScores();
96 	private:
97 		static SDL_Surface * svgToSurface(std::string, Uint32 = gSize, Uint32 = gSize);
98 		static void initSurfaces();
99 		static void cleanSurface(SDL_Surface * &);
updateDisplay(SDL_Surface * s,SDL_Rect z)100 		static void updateDisplay(SDL_Surface * s, SDL_Rect z) { updateDisplay(s, z.x, z.y, z.w, z.h); }
101 		static void updateDisplay(SDL_Surface *, Uint16 = 0, Uint16 = 0, Uint16 = 0, Uint16 = 0);
102 
103 		// Update the scores "panel"
104 		static void updateScores(bool = false);
105 
106 		// Update the barrels
107 		static void updateBarrels();
108 
109 		// Update the players
110 		static void updatePlayers();
111 
112 		// To store the SDL display surface
113 		static SDL_Surface * sDisplay;
114 		static Uint32 flags;
115 		static bool isFullscreen;
116 		static SDL_mutex * mUpdate;
117 
118 		// To store the SDL text color
119 		static SDL_Color textColor;
120 		static SDL_Color highlightColor;
121 		static SDL_Color scoreColor;
122 
123 		static int widthMax, heightMax;
124 		static int width, height;
125 		static std::vector< std::pair< Uint16, Uint16 > > displayModes;
126 
127 		static std::map< SDL_Surface *, unsigned char * > buffers;
128 		static SDL_Surface * sBackground;
129 
130 		static SDL_Surface * gScoresLayer;
131 		static SDL_Surface * gMapLayer;
132 		static SDL_Surface * gBarrelsLayer;
133 		static SDL_Surface * gPlayersLayer;
134 
135 		static std::vector< std::vector< std::vector< SDL_Surface * > > > gPlayers;
136 		static SDL_Surface * gBonuses[NB_BONUSES];
137 		static SDL_Surface * gBomb;
138 		static SDL_Surface * gExplosion;
139 		static SDL_Surface * gBarrel;
140 		static SDL_Surface * gTomb[2];
141 		static SDL_Surface * gFloor;
142 
143 		static Uint32 gMapSize;
144 		static Uint16 gSize;
145 		static SDL_Rect gZone;
146 	};
147 }
148 
149 #endif // _DISPLAY_HPP_
150 
151