minor enhancement of input global keys

This commit is contained in:
thrust26 2020-12-18 22:34:36 +01:00
parent dbdc984e77
commit e76fed006b
5 changed files with 109 additions and 62 deletions

View File

@ -2926,7 +2926,7 @@
<tr>
<td><pre>-dsense &lt;number&gt;</pre></td>
<td>Sensitivity for emulation of paddles when using a digital device
(ie, joystick digital axis or button, keyboard key, etc.).
(i.e. joystick digital axis or button, keyboard key, etc.).
Valid range of values is from 1 to 20, with larger numbers causing
faster movement.</td>
</tr>

View File

@ -267,6 +267,24 @@ void PhysicalJoystickHandler::mapStelladaptors(const string& saport)
myOSystem.settings().setValue("saport", saport);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool PhysicalJoystickHandler::hasStelladaptors() const
{
for(auto& [_id, _joyptr] : mySticks)
{
// remove previously added emulated ports
size_t pos = _joyptr->name.find(" (emulates ");
if(pos != std::string::npos)
_joyptr->name.erase(pos);
if(BSPF::startsWithIgnoreCase(_joyptr->name, "Stelladaptor")
|| BSPF::startsWithIgnoreCase(_joyptr->name, "2600-daptor"))
return true;
}
return false;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Depending on parameters, this method does the following:
// 1. update all events with default (event == Event::NoType, updateDefault == true)
@ -989,7 +1007,7 @@ void PhysicalJoystickHandler::changeDrivingSensitivity(int direction)
ostringstream ss;
ss << sense * 10 << "%";
myOSystem.frameBuffer().showGaugeMessage("Mouse driving controller sensitivity",
myOSystem.frameBuffer().showGaugeMessage("Driving controller sensitivity",
ss.str(), sense,
Driving::MIN_SENSE, Driving::MAX_SENSE);
}

View File

@ -71,6 +71,7 @@ class PhysicalJoystickHandler
bool remove(int id);
bool remove(const string& name);
void mapStelladaptors(const string& saport);
bool hasStelladaptors() const;
void setDefaultMapping(Event::Type type, EventMode mode);
/** define mappings for current controllers */

View File

@ -246,7 +246,7 @@ void EventHandler::changeMouseControl(int direction)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool EventHandler::hasMouseControl()
bool EventHandler::hasMouseControl() const
{
return myMouseControl && myMouseControl->hasMouseControl();
}
@ -416,28 +416,15 @@ bool EventHandler::isTrackball(const Controller& controller) const
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AdjustFunction EventHandler::cycleAdjustSetting(int direction)
bool EventHandler::skipAVSetting() const
{
const bool isPAL = myOSystem.console().timing() == ConsoleTiming::pal;
bool repeat = false;
do
{
switch (getAdjustGroup())
{
case AdjustGroup::AV:
{
const bool isFullScreen = myOSystem.frameBuffer().fullScreen();
const bool isCustomPalette =
myOSystem.settings().getString("palette") == PaletteHandler::SETTING_CUSTOM;
const bool isCustomFilter =
myOSystem.settings().getInt("tv.filter") == int(NTSCFilter::Preset::CUSTOM);
myAdjustSetting =
AdjustSetting(BSPF::clampw(int(myAdjustSetting) + direction,
int(AdjustSetting::START_AV_ADJ), int(AdjustSetting::END_AV_ADJ)));
// skip currently non-relevant adjustments
repeat = (myAdjustSetting == AdjustSetting::OVERSCAN && !isFullScreen)
return (myAdjustSetting == AdjustSetting::OVERSCAN && !isFullScreen)
#ifdef ADAPTABLE_REFRESH_SUPPORT
|| (myAdjustSetting == AdjustSetting::ADAPT_REFRESH && !isFullScreen)
#endif
@ -447,27 +434,30 @@ AdjustFunction EventHandler::cycleAdjustSetting(int direction)
|| (myAdjustSetting >= AdjustSetting::NTSC_SHARPNESS
&& myAdjustSetting <= AdjustSetting::NTSC_BLEEDING
&& !isCustomFilter);
break;
}
}
case AdjustGroup::INPUT:
{
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool EventHandler::skipInputSetting() const
{
const bool grabMouseAllowed = myOSystem.frameBuffer().grabMouseAllowed();
const bool analog = myOSystem.console().leftController().isAnalog()
|| myOSystem.console().rightController().isAnalog();
const bool joystick = isJoystick(myOSystem.console().leftController())
|| isJoystick(myOSystem.console().rightController());
const bool paddle = isPaddle(myOSystem.console().leftController())
|| isPaddle(myOSystem.console().rightController());
const bool trackball = isTrackball(myOSystem.console().leftController())
|| isTrackball(myOSystem.console().rightController());
const bool driving = myOSystem.console().leftController().type() == Controller::Type::Driving
const bool driving =
myOSystem.console().leftController().type() == Controller::Type::Driving
|| myOSystem.console().rightController().type() == Controller::Type::Driving;
const bool useMouse = myOSystem.settings().getString("usemouse") != "never";
const bool useMouse =
BSPF::equalsIgnoreCase("always", myOSystem.settings().getString("usemouse"))
|| (BSPF::equalsIgnoreCase("analog", myOSystem.settings().getString("usemouse"))
&& analog);
const bool stelladapter = myPJoyHandler->hasStelladaptors();
myAdjustSetting =
AdjustSetting(BSPF::clampw(int(myAdjustSetting) + direction,
int(AdjustSetting::START_INPUT_ADJ), int(AdjustSetting::END_INPUT_ADJ)));
// skip currently non-relevant adjustments
repeat = (!grabMouseAllowed && myAdjustSetting == AdjustSetting::GRAB_MOUSE)
return (!grabMouseAllowed && myAdjustSetting == AdjustSetting::GRAB_MOUSE)
|| (!joystick
&& (myAdjustSetting == AdjustSetting::DEADZONE
|| myAdjustSetting == AdjustSetting::FOUR_DIRECTIONS))
@ -484,29 +474,62 @@ AdjustFunction EventHandler::cycleAdjustSetting(int direction)
|| ((!trackball || !useMouse)
&& myAdjustSetting == AdjustSetting::TRACKBALL_SENSITIVITY)
|| (!driving
&& myAdjustSetting == AdjustSetting::DRIVING_SENSITIVITY) // also affects keyboard input sensitivity
&& myAdjustSetting == AdjustSetting::DRIVING_SENSITIVITY) // also affects digital device input sensitivity
|| ((!hasMouseControl() || !useMouse)
&& myAdjustSetting == AdjustSetting::MOUSE_CONTROL)
|| ((!paddle || !useMouse)
&& myAdjustSetting == AdjustSetting::MOUSE_RANGE);
&& myAdjustSetting == AdjustSetting::MOUSE_RANGE)
|| (!stelladapter
&& myAdjustSetting == AdjustSetting::SA_PORT_ORDER);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool EventHandler::skipDebugSetting() const
{
const bool isPAL = myOSystem.console().timing() == ConsoleTiming::pal;
return (myAdjustSetting == AdjustSetting::COLOR_LOSS && !isPAL);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
AdjustFunction EventHandler::cycleAdjustSetting(int direction)
{
bool skip = false;
do
{
switch (getAdjustGroup())
{
case AdjustGroup::AV:
myAdjustSetting =
AdjustSetting(BSPF::clampw(int(myAdjustSetting) + direction,
int(AdjustSetting::START_AV_ADJ), int(AdjustSetting::END_AV_ADJ)));
// skip currently non-relevant adjustments
skip = skipAVSetting();
break;
case AdjustGroup::INPUT:
myAdjustSetting =
AdjustSetting(BSPF::clampw(int(myAdjustSetting) + direction,
int(AdjustSetting::START_INPUT_ADJ), int(AdjustSetting::END_INPUT_ADJ)));
// skip currently non-relevant adjustments
skip = skipInputSetting();
break;
}
case AdjustGroup::DEBUG:
myAdjustSetting =
AdjustSetting(BSPF::clampw(int(myAdjustSetting) + direction,
int(AdjustSetting::START_DEBUG_ADJ), int(AdjustSetting::END_DEBUG_ADJ)));
// skip currently non-relevant adjustments
repeat = (myAdjustSetting == AdjustSetting::COLOR_LOSS && !isPAL);
skip = skipDebugSetting();
break;
default:
break;
}
// avoid endless loop
if(repeat && !direction)
if(skip && !direction)
direction = 1;
} while(repeat);
} while(skip);
return getAdjustSetting(myAdjustSetting);
}

View File

@ -361,7 +361,7 @@ class EventHandler
Handle changing mouse modes.
*/
void changeMouseControl(int direction = +1);
bool hasMouseControl();
bool hasMouseControl() const;
void saveKeyMapping();
void saveJoyMapping();
@ -576,6 +576,11 @@ class EventHandler
bool isPaddle(const Controller& controller) const;
bool isTrackball(const Controller& controller) const;
// Check if a currently non-relevant adjustment can be skipped
bool skipAVSetting() const;
bool skipInputSetting() const;
bool skipDebugSetting() const;
private:
// Structure used for action menu items
struct ActionList {