1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 A widget for custom user interface elements
7 <!-- ##### SECTION Long_Description ##### -->
10 The #GtkDrawingArea widget is used for creating custom user interface
11 elements. It's essentially a blank widget; you can draw on
12 <literal>widget->window</literal>. After creating a drawing area,
13 the application may want to connect to:
18 Mouse and button press signals to respond to input from
19 the user. (Use gtk_widget_add_events() to enable events
25 The "realize" signal to take any necessary actions
26 when the widget is instantiated on a particular display.
27 (Create GDK resources in response to this signal.)
32 The "configure_event" signal to take any necessary actions
33 when the widget changes size.
38 The "draw" signal to handle redrawing the contents of the
45 The following code portion demonstrates using a drawing
46 area to display a circle in the normal widget foreground
48 Note that GDK automatically clears the exposed area
49 to the background color before sending the expose event, and
50 that drawing is implicitly clipped to the exposed area.
53 <title>Simple <structname>GtkDrawingArea</structname> usage.</title>
56 draw_callback (GtkWidget *widget, cairo_t *cr, gpointer data)
61 width = gtk_widget_get_allocated_width (widget);
62 height = gtk_widget_get_allocated_height (widget);
64 width / 2.0, height / 2.0,
65 MIN (width, height) / 2.0,
68 gtk_style_context_get_color (gtk_widget_get_style_context (widget),
71 gdk_cairo_set_source_rgba (cr, &color);
80 GtkWidget *drawing_area = gtk_drawing_area_new (<!-- -->);
81 gtk_widget_set_size_request (drawing_area, 100, 100);
82 g_signal_connect (G_OBJECT (drawing_area), "draw",
83 G_CALLBACK (draw_callback), NULL);
88 Draw signals are normally delivered when a drawing area first comes
89 onscreen, or when it's covered by another window and then uncovered.
90 You can also force a redraw by adding to the "damage region" of the
91 drawing area's window; use gtk_widget_queue_draw_area() to do this.
92 You'll then get a draw event for the invalid region.
96 The available routines for drawing are documented on the <link
97 linkend="gdk3-Cairo-Interaction">GDK Drawing Primitives</link> page
98 and the cairo documentation.
102 To receive mouse events on a drawing area, you will need to enable
103 them with gtk_widget_add_events(). To receive keyboard events, you
104 will need to set the #GTK_CAN_FOCUS flag on the drawing area, and
105 should probably draw some user-visible indication that the drawing
106 area is focused. Use the GTK_HAS_FOCUS() macro in your expose event
107 handler to decide whether to draw the focus indicator. See
108 gtk_paint_focus() for one way to draw focus.
111 <!-- ##### SECTION See_Also ##### -->
113 Sometimes #GtkImage is a useful alternative to a drawing area.
114 You can put a #GdkPixmap in the #GtkImage and draw to the #GdkPixmap,
115 calling gtk_widget_queue_draw() on the #GtkImage when you want to
116 refresh to the screen.
119 <!-- ##### SECTION Stability_Level ##### -->
122 <!-- ##### SECTION Image ##### -->
125 <!-- ##### STRUCT GtkDrawingArea ##### -->
127 The #GtkDrawingArea struct contains private data only, and
128 should be accessed using the functions below.
132 <!-- ##### FUNCTION gtk_drawing_area_new ##### -->
134 Creates a new drawing area.
138 @Returns: a new #GtkDrawingArea