~compiz-team/compiz-plugins-main/oneiric

« back to all changes in this revision

Viewing changes to animation/src/rollup.cpp

  • Committer: Sam Spilsbury
  • Date: 2011-09-29 11:34:08 UTC
  • Revision ID: sam.spilsbury@canonical.com-20110929113408-vnew477gska3l802
Sync in changes from upstream

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: Roll Up  =========================
 
40
 
 
41
const float RollUpAnim::kDurationFactor = 1.67;
 
42
 
 
43
RollUpAnim::RollUpAnim (CompWindow *w,
 
44
                        WindowEvent curWindowEvent,
 
45
                        float duration,
 
46
                        const AnimEffect info,
 
47
                        const CompRect &icon) :
 
48
    Animation::Animation (w, curWindowEvent, kDurationFactor * duration, info,
 
49
                          icon),
 
50
    GridAnim::GridAnim (w, curWindowEvent, kDurationFactor * duration, info,
 
51
                        icon)
 
52
{
 
53
}
 
54
 
 
55
void
 
56
RollUpAnim::initGrid ()
 
57
{
 
58
    mGridWidth = 2;
 
59
    if (mCurWindowEvent == WindowEventShade ||
 
60
        mCurWindowEvent == WindowEventUnshade)
 
61
        mGridHeight = 4;
 
62
    else
 
63
        mGridHeight = 2;
 
64
}
 
65
 
 
66
void
 
67
RollUpAnim::step ()
 
68
{
 
69
    float forwardProgress = progressEaseInEaseOut ();
 
70
    bool fixedInterior = optValB (AnimationOptions::RollupFixedInterior);
 
71
 
 
72
    CompRect outRect (mAWindow->savedRectsValid () ?
 
73
                      mAWindow->savedOutRect () :
 
74
                      mWindow->outputRect ());
 
75
 
 
76
    int ox = outRect.x ();
 
77
    int oy = outRect.y ();
 
78
    int owidth = outRect.width ();
 
79
    int oheight = outRect.height ();
 
80
 
 
81
    GridModel::GridObject *object = mModel->objects ();
 
82
    unsigned int n = mModel->numObjects ();
 
83
    for (unsigned int i = 0; i < n; i++, object++)
 
84
    {
 
85
        // Executing shade mode
 
86
 
 
87
        Point3d &objPos = object->position ();
 
88
 
 
89
        if (i % 2 == 0) // object is at the left side
 
90
        {
 
91
            float objGridY = object->gridPosition ().y ();
 
92
 
 
93
            if (objGridY == 0)
 
94
            {
 
95
                objPos.setY (oy);
 
96
            }
 
97
            else if (objGridY == 1)
 
98
            {
 
99
                objPos.setY (
 
100
                    (1 - forwardProgress) * (oy + oheight * objGridY) +
 
101
                    forwardProgress * (oy +
 
102
                                       mDecorTopHeight + mDecorBottomHeight));
 
103
            }
 
104
            else
 
105
            {
 
106
                // find position in window contents
 
107
                // (window contents correspond to 0.0-1.0 range)
 
108
                float relPosInWinContents =
 
109
                    (objGridY * oheight -
 
110
                     mDecorTopHeight) / mWindow->height ();
 
111
 
 
112
                if (relPosInWinContents > forwardProgress)
 
113
                {
 
114
                    objPos.setY (
 
115
                        (1 - forwardProgress) * (oy + oheight * objGridY) +
 
116
                        forwardProgress * (oy + mDecorTopHeight));
 
117
 
 
118
                    if (fixedInterior)
 
119
                        object->offsetTexCoordForQuadBefore ().
 
120
                            setY (-forwardProgress * mWindow->height ());
 
121
                }
 
122
                else
 
123
                {
 
124
                    objPos.setY (oy + mDecorTopHeight);
 
125
                    if (!fixedInterior)
 
126
                        object->offsetTexCoordForQuadAfter ().
 
127
                            setY ((forwardProgress - relPosInWinContents) *
 
128
                                  mWindow->height ());
 
129
                }
 
130
            }
 
131
        }
 
132
        else // object is at the right side
 
133
        {
 
134
            // Set y position to the y position of the object at the left
 
135
            // on the same row (previous object)
 
136
            objPos.setY ((object - 1)->position ().y ());
 
137
 
 
138
            // Also copy offset texture y coordinates
 
139
            object->offsetTexCoordForQuadBefore ().
 
140
                setY ((object - 1)->offsetTexCoordForQuadBefore ().y ());
 
141
            object->offsetTexCoordForQuadAfter ().
 
142
                setY ((object - 1)->offsetTexCoordForQuadAfter ().y ());
 
143
        }
 
144
 
 
145
        float origx = ox + owidth * object->gridPosition ().x ();
 
146
 
 
147
        objPos.setX (origx);
 
148
    }
 
149
}
 
150