Gtk -drawing area

I want to create a drawing area and clip a small rectangle on the left top of the drawingarea. So, a callback to drawing area should not affect the rectangle clipped . For example, a drawing area of size 600X600 should exclude a rectangle (0, 0, 10, 10) , 0, 0 is the origin of the drawingarea and 10, 10 is the width and height of the rectangle.

I tried overlay , that did not help.

When you use a GtkDrawingArea, you generally use cairo functions for the drawing. Cairo provides cairo_t: Cairo: A Vector Graphics Library which allows to restrict the drawing to a path content. You should be able to manage that. Another option would be to copy the tiny content to a backup surface, and copy it back later. Maybe that is faster for tiny areas.

If you’re using GTK3, you can conceivably use gtk_widget_queue_draw_area() to indicate that you only want to redraw a specific region of the widget.

With GTK4 this is not possible: drawing is based on operations with an intrinsic bounding area, and the rendering pipeline in GTK identifies the region of each rendering command (and diffs the previous rendering operation tree with the new one); for all intents and purposes, though, GtkDrawingArea is a single drawing operation, as it uses a single Cairo surface. If you want to have sub-regions, you will need a custom widget with custom render nodes; or you will need a custom widget with separate child widgets for each part of the UI you’re rendering.

In general, the intent behind GtkDrawingArea, in both GTK3 and GTK4, is to provide an easy way to draw simple content with Cairo without subclassing GtkWidget directly; if you start adding complexity, you should always switch to a custom widget instead.

yes, i try gtk_widget_queue_draw_area , but this will call draw_callback

Yes, that’s how drawing works. The whole idea, though, is that the region that will be actually drawn is clipped to the area you passed. This means geometry submitted outside that region will be ignored—though you may want to also check the clip region and avoid doing operations that would lead to drawing outside of the clip. Then GTK will take that area and only push that to the window manager/compositor.

I thought of gtk_widget_queue_draw_area. But, it ,might not be useful for what I am working with. I record the x, y of the mouse movement on the graphics window. Using the draw_call_back to write a label on the drawing area draws a high CPU load. So, I tried to create an empty label using overlay on the graphics area and tried to set the label text , but overlay on a graphic window till used the “draw_call_back”. So, only way for me is to create the label widget outside the graphics window.

Thanks for letting me know gtk-4. I am interested to replace gtk-3 with gtk-4. Do you have a suggestion for a widely tested version of gtk-4.

GTK 4.0 was released nearly a year ago, December 2020. The current stable release is GTK 4.4, and there’s going to be a 4.6 release at the end of 2021. “Widely tested” isn’t really a thing, I’m afraid; GTK is just as tested as any other free software libraries.

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