summaryrefslogtreecommitdiffstats
path: root/doc/html/qcanvassprite.html
blob: 13c4599b4e0c1d39fa0139fe454f872f16f8fbc2 (plain)
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/canvas/qcanvas.cpp:2483 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QCanvasSprite Class</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<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>

<p>The QCanvasSprite class provides an animated canvas item on a QCanvas.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qcanvas-h.html">qcanvas.h</a>&gt;</tt>
<p>Inherits <a href="qcanvasitem.html">QCanvasItem</a>.
<p><a href="qcanvassprite-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn><a href="#QCanvasSprite"><b>QCanvasSprite</b></a> ( QCanvasPixmapArray&nbsp;*&nbsp;a, QCanvas&nbsp;*&nbsp;canvas )</li>
<li class=fn>void <a href="#setSequence"><b>setSequence</b></a> ( QCanvasPixmapArray&nbsp;*&nbsp;a )</li>
<li class=fn>virtual <a href="#~QCanvasSprite"><b>~QCanvasSprite</b></a> ()</li>
<li class=fn>virtual void <a href="#move"><b>move</b></a> ( double&nbsp;nx, double&nbsp;ny, int&nbsp;nf )</li>
<li class=fn>void <a href="#setFrame"><b>setFrame</b></a> ( int&nbsp;f )</li>
<li class=fn>enum <a href="#FrameAnimationType-enum"><b>FrameAnimationType</b></a> { Cycle, Oscillate }</li>
<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>
<li class=fn>int <a href="#frame"><b>frame</b></a> () const</li>
<li class=fn>int <a href="#frameCount"><b>frameCount</b></a> () const</li>
<li class=fn>virtual int <a href="#rtti"><b>rtti</b></a> () const</li>
<li class=fn>virtual QRect <a href="#boundingRect"><b>boundingRect</b></a> () const</li>
<li class=fn>int <a href="#width"><b>width</b></a> () const</li>
<li class=fn>int <a href="#height"><b>height</b></a> () const</li>
<li class=fn>int <a href="#leftEdge"><b>leftEdge</b></a> () const</li>
<li class=fn>int <a href="#topEdge"><b>topEdge</b></a> () const</li>
<li class=fn>int <a href="#rightEdge"><b>rightEdge</b></a> () const</li>
<li class=fn>int <a href="#bottomEdge"><b>bottomEdge</b></a> () const</li>
<li class=fn>int <a href="#leftEdge-2"><b>leftEdge</b></a> ( int&nbsp;nx ) const</li>
<li class=fn>int <a href="#topEdge-2"><b>topEdge</b></a> ( int&nbsp;ny ) const</li>
<li class=fn>int <a href="#rightEdge-2"><b>rightEdge</b></a> ( int&nbsp;nx ) const</li>
<li class=fn>int <a href="#bottomEdge-2"><b>bottomEdge</b></a> ( int&nbsp;ny ) const</li>
<li class=fn>QCanvasPixmap * <a href="#image"><b>image</b></a> () const</li>
<li class=fn>virtual QCanvasPixmap * <a href="#imageAdvanced"><b>imageAdvanced</b></a> () const</li>
<li class=fn>QCanvasPixmap * <a href="#image-2"><b>image</b></a> ( int&nbsp;f ) const</li>
<li class=fn>virtual void <a href="#advance"><b>advance</b></a> ( int&nbsp;phase )</li>
<li class=fn>virtual void <a href="#draw"><b>draw</b></a> ( QPainter&nbsp;&amp;&nbsp;painter )</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>


The QCanvasSprite class provides an animated canvas item on a <a href="qcanvas.html">QCanvas</a>.

<p> 


<p> A canvas sprite is an object which can contain any number of images
(referred to as frames), only one of which is current, i.e.
displayed, at any one time. The images can be passed in the
constructor or set or changed later with <a href="#setSequence">setSequence</a>(). If you
subclass QCanvasSprite you can change the frame that is displayed
periodically, e.g. whenever <a href="qcanvasitem.html#advance">QCanvasItem::advance</a>(1) is called to
create the effect of animation.
<p> The current frame can be set with <a href="#setFrame">setFrame</a>() or with <a href="#move">move</a>(). The
number of frames available is given by <a href="#frameCount">frameCount</a>(). The bounding
rectangle of the current frame is returned by <a href="#boundingRect">boundingRect</a>().
<p> The current frame's image can be retrieved with <a href="#image">image</a>(); use
<a href="#imageAdvanced">imageAdvanced</a>() to retrieve the image for the frame that will be
shown after <a href="#advance">advance</a>(1) is called. Use the image() overload passing
it an integer index to retrieve a particular image from the list of
frames.
<p> Use <a href="#width">width</a>() and <a href="#height">height</a>() to retrieve the dimensions of the current
frame.
<p> Use <a href="#leftEdge">leftEdge</a>() and <a href="#rightEdge">rightEdge</a>() to retrieve the current frame's
left-hand and right-hand x-coordinates respectively. Use
<a href="#bottomEdge">bottomEdge</a>() and <a href="#topEdge">topEdge</a>() to retrieve the current frame's bottom
and top y-coordinates respectively. These functions have an overload
which will accept an integer frame number to retrieve the
coordinates of a particular frame.
<p> QCanvasSprite draws very quickly, at the expense of memory.
<p> The current frame's image can be drawn on a painter with <a href="#draw">draw</a>().
<p> Like any other canvas item, canvas sprites can be moved with
<a href="#move">move</a>() which sets the x and y coordinates and the frame number, as
well as with <a href="qcanvasitem.html#move">QCanvasItem::move</a>() and <a href="qcanvasitem.html#moveBy">QCanvasItem::moveBy</a>(), or by
setting coordinates with <a href="qcanvasitem.html#setX">QCanvasItem::setX</a>(), <a href="qcanvasitem.html#setY">QCanvasItem::setY</a>()
and <a href="qcanvasitem.html#setZ">QCanvasItem::setZ</a>().
<p> <p>See also <a href="graphics.html">Graphics Classes</a> and <a href="images.html">Image Processing Classes</a>.

<hr><h2>Member Type Documentation</h2>
<h3 class=fn><a name="FrameAnimationType-enum"></a>QCanvasSprite::FrameAnimationType</h3>

<p> This enum is used to identify the different types of frame
animation offered by QCanvasSprite.
<ul>
<li><tt>QCanvasSprite::Cycle</tt> - at each advance the frame number will be incremented by
1 (modulo the frame count).
<li><tt>QCanvasSprite::Oscillate</tt> - at each advance the frame number will be
incremented by 1 up to the frame count then decremented to by 1 to
0, repeating this sequence forever.
</ul>
<hr><h2>Member Function Documentation</h2>
<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 )
</h3>
Constructs a QCanvasSprite which uses images from the
<a href="qcanvaspixmaparray.html">QCanvasPixmapArray</a> <em>a</em>.
<p> The sprite in initially positioned at (0, 0) on <em>canvas</em>, using
frame 0.

<h3 class=fn><a name="~QCanvasSprite"></a>QCanvasSprite::~QCanvasSprite ()<tt> [virtual]</tt>
</h3>
Destroys the sprite and removes it from the canvas. Does <em>not</em>
delete the images.

<h3 class=fn>void <a name="advance"></a>QCanvasSprite::advance ( int&nbsp;phase )<tt> [virtual]</tt>
</h3>
Extends the default <a href="qcanvasitem.html">QCanvasItem</a> implementation to provide the
functionality of <a href="#setFrameAnimation">setFrameAnimation</a>().
<p> The <em>phase</em> is 0 or 1: see <a href="qcanvasitem.html#advance">QCanvasItem::advance</a>() for details.
<p> <p>See also <a href="qcanvasitem.html#advance">QCanvasItem::advance</a>() and <a href="qcanvasitem.html#setVelocity">setVelocity</a>().

<p>Example: <a href="canvas-example.html#x2927">canvas/canvas.cpp</a>.
<p>Reimplemented from <a href="qcanvasitem.html#advance">QCanvasItem</a>.
<h3 class=fn>int <a name="bottomEdge"></a>QCanvasSprite::bottomEdge () const
</h3>
Returns the y-coordinate of the current bottom edge of the sprite.
(This may change as the sprite animates since different frames may
have different bottom edges.)
<p> <p>See also <a href="#leftEdge">leftEdge</a>(), <a href="#rightEdge">rightEdge</a>(), and <a href="#topEdge">topEdge</a>().

<h3 class=fn>int <a name="bottomEdge-2"></a>QCanvasSprite::bottomEdge ( int&nbsp;ny ) const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns what the y-coordinate of the top edge of the sprite would
be if the sprite (actually its hotspot) were moved to y-position
<em>ny</em>.
<p> <p>See also <a href="#leftEdge">leftEdge</a>(), <a href="#rightEdge">rightEdge</a>(), and <a href="#topEdge">topEdge</a>().

<h3 class=fn><a href="qrect.html">QRect</a> <a name="boundingRect"></a>QCanvasSprite::boundingRect () const<tt> [virtual]</tt>
</h3>
Returns the bounding rectangle for the image in the sprite's
current frame. This assumes that the images are tightly cropped
(i.e. do not have transparent pixels all along a side).

<p>Reimplemented from <a href="qcanvasitem.html#boundingRect">QCanvasItem</a>.
<h3 class=fn>void <a name="draw"></a>QCanvasSprite::draw ( <a href="qpainter.html">QPainter</a>&nbsp;&amp;&nbsp;painter )<tt> [virtual]</tt>
</h3>
Draws the current frame's image at the sprite's current position
on painter <em>painter</em>.

<p>Reimplemented from <a href="qcanvasitem.html#draw">QCanvasItem</a>.
<h3 class=fn>int <a name="frame"></a>QCanvasSprite::frame () const
</h3>

<p> Returns the index of the current animation frame in the
QCanvasSprite's <a href="qcanvaspixmaparray.html">QCanvasPixmapArray</a>.
<p> <p>See also <a href="#setFrame">setFrame</a>() and <a href="#move">move</a>().

<h3 class=fn>int <a name="frameCount"></a>QCanvasSprite::frameCount () const
</h3>

<p> Returns the number of frames in the QCanvasSprite's
<a href="qcanvaspixmaparray.html">QCanvasPixmapArray</a>.

<h3 class=fn>int <a name="height"></a>QCanvasSprite::height () const
</h3>
The height of the sprite for the current frame's image.
<p> <p>See also <a href="#frame">frame</a>().

<h3 class=fn><a href="qcanvaspixmap.html">QCanvasPixmap</a>&nbsp;* <a name="image"></a>QCanvasSprite::image () const
</h3>

<p> Returns the current frame's image.
<p> <p>See also <a href="#frame">frame</a>() and <a href="#setFrame">setFrame</a>().

<h3 class=fn><a href="qcanvaspixmap.html">QCanvasPixmap</a>&nbsp;* <a name="image-2"></a>QCanvasSprite::image ( int&nbsp;f ) const
</h3>

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns the image for frame <em>f</em>. Does not do any bounds checking on <em>f</em>.

<h3 class=fn><a href="qcanvaspixmap.html">QCanvasPixmap</a>&nbsp;* <a name="imageAdvanced"></a>QCanvasSprite::imageAdvanced () const<tt> [virtual]</tt>
</h3>
Returns the image the sprite <em>will</em> have after <a href="#advance">advance</a>(1) is
called. By default this is the same as <a href="#image">image</a>().

<h3 class=fn>int <a name="leftEdge"></a>QCanvasSprite::leftEdge () const
</h3>
Returns the x-coordinate of the current left edge of the sprite.
(This may change as the sprite animates since different frames may
have different left edges.)
<p> <p>See also <a href="#rightEdge">rightEdge</a>(), <a href="#bottomEdge">bottomEdge</a>(), and <a href="#topEdge">topEdge</a>().

<h3 class=fn>int <a name="leftEdge-2"></a>QCanvasSprite::leftEdge ( int&nbsp;nx ) const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns what the x-coordinate of the left edge of the sprite would
be if the sprite (actually its hotspot) were moved to x-position
<em>nx</em>.
<p> <p>See also <a href="#rightEdge">rightEdge</a>(), <a href="#bottomEdge">bottomEdge</a>(), and <a href="#topEdge">topEdge</a>().

<h3 class=fn>void <a name="move"></a>QCanvasSprite::move ( double&nbsp;nx, double&nbsp;ny, int&nbsp;nf )<tt> [virtual]</tt>
</h3>

<p> Set the position of the sprite to <em>nx</em>, <em>ny</em> and the current
frame to <em>nf</em>. <em>nf</em> will be ignored if it is larger than
<a href="#frameCount">frameCount</a>() or smaller than 0.

<h3 class=fn>int <a name="rightEdge"></a>QCanvasSprite::rightEdge () const
</h3>
Returns the x-coordinate of the current right edge of the sprite.
(This may change as the sprite animates since different frames may
have different right edges.)
<p> <p>See also <a href="#leftEdge">leftEdge</a>(), <a href="#bottomEdge">bottomEdge</a>(), and <a href="#topEdge">topEdge</a>().

<h3 class=fn>int <a name="rightEdge-2"></a>QCanvasSprite::rightEdge ( int&nbsp;nx ) const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns what the x-coordinate of the right edge of the sprite
would be if the sprite (actually its hotspot) were moved to
x-position <em>nx</em>.
<p> <p>See also <a href="#leftEdge">leftEdge</a>(), <a href="#bottomEdge">bottomEdge</a>(), and <a href="#topEdge">topEdge</a>().

<h3 class=fn>int <a name="rtti"></a>QCanvasSprite::rtti () const<tt> [virtual]</tt>
</h3>
Returns 1 (QCanvasItem::Rtti_Sprite).
<p> <p>See also <a href="qcanvasitem.html#rtti">QCanvasItem::rtti</a>().

<p>Example: <a href="canvas-example.html#x2928">canvas/canvas.cpp</a>.
<p>Reimplemented from <a href="qcanvasitem.html#rtti">QCanvasItem</a>.
<h3 class=fn>void <a name="setFrame"></a>QCanvasSprite::setFrame ( int&nbsp;f )
</h3>
Sets the animation frame used for displaying the sprite to <em>f</em>,
an index into the QCanvasSprite's <a href="qcanvaspixmaparray.html">QCanvasPixmapArray</a>. The call
will be ignored if <em>f</em> is larger than <a href="#frameCount">frameCount</a>() or smaller
than 0.
<p> <p>See also <a href="#frame">frame</a>() and <a href="#move">move</a>().

<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>
</h3>
Sets the animation characteristics for the sprite.
<p> For <em>type</em> == <a href="#FrameAnimationType-enum">Cycle</a>, the frames will increase by <em>step</em>
at each advance, modulo the <a href="#frameCount">frameCount</a>().
<p> For <em>type</em> == <a href="#FrameAnimationType-enum">Oscillate</a>, the frames will increase by <em>step</em>
at each advance, up to the frameCount(), then decrease by <em>step</em>
back to 0, repeating forever.
<p> The <em>state</em> parameter is for internal use.

<h3 class=fn>void <a name="setSequence"></a>QCanvasSprite::setSequence ( <a href="qcanvaspixmaparray.html">QCanvasPixmapArray</a>&nbsp;*&nbsp;a )
</h3>
Set the array of images used for displaying the sprite to the
<a href="qcanvaspixmaparray.html">QCanvasPixmapArray</a> <em>a</em>.
<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.

<h3 class=fn>int <a name="topEdge"></a>QCanvasSprite::topEdge () const
</h3>
Returns the y-coordinate of the top edge of the sprite. (This may
change as the sprite animates since different frames may have
different top edges.)
<p> <p>See also <a href="#leftEdge">leftEdge</a>(), <a href="#rightEdge">rightEdge</a>(), and <a href="#bottomEdge">bottomEdge</a>().

<h3 class=fn>int <a name="topEdge-2"></a>QCanvasSprite::topEdge ( int&nbsp;ny ) const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns what the y-coordinate of the top edge of the sprite would
be if the sprite (actually its hotspot) were moved to y-position
<em>ny</em>.
<p> <p>See also <a href="#leftEdge">leftEdge</a>(), <a href="#rightEdge">rightEdge</a>(), and <a href="#bottomEdge">bottomEdge</a>().

<h3 class=fn>int <a name="width"></a>QCanvasSprite::width () const
</h3>
The width of the sprite for the current frame's image.
<p> <p>See also <a href="#frame">frame</a>().

<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>.
Copyright &copy; 1995-2007
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt 3.3.8</div>
</table></div></address></body>
</html>