1
//============================================================================
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
11
// Copyright (c) 1995-2012 by Bradford W. Mott, Stephen Anthony
12
// and the Stella Team
14
// See the file "License.txt" for information on usage and redistribution of
15
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
17
// $Id: JoystickWidget.cxx 2352 2012-01-10 18:24:13Z stephena $
18
//============================================================================
20
#include "OSystem.hxx"
21
#include "EventHandler.hxx"
22
#include "JoystickWidget.hxx"
24
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
25
JoystickWidget::JoystickWidget(GuiObject* boss, const GUI::Font& font,
26
int x, int y, Controller& controller)
27
: ControllerWidget(boss, font, x, y, controller)
29
bool leftport = myController.jack() == Controller::Left;
30
const string& label = leftport ? "Left (Joystick):" : "Right (Joystick):";
32
const int fontHeight = font.getFontHeight();
33
int xpos = x, ypos = y, lwidth = font.getStringWidth("Right (Joystick):");
36
t = new StaticTextWidget(boss, font, xpos, ypos+2, lwidth,
37
fontHeight, label, kTextAlignLeft);
38
xpos += t->getWidth()/2 - 5; ypos += t->getHeight() + 20;
39
myPins[kJUp] = new CheckboxWidget(boss, font, xpos, ypos, "", kCheckActionCmd);
40
myPins[kJUp]->setID(kJUp);
41
myPins[kJUp]->setTarget(this);
43
ypos += myPins[kJUp]->getHeight() * 2 + 10;
44
myPins[kJDown] = new CheckboxWidget(boss, font, xpos, ypos, "", kCheckActionCmd);
45
myPins[kJDown]->setID(kJDown);
46
myPins[kJDown]->setTarget(this);
48
xpos -= myPins[kJUp]->getWidth() + 5;
49
ypos -= myPins[kJUp]->getHeight() + 5;
50
myPins[kJLeft] = new CheckboxWidget(boss, font, xpos, ypos, "", kCheckActionCmd);
51
myPins[kJLeft]->setID(kJLeft);
52
myPins[kJLeft]->setTarget(this);
54
xpos += (myPins[kJUp]->getWidth() + 5) * 2;
55
myPins[kJRight] = new CheckboxWidget(boss, font, xpos, ypos, "", kCheckActionCmd);
56
myPins[kJRight]->setID(kJRight);
57
myPins[kJRight]->setTarget(this);
59
xpos -= (myPins[kJUp]->getWidth() + 5) * 2;
60
ypos = 30 + (myPins[kJUp]->getHeight() + 10) * 3;
61
myPins[kJFire] = new CheckboxWidget(boss, font, xpos, ypos, "Fire", kCheckActionCmd);
62
myPins[kJFire]->setID(kJFire);
63
myPins[kJFire]->setTarget(this);
66
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
67
JoystickWidget::~JoystickWidget()
71
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
72
void JoystickWidget::loadConfig()
74
myPins[kJUp]->setState(!myController.read(ourPinNo[kJUp]));
75
myPins[kJDown]->setState(!myController.read(ourPinNo[kJDown]));
76
myPins[kJLeft]->setState(!myController.read(ourPinNo[kJLeft]));
77
myPins[kJRight]->setState(!myController.read(ourPinNo[kJRight]));
78
myPins[kJFire]->setState(!myController.read(ourPinNo[kJFire]));
81
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
82
void JoystickWidget::handleCommand(
83
CommandSender* sender, int cmd, int data, int id)
85
if(cmd == kCheckActionCmd)
86
myController.set(ourPinNo[id], !myPins[id]->getState());
89
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
90
Controller::DigitalPin JoystickWidget::ourPinNo[5] = {
91
Controller::One, Controller::Two, Controller::Three, Controller::Four,