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

« back to all changes in this revision

Viewing changes to src/debugger/gui/DrivingWidget.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: DrivingWidget.cxx 2352 2012-01-10 18:24:13Z stephena $
 
18
//============================================================================
 
19
 
 
20
#include "DataGridWidget.hxx"
 
21
#include "DrivingWidget.hxx"
 
22
 
 
23
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
24
DrivingWidget::DrivingWidget(GuiObject* boss, const GUI::Font& font,
 
25
                             int x, int y, Controller& controller)
 
26
  : ControllerWidget(boss, font, x, y, controller),
 
27
    myGreyIndex(0)
 
28
{
 
29
  bool leftport = myController.jack() == Controller::Left;
 
30
  const string& label = leftport ? "Left (Driving):" : "Right (Driving):";
 
31
 
 
32
  const int fontHeight = font.getFontHeight(),
 
33
            bwidth = font.getStringWidth("Grey code +") + 10,
 
34
            bheight = font.getLineHeight() + 4;
 
35
  int xpos = x, ypos = y, lwidth = font.getStringWidth("Right (Driving):");
 
36
  StaticTextWidget* t;
 
37
 
 
38
  t = new StaticTextWidget(boss, font, xpos, ypos+2, lwidth,
 
39
                           fontHeight, label, kTextAlignLeft);
 
40
 
 
41
  ypos += t->getHeight() + 20;
 
42
  myGreyUp = new ButtonWidget(boss, font, xpos, ypos, bwidth, bheight,
 
43
                              "Grey code +", kGreyUpCmd);
 
44
  myGreyUp->setTarget(this);
 
45
 
 
46
  ypos += myGreyUp->getHeight() + 5;
 
47
  myGreyDown = new ButtonWidget(boss, font, xpos, ypos, bwidth, bheight,
 
48
                                "Grey code -", kGreyDownCmd);
 
49
  myGreyDown->setTarget(this);
 
50
 
 
51
  xpos += myGreyDown->getWidth() + 10;  ypos -= 10;
 
52
  myGreyValue = new DataGridWidget(boss, font, xpos, ypos,
 
53
                                   1, 1, 2, 8, kBASE_16);
 
54
  myGreyValue->setTarget(this);
 
55
  myGreyValue->setEditable(false);
 
56
 
 
57
  xpos = x + 30;  ypos += myGreyDown->getHeight() + 20;
 
58
  myFire = new CheckboxWidget(boss, font, xpos, ypos, "Fire", kFireCmd);
 
59
  myFire->setTarget(this);
 
60
}
 
61
 
 
62
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
63
DrivingWidget::~DrivingWidget()
 
64
{
 
65
}
 
66
 
 
67
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
68
void DrivingWidget::loadConfig()
 
69
{
 
70
  uInt8 grey = 0;
 
71
  if(myController.read(Controller::One)) grey += 1;
 
72
  if(myController.read(Controller::Two)) grey += 2;
 
73
 
 
74
  for(myGreyIndex = 0; myGreyIndex < 4; ++myGreyIndex)
 
75
    if(ourGreyTable[myGreyIndex] == grey)
 
76
      break;
 
77
 
 
78
  myFire->setState(!myController.read(Controller::Six));
 
79
  myGreyValue->setList(0, grey);
 
80
}
 
81
 
 
82
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
83
void DrivingWidget::handleCommand(
 
84
    CommandSender* sender, int cmd, int data, int id)
 
85
{
 
86
  switch(cmd)
 
87
  {
 
88
    case kGreyUpCmd:
 
89
      myGreyIndex = (myGreyIndex + 1) % 4;
 
90
      myController.set(Controller::One, (ourGreyTable[myGreyIndex] & 0x1) != 0);
 
91
      myController.set(Controller::Two, (ourGreyTable[myGreyIndex] & 0x2) != 0);
 
92
      myGreyValue->setList(0, ourGreyTable[myGreyIndex]);
 
93
      break;
 
94
    case kGreyDownCmd:
 
95
      myGreyIndex = myGreyIndex == 0 ? 3 : myGreyIndex - 1;
 
96
      myController.set(Controller::One, (ourGreyTable[myGreyIndex] & 0x1) != 0);
 
97
      myController.set(Controller::Two, (ourGreyTable[myGreyIndex] & 0x2) != 0);
 
98
      myGreyValue->setList(0, ourGreyTable[myGreyIndex]);
 
99
      break;
 
100
    case kFireCmd:
 
101
      myController.set(Controller::Six, !myFire->getState());
 
102
      break;
 
103
  }
 
104
}
 
105
 
 
106
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
107
uInt8 DrivingWidget::ourGreyTable[4] = { 0x03, 0x01, 0x00, 0x02 };
 
 
b'\\ No newline at end of file'