vfs: check userland buffers before reading them.
[haiku.git] / src / preferences / appearance / ColorWhichItem.cpp
blob55926a195f71f9bc9c3f165f931a53a68776b024
1 /*
2 * Copyright 2001-2002 OpenBeOS
3 * Copyright 2003-2016 Haiku, Inc. All rights reserved.
4 * Distributed under the terms of the MIT License.
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
14 #include "ColorWhichItem.h"
16 #include <math.h>
18 #include <ControlLook.h>
21 // golden ratio
22 #ifdef M_PHI
23 # undef M_PHI
24 #endif
25 #define M_PHI 1.61803398874989484820
28 ColorWhichItem::ColorWhichItem(const char* text, color_which which,
29 rgb_color color)
31 BStringItem(text, 0, false),
32 fColorWhich(which),
33 fColor(color)
38 void
39 ColorWhichItem::DrawItem(BView* owner, BRect frame, bool complete)
41 rgb_color highColor = owner->HighColor();
42 rgb_color lowColor = owner->LowColor();
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);
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);
60 owner->SetHighColor(fColor);
61 owner->FillRect(colorRect);
62 owner->SetHighUIColor(B_CONTROL_BORDER_COLOR);
63 owner->StrokeRect(colorRect);
65 owner->MovePenTo(colorRect.right + spacer, frame.top + BaselineOffset());
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);
80 owner->DrawString(Text());
82 owner->SetHighColor(highColor);
83 owner->SetLowColor(lowColor);