Author: manolo
Date: 2012-06-15 08:18:28 -0700 (Fri, 15 Jun 2012)
New Revision: 9612
Log:
Mac OS: improved fltk3::repeat_timeout() so the next scheduled timeout is
counted from the previous one.
Modified:
branches/branch-3.0/src/fltk3/cocoa.mm
Modified: branches/branch-3.0/src/fltk3/cocoa.mm
===================================================================
--- branches/branch-3.0/src/fltk3/cocoa.mm 2012-06-15 15:08:17 UTC (rev
9611)
+++ branches/branch-3.0/src/fltk3/cocoa.mm 2012-06-15 15:18:28 UTC (rev
9612)
@@ -479,10 +479,12 @@
void* data;
CFRunLoopTimerRef timer;
char pending;
+ CFAbsoluteTime next_timeout; // scheduled time for this timer
};
static MacTimeout* mac_timers;
static int mac_timer_alloc;
static int mac_timer_used;
+static MacTimeout* current_timer; // the timer that triggered its callback
function, or NULL
static void realloc_timers()
{
@@ -516,7 +518,9 @@
MacTimeout& t = mac_timers[i];
if (t.timer == timer && t.data == data) {
t.pending = 0;
+ current_timer = &t;
(*t.callback)(data);
+ current_timer = NULL;
if (t.pending==0)
delete_timer(t);
break;
@@ -2520,7 +2524,8 @@
MacTimeout& t = mac_timers[i];
// if so, simply change the fire interval
if (t.callback == cb && t.data == data) {
- CFRunLoopTimerSetNextFireDate(t.timer, CFAbsoluteTimeGetCurrent() + time
);
+ t.next_timeout = CFAbsoluteTimeGetCurrent() + time;
+ CFRunLoopTimerSetNextFireDate(t.timer, t.next_timeout );
t.pending = 1;
return;
}
@@ -2561,12 +2566,23 @@
t.data = data;
t.timer = timerRef;
t.pending = 1;
+ t.next_timeout = CFRunLoopTimerGetNextFireDate(timerRef);
}
}
void fltk3::repeat_timeout(double time, fltk3::TimeoutHandler cb, void* data)
{
- // currently, repeat_timeout does not subtract the trigger time of the
previous timer event as it should.
+ if (current_timer) {
+ // k = how many times 'time' seconds after the last scheduled timeout
until the future
+ double k = ceil( (CFAbsoluteTimeGetCurrent() -
current_timer->next_timeout) / time);
+ if (k < 1) k = 1;
+ current_timer->next_timeout += k * time;
+ CFRunLoopTimerSetNextFireDate(current_timer->timer,
current_timer->next_timeout );
+ current_timer->callback = cb;
+ current_timer->data = data;
+ current_timer->pending = 1;
+ return;
+ }
add_timeout(time, cb, data);
}
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit