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: MouseControl.cxx 2376 2012-01-29 22:33:24Z stephena $
18
//============================================================================
20
#include "Console.hxx"
21
#include "Control.hxx"
24
#include "MouseControl.hxx"
26
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
27
MouseControl::MouseControl(Console& console, const string& mode)
28
: myProps(console.properties()),
29
myLeftController(console.controller(Controller::Left)),
30
myRightController(console.controller(Controller::Right)),
33
if(BSPF_equalsIgnoreCase(mode, "never"))
35
myModeList.push_back(MouseMode("Mouse input is disabled"));
38
else if(!BSPF_equalsIgnoreCase(mode, "auto") && mode.length() == 2 &&
39
mode[0] >= '0' && mode[0] <= '5' &&
40
mode[1] >= '0' && mode[1] <= '5')
42
Axis xaxis = (Axis) ((int)mode[0] - '0');
43
Axis yaxis = (Axis) ((int)mode[1] - '0');
45
msg << "Mouse X-axis is ";
49
msg << "Paddle 0"; break;
51
msg << "Paddle 1"; break;
53
msg << "Paddle 2"; break;
55
msg << "Paddle 3"; break;
57
msg << "Driving 0"; break;
59
msg << "Driving 1"; break;
62
msg << ", Y-axis is ";
66
msg << "Paddle 0"; break;
68
msg << "Paddle 1"; break;
70
msg << "Paddle 2"; break;
72
msg << "Paddle 3"; break;
74
msg << "Driving 0"; break;
76
msg << "Driving 1"; break;
79
myModeList.push_back(MouseMode(xaxis, yaxis, -1, msg.str()));
82
// Now consider the possible modes for the mouse based on the left
83
// and right controllers
84
bool noswap = BSPF_equalsIgnoreCase(myProps.get(Console_SwapPorts), "NO");
87
addLeftControllerModes(noswap);
88
addRightControllerModes(noswap);
92
addRightControllerModes(noswap);
93
addLeftControllerModes(noswap);
96
// If the mouse isn't used at all, we still need one item in the list
97
if(myModeList.size() == 0)
98
myModeList.push_back(MouseMode("Mouse not used for current controllers"));
101
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
102
MouseControl::~MouseControl()
106
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
107
const string& MouseControl::next()
109
const MouseMode& mode = myModeList[myCurrentModeNum];
110
myCurrentModeNum = (myCurrentModeNum + 1) % myModeList.size();
112
myLeftController.setMouseControl(mode.xaxis, mode.yaxis, mode.controlID);
113
myRightController.setMouseControl(mode.xaxis, mode.yaxis, mode.controlID);
118
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
119
void MouseControl::addLeftControllerModes(bool noswap)
121
switch(myLeftController.type())
123
case Controller::Joystick:
124
case Controller::BoosterGrip:
125
case Controller::Genesis:
126
case Controller::Driving:
127
case Controller::TrackBall22:
128
case Controller::TrackBall80:
129
case Controller::AmigaMouse:
130
// case Controller::Mindlink:
133
msg << "Mouse is left " << myLeftController.name() << " controller";
134
myModeList.push_back(MouseMode(Automatic, Automatic, noswap ? 0 : 1, msg.str()));
137
case Controller::Paddles:
138
if(noswap) addPaddleModes(0, 1, 0, 1);
139
else addPaddleModes(2, 3, 0, 1);
146
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
147
void MouseControl::addRightControllerModes(bool noswap)
149
switch(myRightController.type())
151
case Controller::Joystick:
152
case Controller::BoosterGrip:
153
case Controller::Genesis:
154
case Controller::Driving:
155
case Controller::TrackBall22:
156
case Controller::TrackBall80:
157
case Controller::AmigaMouse:
158
// case Controller::Mindlink:
161
msg << "Mouse is right " << myRightController.name() << " controller";
162
myModeList.push_back(MouseMode(Automatic, Automatic, noswap ? 1 : 0, msg.str()));
165
case Controller::Paddles:
166
if(noswap) addPaddleModes(2, 3, 2, 3);
167
else addPaddleModes(0, 1, 2, 3);
174
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
175
void MouseControl::addPaddleModes(int lport, int rport, int lname, int rname)
178
msg << "Mouse is Paddle " << lname << " controller";
179
MouseMode mode0(Automatic, Automatic, lport, msg.str());
182
msg << "Mouse is Paddle " << rname << " controller";
183
MouseMode mode1(Automatic, Automatic, rport, msg.str());
185
if(BSPF_equalsIgnoreCase(myProps.get(Controller_SwapPaddles), "NO"))
187
myModeList.push_back(mode0);
188
myModeList.push_back(mode1);
192
myModeList.push_back(mode1);
193
myModeList.push_back(mode0);