initial commit before refactoring

This commit is contained in:
thrust26 2020-01-19 15:45:32 +01:00
parent 7d17a74f62
commit e3f1a0f49f
14 changed files with 180 additions and 27 deletions

View File

@ -53,6 +53,7 @@
#ifdef GUI_SUPPORT
#include "Menu.hxx"
#include "CommandMenu.hxx"
#include "MessageMenu.hxx"
#include "DialogContainer.hxx"
#include "Launcher.hxx"
#include "TimeMachine.hxx"
@ -730,17 +731,35 @@ void EventHandler::handleEvent(Event::Type event, Int32 value, bool repeated)
return;
// this event is called when exiting a ROM from the debugger, so it acts like pressing ESC in emulation
case EventHandlerState::DEBUGGER:
case EventHandlerState::EMULATION:
case EventHandlerState::DEBUGGER:
if (pressed && !repeated)
{
exitEmulation();
// Go back to the launcher, or immediately quit
if (myOSystem.settings().getBool("exitlauncher") ||
myOSystem.launcherUsed())
myOSystem.createLauncher();
else
handleEvent(Event::Quit);
if (myState == EventHandlerState::EMULATION)
{
if (myOSystem.settings().getBool("confirmexit"))
{
StringList msg;
msg.push_back("Do you really want to exit emulation?");
msg.push_back("");
msg.push_back("You will lose all your progress.");
myOSystem.messageMenu().setMessage("Exit Emulation", msg, true);
enterMenuMode(EventHandlerState::MESSAGEMENU);
}
else
exitEmulation(true);
}
}
return;
case EventHandlerState::MESSAGEMENU:
if (pressed && !repeated)
{
leaveMenuMode();
if (myOSystem.messageMenu().confirmed())
exitEmulation(true);
}
return;
@ -978,7 +997,7 @@ bool EventHandler::changeStateByEvent(Event::Type type)
break;
case Event::OptionsMenuMode:
if(myState == EventHandlerState::EMULATION || myState == EventHandlerState::PAUSE)
if (myState == EventHandlerState::EMULATION || myState == EventHandlerState::PAUSE)
enterMenuMode(EventHandlerState::OPTIONSMENU);
else
handled = false;
@ -1696,6 +1715,11 @@ void EventHandler::setState(EventHandlerState state)
enableTextEvents(true);
break;
case EventHandlerState::MESSAGEMENU:
myOverlay = &myOSystem.messageMenu();
enableTextEvents(true);
break;
case EventHandlerState::TIMEMACHINE:
myOSystem.timeMachine().requestResize();
myOverlay = &myOSystem.timeMachine();
@ -1737,15 +1761,24 @@ void EventHandler::setState(EventHandlerState state)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::exitEmulation()
void EventHandler::exitEmulation(bool checkLauncher)
{
// TODO: confirm message
string saveOnExit = myOSystem.settings().getString("saveonexit");
if (saveOnExit == "all")
handleEvent(Event::SaveAllStates);
else if (saveOnExit == "current")
handleEvent(Event::SaveState);
if (checkLauncher)
{
// Go back to the launcher, or immediately quit
if (myOSystem.settings().getBool("exitlauncher") ||
myOSystem.launcherUsed())
myOSystem.createLauncher();
else
handleEvent(Event::Quit);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -26,6 +26,10 @@ class MouseControl;
class DialogContainer;
class PhysicalJoystick;
namespace GUI {
class Font;
}
#include "Event.hxx"
#include "EventHandlerConstants.hxx"
#include "Control.hxx"
@ -329,7 +333,7 @@ class EventHandler
void saveKeyMapping();
void saveJoyMapping();
void exitEmulation();
void exitEmulation(bool checkLauncher = false);
protected:
// Global OSystem object

View File

@ -26,6 +26,7 @@ enum class EventHandlerState {
LAUNCHER,
OPTIONSMENU,
CMDMENU,
MESSAGEMENU,
DEBUGGER,
NONE
};

View File

@ -42,6 +42,7 @@
#include "Launcher.hxx"
#include "Menu.hxx"
#include "CommandMenu.hxx"
#include "MessageMenu.hxx"
#include "TimeMachine.hxx"
#endif
@ -331,6 +332,18 @@ void FrameBuffer::update(bool force)
break; // EventHandlerState::CMDMENU
}
case EventHandlerState::MESSAGEMENU:
{
force = force || myOSystem.messageMenu().needsRedraw();
if (force)
{
clear();
myTIASurface->render();
myOSystem.messageMenu().draw(force);
}
break; // EventHandlerState::MESSAGEMENU
}
case EventHandlerState::TIMEMACHINE:
{
force = force || myOSystem.timeMachine().needsRedraw();

View File

@ -33,6 +33,7 @@
#ifdef GUI_SUPPORT
#include "Menu.hxx"
#include "CommandMenu.hxx"
#include "MessageMenu.hxx"
#include "Launcher.hxx"
#include "TimeMachine.hxx"
#include "Widget.hxx"
@ -171,6 +172,7 @@ bool OSystem::create()
// Create various subsystems (menu and launcher GUI objects, etc)
myMenu = make_unique<Menu>(*this);
myCommandMenu = make_unique<CommandMenu>(*this);
myMessageMenu = make_unique<MessageMenu>(*this);
myTimeMachine = make_unique<TimeMachine>(*this);
myLauncher = make_unique<Launcher>(*this);
#endif

View File

@ -39,6 +39,7 @@ class AudioSettings;
class CommandMenu;
class Launcher;
class Menu;
class MessageMenu;
class TimeMachine;
class VideoDialog;
#endif
@ -208,6 +209,13 @@ class OSystem
*/
CommandMenu& commandMenu() const { return *myCommandMenu; }
/**
Get the message menu of the system.
@return The message menu object
*/
MessageMenu& messageMenu() const { return *myMessageMenu; }
/**
Get the ROM launcher of the system.
@ -483,6 +491,9 @@ class OSystem
// Pointer to the CommandMenu object
unique_ptr<CommandMenu> myCommandMenu;
// Pointer to the CommandMenu object
unique_ptr<MessageMenu> myMessageMenu;
// Pointer to the Launcher object
unique_ptr<Launcher> myLauncher;

View File

@ -143,6 +143,7 @@ Settings::Settings()
setPermanent("ctrlrate", "20");
setPermanent("basic_settings", false);
setPermanent("dialogpos", 0);
setPermanent("confirmexit", false);
// Misc options
setPermanent("loglevel", int(Logger::Level::INFO));
@ -488,6 +489,7 @@ void Settings::usage() const
<< " classic|light>\n"
<< " -hidpi <0|1> Enable HiDPI mode\n"
<< " -dialogpos <0..4> Display all dialogs at given positions\n"
<< " -confirmexit <0|1> Display a confirm dialog when exiting emulation\n"
<< " -listdelay <delay> Time to wait between keypresses in list widgets\n"
<< " (300-1000)\n"
<< " -mwheel <lines> Number of lines the mouse wheel will scroll in\n"

View File

@ -27,13 +27,14 @@ namespace GUI {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MessageBox::MessageBox(GuiObject* boss, const GUI::Font& font,
const StringList& text, int max_w, int max_h, int cmd,
const StringList& text, int max_w, int max_h, int okCmd, int cancelCmd,
const string& okText, const string& cancelText,
const string& title,
bool focusOKButton)
: Dialog(boss->instance(), boss->parent(), font, title, 0, 0, max_w, max_h),
CommandSender(boss),
myCmd(cmd)
myOkCmd(okCmd),
myCancelCmd(cancelCmd)
{
addText(font, text);
@ -44,12 +45,34 @@ MessageBox::MessageBox(GuiObject* boss, const GUI::Font& font,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MessageBox::MessageBox(GuiObject* boss, const GUI::Font& font,
const string& text, int max_w, int max_h, int cmd,
const StringList& text, int max_w, int max_h, int okCmd,
const string& okText, const string& cancelText,
const string& title,
bool focusOKButton)
: MessageBox(boss, font, text, max_w, max_h,
okCmd, 0, okText, cancelText, title, focusOKButton)
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MessageBox::MessageBox(GuiObject* boss, const GUI::Font& font,
const string& text, int max_w, int max_h, int okCmd,
const string& okText, const string& cancelText,
const string& title,
bool focusOKButton)
: MessageBox(boss, font, StringParser(text).stringList(), max_w, max_h,
cmd, okText, cancelText, title, focusOKButton)
okCmd, okText, cancelText, title, focusOKButton)
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MessageBox::MessageBox(GuiObject* boss, const GUI::Font& font,
const string& text, int max_w, int max_h, int okCmd, int cancelCmd,
const string& okText, const string& cancelText,
const string& title,
bool focusOKButton)
: MessageBox(boss, font, StringParser(text).stringList(), max_w, max_h,
okCmd, cancelCmd, okText, cancelText, title, focusOKButton)
{
}
@ -85,8 +108,16 @@ void MessageBox::handleCommand(CommandSender* sender, int cmd, int data, int id)
// Send a signal to the calling class that 'OK' has been selected
// Since we aren't derived from a widget, we don't have a 'data' or 'id'
if(myCmd)
sendCommand(myCmd, 0, 0);
if(myOkCmd)
sendCommand(myOkCmd, 0, 0);
}
else if (cmd == GuiObject::kCloseCmd)
{
close();
// Send a signal to the calling class that 'Cancel' has been selected
if (myCancelCmd)
sendCommand(myCancelCmd, 0, 0);
}
else
Dialog::handleCommand(sender, cmd, data, id);

View File

@ -29,18 +29,28 @@ namespace GUI {
/**
* Show a simple message box containing the given text, with buttons
* prompting the user to accept or reject. If the user selects 'OK',
* the value of 'cmd' is returned.
* the value of 'okCmd' is returned.
*/
class MessageBox : public Dialog, public CommandSender
{
public:
MessageBox(GuiObject* boss, const GUI::Font& font, const StringList& text,
int max_w, int max_h, int cmd = 0,
int max_w, int max_h, int okCmd = 0, int cancelCmd = 0,
const string& okText = "OK", const string& cancelText = "Cancel",
const string& title = "",
bool focusOKButton = true);
MessageBox(GuiObject* boss, const GUI::Font& font, const StringList& text,
int max_w, int max_h, int okCmd = 0,
const string& okText = "OK", const string& cancelText = "Cancel",
const string& title = "",
bool focusOKButton = true);
MessageBox(GuiObject* boss, const GUI::Font& font, const string& text,
int max_w, int max_h, int cmd = 0,
int max_w, int max_h, int okCmd = 0,
const string& okText = "OK", const string& cancelText = "Cancel",
const string& title = "",
bool focusOKButton = true);
MessageBox(GuiObject* boss, const GUI::Font& font, const string& text,
int max_w, int max_h, int okCmd, int cancelCmd,
const string& okText = "OK", const string& cancelText = "Cancel",
const string& title = "",
bool focusOKButton = true);
@ -54,7 +64,8 @@ class MessageBox : public Dialog, public CommandSender
void handleCommand(CommandSender* sender, int cmd, int data, int id) override;
private:
int myCmd{0};
int myOkCmd{0};
int myCancelCmd{0};
private:
// Following constructors and assignment operators not supported

View File

@ -106,6 +106,22 @@ void RomAuditDialog::loadConfig()
myRomPath->setText(path);
myResults1->setText("");
myResults2->setText("");
if (!myConfirmMsg)
{
StringList msg;
msg.push_back("This operation cannot be undone. Your ROMs");
msg.push_back("will be modified, and as such there is a chance");
msg.push_back("that files may be lost. You are recommended");
msg.push_back("to back up your files before proceeding.");
msg.push_back("");
msg.push_back("If you're sure you want to proceed with the");
msg.push_back("audit, click 'OK', otherwise click 'Cancel'.");
myConfirmMsg = make_unique<GUI::MessageBox>
(this, myFont, msg, myMaxWidth, myMaxHeight, kConfirmAuditCmd,
"OK", "Cancel", "ROM Audit", false);
}
myConfirmMsg->show();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -85,6 +85,11 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent,
myPalettePopup = new PopUpWidget(myTab, font, xpos, ypos, pwidth, lineHeight,
items, "Theme ", lwidth);
wid.push_back(myPalettePopup);
// Enable HiDPI mode
myHidpiWidget = new CheckboxWidget(myTab, font, myPalettePopup->getRight() + 40,
ypos, "HiDPI mode (*)");
wid.push_back(myHidpiWidget);
ypos += lineHeight + V_GAP;
// Dialog position
@ -97,12 +102,12 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent,
myPositionPopup = new PopUpWidget(myTab, font, xpos, ypos, pwidth, lineHeight,
items, "Dialogs position ", lwidth);
wid.push_back(myPositionPopup);
ypos += lineHeight + V_GAP;
ypos += lineHeight + V_GAP * 2;
// Enable HiDPI mode
myHidpiWidget = new CheckboxWidget(myTab, font, xpos, ypos, "HiDPI mode (*)");
wid.push_back(myHidpiWidget);
ypos += lineHeight + V_GAP * 4;
// Confirm dialog when exiting emulation
myConfirmExitWidget = new CheckboxWidget(myTab, font, xpos, ypos, "Confirm exiting emulation");
wid.push_back(myConfirmExitWidget);
ypos += lineHeight + V_GAP * 3;
// Delay between quick-selecting characters in ListWidget
int swidth = myPalettePopup->getWidth() - lwidth;
@ -329,6 +334,9 @@ void UIDialog::loadConfig()
myHidpiWidget->setState(settings.getBool("hidpi"));
}
// Confirm dialog when exiting emulation
myConfirmExitWidget->setState(settings.getBool("confirmexit"));
// Dialog position
myPositionPopup->setSelected(settings.getString("dialogpos"), "0");
@ -395,6 +403,9 @@ void UIDialog::saveConfig()
// Dialog position
settings.setValue("dialogpos", myPositionPopup->getSelectedTag().toString());
// Confirm dialog when exiting emulation
settings.setValue("confirmexit", myConfirmExitWidget->getState());
// Listwidget quick delay
settings.setValue("listdelay", myListDelaySlider->getValue());
FileListWidget::setQuickSelectDelay(myListDelaySlider->getValue());
@ -429,6 +440,7 @@ void UIDialog::setDefaults()
myPalettePopup->setSelected("standard");
myHidpiWidget->setState(false);
myPositionPopup->setSelected("0");
myConfirmExitWidget->setState(false);
myListDelaySlider->setValue(300);
myWheelLinesSlider->setValue(4);
myDoubleClickSlider->setValue(500);

View File

@ -66,6 +66,7 @@ class UIDialog : public Dialog, public CommandSender
PopUpWidget* myPalettePopup{nullptr};
CheckboxWidget* myHidpiWidget{nullptr};
PopUpWidget* myPositionPopup{nullptr};
CheckboxWidget* myConfirmExitWidget{nullptr};
SliderWidget* myListDelaySlider{nullptr};
SliderWidget* myWheelLinesSlider{nullptr};
SliderWidget* myControllerRateSlider{nullptr};

View File

@ -518,6 +518,8 @@
<ClCompile Include="..\gui\FileListWidget.cxx" />
<ClCompile Include="..\gui\JoystickDialog.cxx" />
<ClCompile Include="..\gui\LoggerDialog.cxx" />
<ClCompile Include="..\gui\MessageDialog.cxx" />
<ClCompile Include="..\gui\MessageMenu.cxx" />
<ClCompile Include="..\gui\MinUICommandDialog.cxx" />
<ClCompile Include="..\gui\R77HelpDialog.cxx" />
<ClCompile Include="..\gui\RadioButtonWidget.cxx" />
@ -1252,6 +1254,8 @@
<ClInclude Include="..\gui\FileListWidget.hxx" />
<ClInclude Include="..\gui\JoystickDialog.hxx" />
<ClInclude Include="..\gui\LoggerDialog.hxx" />
<ClInclude Include="..\gui\MessageDialog.hxx" />
<ClInclude Include="..\gui\MessageMenu.hxx" />
<ClInclude Include="..\gui\MinUICommandDialog.hxx" />
<ClInclude Include="..\gui\R77HelpDialog.hxx" />
<ClInclude Include="..\gui\RadioButtonWidget.hxx" />

View File

@ -999,6 +999,12 @@
<ClCompile Include="..\emucore\Lightgun.cxx">
<Filter>Source Files\emucore</Filter>
</ClCompile>
<ClCompile Include="..\gui\MessageMenu.cxx">
<Filter>Source Files\gui</Filter>
</ClCompile>
<ClCompile Include="..\gui\MessageDialog.cxx">
<Filter>Source Files\gui</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\common\bspf.hxx">
@ -2042,6 +2048,12 @@
<ClInclude Include="..\emucore\Lightgun.hxx">
<Filter>Header Files\emucore</Filter>
</ClInclude>
<ClInclude Include="..\gui\MessageMenu.hxx">
<Filter>Header Files\gui</Filter>
</ClInclude>
<ClInclude Include="..\gui\MessageDialog.hxx">
<Filter>Header Files\gui</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="stella.ico">