1 /* 2 * Copyright 2001-2002 OpenBeOS 3 * Copyright 2003-2016 Haiku, Inc. All rights reserved. 4 * Distributed under the terms of the MIT License. 5 * 6 * Authors: 7 * DarkWyrm, darkwyrm@earthlink.net 8 * Rene Gollent, rene@gollent.com 9 * Ryan Leavengood, leavengood@gmail.com 10 * John Scipione, jscipione@gmail.com 11 */ 12 13 14 #include "ColorWhichItem.h" 15 16 #include <math.h> 17 18 #include <ControlLook.h> 19 20 21 // golden ratio 22 #ifdef M_PHI 23 # undef M_PHI 24 #endif 25 #define M_PHI 1.61803398874989484820 26 27 28 ColorWhichItem::ColorWhichItem(const char* text, color_which which, 29 rgb_color color) 30 : 31 BStringItem(text, 0, false), 32 fColorWhich(which), 33 fColor(color) 34 { 35 } 36 37 38 void 39 ColorWhichItem::DrawItem(BView* owner, BRect frame, bool complete) 40 { 41 rgb_color highColor = owner->HighColor(); 42 rgb_color lowColor = owner->LowColor(); 43 44 if (IsSelected() || complete) { 45 if (IsSelected()) { 46 owner->SetHighUIColor(B_LIST_SELECTED_BACKGROUND_COLOR); 47 owner->SetLowColor(owner->HighColor()); 48 } else 49 owner->SetHighColor(lowColor); 50 51 owner->FillRect(frame); 52 } 53 54 float spacer = ceilf(be_control_look->DefaultItemSpacing() / 2); 55 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); 60 owner->SetHighColor(fColor); 61 owner->FillRect(colorRect); 62 owner->SetHighUIColor(B_CONTROL_BORDER_COLOR); 63 owner->StrokeRect(colorRect); 64 65 owner->MovePenTo(colorRect.right + spacer, frame.top + BaselineOffset()); 66 67 if (!IsEnabled()) { 68 rgb_color textColor = ui_color(B_LIST_ITEM_TEXT_COLOR); 69 if (textColor.red + textColor.green + textColor.blue > 128 * 3) 70 owner->SetHighColor(tint_color(textColor, B_DARKEN_2_TINT)); 71 else 72 owner->SetHighColor(tint_color(textColor, B_LIGHTEN_2_TINT)); 73 } else { 74 if (IsSelected()) 75 owner->SetHighUIColor(B_LIST_SELECTED_ITEM_TEXT_COLOR); 76 else 77 owner->SetHighUIColor(B_LIST_ITEM_TEXT_COLOR); 78 } 79 80 owner->DrawString(Text()); 81 82 owner->SetHighColor(highColor); 83 owner->SetLowColor(lowColor); 84 } 85