~ubuntu-branches/debian/sid/stella/sid

« back to all changes in this revision

Viewing changes to src/debugger/gui/JoystickWidget.cxx

  • Committer: Package Import Robot
  • Author(s): Stephen Kitt
  • Date: 2012-02-05 08:09:05 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20120205080905-9ej05rmkibowsm7j
Tags: 3.5.5-1
* New upstream version.
* Rewrite debian/copyright, using DEP-5 and updating for 2012.
* Update manpage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-2012 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
// $Id: JoystickWidget.cxx 2352 2012-01-10 18:24:13Z stephena $
 
18
//============================================================================
 
19
 
 
20
#include "OSystem.hxx"
 
21
#include "EventHandler.hxx"
 
22
#include "JoystickWidget.hxx"
 
23
 
 
24
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
25
JoystickWidget::JoystickWidget(GuiObject* boss, const GUI::Font& font,
 
26
                               int x, int y, Controller& controller)
 
27
  : ControllerWidget(boss, font, x, y, controller)
 
28
{
 
29
  bool leftport = myController.jack() == Controller::Left;
 
30
  const string& label = leftport ? "Left (Joystick):" : "Right (Joystick):";
 
31
 
 
32
  const int fontHeight = font.getFontHeight();
 
33
  int xpos = x, ypos = y, lwidth = font.getStringWidth("Right (Joystick):");
 
34
  StaticTextWidget* t;
 
35
 
 
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);
 
42
 
 
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);
 
47
 
 
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);
 
53
 
 
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);
 
58
 
 
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);
 
64
}
 
65
 
 
66
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
67
JoystickWidget::~JoystickWidget()
 
68
{
 
69
}
 
70
 
 
71
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
72
void JoystickWidget::loadConfig()
 
73
{
 
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]));
 
79
}
 
80
 
 
81
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
82
void JoystickWidget::handleCommand(
 
83
    CommandSender* sender, int cmd, int data, int id)
 
84
{
 
85
  if(cmd == kCheckActionCmd)
 
86
    myController.set(ourPinNo[id], !myPins[id]->getState());
 
87
}
 
88
 
 
89
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
90
Controller::DigitalPin JoystickWidget::ourPinNo[5] = {
 
91
  Controller::One, Controller::Two, Controller::Three, Controller::Four,
 
92
  Controller::Six
 
93
};