3rdparty/licenseReport: Add seperate LGPL checks
[haiku.git] / src / add-ons / screen_savers / gravity / RainbowItem.cpp
blob846ad0d02185091425e3d8586972b870af6a4b0a
1 /*
2 * Copyright 2016 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * John Scipione, jscipione@gmail.com
7 */
10 #include "RainbowItem.h"
12 #include <math.h>
14 #include <ControlLook.h>
15 #include <GradientLinear.h>
16 #include <InterfaceDefs.h>
17 #include <View.h>
20 // golden ratio
21 #ifdef M_PHI
22 # undef M_PHI
23 #endif
24 #define M_PHI 1.61803398874989484820
27 // #pragma mark - RainbowItem
30 RainbowItem::RainbowItem(const char* string)
32 BStringItem(string, 0, false)
37 void
38 RainbowItem::DrawItem(BView* owner, BRect frame, bool complete)
40 rgb_color highColor = owner->HighColor();
41 rgb_color lowColor = owner->LowColor();
43 if (IsSelected() || complete) {
44 if (IsSelected()) {
45 owner->SetHighUIColor(B_LIST_SELECTED_BACKGROUND_COLOR);
46 owner->SetLowColor(owner->HighColor());
47 } else
48 owner->SetHighColor(lowColor);
50 owner->FillRect(frame);
53 float spacer = ceilf(be_control_look->DefaultItemSpacing() / 2);
55 BRect colorRect(frame);
56 colorRect.InsetBy(2.0f, 2.0f);
57 colorRect.left += spacer;
58 colorRect.right = colorRect.left + floorf(colorRect.Height() * M_PHI);
60 // draw the rainbow
61 BGradientLinear gradient;
62 gradient.AddColor((rgb_color){ 255, 65, 54 }, 0); // red
63 gradient.AddColor((rgb_color){ 255, 133, 27 }, 60); // orange
64 gradient.AddColor((rgb_color){ 255, 220, 0 }, 102); // yellow
65 gradient.AddColor((rgb_color){ 46, 204, 64 }, 153); // green
66 gradient.AddColor((rgb_color){ 0, 116, 217 }, 195); // blue
67 // indigo ;)
68 gradient.AddColor((rgb_color){ 177, 13, 201 }, 255); // violet
69 gradient.SetStart(colorRect.LeftTop());
70 gradient.SetEnd(colorRect.RightBottom());
71 owner->FillRect(colorRect, gradient);
73 // draw the border
74 owner->SetHighUIColor(B_CONTROL_BORDER_COLOR);
75 owner->StrokeRect(colorRect);
77 // draw the string
78 owner->MovePenTo(colorRect.right + spacer, frame.top + BaselineOffset());
80 if (!IsEnabled()) {
81 rgb_color textColor = ui_color(B_LIST_ITEM_TEXT_COLOR);
82 if (textColor.red + textColor.green + textColor.blue > 128 * 3)
83 owner->SetHighColor(tint_color(textColor, B_DARKEN_2_TINT));
84 else
85 owner->SetHighColor(tint_color(textColor, B_LIGHTEN_2_TINT));
86 } else {
87 if (IsSelected())
88 owner->SetHighUIColor(B_LIST_SELECTED_ITEM_TEXT_COLOR);
89 else
90 owner->SetHighUIColor(B_LIST_ITEM_TEXT_COLOR);
93 owner->DrawString(Text());
95 owner->SetHighColor(highColor);
96 owner->SetLowColor(lowColor);