add more spacing
[personal-kdebase.git] / workspace / kwin / effects / test / drunken.cpp
blob05287e9ab524beaf91755012b80cd33c46e4e217
1 /*****************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
7 You can Freely distribute this program under the GNU General Public
8 License. See the file "COPYING" for the exact licensing terms.
9 ******************************************************************/
11 #include "drunken.h"
13 #include <math.h>
15 namespace KWin
18 KWIN_EFFECT( drunken, DrunkenEffect )
20 void DrunkenEffect::prePaintScreen( ScreenPrePaintData& data, int time )
22 if( !windows.isEmpty())
23 data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
24 effects->prePaintScreen( data, time );
27 void DrunkenEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time )
29 if( windows.contains( w ))
31 windows[ w ] += time / 1000.;
32 if( windows[ w ] < 1 )
33 data.setTransformed();
34 else
35 windows.remove( w );
37 effects->prePaintWindow( w, data, time );
40 void DrunkenEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
42 if( !windows.contains( w ))
44 effects->paintWindow( w, mask, region, data );
45 return;
47 WindowPaintData d1 = data;
48 // 4 cycles, decreasing amplitude
49 int diff = int( sin( windows[ w ] * 8 * M_PI ) * ( 1 - windows[ w ] ) * 10 );
50 d1.xTranslate -= diff;
51 d1.opacity *= 0.5;
52 effects->paintWindow( w, mask, region, d1 );
53 WindowPaintData d2 = data;
54 d2.xTranslate += diff;
55 d2.opacity *= 0.5;
56 effects->paintWindow( w, mask, region, d2 );
59 void DrunkenEffect::postPaintWindow( EffectWindow* w )
61 if( windows.contains( w ))
62 w->addRepaintFull();
63 effects->postPaintWindow( w );
66 void DrunkenEffect::windowAdded( EffectWindow* w )
68 windows[ w ] = 0;
69 w->addRepaintFull();
72 void DrunkenEffect::windowClosed( EffectWindow* w )
74 windows.remove( w );
77 } // namespace