From 4653c32646e9b2fd181771b9eb35f8756077bb9d Mon Sep 17 00:00:00 2001 From: Adubbz Date: Thu, 22 Feb 2018 21:22:41 +1100 Subject: [PATCH] Added a light theme --- Makefile.pc | 2 +- common/common.h | 1 + common/menu.c | 33 ++++++++++++++++++--------------- common/theme.c | 29 +++++++++++++++++++++++++++++ common/theme.h | 24 ++++++++++++++++++++++++ nx_main/main.c | 1 + pc_main/main.cpp | 1 + 7 files changed, 75 insertions(+), 16 deletions(-) create mode 100644 common/theme.c create mode 100644 common/theme.h diff --git a/Makefile.pc b/Makefile.pc index 9dad5cb..766f9b3 100644 --- a/Makefile.pc +++ b/Makefile.pc @@ -10,7 +10,7 @@ endef test : pc_main/main.cpp pc_main/pc_launch.c \ common/menu.c common/font.c common/language.c common/launch.c \ common/menu-entry.c common/menu-list.c common/text.c \ - common/nanojpeg.c common/ui.c common/math.c \ + common/nanojpeg.c common/ui.c common/math.c common/theme.c \ build_pc/tahoma24.o build_pc/tahoma12.o build_pc/switchicon_questionmark.bin.o build_pc/folder_icon.bin.o gcc -Wall -O2 -g0 $^ -lsfml-graphics -lsfml-window -lsfml-system -lstdc++ -I. -Ibuild_pc -o $@ diff --git a/common/common.h b/common/common.h index 8ccc429..9363c53 100644 --- a/common/common.h +++ b/common/common.h @@ -38,6 +38,7 @@ typedef union { #include "nro.h" #include "nanojpeg.h" #include "math.h" +#include "theme.h" void menuStartup(); void menuLoop(); diff --git a/common/menu.c b/common/menu.c index 8112eb8..9e2497a 100644 --- a/common/menu.c +++ b/common/menu.c @@ -43,7 +43,7 @@ static void drawEntry(menuEntry_s* me, int off_x, int is_active) { color_t border_color = MakeColor(255, 255, 255, 255); if (is_active) { - border_color = MakeColor(73, 103, 169, 255); + border_color = themeCurrent.highlightColor; } //{ @@ -132,15 +132,15 @@ static void drawEntry(menuEntry_s* me, int off_x, int is_active) { start_x = 220; start_y = 135; - DrawText(tahoma24, start_x + 256 + 64, start_y, MakeColor(255, 255, 255, 255), me->name); + DrawText(tahoma24, start_x + 256 + 64, start_y, themeCurrent.textColor, me->name); if (me->type != ENTRY_TYPE_FOLDER) { memset(tmpstr, 0, sizeof(tmpstr)); snprintf(tmpstr, sizeof(tmpstr)-1, "Author: %s", me->author); - DrawText(tahoma12, start_x + 256 + 64, start_y + 28 + 30, MakeColor(255, 255, 255, 255), tmpstr); + DrawText(tahoma12, start_x + 256 + 64, start_y + 28 + 30, themeCurrent.textColor, tmpstr); memset(tmpstr, 0, sizeof(tmpstr)); snprintf(tmpstr, sizeof(tmpstr)-1, "Version: %s", me->version); - DrawText(tahoma12, start_x + 256 + 64, start_y + 28 + 30 + 18 + 6, MakeColor(255, 255, 255, 255), tmpstr); + DrawText(tahoma12, start_x + 256 + 64, start_y + 28 + 30 + 18 + 6, themeCurrent.textColor, tmpstr); } } } @@ -164,7 +164,6 @@ color_t waveBlendAdd(color_t a, color_t b, float alpha) { return MakeColor(a.r+(b.r*alpha), a.g+b.g*alpha, a.b + b.b*alpha, 255); } -const int ENABLE_WAVE_BLENDING = 0; double timer; void drawWave(float timer, color_t color, float height, float phase, float speed) { @@ -182,10 +181,14 @@ void drawWave(float timer, color_t color, float height, float phase, float speed alpha = y-wave_top_y; existing_color = FetchPixelColor(x, y); - if (ENABLE_WAVE_BLENDING || alpha < 1.0) { + if (themeCurrent.enableWaveBlending) { new_color = waveBlendAdd(existing_color, color, clamp(alpha, 0.0, 1.0) * 0.3); } - else { + else if (alpha < 0.3) { // anti-aliasing + alpha = fabs(alpha); + new_color = MakeColor(color.r * (1.0 - alpha) + existing_color.r * alpha, color.g * (1.0 - alpha) + existing_color.g * alpha, color.b * (1.0 - alpha) + existing_color.b * alpha, 255); + } + else { // darken closer to bottom of the waves dark_mult = clamp((alpha - 50) / height, 0.0, 1.0); new_color = MakeColor(color.r - dark_sub * dark_mult, color.g - dark_sub * dark_mult, color.b - dark_sub * dark_mult, 255); } @@ -221,24 +224,24 @@ void menuLoop() { for (x=0; x<1280; x++) { for (y=0; y<720; y++) { - DrawPixelRaw(x, y, MakeColor(45, 55, 66, 255)); + DrawPixelRaw(x, y, themeCurrent.backgroundColor); } } - drawWave(timer, MakeColor(73, 103, 169, 255), 320.0, 0.0, 3.0); - drawWave(timer, MakeColor(66, 154, 159, 255), 300.0, 2.0, 3.5); - drawWave(timer, MakeColor(96, 204, 204, 255), 280.0, 4.0, -2.5); + drawWave(timer, themeCurrent.backWaveColor, 320.0, 0.0, 3.0); + drawWave(timer, themeCurrent.middleWaveColor, 300.0, 2.0, 3.5); + drawWave(timer, themeCurrent.frontWaveColor, 280.0, 4.0, -2.5); timer += 0.05; - DrawText(tahoma24, 40, 30, MakeColor(255, 255, 255, 255), "hbmenu"); - DrawText(tahoma12, 40 + 120, 30 + 16, MakeColor(255, 255, 255, 255), "v2.0.0"); - DrawText(tahoma12, 40, 720 - 32 - 16, MakeColor(255, 255, 255, 255), menu->dirname); + DrawText(tahoma24, 40, 30, themeCurrent.textColor, "hbmenu"); + DrawText(tahoma12, 40 + 120, 30 + 16, themeCurrent.textColor, "v2.0.0"); + DrawText(tahoma12, 40, 720 - 32 - 16, themeCurrent.textColor, menu->dirname); //drawTime(); if (menu->nEntries==0) { - DrawText(tahoma12, 64, 96 + 32, MakeColor(255, 255, 255, 255), textGetString(StrId_NoAppsFound_Msg)); + DrawText(tahoma12, 64, 96 + 32, themeCurrent.textColor, textGetString(StrId_NoAppsFound_Msg)); } else { diff --git a/common/theme.c b/common/theme.c new file mode 100644 index 0000000..6c25ae7 --- /dev/null +++ b/common/theme.c @@ -0,0 +1,29 @@ +#include "theme.h" + +void themeStartup(ThemePreset preset) { + switch (preset) { + case THEME_PRESET_DARK: + themeCurrent = (theme_t) { + textColor: MakeColor(255, 255, 255, 255), + frontWaveColor: MakeColor(96, 204, 204, 255), + middleWaveColor: MakeColor(66, 154, 159, 255), + backWaveColor: MakeColor(73, 103, 169, 255), + backgroundColor: MakeColor(45, 55, 66, 255), + highlightColor: MakeColor(73, 103, 169, 255), + enableWaveBlending: 0 + }; + break; + + case THEME_PRESET_LIGHT: + themeCurrent = (theme_t) { + textColor: MakeColor(0, 0, 0, 255), + frontWaveColor: MakeColor(100, 212, 250, 255), + middleWaveColor: MakeColor(100, 153, 255, 255), + backWaveColor: MakeColor(154, 171, 255, 255), + backgroundColor: MakeColor(233, 236, 241, 255), + highlightColor: MakeColor(129, 137, 236, 255), + enableWaveBlending: 0 + }; + break; + } +} \ No newline at end of file diff --git a/common/theme.h b/common/theme.h new file mode 100644 index 0000000..5b15add --- /dev/null +++ b/common/theme.h @@ -0,0 +1,24 @@ +#pragma once + +#include "common.h" + +typedef struct +{ + color_t textColor; + color_t frontWaveColor; + color_t middleWaveColor; + color_t backWaveColor; + color_t backgroundColor; + color_t highlightColor; + bool enableWaveBlending; +} theme_t; + +typedef enum +{ + THEME_PRESET_DARK, + THEME_PRESET_LIGHT, +} ThemePreset; + +void themeStartup(ThemePreset preset); + +theme_t themeCurrent; \ No newline at end of file diff --git a/nx_main/main.c b/nx_main/main.c index eee6fa1..cedfbb3 100644 --- a/nx_main/main.c +++ b/nx_main/main.c @@ -13,6 +13,7 @@ int main(int argc, char **argv) appletSetScreenShotPermission(1); + //themeStartup(); menuStartup(); launchInit(); diff --git a/pc_main/main.cpp b/pc_main/main.cpp index 9119ef3..6727a07 100644 --- a/pc_main/main.cpp +++ b/pc_main/main.cpp @@ -15,6 +15,7 @@ int main() sf::RenderWindow window(sf::VideoMode(1280, 720), "Test"); window.setFramerateLimit(60); + themeStartup(THEME_PRESET_LIGHT); menuStartup(); while (window.isOpen())