From 20b3f78f8d7e5a2df62aa59c7e15bc5ffd7431ab Mon Sep 17 00:00:00 2001 From: Ryan Leavengood Date: Sat, 9 Jun 2012 16:41:13 -0400 Subject: [PATCH] Draw the chosen color next to the name of system colors. I copied BStringItem::Draw then modified it. I couldn't find a clean way of doing it otherwise, since the color box drawing needs to occur between the selection and text drawing, and the text needs to be offset while the selection shouldn't be. --- src/preferences/appearance/APRView.cpp | 14 +++- src/preferences/appearance/ColorWhichItem.cpp | 65 +++++++++++++++++-- src/preferences/appearance/ColorWhichItem.h | 13 +++- 3 files changed, 83 insertions(+), 9 deletions(-) diff --git a/src/preferences/appearance/APRView.cpp b/src/preferences/appearance/APRView.cpp index 32533af441..33b59d5d3a 100644 --- a/src/preferences/appearance/APRView.cpp +++ b/src/preferences/appearance/APRView.cpp @@ -70,6 +70,8 @@ APRView::APRView(const char* name) } #endif + LoadSettings(); + // Set up list of color attributes fAttrList = new BListView("AttributeList", B_SINGLE_SELECTION_LIST); @@ -80,7 +82,8 @@ APRView::APRView(const char* name) const ColorDescription& description = *get_color_description(i); const char* text = B_TRANSLATE_NOCOLLECT(description.text); color_which which = description.which; - fAttrList->AddItem(new ColorWhichItem(text, which)); + fAttrList->AddItem(new ColorWhichItem(text, which, + fCurrentSet.GetColor(which))); } BRect wellrect(0, 0, 50, 50); @@ -122,7 +125,6 @@ APRView::AttachedToWindow() fAttrList->SetTarget(this); fColorWell->SetTarget(this); - LoadSettings(); fAttrList->Select(0); } @@ -246,6 +248,14 @@ void APRView::_UpdateControls() { rgb_color color = fCurrentSet.GetColor(fWhich); + + int32 currentIndex = fAttrList->CurrentSelection(); + ColorWhichItem *item = (ColorWhichItem*) fAttrList->ItemAt(currentIndex); + if (item != NULL) { + item->SetColor(color); + fAttrList->InvalidateItem(currentIndex); + } + fPicker->SetValue(color); fColorWell->SetColor(color); fColorWell->Invalidate(); diff --git a/src/preferences/appearance/ColorWhichItem.cpp b/src/preferences/appearance/ColorWhichItem.cpp index 6c14349aac..23edda4f6d 100644 --- a/src/preferences/appearance/ColorWhichItem.cpp +++ b/src/preferences/appearance/ColorWhichItem.cpp @@ -5,19 +5,76 @@ * Authors: * DarkWyrm (darkwyrm@earthlink.net) * Rene Gollent (rene@gollent.com) + * Ryan Leavengood */ + + #include "ColorWhichItem.h" + #include -ColorWhichItem::ColorWhichItem(const char* text, color_which which) - : BStringItem(text, 0, false) - , colorWhich(which) + +ColorWhichItem::ColorWhichItem(const char* text, color_which which, + rgb_color color) + : + BStringItem(text, 0, false), + fColorWhich(which), + fColor(color) { } + +void +ColorWhichItem::DrawItem(BView *owner, BRect frame, bool complete) +{ + rgb_color highColor = owner->HighColor(); + rgb_color lowColor = owner->LowColor(); + + if (IsSelected() || complete) { + if (IsSelected()) { + owner->SetHighColor(tint_color(lowColor, B_DARKEN_2_TINT)); + owner->SetLowColor(owner->HighColor()); + } else + owner->SetHighColor(lowColor); + + owner->FillRect(frame); + } + + rgb_color black = {0, 0, 0, 255}; + + BRect colorRect(frame); + colorRect.InsetBy(2, 2); + colorRect.right = colorRect.left + colorRect.Height(); + owner->SetHighColor(fColor); + owner->FillRect(colorRect); + owner->SetHighColor(black); + owner->StrokeRect(colorRect); + + owner->MovePenTo(frame.left + colorRect.Width() + 8, frame.top + + BaselineOffset()); + + if (!IsEnabled()) + owner->SetHighColor(tint_color(black, B_LIGHTEN_2_TINT)); + else + owner->SetHighColor(black); + + owner->DrawString(Text()); + + owner->SetHighColor(highColor); + owner->SetLowColor(lowColor); +} + + color_which ColorWhichItem::ColorWhich(void) { - return colorWhich; + return fColorWhich; +} + + +void +ColorWhichItem::SetColor(rgb_color color) +{ + fColor = color; } diff --git a/src/preferences/appearance/ColorWhichItem.h b/src/preferences/appearance/ColorWhichItem.h index 2d2319e760..abc5853719 100644 --- a/src/preferences/appearance/ColorWhichItem.h +++ b/src/preferences/appearance/ColorWhichItem.h @@ -5,22 +5,29 @@ * Authors: * DarkWyrm * Rene Gollent (rene@gollent.com) + * Ryan Leavengood */ + + #ifndef COLORWHICH_ITEM_H #define COLORWHICH_ITEM_H #include #include +#include class ColorWhichItem : public BStringItem { public: - ColorWhichItem(const char* text, color_which which); + ColorWhichItem(const char* text, color_which which, rgb_color color); - color_which ColorWhich(void); + virtual void DrawItem(BView *owner, BRect frame, bool complete); + color_which ColorWhich(void); + void SetColor(rgb_color color); private: - color_which colorWhich; + color_which fColorWhich; + rgb_color fColor; }; #endif