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 3 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
2 changes: 2 additions & 0 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
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
10 changes: 10 additions & 0 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "UI/TiltEventProcessor.h"
#include "UI/GPUDriverTestScreen.h"
#include "UI/MemStickScreen.h"
#include "UI/Theme.h"

#include "Common/File/FileUtil.h"
#include "Common/OSVersion.h"
Expand Down Expand Up @@ -191,6 +192,7 @@ bool PathToVisualUsbPath(Path path, std::string &outPath) {

void GameSettingsScreen::CreateViews() {
ReloadAllPostShaderInfo(screenManager()->getDrawContext());
ReloadAllThemeInfo();

if (editThenRestore_) {
std::shared_ptr<GameInfo> info = g_gameInfoCache->GetInfo(nullptr, gamePath_, 0);
Expand Down Expand Up @@ -881,6 +883,14 @@ void GameSettingsScreen::CreateViews() {
if (backgroundChoice_ != nullptr) {
backgroundChoice_->OnClick.Handle(this, &GameSettingsScreen::OnChangeBackground);
}

PopupMultiChoiceDynamic *theme = systemSettings->Add(new PopupMultiChoiceDynamic(&g_Config.sThemeName, gr->T("Color Theme"), GetThemeInfoNames(), nullptr, screenManager()));
theme->OnChoice.Add([=](EventParams &e) {
UpdateTheme();

return UI::EVENT_CONTINUE;
});

static const char *backgroundAnimations[] = { "No animation", "Floating symbols", "Recent games", "Waves", "Moving background" };
systemSettings->Add(new PopupMultiChoice(&g_Config.iBackgroundAnimation, sy->T("UI background animation"), backgroundAnimations, 0, ARRAY_SIZE(backgroundAnimations), sy->GetName(), screenManager()));

Expand Down
50 changes: 3 additions & 47 deletions UI/NativeApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
#include "UI/RemoteISOScreen.h"
#include "UI/TiltEventProcessor.h"
#include "UI/TextureUtil.h"
#include "UI/Theme.h"

#if !defined(MOBILE_DEVICE) && defined(USING_QT_UI)
#include "Qt/QtHost.h"
Expand All @@ -131,7 +132,6 @@

// The new UI framework, for initialization

static UI::Theme ui_theme;
static Atlas g_ui_atlas;
static Atlas g_font_atlas;

Expand Down Expand Up @@ -873,49 +873,6 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
restarting = false;
}

static UI::Style MakeStyle(uint32_t fg, uint32_t bg) {
UI::Style s;
s.background = UI::Drawable(bg);
s.fgColor = fg;
return s;
}

static void UIThemeInit() {
#if defined(USING_WIN_UI) || PPSSPP_PLATFORM(UWP) || defined(USING_QT_UI)
ui_theme.uiFont = UI::FontStyle(FontID("UBUNTU24"), g_Config.sFont.c_str(), 22);
ui_theme.uiFontSmall = UI::FontStyle(FontID("UBUNTU24"), g_Config.sFont.c_str(), 15);
ui_theme.uiFontSmaller = UI::FontStyle(FontID("UBUNTU24"), g_Config.sFont.c_str(), 12);
#else
ui_theme.uiFont = UI::FontStyle(FontID("UBUNTU24"), "", 20);
ui_theme.uiFontSmall = UI::FontStyle(FontID("UBUNTU24"), "", 14);
ui_theme.uiFontSmaller = UI::FontStyle(FontID("UBUNTU24"), "", 11);
#endif

ui_theme.checkOn = ImageID("I_CHECKEDBOX");
ui_theme.checkOff = ImageID("I_SQUARE");
ui_theme.whiteImage = ImageID("I_SOLIDWHITE");
ui_theme.sliderKnob = ImageID("I_CIRCLE");
ui_theme.dropShadow4Grid = ImageID("I_DROP_SHADOW");

ui_theme.itemStyle = MakeStyle(g_Config.uItemStyleFg, g_Config.uItemStyleBg);
ui_theme.itemFocusedStyle = MakeStyle(g_Config.uItemFocusedStyleFg, g_Config.uItemFocusedStyleBg);
ui_theme.itemDownStyle = MakeStyle(g_Config.uItemDownStyleFg, g_Config.uItemDownStyleBg);
ui_theme.itemDisabledStyle = MakeStyle(g_Config.uItemDisabledStyleFg, g_Config.uItemDisabledStyleBg);
ui_theme.itemHighlightedStyle = MakeStyle(g_Config.uItemHighlightedStyleFg, g_Config.uItemHighlightedStyleBg);

ui_theme.buttonStyle = MakeStyle(g_Config.uButtonStyleFg, g_Config.uButtonStyleBg);
ui_theme.buttonFocusedStyle = MakeStyle(g_Config.uButtonFocusedStyleFg, g_Config.uButtonFocusedStyleBg);
ui_theme.buttonDownStyle = MakeStyle(g_Config.uButtonDownStyleFg, g_Config.uButtonDownStyleBg);
ui_theme.buttonDisabledStyle = MakeStyle(g_Config.uButtonDisabledStyleFg, g_Config.uButtonDisabledStyleBg);
ui_theme.buttonHighlightedStyle = MakeStyle(g_Config.uButtonHighlightedStyleFg, g_Config.uButtonHighlightedStyleBg);

ui_theme.headerStyle.fgColor = g_Config.uHeaderStyleFg;
ui_theme.infoStyle = MakeStyle(g_Config.uInfoStyleFg, g_Config.uInfoStyleBg);

ui_theme.popupTitle.fgColor = g_Config.uPopupTitleStyleFg;
ui_theme.popupStyle = MakeStyle(g_Config.uPopupStyleFg, g_Config.uPopupStyleBg);
}

void RenderOverlays(UIContext *dc, void *userdata);
bool CreateGlobalPipelines();

Expand Down Expand Up @@ -962,10 +919,9 @@ bool NativeInitGraphics(GraphicsContext *graphicsContext) {
ui_draw2d_front.SetAtlas(&g_ui_atlas);
ui_draw2d_front.SetFontAtlas(&g_font_atlas);

UIThemeInit();

UpdateTheme();
uiContext = new UIContext();
uiContext->theme = &ui_theme;
uiContext->theme = GetTheme();

ui_draw2d.Init(g_draw, texColorPipeline);
ui_draw2d_front.Init(g_draw, texColorPipeline);
Expand Down
Loading