1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
|
/* SUSE KWin window decoration
Copyright (C) 2005 Gerd Fleischer <[email protected]>
Copyright (C) 2005 Adrian Schroeter <[email protected]>
based on the window decoration "Plastik" and "Web":
Copyright (C) 2003 Sandro Giessl <[email protected]>
Copyright (C) 2001 Rik Hemsley (rikkus) <[email protected]>
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; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301 USA.
*/
#include <kdebug.h>
#include <math.h>
#include <tqbitmap.h>
#include <tqcursor.h>
#include <tqimage.h>
#include <tqpainter.h>
#include <tqpixmap.h>
#include <tqtooltip.h>
#include <tqtimer.h>
#include <kpixmap.h>
#include <kpixmapeffect.h>
#include <kdecoration.h>
#include "misc.h"
#include "shadow.h"
#include "SUSE2client.h"
#include "SUSE2button.h"
#include "SUSE2button.moc"
#define PLASTIK_FLAT 0
#define LIPSTIK_FLAT 1
#define PLASTIK_3D 2
#define LIPSTIK_3D 3
#define LIPSTIK_BRIGHT 4
namespace KWinSUSE2
{
SUSE2Button::SUSE2Button(ButtonType type, SUSE2Client *parent, const char *name)
: KCommonDecorationButton(type, parent, name),
m_client(parent),
m_iconType(NumButtonIcons),
hover(false)
{
memset(lipstikCache, 0, sizeof(TQPixmap*)*(8 + 3*(ANIMATIONSTEPS+1))*2); // set elements to 0
setBackgroundMode(NoBackground);
animTmr = new TQTimer(this);
connect(animTmr, SIGNAL(timeout() ), this, SLOT(animate() ) );
animProgress = 0;
}
SUSE2Button::~SUSE2Button()
{
for (uint t = 0; t < (8 + 3*ANIMATIONSTEPS+1); ++t)
for (int i = 0; i < 2; ++i)
delete lipstikCache[t][i];
}
void SUSE2Button::reset(unsigned long changed)
{
if (changed&DecorationReset || changed&ManualReset || changed&SizeChange || changed&StateChange) {
switch (type()) {
case CloseButton:
m_iconType = CloseIcon;
break;
case HelpButton:
m_iconType = HelpIcon;
break;
case MinButton:
m_iconType = MinIcon;
break;
case MaxButton:
if (isOn()) {
m_iconType = MaxRestoreIcon;
} else {
m_iconType = MaxIcon;
}
break;
case OnAllDesktopsButton:
if (isOn()) {
m_iconType = NotOnAllDesktopsIcon;
} else {
m_iconType = OnAllDesktopsIcon;
}
break;
case ShadeButton:
if (isOn()) {
m_iconType = UnShadeIcon;
} else {
m_iconType = ShadeIcon;
}
break;
case AboveButton:
if (isOn()) {
m_iconType = NoKeepAboveIcon;
} else {
m_iconType = KeepAboveIcon;
}
break;
case BelowButton:
if (isOn()) {
m_iconType = NoKeepBelowIcon;
} else {
m_iconType = KeepBelowIcon;
}
break;
default:
m_iconType = NumButtonIcons;
break;
}
for (uint t = 0; t < (8 + 3*(ANIMATIONSTEPS+1)); ++t) {
for (int i = 0; i < 2; ++i) {
if (lipstikCache[t][i]) {
delete lipstikCache[t][i];
lipstikCache[t][i] = 0;
}
}
}
this->update();
}
}
void SUSE2Button::animate()
{
animTmr->stop();
if(hover) {
if(animProgress < ANIMATIONSTEPS) {
if (Handler()->animateButtons() ) {
animProgress++;
} else {
animProgress = ANIMATIONSTEPS;
}
animTmr->start(TIMERINTERVAL, true); // single-shot
}
} else {
if(animProgress > 0) {
if (Handler()->animateButtons() ) {
animProgress--;
} else {
animProgress = 0;
}
animTmr->start(TIMERINTERVAL, true); // single-shot
}
}
repaint(false);
}
void SUSE2Button::enterEvent(TQEvent *e)
{
TQButton::enterEvent(e);
hover = true;
animate();
// repaint(false);
}
void SUSE2Button::leaveEvent(TQEvent *e)
{
TQButton::leaveEvent(e);
hover = false;
animate();
// repaint(false);
}
void SUSE2Button::drawButton(TQPainter *painter)
{
int type = Handler()->buttonType();
switch (type) {
case PLASTIK_FLAT:
case LIPSTIK_FLAT:
case LIPSTIK_BRIGHT:
drawPlastikBtn(painter);
break;
case PLASTIK_3D:
case LIPSTIK_3D:
drawLipstikBtn(painter);
break;
default:
drawPlastikBtn(painter);
break;
}
}
void SUSE2Button::drawPlastikBtn(TQPainter *painter)
{
TQRect r(0, 0, width(), height());
bool active = m_client->isActive();
bool down = isDown();
KPixmap backgroundTile = m_client->getTitleBarTile(active);
KPixmap tempKPixmap;
TQColor highlightColor;
if(type() == CloseButton) {
highlightColor = TQColor(255,64,0);
} else {
highlightColor = TQt::white;
}
TQColor contourTop = alphaBlendColors(Handler()->getColor(TitleGradientFrom, active),
TQt::black, 220);
TQColor contourBottom = alphaBlendColors(Handler()->getColor(TitleGradientTo, active),
TQt::black, 220);
TQColor surfaceTop = alphaBlendColors(Handler()->getColor(TitleGradientFrom, active),
TQt::white, 220);
TQColor surfaceBottom = alphaBlendColors(Handler()->getColor(TitleGradientTo, active),
TQt::white, 220);
if (type() == CloseButton && active && Handler()->redCloseButton()) {
contourTop = TQColor(170,70,70);
contourBottom = TQColor(120,50,50);
surfaceTop = TQColor(255,70,70);
surfaceBottom = TQColor(170,50,50);
highlightColor = TQColor(140,10,10);
} else if (Handler()->customColors()) {
contourTop = alphaBlendColors(Handler()->getColor(BtnBg, active), TQt::black, 185);
contourBottom = alphaBlendColors(Handler()->getColor(BtnBg, active), TQt::black, 135);
surfaceTop = Handler()->getColor(BtnBg, active);
surfaceBottom = alphaBlendColors(Handler()->getColor(BtnBg, active), TQt::black, 185);
}
int highlightAlpha = static_cast<int>(255-((60/static_cast<double>(ANIMATIONSTEPS))*
static_cast<double>(animProgress) ) );
contourTop = alphaBlendColors(contourTop, highlightColor, highlightAlpha );
contourBottom = alphaBlendColors(contourBottom, highlightColor, highlightAlpha);
surfaceTop = alphaBlendColors(surfaceTop, highlightColor, highlightAlpha);
surfaceBottom = alphaBlendColors(surfaceBottom, highlightColor, highlightAlpha);
if (down) {
contourTop = alphaBlendColors(contourTop, TQt::black, 200);
contourBottom = alphaBlendColors(contourBottom, TQt::black, 200);
surfaceTop = alphaBlendColors(surfaceTop, TQt::black, 200);
surfaceBottom = alphaBlendColors(surfaceBottom, TQt::black, 200);
}
KPixmap buffer;
buffer.resize(width(), height());
TQPainter bP(&buffer);
// fill with the titlebar background
bP.drawTiledPixmap(0, 0, width(), width(), backgroundTile, 0, TOPMARGIN);
if (type() == MenuButton) {
KPixmap menuIcon(m_client->icon().pixmap( TQIconSet::Small, TQIconSet::Normal));
if (width() < menuIcon.width() || height() < menuIcon.height() ) {
menuIcon.convertFromImage( menuIcon.convertToImage().smoothScale(width(), height()));
}
double fade = animProgress * 0.09;
KPixmapEffect::fade(menuIcon, fade, TQColor(240, 240, 240));
bP.drawPixmap((width()-menuIcon.width())/2, (height()-menuIcon.height())/2, menuIcon);
} else {
// contour
bP.setPen(contourTop);
bP.drawLine(r.x()+2, r.y(), r.right()-2, r.y() );
bP.drawPoint(r.x()+1, r.y()+1);
bP.drawPoint(r.right()-1, r.y()+1);
bP.setPen(contourBottom);
bP.drawLine(r.x()+2, r.bottom(), r.right()-2, r.bottom() );
bP.drawPoint(r.x()+1, r.bottom()-1);
bP.drawPoint(r.right()-1, r.bottom()-1);
// sides of the contour
tempKPixmap.resize(1, r.height()-2*2);
KPixmapEffect::gradient(tempKPixmap,
contourTop,
contourBottom,
KPixmapEffect::VerticalGradient);
bP.drawPixmap(r.x(), r.y()+2, tempKPixmap);
bP.drawPixmap(r.right(), r.y()+2, tempKPixmap);
// sort of anti-alias for the contour
bP.setPen(alphaBlendColors(Handler()->getColor(TitleGradientFrom, active),
contourTop, 150) );
bP.drawPoint(r.x()+1, r.y());
bP.drawPoint(r.right()-1, r.y());
bP.drawPoint(r.x(), r.y()+1);
bP.drawPoint(r.right(), r.y()+1);
bP.setPen(alphaBlendColors(Handler()->getColor(TitleGradientTo, active),
contourBottom, 150) );
bP.drawPoint(r.x()+1, r.bottom());
bP.drawPoint(r.right()-1, r.bottom());
bP.drawPoint(r.x(), r.bottom()-1);
bP.drawPoint(r.right(), r.bottom()-1);
// surface
// fill top and bottom
if (Handler()->buttonType() == PLASTIK_FLAT) {
bP.setPen(surfaceTop);
bP.drawLine(r.x()+2, r.y()+1, r.right()-2, r.y()+1 );
bP.setPen(surfaceBottom);
bP.drawLine(r.x()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
} else if (Handler()->buttonType() == LIPSTIK_FLAT || down) {
bP.setPen(surfaceBottom);
bP.drawLine(r.x()+2, r.y()+1, r.right()-2, r.y()+1 );
bP.setPen(surfaceTop);
bP.drawLine(r.x()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
} else {
bP.setPen(surfaceBottom.light(117));
bP.drawLine(r.x()+2, r.y()+1, r.right()-2, r.y()+1 );
bP.setPen(surfaceTop.dark(122));
bP.drawLine(r.x()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
}
// fill the rest! :)
tempKPixmap.resize(1, r.height()-2*2);
if (Handler()->buttonType() == PLASTIK_FLAT) {
KPixmapEffect::gradient(tempKPixmap,
surfaceTop,
surfaceBottom,
KPixmapEffect::VerticalGradient);
} else {
KPixmapEffect::gradient(tempKPixmap,
surfaceBottom,
surfaceTop,
KPixmapEffect::VerticalGradient);
}
bP.drawTiledPixmap(r.x()+1, r.y()+2, r.width()-2, r.height()-4, tempKPixmap);
int dX,dY;
KPixmap deco;
int s = lroundf(r.height()*Handler()->iconSize());
if ((s + r.height())%2 != 0) --s;
if (down) {
deco = active ? Handler()->buttonPixmap(m_iconType, s, ActiveDown) : Handler()->buttonPixmap(m_iconType, s, InactiveDown);
} else {
deco = active ? Handler()->buttonPixmap(m_iconType, s, ActiveUp) : Handler()->buttonPixmap(m_iconType, s, InactiveUp);
}
dX = r.x()+(r.width()-deco.width())/2;
dY = r.y()+(r.height()-deco.height())/2;
if (down) {
dY++;
}
if(active && !down &&
(Handler()->useTitleProps() && Handler()->titleShadow() || Handler()->iconShadow())) {
bP.drawPixmap(dX+1, dY+1, Handler()->buttonPixmap(m_iconType, s, Shadow));
}
bP.drawPixmap(dX, dY, deco);
}
bP.end();
painter->drawPixmap(0, 0, buffer);
}
void SUSE2Button::drawLipstikBtn(TQPainter *painter)
{
TQRect r(0, 0, width(), height());
bool active = m_client->isActive();
bool down = isDown();
KPixmap backgroundTile = m_client->getTitleBarTile(active);
KPixmap buffer;
buffer.resize(width(), height());
TQPainter bP(&buffer);
// fill with the titlebar background
bP.drawTiledPixmap(0, 0, width(), width(), backgroundTile, 0, TOPMARGIN);
if (type() == MenuButton)
{
KPixmap menuIcon(m_client->icon().pixmap( TQIconSet::Small, TQIconSet::Normal));
if (width() < menuIcon.width() || height() < menuIcon.height() ) {
menuIcon.convertFromImage( menuIcon.convertToImage().smoothScale(width(), height()));
}
double fade = animProgress * 0.09;
KPixmapEffect::fade(menuIcon, fade, TQColor(240, 240, 240));
bP.drawPixmap((width()-menuIcon.width())/2, (height()-menuIcon.height())/2, menuIcon);
} else {
renderBtnContour(&bP, r);
if (down) {
TQColor downColor;
if (type() == CloseButton && active && Handler()->redCloseButton()) {
downColor = TQColor(220,65,65).dark(115);
} else if (Handler()->customColors()) {
downColor = Handler()->getColor(BtnBg, active).dark(115);
} else {
downColor = alphaBlendColors(Handler()->getColor(TitleGradientFrom, active), TQt::black, 220).dark(115);
}
bP.fillRect(r.left()+1, r.top()+2, r.width()-2, r.height()-4, downColor);
bP.setPen(downColor);
// top line
bP.drawLine(r.left()+2, r.top()+1, r.right()-2, r.top()+1);
// bottom and right lines
bP.setPen(downColor.light(106));
bP.drawLine(r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1);
bP.drawLine(r.right()-1, r.top()+2, r.right()-1, r.bottom()-2);
} else {
renderBtnSurface(&bP, TQRect(r.left()+1, r.top()+1, r.width()-2, r.height()-2));
}
int dX,dY;
KPixmap deco;
int s = lroundf(r.height() * Handler()->iconSize());
if ((s + r.height())%2 != 0) --s;
if (down) {
deco = active ? Handler()->buttonPixmap(m_iconType, s, ActiveDown) : Handler()->buttonPixmap(m_iconType, s, InactiveDown);
} else {
deco = active ? Handler()->buttonPixmap(m_iconType, s, ActiveUp) : Handler()->buttonPixmap(m_iconType, s, InactiveUp);
}
dX = r.x()+(r.width()-deco.width())/2;
dY = r.y()+(r.height()-deco.height())/2;
if (down) {
dY++;
}
if(active && !down &&
(Handler()->useTitleProps() && Handler()->titleShadow() || Handler()->iconShadow())) {
bP.drawPixmap(dX+1, dY+1, Handler()->buttonPixmap(m_iconType, s, Shadow));
}
bP.drawPixmap(dX, dY, deco);
}
bP.end();
painter->drawPixmap(0, 0, buffer);
}
void SUSE2Button::renderBtnContour(TQPainter *p, const TQRect &r)
{
if((r.width() <= 0)||(r.height() <= 0))
return;
bool active = m_client->isActive();
TQColor backgroundColor;
if (type() == CloseButton && active && Handler()->redCloseButton()) {
backgroundColor = TQColor(220,65,65);
} else if (Handler()->customColors()) {
backgroundColor = Handler()->getColor(BtnBg, active);
} else {
backgroundColor = alphaBlendColors(Handler()->getColor(TitleGradientFrom, active), TQt::black, 220);
}
TQColor contourColor = backgroundColor.dark(135);
// sides
p->setPen(contourColor);
p->drawLine(r.left(), r.top()+2, r.left(), r.bottom()-2);
p->drawLine(r.right(), r.top()+2, r.right(), r.bottom()-2);
p->drawLine(r.left()+2, r.top(), r.right()-2, r.top());
p->drawLine(r.left()+2, r.bottom(), r.right()-2, r.bottom());
// edges
const int alphaAA = 110; // the alpha value for anti-aliasing...
// first part...
p->setPen(contourColor);
p->drawPoint(r.left()+1, r.top()+1);
p->drawPoint(r.left()+1, r.bottom()-1);
p->drawPoint(r.right()-1, r.top()+1);
p->drawPoint(r.right()-1, r.bottom()-1);
// second part... fill edges in case we don't paint alpha-blended
p->setPen( backgroundColor );
// third part... anti-aliasing...
int intActive = active ? 0 : 1;
renderPixel(p,TQPoint(r.left()+1,r.top()),alphaAA,contourColor, 0, intActive);
renderPixel(p,TQPoint(r.left(),r.top()+1),alphaAA,contourColor, 1, intActive);
renderPixel(p,TQPoint(r.left()+1,r.bottom()),alphaAA,contourColor, 2, intActive);
renderPixel(p,TQPoint(r.left(),r.bottom()-1),alphaAA,contourColor, 3, intActive);
renderPixel(p,TQPoint(r.right()-1,r.top()),alphaAA,contourColor, 4, intActive);
renderPixel(p,TQPoint(r.right(),r.top()+1),alphaAA,contourColor, 5, intActive);
renderPixel(p,TQPoint(r.right()-1,r.bottom()),alphaAA,contourColor, 6, intActive);
renderPixel(p,TQPoint(r.right(),r.bottom()-1),alphaAA,contourColor, 7, intActive);
}
void SUSE2Button::renderBtnSurface(TQPainter *p, const TQRect &r)
{
if((r.width() <= 0)||(r.height() <= 0))
return;
bool active = m_client->isActive();
TQColor backgroundColor;
if (type() == CloseButton && active && Handler()->redCloseButton()) {
backgroundColor = TQColor(220,65,65);
} else if (Handler()->customColors()) {
backgroundColor = Handler()->getColor(BtnBg, active);
} else {
backgroundColor = Handler()->getColor(TitleGradientFrom, active);
if (!active)
backgroundColor = alphaBlendColors(backgroundColor,
Handler()->getColor(TitleGradientTo, active), 128);
backgroundColor = alphaBlendColors(backgroundColor, TQt::black, 220);
}
TQColor highlightColor;
if(type() == CloseButton) {
highlightColor = TQColor(255,0,0);
} else {
highlightColor = TQt::white;
}
int highlightAlpha = static_cast<int>(255-((60/static_cast<double>(ANIMATIONSTEPS)) *
static_cast<double>(animProgress) ) );
TQColor buttonColor, bottomColor, topLineColor, bottomLineColor;
if (Handler()->buttonType() == LIPSTIK_3D) { // Lipstik
buttonColor = backgroundColor;
bottomColor = buttonColor.light(112);
topLineColor = buttonColor.light(112);
bottomLineColor = buttonColor.dark(102);
} else { // Plastik
bottomColor = backgroundColor;
buttonColor = bottomColor.light(130);
topLineColor = buttonColor.light(108);
bottomLineColor = bottomColor.dark(108);
}
buttonColor = alphaBlendColors(buttonColor, highlightColor, highlightAlpha);
bottomColor = alphaBlendColors(bottomColor, highlightColor, highlightAlpha);
topLineColor = alphaBlendColors(topLineColor, highlightColor, highlightAlpha);
bottomLineColor = alphaBlendColors(bottomLineColor, highlightColor, highlightAlpha);
int intActive = active ? 0 : 1;
// sides,left
int height = r.height() - 2;
renderGradient(p, TQRect(r.left(), r.top()+1, 1, height), bottomColor, buttonColor, 8+animProgress, intActive);
//right
renderGradient(p, TQRect(r.right(), r.top()+1, 1, height), bottomColor, buttonColor, 9+ANIMATIONSTEPS+animProgress, intActive);
//top
p->setPen(topLineColor);
p->drawLine(r.left()+1, r.top(), r.right()-1, r.top() );
//bottom
p->setPen(bottomLineColor);
p->drawLine(r.left()+1, r.bottom(), r.right()-1, r.bottom() );
// button area...
int width = r.width();
height = r.height();
width-=2;
height-=2;
renderGradient(p, TQRect(r.left()+1, r.top()+1, width, height), bottomColor, buttonColor,
10 + 2 * ANIMATIONSTEPS+animProgress, intActive);
}
void SUSE2Button::renderPixel(TQPainter *p, const TQPoint &pos, const int alpha, const TQColor &color,
const int pixelPos, const int active)
{
if (lipstikCache[pixelPos][active]) {
p->drawPixmap(pos, *(lipstikCache[pixelPos][active]));
} else {
TQRgb rgb = color.rgb();
TQImage aImg(1,1,32); // 1x1
aImg.setAlphaBuffer(true);
aImg.setPixel(0,0,tqRgba(tqRed(rgb),tqGreen(rgb),tqBlue(rgb),alpha));
TQPixmap *result = new TQPixmap(aImg);
p->drawPixmap(pos, *result);
// add to the cache...
lipstikCache[pixelPos][active] = result;
}
}
void SUSE2Button::renderGradient(TQPainter *painter, const TQRect &rect, const TQColor &c1, const TQColor &c2,
const int gradient, const int active)
{
if((rect.width() <= 0)||(rect.height() <= 0))
return;
if (lipstikCache[gradient][active]) {
painter->drawTiledPixmap(rect, *(lipstikCache[gradient][active]));
} else {
// there wasn't anything matching in the cache, create the pixmap now...
TQPixmap *result = new TQPixmap(10, rect.height());
TQPainter p(result);
int r_h = result->rect().height();
int r_x, r_y, r_x2, r_y2;
result->rect().coords(&r_x, &r_y, &r_x2, &r_y2);
int rDiff, gDiff, bDiff;
int rc, gc, bc;
register int y;
rDiff = ( c1.red()) - (rc = c2.red());
gDiff = ( c1.green()) - (gc = c2.green());
bDiff = ( c1.blue()) - (bc = c2.blue());
register int rl = rc << 16;
register int gl = gc << 16;
register int bl = bc << 16;
int rdelta = ((1<<16) / r_h) * rDiff;
int gdelta = ((1<<16) / r_h) * gDiff;
int bdelta = ((1<<16) / r_h) * bDiff;
// these for-loops could be merged, but the if's in the inner loop
// would make it slow
for ( y = 0; y < r_h; y++ ) {
rl += rdelta;
gl += gdelta;
bl += bdelta;
p.setPen(TQColor(rl>>16, gl>>16, bl>>16));
p.drawLine(r_x, r_y+y, r_x2, r_y+y);
}
p.end();
// draw the result...
painter->drawTiledPixmap(rect, *result);
// add to the cache...
lipstikCache[gradient][active] = result;
}
}
TQBitmap IconEngine::icon(ButtonIcon icon, int size)
{
TQBitmap bitmap(size,size);
bitmap.fill(TQt::color0);
TQPainter p(&bitmap);
p.setPen(TQt::color1);
TQRect r = bitmap.rect();
// line widths
int lwTitleBar = 1;
if (r.width() > 16) {
lwTitleBar = 4;
} else if (r.width() > 4) {
lwTitleBar = 2;
}
int lwArrow = 1;
if (r.width() > 16) {
lwArrow = 4;
} else if (r.width() > 7) {
lwArrow = 2;
}
switch(icon) {
case CloseIcon:
{
int lineWidth = 1;
if (r.width() > 16) {
lineWidth = 3;
} else if (r.width() > 4) {
lineWidth = 2;
}
drawObject(p, DiagonalLine, r.x(), r.y(), r.width(), lineWidth);
drawObject(p, CrossDiagonalLine, r.x(), r.bottom(), r.width(), lineWidth);
break;
}
case MaxIcon:
{
int lineWidth2 = 1; // frame
if (r.width() > 16) {
lineWidth2 = 2;
} else if (r.width() > 4) {
lineWidth2 = 1;
}
drawObject(p, HorizontalLine, r.x(), r.top(), r.width(), lwTitleBar);
drawObject(p, HorizontalLine, r.x(), r.bottom()-(lineWidth2-1), r.width(), lineWidth2);
drawObject(p, VerticalLine, r.x(), r.top(), r.height(), lineWidth2);
drawObject(p, VerticalLine, r.right()-(lineWidth2-1), r.top(), r.height(), lineWidth2);
break;
}
case MaxRestoreIcon:
{
int lineWidth2 = 1; // frame
if (r.width() > 16) {
lineWidth2 = 2;
} else if (r.width() > 4) {
lineWidth2 = 1;
}
int margin1, margin2;
margin1 = margin2 = lineWidth2 * 2;
if (r.width() < 8)
margin1 = 1;
// background window
drawObject(p, HorizontalLine, r.x()+margin1, r.top(), r.width()-margin1, lineWidth2);
drawObject(p, HorizontalLine, r.right()-margin2, r.bottom()-(lineWidth2 - 1)-margin1, margin2, lineWidth2);
drawObject(p, VerticalLine, r.x()+margin1, r.top(), margin2, lineWidth2);
drawObject(p, VerticalLine, r.right()-(lineWidth2 - 1), r.top(), r.height()-margin1, lineWidth2);
// foreground window
drawObject(p, HorizontalLine, r.x(), r.top()+margin2, r.width()-margin2, lwTitleBar);
drawObject(p, HorizontalLine, r.x(), r.bottom()-(lineWidth2 - 1), r.width()-margin2, lineWidth2);
drawObject(p, VerticalLine, r.x(), r.top()+margin2, r.height(), lineWidth2);
drawObject(p, VerticalLine, r.right()-(lineWidth2 - 1)-margin2, r.top()+margin2, r.height(), lineWidth2);
break;
}
case MinIcon:
{
drawObject(p, HorizontalLine, r.x(), r.bottom()-(lwTitleBar - 1), r.width(), lwTitleBar);
break;
}
case HelpIcon:
{
int center = r.x()+r.width() / 2 - 1;
int side = r.width() / 4;
// paint a question mark... code is quite messy, to be cleaned up later...! :o
if (r.width() > 16) {
int lineWidth = 3;
// top bar
drawObject(p, HorizontalLine, center-side + 3, r.y(), 2 * side - 3 - 1, lineWidth);
// top bar rounding
drawObject(p, CrossDiagonalLine, center - side - 1, r.y() + 5, 6, lineWidth);
drawObject(p, DiagonalLine, center+side-3, r.y(), 5, lineWidth);
// right bar
drawObject(p, VerticalLine, center+side+2-lineWidth, r.y()+3, r.height()-(2*lineWidth+side+2+1), lineWidth);
// bottom bar
drawObject(p, CrossDiagonalLine, center, r.bottom()-2*lineWidth, side+2, lineWidth);
drawObject(p, HorizontalLine, center, r.bottom()-3*lineWidth+2, lineWidth, lineWidth);
// the dot
drawObject(p, HorizontalLine, center, r.bottom()-(lineWidth-1), lineWidth, lineWidth);
} else if (r.width() > 8) {
int lineWidth = 2;
// top bar
drawObject(p, HorizontalLine, center-(side-1), r.y(), 2*side-1, lineWidth);
// top bar rounding
if (r.width() > 9) {
drawObject(p, CrossDiagonalLine, center-side-1, r.y()+3, 3, lineWidth);
} else {
drawObject(p, CrossDiagonalLine, center-side-1, r.y()+2, 3, lineWidth);
}
drawObject(p, DiagonalLine, center+side-1, r.y(), 3, lineWidth);
// right bar
drawObject(p, VerticalLine, center+side+2-lineWidth, r.y()+2, r.height()-(2*lineWidth+side+1), lineWidth);
// bottom bar
drawObject(p, CrossDiagonalLine, center, r.bottom()-2*lineWidth+1, side+2, lineWidth);
// the dot
drawObject(p, HorizontalLine, center, r.bottom()-(lineWidth-1), lineWidth, lineWidth);
} else {
int lineWidth = 1;
// top bar
drawObject(p, HorizontalLine, center-(side-1), r.y(), 2*side, lineWidth);
// top bar rounding
drawObject(p, CrossDiagonalLine, center-side-1, r.y()+1, 2, lineWidth);
// right bar
drawObject(p, VerticalLine, center+side+1, r.y(), r.height()-(side+2+1), lineWidth);
// bottom bar
drawObject(p, CrossDiagonalLine, center, r.bottom()-2, side+2, lineWidth);
// the dot
drawObject(p, HorizontalLine, center, r.bottom(), 1, 1);
}
break;
}
case NotOnAllDesktopsIcon:
{
int lwMark = r.width()-lwTitleBar*2-2;
if (lwMark < 1)
lwMark = 3;
drawObject(p, HorizontalLine, r.x()+(r.width()-lwMark)/2, r.y()+(r.height()-lwMark)/2, lwMark, lwMark);
// Fall through to OnAllDesktopsIcon intended!
}
case OnAllDesktopsIcon:
{
// horizontal bars
drawObject(p, HorizontalLine, r.x()+lwTitleBar, r.y(), r.width()-2*lwTitleBar, lwTitleBar);
drawObject(p, HorizontalLine, r.x()+lwTitleBar, r.bottom()-(lwTitleBar-1), r.width()-2*lwTitleBar, lwTitleBar);
// vertical bars
drawObject(p, VerticalLine, r.x(), r.y()+lwTitleBar, r.height()-2*lwTitleBar, lwTitleBar);
drawObject(p, VerticalLine, r.right()-(lwTitleBar-1), r.y()+lwTitleBar, r.height()-2*lwTitleBar, lwTitleBar);
break;
}
case NoKeepAboveIcon:
{
int center = r.x()+r.width()/2;
// arrow
drawObject(p, CrossDiagonalLine, r.x(), center+2*lwArrow, center-r.x(), lwArrow);
drawObject(p, DiagonalLine, r.x()+center, r.y()+1+2*lwArrow, center-r.x(), lwArrow);
if (lwArrow>1)
drawObject(p, HorizontalLine, center-(lwArrow-2), r.y()+2*lwArrow, (lwArrow-2)*2, lwArrow);
// Fall through to KeepAboveIcon intended!
}
case KeepAboveIcon:
{
int center = r.x()+r.width()/2;
// arrow
drawObject(p, CrossDiagonalLine, r.x(), center, center-r.x(), lwArrow);
drawObject(p, DiagonalLine, r.x()+center, r.y()+1, center-r.x(), lwArrow);
if (lwArrow>1)
drawObject(p, HorizontalLine, center-(lwArrow-2), r.y(), (lwArrow-2)*2, lwArrow);
break;
}
case NoKeepBelowIcon:
{
int center = r.x()+r.width()/2;
// arrow
drawObject(p, DiagonalLine, r.x(), center-2*lwArrow, center-r.x(), lwArrow);
drawObject(p, CrossDiagonalLine, r.x()+center, r.bottom()-1-2*lwArrow, center-r.x(), lwArrow);
if (lwArrow>1)
drawObject(p, HorizontalLine, center-(lwArrow-2), r.bottom()-(lwArrow-1)-2*lwArrow, (lwArrow-2)*2, lwArrow);
// Fall through to KeepBelowIcon intended!
}
case KeepBelowIcon:
{
int center = r.x()+r.width()/2;
// arrow
drawObject(p, DiagonalLine, r.x(), center, center-r.x(), lwArrow);
drawObject(p, CrossDiagonalLine, r.x()+center, r.bottom()-1, center-r.x(), lwArrow);
if (lwArrow>1)
drawObject(p, HorizontalLine, center-(lwArrow-2), r.bottom()-(lwArrow-1), (lwArrow-2)*2, lwArrow);
break;
}
case ShadeIcon:
{
drawObject(p, HorizontalLine, r.x(), r.y(), r.width(), lwTitleBar);
break;
}
case UnShadeIcon:
{
int lw1 = 1;
int lw2 = 1;
if (r.width() > 16) {
lw1 = 4;
lw2 = 2;
} else if (r.width() > 7) {
lw1 = 2;
lw2 = 1;
}
int h = TQMAX( (r.width()/2), (lw1+2*lw2) );
// horizontal bars
drawObject(p, HorizontalLine, r.x(), r.y(), r.width(), lw1);
drawObject(p, HorizontalLine, r.x(), r.x()+h-(lw2-1), r.width(), lw2);
// vertical bars
drawObject(p, VerticalLine, r.x(), r.y(), h, lw2);
drawObject(p, VerticalLine, r.right()-(lw2-1), r.y(), h, lw2);
break;
}
default:
break;
}
p.end();
bitmap.setMask(bitmap);
return bitmap;
}
void IconEngine::drawObject(TQPainter &p, Object object, int x, int y, int length, int lineWidth)
{
switch(object) {
case DiagonalLine:
if (lineWidth <= 1) {
for (int i = 0; i < length; ++i) {
p.drawPoint(x+i,y+i);
}
} else if (lineWidth <= 2) {
for (int i = 0; i < length; ++i) {
p.drawPoint(x+i,y+i);
}
for (int i = 0; i < (length-1); ++i) {
p.drawPoint(x+1+i,y+i);
p.drawPoint(x+i,y+1+i);
}
} else {
for (int i = 1; i < (length-1); ++i) {
p.drawPoint(x+i,y+i);
}
for (int i = 0; i < (length-1); ++i) {
p.drawPoint(x+1+i,y+i);
p.drawPoint(x+i,y+1+i);
}
for (int i = 0; i < (length-2); ++i) {
p.drawPoint(x+2+i,y+i);
p.drawPoint(x+i,y+2+i);
}
}
break;
case CrossDiagonalLine:
if (lineWidth <= 1) {
for (int i = 0; i < length; ++i) {
p.drawPoint(x+i,y-i);
}
} else if (lineWidth <= 2) {
for (int i = 0; i < length; ++i) {
p.drawPoint(x+i,y-i);
}
for (int i = 0; i < (length-1); ++i) {
p.drawPoint(x+1+i,y-i);
p.drawPoint(x+i,y-1-i);
}
} else {
for (int i = 1; i < (length-1); ++i) {
p.drawPoint(x+i,y-i);
}
for (int i = 0; i < (length-1); ++i) {
p.drawPoint(x+1+i,y-i);
p.drawPoint(x+i,y-1-i);
}
for (int i = 0; i < (length-2); ++i) {
p.drawPoint(x+2+i,y-i);
p.drawPoint(x+i,y-2-i);
}
}
break;
case HorizontalLine:
for (int i = 0; i < lineWidth; ++i) {
p.drawLine(x,y+i, x+length-1, y+i);
}
break;
case VerticalLine:
for (int i = 0; i < lineWidth; ++i) {
p.drawLine(x+i,y, x+i, y+length-1);
}
break;
default:
break;
}
}
} // KWinSUSE2
// kate: space-indent on; indent-width 4; replace-tabs on;
|