/
SpriteObject.h
135 lines (113 loc) · 4.77 KB
/
SpriteObject.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* GDevelop Core
* Copyright 2008-2014 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
*/
#ifndef GDCORE_SPRITEOBJECT_H
#define GDCORE_SPRITEOBJECT_H
#include "GDCore/PlatformDefinition/Object.h"
#include "GDCore/BuiltinExtensions/SpriteExtension/Animation.h"
#include "GDCore/BuiltinExtensions/SpriteExtension/Direction.h"
#include "GDCore/BuiltinExtensions/SpriteExtension/Sprite.h"
namespace gd { class InitialInstance; }
namespace gd { class Object; }
namespace gd { class Layout; }
namespace gd { class Sprite; }
namespace gd { class Animation; }
namespace gd { class MainFrameWrapper; }
namespace gd { class SerializerElement; }
namespace gd { class PropertyDescriptor; }
#if defined(GD_IDE_ONLY)
class wxBitmap;
class wxWindow;
#endif
namespace gd
{
/**
* \brief Standard sprite object for extensions that implements the standard SpriteExtension
* (see gd::BuiltinExtensionsImplementer::ImplementsSpriteExtension).
*
* A Sprite object is an object composed of animations, containing directions with images.
*
* \see Animation
* \see Direction
* \see Sprite
* \see gd::BuiltinExtensionsImplementer::ImplementsSpriteExtension
* \ingroup SpriteObjectExtension
*/
class GD_CORE_API SpriteObject : public gd::Object
{
public :
SpriteObject(std::string name_);
virtual ~SpriteObject();
virtual gd::Object * Clone() const { return new SpriteObject(*this);}
#if defined(GD_IDE_ONLY)
virtual bool GenerateThumbnail(const gd::Project & project, wxBitmap & thumbnail) const;
virtual void ExposeResources(gd::ArbitraryResourceWorker & worker);
virtual std::map<std::string, gd::PropertyDescriptor> GetInitialInstanceProperties(const gd::InitialInstance & position, gd::Project & project, gd::Layout & scene);
virtual bool UpdateInitialInstanceProperty(gd::InitialInstance & position, const std::string & name, const std::string & value, gd::Project & project, gd::Layout & scene);
virtual void EditObject( wxWindow* parent, gd::Project & project, gd::MainFrameWrapper & mainFrameWrapper_ );
#if !defined(EMSCRIPTEN)
virtual void DrawInitialInstance(gd::InitialInstance & instance, sf::RenderTarget & renderTarget, gd::Project & project, gd::Layout & layout);
virtual sf::Vector2f GetInitialInstanceDefaultSize(gd::InitialInstance & instance, gd::Project & project, gd::Layout & layout) const;
virtual sf::Vector2f GetInitialInstanceOrigin(gd::InitialInstance & instance, gd::Project & project, gd::Layout & layout) const;
virtual void LoadResources(gd::Project & project, gd::Layout & layout);
#endif
virtual bool SupportShaders() { return true; }
#endif
/** \name Animations
* Methods related to animations management
*/
///@{
/**
* \brief Return the animation at the specified index.
* If the index is out of bound, a "bad animation" object is returned.
*/
const Animation & GetAnimation(unsigned int nb) const;
/**
* \brief Return the animation at the specified index.
* If the index is out of bound, a "bad animation" object is returned.
*/
Animation & GetAnimation(unsigned int nb);
/**
* \brief Return the number of animations this object has.
*/
unsigned int GetAnimationsCount() const { return animations.size(); };
/**
* \brief Add an animation at the end of the existing ones.
*/
void AddAnimation(const Animation & animation);
/**
* \brief Remove an animation.
*/
bool RemoveAnimation(unsigned int nb);
/**
* \brief Remove all animations.
*/
void RemoveAllAnimations() { animations.clear(); }
/**
* \brief Return true if the object hasn't any animation.
*/
bool HasNoAnimations() const { return animations.empty(); }
/**
* \brief Swap the position of two sprites
*/
void SwapAnimations(unsigned int firstIndex, unsigned int secondIndex);
/**
* \brief Return a read-only reference to the vector containing all the animation of the object.
*/
const std::vector < Animation > & GetAllAnimations() const { return animations; }
///@}
private:
virtual void DoUnserializeFrom(gd::Project & project, const gd::SerializerElement & element);
#if defined(GD_IDE_ONLY)
virtual void DoSerializeTo(gd::SerializerElement & element) const;
#endif
const Sprite * GetInitialInstanceSprite(gd::InitialInstance & instance, gd::Project & project, gd::Layout & layout, bool * shouldNotRotate = NULL) const;
mutable std::vector < Animation > animations;
static Animation badAnimation; //< Bad animation when an out of bound animation is requested.
};
GD_CORE_API void DestroySpriteObject(gd::Object * object);
GD_CORE_API gd::Object * CreateSpriteObject(std::string name);
}
#endif // GDCORE_SPRITEOBJECT_H