tmxparser  2.1.0
 All Classes Functions Variables Pages
TmxLayer.h
1 //-----------------------------------------------------------------------------
2 // TmxLayer.h
3 //
4 // Copyright (c) 2010-2014, Tamir Atias
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 // DISCLAIMED. IN NO EVENT SHALL TAMIR ATIAS BE LIABLE FOR ANY
19 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 //
26 // Author: Tamir Atias
27 //-----------------------------------------------------------------------------
28 #pragma once
29 
30 #include <string>
31 
32 #include "TmxPropertySet.h"
33 #include "TmxMapTile.h"
34 
35 namespace tinyxml2 {
36  class XMLNode;
37 }
38 
39 namespace Tmx
40 {
41  class Map;
42  class Tile;
43  enum LayerType
44  {
45  TMX_LAYERTYPE_TILE = 0X01,
46  TMX_LAYERTYPE_OBJECTGROUP = 0X02,
47  TMX_LAYERTYPE_IMAGE_LAYER = 0X04,
48  TMX_LAYERTYPE_GROUP_LAYER = 0X08
49  };
50 
51  //-------------------------------------------------------------------------
53  //-------------------------------------------------------------------------
54  class Layer
55  {
56  private:
57  // Prevent copy constructor.
58  Layer(const Layer &_layer);
59 
60  public:
62  Layer(const Tmx::Map *_map, const std::string _name, const int _x, const int _y,
63  const int _width, const int _height, const float _opacity, const bool _visible, const LayerType _layerType);
64 
66  Layer(const Tmx::Tile *_tile, const std::string _name, const int _x, const int _y,
67  const int _width, const int _height, const float _opacity, const bool _visible, const LayerType _layerType);
68 
69  virtual ~Layer();
70 
72  virtual void Parse(const tinyxml2::XMLNode *layerNode) = 0;
73 
75  const Tmx::Map *mapGetMap() const { return map; }
76 
78  const std::string &GetName() const { return name; }
79 
81  int GetX() const { return x; }
82 
84  int GetY() const { return y; }
85 
87  int GetWidth() const { return width; }
88 
90  int GetHeight() const { return height; }
91 
93  float GetOpacity() const { return opacity; }
94 
96  bool IsVisible() const { return visible; }
97 
99  const Tmx::PropertySet &GetProperties() const { return properties; }
100 
102  int GetZOrder() const { return zOrder; }
103 
105  void SetZOrder( int z ) { zOrder = z; }
106 
108  int GetParseOrder() const { return parseOrder; }
109 
111  Tmx::LayerType GetLayerType() const { return layerType; }
112 
113  protected:
115  const Tmx::Map *map;
116  const Tmx::Tile *tile;
117  std::string name;
118 
119  int x;
120  int y;
121  int width;
122  int height;
123 
124  float opacity;
125  bool visible;
126  int zOrder;
127  const int parseOrder;
128 
129  const Tmx::LayerType layerType;
130 
131  Tmx::PropertySet properties;
132 
133  static int nextParseOrder;
135  };
136 }
const Tmx::PropertySet & GetProperties() const
Get the property set.
Definition: TmxLayer.h:99
Base class for other layer types.
Definition: TmxLayer.h:54
const Tmx::Map * mapGetMap() const
Get the pointer to the parent map.
Definition: TmxLayer.h:75
void SetZOrder(int z)
Set the zorder of the layer.
Definition: TmxLayer.h:105
int GetHeight() const
Get the height of the layer, in tiles. Only used in tile layers.
Definition: TmxLayer.h:90
int GetY() const
Get the value of the y attribute of the layer. Means different things for different layer types...
Definition: TmxLayer.h:84
float GetOpacity() const
Get the opacity of the layer.
Definition: TmxLayer.h:93
int GetParseOrder() const
Get the parse order of the layer.
Definition: TmxLayer.h:108
int GetX() const
Get the value of the x attribute of the layer. Means different things for different layer types...
Definition: TmxLayer.h:81
int GetZOrder() const
Get the zorder of the layer.
Definition: TmxLayer.h:102
This class is the root class of the parser.
Definition: TmxMap.h:115
This class contains a map of properties.
Definition: TmxPropertySet.h:47
bool IsVisible() const
Get the visibility of the layer.
Definition: TmxLayer.h:96
int GetWidth() const
Get the width of the layer, in tiles. Only used in tile layers.
Definition: TmxLayer.h:87
Tmx::LayerType GetLayerType() const
Get the type of the layer.
Definition: TmxLayer.h:111
virtual void Parse(const tinyxml2::XMLNode *layerNode)=0
Parse a layer element.
Class to contain information about every tile in the tileset/tiles element.
Definition: TmxTile.h:51
const std::string & GetName() const
Get the name of the layer.
Definition: TmxLayer.h:78