~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy

« back to all changes in this revision

Viewing changes to kwin/effects/minimizeanimation.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-09-05 20:45:14 UTC
  • Revision ID: james.westby@ubuntu.com-20070905204514-632hhspl0nvrc84i
Tags: upstream-3.93.0
ImportĀ upstreamĀ versionĀ 3.93.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************
 
2
 KWin - the KDE window manager
 
3
 This file is part of the KDE project.
 
4
 
 
5
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
 
6
 
 
7
You can Freely distribute this program under the GNU General Public
 
8
License. See the file "COPYING" for the exact licensing terms.
 
9
******************************************************************/
 
10
 
 
11
 
 
12
#include "minimizeanimation.h"
 
13
 
 
14
namespace KWin
 
15
{
 
16
 
 
17
KWIN_EFFECT( minimizeanimation, MinimizeAnimationEffect )
 
18
 
 
19
MinimizeAnimationEffect::MinimizeAnimationEffect()
 
20
    {
 
21
    mActiveAnimations = 0;
 
22
    }
 
23
 
 
24
 
 
25
void MinimizeAnimationEffect::prePaintScreen( ScreenPrePaintData& data, int time )
 
26
    {
 
27
    if( mActiveAnimations > 0 )
 
28
        // We need to mark the screen windows as transformed. Otherwise the
 
29
        //  whole screen won't be repainted, resulting in artefacts
 
30
        data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
 
31
 
 
32
    effects->prePaintScreen(data, time);
 
33
    }
 
34
 
 
35
void MinimizeAnimationEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time )
 
36
    {
 
37
    const float changeTime = 500;
 
38
    if( mAnimationProgress.contains( w ))
 
39
        {
 
40
        if( w->isMinimized() )
 
41
            {
 
42
            mAnimationProgress[w] += time / changeTime;
 
43
            if( mAnimationProgress[w] >= 1.0f )
 
44
                mAnimationProgress.remove( w );
 
45
            }
 
46
        else
 
47
            {
 
48
            mAnimationProgress[w] -= time / changeTime;
 
49
            if( mAnimationProgress[w] <= 0.0f )
 
50
                mAnimationProgress.remove( w );
 
51
            }
 
52
 
 
53
        // Schedule window for transformation if the animation is still in
 
54
        //  progress
 
55
        if( mAnimationProgress.contains( w ))
 
56
            {
 
57
            // We'll transform this window
 
58
            data.setTransformed();
 
59
            w->enablePainting( EffectWindow::PAINT_DISABLED_BY_MINIMIZE );
 
60
            }
 
61
        else
 
62
            // Animation just finished
 
63
            mActiveAnimations--;
 
64
        }
 
65
 
 
66
    effects->prePaintWindow( w, data, time );
 
67
    }
 
68
 
 
69
void MinimizeAnimationEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
 
70
    {
 
71
    if( mAnimationProgress.contains( w ))
 
72
    {
 
73
        // 0 = not minimized, 1 = fully minimized
 
74
        float progress = mAnimationProgress[w];
 
75
 
 
76
        QRect geo = w->geometry();
 
77
        QRect icon = w->iconGeometry();
 
78
        // If there's no icon geometry, minimize to the center of the screen
 
79
        if( !icon.isValid() )
 
80
            icon = QRect( displayWidth() / 2, displayHeight() / 2, 0, 0 );
 
81
 
 
82
        data.xScale *= interpolate(1.0, icon.width() / (float)geo.width(), progress);
 
83
        data.yScale *= interpolate(1.0, icon.height() / (float)geo.height(), progress);
 
84
        data.xTranslate = (int)interpolate(data.xTranslate, icon.x() - geo.x(), progress);
 
85
        data.yTranslate = (int)interpolate(data.yTranslate, icon.y() - geo.y(), progress);
 
86
    }
 
87
 
 
88
    // Call the next effect.
 
89
    effects->paintWindow( w, mask, region, data );
 
90
    }
 
91
 
 
92
void MinimizeAnimationEffect::postPaintScreen()
 
93
    {
 
94
    if( mActiveAnimations > 0 )
 
95
        // Repaint the workspace so that everything would be repainted next time
 
96
        effects->addRepaintFull();
 
97
 
 
98
    // Call the next effect.
 
99
    effects->postPaintScreen();
 
100
    }
 
101
 
 
102
void MinimizeAnimationEffect::windowMinimized( EffectWindow* w )
 
103
    {
 
104
    if( !mAnimationProgress.contains(w) )
 
105
        {
 
106
        mAnimationProgress[w] = 0.0f;
 
107
        mActiveAnimations++;
 
108
        }
 
109
    }
 
110
 
 
111
void MinimizeAnimationEffect::windowUnminimized( EffectWindow* w )
 
112
    {
 
113
    if( !mAnimationProgress.contains(w) )
 
114
        {
 
115
        mAnimationProgress[w] = 1.0f;
 
116
        mActiveAnimations++;
 
117
        }
 
118
    }
 
119
 
 
120
} // namespace
 
121