~unity-team/compiz/plugins-main-trunk.fix_wrong_window_move_expo

« back to all changes in this revision

Viewing changes to animation/src/wave.cpp

  • Committer: David Barth
  • Date: 2011-03-29 16:36:40 UTC
  • Revision ID: david.barth@canonical.com-20110329163640-fpen5qsoo0lbjode
initial import from compiz-plugins-main_0.9.4git20110322.orig.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Animation plugin for compiz/beryl
 
3
 *
 
4
 * animation.c
 
5
 *
 
6
 * Copyright : (C) 2006 Erkin Bahceci
 
7
 * E-mail    : erkinbah@gmail.com
 
8
 *
 
9
 * Based on Wobbly and Minimize plugins by
 
10
 *           : David Reveman
 
11
 * E-mail    : davidr@novell.com>
 
12
 *
 
13
 * Particle system added by : (C) 2006 Dennis Kasprzyk
 
14
 * E-mail                   : onestone@beryl-project.org
 
15
 *
 
16
 * Beam-Up added by : Florencio Guimaraes
 
17
 * E-mail           : florencio@nexcorp.com.br
 
18
 *
 
19
 * Hexagon tessellator added by : Mike Slegeir
 
20
 * E-mail                       : mikeslegeir@mail.utexas.edu>
 
21
 *
 
22
 * This program is free software; you can redistribute it and/or
 
23
 * modify it under the terms of the GNU General Public License
 
24
 * as published by the Free Software Foundation; either version 2
 
25
 * of the License, or (at your option) any later version.
 
26
 *
 
27
 * This program is distributed in the hope that it will be useful,
 
28
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
29
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
30
 * GNU General Public License for more details.
 
31
 *
 
32
 * You should have received a copy of the GNU General Public License
 
33
 * along with this program; if not, write to the Free Software
 
34
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
35
 */
 
36
 
 
37
#include "private.h"
 
38
 
 
39
const float WaveAnim::kMinDuration = 400;
 
40
 
 
41
// =====================  Effect: Wave  =========================
 
42
 
 
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)
 
59
    {
 
60
        mTotalTime = kMinDuration;
 
61
        mRemainingTime = mTotalTime;
 
62
    }
 
63
}
 
64
 
 
65
void
 
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
    int wx = winRect.x ();
 
90
    int wy = winRect.y ();
 
91
 
 
92
    int oy = outRect.y ();
 
93
    int owidth = outRect.width ();
 
94
    int oheight = outRect.height ();
 
95
 
 
96
    float waveHalfWidth = (oheight * mModel->scale ().y () *
 
97
                           optValF (AnimationOptions::WaveWidth) / 2);
 
98
 
 
99
    float waveAmp = (pow ((float)oheight / ::screen->height (), 0.4) *
 
100
                     0.04 * optValF (AnimationOptions::WaveAmpMult));
 
101
 
 
102
    float wavePosition =
 
103
        oy - waveHalfWidth +
 
104
        forwardProgress * (oheight * mModel->scale ().y () + 2 * waveHalfWidth);
 
105
 
 
106
    GridModel::GridObject *object = mModel->objects ();
 
107
    unsigned int n = mModel->numObjects ();
 
108
    for (unsigned int i = 0; i < n; i++, object++)
 
109
    {
 
110
        Point3d &objPos = object->position ();
 
111
 
 
112
        if (i % 2 == 0) // object is at the left side
 
113
        {
 
114
            float origy = wy + mModel->scale ().y () *
 
115
                (oheight * object->gridPosition ().y () -
 
116
                 outExtents.top);
 
117
            objPos.setY (origy);
 
118
 
 
119
            float distFromWaveCenter =
 
120
                fabs (objPos.y () - wavePosition);
 
121
 
 
122
            if (distFromWaveCenter < waveHalfWidth)
 
123
                objPos.
 
124
                    setZ (waveAmp * (cos (distFromWaveCenter *
 
125
                                          M_PI / waveHalfWidth) + 1) / 2);
 
126
            else
 
127
                objPos.setZ (0);
 
128
        }
 
129
        else // object is at the right side
 
130
        {
 
131
            // Set y/z position to the y/z position of the object at the left
 
132
            // on the same row (previous object)
 
133
            Point3d &leftObjPos = (object - 1)->position ();
 
134
            objPos.setY (leftObjPos.y ());
 
135
            objPos.setZ (leftObjPos.z ());
 
136
        }
 
137
 
 
138
        float origx = wx + mModel->scale ().x () *
 
139
            (owidth * object->gridPosition ().x () -
 
140
             outExtents.left);
 
141
        objPos.setX (origx);
 
142
    }
 
143
}
 
144