source: trunk/doc/html/qcanvassprite.html

Last change on this file was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 17.0 KB
RevLine 
[190]1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/canvas/qcanvas.cpp:2483 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>QCanvasSprite Class</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { background: #ffffff; color: black; }
12--></style>
13</head>
14<body>
15
16<table border="0" cellpadding="0" cellspacing="0" width="100%">
17<tr bgcolor="#E5E5E5">
18<td valign=center>
19 <a href="index.html">
20<font color="#004faf">Home</font></a>
21 | <a href="classes.html">
22<font color="#004faf">All&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;Classes</font></a>
25 | <a href="annotated.html">
26<font color="#004faf">Annotated</font></a>
27 | <a href="groups.html">
28<font color="#004faf">Grouped&nbsp;Classes</font></a>
29 | <a href="functions.html">
30<font color="#004faf">Functions</font></a>
31</td>
32<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QCanvasSprite Class Reference<br><small>[<a href="canvas.html">canvas module</a>]</small></h1>
33
34<p>The QCanvasSprite class provides an animated canvas item on a QCanvas.
35<a href="#details">More...</a>
36<p><tt>#include &lt;<a href="qcanvas-h.html">qcanvas.h</a>&gt;</tt>
37<p>Inherits <a href="qcanvasitem.html">QCanvasItem</a>.
38<p><a href="qcanvassprite-members.html">List of all member functions.</a>
39<h2>Public Members</h2>
40<ul>
41<li class=fn><a href="#QCanvasSprite"><b>QCanvasSprite</b></a> ( QCanvasPixmapArray&nbsp;*&nbsp;a, QCanvas&nbsp;*&nbsp;canvas )</li>
42<li class=fn>void <a href="#setSequence"><b>setSequence</b></a> ( QCanvasPixmapArray&nbsp;*&nbsp;a )</li>
43<li class=fn>virtual <a href="#~QCanvasSprite"><b>~QCanvasSprite</b></a> ()</li>
44<li class=fn>virtual void <a href="#move"><b>move</b></a> ( double&nbsp;nx, double&nbsp;ny, int&nbsp;nf )</li>
45<li class=fn>void <a href="#setFrame"><b>setFrame</b></a> ( int&nbsp;f )</li>
46<li class=fn>enum <a href="#FrameAnimationType-enum"><b>FrameAnimationType</b></a> { Cycle, Oscillate }</li>
47<li class=fn>virtual void <a href="#setFrameAnimation"><b>setFrameAnimation</b></a> ( FrameAnimationType&nbsp;type = Cycle, int&nbsp;step = 1, int&nbsp;state = 0 )</li>
48<li class=fn>int <a href="#frame"><b>frame</b></a> () const</li>
49<li class=fn>int <a href="#frameCount"><b>frameCount</b></a> () const</li>
50<li class=fn>virtual int <a href="#rtti"><b>rtti</b></a> () const</li>
51<li class=fn>virtual QRect <a href="#boundingRect"><b>boundingRect</b></a> () const</li>
52<li class=fn>int <a href="#width"><b>width</b></a> () const</li>
53<li class=fn>int <a href="#height"><b>height</b></a> () const</li>
54<li class=fn>int <a href="#leftEdge"><b>leftEdge</b></a> () const</li>
55<li class=fn>int <a href="#topEdge"><b>topEdge</b></a> () const</li>
56<li class=fn>int <a href="#rightEdge"><b>rightEdge</b></a> () const</li>
57<li class=fn>int <a href="#bottomEdge"><b>bottomEdge</b></a> () const</li>
58<li class=fn>int <a href="#leftEdge-2"><b>leftEdge</b></a> ( int&nbsp;nx ) const</li>
59<li class=fn>int <a href="#topEdge-2"><b>topEdge</b></a> ( int&nbsp;ny ) const</li>
60<li class=fn>int <a href="#rightEdge-2"><b>rightEdge</b></a> ( int&nbsp;nx ) const</li>
61<li class=fn>int <a href="#bottomEdge-2"><b>bottomEdge</b></a> ( int&nbsp;ny ) const</li>
62<li class=fn>QCanvasPixmap * <a href="#image"><b>image</b></a> () const</li>
63<li class=fn>virtual QCanvasPixmap * <a href="#imageAdvanced"><b>imageAdvanced</b></a> () const</li>
64<li class=fn>QCanvasPixmap * <a href="#image-2"><b>image</b></a> ( int&nbsp;f ) const</li>
65<li class=fn>virtual void <a href="#advance"><b>advance</b></a> ( int&nbsp;phase )</li>
66<li class=fn>virtual void <a href="#draw"><b>draw</b></a> ( QPainter&nbsp;&amp;&nbsp;painter )</li>
67</ul>
68<hr><a name="details"></a><h2>Detailed Description</h2>
69
70
71The QCanvasSprite class provides an animated canvas item on a <a href="qcanvas.html">QCanvas</a>.
72
73<p>
74
75
76<p> A canvas sprite is an object which can contain any number of images
77(referred to as frames), only one of which is current, i.e.
78displayed, at any one time. The images can be passed in the
79constructor or set or changed later with <a href="#setSequence">setSequence</a>(). If you
80subclass QCanvasSprite you can change the frame that is displayed
81periodically, e.g. whenever <a href="qcanvasitem.html#advance">QCanvasItem::advance</a>(1) is called to
82create the effect of animation.
83<p> The current frame can be set with <a href="#setFrame">setFrame</a>() or with <a href="#move">move</a>(). The
84number of frames available is given by <a href="#frameCount">frameCount</a>(). The bounding
85rectangle of the current frame is returned by <a href="#boundingRect">boundingRect</a>().
86<p> The current frame's image can be retrieved with <a href="#image">image</a>(); use
87<a href="#imageAdvanced">imageAdvanced</a>() to retrieve the image for the frame that will be
88shown after <a href="#advance">advance</a>(1) is called. Use the image() overload passing
89it an integer index to retrieve a particular image from the list of
90frames.
91<p> Use <a href="#width">width</a>() and <a href="#height">height</a>() to retrieve the dimensions of the current
92frame.
93<p> Use <a href="#leftEdge">leftEdge</a>() and <a href="#rightEdge">rightEdge</a>() to retrieve the current frame's
94left-hand and right-hand x-coordinates respectively. Use
95<a href="#bottomEdge">bottomEdge</a>() and <a href="#topEdge">topEdge</a>() to retrieve the current frame's bottom
96and top y-coordinates respectively. These functions have an overload
97which will accept an integer frame number to retrieve the
98coordinates of a particular frame.
99<p> QCanvasSprite draws very quickly, at the expense of memory.
100<p> The current frame's image can be drawn on a painter with <a href="#draw">draw</a>().
101<p> Like any other canvas item, canvas sprites can be moved with
102<a href="#move">move</a>() which sets the x and y coordinates and the frame number, as
103well as with <a href="qcanvasitem.html#move">QCanvasItem::move</a>() and <a href="qcanvasitem.html#moveBy">QCanvasItem::moveBy</a>(), or by
104setting coordinates with <a href="qcanvasitem.html#setX">QCanvasItem::setX</a>(), <a href="qcanvasitem.html#setY">QCanvasItem::setY</a>()
105and <a href="qcanvasitem.html#setZ">QCanvasItem::setZ</a>().
106<p> <p>See also <a href="graphics.html">Graphics Classes</a> and <a href="images.html">Image Processing Classes</a>.
107
108<hr><h2>Member Type Documentation</h2>
109<h3 class=fn><a name="FrameAnimationType-enum"></a>QCanvasSprite::FrameAnimationType</h3>
110
111<p> This enum is used to identify the different types of frame
112animation offered by QCanvasSprite.
113<ul>
114<li><tt>QCanvasSprite::Cycle</tt> - at each advance the frame number will be incremented by
1151 (modulo the frame count).
116<li><tt>QCanvasSprite::Oscillate</tt> - at each advance the frame number will be
117incremented by 1 up to the frame count then decremented to by 1 to
1180, repeating this sequence forever.
119</ul>
120<hr><h2>Member Function Documentation</h2>
121<h3 class=fn><a name="QCanvasSprite"></a>QCanvasSprite::QCanvasSprite ( <a href="qcanvaspixmaparray.html">QCanvasPixmapArray</a>&nbsp;*&nbsp;a, <a href="qcanvas.html">QCanvas</a>&nbsp;*&nbsp;canvas )
122</h3>
123Constructs a QCanvasSprite which uses images from the
124<a href="qcanvaspixmaparray.html">QCanvasPixmapArray</a> <em>a</em>.
125<p> The sprite in initially positioned at (0, 0) on <em>canvas</em>, using
126frame 0.
127
128<h3 class=fn><a name="~QCanvasSprite"></a>QCanvasSprite::~QCanvasSprite ()<tt> [virtual]</tt>
129</h3>
130Destroys the sprite and removes it from the canvas. Does <em>not</em>
131delete the images.
132
133<h3 class=fn>void <a name="advance"></a>QCanvasSprite::advance ( int&nbsp;phase )<tt> [virtual]</tt>
134</h3>
135Extends the default <a href="qcanvasitem.html">QCanvasItem</a> implementation to provide the
136functionality of <a href="#setFrameAnimation">setFrameAnimation</a>().
137<p> The <em>phase</em> is 0 or 1: see <a href="qcanvasitem.html#advance">QCanvasItem::advance</a>() for details.
138<p> <p>See also <a href="qcanvasitem.html#advance">QCanvasItem::advance</a>() and <a href="qcanvasitem.html#setVelocity">setVelocity</a>().
139
140<p>Example: <a href="canvas-example.html#x2927">canvas/canvas.cpp</a>.
141<p>Reimplemented from <a href="qcanvasitem.html#advance">QCanvasItem</a>.
142<h3 class=fn>int <a name="bottomEdge"></a>QCanvasSprite::bottomEdge () const
143</h3>
144Returns the y-coordinate of the current bottom edge of the sprite.
145(This may change as the sprite animates since different frames may
146have different bottom edges.)
147<p> <p>See also <a href="#leftEdge">leftEdge</a>(), <a href="#rightEdge">rightEdge</a>(), and <a href="#topEdge">topEdge</a>().
148
149<h3 class=fn>int <a name="bottomEdge-2"></a>QCanvasSprite::bottomEdge ( int&nbsp;ny ) const
150</h3>
151This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
152<p> Returns what the y-coordinate of the top edge of the sprite would
153be if the sprite (actually its hotspot) were moved to y-position
154<em>ny</em>.
155<p> <p>See also <a href="#leftEdge">leftEdge</a>(), <a href="#rightEdge">rightEdge</a>(), and <a href="#topEdge">topEdge</a>().
156
157<h3 class=fn><a href="qrect.html">QRect</a> <a name="boundingRect"></a>QCanvasSprite::boundingRect () const<tt> [virtual]</tt>
158</h3>
159Returns the bounding rectangle for the image in the sprite's
160current frame. This assumes that the images are tightly cropped
161(i.e. do not have transparent pixels all along a side).
162
163<p>Reimplemented from <a href="qcanvasitem.html#boundingRect">QCanvasItem</a>.
164<h3 class=fn>void <a name="draw"></a>QCanvasSprite::draw ( <a href="qpainter.html">QPainter</a>&nbsp;&amp;&nbsp;painter )<tt> [virtual]</tt>
165</h3>
166Draws the current frame's image at the sprite's current position
167on painter <em>painter</em>.
168
169<p>Reimplemented from <a href="qcanvasitem.html#draw">QCanvasItem</a>.
170<h3 class=fn>int <a name="frame"></a>QCanvasSprite::frame () const
171</h3>
172
173<p> Returns the index of the current animation frame in the
174QCanvasSprite's <a href="qcanvaspixmaparray.html">QCanvasPixmapArray</a>.
175<p> <p>See also <a href="#setFrame">setFrame</a>() and <a href="#move">move</a>().
176
177<h3 class=fn>int <a name="frameCount"></a>QCanvasSprite::frameCount () const
178</h3>
179
180<p> Returns the number of frames in the QCanvasSprite's
181<a href="qcanvaspixmaparray.html">QCanvasPixmapArray</a>.
182
183<h3 class=fn>int <a name="height"></a>QCanvasSprite::height () const
184</h3>
185The height of the sprite for the current frame's image.
186<p> <p>See also <a href="#frame">frame</a>().
187
188<h3 class=fn><a href="qcanvaspixmap.html">QCanvasPixmap</a>&nbsp;* <a name="image"></a>QCanvasSprite::image () const
189</h3>
190
191<p> Returns the current frame's image.
192<p> <p>See also <a href="#frame">frame</a>() and <a href="#setFrame">setFrame</a>().
193
194<h3 class=fn><a href="qcanvaspixmap.html">QCanvasPixmap</a>&nbsp;* <a name="image-2"></a>QCanvasSprite::image ( int&nbsp;f ) const
195</h3>
196
197This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
198<p> Returns the image for frame <em>f</em>. Does not do any bounds checking on <em>f</em>.
199
200<h3 class=fn><a href="qcanvaspixmap.html">QCanvasPixmap</a>&nbsp;* <a name="imageAdvanced"></a>QCanvasSprite::imageAdvanced () const<tt> [virtual]</tt>
201</h3>
202Returns the image the sprite <em>will</em> have after <a href="#advance">advance</a>(1) is
203called. By default this is the same as <a href="#image">image</a>().
204
205<h3 class=fn>int <a name="leftEdge"></a>QCanvasSprite::leftEdge () const
206</h3>
207Returns the x-coordinate of the current left edge of the sprite.
208(This may change as the sprite animates since different frames may
209have different left edges.)
210<p> <p>See also <a href="#rightEdge">rightEdge</a>(), <a href="#bottomEdge">bottomEdge</a>(), and <a href="#topEdge">topEdge</a>().
211
212<h3 class=fn>int <a name="leftEdge-2"></a>QCanvasSprite::leftEdge ( int&nbsp;nx ) const
213</h3>
214This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
215<p> Returns what the x-coordinate of the left edge of the sprite would
216be if the sprite (actually its hotspot) were moved to x-position
217<em>nx</em>.
218<p> <p>See also <a href="#rightEdge">rightEdge</a>(), <a href="#bottomEdge">bottomEdge</a>(), and <a href="#topEdge">topEdge</a>().
219
220<h3 class=fn>void <a name="move"></a>QCanvasSprite::move ( double&nbsp;nx, double&nbsp;ny, int&nbsp;nf )<tt> [virtual]</tt>
221</h3>
222
223<p> Set the position of the sprite to <em>nx</em>, <em>ny</em> and the current
224frame to <em>nf</em>. <em>nf</em> will be ignored if it is larger than
225<a href="#frameCount">frameCount</a>() or smaller than 0.
226
227<h3 class=fn>int <a name="rightEdge"></a>QCanvasSprite::rightEdge () const
228</h3>
229Returns the x-coordinate of the current right edge of the sprite.
230(This may change as the sprite animates since different frames may
231have different right edges.)
232<p> <p>See also <a href="#leftEdge">leftEdge</a>(), <a href="#bottomEdge">bottomEdge</a>(), and <a href="#topEdge">topEdge</a>().
233
234<h3 class=fn>int <a name="rightEdge-2"></a>QCanvasSprite::rightEdge ( int&nbsp;nx ) const
235</h3>
236This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
237<p> Returns what the x-coordinate of the right edge of the sprite
238would be if the sprite (actually its hotspot) were moved to
239x-position <em>nx</em>.
240<p> <p>See also <a href="#leftEdge">leftEdge</a>(), <a href="#bottomEdge">bottomEdge</a>(), and <a href="#topEdge">topEdge</a>().
241
242<h3 class=fn>int <a name="rtti"></a>QCanvasSprite::rtti () const<tt> [virtual]</tt>
243</h3>
244Returns 1 (QCanvasItem::Rtti_Sprite).
245<p> <p>See also <a href="qcanvasitem.html#rtti">QCanvasItem::rtti</a>().
246
247<p>Example: <a href="canvas-example.html#x2928">canvas/canvas.cpp</a>.
248<p>Reimplemented from <a href="qcanvasitem.html#rtti">QCanvasItem</a>.
249<h3 class=fn>void <a name="setFrame"></a>QCanvasSprite::setFrame ( int&nbsp;f )
250</h3>
251Sets the animation frame used for displaying the sprite to <em>f</em>,
252an index into the QCanvasSprite's <a href="qcanvaspixmaparray.html">QCanvasPixmapArray</a>. The call
253will be ignored if <em>f</em> is larger than <a href="#frameCount">frameCount</a>() or smaller
254than 0.
255<p> <p>See also <a href="#frame">frame</a>() and <a href="#move">move</a>().
256
257<h3 class=fn>void <a name="setFrameAnimation"></a>QCanvasSprite::setFrameAnimation ( <a href="qcanvassprite.html#FrameAnimationType-enum">FrameAnimationType</a>&nbsp;type = Cycle, int&nbsp;step = 1, int&nbsp;state = 0 )<tt> [virtual]</tt>
258</h3>
259Sets the animation characteristics for the sprite.
260<p> For <em>type</em> == <a href="#FrameAnimationType-enum">Cycle</a>, the frames will increase by <em>step</em>
261at each advance, modulo the <a href="#frameCount">frameCount</a>().
262<p> For <em>type</em> == <a href="#FrameAnimationType-enum">Oscillate</a>, the frames will increase by <em>step</em>
263at each advance, up to the frameCount(), then decrease by <em>step</em>
264back to 0, repeating forever.
265<p> The <em>state</em> parameter is for internal use.
266
267<h3 class=fn>void <a name="setSequence"></a>QCanvasSprite::setSequence ( <a href="qcanvaspixmaparray.html">QCanvasPixmapArray</a>&nbsp;*&nbsp;a )
268</h3>
269Set the array of images used for displaying the sprite to the
270<a href="qcanvaspixmaparray.html">QCanvasPixmapArray</a> <em>a</em>.
271<p> If the current <a href="#frame">frame</a>() is larger than the number of images in <em>a</em>, the current frame will be reset to 0.
272
273<h3 class=fn>int <a name="topEdge"></a>QCanvasSprite::topEdge () const
274</h3>
275Returns the y-coordinate of the top edge of the sprite. (This may
276change as the sprite animates since different frames may have
277different top edges.)
278<p> <p>See also <a href="#leftEdge">leftEdge</a>(), <a href="#rightEdge">rightEdge</a>(), and <a href="#bottomEdge">bottomEdge</a>().
279
280<h3 class=fn>int <a name="topEdge-2"></a>QCanvasSprite::topEdge ( int&nbsp;ny ) const
281</h3>
282This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
283<p> Returns what the y-coordinate of the top edge of the sprite would
284be if the sprite (actually its hotspot) were moved to y-position
285<em>ny</em>.
286<p> <p>See also <a href="#leftEdge">leftEdge</a>(), <a href="#rightEdge">rightEdge</a>(), and <a href="#bottomEdge">bottomEdge</a>().
287
288<h3 class=fn>int <a name="width"></a>QCanvasSprite::width () const
289</h3>
290The width of the sprite for the current frame's image.
291<p> <p>See also <a href="#frame">frame</a>().
292
293<!-- eof -->
294<hr><p>
295This file is part of the <a href="index.html">Qt toolkit</a>.
296Copyright &copy; 1995-2007
297<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
298<table width=100% cellspacing=0 border=0><tr>
299<td>Copyright &copy; 2007
300<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
301<td align=right><div align=right>Qt 3.3.8</div>
302</table></div></address></body>
303</html>
Note: See TracBrowser for help on using the repository browser.