diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index dff9307fb7..ed7025d4ce 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -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 ) diff --git a/effects/cube.cpp b/effects/cube.cpp index 55d3c62052..01b22609d8 100644 --- a/effects/cube.cpp +++ b/effects/cube.cpp @@ -25,6 +25,8 @@ along with this program. If not, see . #include #include #include +#include +#include #include #include @@ -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; xsetFilter( 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(); } diff --git a/effects/cube.h b/effects/cube.h index 7ad8d99cb9..45b8646ea7 100644 --- a/effects/cube.h +++ b/effects/cube.h @@ -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; diff --git a/effects/cube_config.cpp b/effects/cube_config.cpp index 94b9006ab1..9c8f390f8e 100644 --- a/effects/cube_config.cpp +++ b/effects/cube_config.cpp @@ -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 ); } } diff --git a/effects/cube_config.ui b/effects/cube_config.ui index a99e7e94ca..462af3a8ab 100644 --- a/effects/cube_config.ui +++ b/effects/cube_config.ui @@ -6,7 +6,7 @@ 0 0 400 - 396 + 433 @@ -179,6 +179,13 @@ + + + + Display &image on cube caps + + + diff --git a/effects/data/cubecap.png b/effects/data/cubecap.png new file mode 100644 index 0000000000..ea053cd7b9 Binary files /dev/null and b/effects/data/cubecap.png differ