2 * Copyright 2016 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * John Scipione, jscipione@gmail.com
8 * Based on ColorWhichItem by DarkWyrm (bpmagic@columbus.rr.com)
12 #include "ColorItem.h"
16 #include <ControlLook.h>
24 #define M_PHI 1.61803398874989484820
27 // #pragma mark - ColorItem
30 ColorItem::ColorItem(const char* string
, rgb_color color
)
32 BStringItem(string
, 0, false),
39 ColorItem::DrawItem(BView
* owner
, BRect frame
, bool complete
)
41 rgb_color highColor
= owner
->HighColor();
42 rgb_color lowColor
= owner
->LowColor();
44 if (IsSelected() || complete
) {
46 owner
->SetHighUIColor(B_LIST_SELECTED_BACKGROUND_COLOR
);
47 owner
->SetLowColor(owner
->HighColor());
49 owner
->SetHighColor(lowColor
);
51 owner
->FillRect(frame
);
54 float spacer
= ceilf(be_control_look
->DefaultItemSpacing() / 2);
56 BRect
colorRect(frame
);
57 colorRect
.InsetBy(2.0f
, 2.0f
);
58 colorRect
.left
+= spacer
;
59 colorRect
.right
= colorRect
.left
+ floorf(colorRect
.Height() * M_PHI
);
61 // draw the colored box
62 owner
->SetHighColor(fColor
);
63 owner
->FillRect(colorRect
);
66 owner
->SetHighUIColor(B_CONTROL_BORDER_COLOR
);
67 owner
->StrokeRect(colorRect
);
70 owner
->MovePenTo(colorRect
.right
+ spacer
, frame
.top
+ BaselineOffset());
73 rgb_color textColor
= ui_color(B_LIST_ITEM_TEXT_COLOR
);
74 if (textColor
.red
+ textColor
.green
+ textColor
.blue
> 128 * 3)
75 owner
->SetHighColor(tint_color(textColor
, B_DARKEN_2_TINT
));
77 owner
->SetHighColor(tint_color(textColor
, B_LIGHTEN_2_TINT
));
80 owner
->SetHighUIColor(B_LIST_SELECTED_ITEM_TEXT_COLOR
);
82 owner
->SetHighUIColor(B_LIST_ITEM_TEXT_COLOR
);
85 owner
->DrawString(Text());
87 owner
->SetHighColor(highColor
);
88 owner
->SetLowColor(lowColor
);
93 ColorItem::SetColor(rgb_color color
)