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