-
Notifications
You must be signed in to change notification settings - Fork 3
/
MacDecorator.cpp
945 lines (751 loc) · 22.3 KB
/
MacDecorator.cpp
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
/*
* Copyright 2009-2013 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* DarkWyrm, [email protected]
* Adrien Destugues, [email protected]
* John Scipione, [email protected]
*/
/*! Decorator resembling Mac OS 8 and 9 */
#include "MacDecorator.h"
#include <new>
#include <stdio.h>
#include <GradientLinear.h>
#include <Point.h>
#include <View.h>
#include "DesktopSettings.h"
#include "DrawingEngine.h"
#include "PatternHandler.h"
#include "RGBColor.h"
//#define DEBUG_DECORATOR
#ifdef DEBUG_DECORATOR
# define STRACE(x) printf x
#else
# define STRACE(x) ;
#endif
MacDecorAddOn::MacDecorAddOn(image_id id, const char* name)
:
DecorAddOn(id, name)
{
}
Decorator*
MacDecorAddOn::_AllocateDecorator(DesktopSettings& settings, BRect rect,
Desktop* desktop)
{
return new (std::nothrow)MacDecorator(settings, rect, desktop);
}
MacDecorator::MacDecorator(DesktopSettings& settings, BRect frame,
Desktop* desktop)
:
SATDecorator(settings, frame, desktop),
fButtonHighColor((rgb_color) { 232, 232, 232, 255 }),
fButtonLowColor((rgb_color) { 128, 128, 128, 255 }),
fFrameHighColor((rgb_color) { 255, 255, 255, 255 }),
fFrameMidColor((rgb_color) { 216, 216, 216, 255 }),
fFrameLowColor((rgb_color) { 156, 156, 156, 255 }),
fFrameLowerColor((rgb_color) { 0, 0, 0, 255 }),
fFocusTextColor(settings.UIColor(B_WINDOW_TEXT_COLOR)),
fNonFocusTextColor(settings.UIColor(B_WINDOW_INACTIVE_TEXT_COLOR))
{
STRACE(("MacDecorator()\n"));
STRACE(("\tFrame (%.1f,%.1f,%.1f,%.1f)\n",
frame.left, frame.top, frame.right, frame.bottom));
}
MacDecorator::~MacDecorator()
{
STRACE(("~MacDecorator()\n"));
}
// TODO : Add GetSettings
void
MacDecorator::Draw(BRect updateRect)
{
STRACE(("MacDecorator: Draw(BRect updateRect): "));
updateRect.PrintToStream();
// We need to draw a few things: the tab, the borders,
// and the buttons
fDrawingEngine->SetDrawState(&fDrawState);
_DrawFrame(updateRect & fBorderRect);
_DrawTabs(updateRect & fTitleBarRect);
}
void
MacDecorator::Draw()
{
STRACE("MacDecorator::Draw()\n");
fDrawingEngine->SetDrawState(&fDrawState);
_DrawFrame(fBorderRect);
_DrawTabs(fTitleBarRect);
}
// TODO : add GetSizeLimits
Decorator::Region
MacDecorator::RegionAt(BPoint where, int32& tab) const
{
// Let the base class version identify hits of the buttons and the tab.
Region region = Decorator::RegionAt(where, tab);
if (region != REGION_NONE)
return region;
// check the resize corner
if (fTopTab->look == B_DOCUMENT_WINDOW_LOOK && fResizeRect.Contains(where))
return REGION_RIGHT_BOTTOM_CORNER;
// hit-test the borders
if (!(fTopTab->flags & B_NOT_RESIZABLE)
&& (fTopTab->look == B_TITLED_WINDOW_LOOK
|| fTopTab->look == B_FLOATING_WINDOW_LOOK
|| fTopTab->look == B_MODAL_WINDOW_LOOK)
&& fBorderRect.Contains(where) && !fFrame.Contains(where)) {
return REGION_BOTTOM_BORDER;
// TODO: Determine the actual border!
}
return REGION_NONE;
}
bool
MacDecorator::SetRegionHighlight(Region region, uint8 highlight,
BRegion* dirty, int32 tabIndex)
{
Decorator::Tab* tab
= static_cast<Decorator::Tab*>(_TabAt(tabIndex));
if (tab != NULL) {
tab->isHighlighted = highlight != 0;
// Invalidate the bitmap caches for the close/minimize/zoom button
// when the highlight changes.
switch (region) {
case REGION_CLOSE_BUTTON:
if (highlight != RegionHighlight(region))
memset(&tab->closeBitmaps, 0, sizeof(tab->closeBitmaps));
break;
case REGION_MINIMIZE_BUTTON:
if (highlight != RegionHighlight(region)) {
memset(&tab->minimizeBitmaps, 0,
sizeof(tab->minimizeBitmaps));
}
break;
case REGION_ZOOM_BUTTON:
if (highlight != RegionHighlight(region))
memset(&tab->zoomBitmaps, 0, sizeof(tab->zoomBitmaps));
break;
default:
break;
}
}
return Decorator::SetRegionHighlight(region, highlight, dirty, tabIndex);
}
void
MacDecorator::_DoLayout()
{
STRACE(("MacDecorator: Do Layout\n"));
// Here we determine the size of every rectangle that we use
// internally when we are given the size of the client rectangle.
const int32 kDefaultBorderWidth = 6;
bool hasTab = false;
if (fTopTab) {
switch (fTopTab->look) {
case B_MODAL_WINDOW_LOOK:
fBorderWidth = kDefaultBorderWidth;
break;
case B_TITLED_WINDOW_LOOK:
case B_DOCUMENT_WINDOW_LOOK:
hasTab = true;
fBorderWidth = kDefaultBorderWidth;
break;
case B_FLOATING_WINDOW_LOOK:
hasTab = true;
fBorderWidth = 3;
break;
case B_BORDERED_WINDOW_LOOK:
fBorderWidth = 1;
break;
default:
fBorderWidth = 0;
}
} else
fBorderWidth = 0;
fBorderRect = fFrame.InsetByCopy(-fBorderWidth, -fBorderWidth);
// calculate our tab rect
if (hasTab) {
fBorderRect.top += 3;
font_height fontHeight;
fDrawState.Font().GetHeight(fontHeight);
// TODO the tab is drawn in a fixed height for now
fTitleBarRect.Set(fFrame.left - fBorderWidth,
fFrame.top - 22,
((fFrame.right - fFrame.left) < 32.0 ?
fFrame.left + 32.0 : fFrame.right) + fBorderWidth,
fFrame.top - 3);
for (int32 i = 0; i < fTabList.CountItems(); i++) {
Decorator::Tab* tab = fTabList.ItemAt(i);
tab->tabRect = fTitleBarRect;
// TODO actually handle multiple tabs
tab->zoomRect = fTitleBarRect;
tab->zoomRect.left = tab->zoomRect.right - 12;
tab->zoomRect.bottom = tab->zoomRect.top + 12;
tab->zoomRect.OffsetBy(-4, 4);
tab->closeRect = tab->zoomRect;
tab->minimizeRect = tab->zoomRect;
tab->closeRect.OffsetTo(fTitleBarRect.left + 4,
fTitleBarRect.top + 4);
tab->zoomRect.OffsetBy(0 - (tab->zoomRect.Width() + 4), 0);
if (Title(tab) != NULL && fDrawingEngine != NULL) {
tab->truncatedTitle = Title(tab);
fDrawingEngine->SetFont(fDrawState.Font());
tab->truncatedTitleLength
= (int32)fDrawingEngine->StringWidth(Title(tab),
strlen(Title(tab)));
if (tab->truncatedTitleLength < (tab->zoomRect.left
- tab->closeRect.right - 10)) {
// start with offset from closerect.right
tab->textOffset = int(((tab->zoomRect.left - 5)
- (tab->closeRect.right + 5)) / 2);
tab->textOffset -= int(tab->truncatedTitleLength / 2);
// now make it the offset from fTabRect.left
tab->textOffset += int(tab->closeRect.right + 5
- fTitleBarRect.left);
} else
tab->textOffset = int(tab->closeRect.right) + 5;
} else
tab->textOffset = 0;
}
} else {
for (int32 i = 0; i < fTabList.CountItems(); i++) {
Decorator::Tab* tab = fTabList.ItemAt(i);
tab->tabRect.Set(0.0, 0.0, -1.0, -1.0);
tab->closeRect.Set(0.0, 0.0, -1.0, -1.0);
tab->zoomRect.Set(0.0, 0.0, -1.0, -1.0);
tab->minimizeRect.Set(0.0, 0.0, -1.0, -1.0);
}
}
}
void
MacDecorator::_DrawFrame(BRect invalid)
{
if (fTopTab->look == B_NO_BORDER_WINDOW_LOOK)
return;
if (fBorderWidth <= 0)
return;
BRect r = fBorderRect;
switch (fTopTab->look) {
case B_TITLED_WINDOW_LOOK:
case B_DOCUMENT_WINDOW_LOOK:
case B_MODAL_WINDOW_LOOK:
{
if (IsFocus(fTopTab)) {
BPoint offset = r.LeftTop();
BPoint pt2 = r.LeftBottom();
// Draw the left side of the frame
fDrawingEngine->StrokeLine(offset, pt2, fFrameLowerColor);
offset.x++;
pt2.x++;
pt2.y--;
fDrawingEngine->StrokeLine(offset, pt2, fFrameHighColor);
offset.x++;
pt2.x++;
pt2.y--;
fDrawingEngine->StrokeLine(offset, pt2, fFrameMidColor);
offset.x++;
pt2.x++;
fDrawingEngine->StrokeLine(offset, pt2, fFrameMidColor);
offset.x++;
pt2.x++;
pt2.y--;
fDrawingEngine->StrokeLine(offset, pt2, fFrameLowColor);
offset.x++;
offset.y += 2;
BPoint topleftpt = offset;
pt2.x++;
pt2.y--;
fDrawingEngine->StrokeLine(offset, pt2, fFrameLowerColor);
offset = r.RightTop();
pt2 = r.RightBottom();
// Draw the right side of the frame
fDrawingEngine->StrokeLine(offset, pt2, fFrameLowerColor);
offset.x--;
pt2.x--;
fDrawingEngine->StrokeLine(offset, pt2, fFrameLowColor);
offset.x--;
pt2.x--;
fDrawingEngine->StrokeLine(offset, pt2, fFrameMidColor);
offset.x--;
pt2.x--;
fDrawingEngine->StrokeLine(offset, pt2, fFrameMidColor);
offset.x--;
pt2.x--;
fDrawingEngine->StrokeLine(offset, pt2, fFrameHighColor);
offset.x--;
offset.y += 2;
BPoint toprightpt = offset;
pt2.x--;
fDrawingEngine->StrokeLine(offset, pt2, fFrameLowerColor);
// Draw the top side of the frame that is not in the tab
if (fTopTab->look == B_MODAL_WINDOW_LOOK) {
offset = r.LeftTop();
pt2 = r.RightTop();
fDrawingEngine->StrokeLine(offset, pt2, fFrameLowerColor);
offset.x++;
offset.y++;
pt2.x--;
pt2.y++;
fDrawingEngine->StrokeLine(offset, pt2, fFrameHighColor);
offset.x++;
offset.y++;
pt2.x--;
pt2.y++;
fDrawingEngine->StrokeLine(offset, pt2, fFrameMidColor);
offset.x++;
offset.y++;
pt2.x--;
pt2.y++;
fDrawingEngine->StrokeLine(offset, pt2, fFrameMidColor);
offset.x++;
offset.y++;
pt2.x--;
pt2.y++;
fDrawingEngine->StrokeLine(offset, pt2, fFrameLowColor);
offset.x++;
offset.y++;
pt2.x--;
pt2.y++;
fDrawingEngine->StrokeLine(offset, pt2, fFrameLowerColor);
} else {
// Some odd stuff here where the title bar is melded into the
// window border so that the sides are drawn into the title
// so we draw this bottom up
offset = topleftpt;
pt2 = toprightpt;
fDrawingEngine->StrokeLine(offset, pt2, fFrameLowerColor);
offset.y--;
offset.x++;
pt2.y--;
fDrawingEngine->StrokeLine(offset, pt2, fFrameLowColor);
}
// Draw the bottom side of the frame
offset = r.LeftBottom();
pt2 = r.RightBottom();
fDrawingEngine->StrokeLine(offset, pt2, fFrameLowerColor);
offset.x++;
offset.y--;
pt2.x--;
pt2.y--;
fDrawingEngine->StrokeLine(offset, pt2, fFrameLowColor);
offset.x++;
offset.y--;
pt2.x--;
pt2.y--;
fDrawingEngine->StrokeLine(offset, pt2, fFrameMidColor);
offset.x++;
offset.y--;
pt2.x--;
pt2.y--;
fDrawingEngine->StrokeLine(offset, pt2, fFrameMidColor);
offset.x++;
offset.y--;
pt2.x--;
pt2.y--;
fDrawingEngine->StrokeLine(offset, pt2, fFrameHighColor);
offset.x += 2;
offset.y--;
pt2.x--;
pt2.y--;
fDrawingEngine->StrokeLine(offset, pt2, fFrameLowerColor);
offset.y--;
pt2.x--;
pt2.y--;
} else {
r.top -= 3;
RGBColor inactive(82, 82, 82);
fDrawingEngine->StrokeLine(r.LeftTop(), r.LeftBottom(),
inactive);
fDrawingEngine->StrokeLine(r.RightTop(), r.RightBottom(),
inactive);
fDrawingEngine->StrokeLine(r.LeftBottom(), r.RightBottom(),
inactive);
for (int i = 0; i < 4; i++) {
r.InsetBy(1, 1);
fDrawingEngine->StrokeLine(r.LeftTop(), r.LeftBottom(),
fFrameMidColor);
fDrawingEngine->StrokeLine(r.RightTop(), r.RightBottom(),
fFrameMidColor);
fDrawingEngine->StrokeLine(r.LeftBottom(), r.RightBottom(),
fFrameMidColor);
fDrawingEngine->StrokeLine(r.LeftTop(), r.RightTop(),
fFrameMidColor);
}
r.InsetBy(1, 1);
fDrawingEngine->StrokeLine(r.LeftTop(), r.LeftBottom(),
inactive);
fDrawingEngine->StrokeLine(r.RightTop(), r.RightBottom(),
inactive);
fDrawingEngine->StrokeLine(r.LeftBottom(), r.RightBottom(),
inactive);
fDrawingEngine->StrokeLine(r.LeftTop(), r.RightTop(),
inactive);
}
break;
}
case B_BORDERED_WINDOW_LOOK:
fDrawingEngine->StrokeRect(r, fFrameMidColor);
break;
default:
// don't draw a border frame
break;
}
}
void
MacDecorator::_DrawTab(Decorator::Tab* tab, BRect invalid)
{
// If a window has a tab, this will draw it and any buttons which are
// in it.
if (!tab->tabRect.IsValid() || !invalid.Intersects(tab->tabRect))
return;
BRect rect(tab->tabRect);
fDrawingEngine->SetHighColor(RGBColor(fFrameMidColor));
fDrawingEngine->FillRect(rect, fFrameMidColor);
if (IsFocus(tab)) {
fDrawingEngine->StrokeLine(rect.LeftTop(), rect.RightTop(),
fFrameLowerColor);
fDrawingEngine->StrokeLine(rect.LeftTop(), rect.LeftBottom(),
fFrameLowerColor);
fDrawingEngine->StrokeLine(rect.RightBottom(), rect.RightTop(),
fFrameLowerColor);
rect.InsetBy(1, 1);
rect.bottom++;
fDrawingEngine->StrokeLine(rect.LeftTop(), rect.RightTop(),
fFrameHighColor);
fDrawingEngine->StrokeLine(rect.LeftTop(), rect.LeftBottom(),
fFrameHighColor);
fDrawingEngine->StrokeLine(rect.RightBottom(), rect.RightTop(),
fFrameLowColor);
// Draw the neat little lines on either side of the title if there's
// room
float left;
if ((tab->flags & B_NOT_CLOSABLE) == 0)
left = tab->closeRect.right;
else
left = tab->tabRect.left;
float right;
if ((tab->flags & B_NOT_ZOOMABLE) == 0)
right = tab->zoomRect.left;
else if ((tab->flags & B_NOT_MINIMIZABLE) == 0)
right = tab->minimizeRect.left;
else
right = tab->tabRect.right;
if (tab->tabRect.left + tab->textOffset > left + 5) {
RGBColor dark(115, 115, 115);
// Left side
BPoint offset(left + 5, tab->closeRect.top);
BPoint pt2(tab->tabRect.left + tab->textOffset - 5,
tab->closeRect.top);
fDrawState.SetHighColor(RGBColor(fFrameHighColor));
for (int32 i = 0; i < 6; i++) {
fDrawingEngine->StrokeLine(offset, pt2,
fDrawState.HighColor());
offset.y += 2;
pt2.y += 2;
}
offset.Set(left + 6, tab->closeRect.top + 1);
pt2.Set(tab->tabRect.left + tab->textOffset - 4,
tab->closeRect.top + 1);
fDrawState.SetHighColor(dark);
for (int32 i = 0; i < 6; i++) {
fDrawingEngine->StrokeLine(offset, pt2,
fDrawState.HighColor());
offset.y += 2;
pt2.y += 2;
}
// Right side
offset.Set(tab->tabRect.left + tab->textOffset
+ tab->truncatedTitleLength + 3, tab->zoomRect.top);
pt2.Set(right - 8, tab->zoomRect.top);
if (offset.x < pt2.x) {
fDrawState.SetHighColor(RGBColor(fFrameHighColor));
for (int32 i = 0; i < 6; i++) {
fDrawingEngine->StrokeLine(offset, pt2,
fDrawState.HighColor());
offset.y += 2;
pt2.y += 2;
}
offset.Set(tab->tabRect.left + tab->textOffset
+ tab->truncatedTitleLength + 4, tab->zoomRect.top + 1);
pt2.Set(right - 7, tab->zoomRect.top + 1);
fDrawState.SetHighColor(dark);
for(int32 i = 0; i < 6; i++) {
fDrawingEngine->StrokeLine(offset, pt2,
fDrawState.HighColor());
offset.y += 2;
pt2.y += 2;
}
}
}
_DrawButtons(tab, rect);
} else {
RGBColor inactive(82, 82, 82);
// Not focused - Just draw a plain light grey area with the title
// in the middle
fDrawingEngine->StrokeLine(rect.LeftTop(), rect.RightTop(),
inactive);
fDrawingEngine->StrokeLine(rect.LeftTop(), rect.LeftBottom(),
inactive);
fDrawingEngine->StrokeLine(rect.RightBottom(), rect.RightTop(),
inactive);
}
_DrawTitle(tab, tab->tabRect);
}
void
MacDecorator::_DrawButtons(Decorator::Tab* tab, const BRect& invalid)
{
if ((tab->flags & B_NOT_CLOSABLE) == 0
&& invalid.Intersects(tab->closeRect)) {
_DrawClose(tab, false, tab->closeRect);
}
if ((tab->flags & B_NOT_MINIMIZABLE) == 0
&& invalid.Intersects(tab->minimizeRect)) {
_DrawMinimize(tab, false, tab->minimizeRect);
}
if ((tab->flags & B_NOT_ZOOMABLE) == 0
&& invalid.Intersects(tab->zoomRect)) {
_DrawZoom(tab, false, tab->zoomRect);
}
}
void
MacDecorator::_DrawTitle(Decorator::Tab* tab, BRect rect)
{
fDrawingEngine->SetHighColor(IsFocus(tab)
? fFocusTextColor : fNonFocusTextColor);
fDrawingEngine->SetLowColor(fFrameMidColor);
tab->truncatedTitle = Title(tab);
fDrawState.Font().TruncateString(&tab->truncatedTitle, B_TRUNCATE_END,
(tab->zoomRect.left - 5) - (tab->closeRect.right + 5));
fDrawingEngine->SetFont(fDrawState.Font());
fDrawingEngine->DrawString(tab->truncatedTitle, tab->truncatedTitle.Length(),
BPoint(fTitleBarRect.left + tab->textOffset,
tab->closeRect.bottom - 1));
}
void
MacDecorator::_DrawClose(Decorator::Tab* tab, bool direct, BRect r)
{
_DrawButton(tab, direct, r, tab->closePressed);
}
void
MacDecorator::_DrawZoom(Decorator::Tab* tab, bool direct, BRect rect)
{
_DrawButton(tab, direct, rect, tab->zoomPressed);
rect.top++;
rect.left++;
rect.bottom = rect.top + 6;
rect.right = rect.left + 6;
fDrawState.SetHighColor(RGBColor(33, 33, 33));
fDrawingEngine->StrokeRect(rect, fDrawState.HighColor());
}
void
MacDecorator::_DrawMinimize(Decorator::Tab* tab, bool direct, BRect rect)
{
_DrawButton(tab, direct, rect, tab->minimizePressed);
rect.InsetBy(1, 5);
fDrawState.SetHighColor(RGBColor(33, 33, 33));
fDrawingEngine->StrokeRect(rect, fDrawState.HighColor());
}
void
MacDecorator::_SetTitle(Tab* tab, const char* string, BRegion* updateRegion)
{
// TODO: we could be much smarter about the update region
// TODO may this change the other tabs too ? (to make space for a longer
// title ?)
BRect rect = TabRect(tab);
_DoLayout();
if (updateRegion == NULL)
return;
rect = rect | TabRect(tab);
rect.bottom++;
// the border will look differently when the title is adjacent
updateRegion->Include(rect);
}
// TODO : _SetFocus
void
MacDecorator::_MoveBy(BPoint offset)
{
// Move all internal rectangles the appropriate amount
for (int32 i = 0; i < fTabList.CountItems(); i++) {
Decorator::Tab* tab = fTabList.ItemAt(i);
tab->zoomRect.OffsetBy(offset);
tab->minimizeRect.OffsetBy(offset);
tab->closeRect.OffsetBy(offset);
tab->tabRect.OffsetBy(offset);
}
fFrame.OffsetBy(offset);
fTitleBarRect.OffsetBy(offset);
fResizeRect.OffsetBy(offset);
fBorderRect.OffsetBy(offset);
}
void
MacDecorator::_ResizeBy(BPoint offset, BRegion* dirty)
{
// Move all internal rectangles the appropriate amount
fFrame.right += offset.x;
fFrame.bottom += offset.y;
fTitleBarRect.right += offset.x;
fBorderRect.right += offset.x;
fBorderRect.bottom += offset.y;
// fZoomRect.OffsetBy(offset.x, 0);
// fMinimizeRect.OffsetBy(offset.x, 0);
if (dirty) {
dirty->Include(fTitleBarRect);
dirty->Include(fBorderRect);
}
// TODO probably some other layouting stuff here
_DoLayout();
}
// TODO : _SetSettings
Decorator::Tab*
MacDecorator::_AllocateNewTab()
{
Decorator::Tab* tab = new(std::nothrow) Decorator::Tab;
if (tab == NULL)
return NULL;
// Set appropriate colors based on the current focus value. In this case,
// each decorator defaults to not having the focus.
_SetFocus(tab);
return tab;
}
bool
MacDecorator::_AddTab(DesktopSettings& settings, int32 index,
BRegion* updateRegion)
{
_UpdateFont(settings);
_DoLayout();
if (updateRegion != NULL)
updateRegion->Include(fTitleBarRect);
return true;
}
bool
MacDecorator::_RemoveTab(int32 index, BRegion* updateRegion)
{
BRect oldTitle = fTitleBarRect;
_DoLayout();
if (updateRegion != NULL) {
updateRegion->Include(oldTitle);
updateRegion->Include(fTitleBarRect);
}
return true;
}
bool
MacDecorator::_MoveTab(int32 from, int32 to, bool isMoving,
BRegion* updateRegion)
{
return false;
#if 0
MacDecorator::Tab* toTab = _TabAt(to);
if (toTab == NULL)
return false;
if (from < to) {
fOldMovingTab.OffsetBy(toTab->tabRect.Width(), 0);
toTab->tabRect.OffsetBy(-fOldMovingTab.Width(), 0);
} else {
fOldMovingTab.OffsetBy(-toTab->tabRect.Width(), 0);
toTab->tabRect.OffsetBy(fOldMovingTab.Width(), 0);
}
toTab->tabOffset = uint32(toTab->tabRect.left - fLeftBorder.left);
_LayoutTabItems(toTab, toTab->tabRect);
_CalculateTabsRegion();
if (updateRegion != NULL)
updateRegion->Include(fTitleBarRect);
return true;
#endif
}
void
MacDecorator::_GetFootprint(BRegion* region)
{
// This function calculates the decorator's footprint in coordinates
// relative to the view. This is most often used to set a Window
// object's visible region.
if (!region)
return;
region->MakeEmpty();
if (fTopTab->look == B_NO_BORDER_WINDOW_LOOK)
return;
region->Set(fBorderRect);
region->Exclude(fFrame);
if (fTopTab->look == B_BORDERED_WINDOW_LOOK)
return;
region->Include(fTitleBarRect);
}
void
MacDecorator::_UpdateFont(DesktopSettings& settings)
{
ServerFont font;
if (fTopTab && fTopTab->look == B_FLOATING_WINDOW_LOOK)
settings.GetDefaultPlainFont(font);
else
settings.GetDefaultBoldFont(font);
font.SetFlags(B_FORCE_ANTIALIASING);
font.SetSpacing(B_STRING_SPACING);
fDrawState.SetFont(font);
}
// #pragma mark - Private methods
// Draw a mac-style button
void
MacDecorator::_DrawButton(Decorator::Tab* tab, bool direct, BRect r,
bool down)
{
BRect rect(r);
BPoint offset(r.LeftTop()), pt2(r.RightTop());
// Topleft dark grey border
pt2.x--;
fDrawingEngine->SetHighColor(RGBColor(136, 136, 136));
fDrawingEngine->StrokeLine(offset, pt2);
pt2 = r.LeftBottom();
pt2.y--;
fDrawingEngine->StrokeLine(offset, pt2);
// Bottomright white border
offset = r.RightBottom();
pt2 = r.RightTop();
pt2.y++;
fDrawingEngine->SetHighColor(RGBColor(255, 255, 255));
fDrawingEngine->StrokeLine(offset, pt2);
pt2 = r.LeftBottom();
pt2.x++;
fDrawingEngine->StrokeLine(offset, pt2);
// Black outline
rect.InsetBy(1, 1);
fDrawingEngine->SetHighColor(RGBColor(33, 33, 33));
fDrawingEngine->StrokeRect(rect);
// Double-shaded button
rect.InsetBy(1, 1);
fDrawingEngine->SetHighColor(RGBColor(140, 140, 140));
fDrawingEngine->StrokeLine(rect.RightBottom(), rect.RightTop());
fDrawingEngine->StrokeLine(rect.RightBottom(), rect.LeftBottom());
fDrawingEngine->SetHighColor(RGBColor(206, 206, 206));
fDrawingEngine->StrokeLine(rect.LeftBottom(), rect.LeftTop());
fDrawingEngine->StrokeLine(rect.LeftTop(), rect.RightTop());
fDrawingEngine->SetHighColor(RGBColor(255, 255, 255));
fDrawingEngine->StrokeLine(rect.LeftTop(), rect.LeftTop());
rect.InsetBy(1, 1);
_DrawBlendedRect(fDrawingEngine, rect, !down);
}
/*! \brief Draws a rectangle with a gradient.
\param down The rectangle should be drawn recessed or not
*/
void
MacDecorator::_DrawBlendedRect(DrawingEngine* engine, BRect rect,
bool down/*, bool focus*/)
{
// figure out which colors to use
rgb_color startColor, endColor;
if (down) {
startColor = fButtonLowColor;
endColor = fFrameHighColor;
} else {
startColor = fButtonHighColor;
endColor = fFrameLowerColor;
}
// fill
BGradientLinear gradient;
gradient.SetStart(rect.LeftTop());
gradient.SetEnd(rect.RightBottom());
gradient.AddColor(startColor, 0);
gradient.AddColor(endColor, 255);
engine->FillRect(rect, gradient);
}
// #pragma mark - DecorAddOn
extern "C" DecorAddOn*
instantiate_decor_addon(image_id id, const char* name)
{
return new (std::nothrow)MacDecorAddOn(id, name);
}