GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
Layer.h
1 /*
2  * GDevelop Core
3  * Copyright 2008-2016 Florian Rival ([email protected]). All rights
4  * reserved. This project is released under the MIT License.
5  */
6 #ifndef GDCORE_LAYER_H
7 #define GDCORE_LAYER_H
8 #include <memory>
9 #include <vector>
10 
11 #include "EffectsContainer.h"
12 #include "GDCore/String.h"
13 
14 namespace gd {
15 class Effect;
16 class Camera;
17 class SerializerElement;
18 class EffectsContainer;
19 }
20 
21 namespace gd {
22 
29 class GD_CORE_API Camera {
30  public:
31  Camera();
32  ~Camera(){};
33 
38  void SetViewport(float x1_, float y1_, float x2_, float y2_) {
39  x1 = x1_;
40  x2 = x2_;
41  y1 = y1_;
42  y2 = y2_;
43  };
44  void SetViewportX1(float x1_) { x1 = x1_; };
45  void SetViewportY1(float y1_) { y1 = y1_; };
46  void SetViewportX2(float x2_) { x2 = x2_; };
47  void SetViewportY2(float y2_) { y2 = y2_; };
48  float GetViewportX1() const { return x1; };
49  float GetViewportY1() const { return y1; };
50  float GetViewportX2() const { return x2; };
51  float GetViewportY2() const { return y2; };
52 
56  void SetSize(float width_, float height_) {
57  width = width_;
58  height = height_;
59  };
60  float GetWidth() const { return width; };
61  float GetHeight() const { return height; };
62 
63  void SetUseDefaultSize(bool useDefaultSize = true) {
64  defaultSize = useDefaultSize;
65  };
66  bool UseDefaultSize() const { return defaultSize; }
67 
68  void SetUseDefaultViewport(bool useDefaultViewport = true) {
69  defaultViewport = useDefaultViewport;
70  };
71  bool UseDefaultViewport() const { return defaultViewport; }
72 
73  private:
74  bool defaultSize;
75  bool defaultViewport;
76 
77  float x1;
78  float y1;
79  float x2;
80  float y2;
81  float width;
82  float height;
83 };
84 
91 class GD_CORE_API Layer {
92  public:
93  Layer();
94  virtual ~Layer(){};
95 
99  void SetName(const gd::String& name_) { name = name_; }
100 
104  const gd::String& GetName() const { return name; }
105 
106  const gd::String& GetRenderingType() const { return renderingType; }
107 
108  void SetRenderingType(const gd::String& renderingType_) {
109  renderingType = renderingType_;
110  }
111 
112  const gd::String& GetCameraType() const { return cameraType; }
113 
114  void SetCameraType(const gd::String& cameraType_) {
115  cameraType = cameraType_;
116  }
117 
121  void SetVisibility(bool isVisible_) { isVisible = isVisible_; }
122 
126  bool GetVisibility() const { return isVisible; }
127 
131  void SetLocked(bool isLocked_) { isLocked = isLocked_; }
132 
136  bool IsLocked() const { return isLocked; }
137 
141  void SetLightingLayer(bool isLightingLayer_) {
142  isLightingLayer = isLightingLayer_;
143  }
144 
148  bool IsLightingLayer() const { return isLightingLayer; }
149 
153  void SetFollowBaseLayerCamera(bool followBaseLayerCamera_) {
154  followBaseLayerCamera = followBaseLayerCamera_;
155  }
156 
160  bool IsFollowingBaseLayerCamera() const { return followBaseLayerCamera; }
161 
165  double GetCamera3DNearPlaneDistance() const {
166  return camera3DNearPlaneDistance;
167  }
168  void SetCamera3DNearPlaneDistance(double distance) {
169  camera3DNearPlaneDistance = distance;
170  }
171  double GetCamera3DFarPlaneDistance() const {
172  return camera3DFarPlaneDistance;
173  }
174  void SetCamera3DFarPlaneDistance(double distance) {
175  camera3DFarPlaneDistance = distance;
176  }
177  double GetCamera3DFieldOfView() const { return camera3DFieldOfView; }
178  void SetCamera3DFieldOfView(double angle) { camera3DFieldOfView = angle; }
180 
184 
188  void SetCameraCount(std::size_t n);
189 
193  inline std::size_t GetCameraCount() const { return cameras.size(); };
194 
198  inline const Camera& GetCamera(std::size_t n) const {
199  if (n >= GetCameraCount()) return badCamera;
200  return cameras[n];
201  }
202 
206  inline Camera& GetCamera(std::size_t n) {
207  if (n >= GetCameraCount()) return badCamera;
208  return cameras[n];
209  }
210 
214  inline void DeleteCamera(std::size_t n) {
215  if (n >= GetCameraCount()) return;
216  cameras.erase(cameras.begin() + n);
217  }
218 
222  inline void AddCamera(const Camera& camera) { cameras.push_back(camera); };
223 
225 
229  unsigned int GetAmbientLightColorRed() const { return ambientLightColorR; }
230 
234  unsigned int GetAmbientLightColorGreen() const { return ambientLightColorG; }
235 
239  unsigned int GetAmbientLightColorBlue() const { return ambientLightColorB; }
240 
244  void SetAmbientLightColor(unsigned int r, unsigned int g, unsigned int b) {
245  ambientLightColorR = r;
246  ambientLightColorG = g;
247  ambientLightColorB = b;
248  }
249 
253 
256  EffectsContainer& GetEffects();
257 
261  const EffectsContainer& GetEffects() const;
263 
267  void SerializeTo(SerializerElement& element) const;
268 
272  void UnserializeFrom(const SerializerElement& element);
273 
274  private:
275  gd::String name;
276  gd::String renderingType;
278  gd::String cameraType;
279  bool isVisible;
280  bool isLocked;
281  bool isLightingLayer;
283  bool followBaseLayerCamera;
285  double camera3DNearPlaneDistance;
286  double camera3DFarPlaneDistance;
287  double camera3DFieldOfView;
288  unsigned int ambientLightColorR;
289  unsigned int ambientLightColorG;
290  unsigned int ambientLightColorB;
291  std::vector<gd::Camera> cameras;
292  gd::EffectsContainer effectsContainer;
293 
294  static gd::Camera badCamera;
295 };
296 
302 struct LayerHasName : public std::binary_function<gd::Layer, gd::String, bool> {
303  bool operator()(const Layer& layer, const gd::String& name) const {
304  return layer.GetName() == name;
305  }
306 };
307 
308 } // namespace gd
309 
310 #endif // GDCORE_LAYER_H
A camera is used to render a specific area of a layout.
Definition: Layer.h:29
void SetViewport(float x1_, float y1_, float x2_, float y2_)
Change the viewport, i.e the area of the window where the camera will be displayed.
Definition: Layer.h:38
void SetSize(float width_, float height_)
Change the size of the rendered area of the scene, in pixels.
Definition: Layer.h:56
Contains effects applied to an entity on screen (i.e: a Layer or an Object).
Definition: EffectsContainer.h:29
Represents a layer of a layout.
Definition: Layer.h:91
bool GetVisibility() const
Return true if layer will be displayed at the layout startup.
Definition: Layer.h:126
std::size_t GetCameraCount() const
Get cameras count.
Definition: Layer.h:193
void SetLocked(bool isLocked_)
Change if layer can be modified or not.
Definition: Layer.h:131
void SetName(const gd::String &name_)
Change layer name.
Definition: Layer.h:99
void SetAmbientLightColor(unsigned int r, unsigned int g, unsigned int b)
Definition: Layer.h:244
unsigned int GetAmbientLightColorBlue() const
Definition: Layer.h:239
bool IsLightingLayer() const
Return true if the layer is a lighting layer.
Definition: Layer.h:148
bool IsFollowingBaseLayerCamera() const
Return true if the layer follows the base layer.
Definition: Layer.h:160
void DeleteCamera(std::size_t n)
Delete a specific camera.
Definition: Layer.h:214
const gd::String & GetName() const
Get layer name.
Definition: Layer.h:104
void SetLightingLayer(bool isLightingLayer_)
Set if the layer is a lighting layer or not.
Definition: Layer.h:141
const Camera & GetCamera(std::size_t n) const
Return a reference to a camera.
Definition: Layer.h:198
unsigned int GetAmbientLightColorGreen() const
Definition: Layer.h:234
void AddCamera(const Camera &camera)
Add an already existing camera.
Definition: Layer.h:222
void SetFollowBaseLayerCamera(bool followBaseLayerCamera_)
Set if the layer automatically follows the base layer or not.
Definition: Layer.h:153
void SetVisibility(bool isVisible_)
Change if layer is displayed or not.
Definition: Layer.h:121
bool IsLocked() const
Return true if layer can't be modified.
Definition: Layer.h:136
unsigned int GetAmbientLightColorRed() const
Definition: Layer.h:229
Camera & GetCamera(std::size_t n)
Return a reference to a camera.
Definition: Layer.h:206
A generic container that can represent a value ( containing a string, double, bool or int),...
Definition: SerializerElement.h:37
String represents an UTF8 encoded string.
Definition: String.h:31
Definition: CommonTools.h:24
Functor testing layer name.
Definition: Layer.h:302