add more spacing
[personal-kdebase.git] / workspace / kwin / effects / test / demo_wavywindows.cpp
blobe7a0634eeee84d3b42e4c041d77fa2a4abdeae42
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 "demo_wavywindows.h"
23 #include <math.h>
26 namespace KWin
29 KWIN_EFFECT( demo_wavywindows, WavyWindowsEffect )
31 WavyWindowsEffect::WavyWindowsEffect()
33 mTimeElapsed = 0.0f;
37 void WavyWindowsEffect::prePaintScreen( ScreenPrePaintData& data, int time )
39 // Adjust elapsed time
40 mTimeElapsed += (time / 1000.0f);
41 // We need to mark the screen windows as transformed. Otherwise the whole
42 // screen won't be repainted, resulting in artefacts
43 data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
45 effects->prePaintScreen(data, time);
48 void WavyWindowsEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time )
50 // This window will be transformed by the effect
51 data.setTransformed();
52 // Check if OpenGL compositing is used
53 // Request the window to be divided into cells which are at most 30x30
54 // pixels big
55 data.quads = data.quads.makeGrid( 30 );
57 effects->prePaintWindow( w, data, time );
60 void WavyWindowsEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
62 // Make sure we have OpenGL compositing and the window is vidible and not a
63 // special window
64 // TODO if( w->isVisible() && !w->isSpecialWindow() )
65 if( !w->isSpecialWindow() )
67 // We have OpenGL compositing and the window has been subdivided
68 // because of our request (in pre-paint pass)
69 // Transform all the vertices to create wavy effect
70 for( int i = 0;
71 i < data.quads.count();
72 ++i )
73 for( int j = 0;
74 j < 4;
75 ++j )
77 WindowVertex& v = data.quads[ i ][ j ];
78 v.move( v.x() + sin(mTimeElapsed + v.originalY() / 60 + 0.5f) * 10,
79 v.y() + sin(mTimeElapsed + v.originalX() / 80) * 10 );
83 // Call the next effect.
84 effects->paintWindow( w, mask, region, data );
87 void WavyWindowsEffect::postPaintScreen()
89 // Repaint the workspace so that everything would be repainted next time
90 effects->addRepaintFull();
92 // Call the next effect.
93 effects->postPaintScreen();
96 } // namespace