1// Aseprite UI Library
2// Copyright (C) 2020-2022 Igara Studio S.A.
3// Copyright (C) 2001-2016 David Capello
4//
5// This file is released under the terms of the MIT license.
6// Read LICENSE.txt for more information.
7
8#ifndef UI_TIMER_H_INCLUDED
9#define UI_TIMER_H_INCLUDED
10#pragma once
11
12#include "base/disable_copying.h"
13#include "base/time.h"
14#include "obs/signal.h"
15
16namespace ui {
17
18 class Widget;
19
20 class Timer {
21 public:
22 Timer(int interval, Widget* owner = nullptr);
23 virtual ~Timer();
24
25 int interval() const { return m_interval; }
26 void setInterval(int interval);
27
28 bool isRunning() const {
29 return m_running;
30 }
31
32 void start();
33 void stop();
34
35 void tick();
36
37 obs::signal<void()> Tick;
38
39 static void pollTimers();
40 static bool haveTimers();
41 static bool getNextTimeout(double& timeout);
42
43 protected:
44 virtual void onTick();
45
46 private:
47 Widget* m_owner;
48 int m_interval;
49 bool m_running;
50 base::tick_t m_lastTick;
51
52 DISABLE_COPYING(Timer);
53 };
54
55} // namespace ui
56
57#endif
58