Neo  0.5.0
Developer Documentation
Tile.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014 (C) Yannick Pflanzer <neo-engine.de>
3  *
4  * This file is part of Neo2D.
5  *
6  * Neo2D is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Neo2D is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with Neo2D. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Diese Datei ist Teil von Neo2D.
20  *
21  * Neo2D ist Freie Software: Sie können es unter den Bedingungen
22  * der GNU Lesser General Public License, wie von der Free Software Foundation,
23  * Version 3 der Lizenz oder (nach Ihrer Wahl) jeder späteren
24  * veröffentlichten Version, weiterverbreiten und/oder modifizieren.
25  *
26  * Neo2D wird in der Hoffnung, dass es nützlich sein wird, aber
27  * OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
28  * Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
29  * Siehe die GNU Lesser General Public License für weitere Details.
30  *
31  * Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit
32  *diesem
33  * Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
34  */
35 
36 #ifndef __TILE_H__
37 #define __TILE_H__
38 
39 #include <string>
40 #include <NeoEngine.h>
41 #include <Widget.h>
42 
43 namespace Neo2D
44 {
45 
46 using namespace Neo;
47 
54 class NEO2D_EXPORT TileSheet
55 {
56 private:
57  int m_image;
58 
59  unsigned int m_tileWidth;
60  unsigned int m_tileHeight;
61  unsigned int m_tileDistance;
62 
63  unsigned int m_imageWidth, m_imageHeight;
64 
65 public:
66  TileSheet() : m_image(0) {}
67 
68  void loadImage(const char* path, unsigned int width, unsigned int height,
69  unsigned int dist);
70  Vector4 getTexCoords(unsigned int x, unsigned int y);
71  int getImage() { return m_image; }
72 };
73 
82 class NEO2D_EXPORT Tile : public Widget
83 {
84 protected:
87 
88  unsigned int m_tilex, m_tiley;
89 
90 public:
91  Tile(unsigned int x, unsigned int y, unsigned int width,
92  unsigned int height, const char* label, unsigned int tilex,
93  unsigned int tiley)
94  : Widget(x, y, width, height, label),
95  m_labelText(NULL),
96  m_tilex(tilex),
97  m_tiley(tiley)
98  {
99  }
100 
101  const char* getStaticName() { return "Tile"; }
102 
103  void setTileSheet(TileSheet* sheet) { m_parentSheet = sheet; }
104  void setOffset(Vector2 vec)
105  {
106  m_tilex = vec.x;
107  m_tiley = vec.y;
108  }
109 
110  void draw(Vector2 offset);
111  void update();
112 };
113 }
114 #endif
Definition: Vector4.h:31
TileSheet()
Definition: Tile.h:66
Definition: OText.h:40
TileSheet * m_parentSheet
Definition: Tile.h:86
int getImage()
Definition: Tile.h:71
float y
Definition: Vector2.h:36
float x
Definition: Vector2.h:35
The Widget class contains all information that is common to all GUI widgets.
Definition: Widget.h:72
Definition: Vector2.h:31
Definition: Button.h:42
Implements a tile sheet from which it is possible to retrieve one specific tile.
Definition: Tile.h:54
void setTileSheet(TileSheet *sheet)
Definition: Tile.h:103
unsigned int m_tiley
Definition: Tile.h:88
The Tile class displays a texture on the screen.
Definition: Tile.h:82
Tile(unsigned int x, unsigned int y, unsigned int width, unsigned int height, const char *label, unsigned int tilex, unsigned int tiley)
Definition: Tile.h:91
const char * getStaticName()
Definition: Tile.h:101
void setOffset(Vector2 vec)
Definition: Tile.h:104
Definition: Color.h:29
OText * m_labelText
Definition: Tile.h:85