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

« back to all changes in this revision

Viewing changes to animation/src/glide.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
// =====================  Effect: Glide  =========================
 
40
 
 
41
GlideAnim::GlideAnim (CompWindow *w,
 
42
                      WindowEvent curWindowEvent,
 
43
                      float duration,
 
44
                      const AnimEffect info,
 
45
                      const CompRect &icon) :
 
46
    Animation::Animation (w, curWindowEvent, duration, info, icon),
 
47
    TransformAnim::TransformAnim (w, curWindowEvent, duration, info, icon),
 
48
    ZoomAnim::ZoomAnim (w, curWindowEvent, duration, info, icon)
 
49
{
 
50
}
 
51
 
 
52
Glide2Anim::Glide2Anim (CompWindow *w,
 
53
                        WindowEvent curWindowEvent,
 
54
                        float duration,
 
55
                        const AnimEffect info,
 
56
                        const CompRect &icon) :
 
57
    Animation::Animation (w, curWindowEvent, duration, info, icon),
 
58
    TransformAnim::TransformAnim (w, curWindowEvent, duration, info, icon),
 
59
    GlideAnim::GlideAnim (w, curWindowEvent, duration, info, icon)
 
60
{
 
61
}
 
62
 
 
63
void
 
64
GlideAnim::getParams (float *finalDistFac,
 
65
                      float *finalRotAng,
 
66
                      float *thickness)
 
67
{
 
68
    *finalDistFac = optValF (AnimationOptions::Glide1AwayPosition);
 
69
    *finalRotAng = optValF (AnimationOptions::Glide1AwayAngle);
 
70
}
 
71
 
 
72
void
 
73
Glide2Anim::getParams (float *finalDistFac,
 
74
                       float *finalRotAng,
 
75
                       float *thickness)
 
76
{
 
77
    *finalDistFac = optValF (AnimationOptions::Glide2AwayPosition);
 
78
    *finalRotAng = optValF (AnimationOptions::Glide2AwayAngle);
 
79
}
 
80
 
 
81
float
 
82
GlideAnim::getProgress ()
 
83
{
 
84
    float forwardProgress = progressLinear ();
 
85
 
 
86
    return progressDecelerate (forwardProgress);
 
87
}
 
88
 
 
89
float
 
90
GlideAnim::getFadeProgress ()
 
91
{
 
92
    if (zoomToIcon ())
 
93
        return ZoomAnim::getFadeProgress ();
 
94
 
 
95
    return getProgress ();
 
96
}
 
97
 
 
98
void
 
99
GlideAnim::applyTransform ()
 
100
{
 
101
    if (zoomToIcon ())
 
102
        ZoomAnim::applyTransform ();
 
103
 
 
104
    float finalDistFac;
 
105
    float finalRotAng;
 
106
    float thickness;
 
107
 
 
108
    getParams (&finalDistFac, &finalRotAng, &thickness);
 
109
 
 
110
    float forwardProgress;
 
111
    if (zoomToIcon ())
 
112
        getZoomProgress (&forwardProgress, 0, true);
 
113
    else
 
114
        forwardProgress = getProgress ();
 
115
 
 
116
    float finalz = finalDistFac * 0.8 * DEFAULT_Z_CAMERA *
 
117
        ::screen->width ();
 
118
 
 
119
    CompRect outRect (mAWindow->savedRectsValid () ?
 
120
                      mAWindow->savedOutRect () :
 
121
                      mWindow->outputRect ());
 
122
 
 
123
    GLVector rotAxis (1, 0, 0, 0);
 
124
    GLVector rotAxisOffset (outRect.x () + outRect.width () / 2.0f,
 
125
                            outRect.y () + outRect.height () / 2.0f,
 
126
                            0, 0);
 
127
    GLVector translation (0, 0, finalz * forwardProgress, 0);
 
128
 
 
129
    float rotAngle = finalRotAng * forwardProgress;
 
130
    glideModRotAngle = fmodf (rotAngle + 720, 360.0f);
 
131
 
 
132
    // put back to window position
 
133
    mTransform.translate (rotAxisOffset);
 
134
 
 
135
    perspectiveDistortAndResetZ (mTransform);
 
136
 
 
137
    // animation movement
 
138
    mTransform.translate (translation);
 
139
 
 
140
    // animation rotation
 
141
    mTransform.rotate (rotAngle, rotAxis);
 
142
 
 
143
    // intentional scaling of z by 0 to prevent weird opacity results and
 
144
    // flashing that happen when z coords are between 0 and 1 (bug in compiz?)
 
145
    mTransform.scale (1.0f, 1.0f, 0.0f);
 
146
 
 
147
    // place window rotation axis at origin
 
148
    mTransform.translate (-rotAxisOffset);
 
149
}
 
150
 
 
151
void
 
152
GlideAnim::adjustDuration ()
 
153
{
 
154
    if (zoomToIcon ())
 
155
    {
 
156
        mTotalTime *= kDurationFactor;
 
157
        mRemainingTime = mTotalTime;
 
158
    }
 
159
}
 
160
 
 
161
void
 
162
GlideAnim::prePaintWindow ()
 
163
{
 
164
    if (90 < glideModRotAngle &&
 
165
        glideModRotAngle < 270)
 
166
        glCullFace (GL_FRONT);
 
167
}
 
168
 
 
169
void
 
170
GlideAnim::postPaintWindow ()
 
171
{
 
172
    if (90 < glideModRotAngle &&
 
173
        glideModRotAngle < 270)
 
174
        glCullFace (GL_BACK);
 
175
}
 
176
 
 
177
bool
 
178
GlideAnim::zoomToIcon ()
 
179
{
 
180
    return ((mCurWindowEvent == WindowEventMinimize ||
 
181
             mCurWindowEvent == WindowEventUnminimize) &&
 
182
            optValB (AnimationOptions::Glide1ZoomToTaskbar));
 
183
}
 
184
 
 
185
bool
 
186
Glide2Anim::zoomToIcon ()
 
187
{
 
188
    return ((mCurWindowEvent == WindowEventMinimize ||
 
189
             mCurWindowEvent == WindowEventUnminimize) &&
 
190
            optValB (AnimationOptions::Glide2ZoomToTaskbar));
 
191
}
 
192