JugiMap Framework
jmLayers.h
1 #ifndef JUGIMAP_LAYERS_H
2 #define JUGIMAP_LAYERS_H
3 
4 #include "jmCommon.h"
5 #include "jmColor.h"
6 #include "jmGlobal.h"
7 
8 
9 namespace jugimap {
10 
11 
12 class Map;
13 class Sprite;
14 class StandardSprite;
15 class SourceSprite;
16 class TextSprite;
17 class Font;
18 class ComposedSprite;
19 class JugiMapBinaryLoader;
20 class VectorShape;
21 
22 
23 
24 
27 class Layer
28 {
29 public:
30  friend class JugiMapBinaryLoader;
31  friend class ComposedSprite;
32  friend class Map;
33 
34 
36  Layer(){}
37 
38  Layer(const Layer &l) = delete;
39  Layer& operator=(const Layer &l) = delete;
40 
41 
42 
46  virtual void InitLayerParameters();
47 
48 
52  virtual void InitEngineObjects() {}
53 
54 
58  virtual void UpdateEngineObjects() {}
59 
60 
65  virtual void DrawEngineObjects() {}
66 
67 
71  Map* GetMap() {return map;}
72 
73 
75  ComposedSprite* GetParentComposedSprite() {return parentComposedSprite;}
76 
77 
79  bool IsMapLayer(){ return (parentComposedSprite==nullptr); }
80 
81 
83  LayerKind GetKind() {return kind;}
84 
85 
87  std::string GetName() {return name;}
88 
89 
91  std::vector<jugimap::Parameter>& GetParameters() {return parameters;}
92 
93 
97  int GetZOrder() {return zOrder;}
98 
99 
101  virtual void UpdateBoundingBox(){}
102 
103 
105  Rectf GetBoundingBox(){ return boundingBox;}
106 
107 
111  LayerType GetLayerType(){ return layerType;}
112 
113 
117  //AlignX GetAlignX() {return alignX;}
118 
119 
123  //AlignY GetAlignY() {return alignY;}
124 
125  StretchingVariant GetStretchingVariant(){ return stretchingVariant;}
126 
127 
131  Vec2i GetAlignPosition(){ return alignPosition; }
132 
133 
137  Vec2f GetAlignOffset(){ return alignOffset; }
138 
139 
143  Vec2f GetLayersPlaneSize(){return layersPlaneSize;}
144 
145 
149  //ParallaxLayerMode GetParallaxLayerMode(){ return parallaxLayerMode;}
150 
151 
152 
153 
154 
158  Vec2f GetParallaxFactor() {return parallaxFactor;}
159 
160 
165  Vec2f GetParallaxOffset(){return parallaxOffset;}
166 
167 
171  //ScreenLayerMode GetScreenLayerMode(){ return screenLayerMode;}
172 
173 
174  //-------
175 
179  void _SetName(const std::string &_name){ name = _name; }
180 
181 
185  void _SetKind(LayerKind _kind){ kind = _kind; }
186 
187 
191  void _SetLayerType(LayerType _layerType){ layerType = _layerType; }
192 
193 
198  void _SetParallaxFactor(Vec2f _parallaxFactor){ parallaxFactor = _parallaxFactor; }
199 
200 
205  void _SetAlignPosition(Vec2i _alignPosition){ alignPosition = _alignPosition; }
206 
207 
212  void _SetAlignOffset(Vec2f _alignOffset){ alignOffset = _alignOffset; }
213 
214 
219  void _SetAttachToLayer(std::string _attachToLayer){ attachToLayer = _attachToLayer; }
220 
221 
226  void _SetStretchingVariant(StretchingVariant _stretchingVariant){ stretchingVariant = _stretchingVariant;}
227 
228 
232  void _SetZOrder(int _zOrder){ zOrder = _zOrder; }
233 
234 
235 protected:
236 
238  virtual ~Layer(){}
239 
240  bool UpdateParallaxOffset();
241 
242  //---
243  Rectf boundingBox;
244 
245 private:
246 
247  Map *map = nullptr; // LINK to map
248  ComposedSprite *parentComposedSprite = nullptr; // LINK to parent composed sprite (or nullptr if parent is map).
249 
251  std::string name = "Layer";
252  std::vector<jugimap::Parameter> parameters; // Custom parameters from JugiMap editor.
253 
254  //---
255  int zOrder = 0; // Drawing order of layer sprites (used by some engines)
256 
257 
258 
259  //---- properties of layers of the parallax maps
260  //ParallaxLayerMode parallaxLayerMode = ParallaxLayerMode::STANDARD;
261  LayerType layerType = LayerType::WORLD;
262  Vec2i alignPosition;
263  Vec2f alignOffset;
264  Vec2f parallaxFactor;
265  Vec2i tilingCount;
266  Vec2i tilingSpacing;
267  Vec2i tilingSpacingDelta;
268  Vec2i tilingCountAutoSpread; //boolean Flag
269  StretchingVariant stretchingVariant = StretchingVariant::XY_TO_WORLD_SIZE;
270 
271  Vec2f parallaxOffset;
272 
273  //---- properties of layers of the screen maps
274  //ScreenLayerMode screenLayerMode = ScreenLayerMode::STANDARD;
275 
276  //---- properties of layers of the parallax and screen maps
277  //AlignX alignX = AlignX::MIDDLE;
278  //AlignY alignY = AlignY::MIDDLE;
279 
280 
281  //bool alignOffsetX_obtainFromMap = false;
282  //bool alignOffsetY_obtainFromMap = false;
283  Vec2i alignOffset_obtainFromMap; //boolean Flag
284 
285  std::string attachToLayer;
286  Vec2f layersPlaneSize;
287 
288 
289 
290 
291 
292 };
293 
294 
295 
296 //==================================================================================================
297 
298 
303 class SpriteLayer : public Layer
304 {
305 public:
306  friend class JugiMapBinaryLoader;
307  friend class ComposedSprite;
308  friend class Map;
309 
310 
312  SpriteLayer();
313 
314 
315  //----
316  virtual void InitEngineObjects() override;
317  virtual void InitLayerParameters() override;
318  virtual void UpdateEngineObjects() override;
319  virtual void DrawEngineObjects()override;
320 
321 
323  std::vector<Sprite*>& GetSprites() {return sprites;}
324 
325 
327  virtual void UpdateBoundingBox() override;
328 
329 
334  void SetAlpha(float _alpha);
335 
336 
340  float GetAlpha();
341 
342 
346  void SetBlend(Blend _blend);
347 
348 
352  Blend GetBlend() {return blend;}
353 
354 
358  void AddSprite(Sprite* _sprite);
359 
360 
361  StandardSprite * AddStandardSprite(SourceSprite *_sourceSprite, Vec2f _position);
362 
363  TextSprite * AddTextSprite(const std::string &_textString, Font* _font, ColorRGBA _color, Vec2f _position, TextHandleVariant _textHandle);
364 
365 
369  virtual void RemoveAndDeleteSprite(Sprite* _sprite);
370 
371 
375  void CaptureForLerpDrawing();
376 
377 
378  int FindLastZOrder();
379 
380  //-------
381 
382 
391  void SetSpritesChanged(bool _spritesChanged){ spritesChanged = _spritesChanged;}
392 
393 
397  bool IsSpritesChanged(){ return spritesChanged;}
398 
399 
407  void SetSpritesChangeFlag(int _spritesChangeFlag)
408  {
409  spritesChangeFlag = _spritesChangeFlag;
410  if(spritesChangeFlag!=0){
411  spritesChanged = true;
412  }
413  }
414 
415 
419  void AppendToSpritesChangeFlag(int _spritesChangeFlag)
420  {
421  spritesChangeFlag |= _spritesChangeFlag;
422  if(spritesChangeFlag!=0){
423  spritesChanged = true;
424  }
425  }
426 
430  int GetSpritesChangeFlag(){ return spritesChangeFlag; }
431 
432 
433  //-------
434 
435 
440  bool IsEditorTileLayer(){ return editorTileLayer;}
441 
442 
443 protected:
444 
446  virtual ~SpriteLayer() override;
447 
448 
449 private:
450 
451 
452  float alpha = 1.0; // Transparency for sprites: 0 - 1.0
453  Blend blend = Blend::ALPHA; // Blending mode for sprites: SOLID, ALPHA, ADDITIVE
454 
455  //---
456  std::vector<Sprite*>sprites; // OWNED sprites.
457  bool editorTileLayer = false;
458  bool spritesChanged = false;
459  int spritesChangeFlag = 0;
460 
461 
462 
463 
464  void UpdateSingleSpriteStretch(Vec2i _designSize, bool _stretchX, bool _stretchY);
465  bool UpdateStretchingSingleSpriteLayer();
466 
467 };
468 
469 
470 //==================================================================================================
471 
472 
477 class VectorLayer : public Layer
478 {
479 public:
480  friend class JugiMapBinaryLoader;
481  friend class ComposedSprite;
482  friend class Map;
483 
484 
486  VectorLayer();
487 
488 
489  virtual void InitLayerParameters() override;
490  virtual void UpdateEngineObjects() override;
491 
492  virtual void UpdateBoundingBox() override;
493 
494 
496  std::vector<VectorShape*>& GetVectorShapes() {return vectorShapes;}
497 
498 
502  void AddVectorShape(VectorShape* _vs){vectorShapes.push_back(_vs);}
503 
504 
505 protected:
506 
508  virtual ~VectorLayer() override;
509 
510 
511 private:
512 
513  std::vector<VectorShape*>vectorShapes; //OWNED
514 
515 };
516 
517 
518 
519 }
520 
521 
522 #endif
jugimap::Layer::UpdateEngineObjects
virtual void UpdateEngineObjects()
Update all engine objects related to this layer and its content.
Definition: jmLayers.h:58
jugimap::SpriteLayer::~SpriteLayer
virtual ~SpriteLayer() override
Destructor.
Definition: jmLayers.cpp:210
jugimap::Layer::GetLayerType
LayerType GetLayerType()
Returns the LayerType factor of this layer.
Definition: jmLayers.h:111
jugimap::Layer::GetAlignPosition
Vec2i GetAlignPosition()
Returns the allign position factor of this layer.
Definition: jmLayers.h:131
jugimap::SpriteLayer::GetSprites
std::vector< Sprite * > & GetSprites()
Returns a reference to the vector of stored sprites in this sprite layer.
Definition: jmLayers.h:323
jugimap::VectorLayer::VectorLayer
VectorLayer()
Constructor.
Definition: jmLayers.cpp:641
jugimap::Rect< float >
jugimap::Layer
The Layer class is the base class for layers.
Definition: jmLayers.h:27
jugimap::Layer::GetZOrder
int GetZOrder()
Returns the zOrder of this layer.
Definition: jmLayers.h:97
jugimap::Layer::_SetName
void _SetName(const std::string &_name)
Returns the ScreenLayerMode factor of this layer.
Definition: jmLayers.h:179
jugimap::SpriteLayer::SetSpritesChangeFlag
void SetSpritesChangeFlag(int _spritesChangeFlag)
Set the sprites changes flag to the given **_changedFlags**.
Definition: jmLayers.h:407
jugimap::Layer::InitLayerParameters
virtual void InitLayerParameters()
Initialize layer properties from the parameters set in the editor.
Definition: jmLayers.cpp:18
jugimap::ColorRGBA
Color in RGBA color space - integer variant.
Definition: jmColor.h:15
jugimap::Layer::GetParameters
std::vector< jugimap::Parameter > & GetParameters()
Returns a reference to the vector of stored paramters in this layer.
Definition: jmLayers.h:91
jugimap::Layer::GetMap
Map * GetMap()
Returns a Map object where this layer is stored.
Definition: jmLayers.h:71
jugimap::Layer::IsMapLayer
bool IsMapLayer()
Returns true if this layer is stored in a Map; if it's stored in a ComposedSprite returns false.
Definition: jmLayers.h:79
jugimap::Layer::GetName
std::string GetName()
Returns the name of this layer.
Definition: jmLayers.h:87
jugimap::Layer::_SetAlignOffset
void _SetAlignOffset(Vec2f _alignOffset)
Sets the align offset of this layer to the given *_alignOffset*.
Definition: jmLayers.h:212
jugimap::SpriteLayer::InitLayerParameters
virtual void InitLayerParameters() override
Initialize layer properties from the parameters set in the editor.
Definition: jmLayers.cpp:236
jugimap::Layer::_SetLayerType
void _SetLayerType(LayerType _layerType)
Sets the layer mode of this layer to the given *_layerType*.
Definition: jmLayers.h:191
jugimap::StretchingVariant
StretchingVariant
The stretching variants.
Definition: jmGlobal.h:76
jugimap::LayerKind
LayerKind
The kinds of layer. Used as identifier for Layer objects.
Definition: jmGlobal.h:51
jugimap::Layer::Layer
Layer()
Constructor.
Definition: jmLayers.h:36
jugimap::Layer::GetBoundingBox
Rectf GetBoundingBox()
Returns the map bounding box of this layer.
Definition: jmLayers.h:105
jugimap::VectorLayer::GetVectorShapes
std::vector< VectorShape * > & GetVectorShapes()
Returns a reference to the vector of stored shapes in this vector layer.
Definition: jmLayers.h:496
jugimap::Blend::ALPHA
Alpha blend.
jugimap::Layer::GetParallaxFactor
Vec2f GetParallaxFactor()
Returns the ParallaxLayerMode factor of this layer.
Definition: jmLayers.h:158
jugimap::Layer::GetParallaxOffset
Vec2f GetParallaxOffset()
Returns the parallax offset of this layer.
Definition: jmLayers.h:165
jugimap::SpriteLayer::GetSpritesChangeFlag
int GetSpritesChangeFlag()
Returns the sprites changes flag.
Definition: jmLayers.h:430
jugimap::SpriteLayer::AppendToSpritesChangeFlag
void AppendToSpritesChangeFlag(int _spritesChangeFlag)
Append the given *_spritesChangeFlag* to the current sprites changes flag using bitwise operation.
Definition: jmLayers.h:419
jugimap::StandardSprite
The StandardSprite class defines the sprite from JugiMap Editor.
Definition: jmSprites.h:787
jugimap::Layer::InitEngineObjects
virtual void InitEngineObjects()
Initialize all engine objects related to this layer and its content.
Definition: jmLayers.h:52
jugimap::VectorLayer::UpdateEngineObjects
virtual void UpdateEngineObjects() override
Update all engine objects related to this layer and its content.
Definition: jmLayers.cpp:665
jugimap::Layer::_SetParallaxFactor
void _SetParallaxFactor(Vec2f _parallaxFactor)
Sets the parallax factor of this layer to the given *_parallaxFactor*.
Definition: jmLayers.h:198
jugimap::Layer::_SetAlignPosition
void _SetAlignPosition(Vec2i _alignPosition)
Sets the align position of this layer to the given *_alignPosition*.
Definition: jmLayers.h:205
jugimap::SpriteLayer::UpdateBoundingBox
virtual void UpdateBoundingBox() override
Update the map bounding box of this sprite layer.
Definition: jmLayers.cpp:590
jugimap::Layer::~Layer
virtual ~Layer()
Destructor.
Definition: jmLayers.h:238
jugimap::Sprite
The Sprite is the base sprite class.
Definition: jmSprites.h:32
jugimap::Layer::DrawEngineObjects
virtual void DrawEngineObjects()
Draw all engine objects related to this layer and its content.
Definition: jmLayers.h:65
jugimap::VectorLayer::UpdateBoundingBox
virtual void UpdateBoundingBox() override
Update the map bounding box of this layer.
Definition: jmLayers.cpp:687
jugimap::SpriteLayer::DrawEngineObjects
virtual void DrawEngineObjects() override
Draw all engine objects related to this layer and its content.
Definition: jmLayers.cpp:316
jugimap::Layer::_SetZOrder
void _SetZOrder(int _zOrder)
Sets the z-order factor of this layer to the given *_zOrder*.
Definition: jmLayers.h:232
jugimap::Layer::_SetStretchingVariant
void _SetStretchingVariant(StretchingVariant _stretchingVariant)
Sets the stretching variant of this layer to the given *_stretchingVariant*.
Definition: jmLayers.h:226
jugimap::LayerKind::NOT_DEFINED
The layer kind not defined.
jugimap::SpriteLayer::IsEditorTileLayer
bool IsEditorTileLayer()
Returns true if this layer was a tile layer in JugiMap Editor; if it was a sprite layer returns false...
Definition: jmLayers.h:440
jugimap::SpriteLayer::InitEngineObjects
virtual void InitEngineObjects() override
Initialize all engine objects related to this layer and its content.
Definition: jmLayers.cpp:218
jugimap::Layer::GetAlignOffset
Vec2f GetAlignOffset()
Returns the allign offset factor of this layer.
Definition: jmLayers.h:137
jugimap::SpriteLayer::GetAlpha
float GetAlpha()
Returns the alpha factor of this sprite layer.
Definition: jmLayers.cpp:520
jugimap::Layer::UpdateBoundingBox
virtual void UpdateBoundingBox()
Update the map bounding box of this layer.
Definition: jmLayers.h:101
jugimap::SpriteLayer::CaptureForLerpDrawing
void CaptureForLerpDrawing()
Capture the sprite properties, usually the position only, required for the lerp drawing.
Definition: jmLayers.cpp:602
jugimap::Layer::GetParentComposedSprite
ComposedSprite * GetParentComposedSprite()
Returns a ComposedSprite where this layer is stored or nullptr if it is stored in a map.
Definition: jmLayers.h:75
jugimap::VectorLayer::~VectorLayer
virtual ~VectorLayer() override
Destructor.
Definition: jmLayers.cpp:647
jugimap::VectorLayer::InitLayerParameters
virtual void InitLayerParameters() override
Initialize layer properties from the parameters set in the editor.
Definition: jmLayers.cpp:654
jugimap::Layer::GetStretchingVariant
StretchingVariant GetStretchingVariant()
Returns the AlignX factor of this layer.
Definition: jmLayers.h:125
jugimap::Layer::_SetKind
void _SetKind(LayerKind _kind)
Sets the kind of this layer to the given *_kind*.
Definition: jmLayers.h:185
jugimap::SpriteLayer::IsSpritesChanged
bool IsSpritesChanged()
Returns 'true' if this sprite layer has sprites with changed properties; otherwise returns false.
Definition: jmLayers.h:397
jugimap::SpriteLayer::RemoveAndDeleteSprite
virtual void RemoveAndDeleteSprite(Sprite *_sprite)
Remove and delete the given sprite *_sprite* from this sprite layer.
Definition: jmLayers.cpp:574
jugimap::SpriteLayer::SetAlpha
void SetAlpha(float _alpha)
Sets the alpha factor of this sprite layer to the given *_alpha*.
Definition: jmLayers.cpp:504
jugimap::Layer::GetLayersPlaneSize
Vec2f GetLayersPlaneSize()
Returns the layers plane size of this layer.
Definition: jmLayers.h:143
jugimap::Font
The Font class defines fonts used in TextSprite objects.
Definition: jmFont.h:16
jugimap::SpriteLayer::UpdateEngineObjects
virtual void UpdateEngineObjects() override
Update all engine objects related to this layer and its content.
Definition: jmLayers.cpp:267
jugimap::SpriteLayer::SpriteLayer
SpriteLayer()
Constructor.
Definition: jmLayers.cpp:204
jugimap::Layer::GetKind
LayerKind GetKind()
Returns the kind of this layer.
Definition: jmLayers.h:83
jugimap::Blend
Blend
The blend modes for the openGL pixel blending.
Definition: jmGlobal.h:101
jugimap::ComposedSprite
The ComposedSprite class defines the composed sprite from JugiMap Editor.
Definition: jmSprites.h:682
jugimap::SpriteLayer::SetBlend
void SetBlend(Blend _blend)
Sets the blend factor of this sprite layer to the given *_blend*.
Definition: jmLayers.cpp:512
jugimap::SpriteLayer::AddSprite
void AddSprite(Sprite *_sprite)
Adds a new sprite to this sprite layer.
Definition: jmLayers.cpp:530
jugimap::LayerType
LayerType
The types of layer. Used to distinguish layers for world, parallax and screen maps.
Definition: jmGlobal.h:64
jugimap::Vec2< int >
jugimap::SourceSprite
The SourceSprite class defines the source sprite from JugiMap Editor.
Definition: jmSourceGraphics.h:221
jugimap::VectorLayer::AddVectorShape
void AddVectorShape(VectorShape *_vs)
Adds a new vector shape to this vector layer.
Definition: jmLayers.h:502
jugimap::TextHandleVariant
TextHandleVariant
Predefined handles for TextSprite objects.
Definition: jmGlobal.h:229
jugimap::TextSprite
The TextSprite class defines the text sprite from JugiMap Editor.
Definition: jmSprites.h:889
jugimap::VectorLayer
The VectorLayer class defines the vector layer from JugiMap Editor.
Definition: jmLayers.h:477
jugimap::VectorShape
The VectorShape class defines the vector shape from JugiMap Editor.
Definition: jmVectorShapes.h:206
jugimap::JugiMapBinaryLoader
The JugiMapBinaryLoader class loads data from jugimap binary files (.jmb).
Definition: jmMapBinaryLoader.h:37
jugimap::Map
The Map class defines the map element from JugiMap Editor.
Definition: jmMap.h:26
jugimap::SpriteLayer::SetSpritesChanged
void SetSpritesChanged(bool _spritesChanged)
Set the sprites changed flag which indicates that this sprite layer has sprites with changed properit...
Definition: jmLayers.h:391
jugimap::SpriteLayer
The SpriteLayer class defines the sprite and tile layers from JugiMap Editor.
Definition: jmLayers.h:303
jugimap::SpriteLayer::GetBlend
Blend GetBlend()
Returns the blend factor of this sprite layer.
Definition: jmLayers.h:352
jugimap::Layer::_SetAttachToLayer
void _SetAttachToLayer(std::string _attachToLayer)
Sets the 'attachToLayer' of this layer to the given *_attachToLayer*.
Definition: jmLayers.h:219