| 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 "JoystickWidget.hxx" |
| 19 | |
| 20 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 21 | JoystickWidget::JoystickWidget(GuiObject* boss, const GUI::Font& font, |
| 22 | int x, int y, Controller& controller) |
| 23 | : ControllerWidget(boss, font, x, y, controller) |
| 24 | { |
| 25 | const string& label = getHeader(); |
| 26 | const int fontHeight = font.getFontHeight(); |
| 27 | int xpos = x, ypos = y, lwidth = font.getStringWidth("Right (Joystick)" ); |
| 28 | StaticTextWidget* t; |
| 29 | |
| 30 | t = new StaticTextWidget(boss, font, xpos, ypos+2, lwidth, |
| 31 | fontHeight, label, TextAlign::Left); |
| 32 | xpos += t->getWidth()/2 - 5; ypos += t->getHeight() + 20; |
| 33 | myPins[kJUp] = new CheckboxWidget(boss, font, xpos, ypos, "" , |
| 34 | CheckboxWidget::kCheckActionCmd); |
| 35 | myPins[kJUp]->setID(kJUp); |
| 36 | myPins[kJUp]->setTarget(this); |
| 37 | |
| 38 | ypos += myPins[kJUp]->getHeight() * 2 + 10; |
| 39 | myPins[kJDown] = new CheckboxWidget(boss, font, xpos, ypos, "" , |
| 40 | CheckboxWidget::kCheckActionCmd); |
| 41 | myPins[kJDown]->setID(kJDown); |
| 42 | myPins[kJDown]->setTarget(this); |
| 43 | |
| 44 | xpos -= myPins[kJUp]->getWidth() + 5; |
| 45 | ypos -= myPins[kJUp]->getHeight() + 5; |
| 46 | myPins[kJLeft] = new CheckboxWidget(boss, font, xpos, ypos, "" , |
| 47 | CheckboxWidget::kCheckActionCmd); |
| 48 | myPins[kJLeft]->setID(kJLeft); |
| 49 | myPins[kJLeft]->setTarget(this); |
| 50 | |
| 51 | xpos += (myPins[kJUp]->getWidth() + 5) * 2; |
| 52 | myPins[kJRight] = new CheckboxWidget(boss, font, xpos, ypos, "" , |
| 53 | CheckboxWidget::kCheckActionCmd); |
| 54 | myPins[kJRight]->setID(kJRight); |
| 55 | myPins[kJRight]->setTarget(this); |
| 56 | |
| 57 | xpos -= (myPins[kJUp]->getWidth() + 5) * 2; |
| 58 | ypos = 30 + (myPins[kJUp]->getHeight() + 10) * 3; |
| 59 | myPins[kJFire] = new CheckboxWidget(boss, font, xpos, ypos, "Fire" , |
| 60 | CheckboxWidget::kCheckActionCmd); |
| 61 | myPins[kJFire]->setID(kJFire); |
| 62 | myPins[kJFire]->setTarget(this); |
| 63 | } |
| 64 | |
| 65 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 66 | void JoystickWidget::loadConfig() |
| 67 | { |
| 68 | myPins[kJUp]->setState(!getPin(ourPinNo[kJUp])); |
| 69 | myPins[kJDown]->setState(!getPin(ourPinNo[kJDown])); |
| 70 | myPins[kJLeft]->setState(!getPin(ourPinNo[kJLeft])); |
| 71 | myPins[kJRight]->setState(!getPin(ourPinNo[kJRight])); |
| 72 | myPins[kJFire]->setState(!getPin(ourPinNo[kJFire])); |
| 73 | } |
| 74 | |
| 75 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 76 | void JoystickWidget::handleCommand( |
| 77 | CommandSender* sender, int cmd, int data, int id) |
| 78 | { |
| 79 | if(cmd == CheckboxWidget::kCheckActionCmd) |
| 80 | setPin(ourPinNo[id], !myPins[id]->getState()); |
| 81 | } |
| 82 | |
| 83 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 84 | Controller::DigitalPin JoystickWidget::ourPinNo[5] = { |
| 85 | Controller::DigitalPin::One, Controller::DigitalPin::Two, Controller::DigitalPin::Three, Controller::DigitalPin::Four, |
| 86 | Controller::DigitalPin::Six |
| 87 | }; |
| 88 | |