Merge item and button style, remove hightlighed and few other fixes

This commit is contained in:
iota97 2022-02-14 13:57:22 +01:00
parent 7860aea62f
commit 561870dc25
10 changed files with 30 additions and 93 deletions

View File

@ -473,16 +473,11 @@ float Choice::CalculateTextScale(const UIContext &dc, float availWidth) const {
return 1.0f;
}
void Choice::HighlightChanged(bool highlighted){
highlighted_ = highlighted;
}
void Choice::Draw(UIContext &dc) {
Style style = dc.theme->itemStyle;
if (HasFocus()) style = dc.theme->itemFocusedStyle;
if (down_) style = dc.theme->itemDownStyle;
if (!IsEnabled()) style = dc.theme->itemDisabledStyle;
if (highlighted_) style = dc.theme->itemHighlightedStyle;
DrawBG(dc, style);
@ -499,7 +494,7 @@ void Choice::Draw(UIContext &dc) {
paddingX += image->w + 6;
availWidth -= image->w + 6;
// TODO: Use scale rotation and flip here as well (DrawImageRotated is always ALIGN_CENTER for now)
dc.Draw()->DrawImage(image_, bounds_.x + 6, bounds_.centerY(), 1.0f, 0xFFFFFFFF, ALIGN_LEFT | ALIGN_VCENTER);
dc.Draw()->DrawImage(image_, bounds_.x + 6, bounds_.centerY(), 1.0f, style.fgColor, ALIGN_LEFT | ALIGN_VCENTER);
}
float scale = CalculateTextScale(dc, availWidth);
@ -509,7 +504,8 @@ void Choice::Draw(UIContext &dc) {
dc.DrawTextRect(text_.c_str(), bounds_, style.fgColor, ALIGN_CENTER | FLAG_WRAP_TEXT);
} else {
if (rightIconImage_.isValid()) {
dc.Draw()->DrawImageRotated(rightIconImage_, bounds_.x2() - 32 - paddingX, bounds_.centerY(), rightIconScale_, rightIconRot_, style.fgColor, rightIconFlipH_);
uint32_t col = rightIconKeepColor_ ? 0xffffffff : style.fgColor; // Don't apply theme to gold icon
dc.Draw()->DrawImageRotated(rightIconImage_, bounds_.x2() - 32 - paddingX, bounds_.centerY(), rightIconScale_, rightIconRot_, col, rightIconFlipH_);
}
Bounds textBounds(bounds_.x + paddingX + textPadding_.left, bounds_.y, availWidth, bounds_.h);
dc.DrawTextRect(text_.c_str(), textBounds, style.fgColor, ALIGN_VCENTER | FLAG_WRAP_TEXT);
@ -542,7 +538,7 @@ void InfoItem::Draw(UIContext &dc) {
UI::Style style = HasFocus() ? dc.theme->itemFocusedStyle : dc.theme->infoStyle;
if (choiceStyle_) {
style = HasFocus() ? dc.theme->buttonFocusedStyle : dc.theme->buttonStyle;
style = HasFocus() ? dc.theme->itemFocusedStyle : dc.theme->itemStyle;
}
@ -810,11 +806,11 @@ void Button::Click() {
}
void Button::Draw(UIContext &dc) {
Style style = dc.theme->buttonStyle;
Style style = dc.theme->itemStyle;
if (HasFocus()) style = dc.theme->buttonFocusedStyle;
if (down_) style = dc.theme->buttonDownStyle;
if (!IsEnabled()) style = dc.theme->buttonDisabledStyle;
if (HasFocus()) style = dc.theme->itemFocusedStyle;
if (down_) style = dc.theme->itemDownStyle;
if (!IsEnabled()) style = dc.theme->itemDisabledStyle;
// dc.Draw()->DrawImage4Grid(style.image, bounds_.x, bounds_.y, bounds_.x2(), bounds_.y2(), style.bgColor);
DrawBG(dc, style);
@ -829,13 +825,13 @@ void Button::Draw(UIContext &dc) {
dc.SetFontStyle(dc.theme->uiFont);
dc.SetFontScale(scale_, scale_);
if (imageID_.isValid() && (ignoreText_ || text_.empty())) {
dc.Draw()->DrawImage(imageID_, bounds_.centerX(), bounds_.centerY(), scale_, 0xFFFFFFFF, ALIGN_CENTER);
dc.Draw()->DrawImage(imageID_, bounds_.centerX(), bounds_.centerY(), scale_, style.fgColor, ALIGN_CENTER);
} else if (!text_.empty()) {
float textX = bounds_.centerX();
if (imageID_.isValid()) {
const AtlasImage *img = dc.Draw()->GetAtlas()->getImage(imageID_);
if (img) {
dc.Draw()->DrawImage(imageID_, bounds_.centerX() - tw / 2 - 5, bounds_.centerY(), 1.0f, 0xFFFFFFFF, ALIGN_CENTER);
dc.Draw()->DrawImage(imageID_, bounds_.centerX() - tw / 2 - 5, bounds_.centerY(), 1.0f, style.fgColor, ALIGN_CENTER);
textX += img->w / 2.0f;
}
}
@ -873,13 +869,13 @@ void RadioButton::Click() {
}
void RadioButton::Draw(UIContext &dc) {
Style style = dc.theme->buttonStyle;
Style style = dc.theme->itemStyle;
bool checked = *value_ == thisButtonValue_;
if (HasFocus()) style = dc.theme->buttonFocusedStyle;
if (down_) style = dc.theme->buttonDownStyle;
if (!IsEnabled()) style = dc.theme->buttonDisabledStyle;
if (HasFocus()) style = dc.theme->itemFocusedStyle;
if (down_) style = dc.theme->itemDownStyle;
if (!IsEnabled()) style = dc.theme->itemDisabledStyle;
DrawBG(dc, style);

View File

@ -100,17 +100,10 @@ struct Theme {
ImageID whiteImage;
ImageID dropShadow4Grid;
Style buttonStyle;
Style buttonFocusedStyle;
Style buttonDownStyle;
Style buttonDisabledStyle;
Style buttonHighlightedStyle;
Style itemStyle;
Style itemDownStyle;
Style itemFocusedStyle;
Style itemDisabledStyle;
Style itemHighlightedStyle;
Style headerStyle;
Style infoStyle;
@ -716,14 +709,14 @@ public:
: ClickableItem(layoutParams), image_(image), rightIconImage_(ImageID::invalid()), imgScale_(imgScale), imgRot_(imgRot), imgFlipH_(imgFlipH) {}
void Click() override;
virtual void HighlightChanged(bool highlighted);
void GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const override;
void Draw(UIContext &dc) override;
std::string DescribeText() const override;
virtual void SetCentered(bool c) {
centered_ = c;
}
virtual void SetIcon(ImageID iconImage, float scale = 1.0f, float rot = 0.0f, bool flipH = false) {
virtual void SetIcon(ImageID iconImage, float scale = 1.0f, float rot = 0.0f, bool flipH = false, bool keepColor = true) {
rightIconKeepColor_ = keepColor;
rightIconScale_ = scale;
rightIconRot_ = rot;
rightIconFlipH_ = flipH;
@ -742,9 +735,9 @@ protected:
float rightIconScale_;
float rightIconRot_;
bool rightIconFlipH_;
bool rightIconKeepColor_;
Padding textPadding_;
bool centered_ = false;
bool highlighted_ = false;
float imgScale_ = 1.0f;
float imgRot_ = 0.0f;
bool imgFlipH_ = false;

View File

@ -1505,12 +1505,6 @@ void ChoiceStrip::SetSelection(int sel, bool triggerClick) {
}
}
void ChoiceStrip::HighlightChoice(int choice) {
if (choice < (int)views_.size()) {
Choice(choice)->HighlightChanged(true);
}
}
void ChoiceStrip::EnableChoice(int choice, bool enabled) {
if (choice < (int)views_.size()) {
Choice(choice)->SetEnabled(enabled);

View File

@ -330,7 +330,6 @@ public:
int GetSelection() const { return selected_; }
void SetSelection(int sel, bool triggerClick);
void HighlightChoice(int choice);
void EnableChoice(int choice, bool enabled);
bool Key(const KeyInput &input) override;

View File

@ -212,7 +212,7 @@ void ComboKeyScreen::CreateViews() {
vertLayout->Add(new CheckBox(show, co->T("Visible")));
Choice *icon = vertLayout->Add(new Choice(co->T("Icon")));
icon->SetIcon(ImageID(comboKeyImages[cfg->image].i), 1.0f, comboKeyImages[cfg->image].r*PI/180); // Set right icon on the choice
icon->SetIcon(ImageID(comboKeyImages[cfg->image].i), 1.0f, comboKeyImages[cfg->image].r*PI/180, false, false); // Set right icon on the choice
icon->OnClick.Add([=](UI::EventParams &e) {
auto iconScreen = new ButtonIconScreen(co->T("Icon"), &(cfg->image));
if (e.v)
@ -223,7 +223,7 @@ void ComboKeyScreen::CreateViews() {
});
Choice *shape = vertLayout->Add(new Choice(co->T("Shape")));
shape->SetIcon(ImageID(comboKeyShapes[cfg->shape].l), 0.6f, comboKeyShapes[cfg->shape].r*PI/180, comboKeyShapes[cfg->shape].f); // Set right icon on the choice
shape->SetIcon(ImageID(comboKeyShapes[cfg->shape].l), 0.6f, comboKeyShapes[cfg->shape].r*PI/180, comboKeyShapes[cfg->shape].f, false); // Set right icon on the choice
shape->OnClick.Add([=](UI::EventParams &e) {
auto shape = new ButtonShapeScreen(co->T("Shape"), &(cfg->shape));
if (e.v)

View File

@ -953,7 +953,7 @@ public:
void Draw(UIContext &dc) override {
uint32_t c = 0xFFFFFFFF;
if (HasFocus() || Selected())
c = dc.theme->buttonFocusedStyle.background.color;
c = dc.theme->itemFocusedStyle.background.color;
float scales[2]{};
if (bgImg_.isValid())

View File

@ -401,7 +401,7 @@ void GameButton::Draw(UIContext &dc) {
if (gridStyle_ && g_Config.bShowIDOnGameIcon) {
dc.SetFontScale(0.5f*g_Config.fGameGridScale, 0.5f*g_Config.fGameGridScale);
dc.DrawText(ginfo->id_version.c_str(), x+5, y+1, 0xFF000000, ALIGN_TOPLEFT);
dc.DrawText(ginfo->id_version.c_str(), x+4, y, 0xFFffFFff, ALIGN_TOPLEFT);
dc.DrawText(ginfo->id_version.c_str(), x+4, y, dc.theme->infoStyle.fgColor, ALIGN_TOPLEFT);
dc.SetFontScale(1.0f, 1.0f);
}
if (overlayColor) {
@ -441,11 +441,11 @@ private:
void DirButton::Draw(UIContext &dc) {
using namespace UI;
Style style = dc.theme->buttonStyle;
Style style = dc.theme->itemStyle;
if (HasFocus()) style = dc.theme->buttonFocusedStyle;
if (down_) style = dc.theme->buttonDownStyle;
if (!IsEnabled()) style = dc.theme->buttonDisabledStyle;
if (HasFocus()) style = dc.theme->itemFocusedStyle;
if (down_) style = dc.theme->itemDownStyle;
if (!IsEnabled()) style = dc.theme->itemDisabledStyle;
dc.FillRect(style.background, bounds_);
@ -470,7 +470,7 @@ void DirButton::Draw(UIContext &dc) {
if (image == ImageID("I_FOLDER")) {
dc.DrawText(text.c_str(), bounds_.x + 5, bounds_.centerY(), style.fgColor, ALIGN_VCENTER);
} else {
dc.Draw()->DrawImage(image, bounds_.centerX(), bounds_.centerY(), gridStyle_ ? g_Config.fGameGridScale : 1.0, 0xFFFFFFFF, ALIGN_CENTER);
dc.Draw()->DrawImage(image, bounds_.centerX(), bounds_.centerY(), gridStyle_ ? g_Config.fGameGridScale : 1.0, style.fgColor, ALIGN_CENTER);
}
dc.PopScissor();
} else {
@ -479,7 +479,7 @@ void DirButton::Draw(UIContext &dc) {
dc.PushScissor(bounds_);
scissor = true;
}
dc.Draw()->DrawImage(image, bounds_.x + 72, bounds_.centerY(), 0.88f*(gridStyle_ ? g_Config.fGameGridScale : 1.0), 0xFFFFFFFF, ALIGN_CENTER);
dc.Draw()->DrawImage(image, bounds_.x + 72, bounds_.centerY(), 0.88f*(gridStyle_ ? g_Config.fGameGridScale : 1.0), style.fgColor, ALIGN_CENTER);
dc.DrawText(text.c_str(), bounds_.x + 150, bounds_.centerY(), style.fgColor, ALIGN_VCENTER);
if (scissor) {

View File

@ -767,11 +767,11 @@ void LogoScreen::render() {
// Manually formatting UTF-8 is fun. \xXX doesn't work everywhere.
snprintf(temp, sizeof(temp), "%s Henrik Rydg%c%crd", cr->T("created", "Created by"), 0xC3, 0xA5);
if (System_GetPropertyBool(SYSPROP_APP_GOLD)) {
dc.Draw()->DrawImage(ImageID("I_ICONGOLD"), bounds.centerX() - 120, bounds.centerY() - 30, 1.2f, textColor, ALIGN_CENTER);
dc.Draw()->DrawImage(ImageID("I_ICONGOLD"), bounds.centerX() - 120, bounds.centerY() - 30, 1.2f, 0xFFFFFFFF, ALIGN_CENTER);
} else {
dc.Draw()->DrawImage(ImageID("I_ICON"), bounds.centerX() - 120, bounds.centerY() - 30, 1.2f, textColor, ALIGN_CENTER);
dc.Draw()->DrawImage(ImageID("I_ICON"), bounds.centerX() - 120, bounds.centerY() - 30, 1.2f, 0xFFFFFFFF, ALIGN_CENTER);
}
dc.Draw()->DrawImage(ImageID("I_LOGO"), bounds.centerX() + 40, bounds.centerY() - 30, 1.5f, textColor, ALIGN_CENTER);
dc.Draw()->DrawImage(ImageID("I_LOGO"), bounds.centerX() + 40, bounds.centerY() - 30, 1.5f, 0xFFFFFFFF, ALIGN_CENTER);
//dc.Draw()->DrawTextShadow(UBUNTU48, "PPSSPP", bounds.w / 2, bounds.h / 2 - 30, textColor, ALIGN_CENTER);
dc.SetFontScale(1.0f, 1.0f);
dc.SetFontStyle(dc.theme->uiFont);

View File

@ -43,19 +43,6 @@ struct ThemeInfo {
uint32_t uItemDownStyleBg = 0xFFBD9939;
uint32_t uItemDisabledStyleFg = 0x80EEEEEE;
uint32_t uItemDisabledStyleBg = 0x55000000;
uint32_t uItemHighlightedStyleFg = 0xFFFFFFFF;
uint32_t uItemHighlightedStyleBg = 0x55BDBB39;
uint32_t uButtonStyleFg = 0xFFFFFFFF;
uint32_t uButtonStyleBg = 0x55000000;
uint32_t uButtonFocusedStyleFg = 0xFFFFFFFF;
uint32_t uButtonFocusedStyleBg = 0xFFBD9939;
uint32_t uButtonDownStyleFg = 0xFFFFFFFF;
uint32_t uButtonDownStyleBg = 0xFFBD9939;
uint32_t uButtonDisabledStyleFg = 0x80EEEEEE;
uint32_t uButtonDisabledStyleBg = 0x55000000;
uint32_t uButtonHighlightedStyleFg = 0xFFFFFFFF;
uint32_t uButtonHighlightedStyleBg = 0x55BDBB39;
uint32_t uHeaderStyleFg = 0xFFFFFFFF;
uint32_t uInfoStyleFg = 0xFFFFFFFF;
@ -131,19 +118,6 @@ static void LoadThemeInfo(const std::vector<Path> &directories) {
section.Get("ItemDownStyleBg", &info.uItemDownStyleBg, info.uItemDownStyleBg);
section.Get("ItemDisabledStyleFg", &info.uItemDisabledStyleFg, info.uItemDisabledStyleFg);
section.Get("ItemDisabledStyleBg", &info.uItemDisabledStyleBg, info.uItemDisabledStyleBg);
section.Get("ItemHighlightedStyleFg", &info.uItemHighlightedStyleFg, info.uItemHighlightedStyleFg);
section.Get("ItemHighlightedStyleBg", &info.uItemHighlightedStyleBg, info.uItemHighlightedStyleBg);
section.Get("ButtonStyleFg", &info.uButtonStyleFg, info.uButtonStyleFg);
section.Get("ButtonStyleBg", &info.uButtonStyleBg, info.uButtonStyleBg);
section.Get("ButtonFocusedStyleFg", &info.uButtonFocusedStyleFg, info.uButtonFocusedStyleFg);
section.Get("ButtonFocusedStyleBg", &info.uButtonFocusedStyleBg, info.uButtonFocusedStyleBg);
section.Get("ButtonDownStyleFg", &info.uButtonDownStyleFg, info.uButtonDownStyleFg);
section.Get("ButtonDownStyleBg", &info.uButtonDownStyleBg, info.uButtonDownStyleBg);
section.Get("ButtonDisabledStyleFg", &info.uButtonDisabledStyleFg, info.uButtonDisabledStyleFg);
section.Get("ButtonDisabledStyleBg", &info.uButtonDisabledStyleBg, info.uButtonDisabledStyleBg);
section.Get("ButtonHighlightedStyleFg", &info.uButtonHighlightedStyleFg, info.uButtonHighlightedStyleFg);
section.Get("ButtonHighlightedStyleBg", &info.uButtonHighlightedStyleBg, info.uButtonHighlightedStyleBg);
section.Get("HeaderStyleFg", &info.uHeaderStyleFg, info.uHeaderStyleFg);
section.Get("InfoStyleFg", &info.uInfoStyleFg, info.uInfoStyleFg);
@ -205,13 +179,6 @@ void UpdateTheme() {
ui_theme.itemFocusedStyle = MakeStyle(themeInfos[i].uItemFocusedStyleFg, themeInfos[i].uItemFocusedStyleBg);
ui_theme.itemDownStyle = MakeStyle(themeInfos[i].uItemDownStyleFg, themeInfos[i].uItemDownStyleBg);
ui_theme.itemDisabledStyle = MakeStyle(themeInfos[i].uItemDisabledStyleFg, themeInfos[i].uItemDisabledStyleBg);
ui_theme.itemHighlightedStyle = MakeStyle(themeInfos[i].uItemHighlightedStyleFg, themeInfos[i].uItemHighlightedStyleBg);
ui_theme.buttonStyle = MakeStyle(themeInfos[i].uButtonStyleFg, themeInfos[i].uButtonStyleBg);
ui_theme.buttonFocusedStyle = MakeStyle(themeInfos[i].uButtonFocusedStyleFg, themeInfos[i].uButtonFocusedStyleBg);
ui_theme.buttonDownStyle = MakeStyle(themeInfos[i].uButtonDownStyleFg, themeInfos[i].uButtonDownStyleBg);
ui_theme.buttonDisabledStyle = MakeStyle(themeInfos[i].uButtonDisabledStyleFg, themeInfos[i].uButtonDisabledStyleBg);
ui_theme.buttonHighlightedStyle = MakeStyle(themeInfos[i].uButtonHighlightedStyleFg, themeInfos[i].uButtonHighlightedStyleBg);
ui_theme.headerStyle.fgColor = themeInfos[i].uHeaderStyleFg;
ui_theme.infoStyle = MakeStyle(themeInfos[i].uInfoStyleFg, themeInfos[i].uInfoStyleBg);

View File

@ -8,18 +8,6 @@ ItemDownStyleFg = 0xffffffff
ItemDownStyleBg = 0xffbd9939
ItemDisabledStyleFg = 0x80eeeeee
ItemDisabledStyleBg = 0x55000000
ItemHighlightedStyleFg = 0xffffffff
ItemHighlightedStyleBg = 0x55bdbb39
ButtonStyleFg = 0xffffffff
ButtonStyleBg = 0x55000000
ButtonFocusedStyleFg = 0xffffffff
ButtonFocusedStyleBg = 0xffedc24c
ButtonDownStyleFg = 0xffffffff
ButtonDownStyleBg = 0xffbd9939
ButtonDisabledStyleFg = 0x80eeeeee
ButtonDisabledStyleBg = 0x55000000
ButtonHighlightedStyleFg = 0xffffffff
ButtonHighlightedStyleBg = 0x55bdbb39
HeaderStyleFg = 0xffffffff
InfoStyleFg = 0xffffffff
InfoStyleBg = 0x00000000