1 /*
2 * Copyright (C) 2006-2019 Christopho, Solarus - http://www.solarus-games.org
3 *
4 * Solarus is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Solarus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include "solarus/core/Map.h"
18 #include "solarus/entities/SimpleTilePattern.h"
19 #include "solarus/entities/Tileset.h"
20 #include "solarus/graphics/Surface.h"
21
22 namespace Solarus {
23
24 /**
25 * \brief Creates a simple tile pattern.
26 * \param ground Kind of the of the tile pattern.
27 * \param xy Coordinates of the tile pattern in the tileset.
28 * \param size Size of the tile pattern in the tileset.
29 */
SimpleTilePattern(Ground ground,const Point & xy,const Size & size)30 SimpleTilePattern::SimpleTilePattern(Ground ground, const Point& xy, const Size& size):
31 TilePattern(ground, size),
32 position_in_tileset(xy, size) {
33
34 }
35
36 /**
37 * \brief Draws the tile image on a surface.
38 * \param dst_surface the surface to draw
39 * \param dst_position position where tile pattern should be drawn on dst_surface
40 * \param tileset the tileset of this tile
41 * \param viewport coordinates of the top-left corner of dst_surface relative
42 * to the map (may be used for scrolling tiles)
43 */
draw(const SurfacePtr & dst_surface,const Point & dst_position,const Tileset & tileset,const Point &) const44 void SimpleTilePattern::draw(
45 const SurfacePtr& dst_surface,
46 const Point& dst_position,
47 const Tileset& tileset,
48 const Point& /* viewport */
49 ) const {
50 const SurfacePtr& tileset_image = tileset.get_tiles_image();
51 tileset_image->draw_region(position_in_tileset, dst_surface, dst_position);
52 }
53
54 /**
55 * \brief Returns whether this tile pattern is animated, i.e. not always displayed
56 * the same way.
57 *
58 * Non-animated tiles may be rendered faster by using intermediate surfaces
59 * that are drawn only once.
60 *
61 * \return true if this tile pattern is animated
62 */
is_animated() const63 bool SimpleTilePattern::is_animated() const {
64 return false;
65 }
66
67 }
68
69