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 "Paddles.hxx" |
19 | #include "PaddleWidget.hxx" |
20 | |
21 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
22 | PaddleWidget::PaddleWidget(GuiObject* boss, const GUI::Font& font, |
23 | int x, int y, Controller& controller) |
24 | : ControllerWidget(boss, font, x, y, controller) |
25 | { |
26 | bool leftport = isLeftPort(); |
27 | const string& label = getHeader(); |
28 | |
29 | const int fontHeight = font.getFontHeight(), |
30 | lineHeight = font.getLineHeight(); |
31 | int xpos = x, ypos = y, lwidth = font.getStringWidth("Right (Paddles)" ); |
32 | |
33 | new StaticTextWidget(boss, font, xpos, ypos+2, lwidth, |
34 | fontHeight, label); |
35 | |
36 | ypos += lineHeight + 20; |
37 | const string& p0string = leftport ? "P0 pot " : "P2 pot " ; |
38 | const string& p1string = leftport ? "P1 pot " : "P3 pot " ; |
39 | myP0Resistance = |
40 | new SliderWidget(boss, font, xpos, ypos, |
41 | p0string, 0, kP0Changed); |
42 | myP0Resistance->setMinValue(0); |
43 | myP0Resistance->setMaxValue(uInt32(Paddles::MAX_RESISTANCE)); |
44 | myP0Resistance->setStepValue(uInt32(Paddles::MAX_RESISTANCE/100)); |
45 | myP0Resistance->setTarget(this); |
46 | |
47 | xpos += 20; ypos += myP0Resistance->getHeight() + 4; |
48 | myP0Fire = new CheckboxWidget(boss, font, xpos, ypos, |
49 | "Fire" , kP0Fire); |
50 | myP0Fire->setTarget(this); |
51 | |
52 | xpos = x; ypos += 2*lineHeight; |
53 | myP1Resistance = |
54 | new SliderWidget(boss, font, xpos, ypos, |
55 | p1string, 0, kP1Changed); |
56 | myP1Resistance->setMinValue(0); |
57 | myP1Resistance->setMaxValue(uInt32(Paddles::MAX_RESISTANCE)); |
58 | myP1Resistance->setStepValue(uInt32(Paddles::MAX_RESISTANCE/100)); |
59 | myP1Resistance->setTarget(this); |
60 | |
61 | xpos += 20; ypos += myP1Resistance->getHeight() + 4; |
62 | myP1Fire = new CheckboxWidget(boss, font, xpos, ypos, |
63 | "Fire" , kP1Fire); |
64 | myP1Fire->setTarget(this); |
65 | } |
66 | |
67 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
68 | void PaddleWidget::loadConfig() |
69 | { |
70 | myP0Resistance->setValue(Int32(Paddles::MAX_RESISTANCE - |
71 | getPin(Controller::AnalogPin::Nine))); |
72 | myP1Resistance->setValue(Int32(Paddles::MAX_RESISTANCE - |
73 | getPin(Controller::AnalogPin::Five))); |
74 | myP0Fire->setState(!getPin(Controller::DigitalPin::Four)); |
75 | myP1Fire->setState(!getPin(Controller::DigitalPin::Three)); |
76 | } |
77 | |
78 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
79 | void PaddleWidget::handleCommand( |
80 | CommandSender* sender, int cmd, int data, int id) |
81 | { |
82 | switch(cmd) |
83 | { |
84 | case kP0Changed: |
85 | setPin(Controller::AnalogPin::Nine, |
86 | Int32(Paddles::MAX_RESISTANCE - myP0Resistance->getValue())); |
87 | break; |
88 | case kP1Changed: |
89 | setPin(Controller::AnalogPin::Five, |
90 | Int32(Paddles::MAX_RESISTANCE - myP1Resistance->getValue())); |
91 | break; |
92 | case kP0Fire: |
93 | setPin(Controller::DigitalPin::Four, !myP0Fire->getState()); |
94 | break; |
95 | case kP1Fire: |
96 | setPin(Controller::DigitalPin::Three, !myP1Fire->getState()); |
97 | break; |
98 | } |
99 | } |
100 | |