diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index 069619ee72..b3490ed076 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -92,6 +92,7 @@ if(OPENGL_FOUND) data/sharpen.frag data/sharpen.vert data/shadow-texture.png + data/circle.png DESTINATION ${DATA_INSTALL_DIR}/kwin ) # config modules diff --git a/effects/data/circle.png b/effects/data/circle.png new file mode 100644 index 0000000000..6df7f991e0 Binary files /dev/null and b/effects/data/circle.png differ diff --git a/lib/kwinglutils.cpp b/lib/kwinglutils.cpp index dd63e3681d..c3c4de3265 100644 --- a/lib/kwinglutils.cpp +++ b/lib/kwinglutils.cpp @@ -16,6 +16,7 @@ License. See the file "COPYING" for the exact licensing terms. #include "kwineffects.h" #include "kdebug.h" +#include #include #include @@ -250,6 +251,75 @@ void renderGLGeometryImmediate( int count, const float* vertices, const float* t glEnd(); } +void addQuadVertices(QVector& verts, float x1, float y1, float x2, float y2) +{ + verts << x1 << y1; + verts << x1 << y2; + verts << x2 << y2; + verts << x2 << y1; +} + +void renderRoundBox( const QRect& area, float roundness, GLTexture* texture ) +{ + static GLTexture* circleTexture = 0; + if( !texture && !circleTexture ) + { + QString texturefile = KGlobal::dirs()->findResource("data", "kwin/circle.png"); + circleTexture = new GLTexture(texturefile); + } + if( !texture ) + { + texture = circleTexture; + } + + glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT | GL_TEXTURE_BIT ); + glEnable( GL_BLEND ); + glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); + + glPushMatrix(); + + QVector verts, texcoords; + // center + addQuadVertices(verts, area.left() + roundness, area.top() + roundness, area.right() - roundness, area.bottom() - roundness); + addQuadVertices(texcoords, 0.5, 0.5, 0.5, 0.5); + // sides + // left + addQuadVertices(verts, area.left(), area.top() + roundness, area.left() + roundness, area.bottom() - roundness); + addQuadVertices(texcoords, 0.0, 0.5, 0.5, 0.5); + // top + addQuadVertices(verts, area.left() + roundness, area.top(), area.right() - roundness, area.top() + roundness); + addQuadVertices(texcoords, 0.5, 0.0, 0.5, 0.5); + // right + addQuadVertices(verts, area.right() - roundness, area.top() + roundness, area.right(), area.bottom() - roundness); + addQuadVertices(texcoords, 0.5, 0.5, 1.0, 0.5); + // bottom + addQuadVertices(verts, area.left() + roundness, area.bottom() - roundness, area.right() - roundness, area.bottom()); + addQuadVertices(texcoords, 0.5, 0.5, 0.5, 1.0); + // corners + // top-left + addQuadVertices(verts, area.left(), area.top(), area.left() + roundness, area.top() + roundness); + addQuadVertices(texcoords, 0.0, 0.0, 0.5, 0.5); + // top-right + addQuadVertices(verts, area.right() - roundness, area.top(), area.right(), area.top() + roundness); + addQuadVertices(texcoords, 0.5, 0.0, 1.0, 0.5); + // bottom-left + addQuadVertices(verts, area.left(), area.bottom() - roundness, area.left() + roundness, area.bottom()); + addQuadVertices(texcoords, 0.0, 0.5, 0.5, 1.0); + // bottom-right + addQuadVertices(verts, area.right() - roundness, area.bottom() - roundness, area.right(), area.bottom()); + addQuadVertices(texcoords, 0.5, 0.5, 1.0, 1.0); + + texture->bind(); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + // We have two elements per vertex in the verts array + int verticesCount = verts.count() / 2; + renderGLGeometry( verticesCount, verts.data(), texcoords.data() ); + texture->unbind(); + + glPopMatrix(); + glPopAttrib(); +} + //**************************************** // GLTexture //**************************************** diff --git a/lib/kwinglutils.h b/lib/kwinglutils.h index e3f7a7db7c..c38f64cba6 100644 --- a/lib/kwinglutils.h +++ b/lib/kwinglutils.h @@ -30,6 +30,9 @@ namespace KWin { +class GLTexture; + + // Initializes GLX function pointers void KWIN_EXPORT initGLX(); // Initializes OpenGL stuff. This includes resolving function pointers as @@ -87,6 +90,10 @@ KWIN_EXPORT void renderGLGeometryImmediate( int count, const float* vertices, const float* texture = 0, const float* color = 0, int dim = 2, int stride = 0 ); + +KWIN_EXPORT void renderRoundBox( const QRect& area, float roundness = 10.0f, GLTexture* texture = 0 ); + + class KWIN_EXPORT GLTexture { public: