]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/timer.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTimer class and global time-related functions
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_TIMER_H_BASE_
13 #define _WX_TIMER_H_BASE_
16 #pragma interface "timerbase.h"
19 #include "wx/object.h"
21 // ----------------------------------------------------------------------------
23 // ----------------------------------------------------------------------------
25 // the interface of wxTimer class
26 class WXDLLEXPORT wxTimerBase
: public wxObject
29 wxTimerBase() { m_oneShot
= FALSE
; m_milli
= 0; }
31 // working with the timer
32 // ----------------------
34 // start the timer: if milliseconds == -1, use the same value as for the
36 virtual bool Start(int milliseconds
= -1, bool oneShot
= FALSE
)
38 if ( milliseconds
!= -1 )
40 m_milli
= milliseconds
;
50 virtual void Stop() = 0;
52 // override this in your wxTimer-derived class
53 virtual void Notify() = 0;
58 // return TRUE if the timer is running
59 virtual bool IsRunning() const = 0;
61 // get the (last) timer interval in the milliseconds
62 int GetInterval() const { return m_milli
; }
64 // return TRUE if the timer is one shot
65 bool IsOneShot() const { return m_oneShot
; }
67 #if WXWIN_COMPATIBILITY_2
68 // deprecated functions
69 int Interval() const { return GetInterval(); };
70 bool OneShot() const { return IsOneShot(); }
71 #endif // WXWIN_COMPATIBILITY_2
74 int m_milli
; // the timer interval
75 bool m_oneShot
; // TRUE if one shot
78 #if defined(__WXMSW__)
79 #include "wx/msw/timer.h"
80 #elif defined(__WXMOTIF__)
81 #include "wx/motif/timer.h"
82 #elif defined(__WXGTK__)
83 #include "wx/gtk/timer.h"
84 #elif defined(__WXQT__)
85 #include "wx/qt/timer.h"
86 #elif defined(__WXMAC__)
87 #include "wx/mac/timer.h"
88 #elif defined(__WXPM__)
89 #include "wx/os2/timer.h"
90 #elif defined(__WXSTUBS__)
91 #include "wx/stubs/timer.h"
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
98 class WXDLLEXPORT wxStopWatch
101 // ctor starts the stop watch
102 wxStopWatch() { Start(); }
104 void Start(long t
= 0); // (re)start it t milliseconds ago
106 void Resume() { Start(m_pause
); }
108 // get the elapsed time since the last Start() or Pause() in milliseconds
112 // returns the elapsed time since t0
113 inline long GetElapsedTime() const;
116 long m_t0
; // the time of the last Start()
117 long m_pause
; // the time of the last Pause() or 0
121 #ifdef WXWIN_COMPATIBILITY_2
122 typedef wxStopWatch wxChrono
;
123 #endif // WXWIN_COMPATIBILITY_2
125 // ----------------------------------------------------------------------------
126 // global time functions
127 // ----------------------------------------------------------------------------
129 // Timer functions (milliseconds) -- use wxStopWatch instead
130 void WXDLLEXPORT
wxStartTimer();
132 // Gets time since last wxStartTimer or wxGetElapsedTime -- use wxStopWatch
134 long WXDLLEXPORT
wxGetElapsedTime(bool resetTimer
= TRUE
);
136 // Get the local time
137 bool WXDLLEXPORT
wxGetLocalTime(long *timeZone
, int *dstObserved
);
139 // Get number of seconds since 00:00:00 GMT, Jan 1st 1970.
140 long WXDLLEXPORT
wxGetCurrentTime();
142 // Get number of milliseconds since 00:00:00 GMT, Jan 1st 1970.
143 long WXDLLEXPORT
wxGetCurrentMTime();
145 // ----------------------------------------------------------------------------
147 // ----------------------------------------------------------------------------
149 inline long wxStopWatch::GetElapsedTime() const
151 return wxGetCurrentMTime() - m_t0
;
154 inline void wxStopWatch::Pause()
156 m_pause
= GetElapsedTime();