Cairo line_to equalent for Snapshot / Gtk 4

In Cairo it is possible to draw line and then fill up bordered area (like a waveform) with gradient. Due of Snapshot being quite different, I am still poking my head how to do that with using it. So far I am drawing rectangles and play around with changes there. Any ideas would be welcome :slight_smile:

If you need something more than a rectangle, then use a Cairo node. The snapshot API does not have paths (yet).

Thank you, that worked with some changes. Interestingly enough Gdk.cairo_get_clip_rectangle does not exist in Gdk 4 anymore - how to detect area cairo should draw?

You don’t: you always draw the whole area.

GTK does not use clip rectangles or Cairo, any more; widgets issue render commands as a tree of nodes, and GTK will automatically track which nodes are visible and which ones aren’t.

Thing is it is rather large custom DrawingArea - in this case it is waveform of sound file. So in result that node quite large and might not be all visible at once.

At the moment it seems to be coping rather well, very old version of app implemented quite extensive caching, which I would replicate at some point - or address performance somewhere else :thinking:

Yes, that’s the downside of using Cairo.

Depending on the way your waveform is displayed, you could replace a large drawing surface with a custom widget containing various sub-widgets, each one displaying a section of the waveform.

It would be awesome to do it using acceleration via Snapshot - hoping when I will get to that point, some path support will be already added.

Thanks! :slight_smile:

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