File indexing completed on 2024-09-08 03:44:34
0001 /* 0002 This file is part of the KDE games kwin4 program 0003 SPDX-FileCopyrightText: 2006 Martin Heni <kde@heni-online.de> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef INTRO_SPRITE_H 0009 #define INTRO_SPRITE_H 0010 0011 // own 0012 #include "pixmapsprite.h" 0013 #include "thememanager.h" 0014 // Qt 0015 #include <QElapsedTimer> 0016 #include <QGraphicsPixmapItem> 0017 #include <QList> 0018 #include <QPointF> 0019 0020 class AnimationCommand; 0021 0022 /** 0023 * The sprite to display the introduction pieces and their animation. 0024 */ 0025 class IntroSprite : public PixmapSprite 0026 { 0027 public: 0028 /** 0029 * Constructor for the sprite. 0030 * @param id The theme id 0031 * @param theme The theme manager 0032 * @param no The sprite number [0..41] 0033 * @param scene The scene 0034 */ 0035 IntroSprite(const QString &id, ThemeManager *theme, int no, QGraphicsScene *scene); 0036 0037 /** 0038 * Destructor 0039 */ 0040 ~IntroSprite() override; 0041 0042 /** 0043 * Clear the animation script. 0044 * @param restartTime Reset the timer too (default) 0045 */ 0046 void clearAnimation(bool restartTime = true); 0047 0048 /** 0049 * Create a set position command. The sprite is directly set to the given 0050 * position. 0051 * @param start The position [rel coord.] 0052 * @return The command. 0053 */ 0054 AnimationCommand *addPosition(QPointF start); 0055 0056 /** 0057 * Create a relative pause command. The sprite does nothing for the given 0058 * amount of [ms]. 0059 * @param duration The pause duration [ms] 0060 * @return The command. 0061 */ 0062 AnimationCommand *addPause(int duration); 0063 0064 /** 0065 * Create an absolute wait command. The sprite does nothing until the given 0066 * animation time. If the time is in the past nothing is done. Used to 0067 * synchronize several sprites. 0068 * @param duration The time until when to pause [ms] 0069 * @return The command. 0070 */ 0071 AnimationCommand *addWait(int duration); 0072 0073 /** 0074 * Create a command to show the sprite. 0075 * @return The command. 0076 */ 0077 AnimationCommand *addShow(); 0078 0079 /** 0080 * Create an command to hide the sprite. 0081 * @return The command. 0082 */ 0083 AnimationCommand *addHide(); 0084 0085 /** 0086 * Create a linear movement from start to end with the given duration. 0087 * @param start The start point [rel. coord] 0088 * @param end The end point [rel. coord] 0089 * @param duration The duration of the move [ms] 0090 * @return The command. 0091 */ 0092 AnimationCommand *addLinear(QPointF start, QPointF end, int duration); 0093 0094 /** 0095 * Create a linear movement from the current position to end with the given duration. 0096 * @param end The end point [rel. coord] 0097 * @param duration The duration of the move [ms] 0098 * @return The command. 0099 */ 0100 AnimationCommand *addRelativeLinear(QPointF end, int duration); 0101 0102 /** 0103 * Create a command to move in a full circle around the given center position. 0104 * The circle will have the given radius and take the given amount of time to 0105 * perform. 0106 * @param start The center of the circle [rel. coord] 0107 * @param radius The circle radius [rel. coord] 0108 * @param duration The duration of the move [ms] 0109 * @return The command. 0110 */ 0111 AnimationCommand *addCircle(QPointF start, double radius, int duration); 0112 0113 /** 0114 * Create a linear manhatte movement (edge following) from the current position to end 0115 * with the given duration. 0116 * @param end The end point [rel. coord] 0117 * @param velocity The velocity of the move times 1000 [rel] 0118 * @return The command. 0119 */ 0120 AnimationCommand *addRelativeManhatten(QPointF end, double velocity); 0121 0122 /** 0123 * Retrieve the time the whole animation script takes. 0124 * @return The animation duration [ms] 0125 */ 0126 int animationDuration(); 0127 0128 /** 0129 * Standard QGI advance function. 0130 * @param phase The advance phase 0131 */ 0132 void advance(int phase) override; 0133 0134 /** 0135 * Retrieve the type of QGI. This item is UserType+1 0136 * @return The type of item. 0137 */ 0138 int type() const override 0139 { 0140 return QGraphicsItem::UserType + 1; 0141 } 0142 0143 /** 0144 * Retrieve the sprite numbers (which introsprite e.g. 0-42) 0145 * @return The sprite numbers. 0146 */ 0147 int number() 0148 { 0149 return mNo; 0150 } 0151 0152 /** 0153 * Main theme notification method. Is called for any theme changes. It must be 0154 * implemented so that the item redraws correctly when the theme changed. 0155 */ 0156 void changeTheme() override; 0157 0158 /** 0159 * Retrieve the duration of an animation. 0160 * @return The duration [ms] 0161 */ 0162 int duration(AnimationCommand *anim); 0163 0164 /** 0165 * Delay the animation of this sprite by the given amount in [ms]. 0166 * Used to compensate for long delays in SVG resizes etc. 0167 * @param duration The delay [ms] 0168 */ 0169 void delayAnimation(int duration); 0170 0171 protected: 0172 /** 0173 * Execute a given animation command for the given time relative to the 0174 * start of the command. 0175 * @param anim The command 0176 * @param elapsed The time since the begin of the command [ms] 0177 */ 0178 void executeCmd(AnimationCommand *anim, int elapsed); 0179 0180 /** 0181 * Retrieve the start position of the last added animation command. 0182 * @return The position [rel. coord]. 0183 */ 0184 QPointF previousStart(); 0185 0186 /** 0187 * Retrieve the end position of the last added animation command. 0188 * @return The position [rel. coord]. 0189 */ 0190 QPointF previousEnd(); 0191 0192 private: 0193 /// The current running time for the animation. 0194 QElapsedTimer mTime; 0195 0196 // List of animation commands 0197 QList<AnimationCommand *> mAnimList; 0198 0199 // Time since start of an animation command [ms] 0200 int mDeltaT; 0201 0202 // Global animation delay [ms] 0203 int mDelayT; 0204 0205 // Start animation 0206 bool mStartAnimation; 0207 0208 // Debug timer 0209 QElapsedTimer mDebugTime; 0210 }; 0211 0212 #endif