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"
29 KWIN_EFFECT( demo_wavywindows
, WavyWindowsEffect
)
31 WavyWindowsEffect::WavyWindowsEffect()
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
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
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
71 i
< data
.quads
.count();
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();