Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom UI themes #15394

Merged
merged 8 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,8 @@ list(APPEND NativeAppSource
UI/TextureUtil.cpp
UI/ComboKeyMappingScreen.h
UI/ComboKeyMappingScreen.cpp
UI/Theme.h
UI/Theme.cpp
)

if(ANDROID)
Expand Down Expand Up @@ -2259,6 +2261,7 @@ set(NativeAssets
assets/debugger
assets/lang
assets/shaders
assets/themes
assets/Roboto-Condensed.ttf
assets/7z.png
assets/compat.ini
Expand Down Expand Up @@ -2365,6 +2368,7 @@ if(TargetBin)
file(GLOB_RECURSE FLASH0_FILES assets/flash0/*)
file(GLOB_RECURSE LANG_FILES assets/lang/*)
file(GLOB_RECURSE SHADER_FILES assets/shaders/*)
file(GLOB_RECURSE THEME_FILE assets/themes/*)
file(GLOB_RECURSE DEBUGGER_FILES assets/debugger/*)

if(NOT IOS)
Expand All @@ -2373,14 +2377,15 @@ if(TargetBin)
set_source_files_properties(${FLASH0_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/assets/flash0/font")
set_source_files_properties(${LANG_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/assets/lang")
set_source_files_properties(${SHADER_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/assets/shaders")
set_source_files_properties(${THEME_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/assets/themes")
set_source_files_properties(${DEBUGGER_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/assets/debugger")
endif()

if(IOS)
add_executable(${TargetBin} MACOSX_BUNDLE ${ICON_PATH_ABS} ${NativeAssets} ${BigFontAssets} ${SHADER_FILES} ${DEBUGGER_FILES} ${FLASH0_FILES} ${LANG_FILES} ${NativeAppSource} "ios/Settings.bundle" "ios/Launch Screen.storyboard")
add_executable(${TargetBin} MACOSX_BUNDLE ${ICON_PATH_ABS} ${NativeAssets} ${BigFontAssets} ${SHADER_FILES} ${THEME_FILE} ${DEBUGGER_FILES} ${FLASH0_FILES} ${LANG_FILES} ${NativeAppSource} "ios/Settings.bundle" "ios/Launch Screen.storyboard")
file(INSTALL "${CMAKE_SOURCE_DIR}/ext/vulkan/iOS/Frameworks/libMoltenVK.dylib" DESTINATION "${CMAKE_BINARY_DIR}/PPSSPP.app/Frameworks/")
else()
add_executable(${TargetBin} MACOSX_BUNDLE ${ICON_PATH_ABS} ${NativeAssets} ${BigFontAssets} ${SHADER_FILES} ${DEBUGGER_FILES} ${FLASH0_FILES} ${LANG_FILES} ${NativeAppSource})
add_executable(${TargetBin} MACOSX_BUNDLE ${ICON_PATH_ABS} ${NativeAssets} ${BigFontAssets} ${SHADER_FILES} ${THEME_FILE} ${DEBUGGER_FILES} ${FLASH0_FILES} ${LANG_FILES} ${NativeAppSource})
file(INSTALL "${CMAKE_SOURCE_DIR}/ext/vulkan/macOS/Frameworks/libMoltenVK.dylib" DESTINATION "${CMAKE_BINARY_DIR}/PPSSPPSDL.app/Contents/Frameworks/")
if(TARGET SDL2::SDL2 AND NOT USING_QT_UI)
add_custom_command(TARGET ${TargetBin} POST_BUILD COMMAND /bin/bash "${CMAKE_SOURCE_DIR}/SDL/macbundle.sh" "${CMAKE_BINARY_DIR}/PPSSPPSDL.app")
Expand Down
6 changes: 6 additions & 0 deletions Common/UI/UIScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,12 @@ void AbstractChoiceWithValueDisplay::Draw(UIContext &dc) {
if (!IsEnabled()) {
style = dc.theme->itemDisabledStyle;
}
if (HasFocus()) {
style = dc.theme->itemFocusedStyle;
}
if (down_) {
style = dc.theme->itemDownStyle;
}
int paddingX = 12;
dc.SetFontStyle(dc.theme->uiFont);

Expand Down
68 changes: 30 additions & 38 deletions Common/UI/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ ClickableItem::ClickableItem(LayoutParams *layoutParams) : Clickable(layoutParam
void ClickableItem::Draw(UIContext &dc) {
Style style = dc.theme->itemStyle;

if (!IsEnabled()) {
style = dc.theme->itemDisabledStyle;
}
if (HasFocus()) {
style = dc.theme->itemFocusedStyle;
}
Expand Down Expand Up @@ -470,32 +473,13 @@ float Choice::CalculateTextScale(const UIContext &dc, float availWidth) const {
return 1.0f;
}

void Choice::HighlightChanged(bool highlighted){
highlighted_ = highlighted;
}

void Choice::Draw(UIContext &dc) {
if (!IsSticky()) {
ClickableItem::Draw(dc);
} else {
Style style = dc.theme->itemStyle;
if (highlighted_) {
style = dc.theme->itemHighlightedStyle;
}
if (down_) {
style = dc.theme->itemDownStyle;
}
if (HasFocus()) {
style = dc.theme->itemFocusedStyle;
}

DrawBG(dc, style);
}

Style style = dc.theme->itemStyle;
if (!IsEnabled()) {
style = dc.theme->itemDisabledStyle;
}
if (HasFocus()) style = dc.theme->itemFocusedStyle;
if (down_) style = dc.theme->itemDownStyle;
if (!IsEnabled()) style = dc.theme->itemDisabledStyle;

DrawBG(dc, style);

if (image_.isValid() && text_.empty()) {
dc.Draw()->DrawImageRotated(image_, bounds_.centerX(), bounds_.centerY(), imgScale_, imgRot_, style.fgColor, imgFlipH_);
Expand All @@ -510,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);
Expand All @@ -520,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);
Expand Down Expand Up @@ -553,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;
}


Expand Down Expand Up @@ -702,8 +687,15 @@ EventReturn CheckBox::OnClicked(EventParams &e) {

void CheckBox::Draw(UIContext &dc) {
Style style = dc.theme->itemStyle;
if (!IsEnabled())
if (!IsEnabled()) {
style = dc.theme->itemDisabledStyle;
}
if (HasFocus()) {
style = dc.theme->itemFocusedStyle;
}
if (down_) {
style = dc.theme->itemDownStyle;
}
dc.SetFontStyle(dc.theme->uiFont);

ClickableItem::Draw(dc);
Expand Down Expand Up @@ -821,11 +813,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);
Expand All @@ -840,13 +832,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;
}
}
Expand Down Expand Up @@ -884,13 +876,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);

Expand Down
13 changes: 3 additions & 10 deletions Common/UI/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -716,14 +709,14 @@ class Choice : public ClickableItem {
: 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;
Expand All @@ -742,9 +735,9 @@ class Choice : public ClickableItem {
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;
Expand Down
6 changes: 0 additions & 6 deletions Common/UI/ViewGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion Common/UI/ViewGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ class ChoiceStrip : public LinearLayout {
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;
Expand Down
29 changes: 1 addition & 28 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1169,34 +1169,7 @@ static ConfigSetting upgradeSettings[] = {
};

static ConfigSetting themeSettings[] = {
ConfigSetting("ItemStyleFg", &g_Config.uItemStyleFg, 0xFFFFFFFF, true, false),
ConfigSetting("ItemStyleBg", &g_Config.uItemStyleBg, 0x55000000, true, false),
ConfigSetting("ItemFocusedStyleFg", &g_Config.uItemFocusedStyleFg, 0xFFFFFFFF, true, false),
ConfigSetting("ItemFocusedStyleBg", &g_Config.uItemFocusedStyleBg, 0xFFEDC24C, true, false),
ConfigSetting("ItemDownStyleFg", &g_Config.uItemDownStyleFg, 0xFFFFFFFF, true, false),
ConfigSetting("ItemDownStyleBg", &g_Config.uItemDownStyleBg, 0xFFBD9939, true, false),
ConfigSetting("ItemDisabledStyleFg", &g_Config.uItemDisabledStyleFg, 0x80EEEEEE, true, false),
ConfigSetting("ItemDisabledStyleBg", &g_Config.uItemDisabledStyleBg, 0x55E0D4AF, true, false),
ConfigSetting("ItemHighlightedStyleFg", &g_Config.uItemHighlightedStyleFg, 0xFFFFFFFF, true, false),
ConfigSetting("ItemHighlightedStyleBg", &g_Config.uItemHighlightedStyleBg, 0x55BDBB39, true, false),

ConfigSetting("ButtonStyleFg", &g_Config.uButtonStyleFg, 0xFFFFFFFF, true, false),
ConfigSetting("ButtonStyleBg", &g_Config.uButtonStyleBg, 0x55000000, true, false),
ConfigSetting("ButtonFocusedStyleFg", &g_Config.uButtonFocusedStyleFg, 0xFFFFFFFF, true, false),
ConfigSetting("ButtonFocusedStyleBg", &g_Config.uButtonFocusedStyleBg, 0xFFEDC24C, true, false),
ConfigSetting("ButtonDownStyleFg", &g_Config.uButtonDownStyleFg, 0xFFFFFFFF, true, false),
ConfigSetting("ButtonDownStyleBg", &g_Config.uButtonDownStyleBg, 0xFFBD9939, true, false),
ConfigSetting("ButtonDisabledStyleFg", &g_Config.uButtonDisabledStyleFg, 0x80EEEEEE, true, false),
ConfigSetting("ButtonDisabledStyleBg", &g_Config.uButtonDisabledStyleBg, 0x55E0D4AF, true, false),
ConfigSetting("ButtonHighlightedStyleFg", &g_Config.uButtonHighlightedStyleFg, 0xFFFFFFFF, true, false),
ConfigSetting("ButtonHighlightedStyleBg", &g_Config.uButtonHighlightedStyleBg, 0x55BDBB39, true, false),

ConfigSetting("HeaderStyleFg", &g_Config.uHeaderStyleFg, 0xFFFFFFFF, true, false),
ConfigSetting("InfoStyleFg", &g_Config.uInfoStyleFg, 0xFFFFFFFF, true, false),
ConfigSetting("InfoStyleBg", &g_Config.uInfoStyleBg, 0x00000000U, true, false),
ConfigSetting("PopupTitleStyleFg", &g_Config.uPopupTitleStyleFg, 0xFFE3BE59, true, false),
ConfigSetting("PopupStyleFg", &g_Config.uPopupStyleFg, 0xFFFFFFFF, true, false),
ConfigSetting("PopupStyleBg", &g_Config.uPopupStyleBg, 0xFF303030, true, false),
ConfigSetting("ThemeName", &g_Config.sThemeName, "Default", true, false),

ConfigSetting(false),
};
Expand Down
30 changes: 1 addition & 29 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,35 +255,7 @@ struct Config {
bool bShowOnScreenMessages;
int iBackgroundAnimation; // enum BackgroundAnimation

// TODO: Maybe move to a separate theme system.
uint32_t uItemStyleFg;
uint32_t uItemStyleBg;
uint32_t uItemFocusedStyleFg;
uint32_t uItemFocusedStyleBg;
uint32_t uItemDownStyleFg;
uint32_t uItemDownStyleBg;
uint32_t uItemDisabledStyleFg;
uint32_t uItemDisabledStyleBg;
uint32_t uItemHighlightedStyleFg;
uint32_t uItemHighlightedStyleBg;

uint32_t uButtonStyleFg;
uint32_t uButtonStyleBg;
uint32_t uButtonFocusedStyleFg;
uint32_t uButtonFocusedStyleBg;
uint32_t uButtonDownStyleFg;
uint32_t uButtonDownStyleBg;
uint32_t uButtonDisabledStyleFg;
uint32_t uButtonDisabledStyleBg;
uint32_t uButtonHighlightedStyleFg;
uint32_t uButtonHighlightedStyleBg;

uint32_t uHeaderStyleFg;
uint32_t uInfoStyleFg;
uint32_t uInfoStyleBg;
uint32_t uPopupTitleStyleFg;
uint32_t uPopupStyleFg;
uint32_t uPopupStyleBg;
std::string sThemeName;

bool bLogFrameDrops;
bool bShowDebugStats;
Expand Down
2 changes: 2 additions & 0 deletions Core/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,8 @@ Path GetSysDirectory(PSPDirectories directoryType) {
return pspDirectory / "AUDIO";
case DIRECTORY_CUSTOM_SHADERS:
return pspDirectory / "shaders";
case DIRECTORY_CUSTOM_THEMES:
return pspDirectory / "themes";

case DIRECTORY_MEMSTICK_ROOT:
return g_Config.memStickDirectory;
Expand Down
1 change: 1 addition & 0 deletions Core/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ enum PSPDirectories {
DIRECTORY_MEMSTICK_ROOT,
DIRECTORY_EXDATA,
DIRECTORY_CUSTOM_SHADERS,
DIRECTORY_CUSTOM_THEMES,
};

class GraphicsContext;
Expand Down
4 changes: 2 additions & 2 deletions UI/ComboKeyMappingScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion UI/ControlMappingScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ class MockButton : public UI::Clickable {
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())
Expand Down
Loading