aboutsummaryrefslogtreecommitdiff
path: root/src/animationloader.h
blob: a3a103670631599455202b6f89b85669a985fcff (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#pragma once

#include <QFuture>
#include <QImageReader>
#include <QMutex>
#include <QObject>
#include <QPixmap>
#include <QString>
#include <QWaitCondition>

#include <atomic>

namespace kal
{
class AnimationFrame
{
public:
  QPixmap texture;
  int duration = 0;
};

class AnimationLoader
{
  Q_DISABLE_COPY_MOVE(AnimationLoader)

public:
  explicit AnimationLoader(QThreadPool *threadPool);
  virtual ~AnimationLoader();

  QString loadedFileName() const;
  void load(const QString &fileName);
  void stopLoading();

  QSize size();

  int frameCount();
  AnimationFrame frame(int frameNumber);

  int loopCount();

private:
  QThreadPool *m_thread_pool;
  QString m_file_name;
  QSize m_size;
  int m_frame_count = 0;
  int m_loop_count = -1;
  QList<AnimationFrame> m_frames;
  QFuture<void> m_task;
  std::atomic_bool m_exit_task = false;
  QMutex m_task_lock;
  QWaitCondition m_task_signal;

  void populateVector(QImageReader *reader);
};
} // namespace kal