041673bf86
without kwin4_effect_ prefix, so change the name in those macros to lowercase. Some modifications to the macros themselves as well. Effect loading via dcop might work again now. svn path=/trunk/KDE/kdebase/workspace/; revision=669033
130 lines
3.9 KiB
C++
130 lines
3.9 KiB
C++
/*****************************************************************
|
|
KWin - the KDE window manager
|
|
This file is part of the KDE project.
|
|
|
|
Copyright (C) 2007 Philip Falkner <philip.falkner@gmail.com>
|
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
License. See the file "COPYING" for the exact licensing terms.
|
|
******************************************************************/
|
|
|
|
#include "fade.h"
|
|
|
|
namespace KWin
|
|
{
|
|
|
|
KWIN_EFFECT( fade, FadeEffect )
|
|
|
|
FadeEffect::FadeEffect()
|
|
: fade_in_speed( 20 )
|
|
, fade_out_speed( 70 )
|
|
{
|
|
}
|
|
|
|
void FadeEffect::prePaintWindow( EffectWindow* w, int* mask, QRegion* paint, QRegion* clip, int time )
|
|
{
|
|
if( windows.contains( w ))
|
|
{
|
|
if( windows[ w ].current < windows[ w ].target )
|
|
{
|
|
windows[ w ].current += time / double( 10000 / fade_in_speed ) * windows[ w ].step_mult;
|
|
if( windows[ w ].current > windows[ w ].target )
|
|
windows[ w ].current = windows[ w ].target;
|
|
}
|
|
else if( windows[ w ].current > windows[ w ].target )
|
|
{
|
|
windows[ w ].current -= time / double( 10000 / fade_out_speed ) * windows[ w ].step_mult;
|
|
if( windows[ w ].current < windows[ w ].target )
|
|
windows[ w ].current = windows[ w ].target;
|
|
}
|
|
|
|
if( !windows[ w ].isFading())
|
|
{
|
|
if( windows[ w ].deleted )
|
|
{
|
|
w->unrefWindow();
|
|
windows.remove( w );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
*mask |= PAINT_WINDOW_TRANSLUCENT;
|
|
*mask &= ~PAINT_WINDOW_OPAQUE;
|
|
if( windows[ w ].deleted )
|
|
w->enablePainting( EffectWindow::PAINT_DISABLED_BY_DELETE );
|
|
}
|
|
}
|
|
effects->prePaintWindow( w, mask, paint, clip, time );
|
|
}
|
|
|
|
void FadeEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
|
|
{
|
|
if( windows.contains( w ))
|
|
data.opacity = ( data.opacity + ( w->opacity() == 0.0 ? 1 : 0 )) * windows[ w ].current;
|
|
effects->paintWindow( w, mask, region, data );
|
|
}
|
|
|
|
void FadeEffect::postPaintWindow( EffectWindow* w )
|
|
{
|
|
if( windows.contains( w ) && windows.value( w ).isFading())
|
|
w->addRepaintFull(); // trigger next animation repaint
|
|
effects->postPaintWindow( w );
|
|
}
|
|
|
|
void FadeEffect::windowOpacityChanged( EffectWindow* c, double old_opacity )
|
|
{
|
|
double new_opacity = c->opacity();
|
|
if( !windows.contains( c ))
|
|
windows[ c ].current = 1;
|
|
if( new_opacity == 0.0 )
|
|
{ // special case; if opacity is 0, we can't just multiply data.opacity
|
|
windows[ c ].current = windows[ c ].current * ( old_opacity == 0.0 ? 1 : old_opacity );
|
|
windows[ c ].target = 0;
|
|
windows[ c ].step_mult = 1;
|
|
}
|
|
else
|
|
{
|
|
windows[ c ].current = ( windows[ c ].current * ( old_opacity == 0.0 ? 1 : old_opacity )) / new_opacity;
|
|
windows[ c ].target = 1;
|
|
windows[ c ].step_mult = 1 / new_opacity;
|
|
}
|
|
c->addRepaintFull();
|
|
}
|
|
|
|
void FadeEffect::windowAdded( EffectWindow* c )
|
|
{
|
|
if( !windows.contains( c ))
|
|
windows[ c ].current = 0;
|
|
if( c->opacity() == 0.0 )
|
|
{
|
|
windows[ c ].target = 0;
|
|
windows[ c ].step_mult = 1;
|
|
}
|
|
else
|
|
{
|
|
windows[ c ].target = 1;
|
|
windows[ c ].step_mult = 1 / c->opacity();
|
|
}
|
|
c->addRepaintFull();
|
|
}
|
|
|
|
void FadeEffect::windowClosed( EffectWindow* c )
|
|
{
|
|
if( !windows.contains( c ))
|
|
windows[ c ].current = 1;
|
|
if( c->opacity() == 0.0 )
|
|
windows[ c ].step_mult = 1;
|
|
else
|
|
windows[ c ].step_mult = 1 / c->opacity();
|
|
windows[ c ].target = 0;
|
|
windows[ c ].deleted = true;
|
|
c->addRepaintFull();
|
|
c->refWindow();
|
|
}
|
|
|
|
void FadeEffect::windowDeleted( EffectWindow* c )
|
|
{
|
|
windows.remove( c );
|
|
}
|
|
|
|
} // namespace
|