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 "export.hpp"
37#include "nomlib/core/IObject.hpp"
38#include "nomlib/config.hpp"
39#include "nomlib/version.hpp"
40#include "nomlib/math/Rect.hpp"
41
42// #define NOM_DEBUG_SPRITE_SHEET_JSON_LOAD
43
44namespace nom {
45
46// Forward declarations
47class Value;
48
50class NOM_EXPORT SpriteSheet: public virtual IObject
51{
52 public:
53 NOM_EXPORT static const VersionInfo VERSION;
54
55 typedef SpriteSheet self_type;
56
60
63
66
68 const IntRect& dimensions(int index) const;
69
71 int frames() const;
72
74 bool empty() const;
75
77 std::string version() const;
78
83 const std::string& sheet_filename() const;
84
89 int sheet_width() const;
90
95 int sheet_height() const;
96
101 int sheet_padding() const;
102
107 int sheet_spacing() const;
108
113 int total_frames() const;
114
123 bool load_file(const std::string& filename);
124
128 bool load_sheet_object(const Value& object);
129
130 bool insert_frame(nom::size_type frame_num, const IntRect& frame_bounds);
131 bool append_frame(const IntRect& frame_bounds);
132
134 bool remove_frame(nom::size_type frame);
135
138
140 void dump() const;
141
142 private:
147 std::map<int, IntRect> sheet_;
148
150 std::string sheet_filename_;
151
154
157
160
163
167};
168
169} // namespace nom
170
171#endif // include guard defined
172
IObject(void)
Default constructor.
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:44
Container for x.x.x version schemes.
Definition version.hpp:45