Interface: Rework and use B_CONTROL_BACKGROUND_COLOR for controls.

Presently, the control color is heavily tinted almost everywere
it's used, making it difficult to set from Appearance preferences,
and making the default theme not look so good in "dark mode."

After this patch, the defaults are changed to something much closer
to the actual final color used in buttons and scrollbars, and the tints
thus heavily reduced as a result.

B_CONTROL_BACKGROUND_COLOR wasn't present on BeOS, so it should
be safe to change its default. Some logic is added to app_server to
automatically migrate to the new color if the old default is present.

(This is based on nephele's initial patch, but significantly reworked
so that existing installs are upgraded as seamlessly as possible,
with few or very minor visual differences.)

Co-authored-by: Pascal Abresch <[email protected]>
Change-Id: Ida9fbaa61df9aeb89a9daf59cd9901a34737d5f9
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8878
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
Augustin Cavalier
2025-06-23 19:46:26 +00:00
committed by waddlesplash
co-authored by Pascal Abresch
parent 2a349a0a41
commit 91bed92e07
9 changed files with 78 additions and 56 deletions
+24 -3
View File
@@ -171,6 +171,9 @@ public:
const BMessage* message);
virtual void MessageReceived(BMessage* message);
void AdoptSystemColors();
bool HasSystemColors() const;
bool IsEnabled() const { return fIsEnabled; }
virtual void SetEnabled(bool enable) { fIsEnabled = enable; };
@@ -322,7 +325,7 @@ SpinnerButton::AttachedToWindow()
{
fParent = static_cast<BAbstractSpinner*>(Parent());
AdoptParentColors();
AdoptSystemColors();
BView::AttachedToWindow();
}
@@ -425,8 +428,6 @@ SpinnerButton::Draw(BRect updateRect)
if (rect.IntegerHeight() % 2 != 0)
rect.bottom -= 1;
SetHighColor(tint_color(bgColor, fgTint));
// draw the +/-
float halfHeight = floorf(rect.Height() / 2);
StrokeLine(BPoint(rect.left, rect.top + halfHeight),
@@ -441,6 +442,26 @@ SpinnerButton::Draw(BRect updateRect)
}
void
SpinnerButton::AdoptSystemColors()
{
SetViewUIColor(B_CONTROL_BACKGROUND_COLOR);
SetLowUIColor(B_CONTROL_BACKGROUND_COLOR);
SetHighUIColor(B_CONTROL_TEXT_COLOR);
}
bool
SpinnerButton::HasSystemColors() const
{
float tint = B_NO_TINT;
return ViewUIColor(&tint) == B_CONTROL_BACKGROUND_COLOR && tint == B_NO_TINT
&& LowUIColor(&tint) == B_CONTROL_BACKGROUND_COLOR && tint == B_NO_TINT
&& HighUIColor(&tint) == B_CONTROL_TEXT_COLOR && tint == B_NO_TINT;
}
void
SpinnerButton::MouseDown(BPoint where)
{
+2 -11
View File
@@ -162,15 +162,7 @@ _BMCMenuBar_::AttachedToWindow()
if (fFixedSize && (Flags() & B_SUPPORTS_LAYOUT) == 0)
SetResizingMode(B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
if (Parent() != NULL) {
color_which which = Parent()->LowUIColor();
if (which == B_NO_COLOR)
SetLowColor(Parent()->LowColor());
else
SetLowUIColor(which);
} else
SetLowUIColor(B_MENU_BACKGROUND_COLOR);
SetLowUIColor(B_CONTROL_BACKGROUND_COLOR);
fPreviousWidth = Bounds().Width();
}
@@ -198,7 +190,6 @@ _BMCMenuBar_::Draw(BRect updateRect)
}
BRect rect(Bounds());
rgb_color base = ui_color(B_MENU_BACKGROUND_COLOR);
uint32 flags = 0;
if (!IsEnabled())
flags |= BControlLook::B_DISABLED;
@@ -206,7 +197,7 @@ _BMCMenuBar_::Draw(BRect updateRect)
flags |= BControlLook::B_FOCUSED;
be_control_look->DrawMenuFieldBackground(this, rect,
updateRect, base, fShowPopUpMarker, flags);
updateRect, LowColor(), fShowPopUpMarker, flags);
DrawItems(updateRect);
}
+3 -7
View File
@@ -134,6 +134,7 @@ BButton::Draw(BRect updateRect)
BRect rect(Bounds());
rgb_color background = ViewColor();
rgb_color base = LowColor();
rgb_color text = HighColor();
uint32 flags = be_control_look->Flags(this);
if (_Flag(FLAG_DEFAULT))
@@ -156,7 +157,7 @@ BButton::Draw(BRect updateRect)
| (IsEnabled() ? 0 : B_DISABLED_ICON_BITMAP));
be_control_look->DrawLabel(this, Label(), icon, rect, updateRect, base, flags,
BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE));
BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE), &text);
}
@@ -221,12 +222,7 @@ void
BButton::AttachedToWindow()
{
BControl::AttachedToWindow();
// tint low color to match background
if (ViewColor().IsLight())
SetLowUIColor(B_CONTROL_BACKGROUND_COLOR, 1.115);
else
SetLowUIColor(B_CONTROL_BACKGROUND_COLOR, 0.885);
SetLowUIColor(B_CONTROL_BACKGROUND_COLOR);
SetHighUIColor(B_CONTROL_TEXT_COLOR);
if (IsDefault())
+1 -1
View File
@@ -611,7 +611,7 @@ BChannelSlider::DrawThumb(BView* into, int32 channel, BPoint where,
rect.top = floorf(rect.top);
rect.right = ceilf(rect.right + 0.5);
rect.bottom = ceilf(rect.bottom + 0.5);
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
rgb_color base = ui_color(B_CONTROL_BACKGROUND_COLOR);
uint32 flags = 0;
be_control_look->DrawSliderThumb(into, rect, rect, base,
flags, Orientation());
+31 -28
View File
@@ -28,8 +28,6 @@
namespace BPrivate {
static const float kEdgeBevelLightTint = 0.59;
static const float kEdgeBevelShadowTint = 1.0735;
static const float kHoverTintFactor = 0.85;
static const int32 kButtonPopUpIndicatorWidth = B_USE_ITEM_SPACING;
@@ -2779,7 +2777,10 @@ HaikuControlLook::_DrawButtonBackground(BView* view, BRect& rect,
&& (flags & (B_ACTIVATED | B_PARTIALLY_ACTIVATED)) == 0
&& ((flags & (B_HOVER | B_FOCUSED)) == 0
|| (flags & B_DISABLED) != 0)) {
_DrawFlatButtonBackground(view, rect, updateRect, base, popupIndicator,
rgb_color flatBase = base;
if (view->Parent() != NULL)
flatBase = view->Parent()->LowColor();
_DrawFlatButtonBackground(view, rect, updateRect, flatBase, popupIndicator,
flags, borders, orientation);
} else {
BRegion clipping(rect);
@@ -2829,12 +2830,12 @@ HaikuControlLook::_DrawNonFlatButtonBackground(BView* view, BRect& rect,
rgb_color bevelLightColor = _BevelLightColor(base, flags);
rgb_color bevelShadowColor = _BevelShadowColor(base, flags);
// button background color
rgb_color buttonBgColor;
// button corners color
rgb_color buttonCornerColor;
if ((flags & B_DISABLED) != 0)
buttonBgColor = tint_color(base, 0.7);
buttonCornerColor = tint_color(base, 0.84 /* lighten "< 1" */);
else
buttonBgColor = tint_color(base, B_LIGHTEN_1_TINT);
buttonCornerColor = tint_color(base, 0.7 /* lighten "< 1" */);
// surface top gradient
BGradientLinear fillGradient;
@@ -2929,7 +2930,7 @@ HaikuControlLook::_DrawNonFlatButtonBackground(BView* view, BRect& rect,
_DrawFrame(view, rect,
bevelLightColor, bevelLightColor,
bevelShadowColor, bevelShadowColor,
buttonBgColor, buttonBgColor, borders);
buttonCornerColor, buttonCornerColor, borders);
}
if (popupIndicator) {
@@ -3679,7 +3680,7 @@ HaikuControlLook::_EdgeColor(const rgb_color& base, bool shadow, uint32 flags)
edgeColor = (rgb_color){ value, value, value, alpha };
} else {
float tint = shadow ? kEdgeBevelShadowTint : kEdgeBevelLightTint;
float tint = shadow ? 1.0735 : 0.59;
if ((flags & B_DEFAULT_BUTTON) != 0) {
if ((flags & B_DISABLED) != 0)
tint = B_NO_TINT + (tint - B_NO_TINT) * 0.3;
@@ -3718,7 +3719,7 @@ HaikuControlLook::_FrameLightColor(const rgb_color& base, uint32 flags)
if ((flags & B_BLEND_FRAME) != 0)
frameLightColor = (rgb_color){ 0, 0, 0, 75 };
else
frameLightColor = tint_color(base, 1.33);
frameLightColor = tint_color(base, 1.35);
if ((flags & B_DEFAULT_BUTTON) != 0)
frameLightColor = tint_color(frameLightColor, 1.35);
@@ -3741,7 +3742,7 @@ HaikuControlLook::_FrameShadowColor(const rgb_color& base, uint32 flags)
if ((flags & B_DISABLED) != 0) {
// TODO: B_BLEND_FRAME
frameShadowColor = tint_color(base, 1.24);
frameShadowColor = tint_color(base, 1.26);
if ((flags & B_DEFAULT_BUTTON) != 0) {
frameShadowColor = tint_color(base, 1.145);
@@ -3759,7 +3760,7 @@ HaikuControlLook::_FrameShadowColor(const rgb_color& base, uint32 flags)
if ((flags & B_BLEND_FRAME) != 0)
frameShadowColor = (rgb_color){ 0, 0, 0, 95 };
else
frameShadowColor = tint_color(base, 1.47);
frameShadowColor = tint_color(base, 1.485);
}
}
@@ -3770,13 +3771,14 @@ HaikuControlLook::_FrameShadowColor(const rgb_color& base, uint32 flags)
rgb_color
HaikuControlLook::_BevelLightColor(const rgb_color& base, uint32 flags)
{
rgb_color bevelLightColor = tint_color(base, 0.2);
if ((flags & B_DISABLED) != 0)
bevelLightColor = tint_color(base, B_LIGHTEN_1_TINT);
rgb_color bevelLightColor;
if ((flags & B_ACTIVATED) != 0)
bevelLightColor = tint_color(base, B_DARKEN_1_TINT);
bevelLightColor = tint_color(base, 1.17);
else if ((flags & B_DISABLED) != 0)
bevelLightColor = tint_color(base, B_LIGHTEN_1_TINT);
else
bevelLightColor = tint_color(base, 0.2);
return bevelLightColor;
}
@@ -3785,13 +3787,14 @@ HaikuControlLook::_BevelLightColor(const rgb_color& base, uint32 flags)
rgb_color
HaikuControlLook::_BevelShadowColor(const rgb_color& base, uint32 flags)
{
rgb_color bevelShadowColor = tint_color(base, 1.08);
if ((flags & B_DISABLED) != 0)
bevelShadowColor = base;
rgb_color bevelShadowColor;
if ((flags & B_ACTIVATED) != 0)
bevelShadowColor = tint_color(base, B_DARKEN_1_TINT);
bevelShadowColor = tint_color(base, 1.17);
else if ((flags & B_DISABLED) != 0)
bevelShadowColor = base;
else
bevelShadowColor = tint_color(base, 1.105);
return bevelShadowColor;
}
@@ -3857,14 +3860,14 @@ void
HaikuControlLook::_MakeButtonGradient(BGradientLinear& gradient, BRect& rect,
const rgb_color& base, uint32 flags, orientation orientation) const
{
float topTint = 0.49;
float middleTint1 = 0.62;
float middleTint2 = 0.76;
float bottomTint = 0.90;
float topTint = 0.6;
float middleTint1 = 0.75;
float middleTint2 = 0.9;
float bottomTint = 1.01;
if ((flags & B_ACTIVATED) != 0) {
topTint = 1.11;
bottomTint = 1.08;
topTint = 1.135;
bottomTint = 1.105;
}
if ((flags & B_DISABLED) != 0) {
+1 -1
View File
@@ -85,7 +85,7 @@ static const rgb_color _kDefaultColors[kColorWhichCount] = {
{0, 0, 0, 255}, // B_PANEL_TEXT_COLOR
{255, 255, 255, 255}, // B_DOCUMENT_BACKGROUND_COLOR
{0, 0, 0, 255}, // B_DOCUMENT_TEXT_COLOR
{245, 245, 245, 255}, // B_CONTROL_BACKGROUND_COLOR
{222, 222, 222, 255}, // B_CONTROL_BACKGROUND_COLOR
{0, 0, 0, 255}, // B_CONTROL_TEXT_COLOR
{172, 172, 172, 255}, // B_CONTROL_BORDER_COLOR
{102, 152, 203, 255}, // B_CONTROL_HIGHLIGHT_COLOR
+2 -2
View File
@@ -1593,7 +1593,7 @@ BSlider::_DrawBlockThumb()
BRect frame = ThumbFrame();
BView* view = OffscreenView();
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
rgb_color base = ui_color(B_CONTROL_BACKGROUND_COLOR);
uint32 flags = be_control_look->Flags(this);
be_control_look->DrawSliderThumb(view, frame, frame, base, flags,
fOrientation);
@@ -1605,7 +1605,7 @@ BSlider::_DrawTriangleThumb()
{
BRect frame = ThumbFrame();
BView* view = OffscreenView();
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
rgb_color base = ui_color(B_CONTROL_BACKGROUND_COLOR);
uint32 flags = be_control_look->Flags(this);
be_control_look->DrawSliderTriangle(view, frame, frame, base, flags,
fOrientation);
+3 -3
View File
@@ -336,15 +336,15 @@ ColorsView::_SetColor(color_which which, rgb_color color)
const bool isDark = color.IsDark();
_SetOneColor(B_MENU_BACKGROUND_COLOR, color);
_SetOneColor(B_SCROLL_BAR_THUMB_COLOR, color);
const rgb_color menuSelectedBackground
= tint_color(color, isDark ? 0.8 /* lighten "< 1" */ : B_DARKEN_2_TINT);
_SetOneColor(B_MENU_SELECTED_BACKGROUND_COLOR, menuSelectedBackground);
const rgb_color controlBackground = tint_color(color, isDark
? 0.8 /* lighten "< 1" */ : 0.25 /* lighten "> 2" */);
const rgb_color controlBackground = tint_color(color,
0.84 /* lighten "< 1" */);
_SetOneColor(B_CONTROL_BACKGROUND_COLOR, controlBackground);
_SetOneColor(B_SCROLL_BAR_THUMB_COLOR, controlBackground);
const rgb_color controlBorder
= tint_color(color, isDark ? 0.4875 : 1.20 /* lighten/darken "1.5" */);
+11
View File
@@ -547,6 +547,17 @@ Desktop::Init()
const_cast<menu_info&>(fSettings->MenuInfo()).font_size = fontSize;
}
#if 1
// Migrate old default UI control color to the new one.
// TODO: Drop this after R1/beta6 is released!
if (fSettings->UIColor(B_CONTROL_BACKGROUND_COLOR) == make_color(245, 245, 245)
&& fSettings->ControlLook().IsEmpty()) {
rgb_color newControlBackground = make_color(222, 222, 222);
fSettings->SetUIColor(B_CONTROL_BACKGROUND_COLOR, newControlBackground);
fSettings->SetUIColor(B_SCROLL_BAR_THUMB_COLOR, newControlBackground);
}
#endif
HWInterface()->SetDPMSMode(B_DPMS_ON);
float brightness = fWorkspaces[0].StoredScreenConfiguration().Brightness(0);