From 42a4d364c20ab4ed9ff0db0829b492d0581426dc Mon Sep 17 00:00:00 2001 From: Rivo Laks Date: Wed, 4 Jul 2007 20:33:35 +0000 Subject: [PATCH] Add a generic function to render a box with rounded corners. Algorithm is basically same as for shadow, perhaps even shadow will use it. svn path=/trunk/KDE/kdebase/workspace/; revision=683514 --- effects/CMakeLists.txt | 1 + effects/data/circle.png | Bin 0 -> 2730 bytes lib/kwinglutils.cpp | 70 ++++++++++++++++++++++++++++++++++++++++ lib/kwinglutils.h | 7 ++++ 4 files changed, 78 insertions(+) create mode 100644 effects/data/circle.png 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 0000000000000000000000000000000000000000..6df7f991e01c8adf77e4d7d68c29e8161afdbfb4 GIT binary patch literal 2730 zcmV;b3RU%qP)?2qFr&;OY`&6%|noh=KwJbO%`klyz|xQBgV24_?(>-KYCpa&Pp%% zm%JMR(8}?i&c8qZA4B9N@_7J2xMhyxMW%3zcS(I3P*fp+Nl-h#t0Gtkm+3RSN%5kYs58H zZh{rdPmL7t!xJ>Ye>?v)ODtvOfk&jpCZy`b^8ZKYtn8O>^v3e*K7g3z-)ozf-vQ?p z07&uon(AQyD7yh@@BUtkI1WHZF#u9exoLv*Z#C4)f(8UY0Sq7w6o3lQ06M@Bm;wu6 z0~~=H@B)4y7;FSw5Cal{0Azq{unXjY0#FPNf=W;W>OmuD0cSu5I1es^Yv2~R3x>gC zAOw@(C71*6z#;@eScnYKA!$evQiHT1Lx=-eL5`3IBuVNf*0hti;IXg5>C zfWn~YC>BZwWr1=*`J=d~WYl(4A*vE}64j3CMcqS8%>eiFY(pc2>wOM)LEj;{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zs+xov*qeaiOT2(4E`8bTRYd{H3HzvzMbUPxNf+d3+`4%KcuS-hr#`SFc}lx^|_{ zw(sI~%j@TFnBO>elXJ7wee#y;W!; zyfE%C-v4afv&R$MiI;z*{PAfr_c{4_*_7f`M;$3_A0%L2gTHUJfs0H{X+KneW^MYRKB!_A=z0000PdQ@0+VRdw9 zZ*l+tc-jlfEX!B$Nz5(=01!h1O!NHJp#T5?z)3_wR5;76ld%nhFc3w3r%=+60cb*z z378=ZFiaNn0I67j6wVAZ>7a1#tY1W62|Lc0zL4zyzO2J06Os46mQN>cur!Mu5xuur zihwt9FTQLFUgA+~V?_$L;=A}EUi@AQ_B7M(j*N}TA8SIk{w^5Mo+`}_$}*aII8`C9 zEMwX_uqvaV0@E=j-I#m@j!mH$|9Jj^4V)G@T#_{dUcorVts3D}g}kySELcqSEWRGV kPvq@iu5$5XqSEL50Y$<20m!T*5C8xG07*qoM6N<$f~I0WXaE2J literal 0 HcmV?d00001 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: