2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
|
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include "minimizeanimation.h"
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2007-05-28 11:16:18 +00:00
|
|
|
KWIN_EFFECT( minimizeanimation, MinimizeAnimationEffect )
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
MinimizeAnimationEffect::MinimizeAnimationEffect()
|
|
|
|
{
|
|
|
|
mActiveAnimations = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-07 14:01:32 +00:00
|
|
|
void MinimizeAnimationEffect::prePaintScreen( ScreenPrePaintData& data, int time )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
|
2009-11-25 16:29:18 +00:00
|
|
|
QHash< EffectWindow*, TimeLine >::iterator entry = mTimeLineWindows.begin();
|
|
|
|
bool erase = false;
|
|
|
|
while( entry != mTimeLineWindows.end() )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2009-11-25 16:29:18 +00:00
|
|
|
TimeLine &timeline = entry.value();
|
|
|
|
if( entry.key()->isMinimized() )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2009-11-25 16:29:18 +00:00
|
|
|
timeline.addTime(time);
|
|
|
|
erase = (timeline.progress() >= 1.0f);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-25 16:29:18 +00:00
|
|
|
timeline.removeTime(time);
|
|
|
|
erase = (timeline.progress() <= 0.0f);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2009-11-25 16:29:18 +00:00
|
|
|
if( erase )
|
|
|
|
entry = mTimeLineWindows.erase( entry );
|
|
|
|
else
|
|
|
|
++entry;
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2009-11-25 17:48:01 +00:00
|
|
|
mActiveAnimations = mTimeLineWindows.count();
|
|
|
|
if( mActiveAnimations > 0 )
|
|
|
|
// We need to mark the screen windows as transformed. Otherwise the
|
|
|
|
// whole screen won't be repainted, resulting in artefacts
|
|
|
|
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
|
|
|
|
2009-11-25 16:29:18 +00:00
|
|
|
effects->prePaintScreen(data, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MinimizeAnimationEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time )
|
|
|
|
{
|
|
|
|
// Schedule window for transformation if the animation is still in
|
|
|
|
// progress
|
|
|
|
if( mTimeLineWindows.contains( w ) )
|
|
|
|
{
|
|
|
|
// We'll transform this window
|
|
|
|
data.setTransformed();
|
|
|
|
w->enablePainting( EffectWindow::PAINT_DISABLED_BY_MINIMIZE );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2007-07-07 14:01:32 +00:00
|
|
|
effects->prePaintWindow( w, data, time );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MinimizeAnimationEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
|
|
|
|
{
|
2009-11-28 09:00:57 +00:00
|
|
|
QHash< EffectWindow*, TimeLine >::const_iterator entry = mTimeLineWindows.constFind(w);
|
2009-11-25 16:29:18 +00:00
|
|
|
if( entry != mTimeLineWindows.constEnd() )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
// 0 = not minimized, 1 = fully minimized
|
2009-11-25 16:29:18 +00:00
|
|
|
double progress = entry->value();
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QRect geo = w->geometry();
|
|
|
|
QRect icon = w->iconGeometry();
|
|
|
|
// If there's no icon geometry, minimize to the center of the screen
|
|
|
|
if( !icon.isValid() )
|
|
|
|
icon = QRect( displayWidth() / 2, displayHeight() / 2, 0, 0 );
|
|
|
|
|
2007-09-03 15:00:43 +00:00
|
|
|
data.xScale *= interpolate(1.0, icon.width() / (double)geo.width(), progress);
|
|
|
|
data.yScale *= interpolate(1.0, icon.height() / (double)geo.height(), progress);
|
2007-04-29 17:35:43 +00:00
|
|
|
data.xTranslate = (int)interpolate(data.xTranslate, icon.x() - geo.x(), progress);
|
|
|
|
data.yTranslate = (int)interpolate(data.yTranslate, icon.y() - geo.y(), progress);
|
2008-04-20 23:49:31 +00:00
|
|
|
data.opacity *= 0.1 + (1-progress)*0.9;
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Call the next effect.
|
|
|
|
effects->paintWindow( w, mask, region, data );
|
|
|
|
}
|
|
|
|
|
|
|
|
void MinimizeAnimationEffect::postPaintScreen()
|
|
|
|
{
|
|
|
|
if( mActiveAnimations > 0 )
|
|
|
|
// Repaint the workspace so that everything would be repainted next time
|
|
|
|
effects->addRepaintFull();
|
2008-04-19 00:12:28 +00:00
|
|
|
mActiveAnimations = mTimeLineWindows.count();
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
// Call the next effect.
|
|
|
|
effects->postPaintScreen();
|
|
|
|
}
|
|
|
|
|
2009-11-25 16:29:18 +00:00
|
|
|
void MinimizeAnimationEffect::windowDeleted( EffectWindow* w )
|
|
|
|
{
|
|
|
|
mTimeLineWindows.remove( w );
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
void MinimizeAnimationEffect::windowMinimized( EffectWindow* w )
|
|
|
|
{
|
2009-11-25 16:29:18 +00:00
|
|
|
TimeLine &timeline = mTimeLineWindows[w];
|
|
|
|
timeline.setCurveShape(TimeLine::EaseInCurve);
|
|
|
|
timeline.setDuration( animationTime( 250 ));
|
|
|
|
timeline.setProgress(0.0f);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MinimizeAnimationEffect::windowUnminimized( EffectWindow* w )
|
|
|
|
{
|
2009-11-25 16:29:18 +00:00
|
|
|
TimeLine &timeline = mTimeLineWindows[w];
|
|
|
|
timeline.setCurveShape(TimeLine::EaseOutCurve);
|
|
|
|
timeline.setDuration( animationTime( 250 ));
|
|
|
|
timeline.setProgress(1.0f);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|