From 978ad7c27049e5af6952fbcde78b8e59a29eef2f Mon Sep 17 00:00:00 2001 From: Thomas Jentzsch Date: Sun, 6 Sep 2020 15:30:40 +0200 Subject: [PATCH] working on more controllers and debugger widgets --- src/debugger/gui/DrivingWidget.cxx | 41 +++++++++++++++++-------- src/debugger/gui/DrivingWidget.hxx | 2 +- src/debugger/gui/JoystickWidget.cxx | 2 +- src/debugger/gui/NullControlWidget.hxx | 42 ++++++++++++++++++-------- src/debugger/gui/QuadTariWidget.cxx | 31 ++++++++++++++----- src/emucore/QuadTari.cxx | 21 +++++++++---- src/emucore/QuadTari.hxx | 5 +-- src/gui/QuadTariDialog.cxx | 4 +-- 8 files changed, 102 insertions(+), 46 deletions(-) diff --git a/src/debugger/gui/DrivingWidget.cxx b/src/debugger/gui/DrivingWidget.cxx index 29419268c..3dadc24b4 100644 --- a/src/debugger/gui/DrivingWidget.cxx +++ b/src/debugger/gui/DrivingWidget.cxx @@ -20,37 +20,52 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - DrivingWidget::DrivingWidget(GuiObject* boss, const GUI::Font& font, - int x, int y, Controller& controller) + int x, int y, Controller& controller, bool embedded) : ControllerWidget(boss, font, x, y, controller) { const string& label = getHeader(); const int fontHeight = font.getFontHeight(), - bwidth = font.getStringWidth("Gray code +") + 10, + fontWidth = font.getMaxCharWidth(), bheight = font.getLineHeight() + 4; int xpos = x, ypos = y, lwidth = font.getStringWidth("Right (Driving)"); StaticTextWidget* t; - t = new StaticTextWidget(boss, font, xpos, ypos+2, lwidth, - fontHeight, label, TextAlign::Left); + if(embedded) + { + const int bwidth = font.getStringWidth("GC+ "); - ypos += t->getHeight() + 20; - myGrayUp = new ButtonWidget(boss, font, xpos, ypos, bwidth, bheight, - "Gray code +", kGrayUpCmd); + myGrayUp = new ButtonWidget(boss, font, xpos, ypos, bwidth, bheight, + "GC+", kGrayUpCmd); + + ypos += myGrayUp->getHeight() + 5; + myGrayDown = new ButtonWidget(boss, font, xpos, ypos, bwidth, bheight, + "GC-", kGrayDownCmd); + } + else + { + const int bwidth = font.getStringWidth("Gray code +") + 10; + t = new StaticTextWidget(boss, font, xpos, ypos + 2, lwidth, + fontHeight, label, TextAlign::Left); + + ypos += t->getHeight() + 20; + myGrayUp = new ButtonWidget(boss, font, xpos, ypos, bwidth, bheight, + "Gray code +", kGrayUpCmd); + + ypos += myGrayUp->getHeight() + 5; + myGrayDown = new ButtonWidget(boss, font, xpos, ypos, bwidth, bheight, + "Gray code -", kGrayDownCmd); + } myGrayUp->setTarget(this); - - ypos += myGrayUp->getHeight() + 5; - myGrayDown = new ButtonWidget(boss, font, xpos, ypos, bwidth, bheight, - "Gray code -", kGrayDownCmd); myGrayDown->setTarget(this); - xpos += myGrayDown->getWidth() + 10; ypos -= 10; + xpos += myGrayDown->getWidth() + fontWidth; ypos -= 10; myGrayValue = new DataGridWidget(boss, font, xpos, ypos, 1, 1, 2, 8, Common::Base::Fmt::_16); myGrayValue->setTarget(this); myGrayValue->setEditable(false); - xpos = x + 30; ypos += myGrayDown->getHeight() + 20; + xpos = x + fontWidth*3; ypos += myGrayDown->getHeight() + 20; myFire = new CheckboxWidget(boss, font, xpos, ypos, "Fire", kFireCmd); myFire->setTarget(this); } diff --git a/src/debugger/gui/DrivingWidget.hxx b/src/debugger/gui/DrivingWidget.hxx index 0ab6c1d15..e8d648f8f 100644 --- a/src/debugger/gui/DrivingWidget.hxx +++ b/src/debugger/gui/DrivingWidget.hxx @@ -29,7 +29,7 @@ class DrivingWidget : public ControllerWidget { public: DrivingWidget(GuiObject* boss, const GUI::Font& font, int x, int y, - Controller& controller); + Controller& controller, bool embedded = false); ~DrivingWidget() override = default; private: diff --git a/src/debugger/gui/JoystickWidget.cxx b/src/debugger/gui/JoystickWidget.cxx index 6e9ad18dc..80455dea0 100644 --- a/src/debugger/gui/JoystickWidget.cxx +++ b/src/debugger/gui/JoystickWidget.cxx @@ -34,7 +34,7 @@ JoystickWidget::JoystickWidget(GuiObject* boss, const GUI::Font& font, t = new StaticTextWidget(boss, font, xpos, ypos + 2, lwidth, fontHeight, label, TextAlign::Left); - xpos += t->getWidth() / 2 - 5; ypos += t->getHeight() + 20; + xpos += t->getWidth() / 2 - 5; ypos = t->getBottom() + fontHeight; } myPins[kJUp] = new CheckboxWidget(boss, font, xpos, ypos, "", CheckboxWidget::kCheckActionCmd); diff --git a/src/debugger/gui/NullControlWidget.hxx b/src/debugger/gui/NullControlWidget.hxx index 79364ca6e..d5cef42c9 100644 --- a/src/debugger/gui/NullControlWidget.hxx +++ b/src/debugger/gui/NullControlWidget.hxx @@ -26,22 +26,38 @@ class NullControlWidget : public ControllerWidget { public: NullControlWidget(GuiObject* boss, const GUI::Font& font, int x, int y, - Controller& controller) + Controller& controller, bool embedded = false) : ControllerWidget(boss, font, x, y, controller) { - ostringstream buf; - buf << getHeader(); const int fontHeight = font.getFontHeight(), - lineHeight = font.getLineHeight(), - lwidth = std::max(font.getStringWidth(buf.str()), - font.getStringWidth("Controller input")); - new StaticTextWidget(boss, font, x, y+2, lwidth, - fontHeight, buf.str(), TextAlign::Left); - new StaticTextWidget(boss, font, x, y+2+2*lineHeight, lwidth, - fontHeight, "Controller input", TextAlign::Center); - new StaticTextWidget(boss, font, x, y+2+3*lineHeight, lwidth, - fontHeight, "not available", - TextAlign::Center); + lineHeight = font.getLineHeight(); + + if(embedded) + { + const int lwidth = font.getStringWidth("avail."); + + y += fontHeight; + new StaticTextWidget(boss, font, x, y, lwidth, fontHeight, + "not", TextAlign::Center); + y += lineHeight; + new StaticTextWidget(boss, font, x, y, lwidth, fontHeight, + "avail.", TextAlign::Center); + } + else + { + ostringstream buf; + buf << getHeader(); + const int lwidth = std::max(font.getStringWidth(buf.str()), + font.getStringWidth("Controller input")); + + new StaticTextWidget(boss, font, x, y + 2, lwidth, fontHeight, buf.str()); + y += 2 + lineHeight * 2; + new StaticTextWidget(boss, font, x, y, lwidth, + fontHeight, "Controller input", TextAlign::Center); + new StaticTextWidget(boss, font, x, y+lineHeight, lwidth, + fontHeight, "not available", + TextAlign::Center); + } } ~NullControlWidget() override = default; diff --git a/src/debugger/gui/QuadTariWidget.cxx b/src/debugger/gui/QuadTariWidget.cxx index 2c605da37..23db86995 100644 --- a/src/debugger/gui/QuadTariWidget.cxx +++ b/src/debugger/gui/QuadTariWidget.cxx @@ -19,6 +19,7 @@ #include "Console.hxx" #include "TIA.hxx" #include "QuadTari.hxx" +#include "DrivingWidget.hxx" #include "JoystickWidget.hxx" #include "NullControlWidget.hxx" #include "QuadTariWidget.hxx" @@ -28,40 +29,54 @@ QuadTariWidget::QuadTariWidget(GuiObject* boss, const GUI::Font& font, int x, int y, Controller& controller) : ControllerWidget(boss, font, x, y, controller) { + const int fontWidth = font.getMaxCharWidth(), + fontHeight = font.getFontHeight(); string label = (isLeftPort() ? "Left" : "Right") + string(" (QuadTari)"); StaticTextWidget* t = new StaticTextWidget(boss, font, x, y + 2, label); QuadTari& qt = static_cast(controller); - x += font.getMaxCharWidth() * 2; - y = t->getBottom() + font.getFontHeight() * 1.25; - // TODO: support multiple controller types switch(qt.myFirstController->type()) { case Controller::Type::Joystick: + x += fontWidth * 2; + y = t->getBottom() + fontHeight; myFirstControl = new JoystickWidget(boss, font, x, y, *qt.myFirstController, true); - x = myFirstControl->getRight() - font.getMaxCharWidth() * 8; + break; + + case Controller::Type::Driving: + y = t->getBottom() + font.getFontHeight() * 1; + myFirstControl = new DrivingWidget(boss, font, x, y, *qt.myFirstController, true); break; default: - myFirstControl = new NullControlWidget(boss, font, x, y, *qt.myFirstController); - x += font.getMaxCharWidth() * 8; + y = t->getBottom() + font.getFontHeight() * 1.25; + myFirstControl = new NullControlWidget(boss, font, x, y, *qt.myFirstController, true); break; } + x = t->getLeft() + fontWidth * 10; switch(qt.mySecondController->type()) { case Controller::Type::Joystick: + x += fontWidth * 2; + y = t->getBottom() + fontHeight; mySecondControl = new JoystickWidget(boss, font, x, y, *qt.mySecondController, true); break; + case Controller::Type::Driving: + y = t->getBottom() + font.getFontHeight(); + myFirstControl = new DrivingWidget(boss, font, x, y, *qt.mySecondController, true); + break; + default: - mySecondControl = new NullControlWidget(boss, font, x, y, *qt.mySecondController); + y = t->getBottom() + font.getFontHeight() * 1.25; + mySecondControl = new NullControlWidget(boss, font, x, y, *qt.mySecondController, true); break; } myPointer = new StaticTextWidget(boss, font, - x - font.getMaxCharWidth() * 5, y, " "); + t->getLeft() + font.getMaxCharWidth() * 7, y, " "); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/QuadTari.cxx b/src/emucore/QuadTari.cxx index 390fcac01..64c0cf027 100644 --- a/src/emucore/QuadTari.cxx +++ b/src/emucore/QuadTari.cxx @@ -25,18 +25,20 @@ #include "AtariVox.hxx" #include "Driving.hxx" #include "Joystick.hxx" +#include "Paddles.hxx" #include "SaveKey.hxx" #include "QuadTari.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -QuadTari::QuadTari(Jack jack, OSystem& osystem, const System& system, const Properties& properties) +QuadTari::QuadTari(Jack jack, const OSystem& osystem, const System& system, const Properties& properties) : Controller(jack, osystem.eventHandler().event(), system, Controller::Type::QuadTari), - myOSystem(osystem) + myOSystem(osystem), + myProperties(properties) { - string first, second; Controller::Type firstType = Controller::Type::Joystick, secondType = Controller::Type::Joystick; + string first, second; if(jack == Controller::Jack::Left) { @@ -74,6 +76,16 @@ unique_ptr QuadTari::addController(const Controller::Type type, bool switch(type) { + case Controller::Type::Paddles: + { + // Check if we should swap the paddles plugged into a jack + bool swapPaddles = myProperties.get(PropType::Controller_SwapPaddles) == "YES"; + + return make_unique(myJack, myEvent, mySystem, swapPaddles, false, false); + } + case Controller::Type::Driving: + return make_unique(myJack, myEvent, mySystem, second); + case Controller::Type::AtariVox: { nvramfile /= "atarivox_eeprom.dat"; @@ -81,9 +93,6 @@ unique_ptr QuadTari::addController(const Controller::Type type, bool myOSystem.settings().getString("avoxport"), nvramfile, callback); // no alternative mapping here } - case Controller::Type::Driving: - return make_unique(myJack, myEvent, mySystem, second); - case Controller::Type::SaveKey: { nvramfile /= "savekey_eeprom.dat"; diff --git a/src/emucore/QuadTari.hxx b/src/emucore/QuadTari.hxx index 449a43dff..2ce42e319 100644 --- a/src/emucore/QuadTari.hxx +++ b/src/emucore/QuadTari.hxx @@ -38,7 +38,7 @@ class QuadTari : public Controller @param system The system using this controller @param properties The properties to use for the current ROM */ - QuadTari(Jack jack, OSystem& osystem, const System& system, const Properties& properties); + QuadTari(Jack jack, const OSystem& osystem, const System& system, const Properties& properties); ~QuadTari() override = default; public: @@ -91,7 +91,8 @@ class QuadTari : public Controller private: unique_ptr addController(const Controller::Type type, bool second); - OSystem& myOSystem; + const OSystem& myOSystem; + const Properties& myProperties; unique_ptr myFirstController; unique_ptr mySecondController; diff --git a/src/gui/QuadTariDialog.cxx b/src/gui/QuadTariDialog.cxx index 3db0a6a65..b4d1891ef 100644 --- a/src/gui/QuadTariDialog.cxx +++ b/src/gui/QuadTariDialog.cxx @@ -47,7 +47,7 @@ QuadTariDialog::QuadTariDialog(GuiObject* boss, const GUI::Font& font, int max_w ctrls.clear(); //VarList::push_back(ctrls, "Auto-detect", "AUTO"); VarList::push_back(ctrls, "Joystick", "JOYSTICK"); - //VarList::push_back(ctrls, "Paddles", "PADDLES"); + VarList::push_back(ctrls, "Paddles", "PADDLES"); //VarList::push_back(ctrls, "Paddles_IAxis", "PADDLES_IAXIS"); //VarList::push_back(ctrls, "Paddles_IAxDr", "PADDLES_IAXDR"); //VarList::push_back(ctrls, "BoosterGrip", "BOOSTERGRIP"); @@ -64,7 +64,7 @@ QuadTariDialog::QuadTariDialog(GuiObject* boss, const GUI::Font& font, int max_w //VarList::push_back(ctrls, "MindLink", "MINDLINK"); //VarList::push_back(ctrls, "QuadTari", "QUADTARI"); - int pwidth = font.getStringWidth("Joystick12"); // looks better overall + int pwidth = font.getStringWidth("Joystick12"); // a bit wider looks better overall myLeftPortLabel = new StaticTextWidget(this, font, xpos, ypos + 1, "Left port");