| 1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| 5 |
<title>Underlying Architecture: GooCanvas Reference Manual</title> |
| 6 |
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1"> |
| 7 |
<link rel="home" href="index.html" title="GooCanvas Reference Manual"> |
| 8 |
<link rel="up" href="ch01.html" title="Introduction"> |
| 9 |
<link rel="prev" href="goocanvas-model-view-canvas.html" title="Model/View Canvas Example"> |
| 10 |
<link rel="next" href="goocanvas-coordinates.html" title="Coordinate Spaces and Limits"> |
| 11 |
<meta name="generator" content="GTK-Doc V1.26 (XML mode)"> |
| 12 |
<link rel="stylesheet" href="style.css" type="text/css"> |
| 13 |
</head> |
| 14 |
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> |
| 15 |
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle"> |
| 16 |
<td width="100%" align="left" class="shortcuts"></td> |
| 17 |
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td> |
| 18 |
<td><a accesskey="u" href="ch01.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td> |
| 19 |
<td><a accesskey="p" href="goocanvas-model-view-canvas.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td> |
| 20 |
<td><a accesskey="n" href="goocanvas-coordinates.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td> |
| 21 |
</tr></table> |
| 22 |
<div class="refentry"> |
| 23 |
<a name="goocanvas-architecture"></a><div class="titlepage"></div> |
| 24 |
<div class="refnamediv"><table width="100%"><tr> |
| 25 |
<td valign="top"> |
| 26 |
<h2><span class="refentrytitle">Underlying Architecture</span></h2> |
| 27 |
<p>Underlying Architecture — how the canvas fits together.</p> |
| 28 |
</td> |
| 29 |
<td class="gallery_image" valign="top" align="right"></td> |
| 30 |
</tr></table></div> |
| 31 |
<div class="refsect1"> |
| 32 |
<a name="architecture"></a><h2>Underlying Architecture</h2> |
| 33 |
<div class="refsect2"> |
| 34 |
<a name="widget"></a><h3>The GooCanvas Widget</h3> |
| 35 |
<p> |
| 36 |
<a class="link" href="GooCanvas.html" title="GooCanvas"><span class="type">GooCanvas</span></a> is a <a href="/usr/share/gtk-doc/html/gtk3/GtkWidget.html#GtkWidget-struct"><span class="type">GtkWidget</span></a> (it is actually a subclass of |
| 37 |
<a href="/usr/share/gtk-doc/html/gtk3/GtkContainer.html#GtkContainer-struct"><span class="type">GtkContainer</span></a>), and so can be placed in an interface just like |
| 38 |
any normal widget. Usually a <a class="link" href="GooCanvas.html" title="GooCanvas"><span class="type">GooCanvas</span></a> widget would be placed inside |
| 39 |
a <a href="/usr/share/gtk-doc/html/gtk3/GtkScrolledWindow.html#GtkScrolledWindow-struct"><span class="type">GtkScrolledWindow</span></a> in order to enable scrolling of the canvas. |
| 40 |
</p> |
| 41 |
<p> |
| 42 |
The size of the canvas can be set explicitly using |
| 43 |
<a class="link" href="GooCanvas.html#goo-canvas-set-bounds" title="goo_canvas_set_bounds ()"><code class="function">goo_canvas_set_bounds()</code></a>, or if the <a class="link" href="GooCanvas.html#GooCanvas--automatic-bounds" title="The “automatic-bounds” property"><span class="type">“automatic-bounds”</span></a> |
| 44 |
property is set to <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> the bounds will be automatically calculated |
| 45 |
to include all of the canvas items. The units used in the canvas can |
| 46 |
be set with the <a class="link" href="GooCanvas.html#GooCanvas--units" title="The “units” property"><span class="type">“units”</span></a> property. The canvas units can be |
| 47 |
pixels, points, inches or millimeters and apply to the canvas and |
| 48 |
all items. |
| 49 |
</p> |
| 50 |
</div> |
| 51 |
<hr> |
| 52 |
<div class="refsect2"> |
| 53 |
<a name="simple-structure"></a><h3>The Structure of the Simple Canvas</h3> |
| 54 |
<p> |
| 55 |
The simple canvas consists of a hierarchy of canvas items. |
| 56 |
The root item is automatically created by the canvas and can be |
| 57 |
accessed using <a class="link" href="GooCanvas.html#goo-canvas-get-root-item" title="goo_canvas_get_root_item ()"><code class="function">goo_canvas_get_root_item()</code></a>. New items and groups can |
| 58 |
then be created and added to the root item. |
| 59 |
</p> |
| 60 |
<p> |
| 61 |
Each item in the canvas keeps a <a class="link" href="goocanvas2-GooCanvas-Types.html#GooCanvasBounds" title="struct GooCanvasBounds"><span class="type">GooCanvasBounds</span></a> structure which |
| 62 |
stores the bounding rectangle of the item and all of its descendants. |
| 63 |
This makes it easy to find out which items in the canvas need repainting |
| 64 |
or which item the mouse is over. (The bounds are stored in the canvas |
| 65 |
coordinate space, which is the coordinate space of the entire canvas, |
| 66 |
after any item transformation matrices have been applied.) |
| 67 |
</p> |
| 68 |
</div> |
| 69 |
<hr> |
| 70 |
<div class="refsect2"> |
| 71 |
<a name="model-view-structure"></a><h3>The Structure of the Model/View Canvas</h3> |
| 72 |
<p> |
| 73 |
The model/view canvas consists of a hierarchy of item models, and an |
| 74 |
identical hierarchy of canvas items, with each canvas item |
| 75 |
corresponding to one item model. |
| 76 |
</p> |
| 77 |
<p> |
| 78 |
The hierarchy of item models can be used in several <a class="link" href="GooCanvas.html" title="GooCanvas"><span class="type">GooCanvas</span></a> |
| 79 |
widgets, to allow multiple views of the same model. |
| 80 |
Though different canvas items will be used in each <a class="link" href="GooCanvas.html" title="GooCanvas"><span class="type">GooCanvas</span></a>. |
| 81 |
</p> |
| 82 |
<p> |
| 83 |
The root item model is set with <a class="link" href="GooCanvas.html#goo-canvas-set-root-item-model" title="goo_canvas_set_root_item_model ()"><code class="function">goo_canvas_set_root_item_model()</code></a>. |
| 84 |
The canvas will automatically create canvas items to display |
| 85 |
the hierarchy of item models, and will automatically add and |
| 86 |
remove canvas items as the item model hierarchy is changed. |
| 87 |
</p> |
| 88 |
</div> |
| 89 |
<hr> |
| 90 |
<div class="refsect2"> |
| 91 |
<a name="updates"></a><h3>The Update Procedure</h3> |
| 92 |
<p> |
| 93 |
When items are added to the canvas or their properties are changed |
| 94 |
they may need to recalculate their bounds. To do this they set an |
| 95 |
internal flag such as <em class="parameter"><code>need_update</code></em>, and make a call to |
| 96 |
<a class="link" href="GooCanvasItem.html#goo-canvas-item-request-update" title="goo_canvas_item_request_update ()"><code class="function">goo_canvas_item_request_update()</code></a>. |
| 97 |
</p> |
| 98 |
<p> |
| 99 |
<a class="link" href="GooCanvas.html" title="GooCanvas"><span class="type">GooCanvas</span></a> handles all the update requests at once, to avoid multiple |
| 100 |
redraws of the same parts of the canvas. To do this it installs |
| 101 |
an idle handler, <code class="function">goo_canvas_idle_handler()</code>, which is called as soon |
| 102 |
as the application is idle (and before any part of the canvas is |
| 103 |
redrawn). |
| 104 |
</p> |
| 105 |
<p> |
| 106 |
The idle handler calls <a class="link" href="GooCanvasItem.html#goo-canvas-item-update" title="goo_canvas_item_update ()"><code class="function">goo_canvas_item_update()</code></a> on the root item, |
| 107 |
which recursively calls <a class="link" href="GooCanvasItem.html#goo-canvas-item-update" title="goo_canvas_item_update ()"><code class="function">goo_canvas_item_update()</code></a> on any items as |
| 108 |
necessary, recalculating their bounds and requesting redraws as |
| 109 |
appropriate. |
| 110 |
</p> |
| 111 |
<p> |
| 112 |
If a container item (e.g. <a class="link" href="GooCanvasGroup.html" title="GooCanvasGroup"><span class="type">GooCanvasGroup</span></a>) is changed it needs to |
| 113 |
ensure that all descendants recalculate their bounds so it |
| 114 |
calls <a class="link" href="GooCanvasItem.html#goo-canvas-item-update" title="goo_canvas_item_update ()"><code class="function">goo_canvas_item_update()</code></a> for all of its children with the |
| 115 |
<em class="parameter"><code>entire_tree</code></em> argument set to <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>. |
| 116 |
</p> |
| 117 |
</div> |
| 118 |
<hr> |
| 119 |
<div class="refsect2"> |
| 120 |
<a name="simple-updates"></a><h3>How Changes to Items are Handled</h3> |
| 121 |
<p> |
| 122 |
When an item is changed (e.g. if the <a class="link" href="GooCanvasRect.html#GooCanvasRect--x" title="The “x” property"><span class="type">“x”</span></a> property of |
| 123 |
a <a class="link" href="GooCanvasRect.html" title="GooCanvasRect"><span class="type">GooCanvasRect</span></a> is changed), the item calls |
| 124 |
<a class="link" href="GooCanvasItemSimple.html#goo-canvas-item-simple-changed" title="goo_canvas_item_simple_changed ()"><code class="function">goo_canvas_item_simple_changed()</code></a> with a flag indicating if the |
| 125 |
bounds of the item need to be recalculated. |
| 126 |
</p> |
| 127 |
<p> |
| 128 |
If the bounds don't need to be recalculated, then |
| 129 |
<a class="link" href="GooCanvas.html#goo-canvas-request-redraw" title="goo_canvas_request_redraw ()"><code class="function">goo_canvas_request_redraw()</code></a> is called to simply request that the |
| 130 |
item is redrawn. This results in a call to <a href="/usr/share/gtk-doc/html/gdk3/gdk3-Windows.html#gdk-window-invalidate-rect"><code class="function">gdk_window_invalidate_rect()</code></a> |
| 131 |
and the redraw proceeds just like a normal <a href="/usr/share/gtk-doc/html/gtk3/GtkWidget.html#GtkWidget-struct"><span class="type">GtkWidget</span></a>. |
| 132 |
</p> |
| 133 |
<p> |
| 134 |
However, if the bounds do need to be recalculated then |
| 135 |
<a class="link" href="GooCanvasItem.html#goo-canvas-item-request-update" title="goo_canvas_item_request_update ()"><code class="function">goo_canvas_item_request_update()</code></a> is called to request that the item |
| 136 |
be updated the next time the canvas performs an update. |
| 137 |
</p> |
| 138 |
</div> |
| 139 |
<hr> |
| 140 |
<div class="refsect2"> |
| 141 |
<a name="model-view-updates"></a><h3>How Changes are Handled in the Model/View Canvas</h3> |
| 142 |
<p> |
| 143 |
In the Model/View canvas it is the underlying item models which are |
| 144 |
initially changed. The item models emit "changed" signals which the |
| 145 |
items respond to. For the standard canvas items the |
| 146 |
<code class="function">goo_canvas_item_model_simple_changed()</code> signal handler is called, |
| 147 |
which calls <a class="link" href="GooCanvasItemSimple.html#goo-canvas-item-simple-changed" title="goo_canvas_item_simple_changed ()"><code class="function">goo_canvas_item_simple_changed()</code></a> and the |
| 148 |
procedure continues as in the simple canvas case above. |
| 149 |
</p> |
| 150 |
</div> |
| 151 |
</div> |
| 152 |
</div> |
| 153 |
<div class="footer"> |
| 154 |
<hr>Generated by GTK-Doc V1.26</div> |
| 155 |
</body> |
| 156 |
</html> |