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 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
21 #include "minimizeanimation.h"
26 KWIN_EFFECT( minimizeanimation
, MinimizeAnimationEffect
)
28 MinimizeAnimationEffect::MinimizeAnimationEffect()
30 mActiveAnimations
= 0;
34 void MinimizeAnimationEffect::prePaintScreen( ScreenPrePaintData
& data
, int time
)
36 mActiveAnimations
= mTimeLineWindows
.count();
37 if( mActiveAnimations
> 0 )
38 // We need to mark the screen windows as transformed. Otherwise the
39 // whole screen won't be repainted, resulting in artefacts
40 data
.mask
|= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS
;
42 effects
->prePaintScreen(data
, time
);
45 void MinimizeAnimationEffect::prePaintWindow( EffectWindow
* w
, WindowPrePaintData
& data
, int time
)
47 if( mTimeLineWindows
.contains( w
))
49 if( w
->isMinimized() )
51 mTimeLineWindows
[w
].addTime(time
);
52 if( mTimeLineWindows
[w
].progress() >= 1.0f
)
53 mTimeLineWindows
.remove( w
);
57 mTimeLineWindows
[w
].removeTime(time
);
58 if( mTimeLineWindows
[w
].progress() <= 0.0f
)
59 mTimeLineWindows
.remove( w
);
62 // Schedule window for transformation if the animation is still in
64 if( mTimeLineWindows
.contains( w
))
66 // We'll transform this window
67 data
.setTransformed();
68 w
->enablePainting( EffectWindow::PAINT_DISABLED_BY_MINIMIZE
);
72 effects
->prePaintWindow( w
, data
, time
);
75 void MinimizeAnimationEffect::paintWindow( EffectWindow
* w
, int mask
, QRegion region
, WindowPaintData
& data
)
77 if( mTimeLineWindows
.contains( w
))
79 // 0 = not minimized, 1 = fully minimized
80 double progress
= mTimeLineWindows
[w
].value();
82 QRect geo
= w
->geometry();
83 QRect icon
= w
->iconGeometry();
84 // If there's no icon geometry, minimize to the center of the screen
86 icon
= QRect( displayWidth() / 2, displayHeight() / 2, 0, 0 );
88 data
.xScale
*= interpolate(1.0, icon
.width() / (double)geo
.width(), progress
);
89 data
.yScale
*= interpolate(1.0, icon
.height() / (double)geo
.height(), progress
);
90 data
.xTranslate
= (int)interpolate(data
.xTranslate
, icon
.x() - geo
.x(), progress
);
91 data
.yTranslate
= (int)interpolate(data
.yTranslate
, icon
.y() - geo
.y(), progress
);
92 data
.opacity
*= 0.1 + (1-progress
)*0.9;
95 // Call the next effect.
96 effects
->paintWindow( w
, mask
, region
, data
);
99 void MinimizeAnimationEffect::postPaintScreen()
101 if( mActiveAnimations
> 0 )
102 // Repaint the workspace so that everything would be repainted next time
103 effects
->addRepaintFull();
104 mActiveAnimations
= mTimeLineWindows
.count();
106 // Call the next effect.
107 effects
->postPaintScreen();
110 void MinimizeAnimationEffect::windowMinimized( EffectWindow
* w
)
112 mTimeLineWindows
[w
].setCurveShape(TimeLine::EaseInCurve
);
113 mTimeLineWindows
[w
].setDuration( animationTime( 250 ));
114 mTimeLineWindows
[w
].setProgress(0.0f
);
117 void MinimizeAnimationEffect::windowUnminimized( EffectWindow
* w
)
119 mTimeLineWindows
[w
].setCurveShape(TimeLine::EaseOutCurve
);
120 mTimeLineWindows
[w
].setDuration( animationTime( 250 ));
121 mTimeLineWindows
[w
].setProgress(1.0f
);