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/d11b15d0-4546-47ce-bb4b-5d2c7cf1eaa1n%40googlegroups.com.