2 * Copyright 2016 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * John Scipione, jscipione@gmail.com
10 #include "RainbowItem.h"
14 #include <ControlLook.h>
15 #include <GradientLinear.h>
16 #include <InterfaceDefs.h>
24 #define M_PHI 1.61803398874989484820
27 // #pragma mark - RainbowItem
30 RainbowItem::RainbowItem(const char* string
)
32 BStringItem(string
, 0, false)
38 RainbowItem::DrawItem(BView
* owner
, BRect frame
, bool complete
)
40 rgb_color highColor
= owner
->HighColor();
41 rgb_color lowColor
= owner
->LowColor();
43 if (IsSelected() || complete
) {
45 owner
->SetHighUIColor(B_LIST_SELECTED_BACKGROUND_COLOR
);
46 owner
->SetLowColor(owner
->HighColor());
48 owner
->SetHighColor(lowColor
);
50 owner
->FillRect(frame
);
53 float spacer
= ceilf(be_control_look
->DefaultItemSpacing() / 2);
55 BRect
colorRect(frame
);
56 colorRect
.InsetBy(2.0f
, 2.0f
);
57 colorRect
.left
+= spacer
;
58 colorRect
.right
= colorRect
.left
+ floorf(colorRect
.Height() * M_PHI
);
61 BGradientLinear gradient
;
62 gradient
.AddColor((rgb_color
){ 255, 65, 54 }, 0); // red
63 gradient
.AddColor((rgb_color
){ 255, 133, 27 }, 60); // orange
64 gradient
.AddColor((rgb_color
){ 255, 220, 0 }, 102); // yellow
65 gradient
.AddColor((rgb_color
){ 46, 204, 64 }, 153); // green
66 gradient
.AddColor((rgb_color
){ 0, 116, 217 }, 195); // blue
68 gradient
.AddColor((rgb_color
){ 177, 13, 201 }, 255); // violet
69 gradient
.SetStart(colorRect
.LeftTop());
70 gradient
.SetEnd(colorRect
.RightBottom());
71 owner
->FillRect(colorRect
, gradient
);
74 owner
->SetHighUIColor(B_CONTROL_BORDER_COLOR
);
75 owner
->StrokeRect(colorRect
);
78 owner
->MovePenTo(colorRect
.right
+ spacer
, frame
.top
+ BaselineOffset());
81 rgb_color textColor
= ui_color(B_LIST_ITEM_TEXT_COLOR
);
82 if (textColor
.red
+ textColor
.green
+ textColor
.blue
> 128 * 3)
83 owner
->SetHighColor(tint_color(textColor
, B_DARKEN_2_TINT
));
85 owner
->SetHighColor(tint_color(textColor
, B_LIGHTEN_2_TINT
));
88 owner
->SetHighUIColor(B_LIST_SELECTED_ITEM_TEXT_COLOR
);
90 owner
->SetHighUIColor(B_LIST_ITEM_TEXT_COLOR
);
93 owner
->DrawString(Text());
95 owner
->SetHighColor(highColor
);
96 owner
->SetLowColor(lowColor
);