1
/*****************************************************************
2
KWin - the KDE window manager
3
This file is part of the KDE project.
5
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
7
You can Freely distribute this program under the GNU General Public
8
License. See the file "COPYING" for the exact licensing terms.
9
******************************************************************/
12
#include "minimizeanimation.h"
17
KWIN_EFFECT( minimizeanimation, MinimizeAnimationEffect )
19
MinimizeAnimationEffect::MinimizeAnimationEffect()
21
mActiveAnimations = 0;
25
void MinimizeAnimationEffect::prePaintScreen( ScreenPrePaintData& data, int time )
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;
32
effects->prePaintScreen(data, time);
35
void MinimizeAnimationEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time )
37
const float changeTime = 500;
38
if( mAnimationProgress.contains( w ))
40
if( w->isMinimized() )
42
mAnimationProgress[w] += time / changeTime;
43
if( mAnimationProgress[w] >= 1.0f )
44
mAnimationProgress.remove( w );
48
mAnimationProgress[w] -= time / changeTime;
49
if( mAnimationProgress[w] <= 0.0f )
50
mAnimationProgress.remove( w );
53
// Schedule window for transformation if the animation is still in
55
if( mAnimationProgress.contains( w ))
57
// We'll transform this window
58
data.setTransformed();
59
w->enablePainting( EffectWindow::PAINT_DISABLED_BY_MINIMIZE );
62
// Animation just finished
66
effects->prePaintWindow( w, data, time );
69
void MinimizeAnimationEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
71
if( mAnimationProgress.contains( w ))
73
// 0 = not minimized, 1 = fully minimized
74
float progress = mAnimationProgress[w];
76
QRect geo = w->geometry();
77
QRect icon = w->iconGeometry();
78
// If there's no icon geometry, minimize to the center of the screen
80
icon = QRect( displayWidth() / 2, displayHeight() / 2, 0, 0 );
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);
88
// Call the next effect.
89
effects->paintWindow( w, mask, region, data );
92
void MinimizeAnimationEffect::postPaintScreen()
94
if( mActiveAnimations > 0 )
95
// Repaint the workspace so that everything would be repainted next time
96
effects->addRepaintFull();
98
// Call the next effect.
99
effects->postPaintScreen();
102
void MinimizeAnimationEffect::windowMinimized( EffectWindow* w )
104
if( !mAnimationProgress.contains(w) )
106
mAnimationProgress[w] = 0.0f;
111
void MinimizeAnimationEffect::windowUnminimized( EffectWindow* w )
113
if( !mAnimationProgress.contains(w) )
115
mAnimationProgress[w] = 1.0f;