I tried your flag version too, I like it, it works without delay and is 
simple.
But theoretically you can have situations where the drawn output doesn't 
fully represent the current state (if some things were already done and the 
data was changed afterwards).
Unless I misunderstand your solution.
Practically that is often not an issue.

I think for my use case I prefer the timer solution, because although it 
has delay, that delay can be tweaked as a tradeoff between delay and cpu 
use.
And I can tweak it so that it feels snappy and racket doesn't go to 100% 
cpu use, drawing frames I don't perceive.
It also always does a full redraw eventually after things have changed.
(not really relevant for that mouse event case though, but if I were to 
draw background color based on mouse position it might be)

The timer code is based on other old autosave code:
I think initially I reused the timer, but then needed another flag to know 
whether the timer is already running.
Also I didn't want the timer to hang around for a bunch of text fields 
which get modified rarely and its existence doubles as flag whether it is 
running.
Actually for autosave textfields that part is very important that always 
the latest version is saved.

So many different tradeoffs possible ;)

Thank you, for your perspective!

Simon

alexha...@gmail.com schrieb am Samstag, 22. Mai 2021 um 08:03:30 UTC+2:

> On Saturday, May 22, 2021 at 12:42:30 PM UTC+8 schle...@gmail.com wrote:
>
>> Maybe someone has a clever solution to collapse the calls to refresh less 
>> manually.
>>
>
> I experienced a similar problem as you, where I have to refresh a canvas 
> on a mouse event and the paint method is somewhat slow (it does have a lot 
> of drawing to do in my case, so I expect it to be slow).  I am not sure if 
> this is a regression in the draw performance, but it seems that the canvas% 
> will un `on-paint` for each `refresh` call it receives (unless I am missing 
> something).  This means that sending a refresh on mouse events will result 
> in many unnecessary redraws of the canvas.
>
> Not sure if my solution is "clever", but it involves setting a flag on the 
> first refresh and only clearing after the draw operation is completed.  The 
> internal state is still updated for each mouse event, but refresh is only 
> called on the canvas if the flag is not set (that is if there is no 
> outstanding refresh call).  This way, there is no unnecessary delay for the 
> refresh, and the on-paint always draws the latest version of the internal 
> state, which may have been updated several times between the time refresh 
> was initially called.
>
> Also, if you choose to use a timer% object, you don't need to create one 
> each time, they can be reused.
>
> Alex.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/ac9c8d9e-9381-4e01-acdd-f38091cbed2cn%40googlegroups.com.

Reply via email to