cardsprite.h

Go to the documentation of this file.
00001 #ifndef CARD_SPRITE_H
00002 #define CARD_SPRITE_H
00003 /*
00004    This file is part of the KDE games lskat program
00005    Copyright (c) 2006 Martin Heni <kde@heni-online.de>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.
00021 */
00022 
00023 // Qt includes
00024 #include <QGraphicsPixmapItem>
00025 #include <QList>
00026 #include <QPoint>
00027 #include <QPointF>
00028 #include <QPixmap>
00029 
00030 // Local includes
00031 #include "thememanager.h"
00032 #include "deck.h"
00033 
00034 
00038 class CardSprite : public QGraphicsPixmapItem, public virtual Themable
00039 {
00040 
00041   public:
00049     CardSprite(const Suite suite, const CardType type, ThemeManager* theme, int advancePeriod, QGraphicsScene* scene);
00050 
00052     enum AnimationState {Idle, Turning, Moving, Removing,
00053                          ShuffleMove};
00054 
00059     virtual void changeTheme();
00060 
00063      void setFrontside();
00064 
00067      void setBackside();
00068 
00072      virtual void advance(int phase);
00073 
00076       void stop();
00077 
00081      void setTurning(bool front);
00082 
00088      void setMove(QPointF pos, double time);
00089 
00093      void setPosition(QPointF pos);
00094 
00100      void setRemove(QPointF pos, double time);
00101 
00109      void setShuffleMove(QPointF pos, double delay, bool front);
00110 
00115     void setFrame(int no, bool force=false);
00116 
00120     int count();
00121 
00125     int cardid() {return mCardType*4+mSuite;}
00126 
00130      int frame() {return mCurrentFrame;}
00131   
00132   protected:
00137     void calcFrame(int no);
00138 
00146     QPixmap createCard(const QPixmap front, const QPixmap back, int curNo, int count);
00147 
00152      void calcTargetAndSpeed(QPointF pos, double time);
00153 
00157      bool deltaMove();
00158     
00159 
00160   private:
00161     // Type of animation
00162     AnimationState mAnimationState;  
00163     // Counter of animation [ms]
00164     double mTime;
00165     // Target point for movment
00166     QPointF mMoveTarget;
00167     // Movement speed X
00168     double mMoveSpeedX;
00169     // Movement speed Y
00170     double mMoveSpeedY;
00171     // Front/Backside flag
00172     bool mFrontFlag;
00173     // Store our pixmap array
00174     QList<QPixmap> mFrames;
00175     // Store our pixmap offset values
00176     QList<QPointF> mHotspots;
00177     // The current frame number
00178     int mCurrentFrame;
00179 
00180     // Sprite advance period [ms]
00181     int mAdvancePeriod;
00182     // Card width
00183     double mWidth;
00184     // Suite of card
00185     Suite mSuite;
00186     // Type of card
00187     CardType mCardType;
00188 
00189     // The position of the sprite [rel 0..1, rel 0..1]
00190     QPointF mStart;
00191 
00192 };
00193 
00194 #endif

Generated on Tue May 1 09:34:40 2007 for LSkat by  doxygen 1.4.6