]>
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"
20 #include "wx/object.h"
21 #include "wx/longlong.h"
23 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
27 // the interface of wxTimer class
28 class WXDLLEXPORT wxTimerBase
: public wxObject
31 wxTimerBase() { m_oneShot
= FALSE
; m_milli
= 0; }
33 // working with the timer
34 // ----------------------
36 // start the timer: if milliseconds == -1, use the same value as for the
38 virtual bool Start(int milliseconds
= -1, bool oneShot
= FALSE
)
40 if ( milliseconds
!= -1 )
42 m_milli
= milliseconds
;
52 virtual void Stop() = 0;
54 // override this in your wxTimer-derived class
55 virtual void Notify() = 0;
60 // return TRUE if the timer is running
61 virtual bool IsRunning() const = 0;
63 // get the (last) timer interval in the milliseconds
64 int GetInterval() const { return m_milli
; }
66 // return TRUE if the timer is one shot
67 bool IsOneShot() const { return m_oneShot
; }
69 #if WXWIN_COMPATIBILITY_2
70 // deprecated functions
71 int Interval() const { return GetInterval(); };
72 bool OneShot() const { return IsOneShot(); }
73 #endif // WXWIN_COMPATIBILITY_2
76 int m_milli
; // the timer interval
77 bool m_oneShot
; // TRUE if one shot
80 #if defined(__WXMSW__)
81 #include "wx/msw/timer.h"
82 #elif defined(__WXMOTIF__)
83 #include "wx/motif/timer.h"
84 #elif defined(__WXGTK__)
85 #include "wx/gtk/timer.h"
86 #elif defined(__WXQT__)
87 #include "wx/qt/timer.h"
88 #elif defined(__WXMAC__)
89 #include "wx/mac/timer.h"
90 #elif defined(__WXPM__)
91 #include "wx/os2/timer.h"
92 #elif defined(__WXSTUBS__)
93 #include "wx/stubs/timer.h"
96 // ----------------------------------------------------------------------------
98 // ----------------------------------------------------------------------------
100 class WXDLLEXPORT wxStopWatch
103 // ctor starts the stop watch
104 wxStopWatch() { Start(); }
105 void Start(long t
= 0);
106 inline void Pause() { m_pause
= GetElapsedTime(); }
107 inline void Resume() { Start(m_pause
); }
109 // get elapsed time since the last Start() or Pause() in milliseconds
113 // returns the elapsed time since t0
114 long GetElapsedTime() const;
117 wxLongLong m_t0
; // the time of the last Start()
118 long m_pause
; // the time of the last Pause() or 0
122 // Starts a global timer
123 // -- DEPRECATED: use wxStopWatch instead
124 void WXDLLEXPORT
wxStartTimer();
126 // Gets elapsed milliseconds since last wxStartTimer or wxGetElapsedTime
127 // -- DEPRECATED: use wxStopWatch instead
128 long WXDLLEXPORT
wxGetElapsedTime(bool resetTimer
= TRUE
);
131 // ----------------------------------------------------------------------------
132 // global time functions
133 // ----------------------------------------------------------------------------
135 // Get number of seconds since local time 00:00:00 Jan 1st 1970.
136 long WXDLLEXPORT
wxGetLocalTime();
138 // Get number of seconds since GMT 00:00:00, Jan 1st 1970.
139 long WXDLLEXPORT
wxGetUTCTime();
141 #define wxGetCurrentTime() wxGetLocalTime()