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& GetDefaultCameraBehavior() const { return defaultCameraBehavior; }
113 
114  void SetDefaultCameraBehavior(const gd::String& defaultCameraBehavior_) {
115  defaultCameraBehavior = defaultCameraBehavior_;
116  }
117 
118  const gd::String& GetCameraType() const { return cameraType; }
119 
120  void SetCameraType(const gd::String& cameraType_) {
121  cameraType = cameraType_;
122  }
123 
127  void SetVisibility(bool isVisible_) { isVisible = isVisible_; }
128 
132  bool GetVisibility() const { return isVisible; }
133 
137  void SetLocked(bool isLocked_) { isLocked = isLocked_; }
138 
142  bool IsLocked() const { return isLocked; }
143 
147  void SetLightingLayer(bool isLightingLayer_) {
148  isLightingLayer = isLightingLayer_;
149  }
150 
154  bool IsLightingLayer() const { return isLightingLayer; }
155 
159  void SetFollowBaseLayerCamera(bool followBaseLayerCamera_) {
160  followBaseLayerCamera = followBaseLayerCamera_;
161  }
162 
166  bool IsFollowingBaseLayerCamera() const { return followBaseLayerCamera; }
167 
171  double GetCamera3DNearPlaneDistance() const {
172  return camera3DNearPlaneDistance;
173  }
174  void SetCamera3DNearPlaneDistance(double distance) {
175  camera3DNearPlaneDistance = distance;
176  }
177  double GetCamera3DFarPlaneDistance() const {
178  return camera3DFarPlaneDistance;
179  }
180  void SetCamera3DFarPlaneDistance(double distance) {
181  camera3DFarPlaneDistance = distance;
182  }
183  double GetCamera3DFieldOfView() const { return camera3DFieldOfView; }
184  void SetCamera3DFieldOfView(double angle) { camera3DFieldOfView = angle; }
186 
190 
194  void SetCameraCount(std::size_t n);
195 
199  inline std::size_t GetCameraCount() const { return cameras.size(); };
200 
204  inline const Camera& GetCamera(std::size_t n) const {
205  if (n >= GetCameraCount()) return badCamera;
206  return cameras[n];
207  }
208 
212  inline Camera& GetCamera(std::size_t n) {
213  if (n >= GetCameraCount()) return badCamera;
214  return cameras[n];
215  }
216 
220  inline void DeleteCamera(std::size_t n) {
221  if (n >= GetCameraCount()) return;
222  cameras.erase(cameras.begin() + n);
223  }
224 
228  inline void AddCamera(const Camera& camera) { cameras.push_back(camera); };
229 
231 
235  unsigned int GetAmbientLightColorRed() const { return ambientLightColorR; }
236 
240  unsigned int GetAmbientLightColorGreen() const { return ambientLightColorG; }
241 
245  unsigned int GetAmbientLightColorBlue() const { return ambientLightColorB; }
246 
250  void SetAmbientLightColor(unsigned int r, unsigned int g, unsigned int b) {
251  ambientLightColorR = r;
252  ambientLightColorG = g;
253  ambientLightColorB = b;
254  }
255 
259 
262  EffectsContainer& GetEffects();
263 
267  const EffectsContainer& GetEffects() const;
269 
273  void SerializeTo(SerializerElement& element) const;
274 
278  void UnserializeFrom(const SerializerElement& element);
279 
280  private:
281  gd::String name;
282  gd::String renderingType;
284  gd::String defaultCameraBehavior;
285  gd::String cameraType;
286  bool isVisible;
287  bool isLocked;
288  bool isLightingLayer;
290  bool followBaseLayerCamera;
292  double camera3DNearPlaneDistance;
293  double camera3DFarPlaneDistance;
294  double camera3DFieldOfView;
295  unsigned int ambientLightColorR;
296  unsigned int ambientLightColorG;
297  unsigned int ambientLightColorB;
298  std::vector<gd::Camera> cameras;
299  gd::EffectsContainer effectsContainer;
300 
301  static gd::Camera badCamera;
302 };
303 
304 } // namespace gd
305 
306 #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:132
std::size_t GetCameraCount() const
Get cameras count.
Definition: Layer.h:199
void SetLocked(bool isLocked_)
Change if layer can be modified or not.
Definition: Layer.h:137
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:250
unsigned int GetAmbientLightColorBlue() const
Definition: Layer.h:245
bool IsLightingLayer() const
Return true if the layer is a lighting layer.
Definition: Layer.h:154
bool IsFollowingBaseLayerCamera() const
Return true if the layer follows the base layer.
Definition: Layer.h:166
void DeleteCamera(std::size_t n)
Delete a specific camera.
Definition: Layer.h:220
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:147
const Camera & GetCamera(std::size_t n) const
Return a reference to a camera.
Definition: Layer.h:204
unsigned int GetAmbientLightColorGreen() const
Definition: Layer.h:240
void AddCamera(const Camera &camera)
Add an already existing camera.
Definition: Layer.h:228
void SetFollowBaseLayerCamera(bool followBaseLayerCamera_)
Set if the layer automatically follows the base layer or not.
Definition: Layer.h:159
void SetVisibility(bool isVisible_)
Change if layer is displayed or not.
Definition: Layer.h:127
bool IsLocked() const
Return true if layer can't be modified.
Definition: Layer.h:142
unsigned int GetAmbientLightColorRed() const
Definition: Layer.h:235
Camera & GetCamera(std::size_t n)
Return a reference to a camera.
Definition: Layer.h:212
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:33
Definition: CommonTools.h:24