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

« back to all changes in this revision

Viewing changes to src/horizontalfold.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: Horizontal Folds  =========================
40
40
 
41
 
static inline float
42
 
getObjectZ (Model *model,
43
 
            float forwardProgress,
44
 
            float sinForProg,
45
 
            float relDistToFoldCenter,
46
 
            float foldMaxAmp)
 
41
HorizontalFoldsAnim::HorizontalFoldsAnim (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
    FoldAnim::FoldAnim (w, curWindowEvent, duration, info, icon)
 
49
{
 
50
}
 
51
 
 
52
void
 
53
HorizontalFoldsAnim::initGrid ()
 
54
{
 
55
    mGridWidth = 2;
 
56
    if (mCurWindowEvent == WindowEventShade ||
 
57
        mCurWindowEvent == WindowEventUnshade)
 
58
        mGridHeight = 3 + 2 *
 
59
            optValI (AnimationOptions::HorizontalFoldsNumFolds);
 
60
    else
 
61
        mGridHeight = 1 + 2 *
 
62
            optValI (AnimationOptions::HorizontalFoldsNumFolds);
 
63
}
 
64
 
 
65
float
 
66
HorizontalFoldsAnim::getObjectZ (GridAnim::GridModel *mModel,
 
67
                                 float forwardProgress,
 
68
                                 float sinForProg,
 
69
                                 float relDistToFoldCenter,
 
70
                                 float foldMaxAmp)
47
71
{
48
72
    return -(sinForProg *
49
73
             foldMaxAmp *
50
 
             model->scale.x *
 
74
             mModel->scale ().x () *
51
75
             2 * (0.5 - relDistToFoldCenter));
52
76
}
53
77
 
54
78
void
55
 
fxHorizontalFoldsInitGrid(CompWindow *w,
56
 
                          int *gridWidth, int *gridHeight)
57
 
{
58
 
    ANIM_WINDOW(w);
59
 
 
60
 
    *gridWidth = 2;
61
 
    if (aw->com.curWindowEvent == WindowEventShade ||
62
 
        aw->com.curWindowEvent == WindowEventUnshade)
63
 
        *gridHeight = 3 + 2 *   
64
 
            animGetI (w, ANIM_SCREEN_OPTION_HORIZONTAL_FOLDS_NUM_FOLDS);
65
 
    else
66
 
        *gridHeight = 1 + 2 *
67
 
            animGetI (w, ANIM_SCREEN_OPTION_HORIZONTAL_FOLDS_NUM_FOLDS);
68
 
}
69
 
 
70
 
static void inline
71
 
fxHorizontalFoldsModelStepObject(CompWindow * w,
72
 
                                 Model * model,
73
 
                                 Object * object,
74
 
                                 float forwardProgress,
75
 
                                 float sinForProg,
76
 
                                 float foldMaxAmp, int rowNo)
77
 
{
78
 
    ANIM_WINDOW(w);
79
 
 
80
 
    float origx = w->attrib.x + (WIN_W(w) * object->gridPosition.x -
81
 
                                 w->output.left) * model->scale.x;
82
 
    float origy = w->attrib.y + (WIN_H(w) * object->gridPosition.y -
83
 
                                 w->output.top) * model->scale.y;
84
 
 
85
 
    object->position.x = origx;
86
 
 
87
 
    if (aw->com.curWindowEvent == WindowEventShade ||
88
 
        aw->com.curWindowEvent == WindowEventUnshade)
89
 
    {
90
 
        // Execute shade mode
91
 
 
92
 
        float relDistToFoldCenter = (rowNo % 2 == 1 ? 0.5 : 0);
93
 
 
94
 
        if (object->gridPosition.y == 0)
95
 
        {
96
 
            object->position.y = WIN_Y(w);
97
 
            object->position.z = 0;
98
 
        }
99
 
        else if (object->gridPosition.y == 1)
100
 
        {
101
 
            object->position.y =
102
 
                (1 - forwardProgress) * origy +
103
 
                forwardProgress *
104
 
                (WIN_Y(w) + model->topHeight + model->bottomHeight);
105
 
            object->position.z = 0;
106
 
        }
107
 
        else
108
 
        {
109
 
            object->position.y =
110
 
                (1 - forwardProgress) * origy +
111
 
                forwardProgress * (WIN_Y(w) + model->topHeight);
112
 
            object->position.z =
113
 
                getObjectZ (model, forwardProgress, sinForProg,
114
 
                            relDistToFoldCenter, foldMaxAmp);
115
 
        }
116
 
    }
117
 
    else
118
 
    {
119
 
        // Execute normal mode
120
 
 
121
 
        float relDistToFoldCenter;
122
 
 
123
 
        relDistToFoldCenter = (rowNo % 2 == 0 ? 0.5 : 0);
124
 
 
125
 
        object->position.y =
126
 
            (1 - forwardProgress) * origy +
127
 
            forwardProgress * (BORDER_Y(w) + BORDER_H(w) / 2.0);
128
 
        object->position.z =
129
 
                getObjectZ (model, forwardProgress, sinForProg,
130
 
                            relDistToFoldCenter, foldMaxAmp);
131
 
    }
132
 
}
133
 
 
134
 
void
135
 
fxHorizontalFoldsModelStep (CompWindow *w, float time)
136
 
{
137
 
    defaultAnimStep (w, time);
138
 
 
139
 
    ANIM_WINDOW(w);
140
 
 
141
 
    Model *model = aw->com.model;
142
 
 
 
79
HorizontalFoldsAnim::step ()
 
80
{
 
81
    GridZoomAnim::step ();
 
82
 
 
83
    CompRect winRect (mAWindow->savedRectsValid () ?
 
84
                      mAWindow->saveWinRect () :
 
85
                      mWindow->geometry ());
 
86
    CompRect inRect (mAWindow->savedRectsValid () ?
 
87
                     mAWindow->savedInRect () :
 
88
                     mWindow->inputRect ());
 
89
    CompRect outRect (mAWindow->savedRectsValid () ?
 
90
                      mAWindow->savedOutRect () :
 
91
                      mWindow->outputRect ());
 
92
    CompWindowExtents outExtents (mAWindow->savedRectsValid () ?
 
93
                                  mAWindow->savedOutExtents () :
 
94
                                  mWindow->output ());
143
95
    float winHeight = 0;
144
 
    if (aw->com.curWindowEvent == WindowEventShade ||
145
 
        aw->com.curWindowEvent == WindowEventUnshade)
 
96
    if (mCurWindowEvent == WindowEventShade ||
 
97
        mCurWindowEvent == WindowEventUnshade)
146
98
    {
147
 
        winHeight = (w)->height;
 
99
        winHeight = winRect.height ();
148
100
    }
149
101
    else
150
102
    {
151
 
        winHeight = BORDER_H (w);
 
103
        winHeight = inRect.height ();
152
104
    }
153
105
    int nHalfFolds =
154
 
        2.0 * animGetI (w, ANIM_SCREEN_OPTION_HORIZONTAL_FOLDS_NUM_FOLDS);
 
106
        2.0 * optValI (AnimationOptions::HorizontalFoldsNumFolds);
155
107
    float foldMaxAmp =
156
 
        0.3 * pow ((winHeight / nHalfFolds) / w->screen->height, 0.3) *
157
 
        animGetF (w, ANIM_SCREEN_OPTION_HORIZONTAL_FOLDS_AMP_MULT);
 
108
        0.3 * pow ((winHeight / nHalfFolds) / ::screen->height (), 0.3) *
 
109
        optValF (AnimationOptions::HorizontalFoldsAmpMult);
158
110
 
159
 
    float forwardProgress = getProgressAndCenter (w, NULL);
 
111
    float forwardProgress = getActualProgress ();
160
112
 
161
113
    float sinForProg = sin (forwardProgress * M_PI / 2);
162
114
 
163
 
    Object *object = model->objects;
164
 
    int i;
165
 
    for (i = 0; i < model->numObjects; i++, object++)
166
 
        fxHorizontalFoldsModelStepObject(w, 
167
 
                                         model,
168
 
                                         object,
169
 
                                         forwardProgress,
170
 
                                         sinForProg,
171
 
                                         foldMaxAmp,
172
 
                                         i / model->gridWidth);
 
115
    GridModel::GridObject *object = mModel->objects ();
 
116
    for (int i = 0; i < mModel->numObjects (); i++, object++)
 
117
    {
 
118
        int rowNo = i / mGridWidth;
 
119
        float origx = (winRect.x () +
 
120
                       (outRect.width () * object->gridPosition ().x () -
 
121
                        outExtents.left) * mModel->scale ().x ());
 
122
        float origy = (winRect.y () +
 
123
                       (outRect.height () * object->gridPosition ().y () -
 
124
                        outExtents.top) * mModel->scale ().y ());
 
125
 
 
126
        object->position ().setX (origx);
 
127
 
 
128
        if (mCurWindowEvent == WindowEventShade ||
 
129
            mCurWindowEvent == WindowEventUnshade)
 
130
        {
 
131
            // Execute shade mode
 
132
 
 
133
            float relDistToFoldCenter = (rowNo % 2 == 1 ? 0.5 : 0);
 
134
 
 
135
            if (object->gridPosition ().y () == 0)
 
136
            {
 
137
                object->position ().setY (outRect.y ());
 
138
                object->position ().setZ (0);
 
139
            }
 
140
            else if (object->gridPosition ().y () == 1)
 
141
            {
 
142
                object->position ().setY (
 
143
                    (1 - forwardProgress) * origy +
 
144
                    forwardProgress *
 
145
                    (outRect.y () + mDecorTopHeight + mDecorBottomHeight));
 
146
                object->position ().setZ (0);
 
147
            }
 
148
            else
 
149
            {
 
150
                object->position ().setY (
 
151
                    (1 - forwardProgress) * origy +
 
152
                    forwardProgress * (outRect.y () + mDecorTopHeight));
 
153
                object->position ().setZ (
 
154
                    getObjectZ (mModel, forwardProgress, sinForProg,
 
155
                                relDistToFoldCenter, foldMaxAmp));
 
156
            }
 
157
        }
 
158
        else
 
159
        {
 
160
            // Execute normal mode
 
161
 
 
162
            float relDistToFoldCenter = (rowNo % 2 == 0 ? 0.5 : 0);
 
163
 
 
164
            object->position ().setY (
 
165
                (1 - forwardProgress) * origy +
 
166
                forwardProgress * (inRect.y () + inRect.height () / 2.0));
 
167
            object->position ().setZ (
 
168
                    getObjectZ (mModel, forwardProgress, sinForProg,
 
169
                                relDistToFoldCenter, foldMaxAmp));
 
170
        }
 
171
    }
173
172
}
174
173
 
175
 
Bool
176
 
fxHorizontalFoldsZoomToIcon (CompWindow *w)
 
174
bool
 
175
HorizontalFoldsAnim::zoomToIcon ()
177
176
{
178
 
    ANIM_WINDOW(w);
179
 
    return ((aw->com.curWindowEvent == WindowEventMinimize ||
180
 
             aw->com.curWindowEvent == WindowEventUnminimize) &&
181
 
            animGetB (w, ANIM_SCREEN_OPTION_HORIZONTAL_FOLDS_Z2TOM));
 
177
    return ((mCurWindowEvent == WindowEventMinimize ||
 
178
             mCurWindowEvent == WindowEventUnminimize) &&
 
179
            optValB (AnimationOptions::HorizontalFoldsZoomToTaskbar));
182
180
}
183
181