Skip to content

Commit a87391a

Browse files
authored
Merge pull request #20308 from NABN00B/themable-slider-colors
Make slider colors themable
2 parents c817a07 + fd9fe26 commit a87391a

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

Common/UI/View.cpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,20 +1590,27 @@ void Slider::Clamp() {
15901590

15911591
void Slider::Draw(UIContext &dc) {
15921592
bool focus = HasFocus();
1593-
uint32_t linecolor = dc.theme->itemStyle.fgColor;
1594-
Style knobStyle = (down_ || focus) ? dc.theme->itemStyle : dc.theme->popupStyle;
1593+
uint32_t sliderColor;
1594+
1595+
if (down_) {
1596+
sliderColor = popupStyle_ ? dc.theme->popupSliderFocusedColor : dc.theme->itemDownStyle.fgColor;
1597+
} else if (focus) {
1598+
sliderColor = popupStyle_ ? dc.theme->popupSliderFocusedColor : dc.theme->itemFocusedStyle.fgColor;
1599+
} else {
1600+
sliderColor = popupStyle_ ? dc.theme->popupSliderColor : dc.theme->itemStyle.fgColor;
1601+
}
15951602

15961603
float knobX = ((float)(*value_) - minValue_) / (maxValue_ - minValue_) * (bounds_.w - paddingLeft_ - paddingRight_) + (bounds_.x + paddingLeft_);
1597-
dc.FillRect(Drawable(linecolor), Bounds(bounds_.x + paddingLeft_, bounds_.centerY() - 2, knobX - (bounds_.x + paddingLeft_), 4));
1604+
dc.FillRect(Drawable(sliderColor), Bounds(bounds_.x + paddingLeft_, bounds_.centerY() - 2, knobX - (bounds_.x + paddingLeft_), 4));
15981605
dc.FillRect(Drawable(0xFF808080), Bounds(knobX, bounds_.centerY() - 2, (bounds_.x + bounds_.w - paddingRight_ - knobX), 4));
1599-
dc.Draw()->DrawImage(dc.theme->sliderKnob, knobX, bounds_.centerY(), 1.0f, knobStyle.fgColor, ALIGN_CENTER);
1606+
dc.Draw()->DrawImage(dc.theme->sliderKnob, knobX, bounds_.centerY(), 1.0f, sliderColor, ALIGN_CENTER);
16001607
char temp[64];
16011608
if (showPercent_)
16021609
snprintf(temp, sizeof(temp), "%d%%", *value_);
16031610
else
16041611
snprintf(temp, sizeof(temp), "%d", *value_);
16051612
dc.SetFontStyle(dc.theme->uiFont);
1606-
dc.DrawText(temp, bounds_.x2() - 22, bounds_.centerY(), dc.theme->popupStyle.fgColor, ALIGN_CENTER | FLAG_DYNAMIC_ASCII);
1613+
dc.DrawText(temp, bounds_.x2() - 22, bounds_.centerY(), sliderColor, ALIGN_CENTER | FLAG_DYNAMIC_ASCII);
16071614
}
16081615

16091616
std::string Slider::DescribeText() const {
@@ -1743,17 +1750,24 @@ void SliderFloat::Clamp() {
17431750

17441751
void SliderFloat::Draw(UIContext &dc) {
17451752
bool focus = HasFocus();
1746-
uint32_t linecolor = dc.theme->itemStyle.fgColor;
1747-
Style knobStyle = (down_ || focus) ? dc.theme->itemStyle : dc.theme->popupStyle;
1753+
uint32_t sliderColor;
1754+
1755+
if (down_) {
1756+
sliderColor = popupStyle_ ? dc.theme->popupSliderFocusedColor : dc.theme->itemDownStyle.fgColor;
1757+
} else if (focus) {
1758+
sliderColor = popupStyle_ ? dc.theme->popupSliderFocusedColor : dc.theme->itemFocusedStyle.fgColor;
1759+
} else {
1760+
sliderColor = popupStyle_ ? dc.theme->popupSliderColor : dc.theme->itemStyle.fgColor;
1761+
}
17481762

17491763
float knobX = (*value_ - minValue_) / (maxValue_ - minValue_) * (bounds_.w - paddingLeft_ - paddingRight_) + (bounds_.x + paddingLeft_);
1750-
dc.FillRect(Drawable(linecolor), Bounds(bounds_.x + paddingLeft_, bounds_.centerY() - 2, knobX - (bounds_.x + paddingLeft_), 4));
1764+
dc.FillRect(Drawable(sliderColor), Bounds(bounds_.x + paddingLeft_, bounds_.centerY() - 2, knobX - (bounds_.x + paddingLeft_), 4));
17511765
dc.FillRect(Drawable(0xFF808080), Bounds(knobX, bounds_.centerY() - 2, (bounds_.x + bounds_.w - paddingRight_ - knobX), 4));
1752-
dc.Draw()->DrawImage(dc.theme->sliderKnob, knobX, bounds_.centerY(), 1.0f, knobStyle.fgColor, ALIGN_CENTER);
1766+
dc.Draw()->DrawImage(dc.theme->sliderKnob, knobX, bounds_.centerY(), 1.0f, sliderColor, ALIGN_CENTER);
17531767
char temp[64];
17541768
snprintf(temp, sizeof(temp), "%0.2f", *value_);
17551769
dc.SetFontStyle(dc.theme->uiFont);
1756-
dc.DrawText(temp, bounds_.x2() - 22, bounds_.centerY(), dc.theme->popupStyle.fgColor, ALIGN_CENTER);
1770+
dc.DrawText(temp, bounds_.x2() - 22, bounds_.centerY(), sliderColor, ALIGN_CENTER);
17571771
}
17581772

17591773
std::string SliderFloat::DescribeText() const {

Common/UI/View.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ struct Theme {
116116

117117
uint32_t backgroundColor;
118118
uint32_t scrollbarColor;
119+
uint32_t popupSliderColor;
120+
uint32_t popupSliderFocusedColor;
119121
};
120122

121123
// The four cardinal directions should be enough, plus Prev/Next in "element order".

UI/Theme.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ struct ThemeInfo {
5959
uint32_t uCollapsibleHeaderStyleBg = 0x55000000;
6060
uint32_t uBackgroundColor = 0xFF754D24;
6161
uint32_t uScrollbarColor = 0x80FFFFFF;
62+
uint32_t uPopupSliderColor = 0xFFFFFFFF;
63+
uint32_t uPopupSliderFocusedColor = 0xFFEDC24C;
6264

6365
std::string sUIAtlas = "ui_atlas";
6466

@@ -154,6 +156,8 @@ static void LoadThemeInfo(const std::vector<Path> &directories) {
154156
section.Get("CollapsibleHeaderStyleBg", &info.uCollapsibleHeaderStyleBg, info.uItemStyleBg);
155157
section.Get("BackgroundColor", &info.uBackgroundColor, info.uBackgroundColor);
156158
section.Get("ScrollbarColor", &info.uScrollbarColor, info.uScrollbarColor);
159+
section.Get("PopupSliderColor", &info.uPopupSliderColor, info.uPopupSliderColor);
160+
section.Get("PopupSliderFocusedColor", &info.uPopupSliderFocusedColor, info.uPopupSliderFocusedColor);
157161

158162
std::string tmpPath;
159163
section.Get("UIAtlas", &tmpPath, "");
@@ -263,6 +267,9 @@ void UpdateTheme(UIContext *ctx) {
263267
ui_theme.backgroundColor = themeInfo.uBackgroundColor;
264268
ui_theme.scrollbarColor = themeInfo.uScrollbarColor;
265269

270+
ui_theme.popupSliderColor = themeInfo.uPopupSliderColor;
271+
ui_theme.popupSliderFocusedColor = themeInfo.uPopupSliderFocusedColor;
272+
266273
// Load any missing atlas metadata (the images are loaded from UIContext).
267274
LoadAtlasMetadata(ui_atlas, (themeInfo.sUIAtlas + ".meta").c_str(), true);
268275
#if !(PPSSPP_PLATFORM(WINDOWS) || PPSSPP_PLATFORM(ANDROID))

assets/themes/defaultthemes.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ TooltipStyleFg = "#FFFFFFFF"
2222
TooltipStyleBg = "#303030C0"
2323
BackgroundColor = "#244D75FF"
2424
ScrollbarColor = "#FFFFFF80"
25+
PopupSliderColor = "#FFFFFFFF"
26+
PopupSliderFocusedColor = "#4CC2EDFF"
2527
UIAtlas = "../ui_atlas"
2628

2729
# Colors are either in the format "#RGBA" or 0xABGR (e.g. green is "#00FF00FF" or 0xFF00FF00)
@@ -52,4 +54,6 @@ TooltipStyleFg = "#FFFFFFFF"
5254
TooltipStyleBg = "#303030C0"
5355
BackgroundColor = "#000000FF"
5456
ScrollbarColor = "#FFFFFF80"
57+
PopupSliderColor = "#FFFFFFFF"
58+
PopupSliderFocusedColor = "#3799bdFF"
5559
UIAtlas = "../ui_atlas"

0 commit comments

Comments
 (0)