gdk-graphics 0a0aef92e917cfbac53dffbc32c295e4de914093
Loading...
Searching...
No Matches
aseprite.h
1// © Joseph Cameron - MIT License
2
3#ifndef GDK_GRAPHICS_EXT_ASEPRITE_H
4#define GDK_GRAPHICS_EXT_ASEPRITE_H
5
6#include <gdk/graphics/ext/sprite_animation.h>
7
8#include <cstddef>
9#include <optional>
10#include <span>
11#include <string>
12#include <string_view>
13#include <vector>
14
15namespace gdk::graphics::ext {
16 struct aseprite_frame final {
17 int x = 0;
18 int y = 0;
19 int w = 0;
20 int h = 0;
21
22 int offsetX = 0;
23 int offsetY = 0;
24 int sourceWidth = 0;
25 int sourceHeight = 0;
26
27 int milliseconds = 0;
28
29 [[nodiscard]] bool operator==(const aseprite_frame &) const = default;
30 };
31
33 enum class aseprite_direction {
34 forward,
35 reverse,
36 ping_pong,
37 ping_pong_reverse
38 };
39
41 struct aseprite_tag final {
42 std::string name;
43
44 int from = 0;
45 int to = 0;
46
47 aseprite_direction direction = aseprite_direction::forward;
48
49 int repeat = 0;
50
51 std::string data;
52
53 [[nodiscard]] bool operator==(const aseprite_tag &) const = default;
54 };
55
57 struct aseprite_slice final {
58 std::string name;
59
60 int frame = 0;
61
62 int x = 0;
63 int y = 0;
64 int w = 0;
65 int h = 0;
66
67 std::optional<std::pair<int, int>> pivot;
68
69 [[nodiscard]] bool operator==(const aseprite_slice &) const = default;
70 };
71
72 struct aseprite_sheet final {
73 std::string image;
74
75 int width = 0;
76 int height = 0;
77
78 std::vector<aseprite_frame> frames;
79
80 std::vector<aseprite_tag> tags;
81
82 std::vector<aseprite_slice> slices;
83
85 [[nodiscard]] const aseprite_tag *tag(std::string_view aName) const;
86
88 [[nodiscard]] const aseprite_slice *slice(std::string_view aName) const;
89 };
90
94 constexpr std::size_t MOST_ASEPRITE_FRAMES = 65536;
95
97 [[nodiscard]] aseprite_sheet read_aseprite(std::span<const std::byte> aBytes);
98
100 [[nodiscard]] std::vector<sprite_animation::frame> frames_of(
101 const aseprite_sheet &aSheet,
102 const aseprite_tag &aTag);
103
105 [[nodiscard]] std::vector<sprite_animation::frame> frames_of(const aseprite_sheet &aSheet);
106
108 [[nodiscard]] sprite_animation animation_of(const aseprite_sheet &aSheet, std::string_view aTag);
109
111 [[nodiscard]] sprite_animation animation_of(const aseprite_sheet &aSheet);
112}
113
114#endif
non-interpolated 2d sprite animation
Definition sprite_animation.h:14
Definition aseprite.h:16
Definition aseprite.h:72
const aseprite_tag * tag(std::string_view aName) const
the tag of that name
const aseprite_slice * slice(std::string_view aName) const
the first slice of that name
a slice is a named rectangle of a frame which may carry a pivot
Definition aseprite.h:57
a tag is a run of frames with a name
Definition aseprite.h:41