2007-01-24 17:19:00 +00:00
|
|
|
/*****************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
|
|
|
|
|
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
|
|
License. See the file "COPYING" for the exact licensing terms.
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include "wavywindows.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
2007-04-05 12:07:35 +00:00
|
|
|
namespace KWin
|
2007-01-24 17:19:00 +00:00
|
|
|
{
|
|
|
|
|
2007-04-11 15:46:46 +00:00
|
|
|
KWIN_EFFECT( WavyWindows, WavyWindowsEffect )
|
|
|
|
|
2007-02-04 22:19:17 +00:00
|
|
|
WavyWindowsEffect::WavyWindowsEffect()
|
2007-01-24 17:19:00 +00:00
|
|
|
{
|
|
|
|
mTimeElapsed = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void WavyWindowsEffect::prePaintScreen( int* mask, QRegion* region, int time )
|
|
|
|
{
|
|
|
|
// Adjust elapsed time
|
|
|
|
mTimeElapsed += (time / 1000.0f);
|
2007-02-11 17:35:10 +00:00
|
|
|
// We need to mark the screen windows as transformed. Otherwise the whole
|
|
|
|
// screen won't be repainted, resulting in artefacts
|
2007-04-11 15:46:46 +00:00
|
|
|
*mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
2007-01-24 17:19:00 +00:00
|
|
|
|
|
|
|
effects->prePaintScreen(mask, region, time);
|
|
|
|
}
|
|
|
|
|
2007-03-25 10:48:07 +00:00
|
|
|
void WavyWindowsEffect::prePaintWindow( EffectWindow* w, int* mask, QRegion* paint, QRegion* clip, int time )
|
2007-01-24 17:19:00 +00:00
|
|
|
{
|
|
|
|
// This window will be transformed by the effect
|
2007-04-11 15:46:46 +00:00
|
|
|
*mask |= PAINT_WINDOW_TRANSFORMED;
|
2007-01-24 17:19:00 +00:00
|
|
|
// Check if OpenGL compositing is used
|
2007-04-11 15:46:46 +00:00
|
|
|
// Request the window to be divided into cells which are at most 30x30
|
|
|
|
// pixels big
|
|
|
|
w->requestVertexGrid(30);
|
2007-01-24 17:19:00 +00:00
|
|
|
|
2007-03-25 10:48:07 +00:00
|
|
|
effects->prePaintWindow( w, mask, paint, clip, time );
|
2007-01-24 17:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WavyWindowsEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
|
|
|
|
{
|
|
|
|
// Make sure we have OpenGL compositing and the window is vidible and not a
|
|
|
|
// special window
|
2007-04-11 15:46:46 +00:00
|
|
|
// TODO if( w->isVisible() && !w->isSpecialWindow() )
|
|
|
|
if( !w->isSpecialWindow() )
|
2007-01-24 17:19:00 +00:00
|
|
|
{
|
|
|
|
// We have OpenGL compositing and the window has been subdivided
|
|
|
|
// because of our request (in pre-paint pass)
|
|
|
|
// Transform all the vertices to create wavy effect
|
2007-04-11 15:46:46 +00:00
|
|
|
QVector< Vertex >& vertices = w->vertices();
|
2007-01-24 17:19:00 +00:00
|
|
|
for(int i = 0; i < vertices.count(); i++)
|
|
|
|
{
|
|
|
|
vertices[i].pos[0] += sin(mTimeElapsed + vertices[i].texcoord[1] / 60 + 0.5f) * 10;
|
|
|
|
vertices[i].pos[1] += sin(mTimeElapsed + vertices[i].texcoord[0] / 80) * 10;
|
|
|
|
}
|
|
|
|
// We have changed the vertices, so they will have to be reset before
|
|
|
|
// the next paint pass
|
2007-04-11 15:46:46 +00:00
|
|
|
w->markVerticesDirty();
|
2007-01-24 17:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Call the next effect.
|
|
|
|
effects->paintWindow( w, mask, region, data );
|
|
|
|
}
|
|
|
|
|
|
|
|
void WavyWindowsEffect::postPaintScreen()
|
|
|
|
{
|
2007-02-12 15:22:43 +00:00
|
|
|
// Repaint the workspace so that everything would be repainted next time
|
2007-04-11 15:46:46 +00:00
|
|
|
effects->addRepaintFull();
|
2007-01-24 17:19:00 +00:00
|
|
|
|
|
|
|
// Call the next effect.
|
|
|
|
effects->postPaintScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|