Skip to content

Commit

Permalink
Merge pull request #5123 from aybe/even-more
Browse files Browse the repository at this point in the history
CFGTOOL: Windows themes
  • Loading branch information
aybe authored Jul 15, 2024
2 parents 5d1d451 + e0aa15b commit c2d3428
Show file tree
Hide file tree
Showing 9 changed files with 941 additions and 75 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ NEXT
- Fixed TTF mode didn't change to graphic mode when machine = Hercules
(maron2000)
- Configuration tool: (aybe)
- more Windows 3.1 styling: buttons, colors, focus, layout
- more Windows 3.1 look'n'feel (themes w/ host dark mode detection)
- enhance main window layout, it is now visible in its entirety
- fix layout issues, off by one in rectangle drawing functions
- fix 'list iterators incompatible' when pressing the Tab key
Expand Down
12 changes: 12 additions & 0 deletions src/dosbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,11 @@ void DOSBOX_SetupConfigSections(void) {
const char* quit_settings[] = { "true", "false", "1", "0", "auto", "autofile", nullptr };
const char* autofix_settings[] = { "true", "false", "1", "0", "both", "a20fix", "loadfix", "none", nullptr };
const char* color_themes[] = { "default", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", nullptr };
const char* color_themes_config[] = {
"Windows Default", "Arizona", "Black Leather Jacket", "Bordeaux", "Cinnamon", "Designer", "Emerald City",
"Fluorescent","HotDog Stand", "LCD Default Screen Settings", "LCD Reversed - Dark", "LCD Reversed - Light",
"Mahogany", "Monochrome", "Ocean", "Pastel", "Patchwork", "Plasma Power Saver", "Rugby", "The Blues",
"Tweed", "Valentine", "Wingtips", nullptr };
const char* irqsgus[] = { "5", "3", "7", "9", "10", "11", "12", nullptr };
const char* irqssb[] = { "7", "5", "3", "9", "10", "11", "12", "0", "-1", nullptr };
const char* dmasgus[] = { "3", "0", "1", "5", "6", "7", nullptr };
Expand Down Expand Up @@ -1575,6 +1580,13 @@ void DOSBOX_SetupConfigSections(void) {
Pstring->Set_help("You can specify a different background color theme for the welcome banner from the default one.");
Pstring->SetBasic(true);

Pstring = secprop->Add_path("configuration tool theme", Property::Changeable::WhenIdle, "");
Pstring->Set_values(color_themes_config);
Pstring->Set_help(
"Theme for the configuration tool.\n"
"If not set, host dark mode setting will be followed.\n");
Pstring->SetBasic(true);

Pstring = secprop->Add_string("dpi aware",Property::Changeable::OnlyAtStart,"auto");
Pstring->Set_values(truefalseautoopt);
Pstring->Set_help("Set this option (auto by default) to indicate to your OS that DOSBox-X is DPI aware.\n"
Expand Down
120 changes: 113 additions & 7 deletions src/gui/sdl_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3178,17 +3178,48 @@ class ConfigurationWindow : public GUI::ToplevelWindow {
bar->addItem(0,"");
bar->addItem(0,MSG_Get("CLOSE"));
bar->addMenu(MSG_Get("SETTINGS"));

// theme menu
{
bar->addMenu("Theme"); // TODO MSG_Get("THEME")
bar->addItem(2, GUI::ThemeWindows31WindowsDefault::GetName());
bar->addItem(2, "");
bar->addItem(2, GUI::ThemeWindows31Arizona::GetName());
bar->addItem(2, GUI::ThemeWindows31Bordeaux::GetName());
bar->addItem(2, GUI::ThemeWindows31Cinnamon::GetName());
bar->addItem(2, GUI::ThemeWindows31Designer::GetName());
bar->addItem(2, GUI::ThemeWindows31EmeraldCity::GetName());
bar->addItem(2, GUI::ThemeWindows31Fluorescent::GetName());
bar->addItem(2, GUI::ThemeWindows31HotDogStand::GetName());
bar->addItem(2, GUI::ThemeWindows31LCDDefaultScreenSettings::GetName());
bar->addItem(2, GUI::ThemeWindows31LCDReversedDark::GetName());
bar->addItem(2, GUI::ThemeWindows31LCDReversedLight::GetName());
bar->addItem(2, GUI::ThemeWindows31BlackLeatherJacket::GetName());
bar->addItem(2, "|");
bar->addItem(2, GUI::ThemeWindows31Mahogany::GetName());
bar->addItem(2, GUI::ThemeWindows31Monochrome::GetName());
bar->addItem(2, GUI::ThemeWindows31Ocean::GetName());
bar->addItem(2, GUI::ThemeWindows31Pastel::GetName());
bar->addItem(2, GUI::ThemeWindows31Patchwork::GetName());
bar->addItem(2, GUI::ThemeWindows31PlasmaPowerSaver::GetName());
bar->addItem(2, GUI::ThemeWindows31Rugby::GetName());
bar->addItem(2, GUI::ThemeWindows31TheBlues::GetName());
bar->addItem(2, GUI::ThemeWindows31Tweed::GetName());
bar->addItem(2, GUI::ThemeWindows31Valentine::GetName());
bar->addItem(2, GUI::ThemeWindows31Wingtips::GetName());
}

bar->addMenu(mainMenu.get_item("HelpMenu").get_text().c_str());
bar->addItem(2,MSG_Get("VISIT_HOMEPAGE"));
bar->addItem(2,"");
bar->addItem(3,MSG_Get("VISIT_HOMEPAGE"));
bar->addItem(3,"");
if (!dos_kernel_disabled) {
/* these do not work until shell help text is registered */
bar->addItem(2,MSG_Get("GET_STARTED"));
bar->addItem(2,MSG_Get("CDROM_SUPPORT"));
bar->addItem(2,"");
bar->addItem(3,MSG_Get("GET_STARTED"));
bar->addItem(3,MSG_Get("CDROM_SUPPORT"));
bar->addItem(3,"");
}
bar->addItem(2,MSG_Get("INTRODUCTION"));
bar->addItem(2,mainMenu.get_item("help_about").get_text().c_str());
bar->addItem(3,MSG_Get("INTRODUCTION"));
bar->addItem(3,mainMenu.get_item("help_about").get_text().c_str());
bar->addActionHandler(this);

int gridbtnwidth = 130;
Expand Down Expand Up @@ -3283,6 +3314,30 @@ class ConfigurationWindow : public GUI::ToplevelWindow {
Section_prop * section=static_cast<Section_prop *>(control->GetSection("dosbox"));
advopt->setChecked(section->Get_bool("show advanced options") || advOptUser);

// apply theme
{
auto theme = std::string(section->Get_string("configuration tool theme"));

if(theme.empty())
{
bool dark = false;

#if defined(WIN32) && !defined(HX_DOS)
// ReSharper disable once CppDeclaratorDisambiguatedAsFunction
bool HostDarkMode(); // NOLINT(clang-diagnostic-vexing-parse)
dark = HostDarkMode();
#endif
TryApplyTheme(
dark
? GUI::ThemeWindows31LCDReversedDark::GetName()
: GUI::ThemeWindows31LCDReversedLight::GetName());
}
else
{
TryApplyTheme(theme);
}
}

strcpy(tmp1, (MSG_Get("SAVE")+std::string("...")).c_str());

const auto xSave = gridbtnx + (gridbtnwidth + margin) * 2;
Expand Down Expand Up @@ -3316,8 +3371,59 @@ class ConfigurationWindow : public GUI::ToplevelWindow {
return false;
}

static void TryApplyTheme(const GUI::String& name)
{
if(name == GUI::ThemeWindows31WindowsDefault::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31WindowsDefault();
if(name == GUI::ThemeWindows31Arizona::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31Arizona();
if(name == GUI::ThemeWindows31Bordeaux::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31Bordeaux();
if(name == GUI::ThemeWindows31Cinnamon::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31Cinnamon();
if(name == GUI::ThemeWindows31Designer::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31Designer();
if(name == GUI::ThemeWindows31EmeraldCity::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31EmeraldCity();
if(name == GUI::ThemeWindows31Fluorescent::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31Fluorescent();
if(name == GUI::ThemeWindows31HotDogStand::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31HotDogStand();
if(name == GUI::ThemeWindows31LCDDefaultScreenSettings::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31LCDDefaultScreenSettings();
if(name == GUI::ThemeWindows31LCDReversedDark::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31LCDReversedDark();
if(name == GUI::ThemeWindows31LCDReversedLight::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31LCDReversedLight();
if(name == GUI::ThemeWindows31BlackLeatherJacket::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31BlackLeatherJacket();
if(name == GUI::ThemeWindows31Mahogany::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31Mahogany();
if(name == GUI::ThemeWindows31Monochrome::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31Monochrome();
if(name == GUI::ThemeWindows31Ocean::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31Ocean();
if(name == GUI::ThemeWindows31Pastel::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31Pastel();
if(name == GUI::ThemeWindows31Patchwork::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31Patchwork();
if(name == GUI::ThemeWindows31PlasmaPowerSaver::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31PlasmaPowerSaver();
if(name == GUI::ThemeWindows31Rugby::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31Rugby();
if(name == GUI::ThemeWindows31TheBlues::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31TheBlues();
if(name == GUI::ThemeWindows31Tweed::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31Tweed();
if(name == GUI::ThemeWindows31Valentine::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31Valentine();
if(name == GUI::ThemeWindows31Wingtips::GetName())
GUI::DefaultTheme = GUI::ThemeWindows31Wingtips();
}

void actionExecuted(GUI::ActionEventSource *b, const GUI::String &arg) override {
advOptUser = advopt->isChecked();
TryApplyTheme(arg); // TODO MSG_Get("THEME"), save to config
GUI::String sname = RestoreName(arg);
sname.at(0) = (unsigned int)std::tolower((int)sname.at(0));
Section *sec;
Expand Down
27 changes: 27 additions & 0 deletions src/gui/sdlmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,33 @@ bool UpdateWindows11RoundCorners(HWND hWnd, CornerPreference cornerPreference) {
}
return false;
}

bool HostDarkMode()
{
// https://gist.github.com/rounk-ctrl/b04e5622e30e0d62956870d5c22b7017

using PFNSHOULDAPPSUSEDARKMODE = bool (WINAPI *)();

const auto module = ::LoadLibrary("uxtheme.dll");

if(module)
{
auto* pfnShouldAppsUseDarkMode = reinterpret_cast<PFNSHOULDAPPSUSEDARKMODE>(
GetProcAddress(module, MAKEINTRESOURCEA(132)));

if(pfnShouldAppsUseDarkMode)
{
const auto dark = pfnShouldAppsUseDarkMode();

return dark;
}

FreeLibrary(module);
}

return false;
}

#endif

#if defined(WIN32)
Expand Down
Loading

0 comments on commit c2d3428

Please sign in to comment.