| 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 "GenesisWidget.hxx" | 
|---|
| 19 |  | 
|---|
| 20 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
|---|
| 21 | GenesisWidget::GenesisWidget(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 |  | 
|---|
| 27 | const int fontHeight = font.getFontHeight(); | 
|---|
| 28 | int xpos = x, ypos = y, lwidth = font.getStringWidth( "Right (Genesis)"); | 
|---|
| 29 | StaticTextWidget* t; | 
|---|
| 30 |  | 
|---|
| 31 | t = new StaticTextWidget(boss, font, xpos, ypos+2, lwidth, | 
|---|
| 32 | fontHeight, label, TextAlign::Left); | 
|---|
| 33 | xpos += t->getWidth()/2 - 5;  ypos += t->getHeight() + 20; | 
|---|
| 34 | myPins[kJUp] = new CheckboxWidget(boss, font, xpos, ypos, "", | 
|---|
| 35 | CheckboxWidget::kCheckActionCmd); | 
|---|
| 36 | myPins[kJUp]->setID(kJUp); | 
|---|
| 37 | myPins[kJUp]->setTarget(this); | 
|---|
| 38 |  | 
|---|
| 39 | ypos += myPins[kJUp]->getHeight() * 2 + 10; | 
|---|
| 40 | myPins[kJDown] = new CheckboxWidget(boss, font, xpos, ypos, "", | 
|---|
| 41 | CheckboxWidget::kCheckActionCmd); | 
|---|
| 42 | myPins[kJDown]->setID(kJDown); | 
|---|
| 43 | myPins[kJDown]->setTarget(this); | 
|---|
| 44 |  | 
|---|
| 45 | xpos -= myPins[kJUp]->getWidth() + 5; | 
|---|
| 46 | ypos -= myPins[kJUp]->getHeight() + 5; | 
|---|
| 47 | myPins[kJLeft] = new CheckboxWidget(boss, font, xpos, ypos, "", | 
|---|
| 48 | CheckboxWidget::kCheckActionCmd); | 
|---|
| 49 | myPins[kJLeft]->setID(kJLeft); | 
|---|
| 50 | myPins[kJLeft]->setTarget(this); | 
|---|
| 51 |  | 
|---|
| 52 | xpos += (myPins[kJUp]->getWidth() + 5) * 2; | 
|---|
| 53 | myPins[kJRight] = new CheckboxWidget(boss, font, xpos, ypos, "", | 
|---|
| 54 | CheckboxWidget::kCheckActionCmd); | 
|---|
| 55 | myPins[kJRight]->setID(kJRight); | 
|---|
| 56 | myPins[kJRight]->setTarget(this); | 
|---|
| 57 |  | 
|---|
| 58 | xpos -= (myPins[kJUp]->getWidth() + 5) * 2; | 
|---|
| 59 | ypos = 30 + (myPins[kJUp]->getHeight() + 10) * 3; | 
|---|
| 60 | myPins[kJBbtn] = new CheckboxWidget(boss, font, xpos, ypos, "B button", | 
|---|
| 61 | CheckboxWidget::kCheckActionCmd); | 
|---|
| 62 | myPins[kJBbtn]->setID(kJBbtn); | 
|---|
| 63 | myPins[kJBbtn]->setTarget(this); | 
|---|
| 64 |  | 
|---|
| 65 | ypos += myPins[kJBbtn]->getHeight() + 5; | 
|---|
| 66 | myPins[kJCbtn] = new CheckboxWidget(boss, font, xpos, ypos, "C button", | 
|---|
| 67 | CheckboxWidget::kCheckActionCmd); | 
|---|
| 68 | myPins[kJCbtn]->setID(kJCbtn); | 
|---|
| 69 | myPins[kJCbtn]->setTarget(this); | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
|---|
| 73 | void GenesisWidget::loadConfig() | 
|---|
| 74 | { | 
|---|
| 75 | myPins[kJUp]->setState(!getPin(ourPinNo[kJUp])); | 
|---|
| 76 | myPins[kJDown]->setState(!getPin(ourPinNo[kJDown])); | 
|---|
| 77 | myPins[kJLeft]->setState(!getPin(ourPinNo[kJLeft])); | 
|---|
| 78 | myPins[kJRight]->setState(!getPin(ourPinNo[kJRight])); | 
|---|
| 79 | myPins[kJBbtn]->setState(!getPin(ourPinNo[kJBbtn])); | 
|---|
| 80 |  | 
|---|
| 81 | myPins[kJCbtn]->setState( | 
|---|
| 82 | getPin(Controller::AnalogPin::Five) == Controller::MAX_RESISTANCE); | 
|---|
| 83 | } | 
|---|
| 84 |  | 
|---|
| 85 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
|---|
| 86 | void GenesisWidget::handleCommand( | 
|---|
| 87 | CommandSender* sender, int cmd, int data, int id) | 
|---|
| 88 | { | 
|---|
| 89 | if(cmd == CheckboxWidget::kCheckActionCmd) | 
|---|
| 90 | { | 
|---|
| 91 | switch(id) | 
|---|
| 92 | { | 
|---|
| 93 | case kJUp: | 
|---|
| 94 | case kJDown: | 
|---|
| 95 | case kJLeft: | 
|---|
| 96 | case kJRight: | 
|---|
| 97 | case kJBbtn: | 
|---|
| 98 | setPin(ourPinNo[id], !myPins[id]->getState()); | 
|---|
| 99 | break; | 
|---|
| 100 | case kJCbtn: | 
|---|
| 101 | setPin(Controller::AnalogPin::Five, | 
|---|
| 102 | myPins[id]->getState() ? Controller::MAX_RESISTANCE : | 
|---|
| 103 | Controller::MIN_RESISTANCE); | 
|---|
| 104 | break; | 
|---|
| 105 | } | 
|---|
| 106 | } | 
|---|
| 107 | } | 
|---|
| 108 |  | 
|---|
| 109 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
|---|
| 110 | Controller::DigitalPin GenesisWidget::ourPinNo[5] = { | 
|---|
| 111 | Controller::DigitalPin::One, Controller::DigitalPin::Two, Controller::DigitalPin::Three, Controller::DigitalPin::Four, | 
|---|
| 112 | Controller::DigitalPin::Six | 
|---|
| 113 | }; | 
|---|
| 114 |  | 
|---|