Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gravity: Add ColorItem and RainbowItem
instead of using boring StringItems ColorItem draws a small colored rectangle left of the string RainbowItem draws a rainbow colored rectangle left of the string
- Loading branch information
Showing
6 changed files
with
260 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright 2002-2016 Haiku, Inc. All rights reserved. | ||
* Distributed under the terms of the MIT License. | ||
* | ||
* Authors: | ||
* John Scipione, jscipione@gmail.com | ||
* | ||
* Based on ColorWhichIcon by DarkWyrm (bpmagic@columbus.rr.com) | ||
*/ | ||
|
||
|
||
#include "ColorItem.h" | ||
|
||
#include <math.h> | ||
|
||
#include <ControlLook.h> | ||
#include <View.h> | ||
|
||
|
||
// golden ratio | ||
#ifdef M_PHI | ||
# undef M_PHI | ||
#endif | ||
#define M_PHI 1.61803398874989484820 | ||
|
||
|
||
// #pragma mark - ColorItem | ||
|
||
|
||
ColorItem::ColorItem(const char* string, rgb_color color) | ||
: | ||
BStringItem(string, 0, false), | ||
fColor(color) | ||
{ | ||
} | ||
|
||
|
||
void | ||
ColorItem::DrawItem(BView* owner, BRect frame, bool complete) | ||
{ | ||
rgb_color highColor = owner->HighColor(); | ||
rgb_color lowColor = owner->LowColor(); | ||
|
||
if (IsSelected() || complete) { | ||
if (IsSelected()) { | ||
owner->SetHighColor(ui_color(B_LIST_SELECTED_BACKGROUND_COLOR)); | ||
owner->SetLowColor(owner->HighColor()); | ||
} else | ||
owner->SetHighColor(lowColor); | ||
|
||
owner->FillRect(frame); | ||
} | ||
|
||
float spacer = floorf(be_control_look->DefaultItemSpacing() / 2); | ||
|
||
BRect colorRect(frame); | ||
colorRect.InsetBy(2.0f, 2.0f); | ||
colorRect.left += spacer; | ||
colorRect.right = colorRect.left + colorRect.Height() * M_PHI; | ||
|
||
// draw the colored box | ||
owner->SetHighColor(fColor); | ||
owner->FillRect(colorRect); | ||
|
||
// draw the border | ||
owner->SetHighColor(ui_color(B_CONTROL_BORDER_COLOR)); | ||
owner->StrokeRect(colorRect); | ||
|
||
// draw the string | ||
owner->MovePenTo(colorRect.right + spacer, frame.top + BaselineOffset()); | ||
|
||
if (!IsEnabled()) { | ||
rgb_color textColor = ui_color(B_LIST_ITEM_TEXT_COLOR); | ||
if (textColor.red + textColor.green + textColor.blue > 128 * 3) | ||
owner->SetHighColor(tint_color(textColor, B_DARKEN_2_TINT)); | ||
else | ||
owner->SetHighColor(tint_color(textColor, B_LIGHTEN_2_TINT)); | ||
} else { | ||
if (IsSelected()) | ||
owner->SetHighColor(ui_color(B_LIST_SELECTED_ITEM_TEXT_COLOR)); | ||
else | ||
owner->SetHighColor(ui_color(B_LIST_ITEM_TEXT_COLOR)); | ||
} | ||
|
||
owner->DrawString(Text()); | ||
|
||
owner->SetHighColor(highColor); | ||
owner->SetLowColor(lowColor); | ||
} | ||
|
||
|
||
void | ||
ColorItem::SetColor(rgb_color color) | ||
{ | ||
fColor = color; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2002-2016 Haiku, Inc. All rights reserved. | ||
* Distributed under the terms of the MIT License. | ||
* | ||
* Authors: | ||
* John Scipione, jscipione@gmail.com | ||
* | ||
* Based on ColorWhichIcon by DarkWyrm, bpmagic@columbus.rr.com | ||
*/ | ||
#ifndef _COLOR_ITEM_H | ||
#define _COLOR_ITEM_H | ||
|
||
|
||
#include <InterfaceDefs.h> | ||
#include <StringItem.h> | ||
|
||
|
||
class ColorItem : public BStringItem { | ||
public: | ||
ColorItem(const char* string, rgb_color color); | ||
|
||
virtual void DrawItem(BView* owner, BRect frame, bool complete); | ||
virtual void SetColor(rgb_color color); | ||
|
||
private: | ||
rgb_color fColor; | ||
}; | ||
|
||
|
||
#endif // _COLOR_ITEM_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright 2006 Haiku, Inc. All rights reserved. | ||
* Distributed under the terms of the MIT License. | ||
* | ||
* Authors: | ||
* John Scipione, jscipione@gmail.com | ||
*/ | ||
|
||
|
||
#include "RainbowItem.h" | ||
|
||
#include <math.h> | ||
|
||
#include <ControlLook.h> | ||
#include <GradientLinear.h> | ||
#include <InterfaceDefs.h> | ||
#include <View.h> | ||
|
||
|
||
// golden ratio | ||
#ifdef M_PHI | ||
# undef M_PHI | ||
#endif | ||
#define M_PHI 1.61803398874989484820 | ||
|
||
|
||
// #pragma mark - RainbowItem | ||
|
||
|
||
RainbowItem::RainbowItem(const char* string) | ||
: | ||
BStringItem(string, 0, false) | ||
{ | ||
} | ||
|
||
|
||
void | ||
RainbowItem::DrawItem(BView* owner, BRect frame, bool complete) | ||
{ | ||
rgb_color highColor = owner->HighColor(); | ||
rgb_color lowColor = owner->LowColor(); | ||
|
||
if (IsSelected() || complete) { | ||
if (IsSelected()) { | ||
owner->SetHighColor(ui_color(B_LIST_SELECTED_BACKGROUND_COLOR)); | ||
owner->SetLowColor(owner->HighColor()); | ||
} else | ||
owner->SetHighColor(lowColor); | ||
|
||
owner->FillRect(frame); | ||
} | ||
|
||
float spacer = floorf(be_control_look->DefaultItemSpacing() / 2); | ||
|
||
BRect colorRect(frame); | ||
colorRect.InsetBy(2.0f, 2.0f); | ||
colorRect.left += spacer; | ||
colorRect.right = colorRect.left + colorRect.Height() * M_PHI; | ||
|
||
// draw the rainbow | ||
BGradientLinear gradient; | ||
gradient.AddColor((rgb_color){ 255, 65, 54 }, 0); // red | ||
gradient.AddColor((rgb_color){ 255, 133, 27 }, 60); // orange | ||
gradient.AddColor((rgb_color){ 255, 220, 0 }, 102); // yellow | ||
gradient.AddColor((rgb_color){ 46, 204, 64 }, 153); // green | ||
gradient.AddColor((rgb_color){ 0, 116, 217 }, 195); // blue | ||
// indigo ;) | ||
gradient.AddColor((rgb_color){ 177, 13, 201 }, 255); // violet | ||
gradient.SetStart(colorRect.LeftTop()); | ||
gradient.SetEnd(colorRect.RightBottom()); | ||
owner->FillRect(colorRect, gradient); | ||
|
||
// draw the border | ||
owner->SetHighColor(ui_color(B_CONTROL_BORDER_COLOR)); | ||
owner->StrokeRect(colorRect); | ||
|
||
// draw the string | ||
owner->MovePenTo(colorRect.right + spacer, frame.top + BaselineOffset()); | ||
|
||
if (!IsEnabled()) { | ||
rgb_color textColor = ui_color(B_LIST_ITEM_TEXT_COLOR); | ||
if (textColor.red + textColor.green + textColor.blue > 128 * 3) | ||
owner->SetHighColor(tint_color(textColor, B_DARKEN_2_TINT)); | ||
else | ||
owner->SetHighColor(tint_color(textColor, B_LIGHTEN_2_TINT)); | ||
} else { | ||
if (IsSelected()) | ||
owner->SetHighColor(ui_color(B_LIST_SELECTED_ITEM_TEXT_COLOR)); | ||
else | ||
owner->SetHighColor(ui_color(B_LIST_ITEM_TEXT_COLOR)); | ||
} | ||
|
||
owner->DrawString(Text()); | ||
|
||
owner->SetHighColor(highColor); | ||
owner->SetLowColor(lowColor); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2001-2008, Haiku. | ||
* Distributed under the terms of the MIT License. | ||
* | ||
* Authors: | ||
* DarkWyrm, bpmagic@columbus.rr.com | ||
* Rene Gollent, rene@gollent.com | ||
* Ryan Leavengood, leavengood@gmail.com | ||
* John Scipione, jscipione@gmail.com | ||
*/ | ||
#ifndef _RAINBOW_ITEM_H | ||
#define _RAINBOW_ITEM_H | ||
|
||
|
||
#include <StringItem.h> | ||
|
||
|
||
class RainbowItem : public BStringItem { | ||
public: | ||
RainbowItem(const char* string); | ||
|
||
virtual void DrawItem(BView* owner, BRect frame, bool complete); | ||
}; | ||
|
||
|
||
#endif // _RAINBOW_ITEM_H |