tmxlite 1.0.0
lightweight parse for Tiled maps
ImageLayer.hpp
1/*********************************************************************
2Matt Marchant 2016 - 2022
3http://trederia.blogspot.com
4
5tmxlite - Zlib license.
6
7This software is provided 'as-is', without any express or
8implied warranty. In no event will the authors be held
9liable for any damages arising from the use of this software.
10
11Permission is granted to anyone to use this software for any purpose,
12including commercial applications, and to alter it and redistribute
13it freely, subject to the following restrictions:
14
151. The origin of this software must not be misrepresented;
16you must not claim that you wrote the original software.
17If you use this software in a product, an acknowledgment
18in the product documentation would be appreciated but
19is not required.
20
212. Altered source versions must be plainly marked as such,
22and must not be misrepresented as being the original software.
23
243. This notice may not be removed or altered from any
25source distribution.
26*********************************************************************/
27
28#pragma once
29
30#include <tmxlite/Config.hpp>
31#include <tmxlite/Layer.hpp>
32#include <tmxlite/Types.hpp>
33
34namespace tmx
35{
41 class TMXLITE_EXPORT_API ImageLayer final : public Layer
42 {
43 public:
44 explicit ImageLayer(const std::string&);
45
46 Type getType() const override { return Layer::Type::Image; }
47 void parse(const pugi::xml_node&, Map*) override;
48
53 const std::string& getImagePath() const { return m_filePath; }
54
59 const Colour& getTransparencyColour() const { return m_transparencyColour; }
60
65 bool hasTransparency() const { return m_hasTransparency; }
66
70 const Vector2u& getImageSize() const { return m_imageSize; }
71
76 bool hasRepeatX() const { return m_hasRepeatX; }
77
82 bool hasRepeatY() const { return m_hasRepeatY; }
83
84 private:
85 std::string m_workingDir;
86 std::string m_filePath;
87 Colour m_transparencyColour;
88 bool m_hasTransparency;
89 Vector2u m_imageSize;
90 bool m_hasRepeatX;
91 bool m_hasRepeatY;
92 };
93
94 template <>
95 inline ImageLayer& Layer::getLayerAs<ImageLayer>()
96 {
97 assert(getType() == Type::Image);
98 return *static_cast<ImageLayer*>(this);
99 }
100
101 template <>
102 inline const ImageLayer& Layer::getLayerAs<ImageLayer>() const
103 {
104 assert(getType() == Type::Image);
105 return *static_cast<const ImageLayer*>(this);
106 }
107}
Image layers contain a single image which make up that layer. The parser contains the fully resolved ...
Definition ImageLayer.hpp:42
bool hasRepeatY() const
Returns true if the image drawn by this layer is repeated along the Y axis.
Definition ImageLayer.hpp:82
Type getType() const override
Returns a Type value representing the concrete type. Use this when deciding which conrete layer type ...
Definition ImageLayer.hpp:46
const Colour & getTransparencyColour() const
Returns the colour used by the image to represent transparent pixels. By default this is (0,...
Definition ImageLayer.hpp:59
const std::string & getImagePath() const
Returns the path, relative to the working directory, of the image used by the image layer.
Definition ImageLayer.hpp:53
const Vector2u & getImageSize() const
Returns the size of the image of the image layer in pixels.
Definition ImageLayer.hpp:70
bool hasRepeatX() const
Returns true if the image drawn by this layer is repeated along the X axis.
Definition ImageLayer.hpp:76
bool hasTransparency() const
Returns true if the image used by this layer specifically states a colour to use as transparency.
Definition ImageLayer.hpp:65
void parse(const pugi::xml_node &, Map *) override
Attempts to parse the specific node layer type.
Represents a layer of a tmx format tile map. This is an abstract base class from which all layer type...
Definition Layer.hpp:56
T & getLayerAs()
Use this to get a reference to the concrete layer type which this layer points to....
Type
Layer type as returned by getType() Tile: this layer is a TileLayer type Object: This layer is an Obj...
Definition Layer.hpp:71
virtual Type getType() const =0
Returns a Type value representing the concrete type. Use this when deciding which conrete layer type ...
Parser for TMX format tile maps. This class can be used to parse the XML format tile maps created wit...
Definition Map.hpp:94
Contains the red, green, blue and alpha values of a colour in the range 0 - 255.
Definition Types.hpp:111