1.11
sprite.h
1/*
2 * Copyright (C) 2018 Microchip Technology Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef EGT_SPRITE_H
7#define EGT_SPRITE_H
8
14#include <egt/detail/meta.h>
15#include <egt/window.h>
16#include <memory>
17
18namespace egt
19{
20inline namespace v1
21{
22class Painter;
23class Image;
24
25namespace detail
26{
27class SpriteImpl;
28class SoftwareSprite;
29class HardwareSprite;
30}
31
60class EGT_API Sprite : public Window
61{
62public:
63
69 explicit Sprite(WindowHint hint = WindowHint::automatic);
70
81 Sprite(const Image& image, const Size& frame_size,
82 int frame_count, const Point& frame_point = {},
83 WindowHint hint = WindowHint::automatic);
84
88 explicit Sprite(Serializer::Properties& props) noexcept
89 : Sprite(props, false)
90 {
91 }
92
93protected:
94
95 explicit Sprite(Serializer::Properties& props, bool is_derived) noexcept;
96
97public:
98
99 Sprite(const Sprite&) = delete;
100 Sprite& operator=(const Sprite&) = delete;
101 Sprite(Sprite&&) noexcept;
102 Sprite& operator=(Sprite&&) noexcept;
103
104 void draw(Painter& painter, const Rect& rect) override;
105
115 void init(const Image& image, const Size& frame_size,
116 int frame_count, const Point& frame_point = {});
117
121 void show_frame(int index);
122
126 void advance();
127
131 EGT_NODISCARD bool is_last_frame() const;
132
136 EGT_NODISCARD uint32_t frame_count() const;
137
141 void change_strip(uint32_t id);
142
150 uint32_t add_strip(int frame_count, const Point& frame_point = {});
151
152 ~Sprite() noexcept override;
153
154protected:
155
157 void allocate_screen() override
158 {
159 Window::allocate_screen();
160 }
161
163 void create_impl(const Image& image, const Size& frame_size,
164 int frame_count, const Point& frame_point);
165
167 std::unique_ptr<detail::SpriteImpl> m_simpl;
168
169 friend class detail::SoftwareSprite;
170 friend class detail::HardwareSprite;
171};
172
173}
174}
175
176#endif
Raster image resource used for drawing or displaying.
Definition image.h:38
Drawing interface for 2D graphics.
Definition painter.h:54
std::list< std::tuple< std::string, std::string, Serializer::Attributes > > Properties
Definition serialize.h:47
Widget that shows or animates sprite, or frame, strips from a single sprite sheet.
Definition sprite.h:61
uint32_t add_strip(int frame_count, const Point &frame_point={})
Add a new strip.
~Sprite() noexcept override
Sprite(const Sprite &)=delete
Sprite(const Image &image, const Size &frame_size, int frame_count, const Point &frame_point={}, WindowHint hint=WindowHint::automatic)
void show_frame(int index)
Show the frame specified by the index.
void change_strip(uint32_t id)
Change the strip to the specified id.
void advance()
Advance to the next frame in the strip.
Sprite & operator=(const Sprite &)=delete
Sprite(Serializer::Properties &props, bool is_derived) noexcept
EGT_NODISCARD bool is_last_frame() const
Returns true if the current frame is the last frame.
void create_impl(const Image &image, const Size &frame_size, int frame_count, const Point &frame_point)
Create the internal implementation.
Sprite(WindowHint hint=WindowHint::automatic)
Sprite(Serializer::Properties &props) noexcept
Definition sprite.h:88
EGT_NODISCARD uint32_t frame_count() const
Returns the number of frames in the current strip.
Sprite(Sprite &&) noexcept
A Window is a Widget that handles drawing to a Screen.
Definition window.h:47
WindowHint
Hint used for configuring Window backends.
Definition widgetflags.h:710
EGT framework namespace.
Definition animation.h:24