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

« back to all changes in this revision

Viewing changes to src/glide.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
38
 
39
39
// =====================  Effect: Glide  =========================
40
40
 
41
 
static void
42
 
fxGlideGetParams (CompWindow *w,
43
 
                  float *finalDistFac,
44
 
                  float *finalRotAng,
45
 
                  float *thickness)
46
 
{
47
 
    ANIM_WINDOW(w);
48
 
 
49
 
    if (aw->com.curAnimEffect == AnimEffectGlide1)
50
 
    {
51
 
        *finalDistFac = animGetF (w, ANIM_SCREEN_OPTION_GLIDE1_AWAY_POS);
52
 
        *finalRotAng = animGetF (w, ANIM_SCREEN_OPTION_GLIDE1_AWAY_ANGLE);
53
 
    }
54
 
    else
55
 
    {
56
 
        *finalDistFac = animGetF (w, ANIM_SCREEN_OPTION_GLIDE2_AWAY_POS);
57
 
        *finalRotAng = animGetF (w, ANIM_SCREEN_OPTION_GLIDE2_AWAY_ANGLE);
58
 
    }
59
 
}
60
 
 
61
 
float
62
 
fxGlideAnimProgress (CompWindow *w)
63
 
{
64
 
    float forwardProgress = defaultAnimProgress (w);
65
 
 
66
 
    return decelerateProgress(forwardProgress);
67
 
}
68
 
 
69
 
static void
70
 
applyGlideTransform (CompWindow *w)
71
 
{
72
 
    ANIM_WINDOW(w);
73
 
 
74
 
    CompTransform *transform = &aw->com.transform;
 
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 ();
75
103
 
76
104
    float finalDistFac;
77
105
    float finalRotAng;
78
106
    float thickness;
79
107
 
80
 
    fxGlideGetParams (w, &finalDistFac, &finalRotAng, &thickness);
 
108
    getParams (&finalDistFac, &finalRotAng, &thickness);
81
109
 
82
110
    float forwardProgress;
83
 
    if (fxGlideZoomToIcon (w))
84
 
    {
85
 
        float dummy;
86
 
        fxZoomAnimProgress (w, &forwardProgress, &dummy, TRUE);
87
 
    }
 
111
    if (zoomToIcon ())
 
112
        getZoomProgress (&forwardProgress, 0, true);
88
113
    else
89
 
        forwardProgress = fxGlideAnimProgress (w);
 
114
        forwardProgress = getProgress ();
90
115
 
91
116
    float finalz = finalDistFac * 0.8 * DEFAULT_Z_CAMERA *
92
 
        w->screen->width;
93
 
 
94
 
    Vector3d rotAxis = {1, 0, 0};
95
 
    Point3d rotAxisOffset =
96
 
        {WIN_X(w) + WIN_W(w) / 2.0f,
97
 
         WIN_Y(w) + WIN_H(w) / 2.0f,
98
 
         0};
99
 
    Point3d translation = {0, 0, finalz * forwardProgress};
 
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);
100
128
 
101
129
    float rotAngle = finalRotAng * forwardProgress;
102
 
    aw->glideModRotAngle = fmodf(rotAngle + 720, 360.0f);
 
130
    glideModRotAngle = fmodf (rotAngle + 720, 360.0f);
103
131
 
104
132
    // put back to window position
105
 
    matrixTranslate (transform, rotAxisOffset.x, rotAxisOffset.y, 0);
 
133
    mTransform.translate (rotAxisOffset);
106
134
 
107
 
    perspectiveDistortAndResetZ (w->screen, transform);
 
135
    perspectiveDistortAndResetZ (mTransform);
108
136
 
109
137
    // animation movement
110
 
    matrixTranslate (transform, translation.x, translation.y, translation.z);
 
138
    mTransform.translate (translation);
111
139
 
112
140
    // animation rotation
113
 
    matrixRotate (transform, rotAngle, rotAxis.x, rotAxis.y, rotAxis.z);
 
141
    mTransform.rotate (rotAngle, rotAxis);
114
142
 
115
143
    // intentional scaling of z by 0 to prevent weird opacity results and
116
144
    // flashing that happen when z coords are between 0 and 1 (bug in compiz?)
117
 
    matrixScale (transform, 1.0f, 1.0f, 0.0f);
 
145
    mTransform.scale (1.0f, 1.0f, 0.0f);
118
146
 
119
147
    // place window rotation axis at origin
120
 
    matrixTranslate (transform, -rotAxisOffset.x, -rotAxisOffset.y, 0);
121
 
}
122
 
 
123
 
void
124
 
fxGlideAnimStep (CompWindow *w, float time)
125
 
{
126
 
    defaultAnimStep (w, time);
127
 
 
128
 
    applyGlideTransform (w);
129
 
}
130
 
 
131
 
void
132
 
fxGlideUpdateWindowAttrib (CompWindow * w,
133
 
                           WindowPaintAttrib * wAttrib)
134
 
{
135
 
    ANIM_WINDOW(w);
136
 
 
137
 
    if (fxGlideZoomToIcon (w))
138
 
    {
139
 
        fxZoomUpdateWindowAttrib (w, wAttrib);
140
 
        return;
141
 
    }
142
 
 
143
 
    float forwardProgress = fxGlideAnimProgress (w);
144
 
 
145
 
    wAttrib->opacity = aw->com.storedOpacity * (1 - forwardProgress);
146
 
}
147
 
 
148
 
void
149
 
fxGlideUpdateWindowTransform (CompWindow *w,
150
 
                              CompTransform *wTransform)
151
 
{
152
 
    ANIM_WINDOW(w);
153
 
 
154
 
    applyTransform (wTransform, &aw->com.transform);
155
 
}
156
 
 
157
 
Bool
158
 
fxGlideInit (CompWindow * w)
159
 
{
160
 
    ANIM_WINDOW(w);
161
 
 
162
 
    if (fxGlideZoomToIcon (w))
163
 
    {
164
 
        aw->com.animTotalTime /= ZOOM_PERCEIVED_T;
165
 
        aw->com.animRemainingTime = aw->com.animTotalTime;
166
 
    }
167
 
 
168
 
    return defaultAnimInit (w);
169
 
}
170
 
 
171
 
void fxGlidePrePaintWindow (CompWindow *w)
172
 
{
173
 
    ANIM_WINDOW(w);
174
 
 
175
 
    if (90 < aw->glideModRotAngle &&
176
 
        aw->glideModRotAngle < 270)
177
 
        glCullFace(GL_FRONT);
178
 
}
179
 
 
180
 
void fxGlidePostPaintWindow (CompWindow * w)
181
 
{
182
 
    ANIM_WINDOW(w);
183
 
 
184
 
    if (90 < aw->glideModRotAngle &&
185
 
        aw->glideModRotAngle < 270)
186
 
        glCullFace(GL_BACK);
187
 
}
188
 
 
189
 
Bool
190
 
fxGlideZoomToIcon (CompWindow *w)
191
 
{
192
 
    ANIM_WINDOW(w);
193
 
    return
194
 
        ((aw->com.curWindowEvent == WindowEventMinimize ||
195
 
          aw->com.curWindowEvent == WindowEventUnminimize) &&
196
 
         ((aw->com.curAnimEffect == AnimEffectGlide1 &&
197
 
           animGetB (w, ANIM_SCREEN_OPTION_GLIDE1_Z2TOM)) ||
198
 
          (aw->com.curAnimEffect == AnimEffectGlide2 &&
199
 
           animGetB (w, ANIM_SCREEN_OPTION_GLIDE2_Z2TOM))));
 
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));
200
191
}
201
192