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

« back to all changes in this revision

Viewing changes to animation/src/focusfade.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: Focus Fade  =========================
 
40
 
 
41
FocusFadeAnim::FocusFadeAnim (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
    RestackAnim::RestackAnim (w, curWindowEvent, duration, info, icon),
 
48
    FadeAnim::FadeAnim (w, curWindowEvent, duration, info, icon)
 
49
{
 
50
}
 
51
 
 
52
/// Compute the cross-fade opacity to make the effect look good with every
 
53
/// window opacity value.
 
54
GLushort
 
55
FocusFadeAnim::computeOpacity (GLushort opacityInt)
 
56
{
 
57
    float progress = 1 - progressLinear ();
 
58
    float opacity = opacityInt / (float)OPAQUE;
 
59
    float multiplier;
 
60
 
 
61
    bool newCopy = overNewCopy ();
 
62
 
 
63
    // flip opacity behavior for the other side of the cross-fade
 
64
    if (newCopy)
 
65
        progress = 1 - progress;
 
66
 
 
67
    if (mWindow->alpha () || (newCopy && opacity >= 0.91f))
 
68
        multiplier = progressDecelerate (progress);
 
69
    else if (opacity > 0.94f)
 
70
        multiplier = progressDecelerateCustom (progress, 0.55, 1.32);
 
71
    else if (opacity >= 0.91f && opacity < 0.94f)
 
72
        multiplier = progressDecelerateCustom (progress, 0.62, 0.92);
 
73
    else if (opacity >= 0.89f && opacity < 0.91f)
 
74
        multiplier = progressDecelerate (progress);
 
75
    else if (opacity >= 0.84f && opacity < 0.89f)
 
76
        multiplier = progressDecelerateCustom (progress, 0.64, 0.80);
 
77
    else if (opacity >= 0.79f && opacity < 0.84f)
 
78
        multiplier = progressDecelerateCustom (progress, 0.67, 0.77);
 
79
    else if (opacity >= 0.54f && opacity < 0.79f)
 
80
        multiplier = progressDecelerateCustom (progress, 0.61, 0.69);
 
81
    else
 
82
        multiplier = progress;
 
83
 
 
84
    multiplier = 1 - multiplier;
 
85
    float finalOpacity = opacity * multiplier;
 
86
    finalOpacity = MIN (finalOpacity, 1);
 
87
    finalOpacity = MAX (finalOpacity, 0);
 
88
 
 
89
    return (GLushort)(finalOpacity * OPAQUE);
 
90
}
 
91
 
 
92
void
 
93
FocusFadeAnim::updateAttrib (GLWindowPaintAttrib &attrib)
 
94
{
 
95
    attrib.opacity = computeOpacity (attrib.opacity);
 
96
}
 
97
 
 
98
void
 
99
FocusFadeAnim::processCandidate (CompWindow *candidateWin,
 
100
                                 CompWindow *subjectWin,
 
101
                                 CompRegion &candidateAndSubjectIntersection,
 
102
                                 int &numSelectedCandidates)
 
103
{
 
104
    AnimWindow *aCandidateWin = AnimWindow::get (candidateWin);
 
105
    RestackPersistentData *data = static_cast<RestackPersistentData *>
 
106
        (aCandidateWin->persistentData["restack"]);
 
107
    data->mWinPassingThrough = subjectWin;
 
108
}
 
109
 
 
110
void
 
111
FocusFadeAnim::cleanUp (bool closing, bool destructing)
 
112
{
 
113
    // Clear winPassingThrough of each window
 
114
    // that this one was passing through
 
115
    // during focus effect.
 
116
    foreach (CompWindow *w, ::screen->windows ())
 
117
    {
 
118
        AnimWindow *aw = AnimWindow::get (w);
 
119
        PersistentDataMap::iterator itData = aw->persistentData.find ("restack");
 
120
        if (itData != aw->persistentData.end ()) // if found
 
121
        {
 
122
            RestackPersistentData *data =
 
123
                static_cast<RestackPersistentData *> (itData->second);
 
124
            if (data->mWinPassingThrough == mWindow)
 
125
                data->mWinPassingThrough = 0;
 
126
        }
 
127
    }
 
128
 
 
129
    RestackAnim::cleanUp (closing, destructing);
 
130
}
 
131