diff options
author | Sam Spilsbury <smspillaz@gmail.com> | 2010-08-18 06:33:27 +0800 |
---|---|---|
committer | Sam Spilsbury <smspillaz@gmail.com> | 2010-08-18 06:33:27 +0800 |
commit | 26d7683f8e72210cdb55ced98440ab1ddb475fc9 (patch) | |
tree | c24a17e8a226ca3c2eb0d7e2b073c0486ea88130 | |
parent | 0e4f6f2c39b2dcc177bc8e391804248e27e7bd2a (diff) | |
download | simple-animations-26d7683f8e72210cdb55ced98440ab1ddb475fc9.tar.gz simple-animations-26d7683f8e72210cdb55ced98440ab1ddb475fc9.tar.bz2 |
Add pulse animation
-rw-r--r-- | animationsim.xml.in | 4 | ||||
-rw-r--r-- | src/animationsim.cpp | 6 | ||||
-rw-r--r-- | src/animationsim.h | 44 | ||||
-rw-r--r-- | src/pulse.cpp | 50 |
4 files changed, 102 insertions, 2 deletions
diff --git a/animationsim.xml.in b/animationsim.xml.in index d651315..3ab745d 100644 --- a/animationsim.xml.in +++ b/animationsim.xml.in @@ -210,6 +210,10 @@ <value>animationsim:Expand Piecewise</value> <_name>Expand Piecewise</_name> </restriction> + <restriction> + <value>animationsim:Pulse</value> + <_name>Pulse</_name> + </restriction> </extension> </plugin> diff --git a/src/animationsim.cpp b/src/animationsim.cpp index cdc6d64..d9c557b 100644 --- a/src/animationsim.cpp +++ b/src/animationsim.cpp @@ -50,6 +50,7 @@ AnimEffect AnimEffectExpand; AnimEffect AnimEffectExpandPW; AnimEffect AnimEffectBounce; AnimEffect AnimEffectSheet; +AnimEffect AnimEffectPulse; void AnimSimScreen::initAnimationList () @@ -86,6 +87,11 @@ AnimSimScreen::initAnimationList () true, true, true, false, false, &createAnimation<SheetAnim>); + animEffects[i++] = AnimEffectPulse = + new AnimEffectInfo ("animationsim:Pulse", + true, true, true, false, false, + &createAnimation<PulseAnim>); + animSimExtPluginInfo.effectOptions = &getOptions (); AnimScreen *as = AnimScreen::get (::screen); diff --git a/src/animationsim.h b/src/animationsim.h index b4f57cf..862aeb1 100644 --- a/src/animationsim.h +++ b/src/animationsim.h @@ -17,7 +17,7 @@ extern AnimEffect AnimEffectExpand; extern AnimEffect AnimEffectExpandPW; // TODO Update this for each added animation effect! (total: 10) -#define NUM_EFFECTS 6 +#define NUM_EFFECTS 7 // This must have the value of the first "effect setting" above // in AnimAddonScreenOptions @@ -305,7 +305,47 @@ class SheetAnim : public GridAnim, int sheetsWaveCount; std::vector <WaveParam> sheetsWaves; -}; +}; + +class PulseSingleAnim : public TransformAnim, + virtual public FadeAnim, + virtual public BaseSimAnim +{ + public: + + PulseSingleAnim (CompWindow *w, + WindowEvent curWindowEvent, + float duration, + const AnimEffect info, + const CompRect &icon) : + Animation::Animation (w, curWindowEvent, duration, info, icon), + FadeAnim::FadeAnim (w, curWindowEvent, duration, info, icon), + BaseSimAnim::BaseSimAnim (w, curWindowEvent, duration, info, icon), + TransformAnim::TransformAnim (w, curWindowEvent, duration, info, icon) {} + + void step () { TransformAnim::step (); } + void updateBB (CompOutput &output) { TransformAnim::updateBB (output); } + bool updateBBUsed () { return true; } + + float getProgress () { return progressLinear (); } + float getFadeProgress (); + + void applyTransform (); +}; + +class PulseAnim : public MultiAnim <PulseSingleAnim, 2> +{ + public: + + PulseAnim (CompWindow *w, + WindowEvent curWindowEvent, + float duration, + const AnimEffect info, + const CompRect &icon) : + MultiAnim <PulseSingleAnim, 2>::MultiAnim + (w, curWindowEvent, duration, info, icon) {} + +}; class AnimSimPluginVTable: public CompPlugin::VTableForScreenAndWindow <AnimSimScreen, AnimSimWindow> diff --git a/src/pulse.cpp b/src/pulse.cpp new file mode 100644 index 0000000..a3c9992 --- /dev/null +++ b/src/pulse.cpp @@ -0,0 +1,50 @@ +#include "animationsim.h" + +/* Keep the "principal" window at 100% opacity, only fade out + * the window that is "pulsing" away + */ + +float +PulseSingleAnim::getFadeProgress () +{ + int num = MultiAnim <PulseSingleAnim, 2>::getCurrAnimNumber (mAWindow); + + if (num == 1) + return 1 - getProgress (); + else + return 0.0f; +}; + +void +PulseSingleAnim::applyTransform () +{ + float scale = 1.0f + (1- getProgress ()); + + /* Add a bit of a "kick" for open, close, + * minimize, unminimize, etc anims */ + + switch (mCurWindowEvent) + { + case WindowEventOpen: + case WindowEventClose: + case WindowEventMinimize: + case WindowEventUnminimize: + scale -= 0.2f; + default: + break; + } + + if (MultiAnim <PulseSingleAnim, 2>::getCurrAnimNumber (mAWindow) == 0) + if (scale > 1.0f) + scale = 1.0f; + + GLMatrix *transform = &mTransform; + + transform->translate (WIN_X (mWindow) + WIN_W (mWindow) / 2.0f, + WIN_Y (mWindow) + WIN_H (mWindow) / 2.0f, 0.0f); + + transform->scale (scale, scale, 1.0f); + + transform->translate (-(WIN_X (mWindow) + WIN_W (mWindow) / 2.0f), + -(WIN_Y (mWindow) + WIN_H (mWindow) / 2.0f), 0.0f); +}
\ No newline at end of file |