Add soft shadows
svn path=/trunk/KDE/kdebase/workspace/; revision=675488
This commit is contained in:
parent
65bc41c518
commit
7812443973
4 changed files with 46 additions and 11 deletions
|
@ -25,6 +25,7 @@ ShadowEffect::ShadowEffect()
|
||||||
shadowXOffset = conf.readEntry( "XOffset", 5 );
|
shadowXOffset = conf.readEntry( "XOffset", 5 );
|
||||||
shadowYOffset = conf.readEntry( "YOffset", 5 );
|
shadowYOffset = conf.readEntry( "YOffset", 5 );
|
||||||
shadowOpacity = (float)conf.readEntry( "Opacity", 0.2 );
|
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 )
|
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 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 );
|
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 )
|
if(( mask & PAINT_WINDOW_TRANSLUCENT ) == 0 )
|
||||||
return;
|
return;
|
||||||
glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT );
|
glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT );
|
||||||
glEnable( GL_BLEND );
|
glEnable( GL_BLEND );
|
||||||
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
||||||
glColor4f( 0, 0, 0, shadowOpacity * data.opacity ); // black
|
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
if( mask & PAINT_WINDOW_TRANSFORMED )
|
if( mask & PAINT_WINDOW_TRANSFORMED )
|
||||||
glTranslatef( data.xTranslate, data.yTranslate, 0 );
|
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 ))
|
if(( mask & PAINT_WINDOW_TRANSFORMED ) && ( data.xScale != 1 || data.yScale != 1 ))
|
||||||
glScalef( data.xScale, 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,
|
// center piece (100% opacity)
|
||||||
0, w->height(),
|
0 + fuzzy, 0 + fuzzy, 0 + fuzzy, h - fuzzy, w - fuzzy, h - fuzzy, w - fuzzy, 0 + fuzzy,
|
||||||
w->width(), w->height(),
|
// left
|
||||||
w->width(), 0
|
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();
|
glPopMatrix();
|
||||||
glPopAttrib();
|
glPopAttrib();
|
||||||
|
|
|
@ -29,6 +29,7 @@ class ShadowEffect
|
||||||
void drawShadow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
|
void drawShadow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
|
||||||
int shadowXOffset, shadowYOffset;
|
int shadowXOffset, shadowYOffset;
|
||||||
float shadowOpacity;
|
float shadowOpacity;
|
||||||
|
int shadowFuzzyness;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -52,7 +52,13 @@ ShadowEffectConfig::ShadowEffectConfig(QWidget* parent, const QStringList& args)
|
||||||
connect(mShadowOpacity, SIGNAL(valueChanged(int)), this, SLOT(changed()));
|
connect(mShadowOpacity, SIGNAL(valueChanged(int)), this, SLOT(changed()));
|
||||||
layout->addWidget(mShadowOpacity, 2, 1);
|
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();
|
load();
|
||||||
}
|
}
|
||||||
|
@ -71,6 +77,7 @@ void ShadowEffectConfig::load()
|
||||||
mShadowXOffset->setValue( conf.readEntry( "XOffset", 5 ) );
|
mShadowXOffset->setValue( conf.readEntry( "XOffset", 5 ) );
|
||||||
mShadowYOffset->setValue( conf.readEntry( "YOffset", 5 ) );
|
mShadowYOffset->setValue( conf.readEntry( "YOffset", 5 ) );
|
||||||
mShadowOpacity->setValue( (int)( conf.readEntry( "Opacity", 0.2 ) * 100 ) );
|
mShadowOpacity->setValue( (int)( conf.readEntry( "Opacity", 0.2 ) * 100 ) );
|
||||||
|
mShadowFuzzyness->setValue( conf.readEntry( "Fuzzyness", 10 ) );
|
||||||
|
|
||||||
emit changed(false);
|
emit changed(false);
|
||||||
}
|
}
|
||||||
|
@ -84,6 +91,7 @@ void ShadowEffectConfig::save()
|
||||||
conf.writeEntry( "XOffset", mShadowXOffset->value() );
|
conf.writeEntry( "XOffset", mShadowXOffset->value() );
|
||||||
conf.writeEntry( "YOffset", mShadowYOffset->value() );
|
conf.writeEntry( "YOffset", mShadowYOffset->value() );
|
||||||
conf.writeEntry( "Opacity", mShadowOpacity->value() / 100.0 );
|
conf.writeEntry( "Opacity", mShadowOpacity->value() / 100.0 );
|
||||||
|
conf.writeEntry( "Fuzzyness", mShadowFuzzyness->value() );
|
||||||
conf.sync();
|
conf.sync();
|
||||||
|
|
||||||
emit changed(false);
|
emit changed(false);
|
||||||
|
@ -96,6 +104,7 @@ void ShadowEffectConfig::defaults()
|
||||||
mShadowXOffset->setValue( 5 );
|
mShadowXOffset->setValue( 5 );
|
||||||
mShadowYOffset->setValue( 5 );
|
mShadowYOffset->setValue( 5 );
|
||||||
mShadowOpacity->setValue( 20 );
|
mShadowOpacity->setValue( 20 );
|
||||||
|
mShadowFuzzyness->setValue( 10 );
|
||||||
emit changed(true);
|
emit changed(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ class ShadowEffectConfig : public KCModule
|
||||||
QSpinBox* mShadowXOffset;
|
QSpinBox* mShadowXOffset;
|
||||||
QSpinBox* mShadowYOffset;
|
QSpinBox* mShadowYOffset;
|
||||||
QSpinBox* mShadowOpacity;
|
QSpinBox* mShadowOpacity;
|
||||||
|
QSpinBox* mShadowFuzzyness;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
Loading…
Reference in a new issue