6ddf5d3e87f011b9f51c941b591ae4e9f44c8881
[sdk] / ecere / src / gui / Timer.ec
1 namespace gui;
2
3 import "Window"
4
5 public class Timer
6 {
7 public:
8    property void * userData { set { window = value; } get { return window; } };
9    property Seconds delay { set { delay = value; } get { return delay; } };
10    property bool started { set { if(value) Start(); else Stop(); } get { return started; } };
11
12    ~Timer()
13    {
14       Stop();
15    }
16
17    void Start()
18    {
19       if(!started)
20       {
21          incref this;
22          guiApp.windowTimers.Add(this);
23          lastTime = GetTime();
24          started = true;
25       }
26    }
27
28    void Stop()
29    {
30       if(started)
31       {
32          started = false;
33          guiApp.windowTimers.Remove(this);
34          delete this;
35       }
36    }
37    virtual bool any_object::DelayExpired(void);
38
39 private:
40    Timer prev, next;
41    Seconds delay;
42    Time lastTime;
43    Window window;
44    bool dispatched;
45    bool started;
46 };