aboutsummaryrefslogtreecommitdiff
path: root/src/ui/animated_image.h
blob: 4987d30d4c3297bcfb55cc9d43d1ba624dbfedaa (plain)
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
#pragma once

#include <cstddef>
#include <filesystem>
#include <vector>

namespace Hsdbg
{
    class AnimatedImage
    {
    public:
        AnimatedImage() = default;
        ~AnimatedImage();

        AnimatedImage(const AnimatedImage&) = delete;
        AnimatedImage(AnimatedImage&&) = delete;
        auto operator=(const AnimatedImage&) -> AnimatedImage& = delete;
        auto operator=(AnimatedImage&&) -> AnimatedImage& = delete;

        auto load(const std::filesystem::path& path) -> bool;
        auto unload() -> void;

        auto advance(float delta_seconds) -> void;

        auto valid() const -> bool { return !m_frames.empty(); }

        auto texture() const -> unsigned int;
        auto width() const -> float { return static_cast<float>(m_width); }
        auto height() const -> float { return static_cast<float>(m_height); }

    private:
        std::vector<unsigned int> m_frames;
        std::vector<float> m_delays;
        int m_width = 0;
        int m_height = 0;
        std::size_t m_current = 0;
        float m_accumulator = 0.0f;
    };
}