summaryrefslogtreecommitdiffstats
path: root/doc/html/tqcanvassprite.html
blob: ce211965d83cd410457ec0aaaacd140d53b3d3e7 (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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>TQCanvasSprite 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>TQCanvasSprite Class Reference<br><small>[<a href="canvas.html">canvas module</a>]</small></h1>

<p>The TQCanvasSprite class provides an animated canvas item on a TQCanvas.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="tqcanvas-h.html">tqcanvas.h</a>&gt;</tt>
<p>Inherits <a href="tqcanvasitem.html">TQCanvasItem</a>.
<p><a href="tqcanvassprite-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn><a href="#TQCanvasSprite"><b>TQCanvasSprite</b></a> ( TQCanvasPixmapArray&nbsp;*&nbsp;a, TQCanvas&nbsp;*&nbsp;canvas )</li>
<li class=fn>void <a href="#setSequence"><b>setSequence</b></a> ( TQCanvasPixmapArray&nbsp;*&nbsp;a )</li>
<li class=fn>virtual <a href="#~TQCanvasSprite"><b>~TQCanvasSprite</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 TQRect <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>TQCanvasPixmap * <a href="#image"><b>image</b></a> () const</li>
<li class=fn>virtual TQCanvasPixmap * <a href="#imageAdvanced"><b>imageAdvanced</b></a> () const</li>
<li class=fn>TQCanvasPixmap * <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> ( TQPainter&nbsp;&amp;&nbsp;painter )</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>


The TQCanvasSprite class provides an animated canvas item on a <a href="tqcanvas.html">TQCanvas</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 TQCanvasSprite you can change the frame that is displayed
periodically, e.g. whenever <a href="tqcanvasitem.html#advance">TQCanvasItem::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> TQCanvasSprite 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="tqcanvasitem.html#move">TQCanvasItem::move</a>() and <a href="tqcanvasitem.html#moveBy">TQCanvasItem::moveBy</a>(), or by
setting coordinates with <a href="tqcanvasitem.html#setX">TQCanvasItem::setX</a>(), <a href="tqcanvasitem.html#setY">TQCanvasItem::setY</a>()
and <a href="tqcanvasitem.html#setZ">TQCanvasItem::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>TQCanvasSprite::FrameAnimationType</h3>

<p> This enum is used to identify the different types of frame
animation offered by TQCanvasSprite.
<ul>
<li><tt>TQCanvasSprite::Cycle</tt> - at each advance the frame number will be incremented by
1 (modulo the frame count).
<li><tt>TQCanvasSprite::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="TQCanvasSprite"></a>TQCanvasSprite::TQCanvasSprite ( <a href="tqcanvaspixmaparray.html">TQCanvasPixmapArray</a>&nbsp;*&nbsp;a, <a href="tqcanvas.html">TQCanvas</a>&nbsp;*&nbsp;canvas )
</h3>
Constructs a TQCanvasSprite which uses images from the
<a href="tqcanvaspixmaparray.html">TQCanvasPixmapArray</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="~TQCanvasSprite"></a>TQCanvasSprite::~TQCanvasSprite ()<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>TQCanvasSprite::advance ( int&nbsp;phase )<tt> [virtual]</tt>
</h3>
Extends the default <a href="tqcanvasitem.html">TQCanvasItem</a> implementation to provide the
functionality of <a href="#setFrameAnimation">setFrameAnimation</a>().
<p> The <em>phase</em> is 0 or 1: see <a href="tqcanvasitem.html#advance">TQCanvasItem::advance</a>() for details.
<p> <p>See also <a href="tqcanvasitem.html#advance">TQCanvasItem::advance</a>() and <a href="tqcanvasitem.html#setVelocity">setVelocity</a>().

<p>Example: <a href="canvas-example.html#x2927">canvas/canvas.cpp</a>.
<p>Reimplemented from <a href="tqcanvasitem.html#advance">TQCanvasItem</a>.
<h3 class=fn>int <a name="bottomEdge"></a>TQCanvasSprite::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>TQCanvasSprite::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="tqrect.html">TQRect</a> <a name="boundingRect"></a>TQCanvasSprite::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="tqcanvasitem.html#boundingRect">TQCanvasItem</a>.
<h3 class=fn>void <a name="draw"></a>TQCanvasSprite::draw ( <a href="tqpainter.html">TQPainter</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="tqcanvasitem.html#draw">TQCanvasItem</a>.
<h3 class=fn>int <a name="frame"></a>TQCanvasSprite::frame () const
</h3>

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

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

<p> Returns the number of frames in the TQCanvasSprite's
<a href="tqcanvaspixmaparray.html">TQCanvasPixmapArray</a>.

<h3 class=fn>int <a name="height"></a>TQCanvasSprite::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="tqcanvaspixmap.html">TQCanvasPixmap</a>&nbsp;* <a name="image"></a>TQCanvasSprite::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="tqcanvaspixmap.html">TQCanvasPixmap</a>&nbsp;* <a name="image-2"></a>TQCanvasSprite::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="tqcanvaspixmap.html">TQCanvasPixmap</a>&nbsp;* <a name="imageAdvanced"></a>TQCanvasSprite::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>TQCanvasSprite::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>TQCanvasSprite::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>TQCanvasSprite::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>TQCanvasSprite::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>TQCanvasSprite::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>TQCanvasSprite::rtti () const<tt> [virtual]</tt>
</h3>
Returns 1 (TQCanvasItem::Rtti_Sprite).
<p> <p>See also <a href="tqcanvasitem.html#rtti">TQCanvasItem::rtti</a>().

<p>Example: <a href="canvas-example.html#x2928">canvas/canvas.cpp</a>.
<p>Reimplemented from <a href="tqcanvasitem.html#rtti">TQCanvasItem</a>.
<h3 class=fn>void <a name="setFrame"></a>TQCanvasSprite::setFrame ( int&nbsp;f )
</h3>
Sets the animation frame used for displaying the sprite to <em>f</em>,
an index into the TQCanvasSprite's <a href="tqcanvaspixmaparray.html">TQCanvasPixmapArray</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>TQCanvasSprite::setFrameAnimation ( <a href="tqcanvassprite.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>TQCanvasSprite::setSequence ( <a href="tqcanvaspixmaparray.html">TQCanvasPixmapArray</a>&nbsp;*&nbsp;a )
</h3>
Set the array of images used for displaying the sprite to the
<a href="tqcanvaspixmaparray.html">TQCanvasPixmapArray</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>TQCanvasSprite::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>TQCanvasSprite::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>TQCanvasSprite::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">TQt 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>TQt 3.3.8</div>
</table></div></address></body>
</html>