14b834557SJohn Scipione /*
2cd91a715SJohn Scipione * Copyright 2016 Haiku, Inc. All rights reserved.
34b834557SJohn Scipione * Distributed under the terms of the MIT License.
44b834557SJohn Scipione *
54b834557SJohn Scipione * Authors:
64b834557SJohn Scipione * John Scipione, jscipione@gmail.com
74b834557SJohn Scipione */
84b834557SJohn Scipione
94b834557SJohn Scipione
104b834557SJohn Scipione #include "RainbowItem.h"
114b834557SJohn Scipione
124b834557SJohn Scipione #include <math.h>
134b834557SJohn Scipione
144b834557SJohn Scipione #include <ControlLook.h>
154b834557SJohn Scipione #include <GradientLinear.h>
164b834557SJohn Scipione #include <InterfaceDefs.h>
174b834557SJohn Scipione #include <View.h>
184b834557SJohn Scipione
194b834557SJohn Scipione
204b834557SJohn Scipione // golden ratio
214b834557SJohn Scipione #ifdef M_PHI
224b834557SJohn Scipione # undef M_PHI
234b834557SJohn Scipione #endif
244b834557SJohn Scipione #define M_PHI 1.61803398874989484820
254b834557SJohn Scipione
264b834557SJohn Scipione
274b834557SJohn Scipione // #pragma mark - RainbowItem
284b834557SJohn Scipione
294b834557SJohn Scipione
RainbowItem(const char * string)304b834557SJohn Scipione RainbowItem::RainbowItem(const char* string)
314b834557SJohn Scipione :
324b834557SJohn Scipione BStringItem(string, 0, false)
334b834557SJohn Scipione {
344b834557SJohn Scipione }
354b834557SJohn Scipione
364b834557SJohn Scipione
374b834557SJohn Scipione void
DrawItem(BView * owner,BRect frame,bool complete)384b834557SJohn Scipione RainbowItem::DrawItem(BView* owner, BRect frame, bool complete)
394b834557SJohn Scipione {
404b834557SJohn Scipione rgb_color highColor = owner->HighColor();
414b834557SJohn Scipione rgb_color lowColor = owner->LowColor();
424b834557SJohn Scipione
434b834557SJohn Scipione if (IsSelected() || complete) {
444b834557SJohn Scipione if (IsSelected()) {
45d1d1535aSJohn Scipione owner->SetHighUIColor(B_LIST_SELECTED_BACKGROUND_COLOR);
464b834557SJohn Scipione owner->SetLowColor(owner->HighColor());
474b834557SJohn Scipione } else
484b834557SJohn Scipione owner->SetHighColor(lowColor);
494b834557SJohn Scipione
504b834557SJohn Scipione owner->FillRect(frame);
514b834557SJohn Scipione }
524b834557SJohn Scipione
53*a80db836SJohn Scipione float spacer = ceilf(be_control_look->DefaultItemSpacing() / 2);
544b834557SJohn Scipione
554b834557SJohn Scipione BRect colorRect(frame);
564b834557SJohn Scipione colorRect.InsetBy(2.0f, 2.0f);
574b834557SJohn Scipione colorRect.left += spacer;
58*a80db836SJohn Scipione colorRect.right = colorRect.left + floorf(colorRect.Height() * M_PHI);
594b834557SJohn Scipione
604b834557SJohn Scipione // draw the rainbow
614b834557SJohn Scipione BGradientLinear gradient;
624b834557SJohn Scipione gradient.AddColor((rgb_color){ 255, 65, 54 }, 0); // red
634b834557SJohn Scipione gradient.AddColor((rgb_color){ 255, 133, 27 }, 60); // orange
644b834557SJohn Scipione gradient.AddColor((rgb_color){ 255, 220, 0 }, 102); // yellow
654b834557SJohn Scipione gradient.AddColor((rgb_color){ 46, 204, 64 }, 153); // green
664b834557SJohn Scipione gradient.AddColor((rgb_color){ 0, 116, 217 }, 195); // blue
674b834557SJohn Scipione // indigo ;)
684b834557SJohn Scipione gradient.AddColor((rgb_color){ 177, 13, 201 }, 255); // violet
694b834557SJohn Scipione gradient.SetStart(colorRect.LeftTop());
704b834557SJohn Scipione gradient.SetEnd(colorRect.RightBottom());
714b834557SJohn Scipione owner->FillRect(colorRect, gradient);
724b834557SJohn Scipione
734b834557SJohn Scipione // draw the border
74d1d1535aSJohn Scipione owner->SetHighUIColor(B_CONTROL_BORDER_COLOR);
754b834557SJohn Scipione owner->StrokeRect(colorRect);
764b834557SJohn Scipione
774b834557SJohn Scipione // draw the string
784b834557SJohn Scipione owner->MovePenTo(colorRect.right + spacer, frame.top + BaselineOffset());
794b834557SJohn Scipione
804b834557SJohn Scipione if (!IsEnabled()) {
814b834557SJohn Scipione rgb_color textColor = ui_color(B_LIST_ITEM_TEXT_COLOR);
824b834557SJohn Scipione if (textColor.red + textColor.green + textColor.blue > 128 * 3)
834b834557SJohn Scipione owner->SetHighColor(tint_color(textColor, B_DARKEN_2_TINT));
844b834557SJohn Scipione else
854b834557SJohn Scipione owner->SetHighColor(tint_color(textColor, B_LIGHTEN_2_TINT));
864b834557SJohn Scipione } else {
874b834557SJohn Scipione if (IsSelected())
88d1d1535aSJohn Scipione owner->SetHighUIColor(B_LIST_SELECTED_ITEM_TEXT_COLOR);
894b834557SJohn Scipione else
90d1d1535aSJohn Scipione owner->SetHighUIColor(B_LIST_ITEM_TEXT_COLOR);
914b834557SJohn Scipione }
924b834557SJohn Scipione
934b834557SJohn Scipione owner->DrawString(Text());
944b834557SJohn Scipione
954b834557SJohn Scipione owner->SetHighColor(highColor);
964b834557SJohn Scipione owner->SetLowColor(lowColor);
974b834557SJohn Scipione }
98