-
Notifications
You must be signed in to change notification settings - Fork 332
Rewrite the canvas to use a Gdk.Texture #1485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
785f791 to
bcb6099
Compare
- Rewrite the canvas widget to render to a Gdk.Texture at the original image size, and then apply scaling at render time via Gtk.Snapshot. This avoids allocating huge textures for zoomed in images, which happens in GTK4 with the previous DrawingArea widget. - This would be a bit cleaner to implement as a custom widget once gir.core supports virtual functions, but for now a Gtk.Picture widget suffices. For example, we could more easily react to size changes to simplify updates to the ruler, etc - Since we don't have a 'resize' event from the DrawingArea widget anymore, some of the event handlers now look at the scroll area's adjustments, which have suitable events when they are modified - The workspace offset is no longer needed with the switch to Gtk.Pciture and configuring the H/Valign properties to avoid expansion. This greatly simplifies translating between original and zoomed coordinates. The one exception is the ruler widget, which still needs to figure out the offset from the corner of the viewport to the canvas Bug: #1020
This eliminates hacky code in the canvas which compared against the tool's type name to decide whether to show a filled selection. The magic wand tool also now shows a filled selection to match the other selection tools
This can easily be done by adding a CSS style to the widget rather than drawing it manually, and this also looks nicer since a smooth blur can be added
This implementation ends up being a lot simpler by rendering a scaled Gsk.Path, and performance seems good in my testing.
This can't be done in the canvas renderer since it would scale along with the zoomed image. Instead, we draw a tiled texture into the widget before drawing the scaled canvas texture
013123e to
0699449
Compare
- Provide a clip area to the canvas renderer to limit the updated area for Cairo operations. This avoids the old code's approach of allocating a new surface whenever the area changes - Use the 'update-texture' property of Gdk.MemoryTextureBuilder to apply updates to an area of the texture - Change the "CanvasInvalidated" event to use a canvas-space rectangle, which makes more sense for the new implementation
These can extend beyond the canvas, so this avoids the widget stretching out
…pdate This happened in the eraser tool - since we no longer draw a checkboard background in the canvas renderer (and instead overlay the canvas texture on the background), we need to ensure the existing canvas image surface is cleared out in case the layer now has some transparent pixels
|
I think this is in a pretty good place now and could use some wider testing @JGCarroll - for the snap package, do you know which GTK version (and libadwaita version) would be available? For these changes I think we'll need to bump up to at least GTK 4.16 |
GTK is 4.18 |
That's great, thank you! |
We need at least GTK 4.16 for the new canvas widget, but we may as well jump to 4.18 which is widely available on our target platforms.
1045a4e to
93fc609
Compare
|
Thanks, yeah I could reproduce that after turning on the canvas grid to 16x16 on the default 800x600 image |
This avoids expanding the widget's size (e.g. from the stroke's antialiasing) when the lines extend to the edge of the canvas Bug: #1485
|
I think we just needed to clip the canvas grid to the bounds to make sure it doesn't expand the widget's size by an extra pixel: 601c250 |


Tasks
Gdk.TextureGtk.SnapshotGtk.SnapshotGtk.SnapshotInvalidate()calls (e.g. in the text tool)Bug: #1020