25
/** A smaller version of the map that draws on its own SDL surface
27
* This is a base class that draws the terrain, etc. Derived classes can add
28
* their own stuff by overrriding after_draw.
30
//! Generates a miniature graphic of the game map.
32
* This is a base class that draws the terrain, ruins, temples, and roads
33
* onto an SDL_Surface.
34
* This class is responsible for drawing terrain features using the correct
35
* pattern, as specified in Tile::Pattern. Ruins and Temples are drawn as
36
* white dots, and roads are drawn as brown lines.
37
* If a tile on the game map is obscured due to fog of war on a hidden map,
38
* it appears as black.
39
* This class provides a method for optionally drawing cities onto the map.
40
* Derived classes can add their own stuff to the map by overriding the
41
* after_draw method that is called by OverviewMap::draw.
35
virtual ~OverviewMap();
37
// the map will keep its aspect ratio and resize itself to take up at most
38
// max_dimensions space
46
//! Default constructor.
48
* Make a new overview map. This constructor doesn't do anything, the
49
* real work is done in the OverviewMap::resize and OverviewMap::draw
51
* This constructor is not normally called by itself, usually it is
52
* called by a derived class.
57
virtual ~OverviewMap();
59
//! Draw and scale the miniature map graphic to the given size.
61
* This method is responsible for drawing the terrain (e.g. grass, water,
62
* etc), but not the terrain features (roads, ruins, etc).
63
* It will draw a map that is max_dimensions large, but will keep it's
65
* This method should be called before the draw method.
67
* @param max_dimensions Two integers; the first of which dictates the
68
* width of the map graphic, and the second dictates
39
72
void resize(Vector<int> max_dimensions);
41
// picks the best dimensions to resize to
74
//! Draw and scale the mini map graphic to the correct size of the game map.
76
* @note This method depends on the map being one of the 3 sizes as
77
* defined in the GamePreferencesDialog.
78
* This method should be called before the draw method.
44
// draw the nonstatic stuff, won't redraw the terrain
82
//! Draw the terrain features (roads, ruins, etc) on the map.
84
* Draws the roads, cities, ruins, temples and roads onto the map in the
85
* correct aspect ratio.
87
* The aspect ratio for the terrain features is governed by the dimensions
88
* passed to the OverviewMap::resize method.
90
* This method calls the after_draw method from the derived classes.
47
// redraw the specified tiles (also redraws the terrain)
94
//! Redraw a portion of the map graphic.
96
* This method draws the terrain (water, grass, etc) for the given
97
* portion of the screen.
99
* @note This method redraws all terrain features (roads, ruins, etc),
100
* including the features outside of the given portion.
102
* @param tiles The rectangle to redraw.
48
104
void redraw_tiles(Rectangle tiles);
50
// returns the drawn map
106
//! Returns the map graphic.
108
* It only makes sense to get the surface after OverviewMap::resize and
109
* OverviewMap::draw have been called.
51
111
SDL_Surface *get_surface();
53
//is this tile visible? (convenience function)
54
bool isFogged(Vector<int>);
113
static void draw_tile_pixel(SDL_Surface *surface, Tile::Pattern pattern,
114
SDL_Color first_color, SDL_Color second_color,
115
SDL_Color third_color,
116
int i, int j, bool shadowed);
57
// the background, we keep it cached so it doesn't have to be drawn all
118
//! An SDL surface of the terrain without the features.
120
* This is the cached surface after the resize method was called.
121
* It is cached so that we don't have recalculate it.
59
123
SDL_Surface* static_surface;
125
//! Returns whether or not the given pixel appears sunken (Tile::SUNKEN).
127
* The leftmost and bottommost pixels of a sunken terrain type are shaded
128
* in a different colour. This method returns whether or not a given pixel
131
* @param type The tile associated with the pixel location must be of
132
* this type. If not, then this method always returns false.
133
* @param i The pixel on the horizontal axis on the map graphic that
135
* @param j The pixel on the vertical axis on the map graphic that
138
* @return True if the given pixel location should be shaded, false if not.
60
140
bool isShadowed(Uint32 type, int i, int j);
61
void draw_tile_pixel(Maptile *, int, int);
142
//! Draw the given tile at the given pixel location on the map.
144
* This method draws a square that is Overviewmap::pixels_per_tile pixels
145
* in height and width. It draws it at position (i,j) on the graphic.
146
* This method uses the pattern assocaited the given Maptile to know
147
* what this box should look like.
149
* @param tile The tile of the game map we're trying to draw.
150
* @param i The pixel on the horizontal axis of the map graphic. This
151
* value must be a multiple of OverviewMap::pixels_per_tile.
152
* @param j The pixel on the vertical axis of the map graphic. This
153
* value must be a multiple of OverviewMap::pixels_per_tile.
155
void draw_tile_pixel(Maptile *tile, int i, int j);
159
//! Every pixel on the graphic is this wide and tall.
64
160
double pixels_per_tile;
66
//! Maps the given point in absolute screen coordinates to a map coordinate
162
//! Maps the given point in graphic coordinates to a game map coordinate.
67
163
Vector<int> mapFromScreen(Vector<int> pos);
69
//! And (almost) the other way round. Map a map coordinate to a surface pixel.
165
//! And the other way round. Map a map coordinate to a surface pixel.
70
166
Vector<int> mapToSurface(Vector<int> pos);
72
// hook for derived classes
168
//! A hook method for derived classes to put features on the map.
73
169
virtual void after_draw();
75
//! draw cities on the map
171
//! This method draws the cities onto the map.
173
* Scan through all of the cities in the citylist, and draw each one with
174
* a small shield graphic belonging to the owner of that city.
176
* Derived classes may call this method in their after_draw method.
178
* @param all_razed Show each city as if it were razed.
76
180
void draw_cities(bool all_razed);
78
// redraw the specified terrain pixels
182
//! Redraw the specified region.
79
183
void draw_terrain_pixels(Rectangle r);
185
int calculateResizeFactor();
187
//! The surface containing the drawn map.
81
188
SDL_Surface* surface;