|
|
tl;dr call "redraw()' in event handling and callback routines. Never call "draw()' directly. FLTK will call "draw()" for you when the time is right.
macOS can send a *lot* of DRAG and MOVE events. More than 60 events per second. It makes no sense to actually draw a widget every time an event occurs, and if the screen is sync locked, it generates a huge lag, because while the drawing code is waiting for the screen "flyback", more DRAG events are piling up. Then taking only the top DRAG event and waiting for the screen once more will increase the pile even more.
All MOVE and DRAG event, actually *all* events should be handled quickly. So for a DRAG event, all you do is fetch the coordinates and save them in the widget, and call "redraw()" on the widget, so the widget knows how to draw itself without referencing any events. "redraw()" is very fast. It tells FLTK, that some area wants to be redrawn, but doesn't draw anything at all. It pretty much just sets a flag.
So it doesn't really matter how many DRAG events you have piled up, "redraw()" only sets a flag over and over.
Now once the event queue is empty (simplified), FLTK checks which widgets want to be redrawn, and draws them all at once. Even though you may have handled 20 DRAG events during a single screen refresh, only the most recent event has an effect that will be drawn. That way, you can handle thousands of events per second without ever waiting for the screen, and without getting a lag.
Just for completeness, if you want to animate something, you do exactly the same. In the timer, all you do is call "redraw()". The widget must be able to draw itself based on the current time, not based on the timer event, because you never know how the slow the user's machine is. Events always run completely asynchronously from screen drawing.
Ian MacArthur schrieb am Dienstag, 29. November 2022 um 10:36:31 UTC+1:
On a related note, triggering a lot of redraws from within the handle method is unlikely to be "efficient" anyway, I suspect. But, as Matt says we might need to see a worked example of what you are actually doing here, to better illuminate the issues.
--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/357c925f-b9c0-4a2e-ad8b-357a487efc02n%40googlegroups.com.
[ Direct Link to Message ] | |
|
| |