FileTypes: Use list view color constants

...instead of hardcoding black.

Only you can prevent hard-coded colors.

Make sure to set both high color and low color so we don't get
anti-aliasing glitches.

Also, use be_control_look->DefaultLabelSpacing() instead of 5.0f.

Only you can prevent hard-coded label spacings.

Also return early if text is NULL (not set).

Fixes a small part of #10840
This commit is contained in:
John Scipione
2014-06-27 19:07:29 -04:00
parent c35a9fd0a7
commit e23f93739b
+30 -13
View File
@@ -15,6 +15,7 @@
#include <stdio.h>
#include <Catalog.h>
#include <ControlLook.h>
#include <Locale.h>
#include <ObjectList.h>
@@ -196,28 +197,44 @@ AttributeItem::DrawItem(BView* owner, BRect frame, bool drawEverything)
{
BStringItem::DrawItem(owner, frame, drawEverything);
BString type;
name_for_type(type, fType, fDisplayAs.String());
const char* typeString = type.String();
if (typeString == NULL)
return;
rgb_color highColor = owner->HighColor();
rgb_color lowColor = owner->LowColor();
// set the low color
if (IsSelected())
owner->SetLowColor(tint_color(lowColor, B_DARKEN_2_TINT));
rgb_color black = {0, 0, 0, 255};
if (!IsEnabled())
owner->SetHighColor(tint_color(black, B_LIGHTEN_2_TINT));
owner->SetLowColor(ui_color(B_LIST_SELECTED_BACKGROUND_COLOR));
else
owner->SetHighColor(black);
owner->SetLowColor(ui_color(B_LIST_BACKGROUND_COLOR));
owner->MovePenTo(frame.left + frame.Width() / 2.0f + 5.0f,
// set the high color
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));
}
// move the pen into position
owner->MovePenTo(frame.left + frame.Width() / 2.0f
+ be_control_look->DefaultLabelSpacing(),
owner->PenLocation().y);
BString type;
name_for_type(type, fType, fDisplayAs.String());
owner->DrawString(type.String());
owner->SetHighColor(tint_color(owner->ViewColor(), B_DARKEN_1_TINT));
// draw the type string
owner->DrawString(typeString);
// set the high color and low color back to the original
owner->SetHighColor(highColor);
owner->SetLowColor(lowColor);
}