2008-07-15 19:21:50 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2008 Martin Gräßlin <ubuntu@martin-graesslin.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#include "cube.h"
|
|
|
|
#include "cylinder.h"
|
|
|
|
|
|
|
|
#include <kdebug.h>
|
|
|
|
#include <KStandardDirs>
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include <GL/gl.h>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
KWIN_EFFECT( cylinder, CylinderEffect )
|
2008-08-18 09:52:33 +00:00
|
|
|
KWIN_EFFECT_SUPPORTED( cylinder, CylinderEffect::supported() )
|
2008-07-15 19:21:50 +00:00
|
|
|
|
|
|
|
CylinderEffect::CylinderEffect()
|
|
|
|
: CubeEffect()
|
|
|
|
, mInited( false )
|
|
|
|
, mValid( true )
|
|
|
|
, mShader( 0 )
|
|
|
|
{
|
2009-02-06 09:51:04 +00:00
|
|
|
shortcutsRegistered = false;
|
2008-10-02 09:27:32 +00:00
|
|
|
reconfigure( ReconfigureAll );
|
2008-07-15 19:21:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CylinderEffect::~CylinderEffect()
|
|
|
|
{
|
|
|
|
delete mShader;
|
|
|
|
}
|
|
|
|
|
2008-10-02 09:27:32 +00:00
|
|
|
void CylinderEffect::reconfigure( ReconfigureFlags )
|
|
|
|
{
|
|
|
|
loadConfig( "Cylinder" );
|
|
|
|
}
|
|
|
|
|
2008-08-18 09:52:33 +00:00
|
|
|
bool CylinderEffect::supported()
|
|
|
|
{
|
2008-10-29 12:50:26 +00:00
|
|
|
return GLShader::fragmentShaderSupported() &&
|
2008-08-18 09:52:33 +00:00
|
|
|
(effects->compositingType() == OpenGLCompositing);
|
|
|
|
}
|
|
|
|
|
2008-07-15 19:21:50 +00:00
|
|
|
bool CylinderEffect::loadData()
|
|
|
|
{
|
|
|
|
mInited = true;
|
|
|
|
QString fragmentshader = KGlobal::dirs()->findResource("data", "kwin/cylinder.frag");
|
|
|
|
QString vertexshader = KGlobal::dirs()->findResource("data", "kwin/cylinder.vert");
|
|
|
|
if(fragmentshader.isEmpty() || vertexshader.isEmpty())
|
|
|
|
{
|
2008-11-17 15:04:52 +00:00
|
|
|
kError(1212) << "Couldn't locate shader files" << endl;
|
2008-07-15 19:21:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mShader = new GLShader(vertexshader, fragmentshader);
|
|
|
|
if(!mShader->isValid())
|
|
|
|
{
|
2008-11-17 15:04:52 +00:00
|
|
|
kError(1212) << "The shader failed to load!" << endl;
|
2008-07-15 19:21:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mShader->bind();
|
|
|
|
mShader->setUniform( "winTexture", 0 );
|
|
|
|
mShader->setUniform( "opacity", cubeOpacity );
|
2008-08-04 15:07:34 +00:00
|
|
|
QRect rect = effects->clientArea( FullScreenArea, activeScreen, effects->currentDesktop());
|
2009-02-06 18:53:16 +00:00
|
|
|
if( effects->numScreens() > 1 && bigCube )
|
2008-08-25 14:12:12 +00:00
|
|
|
rect = effects->clientArea( FullArea, activeScreen, effects->currentDesktop() );
|
2008-07-15 19:21:50 +00:00
|
|
|
mShader->setUniform( "width", (float)rect.width() );
|
|
|
|
mShader->unbind();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2008-08-04 15:07:34 +00:00
|
|
|
|
2009-02-06 09:16:30 +00:00
|
|
|
void CylinderEffect::paintCube( int mask, QRegion region, ScreenPaintData& data )
|
2008-08-04 15:07:34 +00:00
|
|
|
{
|
|
|
|
glPushMatrix();
|
2008-08-25 14:12:12 +00:00
|
|
|
QRect rect = effects->clientArea( FullArea, activeScreen, effects->currentDesktop());
|
2008-08-04 15:07:34 +00:00
|
|
|
|
|
|
|
float cubeAngle = (effects->numberOfDesktops() - 2 )/(float)effects->numberOfDesktops() * 180.0f;
|
|
|
|
float radian = (cubeAngle*0.5)*M_PI/180;
|
|
|
|
// height of the triangle compound of one side of the cube and the two bisecting lines
|
|
|
|
float midpoint = rect.width()*0.5*tan(radian);
|
|
|
|
// radius of the circle
|
|
|
|
float radius = (rect.width()*0.5)/cos(radian);
|
|
|
|
glTranslatef( 0.0, 0.0, midpoint - radius );
|
2009-02-06 09:16:30 +00:00
|
|
|
CubeEffect::paintCube( mask, region, data );
|
2008-08-04 15:07:34 +00:00
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
|
2008-07-15 19:21:50 +00:00
|
|
|
void CylinderEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time )
|
|
|
|
{
|
|
|
|
if( activated )
|
|
|
|
{
|
|
|
|
if( cube_painting )
|
|
|
|
{
|
|
|
|
if( w->isOnDesktop( painting_desktop ))
|
|
|
|
{
|
|
|
|
data.quads = data.quads.makeGrid( 40 );
|
2008-08-04 15:07:34 +00:00
|
|
|
QRect rect = effects->clientArea( FullArea, activeScreen, painting_desktop );
|
|
|
|
if( w->x() < rect.width()/2 && w->x() + w->width() > rect.width()/ 2 )
|
|
|
|
data.quads = data.quads.splitAtX( rect.width()/2 - w->x() );
|
2008-07-15 19:21:50 +00:00
|
|
|
w->enablePainting( EffectWindow::PAINT_DISABLED_BY_DESKTOP );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
w->disablePainting( EffectWindow::PAINT_DISABLED_BY_DESKTOP );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
effects->prePaintWindow( w, data, time );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CylinderEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
|
|
|
|
{
|
|
|
|
if( activated && cube_painting )
|
|
|
|
{
|
|
|
|
if( mValid && !mInited )
|
|
|
|
mValid = loadData();
|
|
|
|
bool useShader = mValid;
|
|
|
|
if( useShader )
|
|
|
|
{
|
|
|
|
mShader->bind();
|
|
|
|
mShader->setUniform( "windowWidth", (float)w->width() );
|
|
|
|
mShader->setUniform( "windowHeight", (float)w->height() );
|
|
|
|
mShader->setUniform( "xCoord", (float)w->x() );
|
|
|
|
mShader->setUniform( "cubeAngle", (effects->numberOfDesktops() - 2 )/(float)effects->numberOfDesktops() * 180.0f );
|
|
|
|
data.shader = mShader;
|
|
|
|
}
|
|
|
|
CubeEffect::paintWindow( w, mask, region, data );
|
|
|
|
if( useShader )
|
|
|
|
{
|
|
|
|
mShader->unbind();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
effects->paintWindow( w, mask, region, data );
|
|
|
|
}
|
|
|
|
|
2008-08-04 15:07:34 +00:00
|
|
|
void CylinderEffect::paintCap( float z, float zTexture )
|
|
|
|
{
|
|
|
|
if( ( !paintCaps ) || effects->numberOfDesktops() <= 2 )
|
|
|
|
return;
|
|
|
|
CubeEffect::paintCap( z, zTexture );
|
2009-02-06 09:16:30 +00:00
|
|
|
QRect rect = effects->clientArea( FullArea, activeScreen, effects->currentDesktop() );
|
2008-08-04 15:07:34 +00:00
|
|
|
|
|
|
|
float cubeAngle = (effects->numberOfDesktops() - 2 )/(float)effects->numberOfDesktops() * 180.0f;
|
|
|
|
float radian = (cubeAngle*0.5)*M_PI/180;
|
|
|
|
// height of the triangle compound of one side of the cube and the two bisecting lines
|
|
|
|
float midpoint = rect.width()*0.5*tan(radian);
|
|
|
|
// radius of the circle
|
|
|
|
float radius = (rect.width()*0.5)/cos(radian);
|
|
|
|
|
|
|
|
// paint round part of the cap
|
|
|
|
glPushMatrix();
|
2008-08-25 08:19:39 +00:00
|
|
|
float zTranslate = zPosition + zoom;
|
2008-08-04 15:07:34 +00:00
|
|
|
if( start )
|
|
|
|
zTranslate *= timeLine.value();
|
|
|
|
if( stop )
|
|
|
|
zTranslate *= ( 1.0 - timeLine.value() );
|
|
|
|
glTranslatef( 0.0, 0.0, -zTranslate );
|
|
|
|
float triangleWidth = 40.0;
|
|
|
|
|
|
|
|
for( int i=0; i<effects->numberOfDesktops(); i++ )
|
|
|
|
{
|
|
|
|
glPushMatrix();
|
|
|
|
glTranslatef( rect.width()/2, 0.0, -z );
|
|
|
|
glRotatef( i*(360.0f/effects->numberOfDesktops()), 0.0, 1.0, 0.0 );
|
|
|
|
glTranslatef( -rect.width()/2, 0.0, z );
|
|
|
|
glBegin( GL_TRIANGLE_STRIP );
|
|
|
|
for( int j=0; j<rect.width()/triangleWidth; j++ )
|
|
|
|
{
|
|
|
|
float zValue = 0.0;
|
|
|
|
// distance from midpoint of desktop to x coord
|
|
|
|
// calculation is same as in shader -> see comments
|
|
|
|
float distance = rect.width()*0.5 - (j*triangleWidth);
|
|
|
|
if( (j*triangleWidth) > rect.width()*0.5 )
|
|
|
|
{
|
|
|
|
distance = (j*triangleWidth) - rect.width()*0.5;
|
|
|
|
}
|
|
|
|
// distance in correct format
|
|
|
|
float angle = acos( distance/radius );
|
|
|
|
float h = radius;
|
|
|
|
// if distance == 0 -> angle=90 -> tan(90) singularity
|
|
|
|
if( distance != 0.0 )
|
|
|
|
h = tan( angle ) * distance;
|
|
|
|
zValue = h - midpoint;
|
|
|
|
glVertex3f( j*triangleWidth, 0.0, zValue );
|
|
|
|
glVertex3f( (j+1)*triangleWidth, 0.0, 0.0 );
|
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
|
2008-07-15 19:21:50 +00:00
|
|
|
} // namespace
|