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
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright 2002-2016 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* John Scipione, [email protected]
|
||||
*
|
||||
* Based on ColorWhichIcon by DarkWyrm ([email protected])
|
||||
*/
|
||||
|
||||
|
||||
#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;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2002-2016 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* John Scipione, [email protected]
|
||||
*
|
||||
* Based on ColorWhichIcon by DarkWyrm, [email protected]
|
||||
*/
|
||||
#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
|
||||
@@ -19,7 +19,9 @@
|
||||
#include <StringView.h>
|
||||
#include <View.h>
|
||||
|
||||
#include "ColorItem.h"
|
||||
#include "Gravity.h"
|
||||
#include "RainbowItem.h"
|
||||
|
||||
|
||||
static const int32 kMsgSize = 'size';
|
||||
@@ -43,14 +45,13 @@ ConfigView::ConfigView(BRect frame, Gravity* parent)
|
||||
SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
|
||||
|
||||
fShadeList->SetSelectionMessage(new BMessage(kMsgShade));
|
||||
|
||||
fShadeList->AddItem(new BStringItem("Red"));
|
||||
fShadeList->AddItem(new BStringItem("Green"));
|
||||
fShadeList->AddItem(new BStringItem("Blue"));
|
||||
fShadeList->AddItem(new BStringItem("Orange"));
|
||||
fShadeList->AddItem(new BStringItem("Purple"));
|
||||
fShadeList->AddItem(new BStringItem("White"));
|
||||
fShadeList->AddItem(new BStringItem("Rainbow"));
|
||||
fShadeList->AddItem(new ColorItem("Red", (rgb_color){ 255, 65, 54 }));
|
||||
fShadeList->AddItem(new ColorItem("Green", (rgb_color){ 46, 204, 64 }));
|
||||
fShadeList->AddItem(new ColorItem("Blue", (rgb_color){ 0, 116, 217 }));
|
||||
fShadeList->AddItem(new ColorItem("Orange", (rgb_color){ 255, 133, 27 }));
|
||||
fShadeList->AddItem(new ColorItem("Purple", (rgb_color){ 177, 13, 201 }));
|
||||
fShadeList->AddItem(new ColorItem("White", (rgb_color){ 255, 255, 255 }));
|
||||
fShadeList->AddItem(new RainbowItem("Rainbow"));
|
||||
|
||||
fShadeList->Select(parent->Config.ShadeID);
|
||||
|
||||
|
||||
@@ -10,11 +10,13 @@ if $(TARGET_GCC_VERSION_$(TARGET_PACKAGING_ARCH)[1]) < 3 {
|
||||
AddResources Gravity : Gravity.rdef ;
|
||||
|
||||
local sources =
|
||||
ColorItem.cpp
|
||||
ConfigView.cpp
|
||||
Gravity.cpp
|
||||
GravitySource.cpp
|
||||
GravityView.cpp
|
||||
Particle.cpp
|
||||
RainbowItem.cpp
|
||||
main.cpp
|
||||
;
|
||||
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright 2006 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* John Scipione, [email protected]
|
||||
*/
|
||||
|
||||
|
||||
#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);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2001-2008, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* DarkWyrm, [email protected]
|
||||
* Rene Gollent, [email protected]
|
||||
* Ryan Leavengood, [email protected]
|
||||
* John Scipione, [email protected]
|
||||
*/
|
||||
#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
|
||||
Reference in New Issue
Block a user