Gamedev Framework (gf)  0.17.0
A C++14 framework for 2D games
Tileset.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2019 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 "Portability.h"
25 #include "Texture.h"
26 #include "Vector.h"
27 
28 namespace gf {
29 #ifndef DOXYGEN_SHOULD_SKIP_THIS
30 inline namespace v1 {
31 #endif
32 
39  class GF_API Tileset {
40  public:
41  Tileset();
42 
55  void setTexture(const Texture& texture);
56 
66  const Texture& getTexture() const {
67  return *m_texture;
68  }
69 
77  bool hasTexture() const {
78  return m_texture != nullptr;
79  }
80 
88  void unsetTexture();
89 
96  void setTileSize(Vector2i tileSize);
97 
105  return m_tileSize;
106  }
107 
114  void setMargin(int margin) {
115  setMargin({ margin, margin });
116  }
117 
124  void setMargin(Vector2i margin);
125 
132  Vector2i getMargin() const {
133  return m_margin;
134  }
135 
142  void setSpacing(int spacing) {
143  setSpacing({ spacing, spacing });
144  }
145 
152  void setSpacing(Vector2i spacing);
153 
161  return m_spacing;
162  }
163 
170  void setOffset(Vector2i offset);
171 
178  Vector2i getOffset() const {
179  return m_offset;
180  }
181 
187  Vector2i getSize() const {
188  return m_size;
189  }
190 
197  RectF computeTextureCoords(int tile) const;
198 
205  RectF computeTextureCoords(Vector2i coords) const;
206 
207  private:
208  void updateSize();
209 
210  private:
211  const Texture *m_texture;
212  Vector2i m_tileSize;
213  Vector2i m_margin;
214  Vector2i m_spacing;
215  Vector2i m_offset;
216  Vector2i m_size;
217  };
218 
219 #ifndef DOXYGEN_SHOULD_SKIP_THIS
220 }
221 #endif
222 }
223 
224 #endif // GF_TILESET_H
void setMargin(int margin)
Set the margin of the tileset.
Definition: Tileset.h:114
Vector2i getMargin() const
Get the margin of the tileset.
Definition: Tileset.h:132
void setSpacing(int spacing)
Set the spacing of the tileset.
Definition: Tileset.h:142
A tileset.
Definition: Tileset.h:39
bool hasTexture() const
Check if a texture is set.
Definition: Tileset.h:77
Vector2i getTileSize() const
Get the tile size in the tileset.
Definition: Tileset.h:104
A texture for colored images.
Definition: Texture.h:309
const Texture & getTexture() const
Get the source texture of the tileset.
Definition: Tileset.h:66
Vector2i getSize() const
Get the size of the tileset.
Definition: Tileset.h:187
The namespace for gf classes.
Definition: Action.h:35
Vector2i getOffset() const
Get the offset of the tileset.
Definition: Tileset.h:178
Vector2i getSpacing() const
Get the spacing of the tileset.
Definition: Tileset.h:160