Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
Tileset.h
1/*
2 * Gamedev Framework (gf)
3 * Copyright (C) 2016-2022 Julien Bernard
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21#ifndef GF_TILESET_H
22#define GF_TILESET_H
23
24#include "GraphicsApi.h"
25#include "Texture.h"
26#include "Vector.h"
27
28namespace gf {
29#ifndef DOXYGEN_SHOULD_SKIP_THIS
30inline namespace v1 {
31#endif
32
48 class GF_GRAPHICS_API Tileset {
49 public:
51
64 void setTexture(Texture& texture);
65
75 const Texture& getTexture() const {
76 return *m_texture;
77 }
78
86 void setSmooth(bool smooth = true) {
87 m_texture->setSmooth(smooth);
88 }
89
97 bool hasTexture() const {
98 return m_texture != nullptr;
99 }
100
109
116 void setTileSize(Vector2i tileSize);
117
125 return m_tileSize;
126 }
127
134 void setMargin(int margin) {
135 setMargin({ margin, margin });
136 }
137
144 void setMargin(Vector2i margin);
145
153 return m_margin;
154 }
155
162 void setSpacing(int spacing) {
163 setSpacing({ spacing, spacing });
164 }
165
172 void setSpacing(Vector2i spacing);
173
181 return m_spacing;
182 }
183
190 void setOffset(Vector2i offset);
191
199 return m_offset;
200 }
201
208 return m_size;
209 }
210
218
226
227 private:
228 void updateSize();
229
230 private:
231 Texture *m_texture;
232 Vector2i m_tileSize;
233 Vector2i m_margin;
234 Vector2i m_spacing;
235 Vector2i m_offset;
236 Vector2i m_size;
237 };
238
239#ifndef DOXYGEN_SHOULD_SKIP_THIS
240}
241#endif
242}
243
244#endif // GF_TILESET_H
A texture for colored images.
Definition: Texture.h:313
A tileset.
Definition: Tileset.h:48
void setMargin(int margin)
Set the margin of the tileset.
Definition: Tileset.h:134
void setSpacing(Vector2i spacing)
Set the spacing of the tileset.
void setTexture(Texture &texture)
Change the source texture of the tileset.
void setOffset(Vector2i offset)
Set the offset of the tileset.
Vector2i getTileSize() const
Get the tile size in the tileset.
Definition: Tileset.h:124
RectF computeTextureCoords(int tile) const
Get the texture coordinates for a tile.
Vector2i getOffset() const
Get the offset of the tileset.
Definition: Tileset.h:198
const Texture & getTexture() const
Get the source texture of the tileset.
Definition: Tileset.h:75
Vector2i getMargin() const
Get the margin of the tileset.
Definition: Tileset.h:152
RectF computeTextureCoords(Vector2i coords) const
Get the texture coordinates for a tile.
void setSmooth(bool smooth=true)
Enable or disable the smooth filter on the texture.
Definition: Tileset.h:86
Vector2i getSize() const
Get the size of the tileset.
Definition: Tileset.h:207
void unsetTexture()
Unset the source texture of the tile layer.
void setMargin(Vector2i margin)
Set the margin of the tileset.
Vector2i getSpacing() const
Get the spacing of the tileset.
Definition: Tileset.h:180
bool hasTexture() const
Check if a texture is set.
Definition: Tileset.h:97
void setSpacing(int spacing)
Set the spacing of the tileset.
Definition: Tileset.h:162
void setTileSize(Vector2i tileSize)
Set the tile size in the tileset.
The namespace for gf classes.