233 lines
14 KiB
HTML
233 lines
14 KiB
HTML
<!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: GTK+ 3 Reference Manual</title>
|
||
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
|
||
<link rel="home" href="index.html" title="GTK+ 3 Reference Manual">
|
||
<link rel="up" href="MiscObjects.html" title="Miscellaneous">
|
||
<link rel="prev" href="GtkCalendar.html" title="GtkCalendar">
|
||
<link rel="next" href="GtkGLArea.html" title="GtkGLArea">
|
||
<meta name="generator" content="GTK-Doc V1.25.1 (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="5"><tr valign="middle">
|
||
<td width="100%" align="left" class="shortcuts">
|
||
<a href="#" class="shortcut">Top</a><span id="nav_description"> <span class="dim">|</span>
|
||
<a href="#GtkDrawingArea.description" class="shortcut">Description</a></span><span id="nav_hierarchy"> <span class="dim">|</span>
|
||
<a href="#GtkDrawingArea.object-hierarchy" class="shortcut">Object Hierarchy</a></span><span id="nav_interfaces"> <span class="dim">|</span>
|
||
<a href="#GtkDrawingArea.implemented-interfaces" class="shortcut">Implemented Interfaces</a></span>
|
||
</td>
|
||
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
|
||
<td><a accesskey="u" href="MiscObjects.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
|
||
<td><a accesskey="p" href="GtkCalendar.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
|
||
<td><a accesskey="n" href="GtkGLArea.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
|
||
</tr></table>
|
||
<div class="refentry">
|
||
<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 class="gallery_image" valign="top" align="right"></td>
|
||
</tr></table></div>
|
||
<div class="refsect1">
|
||
<a name="GtkDrawingArea.functions"></a><h2>Functions</h2>
|
||
<div class="informaltable"><table class="informaltable" width="100%" border="0">
|
||
<colgroup>
|
||
<col width="150px" class="functions_return">
|
||
<col class="functions_name">
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td class="function_type">
|
||
<a class="link" href="GtkWidget.html" title="GtkWidget"><span class="returnvalue">GtkWidget</span></a> *
|
||
</td>
|
||
<td class="function_name">
|
||
<a class="link" href="GtkDrawingArea.html#gtk-drawing-area-new" title="gtk_drawing_area_new ()">gtk_drawing_area_new</a> <span class="c_punctuation">()</span>
|
||
</td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
</div>
|
||
<div class="refsect1">
|
||
<a name="GtkDrawingArea.other"></a><h2>Types and Values</h2>
|
||
<div class="informaltable"><table class="informaltable" width="100%" border="0">
|
||
<colgroup>
|
||
<col width="150px" class="name">
|
||
<col class="description">
|
||
</colgroup>
|
||
<tbody><tr>
|
||
<td class="datatype_keyword">struct</td>
|
||
<td class="function_name"><a class="link" href="GtkDrawingArea.html#GtkDrawingArea-struct" title="struct GtkDrawingArea">GtkDrawingArea</a></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
</div>
|
||
<div class="refsect1">
|
||
<a name="GtkDrawingArea.object-hierarchy"></a><h2>Object Hierarchy</h2>
|
||
<pre class="screen"> <a href="../gobject/gobject-The-Base-Object-Type.html#GObject-struct">GObject</a>
|
||
<span class="lineart">╰──</span> <a href="../gobject/gobject-The-Base-Object-Type.html#GInitiallyUnowned">GInitiallyUnowned</a>
|
||
<span class="lineart">╰──</span> <a class="link" href="GtkWidget.html" title="GtkWidget">GtkWidget</a>
|
||
<span class="lineart">╰──</span> GtkDrawingArea
|
||
</pre>
|
||
</div>
|
||
<div class="refsect1">
|
||
<a name="GtkDrawingArea.implemented-interfaces"></a><h2>Implemented Interfaces</h2>
|
||
<p>
|
||
GtkDrawingArea implements
|
||
AtkImplementorIface and <a class="link" href="GtkBuildable.html" title="GtkBuildable">GtkBuildable</a>.</p>
|
||
</div>
|
||
<div class="refsect1">
|
||
<a name="GtkDrawingArea.includes"></a><h2>Includes</h2>
|
||
<pre class="synopsis">#include <gtk/gtk.h>
|
||
</pre>
|
||
</div>
|
||
<div class="refsect1">
|
||
<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 it. After
|
||
creating a drawing area, the application may want to connect to:</p>
|
||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-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 <a class="link" href="GtkWidget.html#GtkWidget-realize" title="The “realize” signal"><span class="type">“realize”</span></a> 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 <a class="link" href="GtkWidget.html#GtkWidget-size-allocate" title="The “size-allocate” signal"><span class="type">“size-allocate”</span></a> signal to take any necessary
|
||
actions when the widget changes size.</p></li>
|
||
<li class="listitem"><p>The <a class="link" href="GtkWidget.html#GtkWidget-draw" title="The “draw” signal"><span class="type">“draw”</span></a> signal to handle redrawing the
|
||
contents of the widget.</p></li>
|
||
</ul></div>
|
||
<p>The following code portion demonstrates using a drawing
|
||
area to display a circle in the normal widget foreground
|
||
color.</p>
|
||
<p>Note that GDK automatically clears the exposed area before sending
|
||
the expose event, and that drawing is implicitly clipped to the exposed
|
||
area. If you want to have a theme-provided background, you need
|
||
to call <a class="link" href="GtkStyleContext.html#gtk-render-background" title="gtk_render_background ()"><code class="function">gtk_render_background()</code></a> in your ::draw method.</p>
|
||
<div class="refsect3">
|
||
<a name="id-1.3.19.4.8.6"></a><h4>Simple GtkDrawingArea usage</h4>
|
||
<div class="informalexample">
|
||
<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
|
||
16
|
||
17
|
||
18
|
||
19
|
||
20
|
||
21
|
||
22
|
||
23
|
||
24
|
||
25
|
||
26
|
||
27
|
||
28
|
||
29
|
||
30
|
||
31
|
||
32
|
||
33</pre></td>
|
||
<td class="listing_code"><pre class="programlisting">gboolean
|
||
<span class="function">draw_callback</span> <span class="gtkdoc opt">(</span>GtkWidget <span class="gtkdoc opt">*</span>widget<span class="gtkdoc opt">,</span> cairo_t <span class="gtkdoc opt">*</span>cr<span class="gtkdoc opt">,</span> gpointer data<span class="gtkdoc opt">)</span>
|
||
<span class="gtkdoc opt">{</span>
|
||
guint width<span class="gtkdoc opt">,</span> height<span class="gtkdoc opt">;</span>
|
||
GdkRGBA color<span class="gtkdoc opt">;</span>
|
||
GtkStyleContext <span class="gtkdoc opt">*</span>context<span class="gtkdoc opt">;</span>
|
||
|
||
context <span class="gtkdoc opt">=</span> <span class="function"><a href="GtkWidget.html#gtk-widget-get-style-context">gtk_widget_get_style_context</a></span> <span class="gtkdoc opt">(</span>widget<span class="gtkdoc opt">);</span>
|
||
|
||
width <span class="gtkdoc opt">=</span> <span class="function"><a href="GtkWidget.html#gtk-widget-get-allocated-width">gtk_widget_get_allocated_width</a></span> <span class="gtkdoc opt">(</span>widget<span class="gtkdoc opt">);</span>
|
||
height <span class="gtkdoc opt">=</span> <span class="function"><a href="GtkWidget.html#gtk-widget-get-allocated-height">gtk_widget_get_allocated_height</a></span> <span class="gtkdoc opt">(</span>widget<span class="gtkdoc opt">);</span>
|
||
|
||
<span class="function"><a href="GtkStyleContext.html#gtk-render-background">gtk_render_background</a></span> <span class="gtkdoc opt">(</span>context<span class="gtkdoc opt">,</span> cr<span class="gtkdoc opt">,</span> <span class="number">0</span><span class="gtkdoc opt">,</span> <span class="number">0</span><span class="gtkdoc opt">,</span> width<span class="gtkdoc opt">,</span> height<span class="gtkdoc opt">);</span>
|
||
|
||
<span class="function">cairo_arc</span> <span class="gtkdoc opt">(</span>cr<span class="gtkdoc opt">,</span>
|
||
width <span class="gtkdoc opt">/</span> <span class="number">2.0</span><span class="gtkdoc opt">,</span> height <span class="gtkdoc opt">/</span> <span class="number">2.0</span><span class="gtkdoc opt">,</span>
|
||
<span class="function"><a href="../glib/glib-Standard-Macros.html#MIN:CAPS">MIN</a></span> <span class="gtkdoc opt">(</span>width<span class="gtkdoc opt">,</span> height<span class="gtkdoc opt">) /</span> <span class="number">2.0</span><span class="gtkdoc opt">,</span>
|
||
<span class="number">0</span><span class="gtkdoc opt">,</span> <span class="number">2</span> <span class="gtkdoc opt">*</span> G_PI<span class="gtkdoc opt">);</span>
|
||
|
||
<span class="function"><a href="GtkStyleContext.html#gtk-style-context-get-color">gtk_style_context_get_color</a></span> <span class="gtkdoc opt">(</span>context<span class="gtkdoc opt">,</span>
|
||
<span class="function"><a href="GtkStyleContext.html#gtk-style-context-get-state">gtk_style_context_get_state</a></span> <span class="gtkdoc opt">(</span>context<span class="gtkdoc opt">),</span>
|
||
<span class="gtkdoc opt">&</span>color<span class="gtkdoc opt">);</span>
|
||
<span class="function"><a href="../gdk4/gdk4-Cairo-Interaction.html#gdk-cairo-set-source-rgba">gdk_cairo_set_source_rgba</a></span> <span class="gtkdoc opt">(</span>cr<span class="gtkdoc opt">, &</span>color<span class="gtkdoc opt">);</span>
|
||
|
||
<span class="function">cairo_fill</span> <span class="gtkdoc opt">(</span>cr<span class="gtkdoc opt">);</span>
|
||
|
||
<span class="keyword">return</span> FALSE<span class="gtkdoc opt">;</span>
|
||
<span class="gtkdoc opt">}</span>
|
||
<span class="gtkdoc opt">[...]</span>
|
||
GtkWidget <span class="gtkdoc opt">*</span>drawing_area <span class="gtkdoc opt">=</span> <span class="function"><a href="GtkDrawingArea.html#gtk-drawing-area-new">gtk_drawing_area_new</a></span> <span class="gtkdoc opt">();</span>
|
||
<span class="function"><a href="GtkWidget.html#gtk-widget-set-size-request">gtk_widget_set_size_request</a></span> <span class="gtkdoc opt">(</span>drawing_area<span class="gtkdoc opt">,</span> <span class="number">100</span><span class="gtkdoc opt">,</span> <span class="number">100</span><span class="gtkdoc opt">);</span>
|
||
<span class="function"><a href="../gobject/gobject-Signals.html#g-signal-connect">g_signal_connect</a></span> <span class="gtkdoc opt">(</span><span class="function"><a href="../gobject/gobject-The-Base-Object-Type.html#G-OBJECT:CAPS">G_OBJECT</a></span> <span class="gtkdoc opt">(</span>drawing_area<span class="gtkdoc opt">),</span> <span class="string">"draw"</span><span class="gtkdoc opt">,</span>
|
||
<span class="function"><a href="../gobject/gobject-Closures.html#G-CALLBACK:CAPS">G_CALLBACK</a></span> <span class="gtkdoc opt">(</span>draw_callback<span class="gtkdoc opt">),</span> NULL<span class="gtkdoc opt">);</span></pre></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
|
||
<p></p>
|
||
<p>Draw signals are normally delivered when a drawing area first comes
|
||
onscreen, or when it’s covered by another window and then uncovered.
|
||
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="../gdk4/gdk4-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 a draw signal for the invalid region.</p>
|
||
<p>The available routines for drawing are documented on the
|
||
GDK Drawing Primitives page
|
||
and the cairo documentation.</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 “can-focus” property on the drawing area, and you
|
||
should probably draw some user-visible indication that the drawing
|
||
area is focused. Use <a class="link" href="GtkWidget.html#gtk-widget-has-focus" title="gtk_widget_has_focus ()"><code class="function">gtk_widget_has_focus()</code></a> in your expose event
|
||
handler to decide whether to draw the focus indicator. See
|
||
<a class="link" href="GtkStyleContext.html#gtk-render-focus" title="gtk_render_focus ()"><code class="function">gtk_render_focus()</code></a> for one way to draw focus.</p>
|
||
</div>
|
||
</div>
|
||
<div class="refsect1">
|
||
<a name="GtkDrawingArea.functions_details"></a><h2>Functions</h2>
|
||
<div class="refsect2">
|
||
<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="refsect3">
|
||
<a name="gtk-drawing-area-new.returns"></a><h4>Returns</h4>
|
||
<p> a new <a class="link" href="GtkDrawingArea.html" title="GtkDrawingArea"><span class="type">GtkDrawingArea</span></a></p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="refsect1">
|
||
<a name="GtkDrawingArea.other_details"></a><h2>Types and Values</h2>
|
||
<div class="refsect2">
|
||
<a name="GtkDrawingArea-struct"></a><h3>struct GtkDrawingArea</h3>
|
||
<pre class="programlisting">struct GtkDrawingArea;</pre>
|
||
</div>
|
||
</div>
|
||
<div class="refsect1">
|
||
<a name="GtkDrawingArea.see-also"></a><h2>See Also</h2>
|
||
<p><a class="link" href="GtkImage.html" title="GtkImage"><span class="type">GtkImage</span></a></p>
|
||
</div>
|
||
</div>
|
||
<div class="footer">
|
||
<hr>Generated by GTK-Doc V1.25.1</div>
|
||
</body>
|
||
</html> |