Debian Codegraph @

doc/reference/migrating-ClutterPath.xml

raw
1 <?xml version="1.0"?>
2 <!DOCTYPE chapter PUBLIC
3 "-//OASIS//DTD DocBook XML V4.3//EN"
4 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
5 ]>
6 <chapter id="migrating-ClutterPath">
7
8 <chapterinfo>
9 <author>
10 <firstname>Emmanuele</firstname>
11 <surname>Bassi</surname>
12 <affiliation>
13 <address>
14 <email>[email protected]</email>
15 </address>
16 </affiliation>
17 </author>
18 </chapterinfo>
19
20 <title>Migrating to ClutterPath</title>
21
22 <para>Between Clutter 0.8 and Clutter 1.0 the #ClutterBehaviourPath
23 behaviour lost all the path manipulation functions and the
24 <structname>ClutterBehaviourBspline</structname> class was entirely
25 deprecated.</para>
26
27 <para>The class that replaced the path description and manipulation
28 functionality is called #ClutterPath. A #ClutterPath allows
29 describing a path using a sequence of #ClutterPathNode<!-- -->s or
30 using a subset of the SVG path description syntax. A Path instance
31 also allows describing complex paths, with linear and Bezier segments
32 and with gaps.</para>
33
34 <para>Finally, #ClutterPath also provides integration with Cairo,
35 by being able to add paths described by the Cairo
36 <structname>cairo_path_t</structname> data structure and being able
37 to "replay" a #ClutterPath onto a <structname>cairo_t</structname>
38 Cairo context.</para>
39
40 <section id="creating-paths">
41 <title>Creating a #ClutterPath</title>
42
43 <para>Before Clutter 1.0, all the path-related functions inside
44 #ClutterBehaviourPath and <structname>ClutterBehaviourBspline</structname>
45 were replicated, but were also subtly different given the different nature
46 of the types of path handled by the two #ClutterBehaviour<!-- -->s.</para>
47
48 <example id="example-clutter-behaviour-path">
49 <title>ClutterBehaviourPath example</title>
50 <para>The following code shows how a #ClutterBehaviourPath was
51 created prior to the introduction of #ClutterPath. The path described
52 is a square box between 100, 100 and 200, 200.</para>
53 <programlisting>
54 ClutterBehaviour *behaviour;
55 ClutterKnot knots[] = {
56 { 100, 100 },
57 { 200, 100 },
58 { 200, 200 },
59 { 100, 200 },
60 { 100, 100 }
61 };
62
63 behaviour = clutter_behaviour_path_new (alpha, knots, G_N_ELEMENTS (knots));
64 </programlisting>
65 </example>
66
67 <para>The construction for a B-Spline path behaviour was similar, though
68 the #ClutterKnot<!-- -->s could only describe a curvilinear path.</para>
69
70 <example id="example-construct-clutter-path">
71 <title>Constructing ClutterPath</title>
72 <para>The following code shows how to construct a #ClutterPath and
73 assign it to a #ClutterBehaviourPath. The created path is the same as
74 the example above.</para>
75 <programlisting>
76 ClutterBehaviour *behaviour;
77 ClutterPath *path;
78
79 path = clutter_path_new ();
80 clutter_path_add_move_to (path, 100, 100);
81 clutter_path_add_line_to (path, 200, 100);
82 clutter_path_add_line_to (path, 200, 200);
83 clutter_path_add_line_to (path, 100, 200);
84 clutter_path_add_close (path);
85
86 behaviour = clutter_behaviour_path_new (alpha, path);
87 </programlisting>
88 </example>
89
90 <para><note>A #ClutterPath object can be shared across behaviours, just
91 like the #ClutterAlpha objects can.</note></para>
92
93 <para>Path can be described by using a subset of the SVG notation for
94 paths as well as using #ClutterPathNode structures.</para>
95
96 <example id="example-describe-clutter-path">
97 <title>Describing ClutterPath</title>
98 <para>The SVG path notation subset used by #ClutterPath is in
99 string format and can be both set as the whole path description
100 using clutter_path_set_description() or can be added to an
101 existing #ClutterPath using clutter_path_add_string(). The following
102 example shows the same path as the two examples above.</para>
103 <programlisting>
104 ClutterPath *path = clutter_path_new ();
105
106 clutter_path_set_description (path,
107 "M 100,100 " /* move to */
108 "L 200,100 " /* line to */
109 "L 200,200 "
110 "L 100,200 "
111 "z" /* close */);
112 </programlisting>
113 </example>
114
115 <para>A #ClutterPath can describe not only linear, closed paths; it
116 can also describe paths with Beziér curvers and can add gaps.</para>
117
118 <example id="example-describe-mixed-clutter-path">
119 <title>Describing a mixed ClutterPath</title>
120 <para>A mixed #ClutterPath, with a Beziér curve between the point
121 at 200, 200 and 100, 100 and both control points in 100, 200.</para>
122 <programlisting>
123 ClutterPath *path = clutter_path_new ();
124
125 clutter_path_set_description (path,
126 "M 100,100 "
127 "L 200,100 "
128 "L 200,200 "
129 "C 100,200 100,200 100,100");
130 </programlisting>
131 </example>
132
133 </section>
134
135 <section id="iterating-paths">
136 <title>Iterating over a #ClutterPath</title>
137
138 <para>It is possible to iterate over all the #ClutterPathNode<!-- -->s
139 inside a #ClutterPath by using clutter_path_get_nodes(), which will return
140 a #GSList of #ClutterPathNode<!-- -->s; or by using clutter_path_foreach()
141 with a function.</para>
142
143 <para>The function pointer passed to clutter_path_foreach() should have the
144 following definition:</para>
145
146 <informalexample><programlisting>
147 static void
148 foreach_node (ClutterPathNode *path_node,
149 gpointer user_data)
150 {
151 }
152 </programlisting></informalexample>
153 </section>
154
155 <section id="using-cairo">
156 <title>Integration with Cairo</title>
157
158 <para>A #ClutterPath can use a previously defined
159 <structname>cairo_path_t</structname> to add new nodes, by using
160 the clutter_path_add_cairo_path() function.</para>
161
162 <para>It is also possible to paint a #ClutterPath on a Cairo context,
163 by moving the Cairo pen across the nodes of the path using the
164 clutter_path_to_cairo_path() function.</para>
165 </section>
166
167 </chapter>