]> Pileus Git - ~andy/gtk/blob - docs/reference/gtk/tmpl/gtkdrawingarea.sgml
2.7.0
[~andy/gtk] / docs / reference / gtk / tmpl / gtkdrawingarea.sgml
1 <!-- ##### SECTION Title ##### -->
2 GtkDrawingArea
3
4 <!-- ##### SECTION Short_Description ##### -->
5 A widget for custom user interface elements
6
7 <!-- ##### SECTION Long_Description ##### -->
8 <para>
9
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-&gt;window</literal>. After creating a drawing area,
13 the application may want to connect to:
14
15 <itemizedlist>
16   <listitem>
17     <para>
18     Mouse and button press signals to respond to input from
19     the user. (Use gtk_widget_add_events() to enable events 
20     you wish to receive.)
21     </para>
22   </listitem>
23   <listitem>
24     <para>
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.)
28     </para>
29   </listitem>
30   <listitem>
31     <para>
32     The "configure_event" signal to take any necessary actions
33     when the widget changes size.
34     </para>
35   </listitem>
36   <listitem>
37     <para>
38     The "expose_event" signal to handle redrawing the
39     contents of the widget.
40     </para>
41   </listitem>
42 </itemizedlist>
43 </para>
44 <para>
45 The following code portion demonstrates using a drawing
46 area to display a circle in the normal widget foreground 
47 color.
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.
51 </para>
52 <example>
53 <title>Simple <structname>GtkDrawingArea</structname> usage.</title>
54 <programlisting>
55 gboolean
56 expose_event_callback (GtkWidget *widget, GdkEventExpose *event, gpointer data)
57 {
58   gdk_draw_arc (widget->window,
59                 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
60                 TRUE,
61                 0, 0, widget->allocation.width, widget->allocation.height,
62                 0, 64 * 360);
63  
64   return TRUE;
65 }
66 [...]
67   GtkWidget *drawing_area = gtk_drawing_area_new (<!-- -->);
68   gtk_widget_set_size_request (drawing_area, 100, 100);
69   g_signal_connect (G_OBJECT (drawing_area), "expose_event",  
70                     G_CALLBACK (expose_event_callback), NULL);
71 </programlisting>
72 </example>
73
74 <para>
75 Expose events are normally delivered when a drawing area first comes
76 onscreen, or when it's covered by another window and then uncovered
77 (exposed). You can also force an expose event by adding to the "damage
78 region" of the drawing area's window; gtk_widget_queue_draw_area() and
79 gdk_window_invalidate_rect() are equally good ways to do this. You'll
80 then get an expose event for the invalid region.
81 </para>
82
83 <para>
84 The available routines for drawing are documented on the <link
85 linkend="gdk-Drawing-Primitives">GDK Drawing Primitives</link> page.
86 See also gdk_pixbuf_render_to_drawable() for drawing a #GdkPixbuf.
87 </para>
88
89 <para>
90 To receive mouse events on a drawing area, you will need to enable
91 them with gtk_widget_add_events(). To receive keyboard events, you
92 will need to set the #GTK_CAN_FOCUS flag on the drawing area, and
93 should probably draw some user-visible indication that the drawing
94 area is focused. Use the GTK_HAS_FOCUS() macro in your expose event
95 handler to decide whether to draw the focus indicator. See
96 gtk_paint_focus() for one way to draw focus.
97 </para>
98
99 <!-- ##### SECTION See_Also ##### -->
100 <para>
101 Sometimes #GtkImage is a useful alternative to a drawing area. 
102 You can put a #GdkPixmap in the #GtkImage and draw to the #GdkPixmap, 
103 calling gtk_widget_queue_draw() on the #GtkImage when you want to 
104 refresh to the screen.
105 </para>
106
107 <!-- ##### SECTION Stability_Level ##### -->
108
109
110 <!-- ##### STRUCT GtkDrawingArea ##### -->
111 <para>
112 The #GtkDrawingArea struct contains private data only, and
113 should be accessed using the functions below.
114 </para>
115
116
117 <!-- ##### FUNCTION gtk_drawing_area_new ##### -->
118 <para>
119 Creates a new drawing area.
120 </para>
121
122 @Returns: a new #GtkDrawingArea
123
124
125 <!-- ##### FUNCTION gtk_drawing_area_size ##### -->
126 <para>
127 (Use gtk_widget_set_size_request() instead.)
128 Sets the size that the drawing area will request
129 in response to a "size_request" signal. The 
130 drawing area may actually be allocated a size
131 larger than this depending on how it is packed
132 within the enclosing containers.
133 </para>
134
135 @darea: a #GtkDrawingArea.
136 @width: the width to request.
137 @height: the height to request.
138
139