Interface Kit: Adopt parent colors on controls

BControl adopts parent colors on AttachedToWindow(). Use the
adopted view and high colors for BControl derivatives before
using B_CONTROL or B_PANEL colors.

Affects the following controls:
Spinners
Checkboxes
Radio buttons
Sliders
Text controls
Buttons (get control text color already, don't pass it in.)

Affects control colors in HaikuControlLook and BeControlLook,
FlatControlLook control colors derived from HaikuControlLook.

Do not remove control flag before drawing label, we get the
correct label color now. The fallback colors are only for if
you override AttachedToWindow() on your BControl subclass to
prevent adopting parent colors.

Change-Id: I9357c0287898bff48c695a7869f3b8be108c02ad
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8235
Haiku-Format: Haiku-format Bot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
John Scipione
2024-09-05 17:45:01 +00:00
committed by waddlesplash
parent 5333610f85
commit 42df4f9689
9 changed files with 26 additions and 67 deletions
@@ -2201,6 +2201,8 @@ BeControlLook::DrawLabel(BView* view, const char* label, const rgb_color& base,
if (textColor != NULL) if (textColor != NULL)
glowColor = *textColor; glowColor = *textColor;
else if (view->Parent() != NULL)
glowColor = view->Parent()->HighColor();
else if ((flags & B_IS_CONTROL) != 0) else if ((flags & B_IS_CONTROL) != 0)
glowColor = ui_color(B_CONTROL_TEXT_COLOR); glowColor = ui_color(B_CONTROL_TEXT_COLOR);
else else
+2 -6
View File
@@ -361,7 +361,7 @@ SpinnerButton::Draw(BRect updateRect)
else else
bgTint = B_NO_TINT; bgTint = B_NO_TINT;
rgb_color bgColor = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color bgColor = ViewColor();
if (bgColor.red + bgColor.green + bgColor.blue <= 128 * 3) { if (bgColor.red + bgColor.green + bgColor.blue <= 128 * 3) {
// if dark background make the tint lighter // if dark background make the tint lighter
frameTint = 2.0f - frameTint; frameTint = 2.0f - frameTint;
@@ -1453,10 +1453,6 @@ BAbstractSpinner::_DrawLabel(BRect updateRect)
uint32 flags = be_control_look->Flags(this); uint32 flags = be_control_look->Flags(this);
// erase the is control flag before drawing the label so that the label
// will get drawn using B_PANEL_TEXT_COLOR.
flags &= ~BControlLook::B_IS_CONTROL;
be_control_look->DrawLabel(this, label, LowColor(), flags, BPoint(x, y)); be_control_look->DrawLabel(this, label, LowColor(), flags, BPoint(x, y));
} }
@@ -1469,7 +1465,7 @@ BAbstractSpinner::_DrawTextView(BRect updateRect)
if (!rect.IsValid() || !rect.Intersects(updateRect)) if (!rect.IsValid() || !rect.Intersects(updateRect))
return; return;
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color base = ViewColor();
uint32 flags = 0; uint32 flags = 0;
if (!IsEnabled()) if (!IsEnabled())
flags |= BControlLook::B_DISABLED; flags |= BControlLook::B_DISABLED;
+7 -12
View File
@@ -134,7 +134,6 @@ BButton::Draw(BRect updateRect)
BRect rect(Bounds()); BRect rect(Bounds());
rgb_color background = ViewColor(); rgb_color background = ViewColor();
rgb_color base = LowColor(); rgb_color base = LowColor();
rgb_color textColor = ui_color(B_CONTROL_TEXT_COLOR);
uint32 flags = be_control_look->Flags(this); uint32 flags = be_control_look->Flags(this);
if (_Flag(FLAG_DEFAULT)) if (_Flag(FLAG_DEFAULT))
@@ -144,24 +143,20 @@ BButton::Draw(BRect updateRect)
if (_Flag(FLAG_INSIDE)) if (_Flag(FLAG_INSIDE))
flags |= BControlLook::B_HOVER; flags |= BControlLook::B_HOVER;
be_control_look->DrawButtonFrame(this, rect, updateRect, be_control_look->DrawButtonFrame(this, rect, updateRect, base, background, flags);
base, background, flags);
if (fBehavior == B_POP_UP_BEHAVIOR) { if (fBehavior == B_POP_UP_BEHAVIOR)
be_control_look->DrawButtonWithPopUpBackground(this, rect, updateRect, be_control_look->DrawButtonWithPopUpBackground(this, rect, updateRect, base, flags);
base, flags); else
} else { be_control_look->DrawButtonBackground(this, rect, updateRect, base, flags);
be_control_look->DrawButtonBackground(this, rect, updateRect,
base, flags);
}
const BBitmap* icon = IconBitmap( const BBitmap* icon = IconBitmap(
(Value() == B_CONTROL_OFF (Value() == B_CONTROL_OFF
? B_INACTIVE_ICON_BITMAP : B_ACTIVE_ICON_BITMAP) ? B_INACTIVE_ICON_BITMAP : B_ACTIVE_ICON_BITMAP)
| (IsEnabled() ? 0 : B_DISABLED_ICON_BITMAP)); | (IsEnabled() ? 0 : B_DISABLED_ICON_BITMAP));
be_control_look->DrawLabel(this, Label(), icon, rect, updateRect, base, be_control_look->DrawLabel(this, Label(), icon, rect, updateRect, base, flags,
flags, BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE), &textColor); BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE));
} }
+2 -14
View File
@@ -103,14 +103,7 @@ BCheckBox::Archive(BMessage* data, bool deep) const
void void
BCheckBox::Draw(BRect updateRect) BCheckBox::Draw(BRect updateRect)
{ {
rgb_color base, textColor; rgb_color base = ViewColor();
if (Parent() != NULL) {
base = Parent()->ViewColor();
textColor = Parent()->HighColor();
} else {
base = ui_color(B_PANEL_BACKGROUND_COLOR);
textColor = ui_color(B_PANEL_TEXT_COLOR);
}
uint32 flags = be_control_look->Flags(this); uint32 flags = be_control_look->Flags(this);
if (fOutlined) if (fOutlined)
@@ -120,10 +113,6 @@ BCheckBox::Draw(BRect updateRect)
BRect rect(checkBoxRect); BRect rect(checkBoxRect);
be_control_look->DrawCheckBox(this, rect, updateRect, base, flags); be_control_look->DrawCheckBox(this, rect, updateRect, base, flags);
// erase the is control flag before drawing the label so that the label
// will get drawn using B_PANEL_TEXT_COLOR
flags &= ~BControlLook::B_IS_CONTROL;
BRect labelRect(Bounds()); BRect labelRect(Bounds());
labelRect.left = checkBoxRect.right + 1 labelRect.left = checkBoxRect.right + 1
+ be_control_look->DefaultLabelSpacing(); + be_control_look->DefaultLabelSpacing();
@@ -132,8 +121,7 @@ BCheckBox::Draw(BRect updateRect)
B_INACTIVE_ICON_BITMAP | (IsEnabled() ? 0 : B_DISABLED_ICON_BITMAP)); B_INACTIVE_ICON_BITMAP | (IsEnabled() ? 0 : B_DISABLED_ICON_BITMAP));
const BAlignment alignment = BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_CENTER); const BAlignment alignment = BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_CENTER);
be_control_look->DrawLabel(this, Label(), icon, labelRect, updateRect, base, flags, alignment, be_control_look->DrawLabel(this, Label(), icon, labelRect, updateRect, base, flags, alignment);
&textColor);
} }
+2 -2
View File
@@ -430,7 +430,7 @@ BColorControl::_DrawColorArea(BView* target, BRect updateRect)
BRect rect = _PaletteFrame(); BRect rect = _PaletteFrame();
bool enabled = IsEnabled(); bool enabled = IsEnabled();
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color base = ViewColor();
rgb_color darken1 = tint_color(base, B_DARKEN_1_TINT); rgb_color darken1 = tint_color(base, B_DARKEN_1_TINT);
uint32 flags = be_control_look->Flags(this); uint32 flags = be_control_look->Flags(this);
@@ -498,7 +498,7 @@ BColorControl::_DrawColorArea(BView* target, BRect updateRect)
void void
BColorControl::_DrawSelectors(BView* target) BColorControl::_DrawSelectors(BView* target)
{ {
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color base = ViewColor();
rgb_color lightenmax = tint_color(base, B_LIGHTEN_MAX_TINT); rgb_color lightenmax = tint_color(base, B_LIGHTEN_MAX_TINT);
if (fPaletteMode) { if (fPaletteMode) {
+5 -6
View File
@@ -2197,12 +2197,9 @@ HaikuControlLook::DrawLabel(BView* view, const char* label, const rgb_color& bas
// setup the text color // setup the text color
BWindow* window = view->Window(); BWindow* window = view->Window();
bool isDesktop = window bool isDesktop = window != NULL && window->Feel() == kDesktopWindowFeel
&& window->Feel() == kDesktopWindowFeel && window->Look() == kDesktopWindowLook && view->Parent() != NULL
&& window->Look() == kDesktopWindowLook && view->Parent()->Parent() == NULL && (flags & B_IGNORE_OUTLINE) == 0;
&& view->Parent()
&& view->Parent()->Parent() == NULL
&& (flags & B_IGNORE_OUTLINE) == 0;
rgb_color low; rgb_color low;
rgb_color color; rgb_color color;
@@ -2210,6 +2207,8 @@ HaikuControlLook::DrawLabel(BView* view, const char* label, const rgb_color& bas
if (textColor != NULL) if (textColor != NULL)
glowColor = *textColor; glowColor = *textColor;
else if (view->Parent() != NULL)
glowColor = view->Parent()->HighColor();
else if ((flags & B_IS_CONTROL) != 0) else if ((flags & B_IS_CONTROL) != 0)
glowColor = ui_color(B_CONTROL_TEXT_COLOR); glowColor = ui_color(B_CONTROL_TEXT_COLOR);
else else
+3 -15
View File
@@ -85,19 +85,12 @@ BRadioButton::Archive(BMessage* data, bool deep) const
void void
BRadioButton::Draw(BRect updateRect) BRadioButton::Draw(BRect updateRect)
{ {
rgb_color base = ViewColor();
// its size depends on the text height // its size depends on the text height
font_height fontHeight; font_height fontHeight;
GetFontHeight(&fontHeight); GetFontHeight(&fontHeight);
rgb_color base, textColor;
if (Parent() != NULL) {
base = Parent()->ViewColor();
textColor = Parent()->HighColor();
} else {
base = ui_color(B_PANEL_BACKGROUND_COLOR);
textColor = ui_color(B_PANEL_TEXT_COLOR);
}
uint32 flags = be_control_look->Flags(this); uint32 flags = be_control_look->Flags(this);
if (fOutlined) if (fOutlined)
flags |= BControlLook::B_CLICKED; flags |= BControlLook::B_CLICKED;
@@ -106,10 +99,6 @@ BRadioButton::Draw(BRect updateRect)
BRect rect(knobRect); BRect rect(knobRect);
be_control_look->DrawRadioButton(this, rect, updateRect, base, flags); be_control_look->DrawRadioButton(this, rect, updateRect, base, flags);
// erase the is control flag before drawing the label so that the label
// will get drawn using B_PANEL_TEXT_COLOR.
flags &= ~BControlLook::B_IS_CONTROL;
BRect labelRect(Bounds()); BRect labelRect(Bounds());
labelRect.left = knobRect.right + 1 + be_control_look->DefaultLabelSpacing(); labelRect.left = knobRect.right + 1 + be_control_look->DefaultLabelSpacing();
@@ -117,8 +106,7 @@ BRadioButton::Draw(BRect updateRect)
B_INACTIVE_ICON_BITMAP | (IsEnabled() ? 0 : B_DISABLED_ICON_BITMAP)); B_INACTIVE_ICON_BITMAP | (IsEnabled() ? 0 : B_DISABLED_ICON_BITMAP));
const BAlignment alignment = BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_CENTER); const BAlignment alignment = BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_CENTER);
be_control_look->DrawLabel(this, Label(), icon, labelRect, updateRect, base, flags, alignment, be_control_look->DrawLabel(this, Label(), icon, labelRect, updateRect, base, flags, alignment);
&textColor);
} }
+2 -6
View File
@@ -434,7 +434,7 @@ BSlider::AllAttached()
// standard system colors manually. Due to how layouts work, this must // standard system colors manually. Due to how layouts work, this must
// happen here, rather than in AttachedToWindow(). // happen here, rather than in AttachedToWindow().
if (Parent() == NULL) if (Parent() == NULL)
SetLowUIColor(B_PANEL_BACKGROUND_COLOR); SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
} }
@@ -971,13 +971,9 @@ BSlider::DrawText()
BRect bounds(Bounds()); BRect bounds(Bounds());
BView* view = OffscreenView(); BView* view = OffscreenView();
rgb_color base = LowColor(); rgb_color base = ViewColor();
uint32 flags = be_control_look->Flags(this); uint32 flags = be_control_look->Flags(this);
// erase the is control flag before drawing the label so that the label
// will get drawn using B_PANEL_TEXT_COLOR
flags &= ~BControlLook::B_IS_CONTROL;
font_height fontHeight; font_height fontHeight;
GetFontHeight(&fontHeight); GetFontHeight(&fontHeight);
if (Orientation() == B_HORIZONTAL) { if (Orientation() == B_HORIZONTAL) {
+1 -6
View File
@@ -367,8 +367,7 @@ BTextControl::Draw(BRect updateRect)
if (active) if (active)
flags |= BControlLook::B_FOCUSED; flags |= BControlLook::B_FOCUSED;
be_control_look->DrawTextControlBorder(this, rect, updateRect, base, be_control_look->DrawTextControlBorder(this, rect, updateRect, base, flags);
flags);
if (Label() != NULL) { if (Label() != NULL) {
if (fLayoutData->label_layout_item != NULL) { if (fLayoutData->label_layout_item != NULL) {
@@ -378,10 +377,6 @@ BTextControl::Draw(BRect updateRect)
rect.right = fDivider - kLabelInputSpacing; rect.right = fDivider - kLabelInputSpacing;
} }
// erase the is control flag before drawing the label so that the label
// will get drawn using B_PANEL_TEXT_COLOR
flags &= ~BControlLook::B_IS_CONTROL;
be_control_look->DrawLabel(this, Label(), rect, updateRect, be_control_look->DrawLabel(this, Label(), rect, updateRect,
base, flags, BAlignment(fLabelAlign, B_ALIGN_MIDDLE)); base, flags, BAlignment(fLabelAlign, B_ALIGN_MIDDLE));
} }