Skip to content

Commit

Permalink
added alternative theme, switchable via hotkey. this is a preparation…
Browse files Browse the repository at this point in the history
… for SDL2 supporting system theme change events (day/night) soon
  • Loading branch information
thrust26 committed Mar 15, 2023
1 parent 05a0481 commit 790bc51
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 18 deletions.
4 changes: 4 additions & 0 deletions Changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

* Enhanced Game Properties dialog for multigame ROMs.

* Added 2nd UI theme and hotkey for toggling UI theme.

* Added optional type format detection based on colors used.

* Added Joy2B+ controller support.
Expand All @@ -34,6 +36,8 @@

* Fixed broken 7800 pause key support.

* Fixed broken mouse and Stelladaptor input for Driving Controller.

* Added user defined CPU cycle timers to debugger.

* For UNIX systems: Now defaults to using system-installed libsqlite3
Expand Down
Binary file modified docs/graphics/options_misc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 18 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2034,6 +2034,11 @@ <h2><b><a name="Hotkeys">Hotkeys</a></b></h2>
<td>Alt + Return</td>
<td>Cmd + Return</td>
</tr>
<tr>
<td>Toggle UI theme</td>
<td>Alt + T</td>
<td>Cmd + T</td>
</tr>
<tr>
<td>Exit Stella</td>
<td>Control + Q</td>
Expand Down Expand Up @@ -3149,7 +3154,17 @@ <h2><b><a name="CommandLine">Using the Command Line</a></b></h2>

<tr>
<td><pre>-uipalette &lt;standard|classic|light|dark&gt;</pre></td>
<td>Use the specified palette for UI elements.</td>
<td>Define default palette/theme for UI elements.</td>
</tr>

<tr>
<td><pre>-uipalette2 &lt;standard|classic|light|dark&gt;</pre></td>
<td>Define alternative palette/theme for UI elements.</td>
</tr>

<tr>
<td><pre>-altpalette &lt;1|0&gt;</pre></td>
<td>Use alternative palette/theme for UI elements.</td>
</tr>

<tr>
Expand Down Expand Up @@ -3850,7 +3865,8 @@ <h2><b><a name="Options">Changing Options</a></b></h2>
<td valign="top">
<table border="1" cellpadding="4">
<tr><th>Item</th><th>Brief description</th><th>For more information,<br>see <a href="#CommandLine">Command Line</a></th></tr>
<tr><td>Theme</td><td>Theme to use for UI elements (see examples)</td><td>-uipalette</td></tr>
<tr><td>Theme #1</td><td>Default theme to use for UI elements (see examples)</td><td>-uipalette</td></tr>
<tr><td>Theme #2</td><td>Alternative theme to use for UI elements (see examples)</td><td>-uipalette2</td></tr>
<tr><td>Dialogs font</td><td>The font used in the dialogs</td><td>-dialogfont</td></tr>
<tr><td>HiDPI mode</td><td>Scale the UI by a factor of two when enabled</td><td>-hidpi</td></tr>
<tr><td>Dialogs position</td><td>Position of dialogs with Stella window</td><td>-dialogpos</td></tr>
Expand Down
1 change: 1 addition & 0 deletions src/common/PKeyboardHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ PhysicalKeyboardHandler::DefaultMenuMapping = {
{Event::UITabPrev, KBDK_TAB, KBDM_SHIFT | KBDM_CTRL},
{Event::UITabNext, KBDK_TAB, KBDM_CTRL},

{Event::ToggleUIPalette, KBDK_T, MOD3},
{Event::ToggleFullScreen, KBDK_RETURN, MOD3},

#ifdef BSPF_MACOS
Expand Down
1 change: 1 addition & 0 deletions src/common/jsonDefinitions.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ NLOHMANN_JSON_SERIALIZE_ENUM(Event::Type, {
{Event::UITabPrev, "UITabPrev"},
{Event::UITabNext, "UITabNext"},
{Event::UIHelp, "UIHelp"},
{Event::ToggleUIPalette, "ToggleUIPalette" },
{Event::MouseAxisXMove, "MouseAxisXMove"},
{Event::MouseAxisYMove, "MouseAxisYMove"},
{Event::MouseAxisXValue, "MouseAxisXValue"},
Expand Down
2 changes: 1 addition & 1 deletion src/emucore/Event.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class Event
SelectHome, SelectEnd, SelectAll,
Delete, DeleteLeftWord, DeleteRightWord, DeleteHome, DeleteEnd, Backspace,
Cut, Copy, Paste, Undo, Redo,
AbortEdit, EndEdit,
AbortEdit, EndEdit, ToggleUIPalette,

HighScoresMenuMode,
// Input settings
Expand Down
16 changes: 16 additions & 0 deletions src/emucore/EventHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ void EventHandler::set7800Mode()
myIs7800 = false;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::toggleUIPalette()
{
myOSystem.settings().setValue("altuipalette", !myOSystem.settings().getBool("altuipalette"));
myOSystem.frameBuffer().setUIPalette();
myOSystem.frameBuffer().update(FrameBuffer::UpdateMode::REDRAW);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::changeMouseControl(int direction)
{
Expand Down Expand Up @@ -529,6 +537,13 @@ void EventHandler::handleEvent(Event::Type event, Int32 value, bool repeated)
}
return;

case Event::ToggleUIPalette:
if(pressed && !repeated)
{
toggleUIPalette();
}
break;

case Event::ToggleFullScreen:
if(pressed && !repeated)
{
Expand Down Expand Up @@ -3109,6 +3124,7 @@ EventHandler::MenuActionList EventHandler::ourMenuActionList = { {

{ Event::UIPrevDir, "Parent directory" },
{ Event::ToggleFullScreen, "Toggle fullscreen" },
{ Event::ToggleUIPalette, "Toggle UI theme" },
{ Event::Quit, "Quit" }
} };

Expand Down
7 changes: 6 additions & 1 deletion src/emucore/EventHandler.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ class EventHandler
*/
void set7800Mode();

/**
Toggle between UI theme #1 and #2.
*/
void toggleUIPalette();

/**
Collects and dispatches any pending events. This method should be
called regularly (at X times per second, where X is the game framerate).
Expand Down Expand Up @@ -527,7 +532,7 @@ class EventHandler
REFRESH_SIZE = 0,
#endif
EMUL_ACTIONLIST_SIZE = 232 + PNG_SIZE + COMBO_SIZE + REFRESH_SIZE,
MENU_ACTIONLIST_SIZE = 19
MENU_ACTIONLIST_SIZE = 20
;

// The event(s) assigned to each combination event
Expand Down
8 changes: 5 additions & 3 deletions src/emucore/FrameBuffer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -989,11 +989,13 @@ void FrameBuffer::setTIAPalette(const PaletteArray& rgb_palette)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FrameBuffer::setUIPalette()
{
const Settings& settings = myOSystem.settings();
const string& key = settings.getBool("altuipalette") ? "uipalette2" : "uipalette";
// Set palette for UI (upper area of full palette)
const UIPaletteArray& ui_palette =
(myOSystem.settings().getString("uipalette") == "classic") ? ourClassicUIPalette :
(myOSystem.settings().getString("uipalette") == "light") ? ourLightUIPalette :
(myOSystem.settings().getString("uipalette") == "dark") ? ourDarkUIPalette :
(settings.getString(key) == "classic") ? ourClassicUIPalette :
(settings.getString(key) == "light") ? ourLightUIPalette :
(settings.getString(key) == "dark") ? ourDarkUIPalette :
ourStandardUIPalette;

for(size_t i = 0, j = myFullPalette.size() - ui_palette.size();
Expand Down
8 changes: 7 additions & 1 deletion src/emucore/Settings.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ Settings::Settings()
setPermanent("dbg.display", 0);
#endif
setPermanent("uipalette", "standard");
setPermanent("uipalette2", "dark");
setPermanent("altuipalette", "false");
setPermanent("hidpi", "false");
setPermanent("listdelay", "300");
setPermanent("mwheel", "4");
Expand Down Expand Up @@ -648,9 +650,13 @@ void Settings::usage()
<< " -lastrom <name> Last played ROM, automatically selected in\n"
<< " launcher\n"
<< " -romloadcount <number> Number of ROM to load next from multicard\n"
<< " -uipalette <standard| Selects GUI theme\n"
<< " -uipalette <standard| Set GUI theme\n"
<< " classic|\n"
<< " light|dark>\n"
<< " -uipalette2 <standard| Set alternative GUI theme\n"
<< " classic|\n"
<< " light|dark>\n"
<< " -altuipalette <0|1> Enable alternative GUI theme\n"
<< " -hidpi <0|1> Enable HiDPI mode\n"
<< " -dialogfont <small| Use the specified font in the dialogs\n"
<< " low_medium|\n"
Expand Down
30 changes: 21 additions & 9 deletions src/gui/UIDialog.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,16 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent,
VarList::push_back(items, "Classic", "classic");
VarList::push_back(items, "Light", "light");
VarList::push_back(items, "Dark", "dark");
myPalettePopup = new PopUpWidget(myTab, font, xpos, ypos, pwidth, lineHeight,
items, "Theme ", lwidth);
wid.push_back(myPalettePopup);
myPalette1Popup = new PopUpWidget(myTab, font, xpos, ypos, pwidth, lineHeight,
items, "Theme #1 ", lwidth);
myPalette1Popup->setToolTip("Primary theme.", Event::ToggleUIPalette, EventMode::kMenuMode);
wid.push_back(myPalette1Popup);
ypos += lineHeight + VGAP;

myPalette2Popup = new PopUpWidget(myTab, font, xpos, ypos, pwidth, lineHeight,
items, "Theme #2 ", lwidth);
myPalette2Popup->setToolTip("Alternative theme.", Event::ToggleUIPalette, EventMode::kMenuMode);
wid.push_back(myPalette2Popup);
ypos += lineHeight + VGAP;

// Dialog font
Expand Down Expand Up @@ -128,8 +135,8 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent,
wid.push_back(myCenter);

// Delay between quick-selecting characters in ListWidget
xpos = HBORDER; ypos += lineHeight + VGAP * 4;
const int swidth = myPalettePopup->getWidth() - lwidth;
xpos = HBORDER; ypos += lineHeight + VGAP * 3;
const int swidth = myPalette1Popup->getWidth() - lwidth;
myListDelaySlider = new SliderWidget(myTab, font, xpos, ypos, swidth, lineHeight,
"List input delay ", 0, kListDelay,
font.getStringWidth("1 second"));
Expand Down Expand Up @@ -388,8 +395,10 @@ void UIDialog::loadConfig()
myLauncherExitWidget->setState(exitlauncher);

// UI palette
const string& pal = settings.getString("uipalette");
myPalettePopup->setSelected(pal, "standard");
const string& pal1 = settings.getString("uipalette");
myPalette1Popup->setSelected(pal1, "standard");
const string& pal2 = settings.getString("uipalette2");
myPalette2Popup->setSelected(pal2, "dark");

// Dialog font
const string& dialogFont = settings.getString("dialogfont");
Expand Down Expand Up @@ -478,7 +487,9 @@ void UIDialog::saveConfig()

// UI palette
settings.setValue("uipalette",
myPalettePopup->getSelectedTag().toString());
myPalette1Popup->getSelectedTag().toString());
settings.setValue("uipalette2",
myPalette2Popup->getSelectedTag().toString());
instance().frameBuffer().setUIPalette();
instance().frameBuffer().update(FrameBuffer::UpdateMode::REDRAW);

Expand Down Expand Up @@ -526,7 +537,8 @@ void UIDialog::setDefaults()
switch(myTab->getActiveTab())
{
case 0: // Misc. options
myPalettePopup->setSelected("standard");
myPalette1Popup->setSelected("standard");
myPalette2Popup->setSelected("dark");
myDialogFontPopup->setSelected("medium", "");
myHidpiWidget->setState(false);
myPositionPopup->setSelected("0");
Expand Down
3 changes: 2 additions & 1 deletion src/gui/UIDialog.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class UIDialog : public Dialog, public CommandSender
CheckboxWidget* myLauncherExitWidget{nullptr};

// Misc options
PopUpWidget* myPalettePopup{nullptr};
PopUpWidget* myPalette1Popup{nullptr};
PopUpWidget* myPalette2Popup{nullptr};
PopUpWidget* myDialogFontPopup{nullptr};
CheckboxWidget* myHidpiWidget{nullptr};
PopUpWidget* myPositionPopup{nullptr};
Expand Down

0 comments on commit 790bc51

Please sign in to comment.