mirror of https://github.com/stella-emu/stella.git
MouseControl class now properly switches between various controller modes,
and take 'swapport' and 'swappaddles' settings into account. Next TODO is add per-ROM settings for specific axis mode. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2371 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
7247029e70
commit
1ef29f585e
|
@ -30,17 +30,94 @@ MouseControl::MouseControl(Console& console, const string& mode)
|
||||||
myRightController(console.controller(Controller::Right)),
|
myRightController(console.controller(Controller::Right)),
|
||||||
myCurrentModeNum(0)
|
myCurrentModeNum(0)
|
||||||
{
|
{
|
||||||
cerr << "MouseControl c'tor: using mode = " << mode << endl;
|
if(BSPF_equalsIgnoreCase(mode, "never"))
|
||||||
|
|
||||||
if(mode == "never")
|
|
||||||
{
|
{
|
||||||
MouseMode mmode;
|
myModeList.push_back(MouseMode("Mouse input is disabled"));
|
||||||
myModeList.push_back(mmode);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if(!BSPF_equalsIgnoreCase(mode, "auto") && mode.length() == 2 &&
|
||||||
|
mode[0] >= '0' && mode[0] <= '5' &&
|
||||||
|
mode[1] >= '0' && mode[1] <= '5')
|
||||||
|
{
|
||||||
|
Axis xaxis = (Axis) ((int)mode[0] - '0');
|
||||||
|
Axis yaxis = (Axis) ((int)mode[1] - '0');
|
||||||
|
ostringstream msg;
|
||||||
|
msg << "Mouse X-axis is ";
|
||||||
|
switch(xaxis)
|
||||||
|
{
|
||||||
|
case Paddle0:
|
||||||
|
msg << "Paddle 0"; break;
|
||||||
|
case Paddle1:
|
||||||
|
msg << "Paddle 1"; break;
|
||||||
|
case Paddle2:
|
||||||
|
msg << "Paddle 2"; break;
|
||||||
|
case Paddle3:
|
||||||
|
msg << "Paddle 3"; break;
|
||||||
|
case Driving0:
|
||||||
|
msg << "Driving 0"; break;
|
||||||
|
case Driving1:
|
||||||
|
msg << "Driving 1"; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
msg << ", Y-axis is ";
|
||||||
|
switch(yaxis)
|
||||||
|
{
|
||||||
|
case Paddle0:
|
||||||
|
msg << "Paddle 0"; break;
|
||||||
|
case Paddle1:
|
||||||
|
msg << "Paddle 1"; break;
|
||||||
|
case Paddle2:
|
||||||
|
msg << "Paddle 2"; break;
|
||||||
|
case Paddle3:
|
||||||
|
msg << "Paddle 3"; break;
|
||||||
|
case Driving0:
|
||||||
|
msg << "Driving 0"; break;
|
||||||
|
case Driving1:
|
||||||
|
msg << "Driving 1"; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
myModeList.push_back(MouseMode(xaxis, yaxis, -1, msg.str()));
|
||||||
|
}
|
||||||
|
|
||||||
// First consider the possible modes for the mouse based on the left
|
// Now consider the possible modes for the mouse based on the left
|
||||||
// and right controllers
|
// and right controllers
|
||||||
|
bool noswap = BSPF_equalsIgnoreCase(myProps.get(Console_SwapPorts), "NO");
|
||||||
|
if(noswap)
|
||||||
|
{
|
||||||
|
addLeftControllerModes(noswap);
|
||||||
|
addRightControllerModes(noswap);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
addRightControllerModes(noswap);
|
||||||
|
addLeftControllerModes(noswap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the mouse isn't used at all, we still need one item in the list
|
||||||
|
if(myModeList.size() == 0)
|
||||||
|
myModeList.push_back(MouseMode("Mouse not used for current controllers"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
MouseControl::~MouseControl()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
const string& MouseControl::next()
|
||||||
|
{
|
||||||
|
const MouseMode& mode = myModeList[myCurrentModeNum];
|
||||||
|
myCurrentModeNum = (myCurrentModeNum + 1) % myModeList.size();
|
||||||
|
|
||||||
|
myLeftController.setMouseControl(mode.xaxis, mode.yaxis, mode.controlID);
|
||||||
|
myRightController.setMouseControl(mode.xaxis, mode.yaxis, mode.controlID);
|
||||||
|
|
||||||
|
return mode.message;
|
||||||
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
void MouseControl::addLeftControllerModes(bool noswap)
|
||||||
|
{
|
||||||
switch(myLeftController.type())
|
switch(myLeftController.type())
|
||||||
{
|
{
|
||||||
case Controller::Joystick:
|
case Controller::Joystick:
|
||||||
|
@ -54,21 +131,21 @@ cerr << "MouseControl c'tor: using mode = " << mode << endl;
|
||||||
{
|
{
|
||||||
ostringstream msg;
|
ostringstream msg;
|
||||||
msg << "Mouse is left " << myLeftController.name() << " controller";
|
msg << "Mouse is left " << myLeftController.name() << " controller";
|
||||||
MouseMode mmode(Automatic, Automatic, 0, msg.str());
|
myModeList.push_back(MouseMode(Automatic, Automatic, noswap ? 0 : 1, msg.str()));
|
||||||
myModeList.push_back(mmode);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Controller::Paddles:
|
case Controller::Paddles:
|
||||||
{
|
if(noswap) addPaddleModes(0, 1, 0, 1);
|
||||||
MouseMode mmode0(Automatic, Automatic, 0, "Mouse is Paddle 0 controller");
|
else addPaddleModes(2, 3, 0, 1);
|
||||||
MouseMode mmode1(Automatic, Automatic, 1, "Mouse is Paddle 1 controller");
|
|
||||||
myModeList.push_back(mmode0);
|
|
||||||
myModeList.push_back(mmode1);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
void MouseControl::addRightControllerModes(bool noswap)
|
||||||
|
{
|
||||||
switch(myRightController.type())
|
switch(myRightController.type())
|
||||||
{
|
{
|
||||||
case Controller::Joystick:
|
case Controller::Joystick:
|
||||||
|
@ -82,91 +159,37 @@ cerr << "MouseControl c'tor: using mode = " << mode << endl;
|
||||||
{
|
{
|
||||||
ostringstream msg;
|
ostringstream msg;
|
||||||
msg << "Mouse is right " << myRightController.name() << " controller";
|
msg << "Mouse is right " << myRightController.name() << " controller";
|
||||||
MouseMode mmode(Automatic, Automatic, 1, msg.str());
|
myModeList.push_back(MouseMode(Automatic, Automatic, noswap ? 1 : 0, msg.str()));
|
||||||
myModeList.push_back(mmode);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Controller::Paddles:
|
case Controller::Paddles:
|
||||||
{
|
if(noswap) addPaddleModes(2, 3, 2, 3);
|
||||||
MouseMode mmode0(Automatic, Automatic, 2, "Mouse is Paddle 2 controller");
|
else addPaddleModes(0, 1, 2, 3);
|
||||||
MouseMode mmode1(Automatic, Automatic, 3, "Mouse is Paddle 3 controller");
|
|
||||||
myModeList.push_back(mmode0);
|
|
||||||
myModeList.push_back(mmode1);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now add per-ROM setting (if one exists)
|
|
||||||
if(mode != "auto")
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
// Note: these constants are from Controller::MouseAxisType enum
|
|
||||||
if(s.length() != 2 || s[0] < '0' || s[0] > '7' || s[1] < '0' || s[1] > '7')
|
|
||||||
setInternal("mcontrol", "auto");
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
MouseControl::~MouseControl()
|
void MouseControl::addPaddleModes(int lport, int rport, int lname, int rname)
|
||||||
{
|
{
|
||||||
}
|
ostringstream msg;
|
||||||
|
msg << "Mouse is Paddle " << lname << " controller" << "(" << lport << ")";
|
||||||
|
MouseMode mode0(Automatic, Automatic, lport, msg.str());
|
||||||
|
|
||||||
#if 0
|
msg.str("");
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
msg << "Mouse is Paddle " << rname << " controller" << "(" << rport << ")";
|
||||||
void MouseControl::setMode(const string& mode)
|
MouseMode mode1(Automatic, Automatic, rport, msg.str());
|
||||||
{
|
|
||||||
cerr << "MouseControl::setMode: " << mode << endl;
|
|
||||||
|
|
||||||
|
if(BSPF_equalsIgnoreCase(myProps.get(Controller_SwapPaddles), "NO"))
|
||||||
if(!&myOSystem->console())
|
|
||||||
return;
|
|
||||||
|
|
||||||
Controller& lc = myOSystem->console().controller(Controller::Left);
|
|
||||||
Controller& rc = myOSystem->console().controller(Controller::Right);
|
|
||||||
if(mode == "auto")
|
|
||||||
{
|
{
|
||||||
bool swap = myOSystem->console().properties().get(Controller_SwapPaddles) == "YES";
|
myModeList.push_back(mode0);
|
||||||
lc.setMouseControl(Controller::Automatic, Controller::Automatic, swap ? 1 : 0);
|
myModeList.push_back(mode1);
|
||||||
rc.setMouseControl(Controller::Automatic, Controller::Automatic, swap ? 1 : 0);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Controller::MouseAxisControl xaxis = (Controller::MouseAxisControl)
|
myModeList.push_back(mode1);
|
||||||
((int)mode[0] - '0');
|
myModeList.push_back(mode0);
|
||||||
Controller::MouseAxisControl yaxis = (Controller::MouseAxisControl)
|
|
||||||
((int)mode[1] - '0');
|
|
||||||
|
|
||||||
lc.setMouseControl(xaxis, yaxis);
|
|
||||||
rc.setMouseControl(xaxis, yaxis);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
||||||
const string& MouseControl::next()
|
|
||||||
{
|
|
||||||
const MouseMode& mode = myModeList[myCurrentModeNum];
|
|
||||||
myCurrentModeNum = (myCurrentModeNum + 1) % myModeList.size();
|
|
||||||
|
|
||||||
return mode.message;
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
if(myOSystem->settings().getString("mcontrol") == "auto")
|
|
||||||
{
|
|
||||||
myOSystem->console().controller(Controller::Left).setMouseControl(
|
|
||||||
Controller::Automatic, Controller::Automatic, paddle);
|
|
||||||
myOSystem->console().controller(Controller::Right).setMouseControl(
|
|
||||||
Controller::Automatic, Controller::Automatic, paddle);
|
|
||||||
|
|
||||||
myOSystem->frameBuffer().showMessage(message);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
myOSystem->frameBuffer().showMessage(
|
|
||||||
"Mouse axis mode not auto, paddle not changed");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
|
@ -72,6 +72,11 @@ class MouseControl
|
||||||
*/
|
*/
|
||||||
const string& next();
|
const string& next();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void addLeftControllerModes(bool noswap);
|
||||||
|
void addRightControllerModes(bool noswap);
|
||||||
|
void addPaddleModes(int lport, int rport, int lname, int rname);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Properties& myProps;
|
const Properties& myProps;
|
||||||
Controller& myLeftController;
|
Controller& myLeftController;
|
||||||
|
@ -86,12 +91,23 @@ class MouseControl
|
||||||
: xaxis(NoControl),
|
: xaxis(NoControl),
|
||||||
yaxis(NoControl),
|
yaxis(NoControl),
|
||||||
controlID(-1),
|
controlID(-1),
|
||||||
message("Mouse input is disabled") { }
|
message("") { }
|
||||||
|
MouseMode(const string& msg)
|
||||||
|
: xaxis(NoControl),
|
||||||
|
yaxis(NoControl),
|
||||||
|
controlID(-1),
|
||||||
|
message(msg) { }
|
||||||
MouseMode(Axis x, Axis y, int id, const string& msg)
|
MouseMode(Axis x, Axis y, int id, const string& msg)
|
||||||
: xaxis(x),
|
: xaxis(x),
|
||||||
yaxis(y),
|
yaxis(y),
|
||||||
controlID(id),
|
controlID(id),
|
||||||
message(msg) { }
|
message(msg) { }
|
||||||
|
friend ostream& operator<<(ostream& os, const MouseMode& mm)
|
||||||
|
{
|
||||||
|
os << "xaxis=" << mm.xaxis << ", yaxis=" << mm.yaxis
|
||||||
|
<< ", id=" << mm.controlID << ", msg=" << mm.message;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
int myCurrentModeNum;
|
int myCurrentModeNum;
|
||||||
|
|
|
@ -976,7 +976,7 @@ void DiStella::processDirectives(const CartDebug::DirectiveList& directives)
|
||||||
for(CartDebug::DirectiveList::const_iterator i = directives.begin();
|
for(CartDebug::DirectiveList::const_iterator i = directives.begin();
|
||||||
i != directives.end(); ++i)
|
i != directives.end(); ++i)
|
||||||
{
|
{
|
||||||
const CartDebug::DirectiveTag tag = *i;
|
const CartDebug::DirectiveTag& tag = *i;
|
||||||
if(check_range(tag.start, tag.end))
|
if(check_range(tag.start, tag.end))
|
||||||
for(uInt32 k = tag.start; k <= tag.end; ++k)
|
for(uInt32 k = tag.start; k <= tag.end; ++k)
|
||||||
mark(k, tag.type, true);
|
mark(k, tag.type, true);
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
Paddles::Paddles(Jack jack, const Event& event, const System& system,
|
Paddles::Paddles(Jack jack, const Event& event, const System& system,
|
||||||
bool swapport, bool swapaxis, bool swapdir)
|
bool swappaddle, bool swapaxis, bool swapdir)
|
||||||
: Controller(jack, event, system, Controller::Paddles),
|
: Controller(jack, event, system, Controller::Paddles),
|
||||||
myMPaddleID(-1),
|
myMPaddleID(-1),
|
||||||
myMPaddleIDX(-1),
|
myMPaddleIDX(-1),
|
||||||
|
@ -46,7 +46,7 @@ Paddles::Paddles(Jack jack, const Event& event, const System& system,
|
||||||
// Consider whether this is the left or right port
|
// Consider whether this is the left or right port
|
||||||
if(myJack == Left)
|
if(myJack == Left)
|
||||||
{
|
{
|
||||||
if(!swapport) // First paddle is 0, second is 1
|
if(!swappaddle) // First paddle is 0, second is 1
|
||||||
{
|
{
|
||||||
// These aren't affected by changes in axis orientation
|
// These aren't affected by changes in axis orientation
|
||||||
myP0AxisValue = Event::SALeftAxis0Value;
|
myP0AxisValue = Event::SALeftAxis0Value;
|
||||||
|
@ -121,7 +121,7 @@ Paddles::Paddles(Jack jack, const Event& event, const System& system,
|
||||||
}
|
}
|
||||||
else // Jack is right port
|
else // Jack is right port
|
||||||
{
|
{
|
||||||
if(!swapport) // First paddle is 2, second is 3
|
if(!swappaddle) // First paddle is 2, second is 3
|
||||||
{
|
{
|
||||||
// These aren't affected by changes in axis orientation
|
// These aren't affected by changes in axis orientation
|
||||||
myP0AxisValue = Event::SARightAxis0Value;
|
myP0AxisValue = Event::SARightAxis0Value;
|
||||||
|
|
|
@ -40,14 +40,14 @@ class Paddles : public Controller
|
||||||
@param event The event object to use for events
|
@param event The event object to use for events
|
||||||
@param system The system using this controller
|
@param system The system using this controller
|
||||||
|
|
||||||
@param swapport Whether to swap the paddles plugged into this jack
|
@param swappaddle Whether to swap the paddles plugged into this jack
|
||||||
@param swapaxis Whether to swap the axis on the paddle (x <-> y)
|
@param swapaxis Whether to swap the axis on the paddle (x <-> y)
|
||||||
@param swapdir Whether to swap the direction for which an axis
|
@param swapdir Whether to swap the direction for which an axis
|
||||||
causes movement (lesser axis values cause paddle
|
causes movement (lesser axis values cause paddle
|
||||||
resistance to decrease instead of increase)
|
resistance to decrease instead of increase)
|
||||||
*/
|
*/
|
||||||
Paddles(Jack jack, const Event& event, const System& system,
|
Paddles(Jack jack, const Event& event, const System& system,
|
||||||
bool swapport, bool swapaxis, bool swapdir);
|
bool swappaddle, bool swapaxis, bool swapdir);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Destructor
|
Destructor
|
||||||
|
@ -126,6 +126,8 @@ class Paddles : public Controller
|
||||||
int myLastAxisX, myLastAxisY;
|
int myLastAxisX, myLastAxisY;
|
||||||
int myAxisDigitalZero, myAxisDigitalOne;
|
int myAxisDigitalZero, myAxisDigitalOne;
|
||||||
|
|
||||||
|
bool mySwapPorts;
|
||||||
|
|
||||||
static int _DIGITAL_SENSITIVITY, _DIGITAL_DISTANCE;
|
static int _DIGITAL_SENSITIVITY, _DIGITAL_DISTANCE;
|
||||||
static int _MOUSE_SENSITIVITY;
|
static int _MOUSE_SENSITIVITY;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue