The official excuse for this effect is that I wanted to try

drawing a window several times.


svn path=/branches/work/kwin_composite/; revision=642577
This commit is contained in:
Luboš Luňák 2007-03-14 18:21:11 +00:00
parent a0133cb048
commit 5cabf743ae
4 changed files with 113 additions and 0 deletions

View file

@ -76,6 +76,7 @@ set(kwin_KDEINIT_SRCS
effects/desktopchangeslide.cpp
effects/boxswitch.cpp
effects/fallapart.cpp
effects/drunken.cpp
effects/test_input.cpp
effects/test_thumbnail.cpp
)

View file

@ -18,6 +18,7 @@ License. See the file "COPYING" for the exact licensing terms.
#include "effects/boxswitch.h"
#include "effects/desktopchangeslide.h"
#include "effects/dialogparent.h"
#include "effects/drunken.h"
#include "effects/fade.h"
#include "effects/howto.h"
#include "effects/maketransparent.h"
@ -194,6 +195,7 @@ EffectsHandler::EffectsHandler()
registerEffect("DialogParent", new GenericEffectFactory<DialogParentEffect>);
registerEffect("DesktopChangeSlide", new GenericEffectFactory<DesktopChangeSlideEffect>);
registerEffect("BoxSwitch", new GenericEffectFactory<BoxSwitchEffect>);
registerEffect("Drunken", new GenericEffectFactory<DrunkenEffect>);
registerEffect("TestInput", new GenericEffectFactory<TestInputEffect>);
registerEffect("TestThumbnail", new GenericEffectFactory<TestThumbnailEffect>);

75
effects/drunken.cpp Normal file
View file

@ -0,0 +1,75 @@
/*****************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
You can Freely distribute this program under the GNU General Public
License. See the file "COPYING" for the exact licensing terms.
******************************************************************/
#include "drunken.h"
#include <math.h>
namespace KWinInternal
{
void DrunkenEffect::prePaintScreen( int* mask, QRegion* region, int time )
{
if( !windows.isEmpty())
*mask |= Scene::PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
effects->prePaintScreen( mask, region, time );
}
void DrunkenEffect::prePaintWindow( EffectWindow* w, int* mask, QRegion* region, int time )
{
if( windows.contains( w ))
{
windows[ w ] += time / 1000.;
if( windows[ w ] < 1 )
*mask |= Scene::PAINT_WINDOW_TRANSFORMED;
else
windows.remove( w );
}
effects->prePaintWindow( w, mask, region, time );
}
void DrunkenEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
{
if( !windows.contains( w ))
{
effects->paintWindow( w, mask, region, data );
return;
}
WindowPaintData d1 = data;
// 4 cycles, decreasing amplitude
int diff = int( sin( windows[ w ] * 8 * M_PI ) * ( 1 - windows[ w ] ) * 10 );
d1.xTranslate -= diff;
d1.opacity *= 0.5;
effects->paintWindow( w, mask, region, d1 );
WindowPaintData d2 = data;
d2.xTranslate += diff;
d2.opacity *= 0.5;
effects->paintWindow( w, mask, region, d2 );
}
void DrunkenEffect::postPaintWindow( EffectWindow* w )
{
if( windows.contains( w ))
w->window()->addRepaintFull();
effects->postPaintWindow( w );
}
void DrunkenEffect::windowAdded( EffectWindow* w )
{
windows[ w ] = 0;
w->window()->addRepaintFull();
}
void DrunkenEffect::windowClosed( EffectWindow* w )
{
windows.remove( w );
}
} // namespace

35
effects/drunken.h Normal file
View file

@ -0,0 +1,35 @@
/*****************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
You can Freely distribute this program under the GNU General Public
License. See the file "COPYING" for the exact licensing terms.
******************************************************************/
#ifndef KWIN_DRUNKEN_H
#define KWIN_DRUNKEN_H
#include <effects.h>
namespace KWinInternal
{
class DrunkenEffect
: public Effect
{
public:
virtual void prePaintScreen( int* mask, QRegion* region, int time );
virtual void prePaintWindow( EffectWindow* w, int* mask, QRegion* region, int time );
virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
virtual void postPaintWindow( EffectWindow* w );
virtual void windowAdded( EffectWindow* w );
virtual void windowClosed( EffectWindow* w );
private:
QHash< EffectWindow*, double > windows; // progress
};
} // namespace
#endif