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)
glowColor = *textColor;
else if (view->Parent() != NULL)
glowColor = view->Parent()->HighColor();
else if ((flags & B_IS_CONTROL) != 0)
glowColor = ui_color(B_CONTROL_TEXT_COLOR);
else
+2 -6
View File
@@ -361,7 +361,7 @@ SpinnerButton::Draw(BRect updateRect)
else
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 dark background make the tint lighter
frameTint = 2.0f - frameTint;
@@ -1453,10 +1453,6 @@ BAbstractSpinner::_DrawLabel(BRect updateRect)
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));
}
@@ -1469,7 +1465,7 @@ BAbstractSpinner::_DrawTextView(BRect updateRect)
if (!rect.IsValid() || !rect.Intersects(updateRect))
return;
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
rgb_color base = ViewColor();
uint32 flags = 0;
if (!IsEnabled())
flags |= BControlLook::B_DISABLED;
+7 -12
View File
@@ -134,7 +134,6 @@ BButton::Draw(BRect updateRect)
BRect rect(Bounds());
rgb_color background = ViewColor();
rgb_color base = LowColor();
rgb_color textColor = ui_color(B_CONTROL_TEXT_COLOR);
uint32 flags = be_control_look->Flags(this);
if (_Flag(FLAG_DEFAULT))
@@ -144,24 +143,20 @@ BButton::Draw(BRect updateRect)
if (_Flag(FLAG_INSIDE))
flags |= BControlLook::B_HOVER;
be_control_look->DrawButtonFrame(this, rect, updateRect,
base, background, flags);
be_control_look->DrawButtonFrame(this, rect, updateRect, base, background, flags);
if (fBehavior == B_POP_UP_BEHAVIOR) {
be_control_look->DrawButtonWithPopUpBackground(this, rect, updateRect,
base, flags);
} else {
be_control_look->DrawButtonBackground(this, rect, updateRect,
base, flags);
}
if (fBehavior == B_POP_UP_BEHAVIOR)
be_control_look->DrawButtonWithPopUpBackground(this, rect, updateRect, base, flags);
else
be_control_look->DrawButtonBackground(this, rect, updateRect, base, flags);
const BBitmap* icon = IconBitmap(
(Value() == B_CONTROL_OFF
? B_INACTIVE_ICON_BITMAP : B_ACTIVE_ICON_BITMAP)
| (IsEnabled() ? 0 : B_DISABLED_ICON_BITMAP));
be_control_look->DrawLabel(this, Label(), icon, rect, updateRect, base,
flags, BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE), &textColor);
be_control_look->DrawLabel(this, Label(), icon, rect, updateRect, base, flags,
BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE));
}
+2 -14
View File
@@ -103,14 +103,7 @@ BCheckBox::Archive(BMessage* data, bool deep) const
void
BCheckBox::Draw(BRect updateRect)
{
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);
}
rgb_color base = ViewColor();
uint32 flags = be_control_look->Flags(this);
if (fOutlined)
@@ -120,10 +113,6 @@ BCheckBox::Draw(BRect updateRect)
BRect rect(checkBoxRect);
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());
labelRect.left = checkBoxRect.right + 1
+ be_control_look->DefaultLabelSpacing();
@@ -132,8 +121,7 @@ BCheckBox::Draw(BRect updateRect)
B_INACTIVE_ICON_BITMAP | (IsEnabled() ? 0 : B_DISABLED_ICON_BITMAP));
const BAlignment alignment = BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_CENTER);
be_control_look->DrawLabel(this, Label(), icon, labelRect, updateRect, base, flags, alignment,
&textColor);
be_control_look->DrawLabel(this, Label(), icon, labelRect, updateRect, base, flags, alignment);
}
+2 -2
View File
@@ -430,7 +430,7 @@ BColorControl::_DrawColorArea(BView* target, BRect updateRect)
BRect rect = _PaletteFrame();
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);
uint32 flags = be_control_look->Flags(this);
@@ -498,7 +498,7 @@ BColorControl::_DrawColorArea(BView* target, BRect updateRect)
void
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);
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
BWindow* window = view->Window();
bool isDesktop = window
&& window->Feel() == kDesktopWindowFeel
&& window->Look() == kDesktopWindowLook
&& view->Parent()
&& view->Parent()->Parent() == NULL
&& (flags & B_IGNORE_OUTLINE) == 0;
bool isDesktop = window != NULL && window->Feel() == kDesktopWindowFeel
&& window->Look() == kDesktopWindowLook && view->Parent() != NULL
&& view->Parent()->Parent() == NULL && (flags & B_IGNORE_OUTLINE) == 0;
rgb_color low;
rgb_color color;
@@ -2210,6 +2207,8 @@ HaikuControlLook::DrawLabel(BView* view, const char* label, const rgb_color& bas
if (textColor != NULL)
glowColor = *textColor;
else if (view->Parent() != NULL)
glowColor = view->Parent()->HighColor();
else if ((flags & B_IS_CONTROL) != 0)
glowColor = ui_color(B_CONTROL_TEXT_COLOR);
else
+3 -15
View File
@@ -85,19 +85,12 @@ BRadioButton::Archive(BMessage* data, bool deep) const
void
BRadioButton::Draw(BRect updateRect)
{
rgb_color base = ViewColor();
// its size depends on the text height
font_height 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);
if (fOutlined)
flags |= BControlLook::B_CLICKED;
@@ -106,10 +99,6 @@ BRadioButton::Draw(BRect updateRect)
BRect rect(knobRect);
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());
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));
const BAlignment alignment = BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_CENTER);
be_control_look->DrawLabel(this, Label(), icon, labelRect, updateRect, base, flags, alignment,
&textColor);
be_control_look->DrawLabel(this, Label(), icon, labelRect, updateRect, base, flags, alignment);
}
+2 -6
View File
@@ -434,7 +434,7 @@ BSlider::AllAttached()
// standard system colors manually. Due to how layouts work, this must
// happen here, rather than in AttachedToWindow().
if (Parent() == NULL)
SetLowUIColor(B_PANEL_BACKGROUND_COLOR);
SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
}
@@ -971,13 +971,9 @@ BSlider::DrawText()
BRect bounds(Bounds());
BView* view = OffscreenView();
rgb_color base = LowColor();
rgb_color base = ViewColor();
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;
GetFontHeight(&fontHeight);
if (Orientation() == B_HORIZONTAL) {
+1 -6
View File
@@ -367,8 +367,7 @@ BTextControl::Draw(BRect updateRect)
if (active)
flags |= BControlLook::B_FOCUSED;
be_control_look->DrawTextControlBorder(this, rect, updateRect, base,
flags);
be_control_look->DrawTextControlBorder(this, rect, updateRect, base, flags);
if (Label() != NULL) {
if (fLayoutData->label_layout_item != NULL) {
@@ -378,10 +377,6 @@ BTextControl::Draw(BRect updateRect)
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,
base, flags, BAlignment(fLabelAlign, B_ALIGN_MIDDLE));
}