diff --git a/libstarlight/source/starlight/ThemeManager.cpp b/libstarlight/source/starlight/ThemeManager.cpp index ccce7a7..560dbef 100644 --- a/libstarlight/source/starlight/ThemeManager.cpp +++ b/libstarlight/source/starlight/ThemeManager.cpp @@ -140,7 +140,7 @@ ThemeInfo::ThemeInfo(const Path& path, const std::string& name) { basePath = path; meta = std::make_shared(); metrics = std::make_shared(); - if (!basePath.IsDirectory()) return; // don't bother trying to load stuff + //if (!basePath.IsDirectory() && std::string(basePath).find("romfs:") != std::string::npos) return; // don't bother trying to load stuff { // using... std::ifstream load = basePath.Combine("meta.json").OpenI(); if (load.good()) load >> *meta; @@ -163,6 +163,7 @@ void ThemeManager::Init() { if (!thm.basePath.IsDirectory()) thm = ThemeInfo("default"); // fall back on default if not found // ...and if "default" doesn't exist, fall back on a standard location in romfs: if (!thm.basePath.IsDirectory()) thm = ThemeInfo(Path("romfs:/.fallback_theme", "FALLBACK")); + if (!thm.basePath.IsDirectory()) thm = ThemeInfo(Path("romfs:/", "FALLBACK")); // fall back on root of romfs for testbed I guess themeData.push_back(thm); while (!(*thm.meta)["fallback"].is_null()) { // follow fallback chain @@ -319,6 +320,13 @@ T ThemeManager::GetMetric(const std::string& path, const T& defaultValue) { }//*/ } +template +T ThemeManager::GetMetric(const std::string& path) { + json& j = GetMetric(path); + if (j.is_null()) return T(); + return j; +} + TextConfig::TextConfig(const std::string& fontName, Color text, Color border) { font = ThemeManager::GetFont(fontName); textColor = text; borderColor = border; @@ -343,8 +351,13 @@ namespace starlight { // todo: expose these in the header } } -template Vector2 ThemeManager::GetMetric(const std::string&, const Vector2&); -template VRect ThemeManager::GetMetric(const std::string&, const VRect&); -template Color ThemeManager::GetMetric(const std::string&, const Color&); +// explicit type conversions for metrics +#define typeconv(t) \ + template t ThemeManager::GetMetric(const std::string&, const t &); \ + template t ThemeManager::GetMetric(const std::string&); -template starlight::TextConfig ThemeManager::GetMetric(const std::string&, const TextConfig&); +typeconv(Vector2); +typeconv(VRect); +typeconv(Color); + +typeconv(TextConfig); diff --git a/libstarlight/source/starlight/ThemeManager.h b/libstarlight/source/starlight/ThemeManager.h index 8a28421..8a694c4 100644 --- a/libstarlight/source/starlight/ThemeManager.h +++ b/libstarlight/source/starlight/ThemeManager.h @@ -66,6 +66,7 @@ namespace starlight { static inline std::string GetThemeName() { return themeData.front().name; } static nlohmann::json& GetMetric(const std::string& path); template static T GetMetric(const std::string& path, const T& defaultValue); + template static T GetMetric(const std::string& path); }; } diff --git a/libstarlight/source/starlight/datatypes/VRect.cpp b/libstarlight/source/starlight/datatypes/VRect.cpp index 7d3e393..a37f5b3 100644 --- a/libstarlight/source/starlight/datatypes/VRect.cpp +++ b/libstarlight/source/starlight/datatypes/VRect.cpp @@ -58,3 +58,6 @@ VRect VRect::RightEdge(float width) const { return VRect(pos.x + size.x - widt const VRect VRect::invalid = VRect(Vector2::invalid, Vector2::invalid); const VRect VRect::zero = VRect(); // should initialize to 0,0,0,0 + +const VRect VRect::touchScreen = VRect(0, 0, 320, 240); +const VRect VRect::topScreen = VRect(0, 0, 400, 240); diff --git a/libstarlight/source/starlight/datatypes/VRect.h b/libstarlight/source/starlight/datatypes/VRect.h index a149bc7..58fa7ce 100644 --- a/libstarlight/source/starlight/datatypes/VRect.h +++ b/libstarlight/source/starlight/datatypes/VRect.h @@ -58,5 +58,8 @@ namespace starlight { static const VRect invalid; static const VRect zero; + + static const VRect touchScreen; + static const VRect topScreen; }; } diff --git a/libstarlight/source/starlight/dialog/MessageBox.cpp b/libstarlight/source/starlight/dialog/MessageBox.cpp index ef3e040..864fc27 100644 --- a/libstarlight/source/starlight/dialog/MessageBox.cpp +++ b/libstarlight/source/starlight/dialog/MessageBox.cpp @@ -1,5 +1,6 @@ #include "MessageBox.h" +#include "starlight/ThemeManager.h" #include "starlight/InputManager.h" #include "starlight/ui/Image.h" @@ -22,7 +23,11 @@ MessageBox::MessageBox(Mode m, const std::string& msg, std::function priority = 10; eOnSelect = onSelect; - VRect boxArea = VRect(160, 120, 0, 0).Expand(Vector2(240, 160)*.5); + VRect boxArea = VRect(160, 120, 0, 0).Expand(ThemeManager::GetMetric("/dialogs/messageBox/size")*.5); + + auto cover = std::make_shared(touchScreen->rect.Expand(4), "decorations/dialog.modal-cover"); + cover->blockTouch = true; + touchScreen->Add(cover); auto bg = std::make_shared(boxArea, "decorations/panel.bg"); touchScreen->Add(bg); @@ -30,7 +35,7 @@ MessageBox::MessageBox(Mode m, const std::string& msg, std::function touchScreen->Add(scroll); auto label = std::make_shared