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