gtkD: How to paint to screen for animation

Michelle Long HappyDance321 at gmail.com
Tue Mar 19 20:18:53 UTC 2019


On Tuesday, 19 March 2019 at 19:03:37 UTC, Mike Wey wrote:
> On 19-03-2019 01:54, Michelle Long wrote:
>> I've added a function to addOnDraw for a DrawingArea and it 
>> paints using the code I have when I resize.
>> 
>> I added a queueDraw in threadsAddIdle and it seems to draws 
>> the screen immediately but it does not seem to be called again.
>> 
>> If I put queueDraw inside the addOnDraw routine then the 
>> animation works but it is quite slow, about 1 fps and cpu 
>> usage is 100% without it, it is 0%.
>
> You will probably want to use glib.Timeout to make the time 
> between redraws consistent.
> The callBack for treadsAddIdle or glib.Idle is only called when 
> the mainloop has nothing else to do.
>
> The cairo clock demo is a good example: 
> https://github.com/gtkd-developers/GtkD/blob/master/demos/cairo/cairo_clock/clock.d
>
> If performance is an issue one option would be to save your 
> context in a cairo surface and only redraw the parts that have 
> changed.


I will try the clock code and see if threading it will help 
though. Just not sure if it's limited by cario or the thread.

It seems that blitting the image is not the slow down because I 
removed the code and it still is slow, so it seems like it is a 
thread.


setSourcePixbuf(buf, 0,0);						
paint();

Thanks.






More information about the Digitalmars-d-learn mailing list