Neo  0.5.0
Developer Documentation
Canvas.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 #ifndef __CANVAS_H_
36 #define __CANVAS_H_
37 
38 #include <Widget.h>
39 #include <Sprite.h>
40 #include <vector>
41 #include <NeoEngine.h>
42 
43 namespace Neo2D
44 {
45 
46 using namespace Neo;
47 
93 class NEO2D_EXPORT SpriteBatch
94 {
95  std::vector<Widget*> m_sprites;
96 public:
97  DISOWN(Widget* s) void addSprite(Widget* s) { m_sprites.push_back(s); }
98  void draw();
99 };
100 
109 class NEO2D_EXPORT Canvas
110 {
111 private:
112  std::vector<int> m_widgets;
113  Vector4 m_clearColor;
114 
115  unsigned int m_width, m_height;
116  unsigned int m_fbo;
117  bool m_renderToTexture;
118 
119  TextureRef* m_texture;
120  int m_layer;
121 
122  Vector2 m_cameraPosition;
123 
124  std::vector<SpriteBatch*> m_batches;
125 public:
130  static Canvas* getInstance()
131  {
132  static Canvas m_instance;
133  return &m_instance;
134  }
135 
136  ~Canvas() { clear(); }
137  Canvas() : m_layer(0), m_renderToTexture(false), m_fbo(0), m_texture(NULL), m_width(0), m_height(0) {}
138 
139  DISOWN(SpriteBatch* b) void addSpriteBatch(SpriteBatch* b) { m_batches.push_back(b); }
140 
144  void draw();
145 
149  void update();
150 
156  void clear();
157 
165  int getLayer() { return m_layer; }
166 
174  void setLayer(int nl) { m_layer = nl; }
175 
185  void addWidget(int w);
186 
191  Vector4 getClearColor() { return m_clearColor; }
192 
198  void setClearColor(Vector4 vec) { m_clearColor = vec; }
199 
213  void enableRenderToTexture(const char* tex);
214 
224  {
225  if (m_texture != NULL)
226  m_renderToTexture = true;
227  }
228 
237  void disableRenderToTexture() { m_renderToTexture = false; }
238 
244  void setCameraOffset(Vector2 value) { m_cameraPosition = value; }
245 
250  Vector2 getCameraOffset() { return m_cameraPosition; }
251 };
252 }
253 #endif
Definition: Vector4.h:31
void enableRenderToTexture()
Enables the render to texture flag.
Definition: Canvas.h:223
static Canvas * getInstance()
Returns the global canvas object that directly maps to the screen.
Definition: Canvas.h:130
Vector4 getClearColor()
Returns the clear color of the Canvas.
Definition: Canvas.h:191
The Canvas class contains all widgets and renders them.
Definition: Canvas.h:109
Vector2 getCameraOffset()
Returns the current camera offset.
Definition: Canvas.h:250
DISOWN(SpriteBatch *b) void addSpriteBatch(SpriteBatch *b)
Definition: Canvas.h:139
void disableRenderToTexture()
Disables the render to texture flag.
Definition: Canvas.h:237
The Widget class contains all information that is common to all GUI widgets.
Definition: Widget.h:72
~Canvas()
Definition: Canvas.h:136
int getLayer()
Returns which layer this particular Canvas is at.
Definition: Canvas.h:165
Definition: Vector2.h:31
Definition: Button.h:42
Implements a batch of sprites that can be used to circumvent the GUI system when rendering 2D objects...
Definition: Canvas.h:93
Definition: TextureRef.h:32
void setCameraOffset(Vector2 value)
Sets the camera offset value that emulates a basic 2D camera.
Definition: Canvas.h:244
Canvas()
Definition: Canvas.h:137
void setLayer(int nl)
Sets the on which layer this Canvas will appear.
Definition: Canvas.h:174
void setClearColor(Vector4 vec)
Changes the clear color of the Canvas.
Definition: Canvas.h:198
DISOWN(Widget *s) void addSprite(Widget *s)
Definition: Canvas.h:97
Definition: Color.h:29