Much, much faster. This used to be mostly KWM's theme code hacked into a KWin

client, which used matrixes and QPainter drawPixmap stuff. Now all that is
gone and it's almost entirely bitBlts.

Still buggy tho, so I'm keeping it disabled for now - but now it's
fast and buggy so I guess that should count for something ;-)

svn path=/trunk/kdebase/kwin/; revision=45235
This commit is contained in:
Daniel M. Duley 2000-03-31 19:10:22 +00:00
parent dde9cbced3
commit 8e6fb39db3
2 changed files with 114 additions and 240 deletions

View file

@ -1,7 +1,6 @@
#include <kconfig.h> #include <kconfig.h>
#include "kwmthemeclient.h" #include "kwmthemeclient.h"
#include <kglobal.h> #include <kglobal.h>
#include <kiconloader.h>
#include <qapplication.h> #include <qapplication.h>
#include <qcursor.h> #include <qcursor.h>
#include <qabstractlayout.h> #include <qabstractlayout.h>
@ -25,6 +24,7 @@ extern "C"
} }
enum FramePixmap{FrameTop=0, FrameBottom, FrameLeft, FrameRight, FrameTopLeft, enum FramePixmap{FrameTop=0, FrameBottom, FrameLeft, FrameRight, FrameTopLeft,
FrameTopRight, FrameBottomLeft, FrameBottomRight}; FrameTopRight, FrameBottomLeft, FrameBottomRight};
@ -51,13 +51,17 @@ static void init_theme()
return; return;
pixmaps_created = true; pixmaps_created = true;
KIconLoader *ldr = KGlobal::iconLoader();
KConfig *config = KGlobal::config(); KConfig *config = KGlobal::config();
config->setGroup("General"); config->setGroup("General");
int i; int i;
QString baseDir="/usr/local/kde2/share/apps/kwin/";
QString localBaseDir="/home/mosfet/.kde/share/apps/kwin/";
for(i=0; i < 8; ++i){ for(i=0; i < 8; ++i){
framePixmaps[i] = new QPixmap(ldr->loadIcon(keys[i])); framePixmaps[i] = new QPixmap(localBaseDir + "/kwmtheme/themepics/" +
config->readEntry(keys[i], " "));
if(framePixmaps[i]->isNull()) if(framePixmaps[i]->isNull())
warning("Unable to load frame pixmap for %s", keys[i]); warning("Unable to load frame pixmap for %s", keys[i]);
else else
@ -71,13 +75,39 @@ static void init_theme()
if(framePixmaps[FrameRight]->width() > maxExtent) if(framePixmaps[FrameRight]->width() > maxExtent)
maxExtent = framePixmaps[FrameRight]->width(); maxExtent = framePixmaps[FrameRight]->width();
menuPix = new QPixmap(ldr->loadIcon("menu")); menuPix = new QPixmap(localBaseDir + "/kwmtheme/themepics/" +
iconifyPix = new QPixmap(ldr->loadIcon("iconify")); config->readEntry("menu", " "));
maxPix = new QPixmap(ldr->loadIcon("maximize")); iconifyPix = new QPixmap(localBaseDir + "/kwmtheme/themepics/" +
minmaxPix = new QPixmap(ldr->loadIcon("maximizedown")); config->readEntry("iconify", " "));
closePix = new QPixmap(ldr->loadIcon("close")); maxPix = new QPixmap(localBaseDir + "/kwmtheme/themepics/" +
pinupPix = new QPixmap(ldr->loadIcon("pinup")); config->readEntry("maximize", " "));
pindownPix = new QPixmap(ldr->loadIcon("pindown")); minmaxPix = new QPixmap(localBaseDir + "/kwmtheme/themepics/" +
config->readEntry("maximizedown", " "));
closePix = new QPixmap(localBaseDir + "/kwmtheme/themepics/" +
config->readEntry("close", " "));
pinupPix = new QPixmap(localBaseDir + "/kwmtheme/themepics/" +
config->readEntry("pinup", " "));
pindownPix = new QPixmap(localBaseDir + "/kwmtheme/themepics/" +
config->readEntry("pindown", " "));
if(menuPix->isNull())
menuPix->load(baseDir + "/kwmtheme/defaultpics/menu.png");
if(iconifyPix->isNull())
iconifyPix->
load(baseDir + "/kwmtheme/defaultpics/iconify.png");
if(maxPix->isNull())
maxPix->
load(baseDir +"/kwmtheme/defaultpics/maximize.png");
if(minmaxPix->isNull())
minmaxPix->
load(baseDir + "/kwmtheme/defaultpics/maximizedown.png");
if(closePix->isNull())
closePix->load(baseDir + "/kwmtheme/defaultpics/close.png");
if(pinupPix->isNull())
pinupPix->load(baseDir + "/kwmtheme/defaultpics/pinup.png");
if(pindownPix->isNull())
pindownPix->
load(baseDir + "/kwmtheme/defaultpics/pindown.png");
QString tmpStr = config->readEntry("TitleAlignment"); QString tmpStr = config->readEntry("TitleAlignment");
if(tmpStr == "right") if(tmpStr == "right")
@ -278,141 +308,51 @@ void KWMThemeClient::captionChange( const QString& )
void KWMThemeClient::paintEvent( QPaintEvent* ) void KWMThemeClient::paintEvent( QPaintEvent* )
{ {
QPainter p; QPainter p;
p.begin(this);
int x,y;
// first the corners // first the corners
int w1 = framePixmaps[FrameTopLeft]->width(); int w1 = framePixmaps[FrameTopLeft]->width();
int h1 = framePixmaps[FrameTopLeft]->height(); int h1 = framePixmaps[FrameTopLeft]->height();
if (w1 > width()/2) w1 = width()/2; if (w1 > width()/2) w1 = width()/2;
if (h1 > height()/2) h1 = height()/2; if (h1 > height()/2) h1 = height()/2;
p.drawPixmap(0,0,*(framePixmaps[FrameTopLeft]), bitBlt(this, 0,0, framePixmaps[FrameTopLeft],
0,0, w1, h1); 0,0, w1, h1);
int w2 = framePixmaps[FrameTopRight]->width(); int w2 = framePixmaps[FrameTopRight]->width();
int h2 = framePixmaps[FrameTopRight]->height(); int h2 = framePixmaps[FrameTopRight]->height();
if (w2 > width()/2) w2 = width()/2; if (w2 > width()/2) w2 = width()/2;
if (h2 > height()/2) h2 = height()/2; if (h2 > height()/2) h2 = height()/2;
p.drawPixmap(width()-w2,0,*(framePixmaps[FrameTopRight]), bitBlt(this, width()-w2,0, framePixmaps[FrameTopRight],
framePixmaps[FrameTopRight]->width()-w2,0,w2, h2); framePixmaps[FrameTopRight]->width()-w2,0,w2, h2);
int w3 = framePixmaps[FrameBottomLeft]->width(); int w3 = framePixmaps[FrameBottomLeft]->width();
int h3 = framePixmaps[FrameBottomLeft]->height(); int h3 = framePixmaps[FrameBottomLeft]->height();
if (w3 > width()/2) w3 = width()/2; if (w3 > width()/2) w3 = width()/2;
if (h3 > height()/2) h3 = height()/2; if (h3 > height()/2) h3 = height()/2;
p.drawPixmap(0,height()-h3,*(framePixmaps[FrameBottomLeft]), bitBlt(this, 0,height()-h3, framePixmaps[FrameBottomLeft],
0,framePixmaps[FrameBottomLeft]->height()-h3,w3, h3); 0,framePixmaps[FrameBottomLeft]->height()-h3,w3, h3);
int w4 = framePixmaps[FrameBottomRight]->width(); int w4 = framePixmaps[FrameBottomRight]->width();
int h4 = framePixmaps[FrameBottomRight]->height(); int h4 = framePixmaps[FrameBottomRight]->height();
if (w4 > width()/2) w4 = width()/2; if (w4 > width()/2) w4 = width()/2;
if (h4 > height()/2) h4 = height()/2; if (h4 > height()/2) h4 = height()/2;
p.drawPixmap(width()-w4,height()-h4,*(framePixmaps[FrameBottomRight]), bitBlt(this, width()-w4,height()-h4, framePixmaps[FrameBottomRight],
framePixmaps[FrameBottomRight]->width()-w4, framePixmaps[FrameBottomRight]->width()-w4,
framePixmaps[FrameBottomRight]->height()-h4, framePixmaps[FrameBottomRight]->height()-h4,
w4, h4); w4, h4);
QPixmap pm; QPixmap *curPix = framePixmaps[FrameTop];
QWMatrix m; tileHoriz(this, curPix, w1, maxExtent-curPix->height()-1, width()-w2-w1);
int n,s,w;
//top
pm = *(framePixmaps[FrameTop]);
s = width()-w2-w1;
n = s/pm.width(); curPix = framePixmaps[FrameBottom];
w = n>0?s/n:s; tileHoriz(this, curPix, w3, height()-maxExtent+1, width()-w3-w4);
m.reset();
m.scale(w/(float)pm.width(), 1);
pm = pm.xForm(m);
x = w1; curPix = framePixmaps[FrameLeft];
while (1){ tileVert(this, curPix, maxExtent-curPix->width()-1, h1, height()-h1-h3);
if (pm.width() < width()-w2-x){
p.drawPixmap(x,maxExtent-pm.height()-1, curPix = framePixmaps[FrameRight];
pm); tileVert(this, curPix, width()-maxExtent+1, h2, height()-h2-h4);
x += pm.width();
}
else {
p.drawPixmap(x,maxExtent-pm.height()-1,
pm,
0,0,width()-w2-x,pm.height());
break;
}
}
//bottom p.begin(this);
pm = *(framePixmaps[FrameBottom]);
s = width()-w4-w3;
n = s/pm.width();
w = n>0 ? s/n : s;
m.reset();
m.scale(w/(float)pm.width(), 1);
pm = pm.xForm(m);
x = w3;
while (1){
if (pm.width() < width()-w4-x){
p.drawPixmap(x,height()-maxExtent+1,pm);
x += pm.width();
}
else {
p.drawPixmap(x,height()-maxExtent+1,pm,
0,0,width()-w4-x,pm.height());
break;
}
}
//left
pm = *(framePixmaps[FrameLeft]);
s = height()-h3-h1;
n = s/pm.height();
w = n>0 ? s/n : s;
m.reset();
m.scale(1, w/(float)pm.height());
pm = pm.xForm(m);
y = h1;
while (1){
if (pm.height() < height()-h3-y){
p.drawPixmap(maxExtent-pm.width()-1, y,
pm);
y += pm.height();
}
else {
p.drawPixmap(maxExtent-pm.width()-1, y,
pm,
0,0, pm.width(),
height()-h3-y);
break;
}
}
//right
pm = *(framePixmaps[FrameRight]);
s = height()-h4-h2;
n = s/pm.height();
w = n>0 ? s/n : s;
m.reset();
m.scale(1, w/(float)pm.height());
pm = pm.xForm(m);
y = h2;
while (1){
if (pm.height() < height()-h4-y){
p.drawPixmap(width()-maxExtent+1, y,
pm);
y += pm.height();
}
else {
p.drawPixmap(width()-maxExtent+1, y,
pm,
0,0, pm.width(),
height()-h4-y);
break;
}
}
drawTitle(p); drawTitle(p);
p.end(); p.end();
} }
@ -422,147 +362,54 @@ void KWMThemeClient::doShape()
QBitmap mask(width(), height()); QBitmap mask(width(), height());
mask.fill(color0); mask.fill(color0);
QPainter p; QPainter p;
p.begin(&mask);
p.setBrush(color1);
p.setPen(color1);
int x,y;
// first the corners // first the corners
int w1 = framePixmaps[FrameTopLeft]->width(); int w1 = framePixmaps[FrameTopLeft]->width();
int h1 = framePixmaps[FrameTopLeft]->height(); int h1 = framePixmaps[FrameTopLeft]->height();
if (w1 > width()/2) w1 = width()/2; if (w1 > width()/2) w1 = width()/2;
if (h1 > height()/2) h1 = height()/2; if (h1 > height()/2) h1 = height()/2;
p.drawPixmap(0,0,*(framePixmaps[FrameTopLeft]->mask()), bitBlt(&mask, 0,0,framePixmaps[FrameTopLeft]->mask(),
0,0,w1, h1); 0,0,w1, h1);
int w2 = framePixmaps[FrameTopRight]->width(); int w2 = framePixmaps[FrameTopRight]->width();
int h2 = framePixmaps[FrameTopRight]->height(); int h2 = framePixmaps[FrameTopRight]->height();
if (w2 > width()/2) w2 = width()/2; if (w2 > width()/2) w2 = width()/2;
if (h2 > height()/2) h2 = height()/2; if (h2 > height()/2) h2 = height()/2;
p.drawPixmap(width()-w2,0,*(framePixmaps[FrameTopRight]->mask()), bitBlt(&mask, width()-w2,0,framePixmaps[FrameTopRight]->mask(),
framePixmaps[FrameTopRight]->width()-w2,0,w2, h2); framePixmaps[FrameTopRight]->width()-w2,0,w2, h2);
int w3 = framePixmaps[FrameBottomLeft]->width(); int w3 = framePixmaps[FrameBottomLeft]->width();
int h3 = framePixmaps[FrameBottomLeft]->height(); int h3 = framePixmaps[FrameBottomLeft]->height();
if (w3 > width()/2) w3 = width()/2; if (w3 > width()/2) w3 = width()/2;
if (h3 > height()/2) h3 = height()/2; if (h3 > height()/2) h3 = height()/2;
p.drawPixmap(0,height()-h3,*(framePixmaps[FrameBottomLeft]->mask()), bitBlt(&mask, 0,height()-h3,framePixmaps[FrameBottomLeft]->mask(),
0, framePixmaps[FrameBottomLeft]->height()-h3,w3, h3); 0, framePixmaps[FrameBottomLeft]->height()-h3,w3, h3);
int w4 = framePixmaps[FrameBottomRight]->width(); int w4 = framePixmaps[FrameBottomRight]->width();
int h4 = framePixmaps[FrameBottomRight]->height(); int h4 = framePixmaps[FrameBottomRight]->height();
if (w4 > width()/2) w4 = width()/2; if (w4 > width()/2) w4 = width()/2;
if (h4 > height()/2) h4 = height()/2; if (h4 > height()/2) h4 = height()/2;
p.drawPixmap(width()-w4,height()-h4,*(framePixmaps[FrameBottomRight]->mask()), bitBlt(&mask, width()-w4,height()-h4,framePixmaps[FrameBottomRight]->mask(),
framePixmaps[FrameBottomRight]->width()-w4, framePixmaps[FrameBottomRight]->width()-w4,
framePixmaps[FrameBottomRight]->height()-h4, framePixmaps[FrameBottomRight]->height()-h4,
w4, h4); w4, h4);
const QBitmap *curPix = framePixmaps[FrameTop]->mask();
tileHoriz(&mask, curPix, w1, maxExtent-curPix->height()-1, width()-w2-w1);
curPix = framePixmaps[FrameBottom]->mask();
tileHoriz(&mask, curPix, w3, height()-maxExtent+1, width()-w3-w4);
QPixmap pm; curPix = framePixmaps[FrameLeft]->mask();
QWMatrix m; tileVert(&mask, curPix, maxExtent-curPix->width()-1, h1, height()-h1-h3);
int n,s,w;
//top curPix = framePixmaps[FrameRight]->mask();
pm = *(framePixmaps[FrameTop]->mask()); tileVert(&mask, curPix, width()-maxExtent+1, h2, height()-h2-h4);
s = width()-w2-w1;
n = s/pm.width();
w = n>0?s/n:s;
m.reset();
m.scale(w/(float)pm.width(), 1);
pm = pm.xForm(m);
x = w1;
while (1){
if (pm.width() < width()-w2-x){
p.drawPixmap(x,maxExtent-pm.height()-1,
pm);
x += pm.width();
}
else {
p.drawPixmap(x,maxExtent-pm.height()-1,
pm,
0,0,width()-w2-x,pm.height());
break;
}
}
//bottom
pm = *(framePixmaps[FrameBottom]->mask());
s = width()-w4-w3;
n = s/pm.width();
w = n>0?s/n:s;
m.reset();
m.scale(w/(float)pm.width(), 1);
pm = pm.xForm(m);
x = w3;
while (1){
if (pm.width() < width()-w4-x){
p.drawPixmap(x,height()-maxExtent+1,pm);
x += pm.width();
}
else {
p.drawPixmap(x,height()-maxExtent+1,pm,
0,0,width()-w4-x,pm.height());
break;
}
}
//left
pm = *(framePixmaps[FrameLeft]->mask());
s = height()-h3-h1;
n = s/pm.height();
w = n>0?s/n:s;
m.reset();
m.scale(1, w/(float)pm.height());
pm = pm.xForm(m);
y = h1;
while (1){
if (pm.height() < height()-h3-y){
p.drawPixmap(maxExtent-pm.width()-1, y,
pm);
y += pm.height();
}
else {
p.drawPixmap(maxExtent-pm.width()-1, y,
pm,
0,0, pm.width(),
height()-h3-y);
break;
}
}
//right
pm = *(framePixmaps[FrameRight]->mask());
s = height()-h4-h2;
n = s/pm.height();
w = n>0?s/n:s;
m.reset();
m.scale(1, w/(float)pm.height());
pm = pm.xForm(m);
y = h2;
while (1){
if (pm.height() < height()-h4-y){
p.drawPixmap(width()-maxExtent+1, y,
pm);
y += pm.height();
}
else {
p.drawPixmap(width()-maxExtent+1, y,
pm,
0,0, pm.width(),
height()-h4-y);
break;
}
}
p.fillRect(maxExtent-1, maxExtent-1, width()-2*maxExtent+2, height()-2*maxExtent+2, color1);
p.begin(&mask);
p.setBrush(color1);
p.setPen(color1);
p.fillRect(maxExtent-1, maxExtent-1, width()-2*maxExtent+2,
height()-2*maxExtent+2, color1);
p.end(); p.end();
setMask(mask); setMask(mask);
} }

View file

@ -13,7 +13,7 @@ class MyButton : public QToolButton
{ {
public: public:
MyButton(QWidget *parent=0, const char *name=0) MyButton(QWidget *parent=0, const char *name=0)
: QToolButton(parent, name){;} : QToolButton(parent, name){setAutoRaise(true);}
protected: protected:
void drawButtonLabel(QPainter *p); void drawButtonLabel(QPainter *p);
}; };
@ -37,11 +37,38 @@ protected:
void stickyChange(bool on); void stickyChange(bool on);
void maximizeChange(bool m); void maximizeChange(bool m);
private: private:
inline void tileHoriz(QPaintDevice *dest, const QPixmap *src,
int x, int y, int w);
inline void tileVert(QPaintDevice *dest, const QPixmap *src,
int x, int y, int h);
KPixmap *aGradient, *iGradient; KPixmap *aGradient, *iGradient;
MyButton *maxBtn, *stickyBtn; MyButton *maxBtn, *stickyBtn;
QSpacerItem *titlebar; QSpacerItem *titlebar;
}; };
inline void KWMThemeClient::tileHoriz(QPaintDevice *dest, const QPixmap *src,
int x, int y, int w)
{
int cx;
for(cx = x; cx < x+w; cx+=src->width()){
bitBlt(dest, cx, y, src, 0, 0, cx+src->width() <= x+w ? src->width() :
(x+w)-cx);
}
}
inline void KWMThemeClient::tileVert(QPaintDevice *dest, const QPixmap *src,
int x, int y, int h)
{
int cy;
for(cy = y; cy < y+h; cy+=src->height()){
bitBlt(dest, x, cy, src, 0, 0, src->width(),
cy+src->height() <= y+h ? src->height() :
(y+h)-cy);
}
}
#endif #endif