Skip to content

Commit d0968c1

Browse files
committed
theme: Adds very basic theme support.
1 parent 54b04d0 commit d0968c1

File tree

14 files changed

+180
-16
lines changed

14 files changed

+180
-16
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ add_executable(${PROJECT_NAME}
3535
Sources/sntpClient.cpp
3636
Sources/subAppRouter.cpp
3737
Sources/subsystems.cpp
38+
Sources/theme.cpp
3839
Sources/timing.cpp
3940
Sources/timeMenu.cpp
4041
Sources/videoMenu.cpp

Includes/config.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void from_json(nlohmann::json const& j, homescreenConfig& o);
133133

134134
class Settings {
135135
public:
136-
Settings() = default;
136+
std::string activeThemeDirectory{ "default" };
137137
#ifdef NXDK
138138
netConfig net;
139139
sntpConfig sntp;
@@ -154,6 +154,7 @@ class Config {
154154

155155
void setChanged();
156156
void storeToDisk();
157+
157158
Settings settings;
158159
nlohmann::json menu;
159160
};

Includes/renderer.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define RENDERER_H
33

44
#include <SDL.h>
5+
#include <string>
56
#include <vector>
67

78
int min(int lhs, int rhs);
@@ -13,7 +14,7 @@ class Renderer {
1314
~Renderer();
1415

1516
int init();
16-
int init(const char* bg);
17+
int init(std::string const& backgroundImagePath);
1718
int clear();
1819
void flip();
1920

Includes/theme.hpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#ifndef NEVOLUTIONX_THEME_H
2+
#define NEVOLUTIONX_THEME_H
3+
4+
#include <string>
5+
6+
#pragma clang diagnostic push
7+
#pragma clang diagnostic ignored "-Wreturn-type"
8+
#include "../3rdparty/json.hpp"
9+
#pragma clang diagnostic pop
10+
11+
12+
class Theme {
13+
public:
14+
struct MenuTheme {
15+
std::string font;
16+
// TODO: Actually support this in Font.
17+
unsigned int fontColor;
18+
};
19+
20+
struct ImageSet {
21+
std::string image480p;
22+
std::string image720p;
23+
};
24+
25+
explicit Theme(std::string themeDirectory);
26+
27+
void setTitle(std::string const& val) { title = val; }
28+
std::string const& getTitle() const { return title; }
29+
30+
void setBackground(ImageSet const& val) { background = val; }
31+
ImageSet const& getBackground() const { return background; }
32+
33+
void setMenu(MenuTheme const& val) { menu = val; }
34+
MenuTheme const& getMenu() const { return menu; }
35+
36+
std::string getAbsolutePath(std::string const& subpath) const {
37+
return rootPath + subpath;
38+
}
39+
40+
private:
41+
void load();
42+
43+
std::string rootPath;
44+
std::string title{ "??MISSING??" };
45+
ImageSet background;
46+
MenuTheme menu;
47+
};
48+
49+
void to_json(nlohmann::json& j, Theme const& o);
50+
void from_json(nlohmann::json const& j, Theme& o);
51+
52+
void to_json(nlohmann::json& j, Theme::MenuTheme const& o);
53+
void from_json(nlohmann::json const& j, Theme::MenuTheme& o);
54+
55+
void to_json(nlohmann::json& j, Theme::ImageSet const& o);
56+
void from_json(nlohmann::json const& j, Theme::ImageSet& o);
57+
58+
#endif // NEVOLUTIONX_THEME_H

Makefile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ SRCS += \
2222
$(SRCDIR)/sntpClient.cpp \
2323
$(SRCDIR)/subAppRouter.cpp \
2424
$(SRCDIR)/subsystems.cpp \
25+
$(SRCDIR)/theme.cpp \
2526
$(SRCDIR)/timeMenu.cpp \
2627
$(SRCDIR)/timing.cpp \
2728
$(SRCDIR)/videoMenu.cpp \
@@ -46,12 +47,17 @@ CFLAGS += -O2
4647
CXXFLAGS += -O2
4748
endif
4849

49-
new_all: copy_resources all
50-
5150
include $(NXDK_DIR)/Makefile
5251

53-
copy_resources: $(OUTPUT_DIR)/config.json
54-
@cp $(RESOURCEDIR)/480.png $(RESOURCEDIR)/720.png $(RESOURCEDIR)/vegur.ttf $(OUTPUT_DIR)
52+
RESOURCES = \
53+
$(OUTPUT_DIR)/config.json \
54+
$(patsubst $(CURDIR)/Resources/%,$(OUTPUT_DIR)/%,$(wildcard $(CURDIR)/Resources/NeXThemes/*))
55+
TARGET += $(RESOURCES)
56+
$(GEN_XISO): $(RESOURCES)
57+
58+
$(OUTPUT_DIR)/NeXThemes/%: $(CURDIR)/Resources/NeXThemes/%
59+
$(VE)mkdir -p '$(dir $@)'
60+
$(VE)cp -r '$<' '$@'
5561

5662
$(OUTPUT_DIR)/config.json: $(CURDIR)/sampleconfig.json
5763
@mkdir -p $(OUTPUT_DIR)
File renamed without changes.
File renamed without changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"title": "Default",
3+
"background": {
4+
"480": "480.png",
5+
"720": "720.png"
6+
},
7+
"menu": {
8+
"font": "vegur.ttf",
9+
"font_color": "FFFFFF"
10+
}
11+
}
File renamed without changes.

Sources/config.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,20 @@ void from_json(nlohmann::json const& j, homescreenConfig& o) {
212212
}
213213

214214
void to_json(nlohmann::json& j, Settings const& o) {
215-
j = nlohmann::json{ { "ftp", nlohmann::json(o.ftp) },
215+
j = nlohmann::json{ { "active_theme_directory", o.activeThemeDirectory },
216+
{ "ftp", nlohmann::json(o.ftp) },
216217
{ "mount", nlohmann::json(o.mount) },
217218
#ifdef NXDK
218219
{ "network", nlohmann::json(o.net) },
219220
#endif
220221
{ "logging", nlohmann::json(o.logging) },
221-
{ "homescreenConfig", nlohmann::json(o.homescreen) } };
222+
{ "homescreen", nlohmann::json(o.homescreen) } };
222223
}
223224

224225
void from_json(nlohmann::json const& j, Settings& o) {
226+
if (j.contains("active_theme_directory")) {
227+
o.activeThemeDirectory = j["active_theme_directory"];
228+
}
225229
if (j.contains("ftp")) {
226230
o.ftp = j["ftp"].get<ftpConfig>();
227231
}

0 commit comments

Comments
 (0)