~vanvugt/compiz-animation-plugin/fix-915236

« back to all changes in this revision

Viewing changes to src/wave.cpp

  • Committer: Erkin Bahceci
  • Date: 2009-07-15 16:05:10 UTC
  • Revision ID: git-v1:6eeaa209932c6039edd4c362c352f242468a118a
Initial C++ port. Dodge and magic lamp changes.

- New dodge mode: all windows moving (made the default).
- Fixed dodge artifacts/weirdness showing up in certain situations.
- Magic Lamp renamed to Magic Lamp Wavy.
- Vacuum renamed to Magic Lamp, allowed for minimize (made the default).
- Separated restack stuff (dodge and focus-fade) from animation core.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
35
35
 */
36
36
 
37
 
#include "animation-internal.h"
 
37
#include "private.h"
 
38
 
 
39
const float WaveAnim::kMinDuration = 400;
38
40
 
39
41
// =====================  Effect: Wave  =========================
40
42
 
41
 
static void inline
42
 
fxWaveModelStepObject(CompWindow * w,
43
 
                      Model * model,
44
 
                      Object * object,
45
 
                      float forwardProgress,
46
 
                      float wavePosition,
47
 
                      float waveAmp,
48
 
                      float waveHalfWidth)
49
 
{
50
 
    float origx = w->attrib.x + (WIN_W(w) * object->gridPosition.x -
51
 
                                 w->output.left) * model->scale.x;
52
 
    float origy = w->attrib.y + (WIN_H(w) * object->gridPosition.y -
53
 
                                 w->output.top) * model->scale.y;
54
 
 
55
 
    object->position.x = origx;
56
 
    object->position.y = origy;
57
 
    object->position.z = 0;
58
 
 
59
 
    if (fabs(object->position.y - wavePosition) < waveHalfWidth)
 
43
WaveAnim::WaveAnim (CompWindow *w,
 
44
                    WindowEvent curWindowEvent,
 
45
                    float duration,
 
46
                    const AnimEffect info,
 
47
                    const CompRect &icon) :
 
48
    Animation::Animation (w, curWindowEvent, duration, info, icon),
 
49
    TransformAnim::TransformAnim (w, curWindowEvent, duration, info, icon),
 
50
    GridTransformAnim::GridTransformAnim (w, curWindowEvent, duration, info,
 
51
                                          icon)
 
52
{
 
53
}
 
54
 
 
55
void
 
56
WaveAnim::adjustDuration ()
 
57
{
 
58
    if (mTotalTime < kMinDuration)
60
59
    {
61
 
        object->position.z += waveAmp *
62
 
            (cos ((object->position.y - wavePosition) *
63
 
                  M_PI / waveHalfWidth) + 1) / 2;
 
60
        mTotalTime = kMinDuration;
 
61
        mRemainingTime = mTotalTime;
64
62
    }
65
63
}
66
64
 
67
65
void
68
 
fxWaveModelStep (CompWindow *w, float time)
69
 
{
70
 
    defaultAnimStep (w, time);
71
 
 
72
 
    ANIM_WINDOW(w);
73
 
 
74
 
    Model *model = aw->com.model;
75
 
 
76
 
    float forwardProgress = 1 - defaultAnimProgress (w);
77
 
 
78
 
    float waveHalfWidth = (WIN_H(w) * model->scale.y *
79
 
                           animGetF (w, ANIM_SCREEN_OPTION_WAVE_WIDTH) / 2);
80
 
 
81
 
    float waveAmp = (0.02 * pow ((float)WIN_H (w) / w->screen->height, 0.4) *
82
 
                     animGetF (w, ANIM_SCREEN_OPTION_WAVE_AMP_MULT));
 
66
WaveAnim::initGrid ()
 
67
{
 
68
    mGridWidth = 2;
 
69
    mGridHeight = optValI (AnimationOptions::MagicLampWavyGridRes); // TODO new option
 
70
}
 
71
 
 
72
void
 
73
WaveAnim::step ()
 
74
{
 
75
    float forwardProgress = 1 - progressLinear ();
 
76
    if (mCurWindowEvent == WindowEventClose)
 
77
        forwardProgress = 1 - forwardProgress;
 
78
 
 
79
    CompRect winRect (mAWindow->savedRectsValid () ?
 
80
                      mAWindow->saveWinRect () :
 
81
                      mWindow->geometry ());
 
82
    CompRect outRect (mAWindow->savedRectsValid () ?
 
83
                      mAWindow->savedOutRect () :
 
84
                      mWindow->outputRect ());
 
85
    CompWindowExtents outExtents (mAWindow->savedRectsValid () ?
 
86
                                  mAWindow->savedOutExtents () :
 
87
                                  mWindow->output ());
 
88
 
 
89
    float waveHalfWidth = (outRect.height () * mModel->scale ().y () *
 
90
                           optValF (AnimationOptions::WaveWidth) / 2);
 
91
 
 
92
    float waveAmp = (pow ((float)outRect.height () / ::screen->height (), 0.4) *
 
93
                     0.04 * optValF (AnimationOptions::WaveAmpMult));
83
94
 
84
95
    float wavePosition =
85
 
        WIN_Y(w) - waveHalfWidth +
86
 
        forwardProgress * (WIN_H(w) * model->scale.y + 2 * waveHalfWidth);
87
 
 
88
 
    Object *object = model->objects;
89
 
    int i;
90
 
    for (i = 0; i < model->numObjects; i++, object++)
91
 
        fxWaveModelStepObject(w,
92
 
                              model,
93
 
                              object,
94
 
                              forwardProgress,
95
 
                              wavePosition,
96
 
                              waveAmp,
97
 
                              waveHalfWidth);
 
96
        outRect.y () - waveHalfWidth +
 
97
        forwardProgress * (outRect.height () * mModel->scale ().y () +
 
98
                           2 * waveHalfWidth);
 
99
 
 
100
    GridModel::GridObject *object = mModel->objects ();
 
101
    for (int i = 0; i < mModel->numObjects (); i++, object++)
 
102
    {
 
103
        float origx = winRect.x () + mModel->scale ().x () *
 
104
            (outRect.width () * object->gridPosition ().x () -
 
105
             outExtents.left);
 
106
        float origy = winRect.y () + mModel->scale ().y () *
 
107
            (outRect.height () * object->gridPosition ().y () -
 
108
             outExtents.top);
 
109
 
 
110
        object->position ().setX (origx);
 
111
        object->position ().setY (origy);
 
112
        float distFromWaveCenter =
 
113
            fabs (object->position ().y () - wavePosition);
 
114
 
 
115
        if (distFromWaveCenter < waveHalfWidth)
 
116
            object->position ().
 
117
                setZ (waveAmp * (cos (distFromWaveCenter *
 
118
                                      M_PI / waveHalfWidth) + 1) / 2);
 
119
        else
 
120
            object->position ().setZ (0);
 
121
    }
98
122
}
99
123