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 "shadow.h"
|
|
|
|
|
|
|
|
#include <kwinglutils.h>
|
|
|
|
|
2007-05-28 11:34:12 +00:00
|
|
|
#include <kconfiggroup.h>
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2007-05-28 11:16:18 +00:00
|
|
|
KWIN_EFFECT( shadow, ShadowEffect )
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
ShadowEffect::ShadowEffect()
|
|
|
|
{
|
2007-05-29 11:48:10 +00:00
|
|
|
KConfigGroup conf = effects->effectConfig("Shadow");
|
2007-05-28 11:34:12 +00:00
|
|
|
shadowXOffset = conf.readEntry( "XOffset", 5 );
|
|
|
|
shadowYOffset = conf.readEntry( "YOffset", 5 );
|
|
|
|
shadowOpacity = (float)conf.readEntry( "Opacity", 0.2 );
|
2007-06-14 11:00:22 +00:00
|
|
|
shadowFuzzyness = conf.readEntry( "Fuzzyness", 10 );
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShadowEffect::prePaintWindow( EffectWindow* w, int* mask, QRegion* paint, QRegion* clip, int time )
|
|
|
|
{
|
|
|
|
*mask |= PAINT_WINDOW_TRANSLUCENT;
|
|
|
|
*paint |= ( QRegion( w->geometry()) & *paint ).translated( shadowXOffset, shadowYOffset );
|
|
|
|
effects->prePaintWindow( w, mask, paint, clip, time );
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShadowEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
|
|
|
|
{
|
|
|
|
if( !w->isDeleted() )
|
|
|
|
drawShadow( w, mask, region, data );
|
|
|
|
effects->paintWindow( w, mask, region, data );
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShadowEffect::postPaintWindow( EffectWindow* w )
|
|
|
|
{
|
|
|
|
effects->postPaintWindow( w );
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect ShadowEffect::transformWindowDamage( EffectWindow* w, const QRect& r )
|
|
|
|
{
|
2007-06-14 11:00:22 +00:00
|
|
|
QRect r2 = r | r.adjusted( shadowXOffset - shadowFuzzyness, shadowYOffset - shadowFuzzyness,
|
|
|
|
shadowXOffset + shadowFuzzyness, shadowYOffset + shadowFuzzyness);
|
2007-04-29 17:35:43 +00:00
|
|
|
return effects->transformWindowDamage( w, r2 );
|
|
|
|
}
|
|
|
|
|
2007-06-14 11:00:22 +00:00
|
|
|
void ShadowEffect::drawShadow( EffectWindow* window, int mask, QRegion region, WindowPaintData& data )
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
if(( mask & PAINT_WINDOW_TRANSLUCENT ) == 0 )
|
|
|
|
return;
|
|
|
|
glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT );
|
|
|
|
glEnable( GL_BLEND );
|
|
|
|
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
|
|
|
|
|
|
|
glPushMatrix();
|
|
|
|
if( mask & PAINT_WINDOW_TRANSFORMED )
|
|
|
|
glTranslatef( data.xTranslate, data.yTranslate, 0 );
|
2007-06-14 11:00:22 +00:00
|
|
|
glTranslatef( window->x() + shadowXOffset, window->y() + shadowYOffset, 0 );
|
2007-04-29 17:35:43 +00:00
|
|
|
if(( mask & PAINT_WINDOW_TRANSFORMED ) && ( data.xScale != 1 || data.yScale != 1 ))
|
|
|
|
glScalef( data.xScale, data.yScale, 1 );
|
|
|
|
|
2007-06-14 11:00:22 +00:00
|
|
|
int w = window->width();
|
|
|
|
int h = window->height();
|
|
|
|
int fuzzy = shadowFuzzyness;
|
|
|
|
const float verts[ 5 * 4 * 2 ] =
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2007-06-14 11:00:22 +00:00
|
|
|
// center piece (100% opacity)
|
|
|
|
0 + fuzzy, 0 + fuzzy, 0 + fuzzy, h - fuzzy, w - fuzzy, h - fuzzy, w - fuzzy, 0 + fuzzy,
|
|
|
|
// left
|
|
|
|
0 - fuzzy, 0 - fuzzy, 0 - fuzzy, h + fuzzy, 0 + fuzzy, h - fuzzy, 0 + fuzzy, 0 + fuzzy,
|
|
|
|
// top
|
|
|
|
0 - fuzzy, 0 - fuzzy, 0 + fuzzy, 0 + fuzzy, w - fuzzy, 0 + fuzzy, w + fuzzy, 0 - fuzzy,
|
|
|
|
// right piece
|
|
|
|
w - fuzzy, 0 + fuzzy, w - fuzzy, h - fuzzy, w + fuzzy, h + fuzzy, w + fuzzy, 0 - fuzzy,
|
|
|
|
// bottom
|
|
|
|
0 + fuzzy, h - fuzzy, 0 - fuzzy, h + fuzzy, w + fuzzy, h + fuzzy, w - fuzzy, h - fuzzy,
|
2007-04-29 17:35:43 +00:00
|
|
|
};
|
2007-06-14 11:00:22 +00:00
|
|
|
float opacity = shadowOpacity * data.opacity;
|
|
|
|
const float colors[ 5 * 4 * 4 ] =
|
|
|
|
{
|
|
|
|
// center
|
|
|
|
0, 0, 0, opacity, 0, 0, 0, opacity, 0, 0, 0, opacity, 0, 0, 0, opacity,
|
|
|
|
// left
|
|
|
|
0, 0, 0, 0 , 0, 0, 0, 0 , 0, 0, 0, opacity, 0, 0, 0, opacity,
|
|
|
|
// top
|
|
|
|
0, 0, 0, 0 , 0, 0, 0, opacity, 0, 0, 0, opacity, 0, 0, 0, 0 ,
|
|
|
|
// right
|
|
|
|
0, 0, 0, opacity, 0, 0, 0, opacity, 0, 0, 0, 0 , 0, 0, 0, 0 ,
|
|
|
|
// bottom
|
|
|
|
0, 0, 0, opacity, 0, 0, 0, 0 , 0, 0, 0, 0 , 0, 0, 0, opacity,
|
|
|
|
};
|
|
|
|
renderGLGeometry( mask, region, 5 * 4, verts, 0, colors );
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
glPopMatrix();
|
|
|
|
glPopAttrib();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|