1 | // Aseprite |
2 | // Copyright (C) 2001-2016 David Capello |
3 | // |
4 | // This program is distributed under the terms of |
5 | // the End-User License Agreement for Aseprite. |
6 | |
7 | #ifndef APP_UI_MARCHING_ANTS_H_INCLUDED |
8 | #define APP_UI_MARCHING_ANTS_H_INCLUDED |
9 | #pragma once |
10 | |
11 | #include "obs/connection.h" |
12 | #include "ui/timer.h" |
13 | |
14 | #include <cmath> |
15 | |
16 | namespace app { |
17 | |
18 | class MarchingAnts { |
19 | public: |
20 | MarchingAnts() |
21 | : m_timer(100) |
22 | , m_offset(0) |
23 | { |
24 | m_scopedConn = m_timer.Tick.connect(&MarchingAnts::onTick, this); |
25 | } |
26 | |
27 | ~MarchingAnts() { |
28 | m_timer.stop(); |
29 | } |
30 | |
31 | protected: |
32 | virtual void onDrawMarchingAnts() = 0; |
33 | |
34 | int getMarchingAntsOffset() const { |
35 | return m_offset; |
36 | } |
37 | |
38 | bool isMarchingAntsRunning() const { |
39 | return m_timer.isRunning(); |
40 | } |
41 | |
42 | void startMarchingAnts() { |
43 | m_timer.start(); |
44 | } |
45 | |
46 | void stopMarchingAnts() { |
47 | m_timer.stop(); |
48 | } |
49 | |
50 | private: |
51 | void onTick() { |
52 | m_offset = ((m_offset+1) % 8); |
53 | onDrawMarchingAnts(); |
54 | } |
55 | |
56 | ui::Timer m_timer; |
57 | int m_offset; |
58 | obs::scoped_connection m_scopedConn; |
59 | }; |
60 | |
61 | } // namespace app |
62 | |
63 | #endif |
64 | |