Added GUI widgets to InputDialog to change speed of paddle movement when

emulating paddles with the keyboard or joystick.  These slider widgets go
from 0 to 100 percent, and represent minimum (0) to maximum (100) speed.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@910 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-12-16 14:41:15 +00:00
parent 514ff4ea9a
commit e6aa6391eb
5 changed files with 117 additions and 44 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: EventHandler.cxx,v 1.127 2005-12-13 00:35:24 stephena Exp $ // $Id: EventHandler.cxx,v 1.128 2005-12-16 14:41:14 stephena Exp $
//============================================================================ //============================================================================
#include <algorithm> #include <algorithm>
@ -180,11 +180,16 @@ void EventHandler::reset(State state)
if(myState == S_LAUNCHER) if(myState == S_LAUNCHER)
myUseLauncherFlag = true; myUseLauncherFlag = true;
// Start paddle emulation in a known state
for(int i = 0; i < 4; ++i) for(int i = 0; i < 4; ++i)
{ {
memset(&myPaddle[i], 0, sizeof(myJoyMouse)); memset(&myPaddle[i], 0, sizeof(myJoyMouse));
myPaddle[i].amt = 70000; // FIXME - get scale factor from GUI and apply to this value myEvent->set(Paddle_Resistance[i], 1000000);
} }
setPaddleSpeed(0, myOSystem->settings().getInt("p1speed"));
setPaddleSpeed(1, myOSystem->settings().getInt("p2speed"));
setPaddleSpeed(2, myOSystem->settings().getInt("p3speed"));
setPaddleSpeed(3, myOSystem->settings().getInt("p4speed"));
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -767,7 +772,6 @@ void EventHandler::poll(uInt32 time)
{ {
int resistance = (int)(1000000.0 * (1000000.0 - myPaddle[i].x) / 1000000.0); int resistance = (int)(1000000.0 * (1000000.0 - myPaddle[i].x) / 1000000.0);
myEvent->set(Paddle_Resistance[i], resistance); myEvent->set(Paddle_Resistance[i], resistance);
cerr << "do paddle resistance for value = " << myPaddle[i].x << endl;
} }
} }
} }
@ -1960,7 +1964,7 @@ cerr << "load recording!\n";
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::setPaddleMode(uInt32 num, bool showmessage) void EventHandler::setPaddleMode(int num, bool showmessage)
{ {
if(num < 0 || num > 3) if(num < 0 || num > 3)
return; return;
@ -1977,6 +1981,18 @@ void EventHandler::setPaddleMode(uInt32 num, bool showmessage)
myOSystem->settings().setInt("paddle", myPaddleMode); myOSystem->settings().setInt("paddle", myPaddleMode);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::setPaddleSpeed(int num, int speed)
{
if(num < 0 || num > 3 || speed < 0 || speed > 100)
return;
myPaddle[num].amt = (int) (20000 + speed/100.0 * 50000);
ostringstream buf;
buf << "p" << num+1 << "speed";
myOSystem->settings().setInt(buf.str(), speed);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EventHandler::enterMenuMode(State state) void EventHandler::enterMenuMode(State state)
{ {

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: EventHandler.hxx,v 1.65 2005-12-13 00:35:24 stephena Exp $ // $Id: EventHandler.hxx,v 1.66 2005-12-16 14:41:14 stephena Exp $
//============================================================================ //============================================================================
#ifndef EVENTHANDLER_HXX #ifndef EVENTHANDLER_HXX
@ -92,7 +92,7 @@ struct Stella_Joystick {
mapping can take place. mapping can take place.
@author Stephen Anthony @author Stephen Anthony
@version $Id: EventHandler.hxx,v 1.65 2005-12-13 00:35:24 stephena Exp $ @version $Id: EventHandler.hxx,v 1.66 2005-12-16 14:41:14 stephena Exp $
*/ */
class EventHandler class EventHandler
{ {
@ -252,7 +252,15 @@ class EventHandler
@param num The paddle which the mouse should emulate @param num The paddle which the mouse should emulate
@param showmessage Print a message to the framebuffer @param showmessage Print a message to the framebuffer
*/ */
void setPaddleMode(uInt32 num, bool showmessage = false); void setPaddleMode(int num, bool showmessage = false);
/**
Sets the speed of the given paddle
@param num The paddle number (0-3)
@param speed The speed of paddle movement for the given paddle
*/
void setPaddleSpeed(int num, int speed);
inline bool kbdAlt(int mod) inline bool kbdAlt(int mod)
{ {

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Settings.cxx,v 1.67 2005-12-07 20:46:49 stephena Exp $ // $Id: Settings.cxx,v 1.68 2005-12-16 14:41:14 stephena Exp $
//============================================================================ //============================================================================
#include <cassert> #include <cassert>
@ -63,6 +63,11 @@ Settings::Settings(OSystem* osystem)
set("joymouse", "false"); set("joymouse", "false");
set("sa1", "left"); set("sa1", "left");
set("sa2", "right"); set("sa2", "right");
set("mspeed", "50");
set("p1speed", "50");
set("p2speed", "50");
set("p3speed", "50");
set("p4speed", "50");
set("showinfo", "false"); set("showinfo", "false");

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: InputDialog.cxx,v 1.5 2005-12-07 20:46:49 stephena Exp $ // $Id: InputDialog.cxx,v 1.6 2005-12-16 14:41:15 stephena Exp $
//============================================================================ //============================================================================
#include "OSystem.hxx" #include "OSystem.hxx"
@ -28,7 +28,10 @@
enum { enum {
kPaddleChanged = 'PDch', kPaddleChanged = 'PDch',
kSenseChanged = 'PSch' kP0SpeedID = 100,
kP1SpeedID = 101,
kP2SpeedID = 102,
kP3SpeedID = 103
}; };
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -109,29 +112,65 @@ void InputDialog::addVDeviceTab()
wid.push_back(myRightPort); wid.push_back(myRightPort);
// Add 'mouse to paddle' mapping // Add 'mouse to paddle' mapping
ypos += 2*lineHeight + 3; ypos += 2*lineHeight;
lwidth = font.getStringWidth("Mouse sensitivity: "); lwidth = font.getStringWidth("Mouse is paddle: ");
myPaddleMode = new SliderWidget(myTab, xpos, ypos, lwidth + 30, lineHeight, myPaddleMode = new SliderWidget(myTab, xpos, ypos, lwidth + 30, lineHeight,
"Mouse is paddle: ", "Mouse is paddle: ",
lwidth, kPaddleChanged); lwidth, kPaddleChanged);
myPaddleMode->setMinValue(0); myPaddleMode->setMaxValue(3); myPaddleMode->setMinValue(0); myPaddleMode->setMaxValue(3);
xpos += myPaddleMode->getWidth() + 5; xpos += myPaddleMode->getWidth() + 5;
myPaddleLabel = new StaticTextWidget(myTab, xpos, ypos+1, 24, lineHeight, myPaddleModeLabel = new StaticTextWidget(myTab, xpos, ypos+1, 24, lineHeight,
"", kTextAlignLeft); "", kTextAlignLeft);
myPaddleLabel->setFlags(WIDGET_CLEARBG); myPaddleModeLabel->setFlags(WIDGET_CLEARBG);
wid.push_back(myPaddleMode); wid.push_back(myPaddleMode);
// Add mouse sensitivity // Add paddle 0 speed
xpos = 5; ypos += lineHeight + 3; xpos = 5; ypos += lineHeight + 3;
myPaddleSense = new SliderWidget(myTab, xpos, ypos, lwidth + 30, lineHeight, myPaddleSpeed[0] = new SliderWidget(myTab, xpos, ypos, lwidth + 30, lineHeight,
"Mouse sensitivity: ", "Paddle 1 speed: ",
lwidth, kSenseChanged); lwidth, kP0SpeedID);
myPaddleSense->setMinValue(1); myPaddleSense->setMaxValue(100); myPaddleSpeed[0]->setMinValue(1); myPaddleSpeed[0]->setMaxValue(100);
xpos += myPaddleSense->getWidth() + 5; xpos += myPaddleSpeed[0]->getWidth() + 5;
mySenseLabel = new StaticTextWidget(myTab, xpos, ypos+1, 24, lineHeight, myPaddleLabel[0] = new StaticTextWidget(myTab, xpos, ypos+1, 24, lineHeight,
"", kTextAlignLeft); "", kTextAlignLeft);
mySenseLabel->setFlags(WIDGET_CLEARBG); myPaddleLabel[0]->setFlags(WIDGET_CLEARBG);
wid.push_back(myPaddleSense); wid.push_back(myPaddleSpeed[0]);
// Add paddle 1 speed
xpos = 5; ypos += lineHeight + 3;
myPaddleSpeed[1] = new SliderWidget(myTab, xpos, ypos, lwidth + 30, lineHeight,
"Paddle 2 speed: ",
lwidth, kP1SpeedID);
myPaddleSpeed[1]->setMinValue(1); myPaddleSpeed[1]->setMaxValue(100);
xpos += myPaddleSpeed[1]->getWidth() + 5;
myPaddleLabel[1] = new StaticTextWidget(myTab, xpos, ypos+1, 24, lineHeight,
"", kTextAlignLeft);
myPaddleLabel[1]->setFlags(WIDGET_CLEARBG);
wid.push_back(myPaddleSpeed[1]);
// Add paddle 2 speed
xpos = 5; ypos += lineHeight + 3;
myPaddleSpeed[2] = new SliderWidget(myTab, xpos, ypos, lwidth + 30, lineHeight,
"Paddle 3 speed: ",
lwidth, kP2SpeedID);
myPaddleSpeed[2]->setMinValue(1); myPaddleSpeed[2]->setMaxValue(100);
xpos += myPaddleSpeed[2]->getWidth() + 5;
myPaddleLabel[2] = new StaticTextWidget(myTab, xpos, ypos+1, 24, lineHeight,
"", kTextAlignLeft);
myPaddleLabel[2]->setFlags(WIDGET_CLEARBG);
wid.push_back(myPaddleSpeed[2]);
// Add paddle 3 speed
xpos = 5; ypos += lineHeight + 3;
myPaddleSpeed[3] = new SliderWidget(myTab, xpos, ypos, lwidth + 30, lineHeight,
"Paddle 4 speed: ",
lwidth, kP3SpeedID);
myPaddleSpeed[3]->setMinValue(1); myPaddleSpeed[3]->setMaxValue(100);
xpos += myPaddleSpeed[3]->getWidth() + 5;
myPaddleLabel[3] = new StaticTextWidget(myTab, xpos, ypos+1, 24, lineHeight,
"", kTextAlignLeft);
myPaddleLabel[3]->setFlags(WIDGET_CLEARBG);
wid.push_back(myPaddleSpeed[3]);
// Add items for virtual device ports // Add items for virtual device ports
addToFocusList(wid, tabID); addToFocusList(wid, tabID);
@ -150,13 +189,17 @@ void InputDialog::loadConfig()
// Paddle mode // Paddle mode
myPaddleMode->setValue(instance()->settings().getInt("paddle")); myPaddleMode->setValue(instance()->settings().getInt("paddle"));
myPaddleLabel->setLabel(instance()->settings().getString("paddle")); myPaddleModeLabel->setLabel(instance()->settings().getString("paddle"));
/* FIXME - add this to eventhandler core // Paddle speed settings
// Paddle sensitivity myPaddleSpeed[0]->setValue(instance()->settings().getInt("p1speed"));
myPaddleSense->setValue(instance()->settings().getInt("paddle")); myPaddleLabel[0]->setLabel(instance()->settings().getString("p1speed"));
mySenseLabel->setLabel(instance()->settings().getString("paddle")); myPaddleSpeed[1]->setValue(instance()->settings().getInt("p2speed"));
*/ myPaddleLabel[1]->setLabel(instance()->settings().getString("p2speed"));
myPaddleSpeed[2]->setValue(instance()->settings().getInt("p3speed"));
myPaddleLabel[2]->setLabel(instance()->settings().getString("p3speed"));
myPaddleSpeed[3]->setValue(instance()->settings().getInt("p4speed"));
myPaddleLabel[3]->setLabel(instance()->settings().getString("p4speed"));
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -171,11 +214,9 @@ void InputDialog::saveConfig()
int mode = myPaddleMode->getValue(); int mode = myPaddleMode->getValue();
instance()->eventHandler().setPaddleMode(mode); instance()->eventHandler().setPaddleMode(mode);
/* FIXME - add this to eventhandler core // Paddle speed settings
// Paddle sensitivity for(int i = 0; i < 4; ++i)
int sense = myPaddleSense->getValue(); instance()->eventHandler().setPaddleSpeed(i, myPaddleSpeed[i]->getValue());
instance()->eventHandler().setPaddleSense(sense);
*/
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -225,11 +266,14 @@ void InputDialog::handleCommand(CommandSender* sender, int cmd,
break; break;
case kPaddleChanged: case kPaddleChanged:
myPaddleLabel->setValue(myPaddleMode->getValue()); myPaddleModeLabel->setValue(myPaddleMode->getValue());
break; break;
case kSenseChanged: case kP0SpeedID:
mySenseLabel->setValue(myPaddleSense->getValue()); case kP1SpeedID:
case kP2SpeedID:
case kP3SpeedID:
myPaddleLabel[cmd-100]->setValue(myPaddleSpeed[cmd-100]->getValue());
break; break;
default: default:

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: InputDialog.hxx,v 1.3 2005-12-07 20:46:49 stephena Exp $ // $Id: InputDialog.hxx,v 1.4 2005-12-16 14:41:15 stephena Exp $
//============================================================================ //============================================================================
#ifndef INPUT_DIALOG_HXX #ifndef INPUT_DIALOG_HXX
@ -59,9 +59,9 @@ class InputDialog : public Dialog
PopUpWidget* myRightPort; PopUpWidget* myRightPort;
SliderWidget* myPaddleMode; SliderWidget* myPaddleMode;
StaticTextWidget* myPaddleLabel; StaticTextWidget* myPaddleModeLabel;
SliderWidget* myPaddleSense; SliderWidget* myPaddleSpeed[4];
StaticTextWidget* mySenseLabel; StaticTextWidget* myPaddleLabel[4];
CheckBoxWidget* myJoyMouse; CheckBoxWidget* myJoyMouse;
}; };