File: GtkDrawingArea.html

package info (click to toggle)
gtk%2B2.0 2.20.1-2%2Bdeb6u2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 136,284 kB
  • ctags: 66,487
  • sloc: ansic: 590,318; sh: 10,559; makefile: 5,573; xml: 1,357; python: 866; perl: 776; asm: 457; awk: 72; cpp: 34
file content (253 lines) | stat: -rw-r--r-- 18,068 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GtkDrawingArea</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="GTK+ Reference Manual">
<link rel="up" href="MiscObjects.html" title="Miscellaneous">
<link rel="prev" href="GtkCalendar.html" title="GtkCalendar">
<link rel="next" href="GtkEventBox.html" title="GtkEventBox">
<meta name="generator" content="GTK-Doc V1.14 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
<tr valign="middle">
<td><a accesskey="p" href="GtkCalendar.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="MiscObjects.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">GTK+ Reference Manual</th>
<td><a accesskey="n" href="GtkEventBox.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr>
<tr><td colspan="5" class="shortcuts">
<a href="#GtkDrawingArea.synopsis" class="shortcut">Top</a>
                   | 
                  <a href="#GtkDrawingArea.description" class="shortcut">Description</a>
                   | 
                  <a href="#GtkDrawingArea.object-hierarchy" class="shortcut">Object Hierarchy</a>
                   | 
                  <a href="#GtkDrawingArea.implemented-interfaces" class="shortcut">Implemented Interfaces</a>
</td></tr>
</table>
<div class="refentry" title="GtkDrawingArea">
<a name="GtkDrawingArea"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle"><a name="GtkDrawingArea.top_of_page"></a>GtkDrawingArea</span></h2>
<p>GtkDrawingArea — A widget for custom user interface elements</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv" title="Synopsis">
<a name="GtkDrawingArea.synopsis"></a><h2>Synopsis</h2>
<pre class="synopsis">
#include &lt;gtk/gtk.h&gt;

                    <a class="link" href="GtkDrawingArea.html#GtkDrawingArea-struct" title="GtkDrawingArea">GtkDrawingArea</a>;
<a class="link" href="GtkWidget.html" title="GtkWidget"><span class="returnvalue">GtkWidget</span></a>*          <a class="link" href="GtkDrawingArea.html#gtk-drawing-area-new" title="gtk_drawing_area_new ()">gtk_drawing_area_new</a>                (<em class="parameter"><code><span class="type">void</span></code></em>);
<span class="returnvalue">void</span>                <a class="link" href="GtkDrawingArea.html#gtk-drawing-area-size" title="gtk_drawing_area_size ()">gtk_drawing_area_size</a>               (<em class="parameter"><code><a class="link" href="GtkDrawingArea.html" title="GtkDrawingArea"><span class="type">GtkDrawingArea</span></a> *darea</code></em>,
                                                         <em class="parameter"><code><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint"><span class="type">gint</span></a> width</code></em>,
                                                         <em class="parameter"><code><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint"><span class="type">gint</span></a> height</code></em>);
</pre>
</div>
<div class="refsect1" title="Object Hierarchy">
<a name="GtkDrawingArea.object-hierarchy"></a><h2>Object Hierarchy</h2>
<pre class="synopsis">
  <a href="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#GObject">GObject</a>
   +----<a href="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#GInitiallyUnowned">GInitiallyUnowned</a>
         +----<a class="link" href="GtkObject.html" title="GtkObject">GtkObject</a>
               +----<a class="link" href="GtkWidget.html" title="GtkWidget">GtkWidget</a>
                     +----GtkDrawingArea
                           +----<a class="link" href="GtkCurve.html" title="GtkCurve">GtkCurve</a>
                           +----<a class="link" href="GtkSpinner.html" title="GtkSpinner">GtkSpinner</a>
</pre>
</div>
<div class="refsect1" title="Implemented Interfaces">
<a name="GtkDrawingArea.implemented-interfaces"></a><h2>Implemented Interfaces</h2>
<p>
GtkDrawingArea implements
 AtkImplementorIface and  <a class="link" href="gtk-gtkbuildable.html#GtkBuildable">GtkBuildable</a>.</p>
</div>
<div class="refsect1" title="Description">
<a name="GtkDrawingArea.description"></a><h2>Description</h2>
<p>
The <a class="link" href="GtkDrawingArea.html" title="GtkDrawingArea"><span class="type">GtkDrawingArea</span></a> widget is used for creating custom user interface
elements. It's essentially a blank widget; you can draw on
<code class="literal">widget-&gt;window</code>. After creating a drawing area,
the application may want to connect to:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
    Mouse and button press signals to respond to input from
    the user. (Use <a class="link" href="GtkWidget.html#gtk-widget-add-events" title="gtk_widget_add_events ()"><code class="function">gtk_widget_add_events()</code></a> to enable events
    you wish to receive.)
    </p></li>
<li class="listitem"><p>
    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.)
    </p></li>
<li class="listitem"><p>
    The "configure_event" signal to take any necessary actions
    when the widget changes size.
    </p></li>
<li class="listitem"><p>
    The "expose_event" signal to handle redrawing the
    contents of the widget.
    </p></li>
</ul></div>
<p>
</p>
<p>
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.
</p>
<div class="example">
<a name="id1012270"></a><p class="title"><b>Example 50. Simple <span class="structname">GtkDrawingArea</span> usage.</b></p>
<div class="example-contents">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="normal"><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a></span>
<span class="function">expose_event_callback</span><span class="normal"> </span><span class="symbol">(</span><span class="normal"><a href="GtkWidget.html">GtkWidget</a> </span><span class="symbol">*</span><span class="normal">widget</span><span class="symbol">,</span><span class="normal"> <a href="http://library.gnome.org/devel/gdk/unstable/gdk-Event-Structures.html#GdkEventExpose">GdkEventExpose</a> </span><span class="symbol">*</span><span class="normal">event</span><span class="symbol">,</span><span class="normal"> <a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gpointer">gpointer</a> data</span><span class="symbol">)</span>
<span class="cbracket">{</span>
<span class="normal">  </span><span class="function"><a href="http://library.gnome.org/devel/gdk/unstable/gdk-Drawing-Primitives.html#gdk-draw-arc">gdk_draw_arc</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">widget</span><span class="symbol">-&gt;</span><span class="normal">window</span><span class="symbol">,</span>
<span class="normal">                widget</span><span class="symbol">-&gt;</span><span class="normal">style</span><span class="symbol">-&gt;</span><span class="normal">fg_gc</span><span class="symbol">[</span><span class="function"><a href="GtkWidget.html#gtk-widget-get-state">gtk_widget_get_state</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">widget</span><span class="symbol">)],</span>
<span class="normal">                <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#TRUE:CAPS">TRUE</a></span><span class="symbol">,</span>
<span class="normal">                </span><span class="number">0</span><span class="symbol">,</span><span class="normal"> </span><span class="number">0</span><span class="symbol">,</span><span class="normal"> widget</span><span class="symbol">-&gt;</span><span class="normal">allocation</span><span class="symbol">.</span><span class="normal">width</span><span class="symbol">,</span><span class="normal"> widget</span><span class="symbol">-&gt;</span><span class="normal">allocation</span><span class="symbol">.</span><span class="normal">height</span><span class="symbol">,</span>
<span class="normal">                </span><span class="number">0</span><span class="symbol">,</span><span class="normal"> </span><span class="number">64</span><span class="normal"> </span><span class="symbol">*</span><span class="normal"> </span><span class="number">360</span><span class="symbol">);</span>
<span class="normal">  </span><span class="keyword">return</span><span class="normal"> <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#TRUE:CAPS">TRUE</a></span><span class="symbol">;</span>
<span class="cbracket">}</span>
<span class="symbol">[...]</span>
<span class="normal">  <a href="GtkWidget.html">GtkWidget</a> </span><span class="symbol">*</span><span class="normal">drawing_area </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="GtkDrawingArea.html#gtk-drawing-area-new">gtk_drawing_area_new</a></span><span class="normal"> </span><span class="symbol">();</span>
<span class="normal">  </span><span class="function"><a href="GtkWidget.html#gtk-widget-set-size-request">gtk_widget_set_size_request</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">drawing_area</span><span class="symbol">,</span><span class="normal"> </span><span class="number">100</span><span class="symbol">,</span><span class="normal"> </span><span class="number">100</span><span class="symbol">);</span>
<span class="normal">  </span><span class="function"><a href="/usr/share/gtk-doc/html/gobject/gobject-Signals.html#g-signal-connect">g_signal_connect</a></span><span class="normal"> </span><span class="symbol">(</span><span class="function"><a href="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#G-OBJECT:CAPS">G_OBJECT</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">drawing_area</span><span class="symbol">),</span><span class="normal"> </span><span class="string">"expose_event"</span><span class="symbol">,</span>
<span class="normal">                    </span><span class="function"><a href="/usr/share/gtk-doc/html/gobject/gobject-Closures.html#G-CALLBACK:CAPS">G_CALLBACK</a></span><span class="normal"> </span><span class="symbol">(</span><span class="normal">expose_event_callback</span><span class="symbol">),</span><span class="normal"> <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

</div>
<br class="example-break"><p>
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; <a class="link" href="GtkWidget.html#gtk-widget-queue-draw-area" title="gtk_widget_queue_draw_area ()"><code class="function">gtk_widget_queue_draw_area()</code></a> and
<a href="http://library.gnome.org/devel/gdk/unstable/gdk-Windows.html#gdk-window-invalidate-rect"><code class="function">gdk_window_invalidate_rect()</code></a> are equally good ways to do this. You'll
then get an expose event for the invalid region.
</p>
<p>
The available routines for drawing are documented on the <a href="http://library.gnome.org/devel/gdk/unstable/gdk-Drawing-Primitives.html">GDK Drawing Primitives</a> page.
See also <a href="http://library.gnome.org/devel/gdk/unstable/gdk-Drawing-Primitives.html#gdk-draw-pixbuf"><code class="function">gdk_draw_pixbuf()</code></a> for drawing a <a href="http://library.gnome.org/devel/gdk-pixbuf/unstable/gdk-pixbuf-gdk-pixbuf.html#GdkPixbuf"><span class="type">GdkPixbuf</span></a>.
</p>
<p>
To receive mouse events on a drawing area, you will need to enable
them with <a class="link" href="GtkWidget.html#gtk-widget-add-events" title="gtk_widget_add_events ()"><code class="function">gtk_widget_add_events()</code></a>. To receive keyboard events, you
will need to set the <a class="link" href="GtkWidget.html#GTK-CAN-FOCUS:CAPS"><span class="type">GTK_CAN_FOCUS</span></a> flag on the drawing area, and
should probably draw some user-visible indication that the drawing
area is focused. Use the <a class="link" href="GtkWidget.html#GTK-HAS-FOCUS:CAPS"><code class="function">GTK_HAS_FOCUS()</code></a> macro in your expose event
handler to decide whether to draw the focus indicator. See
<a class="link" href="GtkStyle.html#gtk-paint-focus" title="gtk_paint_focus ()"><code class="function">gtk_paint_focus()</code></a> for one way to draw focus.
</p>
</div>
<div class="refsect1" title="Details">
<a name="GtkDrawingArea.details"></a><h2>Details</h2>
<div class="refsect2" title="GtkDrawingArea">
<a name="GtkDrawingArea-struct"></a><h3>GtkDrawingArea</h3>
<pre class="programlisting">typedef struct _GtkDrawingArea GtkDrawingArea;</pre>
<p>
The <a class="link" href="GtkDrawingArea.html" title="GtkDrawingArea"><span class="type">GtkDrawingArea</span></a> struct contains private data only, and
should be accessed using the functions below.
</p>
</div>
<hr>
<div class="refsect2" title="gtk_drawing_area_new ()">
<a name="gtk-drawing-area-new"></a><h3>gtk_drawing_area_new ()</h3>
<pre class="programlisting"><a class="link" href="GtkWidget.html" title="GtkWidget"><span class="returnvalue">GtkWidget</span></a>*          gtk_drawing_area_new                (<em class="parameter"><code><span class="type">void</span></code></em>);</pre>
<p>
Creates a new drawing area.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>a new <a class="link" href="GtkDrawingArea.html" title="GtkDrawingArea"><span class="type">GtkDrawingArea</span></a>
</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2" title="gtk_drawing_area_size ()">
<a name="gtk-drawing-area-size"></a><h3>gtk_drawing_area_size ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>                gtk_drawing_area_size               (<em class="parameter"><code><a class="link" href="GtkDrawingArea.html" title="GtkDrawingArea"><span class="type">GtkDrawingArea</span></a> *darea</code></em>,
                                                         <em class="parameter"><code><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint"><span class="type">gint</span></a> width</code></em>,
                                                         <em class="parameter"><code><a href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint"><span class="type">gint</span></a> height</code></em>);</pre>
<div class="warning" title="Warning" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Warning</h3>
<p><code class="literal">gtk_drawing_area_size</code> is deprecated and should not be used in newly-written code. Use <a class="link" href="GtkWidget.html#gtk-widget-set-size-request" title="gtk_widget_set_size_request ()"><code class="function">gtk_widget_set_size_request()</code></a> instead.</p>
</div>
<p>
Sets the size that the drawing area will request
in response to a "size_request" signal. The
drawing area may actually be allocated a size
larger than this depending on how it is packed
within the enclosing containers.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>darea</code></em> :</span></p></td>
<td>a <a class="link" href="GtkDrawingArea.html" title="GtkDrawingArea"><span class="type">GtkDrawingArea</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>width</code></em> :</span></p></td>
<td>the width to request
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>height</code></em> :</span></p></td>
<td>the height to request
</td>
</tr>
</tbody>
</table></div>
</div>
</div>
<div class="refsect1" title="See Also">
<a name="GtkDrawingArea.see-also"></a><h2>See Also</h2>
<p>
Sometimes <a class="link" href="GtkImage.html" title="GtkImage"><span class="type">GtkImage</span></a> is a useful alternative to a drawing area.
You can put a <a href="http://library.gnome.org/devel/gdk/unstable/gdk-Bitmaps-and-Pixmaps.html#GdkPixmap"><span class="type">GdkPixmap</span></a> in the <a class="link" href="GtkImage.html" title="GtkImage"><span class="type">GtkImage</span></a> and draw to the <a href="http://library.gnome.org/devel/gdk/unstable/gdk-Bitmaps-and-Pixmaps.html#GdkPixmap"><span class="type">GdkPixmap</span></a>,
calling <a class="link" href="GtkWidget.html#gtk-widget-queue-draw" title="gtk_widget_queue_draw ()"><code class="function">gtk_widget_queue_draw()</code></a> on the <a class="link" href="GtkImage.html" title="GtkImage"><span class="type">GtkImage</span></a> when you want to
refresh to the screen.
</p>
</div>
</div>
<div class="footer">
<hr>
          Generated by GTK-Doc V1.14</div>
</body>
</html>