Is there state of the art example code for GTK DrawingArea available yet? (Scrollbars, zooming, panning ...)

I think in 2009 it was not, at least I did not found something. So I wrote a demo in Ruby that time, see

http://ssalewski.de/PetEd-Demo.html.en

I jut ported that code to Nim – applying a small fix to gintro bindings it seems to work still fine. You can see the draft code at the bottom of the gintro page

https://github.com/StefanSalewski/gintro

But I have the strong feeling that the state of that code is not well suited for GTK3, for example the creation of the temporary surface may generate a lot of overhead, and 300 lines of code for such a plain demo seems to be too heavy. So before I try to tune it, I want to ask if similar state of the art examples are available. Language does not matter. If not, then I think I will start with replacing surface allocation with functions mentioned at

https://developer.gnome.org/gdk3/stable/GdkDrawingContext.html#gdk-drawing-context-get-cairo-context

Maybe I should try to refactor the code so that all drawing routines are called from inside “draw” callback? That may simplify the code and prevent intermediate allocations. I am not sure if that is possible for all use cases, maybe I had reasons in 2010 to write it in its current shape, but maybe I was just happy to get it working that time.

PS: E. Bassi and site admins, I just got again a message “you can not post a link to that host” when I just tried to send this post. Please investigate that, it is really annoying. I will invalidate the links and try posting again. Will replace github with githuuub, as that worked last time.

Hi Stefan,

Maybe not state of the art but an artistic try at a few things that might be interesting. These are some attempts at 3d using cairo and a drawing area. Cairo might not draw as fast as opengl but it has some built in advantages such as drawing text and output to vector formats like pdf and svg along with good backward compatibility. Animation speed for many drawings is fast enough.

https://gitlab.com/cecashon/OrderedSetVelociRaptor/tree/master/Misc/cairo3d

The UI files put together the test programs. Some drawing pictures are there also if you scroll down on the page.

I can open and edit drawings in Inkscape but I lose the z coordinate value with pdf and svg. I read Inkscape can open a 3d .OBJ file so now I am thinking maybe try to output to that format but I don’t have that figured out.

If you back up one level

https://gitlab.com/cecashon/OrderedSetVelociRaptor/tree/master/Misc/

there are a bunch of other cairo drawings here and there. In the cairo_drawings folder there are some simpler drawings. Most just use the standard gtk3 “draw” callback without any extra allocations. Me trying to be artistic.

Eric

I literally have no idea why that happens to you; I’ve tested various times, but, for instance, I can paste a link to github just fine:

https://github.com/ebassi/glarea-example

And I get the preview.

Edited to add: @StefanSalewski the next time it happens, please take a screenshot of the error and open a topic in the Site Feedback category.

E.Bassi, thanks for fixing the links to gintro. I have no idea why it does not worked for me.

C. Eric Cashon,

yes I was aware of your cairo drawing examples. But that are more about the drawing themself, I was currently basically interested in the cairo-drawingarea interaction with support of zoom, scrollbars, panning, background grid, mouse events, and all that with optimal performance of course. For applications like my old Ruby drawing app http://ssalewski.de/PetEd.html.en

While the current gintro example works fine, I still wonder if same functionality is archivable in simpler form also. DrawingArea supports clipping, so putting it inside of a GtkScrolledWindow would be the start…

I recently remembered why the gintro example draws to a temporary surface – that is done to have the possibility to apply semi static backgrounds. For example a grid, which is a bit larger as the currently visible region, so when scrolling, we can reuse that grid with some offset, instead of repainting for each minimal scroll.

There are at least two minimal gnome examples available of course:

https://developer.gnome.org/gtk3/stable/ch01s05.html

https://developer.gnome.org/gtk3/stable/GtkDrawingArea.html

And the animation example of Uli Schlachter:

https://lists.cairographics.org/archives/cairo/2016-October/027796.html

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.