2007-04-29 17:35:43 +00:00
|
|
|
/*****************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
|
|
License. See the file "COPYING" for the exact licensing terms.
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
#include "fallapart.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2007-05-28 11:16:18 +00:00
|
|
|
KWIN_EFFECT( fallapart, FallApartEffect )
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-07-07 14:01:32 +00:00
|
|
|
void FallApartEffect::prePaintScreen( ScreenPrePaintData& data, int time )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
if( !windows.isEmpty())
|
2007-07-07 14:01:32 +00:00
|
|
|
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
|
|
|
effects->prePaintScreen(data, time);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2007-07-07 14:01:32 +00:00
|
|
|
void FallApartEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
if( windows.contains( w ))
|
|
|
|
{
|
|
|
|
if( windows[ w ] < 1 )
|
|
|
|
{
|
|
|
|
windows[ w ] += time / 1000.;
|
2007-07-19 14:05:59 +00:00
|
|
|
data.setTransformed();
|
2007-04-29 17:35:43 +00:00
|
|
|
w->enablePainting( EffectWindow::PAINT_DISABLED_BY_DELETE );
|
|
|
|
// Request the window to be divided into cells
|
2007-07-07 14:01:32 +00:00
|
|
|
data.quads = data.quads.makeGrid( 40 );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
windows.remove( w );
|
|
|
|
w->unrefWindow();
|
|
|
|
}
|
|
|
|
}
|
2007-07-07 14:01:32 +00:00
|
|
|
effects->prePaintWindow( w, data, time );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FallApartEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
|
|
|
|
{
|
|
|
|
if( windows.contains( w ))
|
|
|
|
{
|
2007-07-07 14:01:32 +00:00
|
|
|
WindowQuadList new_quads;
|
|
|
|
int cnt = 0;
|
|
|
|
foreach( WindowQuad quad, data.quads )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
// make fragments move in various directions, based on where
|
|
|
|
// they are (left pieces generally move to the left, etc.)
|
2007-07-07 14:01:32 +00:00
|
|
|
QPointF p1( quad[ 0 ].x(), quad[ 0 ].y());
|
2007-04-29 17:35:43 +00:00
|
|
|
double xdiff = 0;
|
|
|
|
if( p1.x() < w->width() / 2 )
|
|
|
|
xdiff = -( w->width() / 2 - p1.x()) / w->width() * 100;
|
|
|
|
if( p1.x() > w->width() / 2 )
|
|
|
|
xdiff = ( p1.x() - w->width() / 2 ) / w->width() * 100;
|
|
|
|
double ydiff = 0;
|
|
|
|
if( p1.y() < w->height() / 2 )
|
|
|
|
ydiff = -( w->height() / 2 - p1.y()) / w->height() * 100;
|
|
|
|
if( p1.y() > w->height() / 2 )
|
|
|
|
ydiff = ( p1.y() - w->height() / 2 ) / w->height() * 100;
|
|
|
|
double modif = windows[ w ] * windows[ w ] * 64;
|
2007-07-07 14:01:32 +00:00
|
|
|
srandom( cnt ); // change direction randomly but consistently
|
2007-04-29 17:35:43 +00:00
|
|
|
xdiff += ( rand() % 21 - 10 );
|
|
|
|
ydiff += ( rand() % 21 - 10 );
|
|
|
|
for( int j = 0;
|
|
|
|
j < 4;
|
|
|
|
++j )
|
|
|
|
{
|
2007-07-07 14:01:32 +00:00
|
|
|
quad[ j ].move( quad[ j ].x() + xdiff * modif, quad[ j ].y() + ydiff * modif );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
// also make the fragments rotate around their center
|
2007-07-07 14:01:32 +00:00
|
|
|
QPointF center(( quad[ 0 ].x() + quad[ 1 ].x() + quad[ 2 ].x() + quad[ 3 ].x()) / 4,
|
|
|
|
( quad[ 0 ].y() + quad[ 1 ].y() + quad[ 2 ].y() + quad[ 3 ].y()) / 4 );
|
2007-04-29 17:35:43 +00:00
|
|
|
double adiff = ( rand() % 720 - 360 ) / 360. * 2 * M_PI; // spin randomly
|
|
|
|
for( int j = 0;
|
|
|
|
j < 4;
|
|
|
|
++j )
|
|
|
|
{
|
2007-07-07 14:01:32 +00:00
|
|
|
double x = quad[ j ].x() - center.x();
|
|
|
|
double y = quad[ j ].y() - center.y();
|
2007-04-29 17:35:43 +00:00
|
|
|
double angle = atan2( y, x );
|
|
|
|
angle += windows[ w ] * adiff;
|
|
|
|
double dist = sqrt( x * x + y * y );
|
|
|
|
x = dist * cos( angle );
|
|
|
|
y = dist * sin( angle );
|
2007-07-07 14:01:32 +00:00
|
|
|
quad[ j ].move( center.x() + x, center.y() + y );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2007-07-07 14:01:32 +00:00
|
|
|
new_quads.append( quad );
|
|
|
|
++cnt;
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2007-07-07 14:01:32 +00:00
|
|
|
data.quads = new_quads;
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
effects->paintWindow( w, mask, region, data );
|
|
|
|
}
|
|
|
|
|
|
|
|
void FallApartEffect::postPaintScreen()
|
|
|
|
{
|
|
|
|
if( !windows.isEmpty())
|
|
|
|
effects->addRepaintFull();
|
|
|
|
effects->postPaintScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FallApartEffect::windowClosed( EffectWindow* c )
|
|
|
|
{
|
|
|
|
windows[ c ] = 0;
|
|
|
|
c->refWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FallApartEffect::windowDeleted( EffectWindow* c )
|
|
|
|
{
|
|
|
|
windows.remove( c );
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|