Start to fix some error
[kdeartwork.git] / kwin-styles / riscos / Static.cpp
blob2e65da685d6b6cbb7511df58e22ea67360ac7eef
1 /*
2 RISC OS KWin client
4 Copyright 2000
5 Rik Hemsley <rik@kde.org>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
23 // for enable-final
24 #ifdef Bool
25 #undef Bool
26 #endif
28 #include <qimage.h>
29 #include <qpixmap.h>
30 #include <qpainter.h>
31 #include <q3ptrlist.h>
32 #include <kcommondecoration.h>
33 #include <kdecoration.h>
35 // #include <ksimpleconfig.h>
37 #include "Static.h"
39 namespace RiscOS
42 /* XPM */
43 static const char * const texture_xpm[] = {
44 "64 12 3 1",
45 " c None",
46 "a c #000000",
47 "b c #FFFFFF",
48 " b b b b b b b a b ",
49 " b aa b aaa aaa b a b aab bb a ",
50 " b b a b b b b aa b b aa ",
51 " b b b a a b b b b aa ab ab ",
52 " b b b b b b b ba ",
53 " aaa aaa aa b b b b b b ",
54 " b b bb a b aa b a a aaa a b ",
55 " b b b b b a b b b b b",
56 " b b b b a a b b aa b baa ",
57 " a b a bb aa bb aa aaa b aa a ",
58 " a a aab b b aa aab a b ",
59 " b a b b aaa a b bb b b b b"};
61 Static* Static::instance_ = NULL;
63 Static::Static()
65 instance_ = this;
66 _init();
69 Static::~Static()
71 instance_ = NULL;
74 const QPixmap& Static::titleTextLeft(bool active) const
76 return active ? aTitleTextLeft_ : iTitleTextLeft_;
79 const QPixmap& Static::titleTextRight(bool active) const
81 return active ? aTitleTextRight_ : iTitleTextRight_;
84 const QPixmap& Static::resizeMidLeft(bool active) const
86 return active ? aResizeMidLeft_ : iResizeMidLeft_;
89 const QPixmap& Static::resizeMidRight(bool active) const
91 return active ? aResizeMidRight_ : iResizeMidRight_;
94 const QPixmap& Static::titleTextMid(bool active) const
96 return active ? aTitleTextMid_ : iTitleTextMid_;
99 const QPixmap& Static::resizeMidMid(bool active) const
101 return active ? aResizeMid_ : iResizeMid_;
104 const QPixmap& Static::resize(bool active) const
106 return active ? aResize_ : iResize_;
109 int Static::animationStyle() const
111 return animationStyle_;
114 int Static::titleHeight() const
116 return titleHeight_;
119 int Static::resizeHeight() const
121 return resizeHeight_;
124 void Static::_drawBorder(QPixmap &pix, int w, int h)
126 // 0111111113
127 // 1122222235
128 // 12 46
129 // 12 46
130 // 12 46
131 // 1344444476
132 // 3566666667
134 painter_.begin(&pix);
135 painter_.translate(transx, transy);
137 QColor c0 = down_ ? palette_[7] : palette_[0];
138 QColor c1 = down_ ? palette_[6] : palette_[1];
139 QColor c2 = down_ ? palette_[5] : palette_[2];
140 QColor c3 = down_ ? palette_[4] : palette_[3];
141 QColor c4 = down_ ? palette_[3] : palette_[4];
142 QColor c5 = down_ ? palette_[2] : palette_[5];
143 QColor c6 = down_ ? palette_[2] : palette_[6];
144 QColor c7 = down_ ? palette_[1] : palette_[7];
146 painter_.setPen(c0);
147 painter_.drawPoint(0, 0);
149 painter_.setPen(c1);
150 painter_.drawPoint(1, 1);
151 painter_.drawLine(1, 0, w - 1, 0);
152 painter_.drawLine(0, 1, 0, h - 1);
154 painter_.setPen(c2);
155 painter_.drawLine(2, 1, w - 2, 1);
156 painter_.drawLine(1, 2, 1, h - 2);
158 painter_.setPen(c3);
159 painter_.drawPoint(0, h);
160 painter_.drawPoint(1, h - 1);
161 painter_.drawPoint(w, 0);
162 painter_.drawPoint(w - 1, 1);
163 painter_.fillRect(2, 2, w - 2, h - 2, c3);
165 painter_.setPen(c4);
166 painter_.drawLine(2, h - 1, w - 2, h - 1);
167 painter_.drawLine(w - 1, 2, w - 1, h - 2);
169 painter_.setPen(c5);
170 painter_.drawPoint(w, 1);
171 painter_.drawPoint(1, h);
173 painter_.setPen(c6);
174 painter_.drawLine(w, 2, w, h - 1);
175 painter_.drawLine(2, h, w - 1, h);
177 painter_.setPen(c7);
178 painter_.drawPoint(w - 1, h - 1);
179 painter_.drawPoint(w, h);
181 painter_.end();
183 painter_.resetXForm();
186 void setPalette(Palette &pal, QColor c)
188 pal[3] = c.rgb();
190 int h, s, v;
191 c.hsv(&h, &s, &v);
193 if (v < 72)
194 c.setHsv(h, s, 72);
196 pal[0] = c.light(200).rgb();
197 pal[1] = c.light(166).rgb();
198 pal[2] = c.light(125).rgb();
199 pal[4] = c.dark(133).rgb();
200 pal[5] = c.dark(166).rgb();
201 pal[6] = c.dark(200).rgb();
202 pal[7] = c.dark(300).rgb();
205 void Static::_init()
207 hicolour_ = QPixmap::defaultDepth() > 8;
208 animationStyle_ = 0;
209 updatePixmaps();
212 void Static::reset()
214 updatePixmaps();
215 // Workspace::self()->slotResetAllClientsDelayed();
218 void Static::updatePixmaps()
220 _initSizes();
222 _resizeAllPixmaps();
224 _blankAllPixmaps();
226 if (hicolour_)
228 _initPalettes();
229 _initTextures();
232 _drawTitleTextAreaSides();
234 _drawResizeCentralAreaSides();
236 _drawTitleTextAreaBackground();
238 _drawResizeCentralAreaBackground();
240 _drawResizeHandles();
242 _drawButtonBackgrounds();
245 void Static::_createTexture(QPixmap &px, int t, bool active)
247 const QImage texture(QPixmap((const char **)texture_xpm).convertToImage());
248 const QRgb w(qRgb(255, 255, 255));
249 const QRgb b(qRgb(0, 0, 0));
251 QColor c(KDecoration::options()->color(KDecoration::ColorType(t), active));
253 QRgb mid (c.rgb());
254 QRgb light (c.light(110).rgb());
255 QRgb dark (c.dark(110).rgb());
257 QRgb* data(reinterpret_cast<QRgb *>(texture.bits()));
259 for (int x = 0; x < 64*12; x++)
260 if (data[x] == w)
261 data[x] = light;
262 else if (data[x] == b)
263 data[x] = dark;
264 else
265 data[x] = mid;
267 px.convertFromImage(texture);
270 const QPixmap& Static::buttonBase(bool active, bool down) const
272 if (active)
273 return down ? aButtonDown_ : aButtonUp_;
274 else
275 return down ? iButtonDown_ : iButtonUp_;
278 void Static::_initSizes()
280 QFont f(KDecoration::options()->font(true)); // XXX false doesn't work right at the moment
282 QFontMetrics fm(f);
284 int h = fm.height();
286 titleHeight_ = h + 6;
288 if (titleHeight_ < 20)
289 titleHeight_ = 20;
291 buttonSize_ = titleHeight_ - 1;
293 resizeHeight_ = 10;
296 void Static::_resizeAllPixmaps()
298 aResize_ .resize(30, resizeHeight_);
299 iResize_ .resize(30, resizeHeight_);
300 aTitleTextLeft_ .resize( 3, titleHeight_);
301 aTitleTextRight_.resize( 3, titleHeight_);
302 iTitleTextLeft_ .resize( 3, titleHeight_);
303 iTitleTextRight_.resize( 3, titleHeight_);
304 aTitleTextMid_ .resize(64, titleHeight_);
305 iTitleTextMid_ .resize(64, titleHeight_);
306 aResizeMidLeft_ .resize( 3, resizeHeight_);
307 aResizeMidRight_.resize( 3, resizeHeight_);
308 iResizeMidLeft_ .resize( 3, resizeHeight_);
309 iResizeMidRight_.resize( 3, resizeHeight_);
310 aResizeMid_ .resize(64, resizeHeight_);
311 iResizeMid_ .resize(64, resizeHeight_);
313 aButtonUp_ .resize(buttonSize_, buttonSize_);
314 iButtonUp_ .resize(buttonSize_, buttonSize_);
315 aButtonDown_ .resize(buttonSize_, buttonSize_);
316 iButtonDown_ .resize(buttonSize_, buttonSize_);
319 void Static::_blankAllPixmaps()
321 aResize_ .fill(Qt::black);
322 iResize_ .fill(Qt::black);
323 aTitleTextLeft_ .fill(Qt::black);
324 aTitleTextRight_.fill(Qt::black);
325 iTitleTextLeft_ .fill(Qt::black);
326 iTitleTextRight_.fill(Qt::black);
327 aTitleTextMid_ .fill(Qt::black);
328 iTitleTextMid_ .fill(Qt::black);
329 aResizeMidLeft_ .fill(Qt::black);
330 aResizeMidRight_.fill(Qt::black);
331 iResizeMidLeft_ .fill(Qt::black);
332 iResizeMidRight_.fill(Qt::black);
333 aResizeMid_ .fill(Qt::black);
334 iResizeMid_ .fill(Qt::black);
335 aButtonUp_ .fill(Qt::black);
336 iButtonUp_ .fill(Qt::black);
337 aButtonDown_ .fill(Qt::black);
338 iButtonDown_ .fill(Qt::black);
341 void Static::_initPalettes()
343 const KDecorationOptions* options = KDecoration::options();
344 setPalette(aButPal_, options->color(KDecoration::ColorButtonBg, true));
345 setPalette(iButPal_, options->color(KDecoration::ColorButtonBg, false));
347 setPalette(aTitlePal_, options->color(KDecoration::ColorTitleBar, true));
348 setPalette(iTitlePal_, options->color(KDecoration::ColorTitleBar, false));
350 setPalette(aResizePal_, options->color(KDecoration::ColorTitleBar, true));
351 setPalette(iResizePal_, options->color(KDecoration::ColorTitleBar, false));
354 void Static::_initTextures()
356 _createTexture(aTexture_, KDecoration::ColorTitleBar, true);
357 _createTexture(iTexture_, KDecoration::ColorTitleBar, false);
358 _createTexture(abTexture_, KDecoration::ColorButtonBg, true);
359 _createTexture(ibTexture_, KDecoration::ColorButtonBg, false);
362 void Static::_drawTitleTextAreaSides()
364 QPixmap temp(4, titleHeight_);
365 temp.fill(Qt::black);
367 transx = transy = 0.0;
369 palette_ = aTitlePal_;
370 down_ = false;
372 _drawBorder(temp, 4, titleHeight_ - 2);
374 painter_.begin(&aTitleTextLeft_);
375 painter_.drawPixmap(1, 1, temp, 0, 1);
376 painter_.end();
378 painter_.begin(&aTitleTextRight_);
379 painter_.drawPixmap(0, 1, temp, 2, 1);
380 painter_.end();
382 palette_ = iTitlePal_;
383 _drawBorder(temp, 4, titleHeight_ - 2);
385 painter_.begin(&iTitleTextLeft_);
386 painter_.drawPixmap(1, 1, temp, 0, 1);
387 painter_.end();
389 painter_.begin(&iTitleTextRight_);
390 painter_.drawPixmap(0, 1, temp, 2, 1);
391 painter_.end();
394 void Static::_drawResizeCentralAreaSides()
396 QPixmap temp(4, resizeHeight_);
397 temp.fill(Qt::black);
399 transy = 1.0;
401 palette_ = aResizePal_;
403 _drawBorder(temp, 4, resizeHeight_ - 3);
405 painter_.begin(&aResizeMidLeft_);
406 painter_.drawPixmap(0, 1, temp, 0, 1);
407 painter_.end();
409 painter_.begin(&aResizeMidRight_);
410 painter_.drawPixmap(0, 1, temp, 2, 1);
411 painter_.end();
413 palette_ = iResizePal_;
414 _drawBorder(temp, 4, resizeHeight_ - 3);
416 painter_.begin(&iResizeMidLeft_);
417 painter_.drawPixmap(0, 1, temp, 0, 1);
418 painter_.end();
420 painter_.begin(&iResizeMidRight_);
421 painter_.drawPixmap(0, 1, temp, 2, 1);
422 painter_.end();
425 void Static::_drawTitleTextAreaBackground()
427 QPixmap temp(70, titleHeight_);
428 temp.fill(Qt::black);
430 transx = transy = 0.0;
432 palette_ = aTitlePal_;
433 _drawBorder(temp, 70, titleHeight_ - 3);
435 painter_.begin(&aTitleTextMid_);
436 painter_.drawPixmap(0, 1, temp, 2, 0);
437 if (hicolour_)
438 painter_.drawTiledPixmap(0, 4, 64, titleHeight_ - 8, aTexture_);
439 painter_.end();
441 palette_ = iTitlePal_;
442 _drawBorder(temp, 70, titleHeight_ - 3);
444 painter_.begin(&iTitleTextMid_);
445 painter_.drawPixmap(0, 1, temp, 2, 0);
446 if (hicolour_)
447 painter_.drawTiledPixmap(0, 4, 64, titleHeight_ - 8, iTexture_);
448 painter_.end();
451 void Static::_drawResizeCentralAreaBackground()
453 QPixmap temp(70, titleHeight_);
454 temp.fill(Qt::black);
456 transy = 1.0;
458 palette_ = aResizePal_;
459 _drawBorder(temp, 70, resizeHeight_ - 3);
461 painter_.begin(&aResizeMid_);
462 painter_.drawPixmap(0, 0, temp, 2, 0);
463 if (hicolour_)
464 painter_.drawTiledPixmap(0, 4, 64, resizeHeight_ - 8, aTexture_);
465 painter_.end();
467 palette_ = iResizePal_;
468 _drawBorder(temp, 70, 7);
470 painter_.begin(&iResizeMid_);
471 painter_.drawPixmap(0, 0, temp, 2, 0);
472 if (hicolour_)
473 painter_.drawTiledPixmap(0, 4, 64, resizeHeight_ - 8, iTexture_);
474 painter_.end();
477 void Static::_drawResizeHandles()
479 transx = transy = 1.0;
481 down_ = false;
483 palette_ = aResizePal_;
484 _drawBorder(aResize_, 28, resizeHeight_ - 3);
486 if (hicolour_)
488 painter_.begin(&aResize_);
489 painter_.drawTiledPixmap(4, 4, 20, resizeHeight_ - 8, aTexture_);
490 painter_.end();
493 palette_ = iResizePal_;
494 _drawBorder(iResize_, 28, resizeHeight_ - 3);
496 if (hicolour_)
498 painter_.begin(&iResize_);
499 painter_.drawTiledPixmap(4, 4, 20, resizeHeight_ - 8, iTexture_);
500 painter_.end();
504 void Static::_drawButtonBackgrounds()
506 buttonSize_ -= 2;
508 down_ = false;
509 transx = 0.0;
510 transy = 1.0;
511 palette_ = aButPal_;
512 _drawBorder(aButtonUp_, buttonSize_, buttonSize_);
513 down_ = true;
514 _drawBorder(aButtonDown_, buttonSize_, buttonSize_);
516 palette_ = iButPal_;
517 _drawBorder(iButtonDown_, buttonSize_, buttonSize_);
518 down_ = false;
519 _drawBorder(iButtonUp_, buttonSize_, buttonSize_);
521 painter_.begin(&aButtonUp_);
523 if (hicolour_)
524 painter_.drawTiledPixmap(2, 4, buttonSize_ - 4, buttonSize_ - 5,
525 abTexture_);
527 painter_.end();
529 painter_.begin(&iButtonUp_);
530 if (hicolour_)
531 painter_.drawTiledPixmap(2, 4, buttonSize_ - 4, buttonSize_ - 5,
532 ibTexture_);
534 painter_.end();
537 } // End namespace
539 // vim:ts=2:sw=2:tw=78