xref: /haiku/src/preferences/appearance/ColorWhichItem.cpp (revision 268f99dd7dc4bd7474a8bd2742d3f1ec1de6752a)
13d5da9f4SDarkWyrm /*
2*2ca13760SColdfirex  * Copyright 2001-2016 Haiku, Inc. All rights reserved.
33d5da9f4SDarkWyrm  * Distributed under the terms of the MIT License.
43d5da9f4SDarkWyrm  *
53d5da9f4SDarkWyrm  * Authors:
6eba68f61SJohn Scipione  *		DarkWyrm, darkwyrm@earthlink.net
7eba68f61SJohn Scipione  *		Rene Gollent, rene@gollent.com
8eba68f61SJohn Scipione  *		Ryan Leavengood, leavengood@gmail.com
9a80db836SJohn Scipione  *		John Scipione, jscipione@gmail.com
103d5da9f4SDarkWyrm  */
1120b3f78fSRyan Leavengood 
1220b3f78fSRyan Leavengood 
13a10cf76eSAxel Dörfler #include "ColorWhichItem.h"
1420b3f78fSRyan Leavengood 
15a80db836SJohn Scipione #include <math.h>
16a80db836SJohn Scipione 
17a80db836SJohn Scipione #include <ControlLook.h>
18a80db836SJohn Scipione 
19a80db836SJohn Scipione 
20a80db836SJohn Scipione // golden ratio
21a80db836SJohn Scipione #ifdef M_PHI
22a80db836SJohn Scipione #	undef M_PHI
23a80db836SJohn Scipione #endif
24a80db836SJohn Scipione #define M_PHI 1.61803398874989484820
25a10cf76eSAxel Dörfler 
2620b3f78fSRyan Leavengood 
ColorWhichItem(const char * text,color_which which,rgb_color color)2720b3f78fSRyan Leavengood ColorWhichItem::ColorWhichItem(const char* text, color_which which,
2820b3f78fSRyan Leavengood 	rgb_color color)
2920b3f78fSRyan Leavengood 	:
3020b3f78fSRyan Leavengood 	BStringItem(text, 0, false),
3120b3f78fSRyan Leavengood 	fColorWhich(which),
3220b3f78fSRyan Leavengood 	fColor(color)
33a10cf76eSAxel Dörfler {
34a10cf76eSAxel Dörfler }
35a10cf76eSAxel Dörfler 
3620b3f78fSRyan Leavengood 
3720b3f78fSRyan Leavengood void
DrawItem(BView * owner,BRect frame,bool complete)3820b3f78fSRyan Leavengood ColorWhichItem::DrawItem(BView* owner, BRect frame, bool complete)
3920b3f78fSRyan Leavengood {
4020b3f78fSRyan Leavengood 	rgb_color highColor = owner->HighColor();
4120b3f78fSRyan Leavengood 	rgb_color lowColor = owner->LowColor();
4220b3f78fSRyan Leavengood 
4320b3f78fSRyan Leavengood 	if (IsSelected() || complete) {
4420b3f78fSRyan Leavengood 		if (IsSelected()) {
45a80db836SJohn Scipione 			owner->SetHighUIColor(B_LIST_SELECTED_BACKGROUND_COLOR);
4620b3f78fSRyan Leavengood 			owner->SetLowColor(owner->HighColor());
4720b3f78fSRyan Leavengood 		} else
4820b3f78fSRyan Leavengood 			owner->SetHighColor(lowColor);
4920b3f78fSRyan Leavengood 
5020b3f78fSRyan Leavengood 		owner->FillRect(frame);
5120b3f78fSRyan Leavengood 	}
5220b3f78fSRyan Leavengood 
53a80db836SJohn Scipione 	float spacer = ceilf(be_control_look->DefaultItemSpacing() / 2);
5420b3f78fSRyan Leavengood 
5520b3f78fSRyan Leavengood 	BRect colorRect(frame);
56a80db836SJohn Scipione 	colorRect.InsetBy(2.0f, 2.0f);
57a80db836SJohn Scipione 	colorRect.left += spacer;
58a80db836SJohn Scipione 	colorRect.right = colorRect.left + floorf(colorRect.Height() * M_PHI);
5920b3f78fSRyan Leavengood 	owner->SetHighColor(fColor);
6020b3f78fSRyan Leavengood 	owner->FillRect(colorRect);
61a80db836SJohn Scipione 	owner->SetHighUIColor(B_CONTROL_BORDER_COLOR);
6220b3f78fSRyan Leavengood 	owner->StrokeRect(colorRect);
6320b3f78fSRyan Leavengood 
64a80db836SJohn Scipione 	owner->MovePenTo(colorRect.right + spacer, frame.top + BaselineOffset());
6520b3f78fSRyan Leavengood 
662c1f6c10SJohn Scipione 	if (!IsEnabled()) {
6791c78f09SJohn Scipione 		rgb_color textColor = ui_color(B_LIST_ITEM_TEXT_COLOR);
682c1f6c10SJohn Scipione 		if (textColor.red + textColor.green + textColor.blue > 128 * 3)
692c1f6c10SJohn Scipione 			owner->SetHighColor(tint_color(textColor, B_DARKEN_2_TINT));
7020b3f78fSRyan Leavengood 		else
712c1f6c10SJohn Scipione 			owner->SetHighColor(tint_color(textColor, B_LIGHTEN_2_TINT));
722c1f6c10SJohn Scipione 	} else {
732c1f6c10SJohn Scipione 		if (IsSelected())
74a80db836SJohn Scipione 			owner->SetHighUIColor(B_LIST_SELECTED_ITEM_TEXT_COLOR);
752c1f6c10SJohn Scipione 		else
76a80db836SJohn Scipione 			owner->SetHighUIColor(B_LIST_ITEM_TEXT_COLOR);
772c1f6c10SJohn Scipione 	}
7820b3f78fSRyan Leavengood 
7920b3f78fSRyan Leavengood 	owner->DrawString(Text());
8020b3f78fSRyan Leavengood 
8120b3f78fSRyan Leavengood 	owner->SetHighColor(highColor);
8220b3f78fSRyan Leavengood 	owner->SetLowColor(lowColor);
8320b3f78fSRyan Leavengood }
84