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.
This commit is contained in:
Ryan Leavengood
2012-06-09 17:12:42 -04:00
parent 131161928c
commit 20b3f78f8d
3 changed files with 83 additions and 9 deletions
+12 -2
View File
@@ -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();
+61 -4
View File
@@ -5,19 +5,76 @@
* Authors:
* DarkWyrm ([email protected])
* Rene Gollent ([email protected])
* Ryan Leavengood <[email protected]>
*/
#include "ColorWhichItem.h"
#include <stdio.h>
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;
}
+10 -3
View File
@@ -5,22 +5,29 @@
* Authors:
* DarkWyrm <[email protected]>
* Rene Gollent ([email protected])
* Ryan Leavengood <[email protected]>
*/
#ifndef COLORWHICH_ITEM_H
#define COLORWHICH_ITEM_H
#include <InterfaceDefs.h>
#include <ListItem.h>
#include <View.h>
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