Adding WavyWindows effect which makes all windows wavy.

Meant to demonstrate possibilities of vertex transforming and for cool screenshots ;-)

svn path=/branches/work/kwin_composite/; revision=626815
This commit is contained in:
Rivo Laks 2007-01-24 17:19:00 +00:00
parent e5f5ecf22e
commit adb35ae446
3 changed files with 138 additions and 0 deletions

View file

@ -64,6 +64,7 @@ set(kwin_KDEINIT_SRCS
effects/zoom.cpp
effects/test_input.cpp
effects/presentwindows.cpp
effects/wavywindows.cpp
)
qt4_add_dbus_adaptor( kwin_KDEINIT_SRCS org.kde.KWin.xml workspace.h KWinInternal::Workspace )

95
effects/wavywindows.cpp Normal file
View file

@ -0,0 +1,95 @@
/*****************************************************************
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 <scene_opengl.h>
#include <workspace.h>
#include <client.h>
#include <math.h>
// Note that currently effects need to be manually enabled in the EffectsHandler
// class constructor (in effects.cpp).
namespace KWinInternal
{
WavyWindowsEffect::WavyWindowsEffect( Workspace* ws ) : Effect()
{
mWorkspace = ws;
mTimeElapsed = 0.0f;
}
void WavyWindowsEffect::prePaintScreen( int* mask, QRegion* region, int time )
{
// Adjust elapsed time
mTimeElapsed += (time / 1000.0f);
// We need to mark the screen as transformed. Otherwise the whole screen
// won't be repainted, resulting in artefacts
*mask |= Scene::PAINT_SCREEN_TRANSFORMED;
effects->prePaintScreen(mask, region, time);
}
void WavyWindowsEffect::prePaintWindow( EffectWindow* w, int* mask, QRegion* region, int time )
{
// This window will be transformed by the effect
*mask |= Scene::PAINT_WINDOW_TRANSFORMED;
// Check if OpenGL compositing is used
SceneOpenGL::Window* glwin = dynamic_cast< SceneOpenGL::Window *>( w->sceneWindow() );
if(glwin)
// Request the window to be divided into cells which are at most 30x30
// pixels big
glwin->requestVertexGrid(30);
effects->prePaintWindow( w, mask, region, time );
}
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
SceneOpenGL::Window* glwin = dynamic_cast< SceneOpenGL::Window* >( w->sceneWindow() );
Client* c = qobject_cast< Client* >( w->window() );
if( glwin && glwin->isVisible() && c && !c->isSpecialWindow() )
{
// 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
QVector< SceneOpenGL::Window::Vertex >& vertices = glwin->vertices();
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
glwin->markVerticesDirty();
}
// Call the next effect.
effects->paintWindow( w, mask, region, data );
}
void WavyWindowsEffect::postPaintScreen()
{
// Damage the workspace so that everything would be repainted next time
mWorkspace->addDamageFull();
// Call the next effect.
effects->postPaintScreen();
}
} // namespace

42
effects/wavywindows.h Normal file
View file

@ -0,0 +1,42 @@
/*****************************************************************
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.
******************************************************************/
#ifndef KWIN_WAVYWINDOWS_H
#define KWIN_WAVYWINDOWS_H
// Include with base class for effects.
#include <effects.h>
namespace KWinInternal
{
/**
* Demo effect which applies waves to all windows
**/
class WavyWindowsEffect
: public Effect
{
public:
WavyWindowsEffect( Workspace* ws );
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 postPaintScreen();
private:
Workspace* mWorkspace;
float mTimeElapsed;
};
} // namespace
#endif