Nux

Merge lp:~unity-team/nux/nux-timer-backend-fixes into lp:nux

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
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
=== modified file 'Nux/AnimatedTextureArea.cpp'
--- Nux/AnimatedTextureArea.cpp 2012-06-26 13:59:18 +0000
+++ Nux/AnimatedTextureArea.cpp 2012-07-12 13:45:35 +0000
@@ -37,7 +37,7 @@
37 mouse_drag.connect(sigc::mem_fun(this, &AnimatedTextureArea::RecvMouseDrag));37 mouse_drag.connect(sigc::mem_fun(this, &AnimatedTextureArea::RecvMouseDrag));
3838
39 m_TimerFunctor = new TimerFunctor();39 m_TimerFunctor = new TimerFunctor();
40 m_TimerFunctor->time_expires.connect(sigc::mem_fun(this, &AnimatedTextureArea::TimerNextFrame));40 m_TimerFunctor->tick.connect(sigc::mem_fun(this, &AnimatedTextureArea::TimerNextFrame));
41 }41 }
4242
43 AnimatedTextureArea::~AnimatedTextureArea()43 AnimatedTextureArea::~AnimatedTextureArea()
@@ -106,7 +106,7 @@
106 m_TimerHandler = 0;106 m_TimerHandler = 0;
107 }107 }
108108
109 m_TimerHandler = GetTimer().AddTimerHandler(41, m_TimerFunctor, 0);109 m_TimerHandler = GetTimer().AddOneShotTimer(41, m_TimerFunctor, 0);
110 QueueDraw();110 QueueDraw();
111 }111 }
112112
@@ -128,7 +128,7 @@
128 ObjectPtr<IOpenGLBaseTexture> Texture2D = Texture->m_Texture; //Texture->m_Texture.CastRef<IOpenGLAnimatedTexture>();128 ObjectPtr<IOpenGLBaseTexture> Texture2D = Texture->m_Texture; //Texture->m_Texture.CastRef<IOpenGLAnimatedTexture>();
129129
130 AnimatedTexture->PresentNextFrame();130 AnimatedTexture->PresentNextFrame();
131 m_TimerHandler = GetTimer().AddTimerHandler(41, m_TimerFunctor, 0);131 m_TimerHandler = GetTimer().AddOneShotTimer(41, m_TimerFunctor, 0);
132 }132 }
133133
134 QueueDraw();134 QueueDraw();
135135
=== modified file 'Nux/ColorPreview.cpp'
--- Nux/ColorPreview.cpp 2011-10-17 20:57:35 +0000
+++ Nux/ColorPreview.cpp 2012-07-12 13:45:35 +0000
@@ -61,7 +61,7 @@
61 SetCompositionLayout(m_hlayout);61 SetCompositionLayout(m_hlayout);
6262
63 m_ChangeDetectionTimer = new TimerFunctor();63 m_ChangeDetectionTimer = new TimerFunctor();
64 m_ChangeDetectionTimer->time_expires.connect(sigc::mem_fun(this, &ColorPreview::RecvTimer));64 m_ChangeDetectionTimer->tick.connect(sigc::mem_fun(this, &ColorPreview::RecvTimer));
65 m_ChangeTimerHandler = 0;65 m_ChangeTimerHandler = 0;
66 }66 }
6767
@@ -100,7 +100,7 @@
100 m_DialogThreadProxy->SetColor(m_Color);100 m_DialogThreadProxy->SetColor(m_Color);
101 m_DialogThreadProxy->Start();101 m_DialogThreadProxy->Start();
102102
103 m_ChangeTimerHandler = GetTimer().AddTimerHandler(33, m_ChangeDetectionTimer, this);103 m_ChangeTimerHandler = GetTimer().AddOneShotTimer(33, m_ChangeDetectionTimer, this);
104 }104 }
105105
106 void ColorPreview::RecvTimer(void *v)106 void ColorPreview::RecvTimer(void *v)
@@ -114,7 +114,7 @@
114114
115 if (m_DialogThreadProxy->IsActive())115 if (m_DialogThreadProxy->IsActive())
116 {116 {
117 m_ChangeTimerHandler = GetTimer().AddTimerHandler(33, m_ChangeDetectionTimer, this);117 m_ChangeTimerHandler = GetTimer().AddOneShotTimer(33, m_ChangeDetectionTimer, this);
118 }118 }
119 else119 else
120 {120 {
121121
=== modified file 'Nux/EditTextBox.cpp'
--- Nux/EditTextBox.cpp 2011-12-14 02:01:43 +0000
+++ Nux/EditTextBox.cpp 2012-07-12 13:45:35 +0000
@@ -70,10 +70,10 @@
70 SetLayout(hlayout);70 SetLayout(hlayout);
7171
72 m_BlinkTimerFunctor = new TimerFunctor();72 m_BlinkTimerFunctor = new TimerFunctor();
73 m_BlinkTimerFunctor->time_expires.connect(sigc::mem_fun(this, &EditTextBox::BlinkCursorTimerInterrupt));73 m_BlinkTimerFunctor->tick.connect(sigc::mem_fun(this, &EditTextBox::BlinkCursorTimerInterrupt));
7474
75 m_ScrollTimerFunctor = new TimerFunctor();75 m_ScrollTimerFunctor = new TimerFunctor();
76 m_ScrollTimerFunctor->time_expires.connect(sigc::mem_fun(this, &EditTextBox::ScrollTimerInterrupt));76 m_ScrollTimerFunctor->tick.connect(sigc::mem_fun(this, &EditTextBox::ScrollTimerInterrupt));
7777
78 SetAcceptKeyboardEvent(true);78 SetAcceptKeyboardEvent(true);
79 EnableDoubleClick(true);79 EnableDoubleClick(true);
@@ -102,7 +102,7 @@
102 if (((X < base.x) && (m_KeyboardHandler.GetCursorPosition() > 0)) ||102 if (((X < base.x) && (m_KeyboardHandler.GetCursorPosition() > 0)) ||
103 ((X > base.x + base.GetWidth()) && (m_KeyboardHandler.GetCursorPosition() < m_KeyboardHandler.GetLength())))103 ((X > base.x + base.GetWidth()) && (m_KeyboardHandler.GetCursorPosition() < m_KeyboardHandler.GetLength())))
104 {104 {
105 m_ScrollTimerHandler = GetTimer().AddTimerHandler(50, m_ScrollTimerFunctor, this);105 m_ScrollTimerHandler = GetTimer().AddOneShotTimer(50, m_ScrollTimerFunctor, this);
106 }106 }
107 else107 else
108 {108 {
@@ -120,7 +120,7 @@
120 void EditTextBox::BlinkCursorTimerInterrupt(void *v)120 void EditTextBox::BlinkCursorTimerInterrupt(void *v)
121 {121 {
122 GetTimer().RemoveTimerHandler(m_BlinkTimerHandler);122 GetTimer().RemoveTimerHandler(m_BlinkTimerHandler);
123 m_BlinkTimerHandler = GetTimer().AddTimerHandler(500, m_BlinkTimerFunctor, this);123 m_BlinkTimerHandler = GetTimer().AddOneShotTimer(500, m_BlinkTimerFunctor, this);
124 BlinkCursor = !BlinkCursor;124 BlinkCursor = !BlinkCursor;
125 QueueDraw();125 QueueDraw();
126 }126 }
@@ -135,7 +135,7 @@
135135
136 void EditTextBox::StartBlinkCursor(bool BlinkState)136 void EditTextBox::StartBlinkCursor(bool BlinkState)
137 {137 {
138 m_BlinkTimerHandler = GetTimer().AddTimerHandler(500, m_BlinkTimerFunctor, this);138 m_BlinkTimerHandler = GetTimer().AddOneShotTimer(500, m_BlinkTimerFunctor, this);
139 BlinkCursor = BlinkState;139 BlinkCursor = BlinkState;
140 QueueDraw();140 QueueDraw();
141 }141 }
@@ -292,7 +292,7 @@
292292
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())))
294 {294 {
295 m_ScrollTimerHandler = GetTimer().AddTimerHandler(25, m_ScrollTimerFunctor, this);295 m_ScrollTimerHandler = GetTimer().AddOneShotTimer(25, m_ScrollTimerFunctor, this);
296 }296 }
297 else if ((X >= base.x) && (X < base.x + base.GetWidth()))297 else if ((X >= base.x) && (X < base.x + base.GetWidth()))
298 {298 {
@@ -439,7 +439,7 @@
439 text_input_mode_ = false;439 text_input_mode_ = false;
440 440
441 EnteringKeyboardFocus();441 EnteringKeyboardFocus();
442 m_BlinkTimerHandler = GetTimer().AddTimerHandler(500, m_BlinkTimerFunctor, this);442 m_BlinkTimerHandler = GetTimer().AddOneShotTimer(500, m_BlinkTimerFunctor, this);
443 }443 }
444444
445 void EditTextBox::RecvEndKeyFocus()445 void EditTextBox::RecvEndKeyFocus()
446446
=== modified file 'Nux/HScrollBar.cpp'
--- Nux/HScrollBar.cpp 2011-10-17 20:57:35 +0000
+++ Nux/HScrollBar.cpp 2012-07-12 13:45:35 +0000
@@ -90,15 +90,15 @@
90 hlayout->AddView(_scroll_right_button, 0, eCenter, eFix);90 hlayout->AddView(_scroll_right_button, 0, eCenter, eFix);
9191
92 callback = new TimerFunctor;92 callback = new TimerFunctor;
93 callback->time_expires.connect(sigc::mem_fun(this, &HScrollBar::HScrollBarHandler));93 callback->tick.connect(sigc::mem_fun(this, &HScrollBar::HScrollBarHandler));
94 left_callback = new TimerFunctor;94 left_callback = new TimerFunctor;
95 left_callback->time_expires.connect(sigc::mem_fun(this, &HScrollBar::ScrollLeft));95 left_callback->tick.connect(sigc::mem_fun(this, &HScrollBar::ScrollLeft));
96 right_callback = new TimerFunctor;96 right_callback = new TimerFunctor;
97 right_callback->time_expires.connect(sigc::mem_fun(this, &HScrollBar::ScrollRight));97 right_callback->tick.connect(sigc::mem_fun(this, &HScrollBar::ScrollRight));
98 trackleft_callback = new TimerFunctor;98 trackleft_callback = new TimerFunctor;
99 trackleft_callback->time_expires.connect(sigc::mem_fun(this, &HScrollBar::TrackLeft));99 trackleft_callback->tick.connect(sigc::mem_fun(this, &HScrollBar::TrackLeft));
100 trackright_callback = new TimerFunctor;100 trackright_callback = new TimerFunctor;
101 trackright_callback->time_expires.connect(sigc::mem_fun(this, &HScrollBar::TrackRight));101 trackright_callback->tick.connect(sigc::mem_fun(this, &HScrollBar::TrackRight));
102102
103 SetLayout(hlayout);103 SetLayout(hlayout);
104 SetAcceptMouseWheelEvent(true);104 SetAcceptMouseWheelEvent(true);
@@ -130,7 +130,7 @@
130 else130 else
131 {131 {
132 scrollbar->QueueDraw();132 scrollbar->QueueDraw();
133 GetTimer().AddTimerHandler(10, callback, scrollbar);133 GetTimer().AddOneShotTimer(10, callback, scrollbar);
134 }134 }
135 }135 }
136136
@@ -146,7 +146,7 @@
146 else146 else
147 {147 {
148 scrollbar->QueueDraw();148 scrollbar->QueueDraw();
149 GetTimer().AddTimerHandler(10, callback, scrollbar);149 GetTimer().AddOneShotTimer(10, callback, scrollbar);
150 }150 }
151 }151 }
152 }152 }
@@ -158,7 +158,7 @@
158 if (AtMaximum())158 if (AtMaximum())
159 RecvEndScrollRight(0, 0, 0, 0);159 RecvEndScrollRight(0, 0, 0, 0);
160 else160 else
161 m_RightTimerHandler = GetTimer().AddTimerHandler(10, right_callback, this);161 m_RightTimerHandler = GetTimer().AddOneShotTimer(10, right_callback, this);
162162
163 QueueDraw();163 QueueDraw();
164 }164 }
@@ -170,7 +170,7 @@
170 if (AtMaximum())170 if (AtMaximum())
171 RecvEndScrollLeft(0, 0, 0, 0);171 RecvEndScrollLeft(0, 0, 0, 0);
172 else172 else
173 m_LeftTimerHandler = GetTimer().AddTimerHandler(10, left_callback, this);173 m_LeftTimerHandler = GetTimer().AddOneShotTimer(10, left_callback, this);
174174
175 QueueDraw();175 QueueDraw();
176 }176 }
@@ -180,7 +180,7 @@
180 if (m_TrackMouseCoord.x < _slider->GetBaseX() - _track->GetBaseX())180 if (m_TrackMouseCoord.x < _slider->GetBaseX() - _track->GetBaseX())
181 {181 {
182 OnScrollLeft.emit(container_width_, 1);182 OnScrollLeft.emit(container_width_, 1);
183 m_TrackLeftTimerHandler = GetTimer().AddTimerHandler(10, trackleft_callback, this);183 m_TrackLeftTimerHandler = GetTimer().AddOneShotTimer(10, trackleft_callback, this);
184 QueueDraw();184 QueueDraw();
185 }185 }
186 }186 }
@@ -190,7 +190,7 @@
190 if (m_TrackMouseCoord.x > _slider->GetBaseX() + _slider->GetBaseWidth() - _track->GetBaseX())190 if (m_TrackMouseCoord.x > _slider->GetBaseX() + _slider->GetBaseWidth() - _track->GetBaseX())
191 {191 {
192 OnScrollRight.emit(container_width_, 1);192 OnScrollRight.emit(container_width_, 1);
193 m_TrackRightTimerHandler = GetTimer().AddTimerHandler(10, trackright_callback, this);193 m_TrackRightTimerHandler = GetTimer().AddOneShotTimer(10, trackright_callback, this);
194 QueueDraw();194 QueueDraw();
195 }195 }
196 }196 }
@@ -377,14 +377,14 @@
377 //sigVScrollBarSliderMouseDown.emit();377 //sigVScrollBarSliderMouseDown.emit();
378 b_MouseDownTimer = true;378 b_MouseDownTimer = true;
379 b_MouseUpTimer = false;379 b_MouseUpTimer = false;
380 GetTimer().AddTimerHandler(10, callback, this);380 GetTimer().AddOneShotTimer(10, callback, this);
381 }381 }
382382
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)
384 {384 {
385 b_MouseDownTimer = false;385 b_MouseDownTimer = false;
386 b_MouseUpTimer = true;386 b_MouseUpTimer = true;
387 GetTimer().AddTimerHandler(10, callback, this);387 GetTimer().AddOneShotTimer(10, callback, this);
388 }388 }
389389
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)
391391
=== modified file 'Nux/MainLoopGLib.cpp'
--- Nux/MainLoopGLib.cpp 2011-12-22 06:23:58 +0000
+++ Nux/MainLoopGLib.cpp 2012-07-12 13:45:35 +0000
@@ -289,7 +289,7 @@
289 return 0;289 return 0;
290 }290 }
291291
292 GSource *timeout_source;292 GSource* timeout_source;
293293
294 //create a new time-out source294 //create a new time-out source
295 timeout_source = g_timeout_source_new(duration);295 timeout_source = g_timeout_source_new(duration);
296296
=== modified file 'Nux/NumericValuator.cpp'
--- Nux/NumericValuator.cpp 2011-10-10 01:52:00 +0000
+++ Nux/NumericValuator.cpp 2012-07-12 13:45:35 +0000
@@ -131,7 +131,7 @@
131131
132 if (m_fValue < m_DoubleValidator.GetMaximum())132 if (m_fValue < m_DoubleValidator.GetMaximum())
133 {133 {
134 m_UpTimerHandler = GetTimer().AddTimerHandler(100, m_UpTimerCallback, 0);134 m_UpTimerHandler = GetTimer().AddOneShotTimer(100, m_UpTimerCallback, 0);
135 QueueDraw();135 QueueDraw();
136 }136 }
137 }137 }
@@ -144,7 +144,7 @@
144144
145 if (m_fValue > m_DoubleValidator.GetMinimum())145 if (m_fValue > m_DoubleValidator.GetMinimum())
146 {146 {
147 m_DownTimerHandler = GetTimer().AddTimerHandler(100, m_DownTimerCallback, 0);147 m_DownTimerHandler = GetTimer().AddOneShotTimer(100, m_DownTimerCallback, 0);
148 QueueDraw();148 QueueDraw();
149 }149 }
150 }150 }
151151
=== modified file 'Nux/ProgramFramework/ProgramTemplate.cpp'
--- Nux/ProgramFramework/ProgramTemplate.cpp 2012-01-27 22:37:13 +0000
+++ Nux/ProgramFramework/ProgramTemplate.cpp 2012-07-12 13:45:35 +0000
@@ -89,8 +89,8 @@
89 if (program_life_span_ > 0)89 if (program_life_span_ > 0)
90 {90 {
91 timeout_signal_ = new nux::TimeOutSignal();91 timeout_signal_ = new nux::TimeOutSignal();
92 timeout_signal_->time_expires.connect(sigc::mem_fun(this, &ProgramTemplate::ProgramExitCall));92 timeout_signal_->tick.connect(sigc::mem_fun(this, &ProgramTemplate::ProgramExitCall));
93 window_thread_->GetTimerHandler().AddTimerHandler(program_life_span_, timeout_signal_, NULL, NULL);93 window_thread_->GetTimerHandler().AddOneShotTimer(program_life_span_, timeout_signal_, NULL, NULL);
94 }94 }
9595
96 window_thread_->Run(NULL);96 window_thread_->Run(NULL);
9797
=== modified file 'Nux/SpinBox.cpp'
--- Nux/SpinBox.cpp 2011-10-10 01:52:00 +0000
+++ Nux/SpinBox.cpp 2012-07-12 13:45:35 +0000
@@ -187,9 +187,9 @@
187 if (m_iValue < m_IntValidator.GetMaximum())187 if (m_iValue < m_IntValidator.GetMaximum())
188 {188 {
189 if (m_UpTimerHandler.IsValid())189 if (m_UpTimerHandler.IsValid())
190 m_UpTimerHandler = GetTimer().AddTimerHandler(100, m_UpTimerCallback, 0);190 m_UpTimerHandler = GetTimer().AddOneShotTimer(100, m_UpTimerCallback, 0);
191 else191 else
192 m_UpTimerHandler = GetTimer().AddTimerHandler(800, m_UpTimerCallback, 0);192 m_UpTimerHandler = GetTimer().AddOneShotTimer(800, m_UpTimerCallback, 0);
193193
194 QueueDraw();194 QueueDraw();
195 }195 }
@@ -206,9 +206,9 @@
206 if (m_iValue > m_IntValidator.GetMinimum())206 if (m_iValue > m_IntValidator.GetMinimum())
207 {207 {
208 if (m_DownTimerHandler.IsValid())208 if (m_DownTimerHandler.IsValid())
209 m_DownTimerHandler = GetTimer().AddTimerHandler(100, m_DownTimerCallback, 0);209 m_DownTimerHandler = GetTimer().AddOneShotTimer(100, m_DownTimerCallback, 0);
210 else210 else
211 m_DownTimerHandler = GetTimer().AddTimerHandler(800, m_DownTimerCallback, 0);211 m_DownTimerHandler = GetTimer().AddOneShotTimer(800, m_DownTimerCallback, 0);
212212
213 QueueDraw();213 QueueDraw();
214 }214 }
215215
=== modified file 'Nux/SpinBoxDouble.cpp'
--- Nux/SpinBoxDouble.cpp 2011-10-10 01:52:00 +0000
+++ Nux/SpinBoxDouble.cpp 2012-07-12 13:45:35 +0000
@@ -194,9 +194,9 @@
194 if (m_Value < m_DoubleValidator.GetMaximum())194 if (m_Value < m_DoubleValidator.GetMaximum())
195 {195 {
196 if (m_UpTimerHandler.IsValid())196 if (m_UpTimerHandler.IsValid())
197 m_UpTimerHandler = GetTimer().AddTimerHandler(100, m_UpTimerCallback, 0);197 m_UpTimerHandler = GetTimer().AddOneShotTimer(100, m_UpTimerCallback, 0);
198 else198 else
199 m_UpTimerHandler = GetTimer().AddTimerHandler(800, m_UpTimerCallback, 0);199 m_UpTimerHandler = GetTimer().AddOneShotTimer(800, m_UpTimerCallback, 0);
200200
201 QueueDraw();201 QueueDraw();
202 }202 }
@@ -213,9 +213,9 @@
213 if (m_Value > m_DoubleValidator.GetMinimum())213 if (m_Value > m_DoubleValidator.GetMinimum())
214 {214 {
215 if (m_DownTimerHandler.IsValid())215 if (m_DownTimerHandler.IsValid())
216 m_DownTimerHandler = GetTimer().AddTimerHandler(100, m_DownTimerCallback, 0);216 m_DownTimerHandler = GetTimer().AddOneShotTimer(100, m_DownTimerCallback, 0);
217 else217 else
218 m_DownTimerHandler = GetTimer().AddTimerHandler(800, m_DownTimerCallback, 0);218 m_DownTimerHandler = GetTimer().AddOneShotTimer(800, m_DownTimerCallback, 0);
219219
220 QueueDraw();220 QueueDraw();
221 }221 }
222222
=== modified file 'Nux/SpinBox_Logic.cpp'
--- Nux/SpinBox_Logic.cpp 2011-10-17 20:57:35 +0000
+++ Nux/SpinBox_Logic.cpp 2012-07-12 13:45:35 +0000
@@ -64,9 +64,9 @@
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));
6565
66 m_UpTimerCallback = new TimerFunctor;66 m_UpTimerCallback = new TimerFunctor;
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));
68 m_DownTimerCallback = new TimerFunctor;68 m_DownTimerCallback = new TimerFunctor;
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));
70 }70 }
7171
72 SpinBox_Logic::~SpinBox_Logic()72 SpinBox_Logic::~SpinBox_Logic()
7373
=== modified file 'Nux/TabView.cpp'
--- Nux/TabView.cpp 2011-10-21 22:06:35 +0000
+++ Nux/TabView.cpp 2012-07-12 13:45:35 +0000
@@ -123,9 +123,9 @@
123123
124124
125 tabright_callback = new TimerFunctor;125 tabright_callback = new TimerFunctor;
126 tabright_callback->time_expires.connect(sigc::mem_fun(this, &TabView::RecvTabRightTimerExpired));126 tabright_callback->tick.connect(sigc::mem_fun(this, &TabView::RecvTabRightTimerExpired));
127 tableft_callback = new TimerFunctor;127 tableft_callback = new TimerFunctor;
128 tableft_callback->time_expires.connect(sigc::mem_fun(this, &TabView::RecvTabLeftTimerExpired));128 tableft_callback->tick.connect(sigc::mem_fun(this, &TabView::RecvTabLeftTimerExpired));
129 }129 }
130130
131 TabView::~TabView()131 TabView::~TabView()
@@ -518,13 +518,13 @@
518 void TabView::RecvTabRightTimerExpired(void *v)518 void TabView::RecvTabRightTimerExpired(void *v)
519 {519 {
520 TranslateTabLayout(-10);520 TranslateTabLayout(-10);
521 m_TabRightTimerHandler = GetTimer().AddTimerHandler(10, tabright_callback, this);521 m_TabRightTimerHandler = GetTimer().AddOneShotTimer(10, tabright_callback, this);
522 }522 }
523523
524 void TabView::RecvTabLeftTimerExpired(void *v)524 void TabView::RecvTabLeftTimerExpired(void *v)
525 {525 {
526 TranslateTabLayout(10);526 TranslateTabLayout(10);
527 m_TabLeftTimerHandler = GetTimer().AddTimerHandler(10, tableft_callback, this);527 m_TabLeftTimerHandler = GetTimer().AddOneShotTimer(10, tableft_callback, this);
528 }528 }
529529
530 bool TabView::AcceptKeyNavFocus()530 bool TabView::AcceptKeyNavFocus()
531531
=== modified file 'Nux/TimerProc.cpp'
--- Nux/TimerProc.cpp 2011-12-29 18:06:53 +0000
+++ Nux/TimerProc.cpp 2012-07-12 13:45:35 +0000
@@ -55,6 +55,7 @@
5555
56 //! Delay before the callback expires56 //! Delay before the callback expires
57 TimeStruct when;57 TimeStruct when;
58 gint64 ms_time; // milliseconds
58 void *CallbackData;59 void *CallbackData;
59 TimeOutSignal *timeout_signal;60 TimeOutSignal *timeout_signal;
6061
@@ -67,16 +68,18 @@
67 int Period; //!< The periode of the timer interuption(in milliseconds).68 int Period; //!< The periode of the timer interuption(in milliseconds).
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);
69 int ElapsedTime; //!< Elapsed time during execution(in milliseconds).70 int ElapsedTime; //!< Elapsed time during execution(in milliseconds).
70 bool MarkedForRemoval;71 bool marked_for_removal_;
71 BaseWindow *Window; //!< BaseWindow from where the timer was created.72 BaseWindow *Window; //!< BaseWindow from where the timer was created.
72 TimerObject *next;73 TimerObject *next;
73 TimerObject *prev;74 TimerObject *prev;
74 unsigned int glibid;75 unsigned int glibid;
75 unsigned int uid;76 unsigned int uid;
77 TimerHandler::TimerState state_;
76 };78 };
7779
78 TimerObject::TimerObject()80 TimerObject::TimerObject()
79 {81 {
82 ms_time = 0;
80 Type = 0;83 Type = 0;
81 CallbackData = 0;84 CallbackData = 0;
82 timeout_signal = 0;85 timeout_signal = 0;
@@ -86,12 +89,13 @@
86 ElapsedTime = 0;89 ElapsedTime = 0;
87 ScheduledIteration = 0;90 ScheduledIteration = 0;
88 ProgressIterationCount = 0;91 ProgressIterationCount = 0;
89 MarkedForRemoval = 0;92 marked_for_removal_ = 0;
90 Window = 0;93 Window = 0;
91 next = 0;94 next = 0;
92 prev = 0;95 prev = 0;
93 glibid = 0;96 glibid = 0;
94 uid = 0;97 uid = 0;
98 state_ = TimerHandler::TIMER_STATE_STOPED;
95 }99 }
96100
97 TimerHandle::TimerHandle()101 TimerHandle::TimerHandle()
@@ -168,14 +172,13 @@
168////////////////////////////////////////////////////172////////////////////////////////////////////////////
169 TimerHandler::TimerHandler(WindowThread* window_thread)173 TimerHandler::TimerHandler(WindowThread* window_thread)
170 : window_thread_(window_thread)174 : window_thread_(window_thread)
175 , is_processing_timers_(false)
176 , timer_object_queue_(NULL)
171 {177 {
172 m_timer_object_queue = 0;
173 m_IsProceesingTimers = false;
174 }178 }
175179
176 TimerHandler::~TimerHandler()180 TimerHandler::~TimerHandler()
177 {181 {
178
179 }182 }
180183
181 void TimerHandler::StartEarlyTimerObjects()184 void TimerHandler::StartEarlyTimerObjects()
@@ -184,8 +187,7 @@
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++)
185 {188 {
186 TimerObject *timer_object = *it;189 TimerObject *timer_object = *it;
187 TimeRightNow(&timer_object->when);190 timer_object->ms_time = g_get_monotonic_time() / 1000;
188 Addmillisecs(&timer_object->when, timer_object->Period);
189191
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))
191 timer_object->glibid = GetWindowThread()->AddTimeout(timer_object->Period);193 timer_object->glibid = GetWindowThread()->AddTimeout(timer_object->Period);
@@ -195,17 +197,17 @@
195 _early_timer_objects.clear();197 _early_timer_objects.clear();
196 }198 }
197199
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)
199 {201 {
200 TimerObject *timer_object = new TimerObject();202 TimerObject *timer_object = new TimerObject();
201203
202 TimeRightNow(&timer_object->when);204 timer_object->ms_time = g_get_monotonic_time() / 1000;
203 Addmillisecs(&timer_object->when, Period);
204205
205 timer_object->CallbackData = Data;206 timer_object->CallbackData = Data;
206 timer_object->timeout_signal = timeout_signal;207 timer_object->timeout_signal = timeout_signal;
207 timer_object->Period = Period;208 timer_object->Period = Period;
208 timer_object->Type = TIMERTYPE_PERIODIC;209 timer_object->Type = TIMERTYPE_PERIODIC;
210 timer_object->state_ = TimerHandler::TIMER_STATE_RUNNING;
209 if (window_thread)211 if (window_thread)
210 timer_object->Window = window_thread->GetWindowCompositor().GetProcessingTopView();212 timer_object->Window = window_thread->GetWindowCompositor().GetProcessingTopView();
211 else213 else
@@ -225,10 +227,10 @@
225 _early_timer_objects.push_back(timer_object);227 _early_timer_objects.push_back(timer_object);
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.
227 // Sometimes later, this timer will be examined when ExecTimerHandler is called.229 // Sometimes later, this timer will be examined when ExecTimerHandler is called.
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.
229 }231 }
230232
231 //nuxDebugMsg("[TimerHandler::AddTimerHandler] Adding Timeout ID: %d", timer_object->glibid);233 //nuxDebugMsg("[TimerHandler::AddOneShotTimer] Adding Timeout ID: %d", timer_object->glibid);
232 }234 }
233#endif235#endif
234236
@@ -236,17 +238,18 @@
236 return handle;238 return handle;
237 }239 }
238240
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)
240 {242 {
241 TimerObject *timer_object = new TimerObject();243 TimerObject* timer_object = new TimerObject();
242 TimeRightNow(&timer_object->when);244
243 Addmillisecs(&timer_object->when, Period);245 timer_object->ms_time = g_get_monotonic_time() / 1000;
244 timer_object->CallbackData = Data;246 timer_object->CallbackData = Data;
245 timer_object->timeout_signal = timeout_signal;247 timer_object->timeout_signal = timeout_signal;
246248
247 timer_object->Period = Period;249 timer_object->Period = Period;
248 timer_object->Duration = (Duration < 0) ? -1 : Duration;250 timer_object->Duration = (Duration < 0) ? -1 : Duration;
249 timer_object->Type = TIMERTYPE_DURATION;251 timer_object->Type = TIMERTYPE_DURATION;
252 timer_object->state_ = TimerHandler::TIMER_STATE_RUNNING;
250 AddHandle(timer_object);253 AddHandle(timer_object);
251254
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))
@@ -261,7 +264,7 @@
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.
262 }265 }
263266
264 //nuxDebugMsg("[TimerHandler::AddTimerHandler] Adding Timeout ID: %d", timer_object->glibid);267 //nuxDebugMsg("[TimerHandler::AddOneShotTimer] Adding Timeout ID: %d", timer_object->glibid);
265 }268 }
266#endif269#endif
267270
@@ -269,17 +272,18 @@
269 return handle;272 return handle;
270 }273 }
271274
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)
273 {276 {
274 TimerObject *timer_object = new TimerObject();277 TimerObject* timer_object = new TimerObject();
275 TimeRightNow(&timer_object->when);278
276 Addmillisecs(&timer_object->when, Period);279 timer_object->ms_time = g_get_monotonic_time() / 1000;
277 timer_object->CallbackData = Data;280 timer_object->CallbackData = Data;
278 timer_object->timeout_signal = timeout_signal;281 timer_object->timeout_signal = timeout_signal;
279282
280 timer_object->Period = Period;283 timer_object->Period = Period;
281 timer_object->ScheduledIteration = (NumberOfIterations < 0) ? -1 : NumberOfIterations;284 timer_object->ScheduledIteration = (NumberOfIterations < 0) ? -1 : NumberOfIterations;
282 timer_object->Type = TIMERTYPE_ITERATION;285 timer_object->Type = TIMERTYPE_ITERATION;
286 timer_object->state_ = TimerHandler::TIMER_STATE_RUNNING;
283 AddHandle(timer_object);287 AddHandle(timer_object);
284288
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))
@@ -294,7 +298,7 @@
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.
295 }299 }
296300
297 //nuxDebugMsg("[TimerHandler::AddTimerHandler] Adding Timeout ID: %d", timer_object->glibid);301 //nuxDebugMsg("[TimerHandler::AddOneShotTimer] Adding Timeout ID: %d", timer_object->glibid);
298 }302 }
299#endif303#endif
300 TimerHandle handle(timer_object);304 TimerHandle handle(timer_object);
@@ -302,7 +306,7 @@
302 }306 }
303307
304// Sort timers and add them to the queue308// Sort timers and add them to the queue
305 TimerObject *TimerHandler::AddHandle(TimerObject *timer_object)309 TimerObject *TimerHandler::AddHandle(TimerObject* timer_object)
306 {310 {
307 if (timer_object == NULL)311 if (timer_object == NULL)
308 return NULL;312 return NULL;
@@ -313,26 +317,26 @@
313317
314 // If the queue is empty or the new timer will expire sooner than the first timer in the queue318 // If the queue is empty or the new timer will expire sooner than the first timer in the queue
315 // then add the new timer at the start of the queue.319 // then add the new timer at the start of the queue.
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))
317 {321 {
318 // Add the timer timer_object at the head of the queue322 // Add the timer timer_object at the head of the queue
319 timer_object->next = m_timer_object_queue;323 timer_object->next = timer_object_queue_;
320324
321 if (m_timer_object_queue)325 if (timer_object_queue_)
322 m_timer_object_queue->prev = timer_object;326 timer_object_queue_->prev = timer_object;
323327
324 timer_object->prev = 0;328 timer_object->prev = 0;
325 m_timer_object_queue = timer_object;329 timer_object_queue_ = timer_object;
326330
327 return timer_object;331 return timer_object;
328 }332 }
329333
330 TimerObject *tmp = m_timer_object_queue;334 TimerObject *tmp = timer_object_queue_;
331335
332 while (tmp->next != NULL)336 while (tmp->next != NULL)
333 {337 {
334 // Is the time to wait for tmp->next to expire smaller than for timer_object338 // Is the time to wait for tmp->next to expire smaller than for timer_object
335 if (TimeIsGreater(timer_object->when, tmp->next->when))339 if (timer_object->ms_time > tmp->next->ms_time)
336 {340 {
337 // keep searching341 // keep searching
338 tmp = tmp->next;342 tmp = tmp->next;
@@ -356,7 +360,7 @@
356 unsigned int TimerHandler::GetNumPendingHandler()360 unsigned int TimerHandler::GetNumPendingHandler()
357 {361 {
358 unsigned int count = 0;362 unsigned int count = 0;
359 TimerObject *head = m_timer_object_queue;363 TimerObject *head = timer_object_queue_;
360364
361 while (head)365 while (head)
362 {366 {
@@ -367,20 +371,20 @@
367 return count;371 return count;
368 }372 }
369373
370 bool TimerHandler::RemoveTimerHandler(TimerHandle &timer_object)374 bool TimerHandler::RemoveTimerHandler(TimerHandle &handle)
371 {375 {
372 NUX_RETURN_VALUE_IF_NULL(timer_object.m_d, false);376 NUX_RETURN_VALUE_IF_NULL(handle.m_d, false);
373 NUX_RETURN_VALUE_IF_NULL(m_timer_object_queue, false);377 NUX_RETURN_VALUE_IF_NULL(timer_object_queue_, false);
374378
375 TimerObject *tmp;379 TimerObject* tmp;
376380
377 tmp = m_timer_object_queue;381 tmp = timer_object_queue_;
378382
379 while (tmp)383 while (tmp)
380 {384 {
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))
382 {386 {
383 if (!m_IsProceesingTimers)387 if (!is_processing_timers_)
384 {388 {
385 if (tmp->next)389 if (tmp->next)
386 tmp->next->prev = tmp->prev;390 tmp->next->prev = tmp->prev;
@@ -388,63 +392,138 @@
388 if (tmp->prev)392 if (tmp->prev)
389 tmp->prev->next = tmp->next;393 tmp->prev->next = tmp->next;
390394
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))
392 m_timer_object_queue = timer_object.m_d->next;396 timer_object_queue_ = handle.m_d->next;
393397
394 NUX_SAFE_DELETE(timer_object.m_d);398 NUX_SAFE_DELETE(handle.m_d);
395 }399 }
396 else400 else
397 {401 {
398 timer_object.m_d->MarkedForRemoval = true;402 handle.m_d->marked_for_removal_ = true;
399 }403 }
400404
401 return true;405 return true;
402 }406 }
403407
404 tmp = tmp->next;408 tmp = tmp->next;
405 }409 }
406410
407 return false;411 return false;
408 }412 }
409413
410#if (defined(NUX_OS_LINUX) || defined(NUX_USE_GLIB_LOOP_ON_WINDOWS)) && (!defined(NUX_DISABLE_GLIB_LOOP))414 bool TimerHandler::PauseTimer(TimerHandle& handle)
415 {
416 NUX_RETURN_VALUE_IF_NULL(handle.m_d, false);
417 NUX_RETURN_VALUE_IF_NULL(timer_object_queue_, false);
418
419 if (handle.m_d->state_ != TimerHandler::TIMER_STATE_RUNNING)
420 {
421 return false;
422 }
423
424 TimerObject* tmp;
425
426 // Pointer to the start of the queue.
427 tmp = timer_object_queue_;
428
429 // Search for the timer handle
430 while (tmp)
431 {
432 if ((tmp == handle.m_d) && (tmp->uid == handle.m_d->uid))
433 {
434 handle.m_d->state_ = TimerHandler::TIMER_STATE_PAUSED;
435
436
437 if (!is_processing_timers_)
438 {
439 gint64 ms_time_now = g_get_monotonic_time() / 1000;
440
441 if (handle.m_d->Type == TIMERTYPE_PERIODIC)
442 {
443 handle.m_d->ElapsedTime += (ms_time_now - handle.m_d->ms_time);
444 handle.m_d->ProgressDelta = float(handle.m_d->ElapsedTime) / float(handle.m_d->Period);
445
446 if (handle.m_d->Param + handle.m_d->ProgressDelta > 1.0f)
447 handle.m_d->ProgressDelta = 1.0f - handle.m_d->Param;
448
449 handle.m_d->Param = float(handle.m_d->ElapsedTime) / float(handle.m_d->Period);
450 }
451 }
452
453 return true;
454 }
455
456 tmp = tmp->next;
457 }
458 return false;
459 }
460
461 bool TimerHandler::ResumeTimer(TimerHandle& handle)
462 {
463 NUX_RETURN_VALUE_IF_NULL(handle.m_d, false);
464 NUX_RETURN_VALUE_IF_NULL(timer_object_queue_, false);
465
466 if (handle.m_d->state_ != TimerHandler::TIMER_STATE_PAUSED)
467 {
468 return false;
469 }
470
471 TimerObject* tmp;
472
473 // Pointer to the start of the queue.
474 tmp = timer_object_queue_;
475
476 // Search for the timer handle
477 while (tmp)
478 {
479 if ((tmp == handle.m_d) && (tmp->uid == handle.m_d->uid))
480 {
481 handle.m_d->state_ = TimerHandler::TIMER_STATE_RUNNING;
482
483 if (handle.m_d->Type == TIMERTYPE_PERIODIC)
484 {
485 handle.m_d->glibid = GetWindowThread()->AddTimeout(handle.m_d->Period * (1.0f - handle.m_d->Param));
486 }
487 else
488 {
489 handle.m_d->glibid = GetWindowThread()->AddTimeout(handle.m_d->Period);
490 }
491
492 handle.m_d->ms_time = g_get_monotonic_time() / 1000;
493
494 if (handle.m_d->glibid == 0)
495 {
496 _early_timer_objects.push_back(handle.m_d);
497 }
498 return true;
499 }
500
501 tmp = tmp->next;
502 }
503 return false;
504 }
505
411 int TimerHandler::ExecTimerHandler(unsigned int timer_id)506 int TimerHandler::ExecTimerHandler(unsigned int timer_id)
412#else
413 int TimerHandler::ExecTimerHandler()
414#endif
415 {507 {
416 NUX_RETURN_VALUE_IF_NULL(m_timer_object_queue, 0);508 NUX_RETURN_VALUE_IF_NULL(timer_object_queue_, 0);
417509
418 bool repeat = false;510 bool repeat = false;
419 TimerObject *timer_object = m_timer_object_queue;511 // Pointer to the start of the timer handler queue.
420 TimeStruct now;512 TimerObject* timer_object = timer_object_queue_;
421513
422 int timer_executed = 0;514 is_processing_timers_ = true;
423
424 TimeRightNow(&now);
425
426 m_IsProceesingTimers = true;
427515
428 while (timer_object != NULL)516 while (timer_object != NULL)
429 {517 {
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))
431
432 if ((/*TimeIsGreater(now, timer_object->when) ||*/ (timer_object->glibid == timer_id)) && (timer_object->MarkedForRemoval == false))
433#else
434 if (TimeIsGreater(now, timer_object->when))
435#endif
436 {519 {
437 long elaps = now.sec - timer_object->when.sec;520 if (timer_object->state_ != TIMER_STATE_RUNNING)
438 long uelaps = now.usec - timer_object->when.usec;
439
440 if (uelaps < 0)
441 {521 {
442 uelaps += 1000000;522 return false;
443 //nuxAssert(elaps > 0);
444 elaps -= 1;
445 }523 }
524 // Find the first timer object that
446525
447 timer_object->ElapsedTime += timer_object->Period; //elaps * 1000 + uelaps / 1000; // milliseconds526 timer_object->ElapsedTime += timer_object->Period;
448527
449 if (timer_object->Type == TIMERTYPE_PERIODIC)528 if (timer_object->Type == TIMERTYPE_PERIODIC)
450 {529 {
@@ -484,15 +563,20 @@
484 nuxAssertMsg(0, "[TimerHandler::ExecTimerHandler] Unknown timer type.");563 nuxAssertMsg(0, "[TimerHandler::ExecTimerHandler] Unknown timer type.");
485 }564 }
486565
566
487 if (timer_object->Param > 1.0f)567 if (timer_object->Param > 1.0f)
568 {
569 // correction.
488 timer_object->Param = 1.0f;570 timer_object->Param = 1.0f;
571 }
489572
490 timer_object->MarkedForRemoval = false;573 timer_object->marked_for_removal_ = false;
491574
492 if (timer_object->timeout_signal != 0)575 if (timer_object->timeout_signal != 0)
493 {576 {
577 // Execute the signal
494 GetWindowThread()->GetWindowCompositor().SetProcessingTopView(timer_object->Window);578 GetWindowThread()->GetWindowCompositor().SetProcessingTopView(timer_object->Window);
495 timer_object->timeout_signal->time_expires.emit(timer_object->CallbackData);579 timer_object->timeout_signal->tick.emit(timer_object->CallbackData);
496 GetWindowThread()->GetWindowCompositor().SetProcessingTopView(NULL); 580 GetWindowThread()->GetWindowCompositor().SetProcessingTopView(NULL);
497 // Reset glibid to 0. glibid is not null, if this element ever happened to be at the head of the queue581 // Reset glibid to 0. glibid is not null, if this element ever happened to be at the head of the queue
498 // and we set a timer for it.582 // and we set a timer for it.
@@ -500,56 +584,68 @@
500 //timer_object->glibid = 0;584 //timer_object->glibid = 0;
501 }585 }
502586
503 TimerObject *expired_handler = 0;587 TimerObject* expired_handler = 0;
504588
505 if (timer_object->MarkedForRemoval)589 if (timer_object->marked_for_removal_)
506 {590 {
507 // RemoveTimerHandler was called during the callback execution591 // RemoveTimerHandler was called during the callback execution
508 expired_handler = timer_object;592 expired_handler = timer_object;
509 }593 }
510 else if (timer_object->Type == TIMERTYPE_PERIODIC)594 else if (timer_object->Type == TIMERTYPE_PERIODIC)
511 {595 {
596 // A one shot timer expires after the first execution.
512 expired_handler = timer_object;597 expired_handler = timer_object;
513 }598 }
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))
515 {600 {
601 // A timer delay timer expires after the duration of the timer as expired.
516 expired_handler = timer_object;602 expired_handler = timer_object;
517 }603 }
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))
519 {605 {
606 // An iterative timer expires after the timer as been executedN times.
520 expired_handler = timer_object;607 expired_handler = timer_object;
521 }608 }
522609
523 if (expired_handler)610 if (!expired_handler && (timer_object->state_ == TIMER_STATE_PAUSED))
524 {611 {
612 // The state has been changed to "paused".
613 return false;
614 }
615
616 if(expired_handler)
617 {
618 GetWindowThread()->GetWindowCompositor().SetProcessingTopView(timer_object->Window);
619 timer_object->timeout_signal->expired.emit(timer_object->CallbackData);
620 GetWindowThread()->GetWindowCompositor().SetProcessingTopView(NULL);
621
622 timer_object->state_ = TIMER_STATE_STOPED;
623
525 if (timer_object->next)624 if (timer_object->next)
526 timer_object->next->prev = timer_object->prev;625 timer_object->next->prev = timer_object->prev;
527626
528 if (timer_object->prev)627 if (timer_object->prev)
529 timer_object->prev->next = timer_object->next;628 timer_object->prev->next = timer_object->next;
530629
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))
532 {631 {
533 // timer_object is the first element of the queue.632 // timer_object is the first element of the queue.
534 m_timer_object_queue = timer_object->next;633 timer_object_queue_ = timer_object->next;
535634
536 if (m_timer_object_queue)635 if (timer_object_queue_)
537 {636 {
538 m_timer_object_queue->prev = 0;637 timer_object_queue_->prev = 0;
539 }638 }
540 }639 }
541640
542 timer_object = timer_object->next;641 timer_object = timer_object->next;
543
544 delete expired_handler;642 delete expired_handler;
545 }643 }
546 else644 else
547 {645 {
548 repeat = true;646 repeat = true;
549 //timer_object = timer_object->next;
550 }647 }
551648
552 timer_executed++;
553 break;649 break;
554 }650 }
555 else651 else
@@ -558,24 +654,14 @@
558 }654 }
559 }655 }
560656
561// // Look at the head of the queue and set a glib timeout for the first element, if one wasn't set already.
562// if (m_timer_object_queue && (m_timer_object_queue->glibid == 0))
563// {
564// // How long(in milliseconds) between now and the moment the timeout expires?
565// unsigned int time_difference = TimeDiff(now, m_timer_object_queue->when);
566//
567// m_timer_object_queue->glibid = GetWindowThread()->AddTimeout(time_difference);
568// //nuxDebugMsg("[TimerHandler::ExecTimerHandler] Adding Timeout ID: %d", m_timer_object_queue->glibid);
569// }
570
571 // Purge handles that have been marked for removal657 // Purge handles that have been marked for removal
572 timer_object = m_timer_object_queue;658 timer_object = timer_object_queue_;
573659
574 while (timer_object)660 while (timer_object)
575 {661 {
576 if (timer_object->MarkedForRemoval)662 if (timer_object->marked_for_removal_)
577 {663 {
578 TimerObject *expired_handler = timer_object;664 TimerObject* expired_handler = timer_object;
579665
580 if (timer_object->next)666 if (timer_object->next)
581 timer_object->next->prev = timer_object->prev;667 timer_object->next->prev = timer_object->prev;
@@ -585,11 +671,11 @@
585 else671 else
586 {672 {
587 // timer_object is the first element of the queue.673 // timer_object is the first element of the queue.
588 m_timer_object_queue = timer_object->next;674 timer_object_queue_ = timer_object->next;
589675
590 if (m_timer_object_queue)676 if (timer_object_queue_)
591 {677 {
592 m_timer_object_queue->prev = 0;678 timer_object_queue_->prev = 0;
593 }679 }
594 }680 }
595681
@@ -602,14 +688,13 @@
602 }688 }
603 }689 }
604690
605 m_IsProceesingTimers = false;691 is_processing_timers_ = false;
606 //return timer_executed;
607 return repeat;692 return repeat;
608 }693 }
609694
610 bool TimerHandler::FindTimerHandle(TimerHandle &timer_object)695 bool TimerHandler::FindTimerHandle(TimerHandle &timer_object)
611 {696 {
612 TimerObject *tmp = m_timer_object_queue;697 TimerObject *tmp = timer_object_queue_;
613698
614 while (tmp)699 while (tmp)
615 {700 {
@@ -630,7 +715,7 @@
630 TimeStruct now;715 TimeStruct now;
631 TimeStruct delay;716 TimeStruct delay;
632717
633 if (m_timer_object_queue == NULL)718 if (timer_object_queue_ == NULL)
634 {719 {
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.
636 return 0;721 return 0;
@@ -639,14 +724,14 @@
639 {724 {
640 TimeRightNow(&now);725 TimeRightNow(&now);
641726
642 if (TimeIsGreater(now, m_timer_object_queue->when))727 if (TimeIsGreater(now, timer_object_queue_->when))
643 {728 {
644 return 0;729 return 0;
645 }730 }
646 else731 else
647 {732 {
648 delay.sec = m_timer_object_queue->when.sec - now.sec;733 delay.sec = timer_object_queue_->when.sec - now.sec;
649 delay.usec = m_timer_object_queue->when.usec - now.usec;734 delay.usec = timer_object_queue_->when.usec - now.usec;
650735
651 // make sure that usec cannot be less than -1000000 before applying this code736 // make sure that usec cannot be less than -1000000 before applying this code
652 if (delay.usec < 0)737 if (delay.usec < 0)
653738
=== modified file 'Nux/TimerProc.h'
--- Nux/TimerProc.h 2011-12-29 18:06:53 +0000
+++ Nux/TimerProc.h 2012-07-12 13:45:35 +0000
@@ -33,7 +33,8 @@
33 class TimeOutSignal : public sigc::trackable33 class TimeOutSignal : public sigc::trackable
34 {34 {
35 public:35 public:
36 sigc::signal<void, void *> time_expires;36 sigc::signal<void, void *> tick;
37 sigc::signal<void, void *> expired;
37 };38 };
38 typedef TimeOutSignal TimerFunctor;39 typedef TimeOutSignal TimerFunctor;
3940
@@ -77,6 +78,13 @@
77 TIMERTYPE_ITERATION,78 TIMERTYPE_ITERATION,
78 };79 };
7980
81 typedef enum
82 {
83 TIMER_STATE_STOPED,
84 TIMER_STATE_PAUSED,
85 TIMER_STATE_RUNNING,
86 } TimerState;
87
80 TimerHandler(WindowThread *window_thread);88 TimerHandler(WindowThread *window_thread);
81 ~TimerHandler();89 ~TimerHandler();
8290
@@ -85,38 +93,38 @@
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.
86 The returned TimerObject should not be deleted by the caller.94 The returned TimerObject should not be deleted by the caller.
8795
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.
89 @param timeout_signal The callback to execute when the timer expires.97 @param timeout_signal The callback to execute when the timer expires.
90 @param Data The callback data98 @param Data The callback data
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.
92 @return A handle to the timer.100 @return A handle to the timer.
93 */101 */
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);
95 //! Add a periodic timer callback.103 //! Add a periodic timer callback.
96 /*!104 /*!
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.
98 The returned TimerHandle should not be deleted by the caller.106 The returned TimerHandle should not be deleted by the caller.
99107
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.
101 @param Duration The duration over which the timer is repeated.109 @param Duration The duration over which the timer is repeated.
102 @param timeout_signal The callback to execute when the timer expires.110 @param timeout_signal The callback to execute when the timer expires.
103 @param Data The callback data111 @param Data The callback data
104 @return A handle to the timer.112 @return A handle to the timer.
105 */113 */
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);
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.
108 /*!116 /*!
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.
110 Every time the timer expires, the callback function is executed.118 Every time the timer expires, the callback function is executed.
111 The returned TimerHandle should not be deleted by the caller.119 The returned TimerHandle should not be deleted by the caller.
112120
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.
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.
115 @param timeout_signal The callback to execute when the timer expires.123 @param timeout_signal The callback to execute when the timer expires.
116 @param Data The callback data124 @param Data The callback data
117 @return A handle to the timer.125 @return A handle to the timer.
118 */126 */
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);
120128
121 //! Search for a timer handle.129 //! Search for a timer handle.
122 /*!130 /*!
@@ -125,14 +133,31 @@
125 @param handle Timer handle to search.133 @param handle Timer handle to search.
126 @return Return true if the timer is found; false otherwise.134 @return Return true if the timer is found; false otherwise.
127 */135 */
128 bool FindTimerHandle (TimerHandle &handle);136 bool FindTimerHandle(TimerHandle& handle);
129137
130 //! Remove a timer;138 //! Remove a timer;
131 /*!139 /*!
132 @param handle Timer handle to search.140 This call stops the timer.
133 @return Return True if the timer is found.141 @param handle Timer handle to search.
134 */142 @return Return True if the timer is found.
135 bool RemoveTimerHandler (TimerHandle &handle);143 */
144 bool RemoveTimerHandler(TimerHandle& handle);
145
146 //! Pause a timer.
147 /*!
148 This call pauses a timer.
149 @param handle Timer handle to look for.
150 @return True if the timer is paused.
151 */
152 bool PauseTimer(TimerHandle& handle);
153
154 //! Resume the execution of a timer.
155 /*!
156 This call resumes the execution of a timer.
157 @param handle Timer handle to look for.
158 @return True if the timer execution has resumed..
159 */
160 bool ResumeTimer(TimerHandle& handle);
136161
137 //! Return the delay until the next timer expires.162 //! Return the delay until the next timer expires.
138 /*!163 /*!
@@ -150,14 +175,20 @@
150 void StartEarlyTimerObjects();175 void StartEarlyTimerObjects();
151176
152 private:177 private:
178 // Prevent copy constructor.
179 TimerHandler(const TimerHandler&);
180
181 // Prevent assignment operator.
182 TimerHandler& operator = (const TimerHandler&);
183
153 WindowThread *window_thread_; //!< The WindowThread to which this object belongs.184 WindowThread *window_thread_; //!< The WindowThread to which this object belongs.
154185
155 bool m_IsProceesingTimers;186 bool is_processing_timers_;
156 TimerObject *AddHandle (TimerObject *handle);187 TimerObject* AddHandle(TimerObject *handle);
157 unsigned int GetNumPendingHandler();188 unsigned int GetNumPendingHandler();
158189
159 //! Single linked list of timer delays.190 //! Single linked list of timer delays.
160 TimerObject *m_timer_object_queue;191 TimerObject* timer_object_queue_;
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.
162 };193 };
163194
164195
=== modified file 'Nux/VScrollBar.cpp'
--- Nux/VScrollBar.cpp 2012-01-02 20:56:41 +0000
+++ Nux/VScrollBar.cpp 2012-07-12 13:45:35 +0000
@@ -91,15 +91,15 @@
91 vlayout->AddView(_scroll_down_button, 0, eCenter, eFix);91 vlayout->AddView(_scroll_down_button, 0, eCenter, eFix);
9292
93 callback = new TimerFunctor;93 callback = new TimerFunctor;
94 callback->time_expires.connect(sigc::mem_fun(this, &VScrollBar::VScrollBarHandler));94 callback->tick.connect(sigc::mem_fun(this, &VScrollBar::VScrollBarHandler));
95 up_callback = new TimerFunctor;95 up_callback = new TimerFunctor;
96 up_callback->time_expires.connect(sigc::mem_fun(this, &VScrollBar::ScrollUp));96 up_callback->tick.connect(sigc::mem_fun(this, &VScrollBar::ScrollUp));
97 down_callback = new TimerFunctor;97 down_callback = new TimerFunctor;
98 down_callback->time_expires.connect(sigc::mem_fun(this, &VScrollBar::ScrollDown));98 down_callback->tick.connect(sigc::mem_fun(this, &VScrollBar::ScrollDown));
99 trackup_callback = new TimerFunctor;99 trackup_callback = new TimerFunctor;
100 trackup_callback->time_expires.connect(sigc::mem_fun(this, &VScrollBar::TrackUp));100 trackup_callback->tick.connect(sigc::mem_fun(this, &VScrollBar::TrackUp));
101 trackdown_callback = new TimerFunctor;101 trackdown_callback = new TimerFunctor;
102 trackdown_callback->time_expires.connect(sigc::mem_fun(this, &VScrollBar::TrackDown));102 trackdown_callback->tick.connect(sigc::mem_fun(this, &VScrollBar::TrackDown));
103103
104 SetLayout(vlayout);104 SetLayout(vlayout);
105 SetAcceptMouseWheelEvent(true);105 SetAcceptMouseWheelEvent(true);
@@ -132,7 +132,7 @@
132 else132 else
133 {133 {
134 scrollbar->QueueDraw();134 scrollbar->QueueDraw();
135 GetTimer().AddTimerHandler(10, callback, scrollbar);135 GetTimer().AddOneShotTimer(10, callback, scrollbar);
136 }136 }
137 }137 }
138138
@@ -148,7 +148,7 @@
148 else148 else
149 {149 {
150 scrollbar->QueueDraw();150 scrollbar->QueueDraw();
151 GetTimer().AddTimerHandler(10, callback, scrollbar);151 GetTimer().AddOneShotTimer(10, callback, scrollbar);
152 }152 }
153 }153 }
154154
@@ -162,7 +162,7 @@
162 if (AtMaximum())162 if (AtMaximum())
163 RecvEndScrollDown(0, 0, 0, 0);163 RecvEndScrollDown(0, 0, 0, 0);
164 else164 else
165 m_DownTimerHandler = GetTimer().AddTimerHandler(10, down_callback, this);165 m_DownTimerHandler = GetTimer().AddOneShotTimer(10, down_callback, this);
166166
167 QueueDraw();167 QueueDraw();
168 }168 }
@@ -174,7 +174,7 @@
174 if (AtMaximum())174 if (AtMaximum())
175 RecvEndScrollUp(0, 0, 0, 0);175 RecvEndScrollUp(0, 0, 0, 0);
176 else176 else
177 m_UpTimerHandler = GetTimer().AddTimerHandler(10, up_callback, this);177 m_UpTimerHandler = GetTimer().AddOneShotTimer(10, up_callback, this);
178178
179 QueueDraw();179 QueueDraw();
180 }180 }
@@ -184,7 +184,7 @@
184 if (m_TrackMouseCoord.y < _slider->GetBaseY() - _track->GetBaseY())184 if (m_TrackMouseCoord.y < _slider->GetBaseY() - _track->GetBaseY())
185 {185 {
186 OnScrollUp.emit(container_height_, 1);186 OnScrollUp.emit(container_height_, 1);
187 m_TrackUpTimerHandler = GetTimer().AddTimerHandler(10, trackup_callback, this);187 m_TrackUpTimerHandler = GetTimer().AddOneShotTimer(10, trackup_callback, this);
188 QueueDraw();188 QueueDraw();
189 }189 }
190 }190 }
@@ -194,7 +194,7 @@
194 if (m_TrackMouseCoord.y > _slider->GetBaseY() + _slider->GetBaseHeight() - _track->GetBaseY())194 if (m_TrackMouseCoord.y > _slider->GetBaseY() + _slider->GetBaseHeight() - _track->GetBaseY())
195 {195 {
196 OnScrollDown.emit(container_height_, 1);196 OnScrollDown.emit(container_height_, 1);
197 m_TrackDownTimerHandler = GetTimer().AddTimerHandler(10, trackdown_callback, this);197 m_TrackDownTimerHandler = GetTimer().AddOneShotTimer(10, trackdown_callback, this);
198 QueueDraw();198 QueueDraw();
199 }199 }
200 }200 }
@@ -396,14 +396,14 @@
396 //sigVScrollBarSliderMouseDown.emit();396 //sigVScrollBarSliderMouseDown.emit();
397 b_MouseDownTimer = true;397 b_MouseDownTimer = true;
398 b_MouseUpTimer = false;398 b_MouseUpTimer = false;
399 GetTimer().AddTimerHandler(10, callback, this);399 GetTimer().AddOneShotTimer(10, callback, this);
400 }400 }
401401
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)
403 {403 {
404 b_MouseDownTimer = false;404 b_MouseDownTimer = false;
405 b_MouseUpTimer = true;405 b_MouseUpTimer = true;
406 GetTimer().AddTimerHandler(10, callback, this);406 GetTimer().AddOneShotTimer(10, callback, this);
407 }407 }
408408
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)
410410
=== modified file 'Nux/WindowThread.cpp'
--- Nux/WindowThread.cpp 2012-06-11 14:27:57 +0000
+++ Nux/WindowThread.cpp 2012-07-12 13:45:35 +0000
@@ -105,7 +105,7 @@
105 _inside_main_loop = false;105 _inside_main_loop = false;
106 _inside_timer_loop = false;106 _inside_timer_loop = false;
107 async_wake_up_signal_ = new TimerFunctor();107 async_wake_up_signal_ = new TimerFunctor();
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));
109 }109 }
110110
111 WindowThread::~WindowThread()111 WindowThread::~WindowThread()
@@ -152,7 +152,7 @@
152 return TimerHandle();152 return TimerHandle();
153153
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.
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);
156156
157 return handle;157 return handle;
158 }158 }
@@ -196,7 +196,7 @@
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))
197 {197 {
198 _pending_wake_up_timer = true;198 _pending_wake_up_timer = true;
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);
200 }200 }
201 }201 }
202 }202 }

Subscribers

People subscribed via source and target branches