33#include "../../Core/Math/origin.h"
34#include "../../Core/Signals/signal.h"
35#include "../../Core/IOData/file_system.h"
36#include "../../Core/Resources/resource.h"
37#include "../Render/graphic_context.h"
38#include "../Image/image_import_description.h"
48 class ResourceManager;
51 class XMLResourceDocument;
104 explicit operator bool()
const {
return bool(impl); }
193 return impl == other.impl;
199 return impl != other.impl;
205 return impl < other.impl;
383 int width,
int height,
384 int xarray = 1,
int yarray = 1,
385 int array_skipframes = 0,
386 int xspacing = 0,
int yspacing = 0);
400 int xpos = 0,
int ypos = 0,
401 float trans_limit = 0.05f);
414 int xpos = 0,
int ypos = 0,
415 float trans_limit = 0.05f);
423 std::shared_ptr<Sprite_Impl> impl;
Angle class.
Definition: angle.h:60
2D Graphics Canvas
Definition: canvas.h:72
Color description class.
Definition: color.h:46
Floating point color description class (for float).
Definition: color.h:799
Virtual File System (VFS).
Definition: file_system.h:47
I/O Device interface.
Definition: iodevice.h:50
Image Import Description Class.
Definition: image_import_description.h:48
2D (x,y) point structure - Integer
Definition: point.h:62
2D (left,top,right,bottom) rectangle structure - Integer
Definition: rect.h:489
2D (left,top,right,bottom) rectangle structure - Float
Definition: rect.h:503
Resource manager.
Definition: resource_manager.h:44
Resource proxy of a specific type.
Definition: resource.h:58
2D (width,height) size structure - Integer
Definition: size.h:171
Sprite class.
Definition: sprite.h:55
void set_base_angle(Angle angle)
Sets the base angle in degrees - angle added to any rotation set with set_rotate() or rotate().
bool get_linear_filter() const
Returns true if the sprite uses a linear filter for scaling up and down, false if a nearest-point fil...
bool is_play_backward() const
Returns true if animation is played in from right to left (starts at end).
void update(int time_elapsed_ms)
Call this function to update the animation.
Sprite(Canvas &canvas)
Constructs an empty Sprite.
static Sprite load(Canvas &canvas, const std::string &id, const XMLResourceDocument &doc)
Loads a Sprite from a XML resource definition.
void set_scale(float x, float y)
Set scale for x and y directions individually.
void set_angle_yaw(Angle angle)
Set absolute rotation yaw angle.
void set_color(const Colorf &color)
Sets the color.
bool is_play_loop() const
Returns true if animation is played in loop (more than once).
void add_frame(Canvas &canvas, const std::string &fullname, const ImageImportDescription &import_desc=ImageImportDescription())
Add frame.
Sprite(Canvas &canvas, IODevice &file, const std::string &image_type, const ImageImportDescription &import_desc=ImageImportDescription())
Constructs a Sprite.
int get_current_frame() const
Returns current frame in animation. 0 is first frame.
void rotate(Angle angle)
Add angle in degrees to current angle.
void draw(Canvas &canvas, int x, int y)
void add_frame(const Texture2D &texture, const Rect &frame)
Add frame.
void draw(Canvas &canvas, const Rectf &src, const Rectf &dest)
void set_color(const Color &c)
Set color.
Definition: sprite.h:284
void set_play_pingpong(bool pingpong=true)
Set to true if animation should loop, false otherwise.
void set_rotation_hotspot(Origin origin, int x=0, int y=0)
Sets rotation hotspot.
Angle get_angle() const
Returns current angle in degrees.
bool is_finished() const
Returns true if animation is finished.
Subtexture get_frame_texture(int frame) const
Return the texture of a frame. 0 is first frame.
int get_frame_count() const
Returns number of frames in animation.
void rotate_pitch(Angle angle)
Add angle in degrees to current pitch angle.
void set_alpha(float alpha)
Sets transparency.
Sprite()
Constructs a null instance.
void draw(Canvas &canvas, float x, float y)
Draw sprite on graphic context.
Sprite(Canvas &canvas, const std::string &filename, const FileSystem &file_system, const ImageImportDescription &import_desc=ImageImportDescription())
Constructs a Sprite.
int get_id() const
Returns the attached id (if exists).
ShowOnFinish get_show_on_finish() const
Returns an enum for what is shown when the animation is finished.
void set_frame_delay(int frame, int delay_ms)
Sets the delay of a specific frame.
void add_frame(Canvas &canvas, IODevice &file, const std::string &image_type, const ImageImportDescription &import_desc=ImageImportDescription())
Add frame.
void set_play_loop(bool loop=true)
Set to true if animation should loop, false otherwise.
void add_frame(Canvas &canvas, const std::string &filename, const FileSystem &file_system, const ImageImportDescription &import_desc=ImageImportDescription())
Add frame.
int get_height() const
Return the height of the current frame, shortcut for 'get_frame_size(get_current_frame())....
void add_alphaclipped_frames_free(Canvas &canvas, const Texture2D &texture, int xpos=0, int ypos=0, float trans_limit=0.05f)
Adds images separated with pure alpha (within trans_limit).
void add_gridclipped_frames(Canvas &canvas, const Texture2D &texture, int xpos, int ypos, int width, int height, int xarray=1, int yarray=1, int array_skipframes=0, int xspacing=0, int yspacing=0)
Adds images formed in a grid.
Size get_frame_size(int frame) const
Returns the size of a frame. 0 is first frame.
float get_alpha() const
Returns current alpha.
Signal< void()> & sig_animation_finished()
Sig animation finished.
void throw_if_null() const
Throw an exception if this object is invalid.
void get_scale(float &x, float &y) const
Returns scale for x and y.
void set_frame(unsigned int frame)
Sets current animation frame. 0 is first frame.
static Resource< Sprite > resource(Canvas &canvas, const std::string &id, const ResourceManager &resources)
Retrieves a Sprite resource from the resource manager.
void set_frame_offset(int frame, Point offset)
Sets the translate offset of a specific frame. 0 is first frame.
void set_image_data(const Sprite &image_source)
Sets the image data from another sprite, sharing animation state.
void add_alphaclipped_frames(Canvas &canvas, const Texture2D &texture, int xpos=0, int ypos=0, float trans_limit=0.05f)
Adds images separated with pure alpha (within trans_limit).
void set_show_on_finish(Sprite::ShowOnFinish show_on_finish)
Set what is shown when the animation is finished.
Sprite(Canvas &canvas, const std::string &fullname, const ImageImportDescription &import_desc=ImageImportDescription())
Constructs a Sprite.
bool operator==(const Sprite &other) const
Equality operator.
Definition: sprite.h:191
void set_angle(Angle angle)
Set absolute rotation angle.
int get_frame_delay(int frame) const
Returns the delay of a frame.
ShowOnFinish
Definition: sprite.h:58
@ show_first_frame
Definition: sprite.h:59
@ show_blank
Definition: sprite.h:59
@ show_last_frame
Definition: sprite.h:59
void draw(Canvas &canvas, const Rectf &dest)
void set_alignment(Origin origin, int x=0, int y=0)
Sets translation hotspot.
Point get_frame_offset(int frame) const
Returns the translation offset of a frame. 0 is first frame.
void finish()
Finish animation.
friend class FontFamily_Impl
Definition: sprite.h:425
void set_delay(int delay_ms)
Sets the delay for all frames.
void add_frame(const Texture2D &texture)
Add frame.
bool operator<(const Sprite &other) const
Less than operator.
Definition: sprite.h:203
bool is_null() const
Returns true if this object is invalid.
Definition: sprite.h:103
void set_id(int id)
Sets an attached id.
Colorf get_color() const
Returns current color.
Sprite clone() const
Copies all information from this sprite to another, excluding the graphics that remain shared.
bool is_play_pingpong() const
Returns true if animation is played in ping-pong mode.
void add_frames(const Texture2D &texture, Rect *frames, int num_frames)
Add frames.
bool is_looping() const
Returns true if animation has looped in the last update cycle.
Angle get_base_angle() const
Returns the base angle in degrees - angle added to any rotation set with set_rotate() or rotate().
bool operator!=(const Sprite &other) const
Inequality operator.
Definition: sprite.h:197
void set_linear_filter(bool linear_filter=true)
Set to true if a linear filter should be used for scaling up and down, false if a nearest-point filte...
void get_alignment(Origin &origin, int &x, int &y) const
Returns translation hot-spot.
void set_angle_pitch(Angle angle)
Set absolute rotation pitch angle.
void get_rotation_hotspot(Origin &origin, int &x, int &y) const
Returns rotation hot-spot.
void set_play_backward(bool backward=true)
Set to true if animation should go backward (start at end).
int get_width() const
Return the width of the current frame, shortcut for 'get_frame_size(get_current_frame())....
void restart()
Restart animation.
Sprite & operator=(const Sprite ©)
Copy assignment operator.
Size get_size() const
Return the size of the current frame, shortcut for 'get_frame_size(get_current_frame())'.
void rotate_yaw(Angle angle)
Add angle in degrees to current yaw angle.
Sub-texture description.
Definition: subtexture.h:45
2D texture object class.
Definition: texture_2d.h:41
XML Resource Document.
Definition: xml_resource_document.h:48
Origin
Alignment origins.
Definition: origin.h:39