mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-27 07:20:49 +00:00
238 lines
8.8 KiB
C++
238 lines
8.8 KiB
C++
// Copyright (c) 2013- PPSSPP Project.
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
// Official git repository and contact information can be found at
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
#include "ppsspp_config.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include "UI/Theme.h"
|
|
|
|
#include "Common/File/FileUtil.h"
|
|
#include "Common/File/VFS/VFS.h"
|
|
#include "Common/Data/Format/IniFile.h"
|
|
|
|
#include "Core/Config.h"
|
|
|
|
#include "Common/UI/View.h"
|
|
#include "Common/UI/Context.h"
|
|
#include "Core/System.h"
|
|
|
|
struct themeInfo {
|
|
std::string name;
|
|
|
|
uint32_t uItemStyleFg = 0xFFFFFFFF;
|
|
uint32_t uItemStyleBg = 0x55000000;
|
|
uint32_t uItemFocusedStyleFg = 0xFFFFFFFF;
|
|
uint32_t uItemFocusedStyleBg = 0xFFEDC24C;
|
|
uint32_t uItemDownStyleFg = 0xFFFFFFFF;
|
|
uint32_t uItemDownStyleBg = 0xFFBD9939;
|
|
uint32_t uItemDisabledStyleFg = 0x80EEEEEE;
|
|
uint32_t uItemDisabledStyleBg = 0x55E0D4AF;
|
|
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 = 0x55E0D4AF;
|
|
uint32_t uButtonHighlightedStyleFg = 0xFFFFFFFF;
|
|
uint32_t uButtonHighlightedStyleBg = 0x55BDBB39;
|
|
|
|
uint32_t uHeaderStyleFg = 0xFFFFFFFF;
|
|
uint32_t uInfoStyleFg = 0xFFFFFFFF;
|
|
uint32_t uInfoStyleBg = 0x00000000;
|
|
uint32_t uPopupTitleStyleFg = 0xFFE3BE59;
|
|
uint32_t uPopupStyleFg = 0xFFFFFFFF;
|
|
uint32_t uPopupStyleBg = 0xFF303030;
|
|
|
|
bool operator == (const std::string &other) {
|
|
return name == other;
|
|
}
|
|
bool operator == (const themeInfo &other) {
|
|
return name == other.name;
|
|
}
|
|
};
|
|
|
|
static UI::Theme ui_theme;
|
|
static std::vector<themeInfo> themeInfos;
|
|
|
|
static void LoadThemeInfo(const std::vector<Path> &directories) {
|
|
themeInfos.clear();
|
|
themeInfo def{};
|
|
def.name = "Default";
|
|
themeInfos.push_back(def);
|
|
|
|
auto appendTheme = [&](const themeInfo &info) {
|
|
auto beginErase = std::remove(themeInfos.begin(), themeInfos.end(), info.name);
|
|
if (beginErase != themeInfos.end()) {
|
|
themeInfos.erase(beginErase, themeInfos.end());
|
|
}
|
|
themeInfos.push_back(info);
|
|
};
|
|
|
|
for (size_t d = 0; d < directories.size(); d++) {
|
|
std::vector<File::FileInfo> fileInfo;
|
|
VFSGetFileListing(directories[d].c_str(), &fileInfo, "ini:");
|
|
|
|
if (fileInfo.empty()) {
|
|
File::GetFilesInDir(directories[d], &fileInfo, "ini:");
|
|
}
|
|
|
|
for (size_t f = 0; f < fileInfo.size(); f++) {
|
|
IniFile ini;
|
|
bool success = false;
|
|
Path name = fileInfo[f].fullName;
|
|
Path path = directories[d];
|
|
// Hack around Android VFS path bug. really need to redesign this.
|
|
if (name.ToString().substr(0, 7) == "assets/")
|
|
name = Path(name.ToString().substr(7));
|
|
if (path.ToString().substr(0, 7) == "assets/")
|
|
path = Path(path.ToString().substr(7));
|
|
|
|
if (ini.LoadFromVFS(name.ToString()) || ini.Load(fileInfo[f].fullName)) {
|
|
success = true;
|
|
// vsh load. meh.
|
|
}
|
|
|
|
if (!success)
|
|
continue;
|
|
|
|
// Alright, let's loop through the sections and see if any is a themes.
|
|
for (size_t i = 0; i < ini.Sections().size(); i++) {
|
|
Section §ion = ini.Sections()[i];
|
|
themeInfo info;
|
|
section.Get("Name", &info.name, section.name().c_str());
|
|
|
|
section.Get("ItemStyleFg", &info.uItemStyleFg, 0xFFFFFFFF);
|
|
section.Get("ItemStyleBg", &info.uItemStyleBg, 0x55000000);
|
|
section.Get("ItemFocusedStyleFg", &info.uItemFocusedStyleFg, 0xFFFFFFFF);
|
|
section.Get("ItemFocusedStyleBg", &info.uItemFocusedStyleBg, 0xFFEDC24C);
|
|
section.Get("ItemDownStyleFg", &info.uItemDownStyleFg, 0xFFFFFFFF);
|
|
section.Get("ItemDownStyleBg", &info.uItemDownStyleBg, 0xFFBD9939);
|
|
section.Get("ItemDisabledStyleFg", &info.uItemDisabledStyleFg, 0x80EEEEEE);
|
|
section.Get("ItemDisabledStyleBg", &info.uItemDisabledStyleBg, 0x55E0D4AF);
|
|
section.Get("ItemHighlightedStyleFg", &info.uItemHighlightedStyleFg, 0xFFFFFFFF);
|
|
section.Get("ItemHighlightedStyleBg", &info.uItemHighlightedStyleBg, 0x55BDBB39);
|
|
|
|
section.Get("ButtonStyleFg", &info.uButtonStyleFg, 0xFFFFFFFF);
|
|
section.Get("ButtonStyleBg", &info.uButtonStyleBg, 0x55000000);
|
|
section.Get("ButtonFocusedStyleFg", &info.uButtonFocusedStyleFg, 0xFFFFFFFF);
|
|
section.Get("ButtonFocusedStyleBg", &info.uButtonFocusedStyleBg, 0xFFBD9939);
|
|
section.Get("ButtonDownStyleFg", &info.uButtonDownStyleFg, 0xFFFFFFFF);
|
|
section.Get("ButtonDownStyleBg", &info.uButtonDownStyleBg, 0xFFBD9939);
|
|
section.Get("ButtonDisabledStyleFg", &info.uButtonDisabledStyleFg, 0x80EEEEEE);
|
|
section.Get("ButtonDisabledStyleBg", &info.uButtonDisabledStyleBg, 0x55E0D4AF);
|
|
section.Get("ButtonHighlightedStyleFg", &info.uButtonHighlightedStyleFg, 0xFFFFFFFF);
|
|
section.Get("ButtonHighlightedStyleBg", &info.uButtonHighlightedStyleBg, 0x55BDBB39);
|
|
|
|
section.Get("HeaderStyleFg", &info.uHeaderStyleFg, 0xFFFFFFFF);
|
|
section.Get("InfoStyleFg", &info.uInfoStyleFg, 0xFFFFFFFF);
|
|
section.Get("InfoStyleBg", &info.uInfoStyleBg, 0x00000000);
|
|
section.Get("PopupTitleStyleFg", &info.uPopupTitleStyleFg, 0xFFE3BE59);
|
|
section.Get("PopupStyleFg", &info.uPopupStyleFg, 0xFFFFFFFF);
|
|
section.Get("PopupStyleBg", &info.uPopupStyleBg, 0xFF303030);
|
|
|
|
appendTheme(info);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static UI::Style MakeStyle (uint32_t fg, uint32_t bg) {
|
|
UI::Style s;
|
|
s.background = UI::Drawable(bg);
|
|
s.fgColor = fg;
|
|
return s;
|
|
}
|
|
|
|
void UpdateTheme() {
|
|
// First run, get the default in at least
|
|
if (themeInfos.empty()) {
|
|
ReloadAllThemeInfo();
|
|
}
|
|
|
|
size_t i;
|
|
for (i = 0; i < themeInfos.size(); ++i) {
|
|
if (themeInfos[i].name == g_Config.sThemeName) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Reset to Default if not found
|
|
if (i >= themeInfos.size()) {
|
|
g_Config.sThemeName = "Default";
|
|
i = 0;
|
|
}
|
|
|
|
#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");
|
|
|
|
// Actual configurable themes setting start here
|
|
ui_theme.itemStyle = MakeStyle(themeInfos[i].uItemStyleFg, themeInfos[i].uItemStyleBg);
|
|
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);
|
|
|
|
ui_theme.popupTitle.fgColor = themeInfos[i].uPopupTitleStyleFg;
|
|
ui_theme.popupStyle = MakeStyle(themeInfos[i].uPopupStyleFg, themeInfos[i].uPopupStyleBg);
|
|
}
|
|
|
|
UI::Theme *GetTheme() {
|
|
return &ui_theme;
|
|
}
|
|
|
|
void ReloadAllThemeInfo() {
|
|
std::vector<Path> directories;
|
|
directories.push_back(Path("themes")); // For VFS
|
|
directories.push_back(GetSysDirectory(DIRECTORY_CUSTOM_THEMES));
|
|
LoadThemeInfo(directories);
|
|
}
|
|
|
|
std::vector<std::string> GetThemeInfoNames() {
|
|
std::vector<std::string> names;
|
|
for (auto& i : themeInfos)
|
|
names.push_back(i.name);
|
|
|
|
return names;
|
|
} |