Libraries:Gtk:Gtk:DrawingArea
Types
T
Inherits from:The T widget is used for creating custom user interface elements. It's essentially a blank widget; you can draw on widget->window. After creating a drawing area, the application may want to connect to:
-
Mouse and button press signals to respond to input from the user. (Use Gtk.Gtk.Widget.AddEvents to enable events you wish to receive.)
-
The "realize" signal to take any necessary actions when the widget is instantiated on a particular display. (Create GDK resources in response to this signal.)
-
The "configure_event" signal to take any necessary actions when the widget changes size.
-
The "expose_event" signal to handle redrawing the contents of the widget.
The following code portion demonstrates using a drawing area to display a circle in the normal widget foreground color. Note that GDK automatically clears the exposed area to the background color before sending the expose event, and that drawing is implicitly clipped to the exposed area.
Example 53. Simple GtkDrawingArea usage.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
gboolean expose_event_callback (GtkWidget *widget, GdkEventExpose *event, gpointer data) { gdk_draw_arc (widget->window, widget->style->fg_gc[gtk_widget_get_state (widget)], TRUE, 0, 0, widget->allocation.width, widget->allocation.height, 0, 64 * 360); return TRUE; } [...] GtkWidget *drawing_area = gtk_drawing_area_new (); gtk_widget_set_size_request (drawing_area, 100, 100); g_signal_connect (G_OBJECT (drawing_area), "expose_event", G_CALLBACK (expose_event_callback), NULL); |
Expose events are normally delivered when a drawing area first comes onscreen, or when it's covered by another window and then uncovered (exposed). You can also force an expose event by adding to the "damage region" of the drawing area's window; Gtk.Gtk.Widget.QueueDrawArea and Gtk.Gdk.Window.InvalidateRect are equally good ways to do this. You'll then get an expose event for the invalid region.
The available routines for drawing are documented on the GDK Drawing Primitives page. See also Gtk.Gdk.Drawable.DrawPixbuf for drawing a Gtk.Gdk.Pixbuf.T.
To receive mouse events on a drawing area, you will need to enable them with Gtk.Gtk.Widget.AddEvents. To receive keyboard events, you will need to set the Gtk.Gtk.WidgetFlags.CanFocus flag on the drawing area, and should probably draw some user-visible indication that the drawing area is focused. Use the Gtk.Gtk.WidgetFlags.HasFocus macro in your expose event handler to decide whether to draw the focus indicator. See Gtk.Gtk.Global.PaintFocus for one way to draw focus.
Constants
Nil : T
Functions
GetType() : Gtk.GObject.Type.T
New() : Gtk.Gtk.DrawingArea.T
Methods
:Size(self @ T, width @ Std.Integer.SmallT, height @ Std.Integer.SmallT) : Std.Object.T
Warning
Size is deprecated and should not be used in newly-written code. Use Gtk.Gtk.Widget.SetSizeRequest instead.