]> git.saurik.com Git - wxWidgets.git/blob - include/wx/stopwatch.h
wxBitmapButton doesn't need own DoGetBestSize, wxControl's one works (fixes sizing...
[wxWidgets.git] / include / wx / stopwatch.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/stopwatch.h
3 // Purpose: wxStopWatch and global time-related functions
4 // Author: Julian Smart (wxTimer), Sylvain Bougnoux (wxStopWatch)
5 // Created: 26.06.03 (extracted from wx/timer.h)
6 // RCS-ID: $Id$
7 // Copyright: (c) 1998-2003 wxWidgets team
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_STOPWATCH_H_
12 #define _WX_STOPWATCH_H_
13
14 #include "wx/longlong.h"
15
16 // ----------------------------------------------------------------------------
17 // wxStopWatch: measure time intervals with up to 1ms resolution
18 // ----------------------------------------------------------------------------
19
20 #if wxUSE_STOPWATCH
21
22 class WXDLLIMPEXP_BASE wxStopWatch
23 {
24 public:
25 // ctor starts the stop watch
26 wxStopWatch() { m_pauseCount = 0; Start(); }
27
28 // start the stop watch at the moment t0
29 void Start(long t0 = 0);
30
31 // pause the stop watch
32 void Pause()
33 {
34 if ( !m_pauseCount++ )
35 m_pause = GetElapsedTime();
36 }
37
38 // resume it
39 void Resume()
40 {
41 wxASSERT_MSG( m_pauseCount > 0,
42 _T("Resuming stop watch which is not paused") );
43
44 if ( !--m_pauseCount )
45 Start(m_pause);
46 }
47
48 // get elapsed time since the last Start() in milliseconds
49 long Time() const;
50
51 protected:
52 // returns the elapsed time since t0
53 long GetElapsedTime() const;
54
55 private:
56 // the time of the last Start()
57 wxLongLong m_t0;
58
59 // the time of the last Pause() (only valid if m_pauseCount > 0)
60 long m_pause;
61
62 // if > 0, the stop watch is paused, otherwise it is running
63 int m_pauseCount;
64 };
65
66 #endif // wxUSE_STOPWATCH
67
68 #if wxUSE_LONGLONG
69
70 // Starts a global timer
71 // -- DEPRECATED: use wxStopWatch instead
72 void WXDLLIMPEXP_BASE wxStartTimer();
73
74 // Gets elapsed milliseconds since last wxStartTimer or wxGetElapsedTime
75 // -- DEPRECATED: use wxStopWatch instead
76 long WXDLLIMPEXP_BASE wxGetElapsedTime(bool resetTimer = true);
77
78 #endif // wxUSE_LONGLONG
79
80 // ----------------------------------------------------------------------------
81 // global time functions
82 // ----------------------------------------------------------------------------
83
84 // Get number of seconds since local time 00:00:00 Jan 1st 1970.
85 extern long WXDLLIMPEXP_BASE wxGetLocalTime();
86
87 // Get number of seconds since GMT 00:00:00, Jan 1st 1970.
88 extern long WXDLLIMPEXP_BASE wxGetUTCTime();
89
90 #if wxUSE_LONGLONG
91 // Get number of milliseconds since local time 00:00:00 Jan 1st 1970
92 extern wxLongLong WXDLLIMPEXP_BASE wxGetLocalTimeMillis();
93 #endif // wxUSE_LONGLONG
94
95 #define wxGetCurrentTime() wxGetLocalTime()
96
97 #endif // _WX_STOPWATCH_H_
98