nomlib
Loading...
Searching...
No Matches
SpriteSheet.hpp
1/******************************************************************************
2
3 nomlib - C++11 cross-platform game engine
4
5Copyright (c) 2013, 2014 Jeffrey Carpenter <i8degrees@gmail.com>
6All rights reserved.
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are met:
10
111. Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
132. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28******************************************************************************/
29#ifndef NOMLIB_GRAPHICS_SPRITE_SPRITE_SHEET_HPP
30#define NOMLIB_GRAPHICS_SPRITE_SPRITE_SHEET_HPP
31
32#include <string>
33#include <map>
34#include <memory>
35
36#include "nomlib/config.hpp"
37#include "nomlib/version.hpp"
38#include "nomlib/math/Rect.hpp"
39#include "nomlib/ptree.hpp"
40
41// #define NOM_DEBUG_SPRITE_SHEET_JSON_LOAD
42
43namespace nom {
44
47{
48 public:
49 static const VersionInfo VERSION;
50
51 typedef SpriteSheet self_type;
52
56
59
62
64 const IntRect& dimensions(int index) const;
65
67 int frames() const;
68
70 bool empty() const;
71
73 std::string version() const;
74
79 const std::string& sheet_filename() const;
80
85 int sheet_width() const;
86
91 int sheet_height() const;
92
97 int sheet_padding() const;
98
103 int sheet_spacing() const;
104
109 int total_frames() const;
110
119 bool load_file(const std::string& filename);
120
124 bool load_sheet_object(const Value& object);
125
126 bool insert_frame(nom::size_type frame_num, const IntRect& frame_bounds);
127 bool append_frame(const IntRect& frame_bounds);
128
130 bool remove_frame(nom::size_type frame);
131
134
136 void dump() const;
137
138 private:
143 std::map<int, IntRect> sheet_;
144
146 std::string sheet_filename_;
147
150
153
156
159
163};
164
165} // namespace nom
166
167#endif // include guard defined
168
int sheet_height_
Source sheet_height used is saved with the output (meta-data).
std::map< int, IntRect > sheet_
Sprite sheet container.
int sheet_padding_
Source padding used is saved with the output (meta-data).
int sheet_width_
Source sheet_width used is saved with the output (meta-data).
bool empty() const
Obtain whether the sprite sheet is empty or not.
bool load_file(const std::string &filename)
De-serialize an existing JSON file.
std::string version() const
Get the current version of the sprite sheet file format.
int total_frames_
The total number of sprite frames; as per the number of objects in the frames object node.
~SpriteSheet()
Destructor.
std::string sheet_filename_
Source filename used is saved with the output (meta-data).
int sheet_height() const
Get the total sprite sheet height.
const IntRect & dimensions(int index) const
Get the calculations made for a particular ID number.
const std::string & sheet_filename() const
Get the sprite sheet's filename.
int total_frames() const
Get the total number of sprite frames.
int sheet_spacing_
Source spacing used is saved with the output (meta-data).
bool remove_frame(nom::size_type frame)
Erase an existing frame from the sheet.
bool load_sheet_object(const Value &object)
Load a sprite sheet from a de-serialized object.
int sheet_width() const
Get the total sprite sheet width.
int sheet_padding() const
Get the sprite sheet's padding.
int frames() const
Obtain the number of frames this object contains.
SpriteSheet * clone() const
Make a duplicate of this object's instance.
void dump() const
Dump the state of this object instance.
int sheet_spacing() const
Get the sprite sheet's spacing.
void remove_frames()
Destroy all stored sprite frames.
Generic interface for opaque data containers.
Definition Value.hpp:43
Container for x.x.x version schemes.
Definition version.hpp:44