From 7812443973575d9c40addd01c6345321b90fb91a Mon Sep 17 00:00:00 2001 From: Rivo Laks Date: Thu, 14 Jun 2007 11:00:22 +0000 Subject: [PATCH] Add soft shadows svn path=/trunk/KDE/kdebase/workspace/; revision=675488 --- effects/shadow.cpp | 44 ++++++++++++++++++++++++++++++--------- effects/shadow.h | 1 + effects/shadow_config.cpp | 11 +++++++++- effects/shadow_config.h | 1 + 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/effects/shadow.cpp b/effects/shadow.cpp index 54e39b7c67..b45a044cd8 100644 --- a/effects/shadow.cpp +++ b/effects/shadow.cpp @@ -25,6 +25,7 @@ ShadowEffect::ShadowEffect() shadowXOffset = conf.readEntry( "XOffset", 5 ); shadowYOffset = conf.readEntry( "YOffset", 5 ); shadowOpacity = (float)conf.readEntry( "Opacity", 0.2 ); + shadowFuzzyness = conf.readEntry( "Fuzzyness", 10 ); } void ShadowEffect::prePaintWindow( EffectWindow* w, int* mask, QRegion* paint, QRegion* clip, int time ) @@ -48,34 +49,57 @@ void ShadowEffect::postPaintWindow( EffectWindow* w ) QRect ShadowEffect::transformWindowDamage( EffectWindow* w, const QRect& r ) { - QRect r2 = r | r.translated( shadowXOffset, shadowYOffset ); + QRect r2 = r | r.adjusted( shadowXOffset - shadowFuzzyness, shadowYOffset - shadowFuzzyness, + shadowXOffset + shadowFuzzyness, shadowYOffset + shadowFuzzyness); return effects->transformWindowDamage( w, r2 ); } -void ShadowEffect::drawShadow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ) +void ShadowEffect::drawShadow( EffectWindow* window, int mask, QRegion region, WindowPaintData& data ) { 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 ); - glColor4f( 0, 0, 0, shadowOpacity * data.opacity ); // black glPushMatrix(); if( mask & PAINT_WINDOW_TRANSFORMED ) glTranslatef( data.xTranslate, data.yTranslate, 0 ); - glTranslatef( w->x() + shadowXOffset, w->y() + shadowYOffset, 0 ); + glTranslatef( window->x() + shadowXOffset, window->y() + shadowYOffset, 0 ); if(( mask & PAINT_WINDOW_TRANSFORMED ) && ( data.xScale != 1 || data.yScale != 1 )) glScalef( data.xScale, data.yScale, 1 ); - const float verts[ 4 * 2 ] = + int w = window->width(); + int h = window->height(); + int fuzzy = shadowFuzzyness; + const float verts[ 5 * 4 * 2 ] = { - 0, 0, - 0, w->height(), - w->width(), w->height(), - w->width(), 0 + // 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, }; - renderGLGeometry( mask, region, 4, verts ); + 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 ); glPopMatrix(); glPopAttrib(); diff --git a/effects/shadow.h b/effects/shadow.h index 3fca64e974..a9c3a10e91 100644 --- a/effects/shadow.h +++ b/effects/shadow.h @@ -29,6 +29,7 @@ class ShadowEffect void drawShadow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ); int shadowXOffset, shadowYOffset; float shadowOpacity; + int shadowFuzzyness; }; } // namespace diff --git a/effects/shadow_config.cpp b/effects/shadow_config.cpp index 8ab56b2db3..735f10ddb0 100644 --- a/effects/shadow_config.cpp +++ b/effects/shadow_config.cpp @@ -52,7 +52,13 @@ ShadowEffectConfig::ShadowEffectConfig(QWidget* parent, const QStringList& args) connect(mShadowOpacity, SIGNAL(valueChanged(int)), this, SLOT(changed())); layout->addWidget(mShadowOpacity, 2, 1); - layout->addItem(new QSpacerItem(10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding), 3, 0, 1, 2); + layout->addWidget(new QLabel(i18n("Shadow fuzzyness:")), 3, 0); + mShadowFuzzyness = new QSpinBox; + mShadowFuzzyness->setRange(0, 20); + connect(mShadowFuzzyness, SIGNAL(valueChanged(int)), this, SLOT(changed())); + layout->addWidget(mShadowFuzzyness, 3, 1); + + layout->addItem(new QSpacerItem(10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding), 4, 0, 1, 2); load(); } @@ -71,6 +77,7 @@ void ShadowEffectConfig::load() mShadowXOffset->setValue( conf.readEntry( "XOffset", 5 ) ); mShadowYOffset->setValue( conf.readEntry( "YOffset", 5 ) ); mShadowOpacity->setValue( (int)( conf.readEntry( "Opacity", 0.2 ) * 100 ) ); + mShadowFuzzyness->setValue( conf.readEntry( "Fuzzyness", 10 ) ); emit changed(false); } @@ -84,6 +91,7 @@ void ShadowEffectConfig::save() conf.writeEntry( "XOffset", mShadowXOffset->value() ); conf.writeEntry( "YOffset", mShadowYOffset->value() ); conf.writeEntry( "Opacity", mShadowOpacity->value() / 100.0 ); + conf.writeEntry( "Fuzzyness", mShadowFuzzyness->value() ); conf.sync(); emit changed(false); @@ -96,6 +104,7 @@ void ShadowEffectConfig::defaults() mShadowXOffset->setValue( 5 ); mShadowYOffset->setValue( 5 ); mShadowOpacity->setValue( 20 ); + mShadowFuzzyness->setValue( 10 ); emit changed(true); } diff --git a/effects/shadow_config.h b/effects/shadow_config.h index 9f33522ee5..379ae364ab 100644 --- a/effects/shadow_config.h +++ b/effects/shadow_config.h @@ -34,6 +34,7 @@ class ShadowEffectConfig : public KCModule QSpinBox* mShadowXOffset; QSpinBox* mShadowYOffset; QSpinBox* mShadowOpacity; + QSpinBox* mShadowFuzzyness; }; } // namespace