1// Aseprite
2// Copyright (C) 2017-2018 David Capello
3//
4// This program is distributed under the terms of
5// the End-User License Agreement for Aseprite.
6
7#ifndef APP_SPRITE_JOB_H_INCLUDED
8#define APP_SPRITE_JOB_H_INCLUDED
9#pragma once
10
11#include "app/context.h"
12#include "app/context_access.h"
13#include "app/job.h"
14#include "app/tx.h"
15#include "render/task_delegate.h"
16
17#include <functional>
18
19namespace app {
20
21class SpriteJob : public Job,
22 public render::TaskDelegate {
23public:
24 SpriteJob(const ContextReader& reader, const char* jobName);
25 ~SpriteJob();
26
27 ContextWriter& writer() { return m_writer; }
28 Doc* document() const { return m_document; }
29 Sprite* sprite() const { return m_sprite; }
30 Tx& tx() { return m_tx; }
31
32 template<typename T>
33 void startJobWithCallback(T&& callback) {
34 m_callback = std::move(callback);
35 Job::startJob();
36 }
37
38private:
39 // Job impl
40 void onJob() override;
41
42 // render::TaskDelegate impl just in case you need to use this
43 // Job as a delegate in render::create_palette_from_sprite()
44 bool continueTask() override;
45 void notifyTaskProgress(double progress) override;
46
47 ContextWriter m_writer;
48 Doc* m_document;
49 Sprite* m_sprite;
50 Tx m_tx;
51
52 // Default implementation calls the given function in
53 // startJob(). Anyway you can just extended the SpriteJob and
54 // override onJob().
55 std::function<void()> m_callback;
56};
57
58} // namespace app
59
60#endif // APP_SPRITE_JOB_H_INCLUDED
61