| 1 | //============================================================================ |
| 2 | // |
| 3 | // SSSS tt lll lll |
| 4 | // SS SS tt ll ll |
| 5 | // SS tttttt eeee ll ll aaaa |
| 6 | // SSSS tt ee ee ll ll aa |
| 7 | // SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" |
| 8 | // SS SS tt ee ll ll aa aa |
| 9 | // SSSS ttt eeeee llll llll aaaaa |
| 10 | // |
| 11 | // Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony |
| 12 | // and the Stella Team |
| 13 | // |
| 14 | // See the file "License.txt" for information on usage and redistribution of |
| 15 | // this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 16 | //============================================================================ |
| 17 | |
| 18 | #include "bspf.hxx" |
| 19 | #include "OSystem.hxx" |
| 20 | #include "Console.hxx" |
| 21 | #include "EventHandler.hxx" |
| 22 | #include "Joystick.hxx" |
| 23 | #include "Paddles.hxx" |
| 24 | #include "PointingDevice.hxx" |
| 25 | #include "SaveKey.hxx" |
| 26 | #include "AtariVox.hxx" |
| 27 | #include "Settings.hxx" |
| 28 | #include "EventMappingWidget.hxx" |
| 29 | #include "EditTextWidget.hxx" |
| 30 | #include "JoystickDialog.hxx" |
| 31 | #include "PopUpWidget.hxx" |
| 32 | #include "TabWidget.hxx" |
| 33 | #include "Widget.hxx" |
| 34 | #include "Font.hxx" |
| 35 | #include "MessageBox.hxx" |
| 36 | #include "InputDialog.hxx" |
| 37 | |
| 38 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 39 | InputDialog::InputDialog(OSystem& osystem, DialogContainer& parent, |
| 40 | const GUI::Font& font, int max_w, int max_h) |
| 41 | : Dialog(osystem, parent, font, "Input settings" ), |
| 42 | myConfirmMsg(nullptr), |
| 43 | myMaxWidth(max_w), |
| 44 | myMaxHeight(max_h) |
| 45 | { |
| 46 | const int lineHeight = font.getLineHeight(), |
| 47 | fontWidth = font.getMaxCharWidth(), |
| 48 | buttonHeight = font.getLineHeight() + 4; |
| 49 | const int vBorder = 4; |
| 50 | int xpos, ypos, tabID; |
| 51 | |
| 52 | // Set real dimensions |
| 53 | setSize(51 * fontWidth + 10, 17 * (lineHeight + 4) + 16 + _th, max_w, max_h); |
| 54 | |
| 55 | // The tab widget |
| 56 | xpos = 2; ypos = vBorder + _th; |
| 57 | myTab = new TabWidget(this, font, xpos, ypos, _w - 2*xpos, _h -_th - buttonHeight - 20); |
| 58 | addTabWidget(myTab); |
| 59 | |
| 60 | // 1) Event mapper for emulation actions |
| 61 | tabID = myTab->addTab(" Emulation Events " , TabWidget::AUTO_WIDTH); |
| 62 | myEmulEventMapper = new EventMappingWidget(myTab, font, 2, 2, |
| 63 | myTab->getWidth(), |
| 64 | myTab->getHeight() - 4, |
| 65 | EventMode::kEmulationMode); |
| 66 | myTab->setParentWidget(tabID, myEmulEventMapper); |
| 67 | addToFocusList(myEmulEventMapper->getFocusList(), myTab, tabID); |
| 68 | |
| 69 | // 2) Event mapper for UI actions |
| 70 | tabID = myTab->addTab(" UI Events " , TabWidget::AUTO_WIDTH); |
| 71 | myMenuEventMapper = new EventMappingWidget(myTab, font, 2, 2, |
| 72 | myTab->getWidth(), |
| 73 | myTab->getHeight() - 4, |
| 74 | EventMode::kMenuMode); |
| 75 | myTab->setParentWidget(tabID, myMenuEventMapper); |
| 76 | addToFocusList(myMenuEventMapper->getFocusList(), myTab, tabID); |
| 77 | |
| 78 | // 3) Devices & ports |
| 79 | addDevicePortTab(font); |
| 80 | |
| 81 | // Finalize the tabs, and activate the first tab |
| 82 | myTab->activateTabs(); |
| 83 | myTab->setActiveTab(0); |
| 84 | |
| 85 | // Add Defaults, OK and Cancel buttons |
| 86 | WidgetArray wid; |
| 87 | addDefaultsOKCancelBGroup(wid, font); |
| 88 | addBGroupToFocusList(wid); |
| 89 | } |
| 90 | |
| 91 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 92 | InputDialog::~InputDialog() |
| 93 | { |
| 94 | } |
| 95 | |
| 96 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 97 | void InputDialog::addDevicePortTab(const GUI::Font& font) |
| 98 | { |
| 99 | const int lineHeight = font.getLineHeight(), |
| 100 | fontWidth = font.getMaxCharWidth(), |
| 101 | fontHeight = font.getFontHeight(); |
| 102 | int xpos, ypos, lwidth, pwidth, tabID; |
| 103 | WidgetArray wid; |
| 104 | VariantList items; |
| 105 | const int VGAP = 4; |
| 106 | const int VBORDER = 9; |
| 107 | const int HBORDER = 8; |
| 108 | |
| 109 | // Devices/ports |
| 110 | tabID = myTab->addTab(" Devices & Ports " , TabWidget::AUTO_WIDTH); |
| 111 | |
| 112 | ypos = VBORDER; |
| 113 | lwidth = font.getStringWidth("Digital paddle sensitivity " ); // was: "Use mouse as a controller " |
| 114 | pwidth = font.getStringWidth("-UI, -Emulation" ); |
| 115 | |
| 116 | // Use mouse as controller |
| 117 | items.clear(); |
| 118 | VarList::push_back(items, "Always" , "always" ); |
| 119 | VarList::push_back(items, "Analog devices" , "analog" ); |
| 120 | VarList::push_back(items, "Never" , "never" ); |
| 121 | myMouseControl = new PopUpWidget(myTab, font, HBORDER, ypos, pwidth, lineHeight, items, |
| 122 | "Use mouse as a controller " , lwidth); |
| 123 | wid.push_back(myMouseControl); |
| 124 | |
| 125 | // Mouse cursor state |
| 126 | ypos += lineHeight + VGAP; |
| 127 | items.clear(); |
| 128 | VarList::push_back(items, "-UI, -Emulation" , "0" ); |
| 129 | VarList::push_back(items, "-UI, +Emulation" , "1" ); |
| 130 | VarList::push_back(items, "+UI, -Emulation" , "2" ); |
| 131 | VarList::push_back(items, "+UI, +Emulation" , "3" ); |
| 132 | myCursorState = new PopUpWidget(myTab, font, HBORDER, ypos, pwidth, lineHeight, items, |
| 133 | "Mouse cursor visibility " , lwidth); |
| 134 | wid.push_back(myCursorState); |
| 135 | #ifndef WINDOWED_SUPPORT |
| 136 | myCursorState->clearFlags(Widget::FLAG_ENABLED); |
| 137 | #endif |
| 138 | |
| 139 | lwidth = font.getStringWidth("Digital paddle sensitivity " ); |
| 140 | |
| 141 | // Add joystick deadzone setting |
| 142 | ypos += lineHeight + VGAP*3; |
| 143 | myDeadzone = new SliderWidget(myTab, font, HBORDER, ypos, 13 * fontWidth, lineHeight, |
| 144 | "Joystick deadzone size " , lwidth, kDeadzoneChanged); |
| 145 | myDeadzone->setMinValue(0); myDeadzone->setMaxValue(29); |
| 146 | myDeadzone->setTickmarkIntervals(4); |
| 147 | xpos = HBORDER + myDeadzone->getWidth() + 5; |
| 148 | myDeadzoneLabel = new StaticTextWidget(myTab, font, xpos, ypos+1, 5*fontWidth, lineHeight, "" ); |
| 149 | wid.push_back(myDeadzone); |
| 150 | |
| 151 | // Add dejitter (Stelladaptor emulation for now only) |
| 152 | ypos += lineHeight + VGAP; |
| 153 | myDejitterBase = new SliderWidget(myTab, font, HBORDER, ypos, 6 * fontWidth, lineHeight, |
| 154 | "Paddle dejitter strength" , lwidth, kDejitterChanged); |
| 155 | myDejitterBase->setMinValue(Paddles::MIN_DEJITTER); myDejitterBase->setMaxValue(Paddles::MAX_DEJITTER); |
| 156 | myDejitterBase->setTickmarkIntervals(2); |
| 157 | xpos = HBORDER + myDejitterBase->getWidth() + fontWidth; |
| 158 | wid.push_back(myDejitterBase); |
| 159 | |
| 160 | myDejitterDiff = new SliderWidget(myTab, font, xpos, ypos, 6 * fontWidth, lineHeight, |
| 161 | "" , 0, kDejitterChanged); |
| 162 | myDejitterDiff->setMinValue(Paddles::MIN_DEJITTER); myDejitterDiff->setMaxValue(Paddles::MAX_DEJITTER); |
| 163 | myDejitterDiff->setTickmarkIntervals(2); |
| 164 | xpos += myDejitterDiff->getWidth() + 5; |
| 165 | wid.push_back(myDejitterDiff); |
| 166 | |
| 167 | myDejitterLabel = new StaticTextWidget(myTab, font, xpos, ypos + 1, 7 * fontWidth, lineHeight, "" ); |
| 168 | |
| 169 | // Add paddle speed (digital emulation) |
| 170 | ypos += lineHeight + VGAP; |
| 171 | myDPaddleSpeed = new SliderWidget(myTab, font, HBORDER, ypos, 13 * fontWidth, lineHeight, |
| 172 | "Digital paddle sensitivity " , |
| 173 | lwidth, kDPSpeedChanged); |
| 174 | myDPaddleSpeed->setMinValue(1); myDPaddleSpeed->setMaxValue(20); |
| 175 | myDPaddleSpeed->setTickmarkIntervals(4); |
| 176 | xpos = HBORDER + myDPaddleSpeed->getWidth() + 5; |
| 177 | myDPaddleLabel = new StaticTextWidget(myTab, font, xpos, ypos+1, 24, lineHeight, "" ); |
| 178 | wid.push_back(myDPaddleSpeed); |
| 179 | |
| 180 | // Add paddle speed (mouse emulation) |
| 181 | ypos += lineHeight + VGAP; |
| 182 | myMPaddleSpeed = new SliderWidget(myTab, font, HBORDER, ypos, 13 * fontWidth, lineHeight, |
| 183 | "Mouse paddle sensitivity " , |
| 184 | lwidth, kMPSpeedChanged); |
| 185 | myMPaddleSpeed->setMinValue(1); myMPaddleSpeed->setMaxValue(20); |
| 186 | myMPaddleSpeed->setTickmarkIntervals(4); |
| 187 | xpos = HBORDER + myMPaddleSpeed->getWidth() + 5; |
| 188 | myMPaddleLabel = new StaticTextWidget(myTab, font, xpos, ypos+1, 24, lineHeight, "" ); |
| 189 | wid.push_back(myMPaddleSpeed); |
| 190 | |
| 191 | // Add trackball speed |
| 192 | ypos += lineHeight + VGAP; |
| 193 | myTrackBallSpeed = new SliderWidget(myTab, font, HBORDER, ypos, 13 * fontWidth, lineHeight, |
| 194 | "Trackball sensitivity " , |
| 195 | lwidth, kTBSpeedChanged); |
| 196 | myTrackBallSpeed->setMinValue(1); myTrackBallSpeed->setMaxValue(20); |
| 197 | myTrackBallSpeed->setTickmarkIntervals(4); |
| 198 | xpos = HBORDER + myTrackBallSpeed->getWidth() + 5; |
| 199 | myTrackBallLabel = new StaticTextWidget(myTab, font, xpos, ypos+1, 24, lineHeight, "" ); |
| 200 | wid.push_back(myTrackBallSpeed); |
| 201 | |
| 202 | // Add 'allow all 4 directions' for joystick |
| 203 | ypos += lineHeight + VGAP*3; |
| 204 | myAllowAll4 = new CheckboxWidget(myTab, font, HBORDER, ypos, |
| 205 | "Allow all 4 directions on joystick" ); |
| 206 | wid.push_back(myAllowAll4); |
| 207 | |
| 208 | // Grab mouse (in windowed mode) |
| 209 | ypos += lineHeight + VGAP; |
| 210 | myGrabMouse = new CheckboxWidget(myTab, font, HBORDER, ypos, |
| 211 | "Grab mouse in emulation mode" ); |
| 212 | wid.push_back(myGrabMouse); |
| 213 | #ifndef WINDOWED_SUPPORT |
| 214 | myGrabMouse->clearFlags(Widget::FLAG_ENABLED); |
| 215 | #endif |
| 216 | |
| 217 | // Enable/disable modifier key-combos |
| 218 | ypos += lineHeight + VGAP; |
| 219 | myModCombo = new CheckboxWidget(myTab, font, HBORDER, ypos, |
| 220 | "Use modifier key combos" ); |
| 221 | wid.push_back(myModCombo); |
| 222 | ypos += lineHeight + VGAP; |
| 223 | |
| 224 | // Stelladaptor mappings |
| 225 | mySAPort = new CheckboxWidget(myTab, font, HBORDER, ypos, |
| 226 | "Swap Stelladaptor ports" ); |
| 227 | wid.push_back(mySAPort); |
| 228 | |
| 229 | int fwidth; |
| 230 | |
| 231 | // Add EEPROM erase (part 1/2) |
| 232 | ypos += VGAP*4; |
| 233 | fwidth = font.getStringWidth("AtariVox/SaveKey" ); |
| 234 | lwidth = font.getStringWidth("AtariVox/SaveKey" ); |
| 235 | new StaticTextWidget(myTab, font, _w - HBORDER - 4 - (fwidth + lwidth) / 2, ypos, |
| 236 | "AtariVox/SaveKey" ); |
| 237 | |
| 238 | // Show joystick database |
| 239 | ypos += lineHeight; |
| 240 | myJoyDlgButton = new ButtonWidget(myTab, font, HBORDER, ypos, 20, |
| 241 | "Joystick Database" + ELLIPSIS, kDBButtonPressed); |
| 242 | wid.push_back(myJoyDlgButton); |
| 243 | |
| 244 | // Add EEPROM erase (part 1/2) |
| 245 | myEraseEEPROMButton = new ButtonWidget(myTab, font, _w - HBORDER - 4 - fwidth, ypos, |
| 246 | fwidth, lineHeight+4, |
| 247 | "Erase EEPROM" , kEEButtonPressed); |
| 248 | wid.push_back(myEraseEEPROMButton); |
| 249 | |
| 250 | // Add AtariVox serial port |
| 251 | ypos += lineHeight + VGAP*2; |
| 252 | lwidth = font.getStringWidth("AVox serial port " ); |
| 253 | fwidth = _w - HBORDER * 2 - 4 - lwidth; |
| 254 | new StaticTextWidget(myTab, font, HBORDER, ypos + 2, "AVox serial port " ); |
| 255 | myAVoxPort = new EditTextWidget(myTab, font, HBORDER + lwidth, ypos, |
| 256 | fwidth, fontHeight); |
| 257 | |
| 258 | wid.push_back(myAVoxPort); |
| 259 | |
| 260 | // Add items for virtual device ports |
| 261 | addToFocusList(wid, myTab, tabID); |
| 262 | } |
| 263 | |
| 264 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 265 | void InputDialog::loadConfig() |
| 266 | { |
| 267 | // Left & right ports |
| 268 | mySAPort->setState(instance().settings().getString("saport" ) == "rl" ); |
| 269 | |
| 270 | // Use mouse as a controller |
| 271 | myMouseControl->setSelected( |
| 272 | instance().settings().getString("usemouse" ), "analog" ); |
| 273 | |
| 274 | // Mouse cursor state |
| 275 | myCursorState->setSelected(instance().settings().getString("cursor" ), "2" ); |
| 276 | |
| 277 | // Joystick deadzone |
| 278 | myDeadzone->setValue(instance().settings().getInt("joydeadzone" )); |
| 279 | myDeadzoneLabel->setValue(Joystick::deadzone()); |
| 280 | |
| 281 | // Paddle speed (digital and mouse) |
| 282 | myDejitterBase->setValue(instance().settings().getInt("dejitter.base" )); |
| 283 | myDejitterDiff->setValue(instance().settings().getInt("dejitter.diff" )); |
| 284 | UpdateDejitter(); |
| 285 | myDPaddleSpeed->setValue(instance().settings().getInt("dsense" )); |
| 286 | myDPaddleLabel->setLabel(instance().settings().getString("dsense" )); |
| 287 | myMPaddleSpeed->setValue(instance().settings().getInt("msense" )); |
| 288 | myMPaddleLabel->setLabel(instance().settings().getString("msense" )); |
| 289 | |
| 290 | // Trackball speed |
| 291 | myTrackBallSpeed->setValue(instance().settings().getInt("tsense" )); |
| 292 | myTrackBallLabel->setLabel(instance().settings().getString("tsense" )); |
| 293 | |
| 294 | // AtariVox serial port |
| 295 | myAVoxPort->setText(instance().settings().getString("avoxport" )); |
| 296 | |
| 297 | // EEPROM erase (only enable in emulation mode and for valid controllers) |
| 298 | if(instance().hasConsole()) |
| 299 | { |
| 300 | Controller& lport = instance().console().leftController(); |
| 301 | Controller& rport = instance().console().rightController(); |
| 302 | |
| 303 | myEraseEEPROMButton->setEnabled(lport.type() == Controller::Type::SaveKey || lport.type() == Controller::Type::AtariVox || |
| 304 | rport.type() == Controller::Type::SaveKey || rport.type() == Controller::Type::AtariVox); |
| 305 | } |
| 306 | else |
| 307 | myEraseEEPROMButton->setEnabled(false); |
| 308 | |
| 309 | // Allow all 4 joystick directions |
| 310 | myAllowAll4->setState(instance().settings().getBool("joyallow4" )); |
| 311 | |
| 312 | // Grab mouse |
| 313 | myGrabMouse->setState(instance().settings().getBool("grabmouse" )); |
| 314 | |
| 315 | // Enable/disable modifier key-combos |
| 316 | myModCombo->setState(instance().settings().getBool("modcombo" )); |
| 317 | |
| 318 | myTab->loadConfig(); |
| 319 | } |
| 320 | |
| 321 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 322 | void InputDialog::saveConfig() |
| 323 | { |
| 324 | // Left & right ports |
| 325 | instance().eventHandler().mapStelladaptors(mySAPort->getState() ? "rl" : "lr" ); |
| 326 | |
| 327 | // Use mouse as a controller |
| 328 | const string& usemouse = myMouseControl->getSelectedTag().toString(); |
| 329 | instance().settings().setValue("usemouse" , usemouse); |
| 330 | instance().eventHandler().setMouseControllerMode(usemouse); |
| 331 | |
| 332 | // Joystick deadzone |
| 333 | int deadzone = myDeadzone->getValue(); |
| 334 | instance().settings().setValue("joydeadzone" , deadzone); |
| 335 | Joystick::setDeadZone(deadzone); |
| 336 | |
| 337 | // Paddle speed (digital and mouse) |
| 338 | int dejitter = myDejitterBase->getValue(); |
| 339 | instance().settings().setValue("dejitter.base" , dejitter); |
| 340 | Paddles::setDejitterBase(dejitter); |
| 341 | dejitter = myDejitterDiff->getValue(); |
| 342 | instance().settings().setValue("dejitter.diff" , dejitter); |
| 343 | Paddles::setDejitterDiff(dejitter); |
| 344 | |
| 345 | int sensitivity = myDPaddleSpeed->getValue(); |
| 346 | instance().settings().setValue("dsense" , sensitivity); |
| 347 | Paddles::setDigitalSensitivity(sensitivity); |
| 348 | |
| 349 | sensitivity = myMPaddleSpeed->getValue(); |
| 350 | instance().settings().setValue("msense" , sensitivity); |
| 351 | Paddles::setMouseSensitivity(sensitivity); |
| 352 | |
| 353 | // Trackball speed |
| 354 | sensitivity = myTrackBallSpeed->getValue(); |
| 355 | instance().settings().setValue("tsense" , sensitivity); |
| 356 | PointingDevice::setSensitivity(sensitivity); |
| 357 | |
| 358 | // AtariVox serial port |
| 359 | instance().settings().setValue("avoxport" , myAVoxPort->getText()); |
| 360 | |
| 361 | // Allow all 4 joystick directions |
| 362 | bool allowall4 = myAllowAll4->getState(); |
| 363 | instance().settings().setValue("joyallow4" , allowall4); |
| 364 | instance().eventHandler().allowAllDirections(allowall4); |
| 365 | |
| 366 | // Grab mouse and hide cursor |
| 367 | const string& cursor = myCursorState->getSelectedTag().toString(); |
| 368 | instance().settings().setValue("cursor" , cursor); |
| 369 | instance().settings().setValue("grabmouse" , myGrabMouse->getState()); |
| 370 | instance().frameBuffer().enableGrabMouse(myGrabMouse->getState()); |
| 371 | |
| 372 | // Enable/disable modifier key-combos |
| 373 | instance().settings().setValue("modcombo" , myModCombo->getState()); |
| 374 | |
| 375 | instance().eventHandler().saveKeyMapping(); |
| 376 | instance().eventHandler().saveJoyMapping(); |
| 377 | // instance().saveConfig(); |
| 378 | } |
| 379 | |
| 380 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 381 | void InputDialog::setDefaults() |
| 382 | { |
| 383 | switch(myTab->getActiveTab()) |
| 384 | { |
| 385 | case 0: // Emulation events |
| 386 | myEmulEventMapper->setDefaults(); |
| 387 | break; |
| 388 | |
| 389 | case 1: // UI events |
| 390 | myMenuEventMapper->setDefaults(); |
| 391 | break; |
| 392 | |
| 393 | case 2: // Virtual devices |
| 394 | { |
| 395 | // Left & right ports |
| 396 | mySAPort->setState(false); |
| 397 | |
| 398 | // Use mouse as a controller |
| 399 | myMouseControl->setSelected("analog" ); |
| 400 | |
| 401 | // Mouse cursor state |
| 402 | myCursorState->setSelected("2" ); |
| 403 | |
| 404 | // Joystick deadzone |
| 405 | myDeadzone->setValue(0); |
| 406 | myDeadzoneLabel->setValue(3200); |
| 407 | |
| 408 | // Paddle speed (digital and mouse) |
| 409 | myDPaddleSpeed->setValue(10); |
| 410 | myDPaddleLabel->setLabel("10" ); |
| 411 | myMPaddleSpeed->setValue(10); |
| 412 | myMPaddleLabel->setLabel("10" ); |
| 413 | #if defined(RETRON77) |
| 414 | myDejitterBase->setValue(2); |
| 415 | myDejitterDiff->setValue(6); |
| 416 | #else |
| 417 | myDejitterBase->setValue(0); |
| 418 | myDejitterDiff->setValue(0); |
| 419 | #endif |
| 420 | UpdateDejitter(); |
| 421 | myTrackBallSpeed->setValue(10); |
| 422 | myTrackBallLabel->setLabel("10" ); |
| 423 | |
| 424 | // AtariVox serial port |
| 425 | myAVoxPort->setText("" ); |
| 426 | |
| 427 | // Allow all 4 joystick directions |
| 428 | myAllowAll4->setState(false); |
| 429 | |
| 430 | // Grab mouse |
| 431 | myGrabMouse->setState(true); |
| 432 | |
| 433 | // Enable/disable modifier key-combos |
| 434 | myModCombo->setState(true); |
| 435 | |
| 436 | break; |
| 437 | } |
| 438 | |
| 439 | default: |
| 440 | break; |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 445 | bool InputDialog::repeatEnabled() |
| 446 | { |
| 447 | return !myEmulEventMapper->isRemapping() && !myMenuEventMapper->isRemapping(); |
| 448 | } |
| 449 | |
| 450 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 451 | void InputDialog::handleKeyDown(StellaKey key, StellaMod mod, bool repeated) |
| 452 | { |
| 453 | // Remap key events in remap mode, otherwise pass to parent dialog |
| 454 | if (myEmulEventMapper->remapMode()) |
| 455 | myEmulEventMapper->handleKeyDown(key, mod); |
| 456 | else if (myMenuEventMapper->remapMode()) |
| 457 | myMenuEventMapper->handleKeyDown(key, mod); |
| 458 | else |
| 459 | Dialog::handleKeyDown(key, mod); |
| 460 | } |
| 461 | |
| 462 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 463 | void InputDialog::handleKeyUp(StellaKey key, StellaMod mod) |
| 464 | { |
| 465 | // Remap key events in remap mode, otherwise pass to parent dialog |
| 466 | if (myEmulEventMapper->remapMode()) |
| 467 | myEmulEventMapper->handleKeyUp(key, mod); |
| 468 | else if (myMenuEventMapper->remapMode()) |
| 469 | myMenuEventMapper->handleKeyUp(key, mod); |
| 470 | else |
| 471 | Dialog::handleKeyUp(key, mod); |
| 472 | } |
| 473 | |
| 474 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 475 | void InputDialog::handleJoyDown(int stick, int button, bool longPress) |
| 476 | { |
| 477 | // Remap joystick buttons in remap mode, otherwise pass to parent dialog |
| 478 | if(myEmulEventMapper->remapMode()) |
| 479 | myEmulEventMapper->handleJoyDown(stick, button); |
| 480 | else if(myMenuEventMapper->remapMode()) |
| 481 | myMenuEventMapper->handleJoyDown(stick, button); |
| 482 | else |
| 483 | Dialog::handleJoyDown(stick, button); |
| 484 | } |
| 485 | |
| 486 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 487 | void InputDialog::handleJoyUp(int stick, int button) |
| 488 | { |
| 489 | // Remap joystick buttons in remap mode, otherwise pass to parent dialog |
| 490 | if (myEmulEventMapper->remapMode()) |
| 491 | myEmulEventMapper->handleJoyUp(stick, button); |
| 492 | else if (myMenuEventMapper->remapMode()) |
| 493 | myMenuEventMapper->handleJoyUp(stick, button); |
| 494 | else |
| 495 | Dialog::handleJoyUp(stick, button); |
| 496 | } |
| 497 | |
| 498 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 499 | void InputDialog::handleJoyAxis(int stick, JoyAxis axis, JoyDir adir, int button) |
| 500 | { |
| 501 | // Remap joystick axis in remap mode, otherwise pass to parent dialog |
| 502 | if(myEmulEventMapper->remapMode()) |
| 503 | myEmulEventMapper->handleJoyAxis(stick, axis, adir, button); |
| 504 | else if(myMenuEventMapper->remapMode()) |
| 505 | myMenuEventMapper->handleJoyAxis(stick, axis, adir, button); |
| 506 | else |
| 507 | Dialog::handleJoyAxis(stick, axis, adir, button); |
| 508 | } |
| 509 | |
| 510 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 511 | bool InputDialog::handleJoyHat(int stick, int hat, JoyHatDir hdir, int button) |
| 512 | { |
| 513 | // Remap joystick hat in remap mode, otherwise pass to parent dialog |
| 514 | if(myEmulEventMapper->remapMode()) |
| 515 | return myEmulEventMapper->handleJoyHat(stick, hat, hdir, button); |
| 516 | else if(myMenuEventMapper->remapMode()) |
| 517 | return myMenuEventMapper->handleJoyHat(stick, hat, hdir, button); |
| 518 | else |
| 519 | return Dialog::handleJoyHat(stick, hat, hdir, button); |
| 520 | } |
| 521 | |
| 522 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 523 | void InputDialog::eraseEEPROM() |
| 524 | { |
| 525 | // This method will only be callable if a console exists, so we don't |
| 526 | // need to check again here |
| 527 | Controller& lport = instance().console().leftController(); |
| 528 | Controller& rport = instance().console().rightController(); |
| 529 | |
| 530 | if(lport.type() == Controller::Type::SaveKey || lport.type() == Controller::Type::AtariVox) |
| 531 | { |
| 532 | SaveKey& skey = static_cast<SaveKey&>(lport); |
| 533 | skey.eraseCurrent(); |
| 534 | } |
| 535 | |
| 536 | if(rport.type() == Controller::Type::SaveKey || rport.type() == Controller::Type::AtariVox) |
| 537 | { |
| 538 | SaveKey& skey = static_cast<SaveKey&>(rport); |
| 539 | skey.eraseCurrent(); |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 544 | void InputDialog::handleCommand(CommandSender* sender, int cmd, |
| 545 | int data, int id) |
| 546 | { |
| 547 | switch(cmd) |
| 548 | { |
| 549 | case GuiObject::kOKCmd: |
| 550 | saveConfig(); |
| 551 | close(); |
| 552 | break; |
| 553 | |
| 554 | case GuiObject::kCloseCmd: |
| 555 | // Revert changes made to event mapping |
| 556 | close(); |
| 557 | break; |
| 558 | |
| 559 | case GuiObject::kDefaultsCmd: |
| 560 | setDefaults(); |
| 561 | break; |
| 562 | |
| 563 | case kDeadzoneChanged: |
| 564 | myDeadzoneLabel->setValue(3200 + 1000*myDeadzone->getValue()); |
| 565 | break; |
| 566 | |
| 567 | case kDPSpeedChanged: |
| 568 | myDPaddleLabel->setValue(myDPaddleSpeed->getValue()); |
| 569 | break; |
| 570 | |
| 571 | case kMPSpeedChanged: |
| 572 | myMPaddleLabel->setValue(myMPaddleSpeed->getValue()); |
| 573 | break; |
| 574 | |
| 575 | case kDejitterChanged: |
| 576 | UpdateDejitter(); |
| 577 | break; |
| 578 | |
| 579 | case kTBSpeedChanged: |
| 580 | myTrackBallLabel->setValue(myTrackBallSpeed->getValue()); |
| 581 | break; |
| 582 | |
| 583 | case kDBButtonPressed: |
| 584 | if(!myJoyDialog) |
| 585 | { |
| 586 | const GUI::Font& font = instance().frameBuffer().font(); |
| 587 | myJoyDialog = make_unique<JoystickDialog> |
| 588 | (this, font, font.getMaxCharWidth() * 56 + 20, font.getFontHeight() * 18 + 20); |
| 589 | } |
| 590 | myJoyDialog->show(); |
| 591 | break; |
| 592 | |
| 593 | case kEEButtonPressed: |
| 594 | if(!myConfirmMsg) |
| 595 | { |
| 596 | StringList msg; |
| 597 | msg.push_back("This operation cannot be undone." ); |
| 598 | msg.push_back("All data stored on your AtariVox" ); |
| 599 | msg.push_back("or SaveKey will be erased!" ); |
| 600 | msg.push_back("" ); |
| 601 | msg.push_back("If you are sure you want to erase" ); |
| 602 | msg.push_back("the data, click 'OK', otherwise " ); |
| 603 | msg.push_back("click 'Cancel'." ); |
| 604 | myConfirmMsg = make_unique<GUI::MessageBox> |
| 605 | (this, instance().frameBuffer().font(), msg, |
| 606 | myMaxWidth, myMaxHeight, kConfirmEEEraseCmd, |
| 607 | "OK" , "Cancel" , "Erase EEPROM" , false); |
| 608 | } |
| 609 | myConfirmMsg->show(); |
| 610 | break; |
| 611 | |
| 612 | case kConfirmEEEraseCmd: |
| 613 | eraseEEPROM(); |
| 614 | break; |
| 615 | |
| 616 | default: |
| 617 | Dialog::handleCommand(sender, cmd, data, 0); |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 622 | void InputDialog::UpdateDejitter() |
| 623 | { |
| 624 | int strength = myDejitterBase->getValue(); |
| 625 | stringstream label; |
| 626 | |
| 627 | if (strength) |
| 628 | label << myDejitterBase->getValue(); |
| 629 | else |
| 630 | label << "Off" ; |
| 631 | |
| 632 | label << " " ; |
| 633 | strength = myDejitterDiff->getValue(); |
| 634 | |
| 635 | if (strength) |
| 636 | label << myDejitterDiff->getValue(); |
| 637 | else |
| 638 | label << "Off" ; |
| 639 | |
| 640 | myDejitterLabel->setLabel(label.str()); |
| 641 | } |
| 642 | |
| 643 | |