Merge lp:~unity-team/nux/nux-timer-backend-fixes into lp:nux
- nux-timer-backend-fixes
- Merge into trunk
Proposed by
Jay Taoko
Status: | Merged |
---|---|
Approved by: | Jay Taoko |
Approved revision: | 634 |
Merged at revision: | 634 |
Proposed branch: | lp:~unity-team/nux/nux-timer-backend-fixes |
Merge into: | lp:nux |
Diff against target: |
1273 lines (+324/-208) 15 files modified
Nux/AnimatedTextureArea.cpp (+3/-3) Nux/ColorPreview.cpp (+3/-3) Nux/EditTextBox.cpp (+7/-7) Nux/HScrollBar.cpp (+13/-13) Nux/MainLoopGLib.cpp (+1/-1) Nux/NumericValuator.cpp (+2/-2) Nux/ProgramFramework/ProgramTemplate.cpp (+2/-2) Nux/SpinBox.cpp (+4/-4) Nux/SpinBoxDouble.cpp (+4/-4) Nux/SpinBox_Logic.cpp (+2/-2) Nux/TabView.cpp (+4/-4) Nux/TimerProc.cpp (+212/-127) Nux/TimerProc.h (+51/-20) Nux/VScrollBar.cpp (+13/-13) Nux/WindowThread.cpp (+3/-3) |
To merge this branch: | bzr merge lp:~unity-team/nux/nux-timer-backend-fixes |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jay Taoko (community) | Approve | ||
Review via email: mp+114642@code.launchpad.net |
Commit message
* Refactoring Nux timer API: Some cleanup and update were required for the animation framework.
Description of the change
* Refactoring Nux timer API: Some cleanup and update were required for the animation framework.
To post a comment you must log in.
Revision history for this message
Jay Taoko (jaytaoko) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'Nux/AnimatedTextureArea.cpp' |
2 | --- Nux/AnimatedTextureArea.cpp 2012-06-26 13:59:18 +0000 |
3 | +++ Nux/AnimatedTextureArea.cpp 2012-07-12 13:45:35 +0000 |
4 | @@ -37,7 +37,7 @@ |
5 | mouse_drag.connect(sigc::mem_fun(this, &AnimatedTextureArea::RecvMouseDrag)); |
6 | |
7 | m_TimerFunctor = new TimerFunctor(); |
8 | - m_TimerFunctor->time_expires.connect(sigc::mem_fun(this, &AnimatedTextureArea::TimerNextFrame)); |
9 | + m_TimerFunctor->tick.connect(sigc::mem_fun(this, &AnimatedTextureArea::TimerNextFrame)); |
10 | } |
11 | |
12 | AnimatedTextureArea::~AnimatedTextureArea() |
13 | @@ -106,7 +106,7 @@ |
14 | m_TimerHandler = 0; |
15 | } |
16 | |
17 | - m_TimerHandler = GetTimer().AddTimerHandler(41, m_TimerFunctor, 0); |
18 | + m_TimerHandler = GetTimer().AddOneShotTimer(41, m_TimerFunctor, 0); |
19 | QueueDraw(); |
20 | } |
21 | |
22 | @@ -128,7 +128,7 @@ |
23 | ObjectPtr<IOpenGLBaseTexture> Texture2D = Texture->m_Texture; //Texture->m_Texture.CastRef<IOpenGLAnimatedTexture>(); |
24 | |
25 | AnimatedTexture->PresentNextFrame(); |
26 | - m_TimerHandler = GetTimer().AddTimerHandler(41, m_TimerFunctor, 0); |
27 | + m_TimerHandler = GetTimer().AddOneShotTimer(41, m_TimerFunctor, 0); |
28 | } |
29 | |
30 | QueueDraw(); |
31 | |
32 | === modified file 'Nux/ColorPreview.cpp' |
33 | --- Nux/ColorPreview.cpp 2011-10-17 20:57:35 +0000 |
34 | +++ Nux/ColorPreview.cpp 2012-07-12 13:45:35 +0000 |
35 | @@ -61,7 +61,7 @@ |
36 | SetCompositionLayout(m_hlayout); |
37 | |
38 | m_ChangeDetectionTimer = new TimerFunctor(); |
39 | - m_ChangeDetectionTimer->time_expires.connect(sigc::mem_fun(this, &ColorPreview::RecvTimer)); |
40 | + m_ChangeDetectionTimer->tick.connect(sigc::mem_fun(this, &ColorPreview::RecvTimer)); |
41 | m_ChangeTimerHandler = 0; |
42 | } |
43 | |
44 | @@ -100,7 +100,7 @@ |
45 | m_DialogThreadProxy->SetColor(m_Color); |
46 | m_DialogThreadProxy->Start(); |
47 | |
48 | - m_ChangeTimerHandler = GetTimer().AddTimerHandler(33, m_ChangeDetectionTimer, this); |
49 | + m_ChangeTimerHandler = GetTimer().AddOneShotTimer(33, m_ChangeDetectionTimer, this); |
50 | } |
51 | |
52 | void ColorPreview::RecvTimer(void *v) |
53 | @@ -114,7 +114,7 @@ |
54 | |
55 | if (m_DialogThreadProxy->IsActive()) |
56 | { |
57 | - m_ChangeTimerHandler = GetTimer().AddTimerHandler(33, m_ChangeDetectionTimer, this); |
58 | + m_ChangeTimerHandler = GetTimer().AddOneShotTimer(33, m_ChangeDetectionTimer, this); |
59 | } |
60 | else |
61 | { |
62 | |
63 | === modified file 'Nux/EditTextBox.cpp' |
64 | --- Nux/EditTextBox.cpp 2011-12-14 02:01:43 +0000 |
65 | +++ Nux/EditTextBox.cpp 2012-07-12 13:45:35 +0000 |
66 | @@ -70,10 +70,10 @@ |
67 | SetLayout(hlayout); |
68 | |
69 | m_BlinkTimerFunctor = new TimerFunctor(); |
70 | - m_BlinkTimerFunctor->time_expires.connect(sigc::mem_fun(this, &EditTextBox::BlinkCursorTimerInterrupt)); |
71 | + m_BlinkTimerFunctor->tick.connect(sigc::mem_fun(this, &EditTextBox::BlinkCursorTimerInterrupt)); |
72 | |
73 | m_ScrollTimerFunctor = new TimerFunctor(); |
74 | - m_ScrollTimerFunctor->time_expires.connect(sigc::mem_fun(this, &EditTextBox::ScrollTimerInterrupt)); |
75 | + m_ScrollTimerFunctor->tick.connect(sigc::mem_fun(this, &EditTextBox::ScrollTimerInterrupt)); |
76 | |
77 | SetAcceptKeyboardEvent(true); |
78 | EnableDoubleClick(true); |
79 | @@ -102,7 +102,7 @@ |
80 | if (((X < base.x) && (m_KeyboardHandler.GetCursorPosition() > 0)) || |
81 | ((X > base.x + base.GetWidth()) && (m_KeyboardHandler.GetCursorPosition() < m_KeyboardHandler.GetLength()))) |
82 | { |
83 | - m_ScrollTimerHandler = GetTimer().AddTimerHandler(50, m_ScrollTimerFunctor, this); |
84 | + m_ScrollTimerHandler = GetTimer().AddOneShotTimer(50, m_ScrollTimerFunctor, this); |
85 | } |
86 | else |
87 | { |
88 | @@ -120,7 +120,7 @@ |
89 | void EditTextBox::BlinkCursorTimerInterrupt(void *v) |
90 | { |
91 | GetTimer().RemoveTimerHandler(m_BlinkTimerHandler); |
92 | - m_BlinkTimerHandler = GetTimer().AddTimerHandler(500, m_BlinkTimerFunctor, this); |
93 | + m_BlinkTimerHandler = GetTimer().AddOneShotTimer(500, m_BlinkTimerFunctor, this); |
94 | BlinkCursor = !BlinkCursor; |
95 | QueueDraw(); |
96 | } |
97 | @@ -135,7 +135,7 @@ |
98 | |
99 | void EditTextBox::StartBlinkCursor(bool BlinkState) |
100 | { |
101 | - m_BlinkTimerHandler = GetTimer().AddTimerHandler(500, m_BlinkTimerFunctor, this); |
102 | + m_BlinkTimerHandler = GetTimer().AddOneShotTimer(500, m_BlinkTimerFunctor, this); |
103 | BlinkCursor = BlinkState; |
104 | QueueDraw(); |
105 | } |
106 | @@ -292,7 +292,7 @@ |
107 | |
108 | if ((!m_ScrollTimerHandler.IsValid()) && ((X < base.x) || (X > base.x + base.GetWidth()))) |
109 | { |
110 | - m_ScrollTimerHandler = GetTimer().AddTimerHandler(25, m_ScrollTimerFunctor, this); |
111 | + m_ScrollTimerHandler = GetTimer().AddOneShotTimer(25, m_ScrollTimerFunctor, this); |
112 | } |
113 | else if ((X >= base.x) && (X < base.x + base.GetWidth())) |
114 | { |
115 | @@ -439,7 +439,7 @@ |
116 | text_input_mode_ = false; |
117 | |
118 | EnteringKeyboardFocus(); |
119 | - m_BlinkTimerHandler = GetTimer().AddTimerHandler(500, m_BlinkTimerFunctor, this); |
120 | + m_BlinkTimerHandler = GetTimer().AddOneShotTimer(500, m_BlinkTimerFunctor, this); |
121 | } |
122 | |
123 | void EditTextBox::RecvEndKeyFocus() |
124 | |
125 | === modified file 'Nux/HScrollBar.cpp' |
126 | --- Nux/HScrollBar.cpp 2011-10-17 20:57:35 +0000 |
127 | +++ Nux/HScrollBar.cpp 2012-07-12 13:45:35 +0000 |
128 | @@ -90,15 +90,15 @@ |
129 | hlayout->AddView(_scroll_right_button, 0, eCenter, eFix); |
130 | |
131 | callback = new TimerFunctor; |
132 | - callback->time_expires.connect(sigc::mem_fun(this, &HScrollBar::HScrollBarHandler)); |
133 | + callback->tick.connect(sigc::mem_fun(this, &HScrollBar::HScrollBarHandler)); |
134 | left_callback = new TimerFunctor; |
135 | - left_callback->time_expires.connect(sigc::mem_fun(this, &HScrollBar::ScrollLeft)); |
136 | + left_callback->tick.connect(sigc::mem_fun(this, &HScrollBar::ScrollLeft)); |
137 | right_callback = new TimerFunctor; |
138 | - right_callback->time_expires.connect(sigc::mem_fun(this, &HScrollBar::ScrollRight)); |
139 | + right_callback->tick.connect(sigc::mem_fun(this, &HScrollBar::ScrollRight)); |
140 | trackleft_callback = new TimerFunctor; |
141 | - trackleft_callback->time_expires.connect(sigc::mem_fun(this, &HScrollBar::TrackLeft)); |
142 | + trackleft_callback->tick.connect(sigc::mem_fun(this, &HScrollBar::TrackLeft)); |
143 | trackright_callback = new TimerFunctor; |
144 | - trackright_callback->time_expires.connect(sigc::mem_fun(this, &HScrollBar::TrackRight)); |
145 | + trackright_callback->tick.connect(sigc::mem_fun(this, &HScrollBar::TrackRight)); |
146 | |
147 | SetLayout(hlayout); |
148 | SetAcceptMouseWheelEvent(true); |
149 | @@ -130,7 +130,7 @@ |
150 | else |
151 | { |
152 | scrollbar->QueueDraw(); |
153 | - GetTimer().AddTimerHandler(10, callback, scrollbar); |
154 | + GetTimer().AddOneShotTimer(10, callback, scrollbar); |
155 | } |
156 | } |
157 | |
158 | @@ -146,7 +146,7 @@ |
159 | else |
160 | { |
161 | scrollbar->QueueDraw(); |
162 | - GetTimer().AddTimerHandler(10, callback, scrollbar); |
163 | + GetTimer().AddOneShotTimer(10, callback, scrollbar); |
164 | } |
165 | } |
166 | } |
167 | @@ -158,7 +158,7 @@ |
168 | if (AtMaximum()) |
169 | RecvEndScrollRight(0, 0, 0, 0); |
170 | else |
171 | - m_RightTimerHandler = GetTimer().AddTimerHandler(10, right_callback, this); |
172 | + m_RightTimerHandler = GetTimer().AddOneShotTimer(10, right_callback, this); |
173 | |
174 | QueueDraw(); |
175 | } |
176 | @@ -170,7 +170,7 @@ |
177 | if (AtMaximum()) |
178 | RecvEndScrollLeft(0, 0, 0, 0); |
179 | else |
180 | - m_LeftTimerHandler = GetTimer().AddTimerHandler(10, left_callback, this); |
181 | + m_LeftTimerHandler = GetTimer().AddOneShotTimer(10, left_callback, this); |
182 | |
183 | QueueDraw(); |
184 | } |
185 | @@ -180,7 +180,7 @@ |
186 | if (m_TrackMouseCoord.x < _slider->GetBaseX() - _track->GetBaseX()) |
187 | { |
188 | OnScrollLeft.emit(container_width_, 1); |
189 | - m_TrackLeftTimerHandler = GetTimer().AddTimerHandler(10, trackleft_callback, this); |
190 | + m_TrackLeftTimerHandler = GetTimer().AddOneShotTimer(10, trackleft_callback, this); |
191 | QueueDraw(); |
192 | } |
193 | } |
194 | @@ -190,7 +190,7 @@ |
195 | if (m_TrackMouseCoord.x > _slider->GetBaseX() + _slider->GetBaseWidth() - _track->GetBaseX()) |
196 | { |
197 | OnScrollRight.emit(container_width_, 1); |
198 | - m_TrackRightTimerHandler = GetTimer().AddTimerHandler(10, trackright_callback, this); |
199 | + m_TrackRightTimerHandler = GetTimer().AddOneShotTimer(10, trackright_callback, this); |
200 | QueueDraw(); |
201 | } |
202 | } |
203 | @@ -377,14 +377,14 @@ |
204 | //sigVScrollBarSliderMouseDown.emit(); |
205 | b_MouseDownTimer = true; |
206 | b_MouseUpTimer = false; |
207 | - GetTimer().AddTimerHandler(10, callback, this); |
208 | + GetTimer().AddOneShotTimer(10, callback, this); |
209 | } |
210 | |
211 | void HScrollBar::OnSliderMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags) |
212 | { |
213 | b_MouseDownTimer = false; |
214 | b_MouseUpTimer = true; |
215 | - GetTimer().AddTimerHandler(10, callback, this); |
216 | + GetTimer().AddOneShotTimer(10, callback, this); |
217 | } |
218 | |
219 | void HScrollBar::OnSliderMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags) |
220 | |
221 | === modified file 'Nux/MainLoopGLib.cpp' |
222 | --- Nux/MainLoopGLib.cpp 2011-12-22 06:23:58 +0000 |
223 | +++ Nux/MainLoopGLib.cpp 2012-07-12 13:45:35 +0000 |
224 | @@ -289,7 +289,7 @@ |
225 | return 0; |
226 | } |
227 | |
228 | - GSource *timeout_source; |
229 | + GSource* timeout_source; |
230 | |
231 | //create a new time-out source |
232 | timeout_source = g_timeout_source_new(duration); |
233 | |
234 | === modified file 'Nux/NumericValuator.cpp' |
235 | --- Nux/NumericValuator.cpp 2011-10-10 01:52:00 +0000 |
236 | +++ Nux/NumericValuator.cpp 2012-07-12 13:45:35 +0000 |
237 | @@ -131,7 +131,7 @@ |
238 | |
239 | if (m_fValue < m_DoubleValidator.GetMaximum()) |
240 | { |
241 | - m_UpTimerHandler = GetTimer().AddTimerHandler(100, m_UpTimerCallback, 0); |
242 | + m_UpTimerHandler = GetTimer().AddOneShotTimer(100, m_UpTimerCallback, 0); |
243 | QueueDraw(); |
244 | } |
245 | } |
246 | @@ -144,7 +144,7 @@ |
247 | |
248 | if (m_fValue > m_DoubleValidator.GetMinimum()) |
249 | { |
250 | - m_DownTimerHandler = GetTimer().AddTimerHandler(100, m_DownTimerCallback, 0); |
251 | + m_DownTimerHandler = GetTimer().AddOneShotTimer(100, m_DownTimerCallback, 0); |
252 | QueueDraw(); |
253 | } |
254 | } |
255 | |
256 | === modified file 'Nux/ProgramFramework/ProgramTemplate.cpp' |
257 | --- Nux/ProgramFramework/ProgramTemplate.cpp 2012-01-27 22:37:13 +0000 |
258 | +++ Nux/ProgramFramework/ProgramTemplate.cpp 2012-07-12 13:45:35 +0000 |
259 | @@ -89,8 +89,8 @@ |
260 | if (program_life_span_ > 0) |
261 | { |
262 | timeout_signal_ = new nux::TimeOutSignal(); |
263 | - timeout_signal_->time_expires.connect(sigc::mem_fun(this, &ProgramTemplate::ProgramExitCall)); |
264 | - window_thread_->GetTimerHandler().AddTimerHandler(program_life_span_, timeout_signal_, NULL, NULL); |
265 | + timeout_signal_->tick.connect(sigc::mem_fun(this, &ProgramTemplate::ProgramExitCall)); |
266 | + window_thread_->GetTimerHandler().AddOneShotTimer(program_life_span_, timeout_signal_, NULL, NULL); |
267 | } |
268 | |
269 | window_thread_->Run(NULL); |
270 | |
271 | === modified file 'Nux/SpinBox.cpp' |
272 | --- Nux/SpinBox.cpp 2011-10-10 01:52:00 +0000 |
273 | +++ Nux/SpinBox.cpp 2012-07-12 13:45:35 +0000 |
274 | @@ -187,9 +187,9 @@ |
275 | if (m_iValue < m_IntValidator.GetMaximum()) |
276 | { |
277 | if (m_UpTimerHandler.IsValid()) |
278 | - m_UpTimerHandler = GetTimer().AddTimerHandler(100, m_UpTimerCallback, 0); |
279 | + m_UpTimerHandler = GetTimer().AddOneShotTimer(100, m_UpTimerCallback, 0); |
280 | else |
281 | - m_UpTimerHandler = GetTimer().AddTimerHandler(800, m_UpTimerCallback, 0); |
282 | + m_UpTimerHandler = GetTimer().AddOneShotTimer(800, m_UpTimerCallback, 0); |
283 | |
284 | QueueDraw(); |
285 | } |
286 | @@ -206,9 +206,9 @@ |
287 | if (m_iValue > m_IntValidator.GetMinimum()) |
288 | { |
289 | if (m_DownTimerHandler.IsValid()) |
290 | - m_DownTimerHandler = GetTimer().AddTimerHandler(100, m_DownTimerCallback, 0); |
291 | + m_DownTimerHandler = GetTimer().AddOneShotTimer(100, m_DownTimerCallback, 0); |
292 | else |
293 | - m_DownTimerHandler = GetTimer().AddTimerHandler(800, m_DownTimerCallback, 0); |
294 | + m_DownTimerHandler = GetTimer().AddOneShotTimer(800, m_DownTimerCallback, 0); |
295 | |
296 | QueueDraw(); |
297 | } |
298 | |
299 | === modified file 'Nux/SpinBoxDouble.cpp' |
300 | --- Nux/SpinBoxDouble.cpp 2011-10-10 01:52:00 +0000 |
301 | +++ Nux/SpinBoxDouble.cpp 2012-07-12 13:45:35 +0000 |
302 | @@ -194,9 +194,9 @@ |
303 | if (m_Value < m_DoubleValidator.GetMaximum()) |
304 | { |
305 | if (m_UpTimerHandler.IsValid()) |
306 | - m_UpTimerHandler = GetTimer().AddTimerHandler(100, m_UpTimerCallback, 0); |
307 | + m_UpTimerHandler = GetTimer().AddOneShotTimer(100, m_UpTimerCallback, 0); |
308 | else |
309 | - m_UpTimerHandler = GetTimer().AddTimerHandler(800, m_UpTimerCallback, 0); |
310 | + m_UpTimerHandler = GetTimer().AddOneShotTimer(800, m_UpTimerCallback, 0); |
311 | |
312 | QueueDraw(); |
313 | } |
314 | @@ -213,9 +213,9 @@ |
315 | if (m_Value > m_DoubleValidator.GetMinimum()) |
316 | { |
317 | if (m_DownTimerHandler.IsValid()) |
318 | - m_DownTimerHandler = GetTimer().AddTimerHandler(100, m_DownTimerCallback, 0); |
319 | + m_DownTimerHandler = GetTimer().AddOneShotTimer(100, m_DownTimerCallback, 0); |
320 | else |
321 | - m_DownTimerHandler = GetTimer().AddTimerHandler(800, m_DownTimerCallback, 0); |
322 | + m_DownTimerHandler = GetTimer().AddOneShotTimer(800, m_DownTimerCallback, 0); |
323 | |
324 | QueueDraw(); |
325 | } |
326 | |
327 | === modified file 'Nux/SpinBox_Logic.cpp' |
328 | --- Nux/SpinBox_Logic.cpp 2011-10-17 20:57:35 +0000 |
329 | +++ Nux/SpinBox_Logic.cpp 2012-07-12 13:45:35 +0000 |
330 | @@ -64,9 +64,9 @@ |
331 | m_EditLine->mouse_leave.connect(sigc::mem_fun(this, &SpinBox_Logic::RecvMouseLeave)); |
332 | |
333 | m_UpTimerCallback = new TimerFunctor; |
334 | - m_UpTimerCallback->time_expires.connect(sigc::mem_fun(this, &SpinBox_Logic::TimerSpinUpBtn)); |
335 | + m_UpTimerCallback->tick.connect(sigc::mem_fun(this, &SpinBox_Logic::TimerSpinUpBtn)); |
336 | m_DownTimerCallback = new TimerFunctor; |
337 | - m_DownTimerCallback->time_expires.connect(sigc::mem_fun(this, &SpinBox_Logic::TimerSpinDownBtn)); |
338 | + m_DownTimerCallback->tick.connect(sigc::mem_fun(this, &SpinBox_Logic::TimerSpinDownBtn)); |
339 | } |
340 | |
341 | SpinBox_Logic::~SpinBox_Logic() |
342 | |
343 | === modified file 'Nux/TabView.cpp' |
344 | --- Nux/TabView.cpp 2011-10-21 22:06:35 +0000 |
345 | +++ Nux/TabView.cpp 2012-07-12 13:45:35 +0000 |
346 | @@ -123,9 +123,9 @@ |
347 | |
348 | |
349 | tabright_callback = new TimerFunctor; |
350 | - tabright_callback->time_expires.connect(sigc::mem_fun(this, &TabView::RecvTabRightTimerExpired)); |
351 | + tabright_callback->tick.connect(sigc::mem_fun(this, &TabView::RecvTabRightTimerExpired)); |
352 | tableft_callback = new TimerFunctor; |
353 | - tableft_callback->time_expires.connect(sigc::mem_fun(this, &TabView::RecvTabLeftTimerExpired)); |
354 | + tableft_callback->tick.connect(sigc::mem_fun(this, &TabView::RecvTabLeftTimerExpired)); |
355 | } |
356 | |
357 | TabView::~TabView() |
358 | @@ -518,13 +518,13 @@ |
359 | void TabView::RecvTabRightTimerExpired(void *v) |
360 | { |
361 | TranslateTabLayout(-10); |
362 | - m_TabRightTimerHandler = GetTimer().AddTimerHandler(10, tabright_callback, this); |
363 | + m_TabRightTimerHandler = GetTimer().AddOneShotTimer(10, tabright_callback, this); |
364 | } |
365 | |
366 | void TabView::RecvTabLeftTimerExpired(void *v) |
367 | { |
368 | TranslateTabLayout(10); |
369 | - m_TabLeftTimerHandler = GetTimer().AddTimerHandler(10, tableft_callback, this); |
370 | + m_TabLeftTimerHandler = GetTimer().AddOneShotTimer(10, tableft_callback, this); |
371 | } |
372 | |
373 | bool TabView::AcceptKeyNavFocus() |
374 | |
375 | === modified file 'Nux/TimerProc.cpp' |
376 | --- Nux/TimerProc.cpp 2011-12-29 18:06:53 +0000 |
377 | +++ Nux/TimerProc.cpp 2012-07-12 13:45:35 +0000 |
378 | @@ -55,6 +55,7 @@ |
379 | |
380 | //! Delay before the callback expires |
381 | TimeStruct when; |
382 | + gint64 ms_time; // milliseconds |
383 | void *CallbackData; |
384 | TimeOutSignal *timeout_signal; |
385 | |
386 | @@ -67,16 +68,18 @@ |
387 | int Period; //!< The periode of the timer interuption(in milliseconds). |
388 | int Duration; //!< How long the timer will be running from start to finish(in milliseconds); |
389 | int ElapsedTime; //!< Elapsed time during execution(in milliseconds). |
390 | - bool MarkedForRemoval; |
391 | + bool marked_for_removal_; |
392 | BaseWindow *Window; //!< BaseWindow from where the timer was created. |
393 | TimerObject *next; |
394 | TimerObject *prev; |
395 | unsigned int glibid; |
396 | unsigned int uid; |
397 | + TimerHandler::TimerState state_; |
398 | }; |
399 | |
400 | TimerObject::TimerObject() |
401 | { |
402 | + ms_time = 0; |
403 | Type = 0; |
404 | CallbackData = 0; |
405 | timeout_signal = 0; |
406 | @@ -86,12 +89,13 @@ |
407 | ElapsedTime = 0; |
408 | ScheduledIteration = 0; |
409 | ProgressIterationCount = 0; |
410 | - MarkedForRemoval = 0; |
411 | + marked_for_removal_ = 0; |
412 | Window = 0; |
413 | next = 0; |
414 | prev = 0; |
415 | glibid = 0; |
416 | uid = 0; |
417 | + state_ = TimerHandler::TIMER_STATE_STOPED; |
418 | } |
419 | |
420 | TimerHandle::TimerHandle() |
421 | @@ -168,14 +172,13 @@ |
422 | //////////////////////////////////////////////////// |
423 | TimerHandler::TimerHandler(WindowThread* window_thread) |
424 | : window_thread_(window_thread) |
425 | + , is_processing_timers_(false) |
426 | + , timer_object_queue_(NULL) |
427 | { |
428 | - m_timer_object_queue = 0; |
429 | - m_IsProceesingTimers = false; |
430 | } |
431 | |
432 | TimerHandler::~TimerHandler() |
433 | { |
434 | - |
435 | } |
436 | |
437 | void TimerHandler::StartEarlyTimerObjects() |
438 | @@ -184,8 +187,7 @@ |
439 | for (it = _early_timer_objects.begin(); it != _early_timer_objects.end(); it++) |
440 | { |
441 | TimerObject *timer_object = *it; |
442 | - TimeRightNow(&timer_object->when); |
443 | - Addmillisecs(&timer_object->when, timer_object->Period); |
444 | + timer_object->ms_time = g_get_monotonic_time() / 1000; |
445 | |
446 | #if (defined(NUX_OS_LINUX) || defined(NUX_USE_GLIB_LOOP_ON_WINDOWS)) && (!defined(NUX_DISABLE_GLIB_LOOP)) |
447 | timer_object->glibid = GetWindowThread()->AddTimeout(timer_object->Period); |
448 | @@ -195,17 +197,17 @@ |
449 | _early_timer_objects.clear(); |
450 | } |
451 | |
452 | - TimerHandle TimerHandler::AddTimerHandler(unsigned int Period, TimeOutSignal *timeout_signal, void *Data, WindowThread* window_thread) |
453 | + TimerHandle TimerHandler::AddOneShotTimer(unsigned int Period, TimeOutSignal* timeout_signal, void* Data, WindowThread* window_thread) |
454 | { |
455 | TimerObject *timer_object = new TimerObject(); |
456 | |
457 | - TimeRightNow(&timer_object->when); |
458 | - Addmillisecs(&timer_object->when, Period); |
459 | + timer_object->ms_time = g_get_monotonic_time() / 1000; |
460 | |
461 | timer_object->CallbackData = Data; |
462 | timer_object->timeout_signal = timeout_signal; |
463 | timer_object->Period = Period; |
464 | timer_object->Type = TIMERTYPE_PERIODIC; |
465 | + timer_object->state_ = TimerHandler::TIMER_STATE_RUNNING; |
466 | if (window_thread) |
467 | timer_object->Window = window_thread->GetWindowCompositor().GetProcessingTopView(); |
468 | else |
469 | @@ -225,10 +227,10 @@ |
470 | _early_timer_objects.push_back(timer_object); |
471 | // Probably trying to set a timeout before Glib main context and loop have been created. |
472 | // Sometimes later, this timer will be examined when ExecTimerHandler is called. |
473 | - // This happens when trying to set a callback before the mainloop has been initialized. |
474 | + // This happens when trying to set a callback before the main loop has been initialized. |
475 | } |
476 | |
477 | - //nuxDebugMsg("[TimerHandler::AddTimerHandler] Adding Timeout ID: %d", timer_object->glibid); |
478 | + //nuxDebugMsg("[TimerHandler::AddOneShotTimer] Adding Timeout ID: %d", timer_object->glibid); |
479 | } |
480 | #endif |
481 | |
482 | @@ -236,17 +238,18 @@ |
483 | return handle; |
484 | } |
485 | |
486 | - TimerHandle TimerHandler::AddPeriodicTimerHandler(unsigned int Period, int Duration, TimeOutSignal *timeout_signal, void *Data) |
487 | + TimerHandle TimerHandler::AddDurationTimer(unsigned int Period, int Duration, TimeOutSignal *timeout_signal, void *Data) |
488 | { |
489 | - TimerObject *timer_object = new TimerObject(); |
490 | - TimeRightNow(&timer_object->when); |
491 | - Addmillisecs(&timer_object->when, Period); |
492 | + TimerObject* timer_object = new TimerObject(); |
493 | + |
494 | + timer_object->ms_time = g_get_monotonic_time() / 1000; |
495 | timer_object->CallbackData = Data; |
496 | timer_object->timeout_signal = timeout_signal; |
497 | |
498 | - timer_object->Period = Period; |
499 | - timer_object->Duration = (Duration < 0) ? -1 : Duration; |
500 | - timer_object->Type = TIMERTYPE_DURATION; |
501 | + timer_object->Period = Period; |
502 | + timer_object->Duration = (Duration < 0) ? -1 : Duration; |
503 | + timer_object->Type = TIMERTYPE_DURATION; |
504 | + timer_object->state_ = TimerHandler::TIMER_STATE_RUNNING; |
505 | AddHandle(timer_object); |
506 | |
507 | #if (defined(NUX_OS_LINUX) || defined(NUX_USE_GLIB_LOOP_ON_WINDOWS)) && (!defined(NUX_DISABLE_GLIB_LOOP)) |
508 | @@ -261,7 +264,7 @@ |
509 | // This happens when trying to set a callback before the mainloop has been initialized. |
510 | } |
511 | |
512 | - //nuxDebugMsg("[TimerHandler::AddTimerHandler] Adding Timeout ID: %d", timer_object->glibid); |
513 | + //nuxDebugMsg("[TimerHandler::AddOneShotTimer] Adding Timeout ID: %d", timer_object->glibid); |
514 | } |
515 | #endif |
516 | |
517 | @@ -269,17 +272,18 @@ |
518 | return handle; |
519 | } |
520 | |
521 | - TimerHandle TimerHandler::AddCountIterationTimerHandler(unsigned int Period, int NumberOfIterations, TimeOutSignal *timeout_signal, void *Data) |
522 | + TimerHandle TimerHandler::AddIterativeTimer(unsigned int Period, int NumberOfIterations, TimeOutSignal *timeout_signal, void *Data) |
523 | { |
524 | - TimerObject *timer_object = new TimerObject(); |
525 | - TimeRightNow(&timer_object->when); |
526 | - Addmillisecs(&timer_object->when, Period); |
527 | + TimerObject* timer_object = new TimerObject(); |
528 | + |
529 | + timer_object->ms_time = g_get_monotonic_time() / 1000; |
530 | timer_object->CallbackData = Data; |
531 | timer_object->timeout_signal = timeout_signal; |
532 | |
533 | - timer_object->Period = Period; |
534 | + timer_object->Period = Period; |
535 | timer_object->ScheduledIteration = (NumberOfIterations < 0) ? -1 : NumberOfIterations; |
536 | - timer_object->Type = TIMERTYPE_ITERATION; |
537 | + timer_object->Type = TIMERTYPE_ITERATION; |
538 | + timer_object->state_ = TimerHandler::TIMER_STATE_RUNNING; |
539 | AddHandle(timer_object); |
540 | |
541 | #if (defined(NUX_OS_LINUX) || defined(NUX_USE_GLIB_LOOP_ON_WINDOWS)) && (!defined(NUX_DISABLE_GLIB_LOOP)) |
542 | @@ -294,7 +298,7 @@ |
543 | // This happens when trying to set a callback before the mainloop has been initialized. |
544 | } |
545 | |
546 | - //nuxDebugMsg("[TimerHandler::AddTimerHandler] Adding Timeout ID: %d", timer_object->glibid); |
547 | + //nuxDebugMsg("[TimerHandler::AddOneShotTimer] Adding Timeout ID: %d", timer_object->glibid); |
548 | } |
549 | #endif |
550 | TimerHandle handle(timer_object); |
551 | @@ -302,7 +306,7 @@ |
552 | } |
553 | |
554 | // Sort timers and add them to the queue |
555 | - TimerObject *TimerHandler::AddHandle(TimerObject *timer_object) |
556 | + TimerObject *TimerHandler::AddHandle(TimerObject* timer_object) |
557 | { |
558 | if (timer_object == NULL) |
559 | return NULL; |
560 | @@ -313,26 +317,26 @@ |
561 | |
562 | // If the queue is empty or the new timer will expire sooner than the first timer in the queue |
563 | // then add the new timer at the start of the queue. |
564 | - if ((m_timer_object_queue == NULL) || TimeIsGreater(m_timer_object_queue->when, timer_object->when)) |
565 | + if ((timer_object_queue_ == NULL) || (timer_object_queue_->ms_time > timer_object->ms_time)) |
566 | { |
567 | // Add the timer timer_object at the head of the queue |
568 | - timer_object->next = m_timer_object_queue; |
569 | + timer_object->next = timer_object_queue_; |
570 | |
571 | - if (m_timer_object_queue) |
572 | - m_timer_object_queue->prev = timer_object; |
573 | + if (timer_object_queue_) |
574 | + timer_object_queue_->prev = timer_object; |
575 | |
576 | timer_object->prev = 0; |
577 | - m_timer_object_queue = timer_object; |
578 | + timer_object_queue_ = timer_object; |
579 | |
580 | return timer_object; |
581 | } |
582 | |
583 | - TimerObject *tmp = m_timer_object_queue; |
584 | + TimerObject *tmp = timer_object_queue_; |
585 | |
586 | while (tmp->next != NULL) |
587 | { |
588 | // Is the time to wait for tmp->next to expire smaller than for timer_object |
589 | - if (TimeIsGreater(timer_object->when, tmp->next->when)) |
590 | + if (timer_object->ms_time > tmp->next->ms_time) |
591 | { |
592 | // keep searching |
593 | tmp = tmp->next; |
594 | @@ -356,7 +360,7 @@ |
595 | unsigned int TimerHandler::GetNumPendingHandler() |
596 | { |
597 | unsigned int count = 0; |
598 | - TimerObject *head = m_timer_object_queue; |
599 | + TimerObject *head = timer_object_queue_; |
600 | |
601 | while (head) |
602 | { |
603 | @@ -367,20 +371,20 @@ |
604 | return count; |
605 | } |
606 | |
607 | - bool TimerHandler::RemoveTimerHandler(TimerHandle &timer_object) |
608 | + bool TimerHandler::RemoveTimerHandler(TimerHandle &handle) |
609 | { |
610 | - NUX_RETURN_VALUE_IF_NULL(timer_object.m_d, false); |
611 | - NUX_RETURN_VALUE_IF_NULL(m_timer_object_queue, false); |
612 | - |
613 | - TimerObject *tmp; |
614 | - |
615 | - tmp = m_timer_object_queue; |
616 | + NUX_RETURN_VALUE_IF_NULL(handle.m_d, false); |
617 | + NUX_RETURN_VALUE_IF_NULL(timer_object_queue_, false); |
618 | + |
619 | + TimerObject* tmp; |
620 | + |
621 | + tmp = timer_object_queue_; |
622 | |
623 | while (tmp) |
624 | { |
625 | - if ((tmp == timer_object.m_d) && (tmp->uid == timer_object.m_d->uid)) |
626 | + if ((tmp == handle.m_d) && (tmp->uid == handle.m_d->uid)) |
627 | { |
628 | - if (!m_IsProceesingTimers) |
629 | + if (!is_processing_timers_) |
630 | { |
631 | if (tmp->next) |
632 | tmp->next->prev = tmp->prev; |
633 | @@ -388,63 +392,138 @@ |
634 | if (tmp->prev) |
635 | tmp->prev->next = tmp->next; |
636 | |
637 | - if ((timer_object.m_d == m_timer_object_queue) && (timer_object.m_d->uid == m_timer_object_queue->uid)) |
638 | - m_timer_object_queue = timer_object.m_d->next; |
639 | - |
640 | - NUX_SAFE_DELETE(timer_object.m_d); |
641 | - } |
642 | - else |
643 | - { |
644 | - timer_object.m_d->MarkedForRemoval = true; |
645 | - } |
646 | - |
647 | - return true; |
648 | - } |
649 | - |
650 | - tmp = tmp->next; |
651 | - } |
652 | - |
653 | - return false; |
654 | - } |
655 | - |
656 | -#if (defined(NUX_OS_LINUX) || defined(NUX_USE_GLIB_LOOP_ON_WINDOWS)) && (!defined(NUX_DISABLE_GLIB_LOOP)) |
657 | + if ((handle.m_d == timer_object_queue_) && (handle.m_d->uid == timer_object_queue_->uid)) |
658 | + timer_object_queue_ = handle.m_d->next; |
659 | + |
660 | + NUX_SAFE_DELETE(handle.m_d); |
661 | + } |
662 | + else |
663 | + { |
664 | + handle.m_d->marked_for_removal_ = true; |
665 | + } |
666 | + |
667 | + return true; |
668 | + } |
669 | + |
670 | + tmp = tmp->next; |
671 | + } |
672 | + |
673 | + return false; |
674 | + } |
675 | + |
676 | + bool TimerHandler::PauseTimer(TimerHandle& handle) |
677 | + { |
678 | + NUX_RETURN_VALUE_IF_NULL(handle.m_d, false); |
679 | + NUX_RETURN_VALUE_IF_NULL(timer_object_queue_, false); |
680 | + |
681 | + if (handle.m_d->state_ != TimerHandler::TIMER_STATE_RUNNING) |
682 | + { |
683 | + return false; |
684 | + } |
685 | + |
686 | + TimerObject* tmp; |
687 | + |
688 | + // Pointer to the start of the queue. |
689 | + tmp = timer_object_queue_; |
690 | + |
691 | + // Search for the timer handle |
692 | + while (tmp) |
693 | + { |
694 | + if ((tmp == handle.m_d) && (tmp->uid == handle.m_d->uid)) |
695 | + { |
696 | + handle.m_d->state_ = TimerHandler::TIMER_STATE_PAUSED; |
697 | + |
698 | + |
699 | + if (!is_processing_timers_) |
700 | + { |
701 | + gint64 ms_time_now = g_get_monotonic_time() / 1000; |
702 | + |
703 | + if (handle.m_d->Type == TIMERTYPE_PERIODIC) |
704 | + { |
705 | + handle.m_d->ElapsedTime += (ms_time_now - handle.m_d->ms_time); |
706 | + handle.m_d->ProgressDelta = float(handle.m_d->ElapsedTime) / float(handle.m_d->Period); |
707 | + |
708 | + if (handle.m_d->Param + handle.m_d->ProgressDelta > 1.0f) |
709 | + handle.m_d->ProgressDelta = 1.0f - handle.m_d->Param; |
710 | + |
711 | + handle.m_d->Param = float(handle.m_d->ElapsedTime) / float(handle.m_d->Period); |
712 | + } |
713 | + } |
714 | + |
715 | + return true; |
716 | + } |
717 | + |
718 | + tmp = tmp->next; |
719 | + } |
720 | + return false; |
721 | + } |
722 | + |
723 | + bool TimerHandler::ResumeTimer(TimerHandle& handle) |
724 | + { |
725 | + NUX_RETURN_VALUE_IF_NULL(handle.m_d, false); |
726 | + NUX_RETURN_VALUE_IF_NULL(timer_object_queue_, false); |
727 | + |
728 | + if (handle.m_d->state_ != TimerHandler::TIMER_STATE_PAUSED) |
729 | + { |
730 | + return false; |
731 | + } |
732 | + |
733 | + TimerObject* tmp; |
734 | + |
735 | + // Pointer to the start of the queue. |
736 | + tmp = timer_object_queue_; |
737 | + |
738 | + // Search for the timer handle |
739 | + while (tmp) |
740 | + { |
741 | + if ((tmp == handle.m_d) && (tmp->uid == handle.m_d->uid)) |
742 | + { |
743 | + handle.m_d->state_ = TimerHandler::TIMER_STATE_RUNNING; |
744 | + |
745 | + if (handle.m_d->Type == TIMERTYPE_PERIODIC) |
746 | + { |
747 | + handle.m_d->glibid = GetWindowThread()->AddTimeout(handle.m_d->Period * (1.0f - handle.m_d->Param)); |
748 | + } |
749 | + else |
750 | + { |
751 | + handle.m_d->glibid = GetWindowThread()->AddTimeout(handle.m_d->Period); |
752 | + } |
753 | + |
754 | + handle.m_d->ms_time = g_get_monotonic_time() / 1000; |
755 | + |
756 | + if (handle.m_d->glibid == 0) |
757 | + { |
758 | + _early_timer_objects.push_back(handle.m_d); |
759 | + } |
760 | + return true; |
761 | + } |
762 | + |
763 | + tmp = tmp->next; |
764 | + } |
765 | + return false; |
766 | + } |
767 | + |
768 | int TimerHandler::ExecTimerHandler(unsigned int timer_id) |
769 | -#else |
770 | - int TimerHandler::ExecTimerHandler() |
771 | -#endif |
772 | { |
773 | - NUX_RETURN_VALUE_IF_NULL(m_timer_object_queue, 0); |
774 | + NUX_RETURN_VALUE_IF_NULL(timer_object_queue_, 0); |
775 | |
776 | bool repeat = false; |
777 | - TimerObject *timer_object = m_timer_object_queue; |
778 | - TimeStruct now; |
779 | - |
780 | - int timer_executed = 0; |
781 | - |
782 | - TimeRightNow(&now); |
783 | - |
784 | - m_IsProceesingTimers = true; |
785 | + // Pointer to the start of the timer handler queue. |
786 | + TimerObject* timer_object = timer_object_queue_; |
787 | + |
788 | + is_processing_timers_ = true; |
789 | |
790 | while (timer_object != NULL) |
791 | { |
792 | -#if (defined(NUX_OS_LINUX) || defined(NUX_USE_GLIB_LOOP_ON_WINDOWS)) && (!defined(NUX_DISABLE_GLIB_LOOP)) |
793 | - |
794 | - if ((/*TimeIsGreater(now, timer_object->when) ||*/ (timer_object->glibid == timer_id)) && (timer_object->MarkedForRemoval == false)) |
795 | -#else |
796 | - if (TimeIsGreater(now, timer_object->when)) |
797 | -#endif |
798 | + if ((timer_object->glibid == timer_id) && (timer_object->marked_for_removal_ == false)) |
799 | { |
800 | - long elaps = now.sec - timer_object->when.sec; |
801 | - long uelaps = now.usec - timer_object->when.usec; |
802 | - |
803 | - if (uelaps < 0) |
804 | + if (timer_object->state_ != TIMER_STATE_RUNNING) |
805 | { |
806 | - uelaps += 1000000; |
807 | - //nuxAssert(elaps > 0); |
808 | - elaps -= 1; |
809 | + return false; |
810 | } |
811 | + // Find the first timer object that |
812 | |
813 | - timer_object->ElapsedTime += timer_object->Period; //elaps * 1000 + uelaps / 1000; // milliseconds |
814 | + timer_object->ElapsedTime += timer_object->Period; |
815 | |
816 | if (timer_object->Type == TIMERTYPE_PERIODIC) |
817 | { |
818 | @@ -484,15 +563,20 @@ |
819 | nuxAssertMsg(0, "[TimerHandler::ExecTimerHandler] Unknown timer type."); |
820 | } |
821 | |
822 | + |
823 | if (timer_object->Param > 1.0f) |
824 | + { |
825 | + // correction. |
826 | timer_object->Param = 1.0f; |
827 | + } |
828 | |
829 | - timer_object->MarkedForRemoval = false; |
830 | + timer_object->marked_for_removal_ = false; |
831 | |
832 | if (timer_object->timeout_signal != 0) |
833 | { |
834 | + // Execute the signal |
835 | GetWindowThread()->GetWindowCompositor().SetProcessingTopView(timer_object->Window); |
836 | - timer_object->timeout_signal->time_expires.emit(timer_object->CallbackData); |
837 | + timer_object->timeout_signal->tick.emit(timer_object->CallbackData); |
838 | GetWindowThread()->GetWindowCompositor().SetProcessingTopView(NULL); |
839 | // Reset glibid to 0. glibid is not null, if this element ever happened to be at the head of the queue |
840 | // and we set a timer for it. |
841 | @@ -500,56 +584,68 @@ |
842 | //timer_object->glibid = 0; |
843 | } |
844 | |
845 | - TimerObject *expired_handler = 0; |
846 | + TimerObject* expired_handler = 0; |
847 | |
848 | - if (timer_object->MarkedForRemoval) |
849 | + if (timer_object->marked_for_removal_) |
850 | { |
851 | // RemoveTimerHandler was called during the callback execution |
852 | expired_handler = timer_object; |
853 | } |
854 | else if (timer_object->Type == TIMERTYPE_PERIODIC) |
855 | { |
856 | + // A one shot timer expires after the first execution. |
857 | expired_handler = timer_object; |
858 | } |
859 | else if ((timer_object->Type == TIMERTYPE_DURATION) && (timer_object->Param >= 1.0f)) |
860 | { |
861 | + // A timer delay timer expires after the duration of the timer as expired. |
862 | expired_handler = timer_object; |
863 | } |
864 | else if ((timer_object->Type == TIMERTYPE_ITERATION) && (timer_object->ProgressIterationCount >= timer_object->ScheduledIteration)) |
865 | { |
866 | + // An iterative timer expires after the timer as been executedN times. |
867 | expired_handler = timer_object; |
868 | } |
869 | |
870 | - if (expired_handler) |
871 | - { |
872 | + if (!expired_handler && (timer_object->state_ == TIMER_STATE_PAUSED)) |
873 | + { |
874 | + // The state has been changed to "paused". |
875 | + return false; |
876 | + } |
877 | + |
878 | + if(expired_handler) |
879 | + { |
880 | + GetWindowThread()->GetWindowCompositor().SetProcessingTopView(timer_object->Window); |
881 | + timer_object->timeout_signal->expired.emit(timer_object->CallbackData); |
882 | + GetWindowThread()->GetWindowCompositor().SetProcessingTopView(NULL); |
883 | + |
884 | + timer_object->state_ = TIMER_STATE_STOPED; |
885 | + |
886 | if (timer_object->next) |
887 | timer_object->next->prev = timer_object->prev; |
888 | |
889 | if (timer_object->prev) |
890 | timer_object->prev->next = timer_object->next; |
891 | |
892 | - if ((timer_object == m_timer_object_queue) && (timer_object->uid == m_timer_object_queue->uid)) |
893 | + if ((timer_object == timer_object_queue_) && (timer_object->uid == timer_object_queue_->uid)) |
894 | { |
895 | // timer_object is the first element of the queue. |
896 | - m_timer_object_queue = timer_object->next; |
897 | + timer_object_queue_ = timer_object->next; |
898 | |
899 | - if (m_timer_object_queue) |
900 | + if (timer_object_queue_) |
901 | { |
902 | - m_timer_object_queue->prev = 0; |
903 | + timer_object_queue_->prev = 0; |
904 | } |
905 | } |
906 | |
907 | timer_object = timer_object->next; |
908 | - |
909 | delete expired_handler; |
910 | } |
911 | else |
912 | { |
913 | repeat = true; |
914 | - //timer_object = timer_object->next; |
915 | } |
916 | |
917 | - timer_executed++; |
918 | break; |
919 | } |
920 | else |
921 | @@ -558,24 +654,14 @@ |
922 | } |
923 | } |
924 | |
925 | -// // Look at the head of the queue and set a glib timeout for the first element, if one wasn't set already. |
926 | -// if (m_timer_object_queue && (m_timer_object_queue->glibid == 0)) |
927 | -// { |
928 | -// // How long(in milliseconds) between now and the moment the timeout expires? |
929 | -// unsigned int time_difference = TimeDiff(now, m_timer_object_queue->when); |
930 | -// |
931 | -// m_timer_object_queue->glibid = GetWindowThread()->AddTimeout(time_difference); |
932 | -// //nuxDebugMsg("[TimerHandler::ExecTimerHandler] Adding Timeout ID: %d", m_timer_object_queue->glibid); |
933 | -// } |
934 | - |
935 | // Purge handles that have been marked for removal |
936 | - timer_object = m_timer_object_queue; |
937 | + timer_object = timer_object_queue_; |
938 | |
939 | while (timer_object) |
940 | { |
941 | - if (timer_object->MarkedForRemoval) |
942 | + if (timer_object->marked_for_removal_) |
943 | { |
944 | - TimerObject *expired_handler = timer_object; |
945 | + TimerObject* expired_handler = timer_object; |
946 | |
947 | if (timer_object->next) |
948 | timer_object->next->prev = timer_object->prev; |
949 | @@ -585,11 +671,11 @@ |
950 | else |
951 | { |
952 | // timer_object is the first element of the queue. |
953 | - m_timer_object_queue = timer_object->next; |
954 | + timer_object_queue_ = timer_object->next; |
955 | |
956 | - if (m_timer_object_queue) |
957 | + if (timer_object_queue_) |
958 | { |
959 | - m_timer_object_queue->prev = 0; |
960 | + timer_object_queue_->prev = 0; |
961 | } |
962 | } |
963 | |
964 | @@ -602,14 +688,13 @@ |
965 | } |
966 | } |
967 | |
968 | - m_IsProceesingTimers = false; |
969 | - //return timer_executed; |
970 | + is_processing_timers_ = false; |
971 | return repeat; |
972 | } |
973 | |
974 | bool TimerHandler::FindTimerHandle(TimerHandle &timer_object) |
975 | { |
976 | - TimerObject *tmp = m_timer_object_queue; |
977 | + TimerObject *tmp = timer_object_queue_; |
978 | |
979 | while (tmp) |
980 | { |
981 | @@ -630,7 +715,7 @@ |
982 | TimeStruct now; |
983 | TimeStruct delay; |
984 | |
985 | - if (m_timer_object_queue == NULL) |
986 | + if (timer_object_queue_ == NULL) |
987 | { |
988 | // The return value of this function is only valid if there _are_ timers active. |
989 | return 0; |
990 | @@ -639,14 +724,14 @@ |
991 | { |
992 | TimeRightNow(&now); |
993 | |
994 | - if (TimeIsGreater(now, m_timer_object_queue->when)) |
995 | + if (TimeIsGreater(now, timer_object_queue_->when)) |
996 | { |
997 | return 0; |
998 | } |
999 | else |
1000 | { |
1001 | - delay.sec = m_timer_object_queue->when.sec - now.sec; |
1002 | - delay.usec = m_timer_object_queue->when.usec - now.usec; |
1003 | + delay.sec = timer_object_queue_->when.sec - now.sec; |
1004 | + delay.usec = timer_object_queue_->when.usec - now.usec; |
1005 | |
1006 | // make sure that usec cannot be less than -1000000 before applying this code |
1007 | if (delay.usec < 0) |
1008 | |
1009 | === modified file 'Nux/TimerProc.h' |
1010 | --- Nux/TimerProc.h 2011-12-29 18:06:53 +0000 |
1011 | +++ Nux/TimerProc.h 2012-07-12 13:45:35 +0000 |
1012 | @@ -33,7 +33,8 @@ |
1013 | class TimeOutSignal : public sigc::trackable |
1014 | { |
1015 | public: |
1016 | - sigc::signal<void, void *> time_expires; |
1017 | + sigc::signal<void, void *> tick; |
1018 | + sigc::signal<void, void *> expired; |
1019 | }; |
1020 | typedef TimeOutSignal TimerFunctor; |
1021 | |
1022 | @@ -77,6 +78,13 @@ |
1023 | TIMERTYPE_ITERATION, |
1024 | }; |
1025 | |
1026 | + typedef enum |
1027 | + { |
1028 | + TIMER_STATE_STOPED, |
1029 | + TIMER_STATE_PAUSED, |
1030 | + TIMER_STATE_RUNNING, |
1031 | + } TimerState; |
1032 | + |
1033 | TimerHandler(WindowThread *window_thread); |
1034 | ~TimerHandler(); |
1035 | |
1036 | @@ -85,38 +93,38 @@ |
1037 | Add a timer callback to the timer manager. When the timer expires, the callback function is executed. |
1038 | The returned TimerObject should not be deleted by the caller. |
1039 | |
1040 | - @param Milliseconds Period delay before the callback is executed. |
1041 | - @param timeout_signal The callback to execute when the timer expires. |
1042 | + @param Milliseconds period Time before the timer ticks. The timer ticks only once and then it expires. |
1043 | + @param timeout_signal The callback to execute when the timer expires. |
1044 | @param Data The callback data |
1045 | - @param window_thread Thread safety mesure. Pass the WindowThread associated to this TimerHandler if it is called from a different thread than the one where the main thread was created. |
1046 | + @param window_thread Thread safety measure. Pass the WindowThread associated to this TimerHandler if it is called from a different thread than the one where the main thread was created. |
1047 | @return A handle to the timer. |
1048 | */ |
1049 | - TimerHandle AddTimerHandler (unsigned int Period, TimeOutSignal *timeout_signal, void *Data, WindowThread* window_thread = NULL); |
1050 | + TimerHandle AddOneShotTimer(unsigned int period, TimeOutSignal *timeout_signal, void *Data, WindowThread* window_thread = NULL); |
1051 | //! Add a periodic timer callback. |
1052 | /*! |
1053 | Add a timer callback to the timer manager. Every time the timer expires, the callback function is executed. |
1054 | The returned TimerHandle should not be deleted by the caller. |
1055 | |
1056 | - @param Milliseconds Period delay before the callback is executed. |
1057 | + @param Milliseconds period Time between the timer ticks. The timer will tick 'NumberOfIteration' times. |
1058 | @param Duration The duration over which the timer is repeated. |
1059 | - @param timeout_signal The callback to execute when the timer expires. |
1060 | + @param timeout_signal The callback to execute when the timer expires. |
1061 | @param Data The callback data |
1062 | @return A handle to the timer. |
1063 | */ |
1064 | - TimerHandle AddPeriodicTimerHandler (unsigned int Period, int Duration, TimeOutSignal *timeout_signal, void *Data); |
1065 | + TimerHandle AddDurationTimer(unsigned int period, int Duration, TimeOutSignal *timeout_signal, void *Data); |
1066 | //! Add a timer callback to be called a finite number of time. |
1067 | /*! |
1068 | Add a timer callback to the timer manager. The timer callback will be call N times exactly. |
1069 | Every time the timer expires, the callback function is executed. |
1070 | The returned TimerHandle should not be deleted by the caller. |
1071 | |
1072 | - @param Milliseconds Period delay before the callback is executed. |
1073 | - @param NumberOfIteration The number of time to repeat the the wait period. |
1074 | - @param timeout_signal The callback to execute when the timer expires. |
1075 | + @param Milliseconds period Time between the timer ticks. The timer will tick 'NumberOfIteration' times. |
1076 | + @param NumberOfIteration The number of time to repeat the wait period. |
1077 | + @param timeout_signal The callback to execute when the timer expires. |
1078 | @param Data The callback data |
1079 | @return A handle to the timer. |
1080 | */ |
1081 | - TimerHandle AddCountIterationTimerHandler (unsigned int Period, int NumberOfIteration, TimeOutSignal *timeout_signal, void *Data); |
1082 | + TimerHandle AddIterativeTimer(unsigned int period, int NumberOfIteration, TimeOutSignal *timeout_signal, void *Data); |
1083 | |
1084 | //! Search for a timer handle. |
1085 | /*! |
1086 | @@ -125,14 +133,31 @@ |
1087 | @param handle Timer handle to search. |
1088 | @return Return true if the timer is found; false otherwise. |
1089 | */ |
1090 | - bool FindTimerHandle (TimerHandle &handle); |
1091 | + bool FindTimerHandle(TimerHandle& handle); |
1092 | |
1093 | //! Remove a timer; |
1094 | /*! |
1095 | - @param handle Timer handle to search. |
1096 | - @return Return True if the timer is found. |
1097 | - */ |
1098 | - bool RemoveTimerHandler (TimerHandle &handle); |
1099 | + This call stops the timer. |
1100 | + @param handle Timer handle to search. |
1101 | + @return Return True if the timer is found. |
1102 | + */ |
1103 | + bool RemoveTimerHandler(TimerHandle& handle); |
1104 | + |
1105 | + //! Pause a timer. |
1106 | + /*! |
1107 | + This call pauses a timer. |
1108 | + @param handle Timer handle to look for. |
1109 | + @return True if the timer is paused. |
1110 | + */ |
1111 | + bool PauseTimer(TimerHandle& handle); |
1112 | + |
1113 | + //! Resume the execution of a timer. |
1114 | + /*! |
1115 | + This call resumes the execution of a timer. |
1116 | + @param handle Timer handle to look for. |
1117 | + @return True if the timer execution has resumed.. |
1118 | + */ |
1119 | + bool ResumeTimer(TimerHandle& handle); |
1120 | |
1121 | //! Return the delay until the next timer expires. |
1122 | /*! |
1123 | @@ -150,14 +175,20 @@ |
1124 | void StartEarlyTimerObjects(); |
1125 | |
1126 | private: |
1127 | + // Prevent copy constructor. |
1128 | + TimerHandler(const TimerHandler&); |
1129 | + |
1130 | + // Prevent assignment operator. |
1131 | + TimerHandler& operator = (const TimerHandler&); |
1132 | + |
1133 | WindowThread *window_thread_; //!< The WindowThread to which this object belongs. |
1134 | |
1135 | - bool m_IsProceesingTimers; |
1136 | - TimerObject *AddHandle (TimerObject *handle); |
1137 | + bool is_processing_timers_; |
1138 | + TimerObject* AddHandle(TimerObject *handle); |
1139 | unsigned int GetNumPendingHandler(); |
1140 | |
1141 | //! Single linked list of timer delays. |
1142 | - TimerObject *m_timer_object_queue; |
1143 | + TimerObject* timer_object_queue_; |
1144 | std::list<TimerObject*> _early_timer_objects; //!< timer objects that couldn't be started because the main loop is not runing yet. |
1145 | }; |
1146 | |
1147 | |
1148 | === modified file 'Nux/VScrollBar.cpp' |
1149 | --- Nux/VScrollBar.cpp 2012-01-02 20:56:41 +0000 |
1150 | +++ Nux/VScrollBar.cpp 2012-07-12 13:45:35 +0000 |
1151 | @@ -91,15 +91,15 @@ |
1152 | vlayout->AddView(_scroll_down_button, 0, eCenter, eFix); |
1153 | |
1154 | callback = new TimerFunctor; |
1155 | - callback->time_expires.connect(sigc::mem_fun(this, &VScrollBar::VScrollBarHandler)); |
1156 | + callback->tick.connect(sigc::mem_fun(this, &VScrollBar::VScrollBarHandler)); |
1157 | up_callback = new TimerFunctor; |
1158 | - up_callback->time_expires.connect(sigc::mem_fun(this, &VScrollBar::ScrollUp)); |
1159 | + up_callback->tick.connect(sigc::mem_fun(this, &VScrollBar::ScrollUp)); |
1160 | down_callback = new TimerFunctor; |
1161 | - down_callback->time_expires.connect(sigc::mem_fun(this, &VScrollBar::ScrollDown)); |
1162 | + down_callback->tick.connect(sigc::mem_fun(this, &VScrollBar::ScrollDown)); |
1163 | trackup_callback = new TimerFunctor; |
1164 | - trackup_callback->time_expires.connect(sigc::mem_fun(this, &VScrollBar::TrackUp)); |
1165 | + trackup_callback->tick.connect(sigc::mem_fun(this, &VScrollBar::TrackUp)); |
1166 | trackdown_callback = new TimerFunctor; |
1167 | - trackdown_callback->time_expires.connect(sigc::mem_fun(this, &VScrollBar::TrackDown)); |
1168 | + trackdown_callback->tick.connect(sigc::mem_fun(this, &VScrollBar::TrackDown)); |
1169 | |
1170 | SetLayout(vlayout); |
1171 | SetAcceptMouseWheelEvent(true); |
1172 | @@ -132,7 +132,7 @@ |
1173 | else |
1174 | { |
1175 | scrollbar->QueueDraw(); |
1176 | - GetTimer().AddTimerHandler(10, callback, scrollbar); |
1177 | + GetTimer().AddOneShotTimer(10, callback, scrollbar); |
1178 | } |
1179 | } |
1180 | |
1181 | @@ -148,7 +148,7 @@ |
1182 | else |
1183 | { |
1184 | scrollbar->QueueDraw(); |
1185 | - GetTimer().AddTimerHandler(10, callback, scrollbar); |
1186 | + GetTimer().AddOneShotTimer(10, callback, scrollbar); |
1187 | } |
1188 | } |
1189 | |
1190 | @@ -162,7 +162,7 @@ |
1191 | if (AtMaximum()) |
1192 | RecvEndScrollDown(0, 0, 0, 0); |
1193 | else |
1194 | - m_DownTimerHandler = GetTimer().AddTimerHandler(10, down_callback, this); |
1195 | + m_DownTimerHandler = GetTimer().AddOneShotTimer(10, down_callback, this); |
1196 | |
1197 | QueueDraw(); |
1198 | } |
1199 | @@ -174,7 +174,7 @@ |
1200 | if (AtMaximum()) |
1201 | RecvEndScrollUp(0, 0, 0, 0); |
1202 | else |
1203 | - m_UpTimerHandler = GetTimer().AddTimerHandler(10, up_callback, this); |
1204 | + m_UpTimerHandler = GetTimer().AddOneShotTimer(10, up_callback, this); |
1205 | |
1206 | QueueDraw(); |
1207 | } |
1208 | @@ -184,7 +184,7 @@ |
1209 | if (m_TrackMouseCoord.y < _slider->GetBaseY() - _track->GetBaseY()) |
1210 | { |
1211 | OnScrollUp.emit(container_height_, 1); |
1212 | - m_TrackUpTimerHandler = GetTimer().AddTimerHandler(10, trackup_callback, this); |
1213 | + m_TrackUpTimerHandler = GetTimer().AddOneShotTimer(10, trackup_callback, this); |
1214 | QueueDraw(); |
1215 | } |
1216 | } |
1217 | @@ -194,7 +194,7 @@ |
1218 | if (m_TrackMouseCoord.y > _slider->GetBaseY() + _slider->GetBaseHeight() - _track->GetBaseY()) |
1219 | { |
1220 | OnScrollDown.emit(container_height_, 1); |
1221 | - m_TrackDownTimerHandler = GetTimer().AddTimerHandler(10, trackdown_callback, this); |
1222 | + m_TrackDownTimerHandler = GetTimer().AddOneShotTimer(10, trackdown_callback, this); |
1223 | QueueDraw(); |
1224 | } |
1225 | } |
1226 | @@ -396,14 +396,14 @@ |
1227 | //sigVScrollBarSliderMouseDown.emit(); |
1228 | b_MouseDownTimer = true; |
1229 | b_MouseUpTimer = false; |
1230 | - GetTimer().AddTimerHandler(10, callback, this); |
1231 | + GetTimer().AddOneShotTimer(10, callback, this); |
1232 | } |
1233 | |
1234 | void VScrollBar::OnSliderMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags) |
1235 | { |
1236 | b_MouseDownTimer = false; |
1237 | b_MouseUpTimer = true; |
1238 | - GetTimer().AddTimerHandler(10, callback, this); |
1239 | + GetTimer().AddOneShotTimer(10, callback, this); |
1240 | } |
1241 | |
1242 | void VScrollBar::OnSliderMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags) |
1243 | |
1244 | === modified file 'Nux/WindowThread.cpp' |
1245 | --- Nux/WindowThread.cpp 2012-06-11 14:27:57 +0000 |
1246 | +++ Nux/WindowThread.cpp 2012-07-12 13:45:35 +0000 |
1247 | @@ -105,7 +105,7 @@ |
1248 | _inside_main_loop = false; |
1249 | _inside_timer_loop = false; |
1250 | async_wake_up_signal_ = new TimerFunctor(); |
1251 | - async_wake_up_signal_->time_expires.connect(sigc::mem_fun(this, &WindowThread::AsyncWakeUpCallback)); |
1252 | + async_wake_up_signal_->tick.connect(sigc::mem_fun(this, &WindowThread::AsyncWakeUpCallback)); |
1253 | } |
1254 | |
1255 | WindowThread::~WindowThread() |
1256 | @@ -152,7 +152,7 @@ |
1257 | return TimerHandle(); |
1258 | |
1259 | // Use "this->" because if called from a different thread, GetTimer and GetWindowThread are invalid. |
1260 | - TimerHandle handle = this->GetTimerHandler().AddTimerHandler(time_ms, timeout_signal, user_data, this); |
1261 | + TimerHandle handle = this->GetTimerHandler().AddOneShotTimer(time_ms, timeout_signal, user_data, this); |
1262 | |
1263 | return handle; |
1264 | } |
1265 | @@ -196,7 +196,7 @@ |
1266 | if ((_inside_main_loop == false) && (_inside_timer_loop == false) && (_pending_wake_up_timer == false)) |
1267 | { |
1268 | _pending_wake_up_timer = true; |
1269 | - async_wake_up_timer_handle_ = this->GetTimerHandler().AddTimerHandler(0, async_wake_up_signal_, this); |
1270 | + async_wake_up_timer_handle_ = this->GetTimerHandler().AddOneShotTimer(0, async_wake_up_signal_, this); |
1271 | } |
1272 | } |
1273 | } |