Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

Q3CanvasSprite Class Reference
[Qt3Support module]

The Q3CanvasSprite class provides an animated canvas item on a Q3Canvas. More...

 #include <Q3CanvasSprite>

This class is part of the Qt 3 support library. It is provided to keep old source code working. We strongly advise against using it in new code. See Porting to Qt 4 for more information.

This class is not part of the Qt GUI Framework Edition.

Inherits Q3CanvasItem.


Public Types

enum FrameAnimationType { Cycle, Oscillate }

Public Functions

Q3CanvasSprite ( Q3CanvasPixmapArray * a, Q3Canvas * canvas )
virtual ~Q3CanvasSprite ()
int bottomEdge () const
int bottomEdge ( int ny ) const
int frame () const
int frameCount () const
int height () const
Q3CanvasPixmap * image () const
Q3CanvasPixmap * image ( int f ) const
virtual Q3CanvasPixmap * imageAdvanced () const
int leftEdge () const
int leftEdge ( int nx ) const
void move ( double x, double y )
virtual void move ( double nx, double ny, int nf )
int rightEdge () const
int rightEdge ( int nx ) const
void setFrame ( int f )
virtual void setFrameAnimation ( FrameAnimationType type = Cycle, int step = 1, int state = 0 )
void setSequence ( Q3CanvasPixmapArray * a )
int topEdge () const
int topEdge ( int ny ) const
int width () const

Reimplemented Public Functions

virtual void advance ( int phase )
virtual QRect boundingRect () const
virtual bool collidesWith ( const Q3CanvasItem * i ) const
virtual void draw ( QPainter & painter )
virtual int rtti () const

Additional Inherited Members


Detailed Description

The Q3CanvasSprite class provides an animated canvas item on a Q3Canvas.

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 setSequence(). If you subclass Q3CanvasSprite you can change the frame that is displayed periodically, e.g. whenever Q3CanvasItem::advance(1) is called to create the effect of animation.

The current frame can be set with setFrame() or with move(). The number of frames available is given by frameCount(). The bounding rectangle of the current frame is returned by boundingRect().

The current frame's image can be retrieved with image(); use imageAdvanced() to retrieve the image for the frame that will be shown after advance(1) is called. Use the image() overload passing it an integer index to retrieve a particular image from the list of frames.

Use width() and height() to retrieve the dimensions of the current frame.

Use leftEdge() and rightEdge() to retrieve the current frame's left-hand and right-hand x-coordinates respectively. Use bottomEdge() and topEdge() 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.

Q3CanvasSprite draws very quickly, at the expense of memory.

The current frame's image can be drawn on a painter with draw().

Like any other canvas item, canvas sprites can be moved with move() which sets the x and y coordinates and the frame number, as well as with Q3CanvasItem::move() and Q3CanvasItem::moveBy(), or by setting coordinates with Q3CanvasItem::setX(), Q3CanvasItem::setY() and Q3CanvasItem::setZ().

See also QtCanvas and Porting to Graphics View.


Member Type Documentation

enum Q3CanvasSprite::FrameAnimationType

This enum is used to identify the different types of frame animation offered by Q3CanvasSprite.

ConstantValueDescription
Q3CanvasSprite::Cycle0at each advance the frame number will be incremented by 1 (modulo the frame count).
Q3CanvasSprite::Oscillate1at 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.


Member Function Documentation

Q3CanvasSprite::Q3CanvasSprite ( Q3CanvasPixmapArray * a, Q3Canvas * canvas )

Constructs a Q3CanvasSprite which uses images from the Q3CanvasPixmapArray a.

The sprite in initially positioned at (0, 0) on canvas, using frame 0.

Q3CanvasSprite::~Q3CanvasSprite ()   [virtual]

Destroys the sprite and removes it from the canvas. Does not delete the images.

void Q3CanvasSprite::advance ( int phase )   [virtual]

Reimplemented from Q3CanvasItem::advance().

Extends the default Q3CanvasItem implementation to provide the functionality of setFrameAnimation().

The phase is 0 or 1: see Q3CanvasItem::advance() for details.

See also Q3CanvasItem::advance() and setVelocity().

int Q3CanvasSprite::bottomEdge () const

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.)

See also leftEdge(), rightEdge(), and topEdge().

int Q3CanvasSprite::bottomEdge ( int ny ) const

This is an overloaded function.

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 ny.

See also leftEdge(), rightEdge(), and topEdge().

QRect Q3CanvasSprite::boundingRect () const   [virtual]

Reimplemented from Q3CanvasItem::boundingRect().

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).

bool Q3CanvasSprite::collidesWith ( const Q3CanvasItem * i ) const   [virtual]

Reimplemented from Q3CanvasItem::collidesWith().

void Q3CanvasSprite::draw ( QPainter & painter )   [virtual]

Reimplemented from Q3CanvasItem::draw().

Draws the current frame's image at the sprite's current position on painter painter.

int Q3CanvasSprite::frame () const

Returns the index of the current animation frame in the Q3CanvasSprite's Q3CanvasPixmapArray.

See also setFrame() and move().

int Q3CanvasSprite::frameCount () const

Returns the number of frames in the Q3CanvasSprite's Q3CanvasPixmapArray.

int Q3CanvasSprite::height () const

The height of the sprite for the current frame's image.

See also frame().

Q3CanvasPixmap * Q3CanvasSprite::image () const

Returns the current frame's image.

See also frame() and setFrame().

Q3CanvasPixmap * Q3CanvasSprite::image ( int f ) const

This is an overloaded function.

Returns the image for frame f. Does not do any bounds checking on f.

Q3CanvasPixmap * Q3CanvasSprite::imageAdvanced () const   [virtual]

Returns the image the sprite will have after advance(1) is called. By default this is the same as image().

int Q3CanvasSprite::leftEdge () const

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.)

See also rightEdge(), bottomEdge(), and topEdge().

int Q3CanvasSprite::leftEdge ( int nx ) const

This is an overloaded function.

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 nx.

See also rightEdge(), bottomEdge(), and topEdge().

void Q3CanvasSprite::move ( double x, double y )

Moves the sprite to (x, y).

void Q3CanvasSprite::move ( double nx, double ny, int nf )   [virtual]

Moves the sprite to (nx, ny) and sets the current frame to nf. nf will be ignored if it is larger than frameCount() or smaller than 0.

int Q3CanvasSprite::rightEdge () const

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.)

See also leftEdge(), bottomEdge(), and topEdge().

int Q3CanvasSprite::rightEdge ( int nx ) const

This is an overloaded function.

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 nx.

See also leftEdge(), bottomEdge(), and topEdge().

int Q3CanvasSprite::rtti () const   [virtual]

Reimplemented from Q3CanvasItem::rtti().

Returns 1 (Q3CanvasItem::Rtti_Sprite).

See also Q3CanvasItem::rtti().

void Q3CanvasSprite::setFrame ( int f )

Sets the animation frame used for displaying the sprite to f, an index into the Q3CanvasSprite's Q3CanvasPixmapArray. The call will be ignored if f is larger than frameCount() or smaller than 0.

See also frame() and move().

void Q3CanvasSprite::setFrameAnimation ( FrameAnimationType type = Cycle, int step = 1, int state = 0 )   [virtual]

Sets the animation characteristics for the sprite.

For type == Cycle, the frames will increase by step at each advance, modulo the frameCount().

For type == Oscillate, the frames will increase by step at each advance, up to the frameCount(), then decrease by step back to 0, repeating forever.

The state parameter is for internal use.

void Q3CanvasSprite::setSequence ( Q3CanvasPixmapArray * a )

Set the array of images used for displaying the sprite to the Q3CanvasPixmapArray a.

If the current frame() is larger than the number of images in a, the current frame will be reset to 0.

int Q3CanvasSprite::topEdge () const

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.)

See also leftEdge(), rightEdge(), and bottomEdge().

int Q3CanvasSprite::topEdge ( int ny ) const

This is an overloaded function.

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 ny.

See also leftEdge(), rightEdge(), and bottomEdge().

int Q3CanvasSprite::width () const

The width of the sprite for the current frame's image.

See also frame().

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 80
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 6
Page suivante

Le Qt Labs au hasard

Logo

Améliorer les performances de Qt lors du rendu avec plus de SIMD

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.6
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web