1 /* 2 * Copyright 2002-2013 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * DarkWyrm, darkwyrm@earthlink.net 7 * Rene Gollent, rene@gollent.com 8 * Ryan Leavengood, leavengood@gmail.com 9 */ 10 11 12 #include "ColorWhichItem.h" 13 14 #include <stdio.h> 15 16 17 ColorWhichItem::ColorWhichItem(const char* text, color_which which, 18 rgb_color color) 19 : 20 BStringItem(text, 0, false), 21 fColorWhich(which), 22 fColor(color) 23 { 24 } 25 26 27 void 28 ColorWhichItem::DrawItem(BView* owner, BRect frame, bool complete) 29 { 30 rgb_color highColor = owner->HighColor(); 31 rgb_color lowColor = owner->LowColor(); 32 33 if (IsSelected() || complete) { 34 if (IsSelected()) { 35 owner->SetHighColor(ui_color(B_LIST_SELECTED_BACKGROUND_COLOR)); 36 owner->SetLowColor(owner->HighColor()); 37 } else 38 owner->SetHighColor(lowColor); 39 40 owner->FillRect(frame); 41 } 42 43 rgb_color border = (rgb_color){ 184, 184, 184, 255 }; 44 45 BRect colorRect(frame); 46 colorRect.InsetBy(2, 2); 47 colorRect.right = colorRect.left + colorRect.Height(); 48 owner->SetHighColor(fColor); 49 owner->FillRect(colorRect); 50 owner->SetHighColor(border); 51 owner->StrokeRect(colorRect); 52 53 owner->MovePenTo(frame.left + colorRect.Width() + 8, frame.top 54 + BaselineOffset()); 55 56 if (!IsEnabled()) { 57 rgb_color textColor = ui_color(B_LIST_ITEM_TEXT_COLOR); 58 if (textColor.red + textColor.green + textColor.blue > 128 * 3) 59 owner->SetHighColor(tint_color(textColor, B_DARKEN_2_TINT)); 60 else 61 owner->SetHighColor(tint_color(textColor, B_LIGHTEN_2_TINT)); 62 } else { 63 if (IsSelected()) 64 owner->SetHighColor(ui_color(B_LIST_SELECTED_ITEM_TEXT_COLOR)); 65 else 66 owner->SetHighColor(ui_color(B_LIST_ITEM_TEXT_COLOR)); 67 } 68 69 owner->DrawString(Text()); 70 71 owner->SetHighColor(highColor); 72 owner->SetLowColor(lowColor); 73 } 74 75 76 color_which 77 ColorWhichItem::ColorWhich(void) 78 { 79 return fColorWhich; 80 } 81 82 83 void 84 ColorWhichItem::SetColor(rgb_color color) 85 { 86 fColor = color; 87 } 88