Now we are able to display an image on the cube caps.

svn path=/trunk/KDE/kdebase/workspace/; revision=834710
This commit is contained in:
Martin Gräßlin 2008-07-19 13:43:13 +00:00
parent 1d6da823a0
commit fc777afc8f
6 changed files with 80 additions and 9 deletions

View file

@ -157,6 +157,7 @@ if(KWIN_HAVE_OPENGL_COMPOSITING)
data/snowflake.png
data/circle.png
data/circle-edgy.png
data/cubecap.png
data/cylinder.frag
data/cylinder.vert
DESTINATION ${DATA_INSTALL_DIR}/kwin )

View file

@ -25,6 +25,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <kwinconfig.h>
#include <kconfiggroup.h>
#include <kcolorscheme.h>
#include <kglobal.h>
#include <kstandarddirs.h>
#include <kdebug.h>
#include <QColor>
@ -57,6 +59,8 @@ CubeEffect::CubeEffect()
, verticalRotationDirection( Upwards )
, verticalPosition( Normal )
, wallpaper( NULL )
, texturedCaps( true )
, capTexture( NULL )
, manualAngle( 0.0 )
, manualVerticalAngle( 0.0 )
, currentShape( TimeLine::EaseInOutCurve )
@ -85,6 +89,26 @@ CubeEffect::CubeEffect()
wallpaper = new GLTexture( img );
}
}
texturedCaps = conf.readEntry( "TexturedCaps", true );
if( texturedCaps )
{
QImage img = QImage( KGlobal::dirs()->findResource( "appdata", "cubecap.png" ) );
if( !img.isNull() )
{
// change the alpha value of each pixel
for( int x=0; x<img.width(); x++ )
{
for( int y=0; y<img.height(); y++ )
{
QRgb pixel = img.pixel( x, y );
img.setPixel( x, y, qRgba( qRed(pixel), qGreen(pixel), qBlue(pixel), ((float)qAlpha(pixel))*cubeOpacity ) );
}
}
capTexture = new GLTexture( img );
capTexture->setFilter( GL_LINEAR );
capTexture->setWrapMode( GL_CLAMP );
}
}
timeLine.setCurveShape( TimeLine::EaseInOutCurve );
timeLine.setDuration( rotationDuration );
@ -119,6 +143,7 @@ CubeEffect::~CubeEffect()
{
effects->unreserveElectricBorder( borderActivate );
delete wallpaper;
delete capTexture;
}
void CubeEffect::prePaintScreen( ScreenPrePaintData& data, int time )
@ -335,6 +360,7 @@ void CubeEffect::paintScene( int mask, QRegion region, ScreenPaintData& data )
// Rotation of the cube
float cubeAngle = (float)((float)(effects->numberOfDesktops() - 2 )/(float)effects->numberOfDesktops() * 180.0f);
float point = xmax*scaleFactor*tan(cubeAngle*0.5f*M_PI/180.0f);
float zTexture = xmax*scaleFactor*tan(45.0f*M_PI/180.0f);
if( verticalRotating || verticalPosition != Normal || manualVerticalAngle != 0.0 )
{
// change the verticalPosition if manualVerticalAngle > 90 or < -90 degrees
@ -512,14 +538,14 @@ void CubeEffect::paintScene( int mask, QRegion region, ScreenPaintData& data )
{
// paint the bottom cap
glTranslatef( 0.0, -yTranslate, 0.0 );
paintCap( xmin*scaleFactor, xmax*scaleFactor, point );
paintCap( xmin*scaleFactor, xmax*scaleFactor, point, zTexture );
glTranslatef( 0.0, yTranslate, 0.0 );
}
if( (topCapBefore && !reflectionPainting) || (topCapAfter && reflectionPainting) )
{
// paint the top cap
glTranslatef( 0.0, yTranslate, 0.0 );
paintCap( xmin*scaleFactor, xmax*scaleFactor, point );
paintCap( xmin*scaleFactor, xmax*scaleFactor, point, zTexture );
glTranslatef( 0.0, -yTranslate, 0.0 );
}
}
@ -530,11 +556,11 @@ void CubeEffect::paintScene( int mask, QRegion region, ScreenPaintData& data )
{
// paint the bottom cap
glTranslatef( 0.0, -yTranslate, 0.0 );
paintCap( xmin*scaleFactor, xmax*scaleFactor, point );
paintCap( xmin*scaleFactor, xmax*scaleFactor, point, zTexture );
glTranslatef( 0.0, yTranslate, 0.0 );
// paint the top cap
glTranslatef( 0.0, yTranslate, 0.0 );
paintCap( xmin*scaleFactor, xmax*scaleFactor, point );
paintCap( xmin*scaleFactor, xmax*scaleFactor, point, zTexture );
glTranslatef( 0.0, -yTranslate, 0.0 );
}
if( i%2 == 0 && i != effects->numberOfDesktops() -1)
@ -570,14 +596,14 @@ void CubeEffect::paintScene( int mask, QRegion region, ScreenPaintData& data )
{
// paint the top cap
glTranslatef( 0.0, yTranslate, 0.0 );
paintCap( xmin*scaleFactor, xmax*scaleFactor, point );
paintCap( xmin*scaleFactor, xmax*scaleFactor, point, zTexture );
glTranslatef( 0.0, -yTranslate, 0.0 );
}
if( (topCapBefore && !reflectionPainting) || (topCapAfter && reflectionPainting) )
{
// paint the bottom cap
glTranslatef( 0.0, -yTranslate, 0.0 );
paintCap( xmin*scaleFactor, xmax*scaleFactor, point );
paintCap( xmin*scaleFactor, xmax*scaleFactor, point, zTexture );
glTranslatef( 0.0, yTranslate, 0.0 );
}
}
@ -585,7 +611,7 @@ void CubeEffect::paintScene( int mask, QRegion region, ScreenPaintData& data )
painting_desktop = effects->currentDesktop();
}
void CubeEffect::paintCap( float left, float right, float z )
void CubeEffect::paintCap( float left, float right, float z, float zTexture )
{
if( ( !paintCaps ) || effects->numberOfDesktops() <= 2 )
return;
@ -609,6 +635,27 @@ void CubeEffect::paintCap( float left, float right, float z )
glEnd();
glPopMatrix();
}
// textured caps
// only works for more than three desktops
if( texturedCaps && effects->numberOfDesktops() > 3 && capTexture )
{
glPushMatrix();
glRotatef( (effects->currentDesktop()-frontDesktop)*angle, 0.0, 1.0, 0.0 );
capTexture->bind();
glBegin( GL_QUADS );
glTexCoord2f( 0.0, 0.0 );
glVertex3f( left, 0.0, zTexture );
glTexCoord2f( 1.0, 0.0 );
glVertex3f( right, 0.0, zTexture );
glTexCoord2f( 1.0, 1.0 );
glVertex3f( right, 0.0, -zTexture );
glTexCoord2f( 0.0, 1.0 );
glVertex3f( left, 0.0, -zTexture );
glEnd( );
capTexture->unbind();
glPopMatrix();
}
glPopMatrix();
}

View file

@ -64,7 +64,7 @@ class CubeEffect
Down
};
void paintScene( int mask, QRegion region, ScreenPaintData& data );
void paintCap( float left, float right, float z );
void paintCap( float left, float right, float z, float zTexture );
void rotateToDesktop( int desktop );
void setActive( bool active );
bool activated;
@ -92,6 +92,8 @@ class CubeEffect
QColor backgroundColor;
QColor capColor;
GLTexture* wallpaper;
bool texturedCaps;
GLTexture* capTexture;
float manualAngle;
float manualVerticalAngle;
TimeLine::CurveShape currentShape;

View file

@ -78,6 +78,7 @@ CubeEffectConfig::CubeEffectConfig(QWidget* parent, const QVariantList& args) :
connect(m_ui->backgroundColorButton, SIGNAL(changed(QColor)), this, SLOT(changed()));
connect(m_ui->cubeCapsBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
connect(m_ui->cubeCapsBox, SIGNAL(stateChanged(int)), this, SLOT(capsSelectionChanged()));
connect(m_ui->capsImageBox, SIGNAL(stateChanged(int)), this, SLOT(changed()));
connect(m_ui->capColorButton, SIGNAL(changed(QColor)), this, SLOT(changed()));
load();
@ -96,6 +97,7 @@ void CubeEffectConfig::load()
int activateBorder = conf.readEntry( "BorderActivate", (int)ElectricNone );
QColor background = conf.readEntry( "BackgroundColor", QColor( Qt::black ) );
QColor capColor = conf.readEntry( "CapColor", KColorScheme( QPalette::Active, KColorScheme::Window ).background().color() );
bool texturedCaps = conf.readEntry( "TexturedCaps", true );
bool caps = conf.readEntry( "Caps", true );
if( activateBorder == (int)ElectricNone )
activateBorder--;
@ -128,6 +130,14 @@ void CubeEffectConfig::load()
{
m_ui->cubeCapsBox->setCheckState( Qt::Unchecked );
}
if( texturedCaps )
{
m_ui->capsImageBox->setCheckState( Qt::Checked );
}
else
{
m_ui->capsImageBox->setCheckState( Qt::Unchecked );
}
m_ui->backgroundColorButton->setColor( background );
m_ui->capColorButton->setColor( capColor );
capsSelectionChanged();
@ -146,6 +156,7 @@ void CubeEffectConfig::save()
conf.writeEntry( "BackgroundColor", m_ui->backgroundColorButton->color() );
conf.writeEntry( "Caps", m_ui->cubeCapsBox->checkState() == Qt::Checked ? true : false );
conf.writeEntry( "CapColor", m_ui->capColorButton->color() );
conf.writeEntry( "TexturedCaps", m_ui->capsImageBox->checkState() == Qt::Checked ? true : false );
int activateBorder = m_ui->screenEdgeCombo->currentIndex();
if( activateBorder == (int)ELECTRIC_COUNT )
@ -171,6 +182,7 @@ void CubeEffectConfig::defaults()
m_ui->backgroundColorButton->setColor( QColor( Qt::black ) );
m_ui->cubeCapsBox->setCheckState( Qt::Checked );
m_ui->capColorButton->setColor( KColorScheme( QPalette::Active, KColorScheme::Window ).background().color() );
m_ui->capsImageBox->setCheckState( Qt::Checked );
m_ui->editor->allDefault();
emit changed(true);
}
@ -182,12 +194,14 @@ void CubeEffectConfig::capsSelectionChanged()
// activate cap color
m_ui->capColorButton->setEnabled( true );
m_ui->capColorLabel->setEnabled( true );
m_ui->capsImageBox->setEnabled( true );
}
else
{
// deactivate cap color
m_ui->capColorButton->setEnabled( false );
m_ui->capColorLabel->setEnabled( false );
m_ui->capsImageBox->setEnabled( false );
}
}

View file

@ -6,7 +6,7 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>396</height>
<height>433</height>
</rect>
</property>
<layout class="QVBoxLayout" >
@ -179,6 +179,13 @@
<item row="11" column="1" >
<widget class="KColorButton" name="capColorButton" />
</item>
<item row="12" column="0" >
<widget class="QCheckBox" name="capsImageBox" >
<property name="text" >
<string>Display &amp;image on cube caps</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

BIN
effects/data/cubecap.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 371 KiB