| 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 "PointingDevice.hxx" | 
|---|
| 19 | #include "DataGridWidget.hxx" | 
|---|
| 20 | #include "PointingDeviceWidget.hxx" | 
|---|
| 21 |  | 
|---|
| 22 | PointingDeviceWidget::PointingDeviceWidget(GuiObject* boss, const GUI::Font& font, | 
|---|
| 23 | int x, int y, Controller& controller) | 
|---|
| 24 | : ControllerWidget(boss, font, x, y, controller) | 
|---|
| 25 | { | 
|---|
| 26 | int ypos = y; | 
|---|
| 27 | int xLeft = x + 10; | 
|---|
| 28 | int xMid = xLeft + 30; | 
|---|
| 29 | int xRight = xLeft + 60; | 
|---|
| 30 | int xValue = xLeft + 87; | 
|---|
| 31 | StaticTextWidget* t; | 
|---|
| 32 |  | 
|---|
| 33 | t = new StaticTextWidget(boss, font, x, y + 2, getHeader()); | 
|---|
| 34 | ypos += t->getHeight() + 8; | 
|---|
| 35 |  | 
|---|
| 36 | // add gray code and up widgets | 
|---|
| 37 | myGrayValueV = new DataGridWidget(boss, font, xMid, ypos, | 
|---|
| 38 | 1, 1, 2, 8, Common::Base::F_16); | 
|---|
| 39 | myGrayValueV->setTarget(this); | 
|---|
| 40 | myGrayValueV->setEditable(false); | 
|---|
| 41 |  | 
|---|
| 42 | ypos += myGrayValueV->getHeight() + 2; | 
|---|
| 43 |  | 
|---|
| 44 | myGrayUp = new ButtonWidget(boss, font, xMid, ypos, 17, "+", kTBUp); | 
|---|
| 45 | myGrayUp->setTarget(this); | 
|---|
| 46 |  | 
|---|
| 47 | ypos += myGrayUp->getHeight() + 5; | 
|---|
| 48 |  | 
|---|
| 49 | // add horizontal direction and gray code widgets | 
|---|
| 50 | myGrayLeft = new ButtonWidget(boss, font, xLeft, ypos, 17, "-", kTBLeft); | 
|---|
| 51 | myGrayLeft->setTarget(this); | 
|---|
| 52 |  | 
|---|
| 53 | myGrayRight = new ButtonWidget(boss, font, xRight, ypos, 17, "+", kTBRight); | 
|---|
| 54 | myGrayRight->setTarget(this); | 
|---|
| 55 |  | 
|---|
| 56 | myGrayValueH = new DataGridWidget(boss, font, xValue, ypos + 2, | 
|---|
| 57 | 1, 1, 2, 8, Common::Base::F_16); | 
|---|
| 58 | myGrayValueH->setTarget(this); | 
|---|
| 59 | myGrayValueH->setEditable(false); | 
|---|
| 60 |  | 
|---|
| 61 | ypos += myGrayLeft->getHeight() + 5; | 
|---|
| 62 |  | 
|---|
| 63 | // add down widget | 
|---|
| 64 | myGrayDown = new ButtonWidget(boss, font, xMid, ypos, 17, "-", kTBDown); | 
|---|
| 65 | myGrayDown->setTarget(this); | 
|---|
| 66 |  | 
|---|
| 67 | ypos += myGrayDown->getHeight() + 8; | 
|---|
| 68 |  | 
|---|
| 69 | myFire = new CheckboxWidget(boss, font, xLeft, ypos, "Fire", kTBFire); | 
|---|
| 70 | myFire->setTarget(this); | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|
| 73 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
|---|
| 74 | void PointingDeviceWidget::loadConfig() | 
|---|
| 75 | { | 
|---|
| 76 | setGrayCodeH(); | 
|---|
| 77 | setGrayCodeV(); | 
|---|
| 78 | myFire->setState(!getPin(Controller::DigitalPin::Six)); | 
|---|
| 79 | } | 
|---|
| 80 |  | 
|---|
| 81 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
|---|
| 82 | void PointingDeviceWidget::handleCommand(CommandSender* sender, int cmd, int data, int id) | 
|---|
| 83 | { | 
|---|
| 84 | // since the PointingDevice uses its own, internal state (not reading the controller), | 
|---|
| 85 | // we have to communicate directly with it | 
|---|
| 86 | PointingDevice& pDev = static_cast<PointingDevice&>(controller()); | 
|---|
| 87 |  | 
|---|
| 88 | switch(cmd) | 
|---|
| 89 | { | 
|---|
| 90 | case kTBLeft: | 
|---|
| 91 | ++pDev.myCountH; | 
|---|
| 92 | pDev.myTrackBallLeft = false; | 
|---|
| 93 | setGrayCodeH(); | 
|---|
| 94 | break; | 
|---|
| 95 | case kTBRight: | 
|---|
| 96 | --pDev.myCountH; | 
|---|
| 97 | pDev.myTrackBallLeft = true; | 
|---|
| 98 | setGrayCodeH(); | 
|---|
| 99 | break; | 
|---|
| 100 | case kTBUp: | 
|---|
| 101 | ++pDev.myCountV; | 
|---|
| 102 | pDev.myTrackBallDown = true; | 
|---|
| 103 | setGrayCodeV(); | 
|---|
| 104 | break; | 
|---|
| 105 | case kTBDown: | 
|---|
| 106 | --pDev.myCountV; | 
|---|
| 107 | pDev.myTrackBallDown = false; | 
|---|
| 108 | setGrayCodeV(); | 
|---|
| 109 | break; | 
|---|
| 110 | case kTBFire: | 
|---|
| 111 | setPin(Controller::DigitalPin::Six, !myFire->getState()); | 
|---|
| 112 | break; | 
|---|
| 113 | } | 
|---|
| 114 | } | 
|---|
| 115 |  | 
|---|
| 116 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
|---|
| 117 | void PointingDeviceWidget::setGrayCodeH() | 
|---|
| 118 | { | 
|---|
| 119 | PointingDevice& pDev = static_cast<PointingDevice&>(controller()); | 
|---|
| 120 |  | 
|---|
| 121 | pDev.myCountH &= 0b11; | 
|---|
| 122 | setValue(myGrayValueH, pDev.myCountH, pDev.myTrackBallLeft); | 
|---|
| 123 | } | 
|---|
| 124 |  | 
|---|
| 125 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
|---|
| 126 | void PointingDeviceWidget::setGrayCodeV() | 
|---|
| 127 | { | 
|---|
| 128 | PointingDevice& pDev = static_cast<PointingDevice&>(controller()); | 
|---|
| 129 |  | 
|---|
| 130 | pDev.myCountV &= 0b11; | 
|---|
| 131 | setValue(myGrayValueV, pDev.myCountV, !pDev.myTrackBallDown); | 
|---|
| 132 | } | 
|---|
| 133 |  | 
|---|
| 134 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 
|---|
| 135 | void PointingDeviceWidget::setValue(DataGridWidget* grayValue, const int index, const int direction) | 
|---|
| 136 | { | 
|---|
| 137 | uInt8 grayCode = getGrayCodeTable(index, direction); | 
|---|
| 138 |  | 
|---|
| 139 | // FIXME  * 8 = a nasty hack, because the DataGridWidget does not support 2 digit binary output | 
|---|
| 140 | grayValue->setList(0, (grayCode & 0b01) + (grayCode & 0b10) * 8); | 
|---|
| 141 | } | 
|---|
| 142 |  | 
|---|