1.10
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
106 void paint(Painter& painter) override;
107
117 void init(const Image& image, const Size& frame_size,
118 int frame_count, const Point& frame_point = {});
119
123 void show_frame(int index);
124
131 EGT_NODISCARD shared_cairo_surface_t surface() const;
132
136 void advance();
137
141 EGT_NODISCARD bool is_last_frame() const;
142
146 EGT_NODISCARD uint32_t frame_count() const;
147
151 void change_strip(uint32_t id);
152
160 uint32_t add_strip(int frame_count, const Point& frame_point = {});
161
162 ~Sprite() noexcept override;
163
164protected:
165
167 void allocate_screen() override
168 {
169 Window::allocate_screen();
170 }
171
173 void create_impl(const Image& image, const Size& frame_size,
174 int frame_count, const Point& frame_point);
175
177 std::unique_ptr<detail::SpriteImpl> m_simpl;
178
179 friend class detail::SoftwareSprite;
180 friend class detail::HardwareSprite;
181};
182
183}
184}
185
186#endif
Raster image resource used for drawing or displaying.
Definition image.h:39
Drawing interface for 2D graphics.
Definition painter.h:45
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.
EGT_NODISCARD shared_cairo_surface_t surface() const
Get a surface for the current 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
std::shared_ptr< cairo_surface_t > shared_cairo_surface_t
Shared pointer for a cairo surface.
Definition types.h:29
WindowHint
Hint used for configuring Window backends.
Definition widgetflags.h:683
EGT framework namespace.
Definition animation.h:24