~vanvugt/compiz-plugins-main/fix-1084386

« back to all changes in this revision

Viewing changes to animation/src/horizontalfold.cpp

  • Committer: Sam Spilsbury
  • Date: 2011-08-12 06:36:10 UTC
  • Revision ID: sam.spilsbury@canonical.com-20110812063610-8mcxo2xohctyp2ak
Sync - Remove Plugins

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: Horizontal Folds  =========================
40
 
 
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)
71
 
{
72
 
    return -(sinForProg *
73
 
             foldMaxAmp *
74
 
             mModel->scale ().x () *
75
 
             2 * (0.5 - relDistToFoldCenter));
76
 
}
77
 
 
78
 
void
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 ());
95
 
 
96
 
    int wx = winRect.x ();
97
 
    int wy = winRect.y ();
98
 
 
99
 
    int oy = outRect.y ();
100
 
    int owidth = outRect.width ();
101
 
    int oheight = outRect.height ();
102
 
 
103
 
    float winHeight = 0;
104
 
    if (mCurWindowEvent == WindowEventShade ||
105
 
        mCurWindowEvent == WindowEventUnshade)
106
 
    {
107
 
        winHeight = winRect.height ();
108
 
    }
109
 
    else
110
 
    {
111
 
        winHeight = inRect.height ();
112
 
    }
113
 
    int nHalfFolds =
114
 
        2.0 * optValI (AnimationOptions::HorizontalFoldsNumFolds);
115
 
    float foldMaxAmp =
116
 
        0.3 * pow ((winHeight / nHalfFolds) / ::screen->height (), 0.3) *
117
 
        optValF (AnimationOptions::HorizontalFoldsAmpMult);
118
 
 
119
 
    float forwardProgress = getActualProgress ();
120
 
 
121
 
    float sinForProg = sin (forwardProgress * M_PI / 2);
122
 
 
123
 
    GridModel::GridObject *object = mModel->objects ();
124
 
    unsigned int n = mModel->numObjects ();
125
 
    for (unsigned int i = 0; i < n; i++, object++)
126
 
    {
127
 
        Point3d &objPos = object->position ();
128
 
 
129
 
        if (i % 2 == 0) // object is at the left side
130
 
        {
131
 
            float objGridY = object->gridPosition ().y ();
132
 
 
133
 
            int rowNo = (int)i / mGridWidth;
134
 
            float origy = (wy +
135
 
                           (oheight * objGridY -
136
 
                            outExtents.top) * mModel->scale ().y ());
137
 
            if (mCurWindowEvent == WindowEventShade ||
138
 
                mCurWindowEvent == WindowEventUnshade)
139
 
            {
140
 
                // Execute shade mode
141
 
 
142
 
                if (objGridY == 0)
143
 
                {
144
 
                    objPos.setY (oy);
145
 
                    objPos.setZ (0);
146
 
                }
147
 
                else if (objGridY == 1)
148
 
                {
149
 
                    objPos.setY (
150
 
                        (1 - forwardProgress) * origy +
151
 
                        forwardProgress *
152
 
                        (oy + mDecorTopHeight + mDecorBottomHeight));
153
 
                    objPos.setZ (0);
154
 
                }
155
 
                else
156
 
                {
157
 
                    float relDistToFoldCenter = (rowNo % 2 == 1 ? 0.5 : 0);
158
 
 
159
 
                    objPos.setY (
160
 
                        (1 - forwardProgress) * origy +
161
 
                        forwardProgress * (oy + mDecorTopHeight));
162
 
                    objPos.setZ (
163
 
                        getObjectZ (mModel, forwardProgress, sinForProg,
164
 
                                    relDistToFoldCenter, foldMaxAmp));
165
 
                }
166
 
            }
167
 
            else
168
 
            {
169
 
                // Execute normal mode
170
 
 
171
 
                float relDistToFoldCenter = (rowNo % 2 == 0 ? 0.5 : 0);
172
 
 
173
 
                objPos.setY (
174
 
                    (1 - forwardProgress) * origy +
175
 
                    forwardProgress * (inRect.y () + inRect.height () / 2.0));
176
 
                objPos.setZ (
177
 
                        getObjectZ (mModel, forwardProgress, sinForProg,
178
 
                                    relDistToFoldCenter, foldMaxAmp));
179
 
            }
180
 
        }
181
 
        else // object is at the right side
182
 
        {
183
 
            // Set y/z position to the y/z position of the object at the left
184
 
            // on the same row (previous object)
185
 
            Point3d &leftObjPos = (object - 1)->position ();
186
 
            objPos.setY (leftObjPos.y ());
187
 
            objPos.setZ (leftObjPos.z ());
188
 
        }
189
 
 
190
 
        float origx = (wx +
191
 
                       (owidth * object->gridPosition ().x () -
192
 
                        outExtents.left) * mModel->scale ().x ());
193
 
        objPos.setX (origx);
194
 
    }
195
 
}
196
 
 
197
 
bool
198
 
HorizontalFoldsAnim::zoomToIcon ()
199
 
{
200
 
    return ((mCurWindowEvent == WindowEventMinimize ||
201
 
             mCurWindowEvent == WindowEventUnminimize) &&
202
 
            optValB (AnimationOptions::HorizontalFoldsZoomToTaskbar));
203
 
}
204