1
0
Fork 0

Change multi_remain to repeat last parsed value for non-string types if the next value is empty and of the same type as the last.

Use this to add an optional parameter to sensitivity which controls the y axis. When optional parameter is missing, x and y axis have the same value.
Change limits on sensitivity to allow for negative values so the Mouse Y-axis can be inversed. Similar to patch #276.


Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@4197
This commit is contained in:
Peter Veenstra 2019-03-29 20:47:57 +00:00
parent 202bfa1155
commit 94113a7362
2 changed files with 46 additions and 16 deletions

View file

@ -206,7 +206,8 @@ struct SDL_Block {
bool autoenable;
bool requestlock;
bool locked;
Bitu sensitivity;
int xsensitivity;
int ysensitivity;
} mouse;
SDL_Rect updateRects[1024];
Bitu num_joysticks;
@ -1289,7 +1290,10 @@ static void GUI_StartUp(Section * sec) {
sdl.mouse.autoenable=section->Get_bool("autolock");
if (!sdl.mouse.autoenable) SDL_ShowCursor(SDL_DISABLE);
sdl.mouse.autolock=false;
sdl.mouse.sensitivity=section->Get_int("sensitivity");
Prop_multival* p3 = section->Get_multival("sensitivity");
sdl.mouse.xsensitivity = p3->GetSection()->Get_int("xsens");
sdl.mouse.ysensitivity = p3->GetSection()->Get_int("ysens");
std::string output=section->Get_string("output");
/* Setup Mouse correctly if fullscreen */
@ -1458,10 +1462,10 @@ void Mouse_AutoLock(bool enable) {
static void HandleMouseMotion(SDL_MouseMotionEvent * motion) {
if (sdl.mouse.locked || !sdl.mouse.autoenable)
Mouse_CursorMoved((float)motion->xrel*sdl.mouse.sensitivity/100.0f,
(float)motion->yrel*sdl.mouse.sensitivity/100.0f,
(float)(motion->x-sdl.clip.x)/(sdl.clip.w-1)*sdl.mouse.sensitivity/100.0f,
(float)(motion->y-sdl.clip.y)/(sdl.clip.h-1)*sdl.mouse.sensitivity/100.0f,
Mouse_CursorMoved((float)motion->xrel*sdl.mouse.xsensitivity/100.0f,
(float)motion->yrel*sdl.mouse.ysensitivity/100.0f,
(float)(motion->x-sdl.clip.x)/(sdl.clip.w-1)*sdl.mouse.xsensitivity/100.0f,
(float)(motion->y-sdl.clip.y)/(sdl.clip.h-1)*sdl.mouse.ysensitivity/100.0f,
sdl.mouse.locked);
}
@ -1470,7 +1474,7 @@ static void HandleMouseButton(SDL_MouseButtonEvent * button) {
case SDL_PRESSED:
if (sdl.mouse.requestlock && !sdl.mouse.locked) {
GFX_CaptureMouse();
// Dont pass klick to mouse handler
// Don't pass click to mouse handler
break;
}
if (!sdl.mouse.autoenable && sdl.mouse.autolock && button->button == SDL_BUTTON_MIDDLE) {
@ -1755,9 +1759,13 @@ void Config_Add_SDL() {
Pbool = sdl_sec->Add_bool("autolock",Property::Changeable::Always,true);
Pbool->Set_help("Mouse will automatically lock, if you click on the screen. (Press CTRL-F10 to unlock)");
Pint = sdl_sec->Add_int("sensitivity",Property::Changeable::Always,100);
Pint->SetMinMax(1,1000);
Pint->Set_help("Mouse sensitivity.");
Pmulti = sdl_sec->Add_multi("sensitivity",Property::Changeable::Always, ",");
Pmulti->Set_help("Mouse sensitivity. The optional second parameter specifies vertical sensitivity (e.g. 100,-50).");
Pmulti->SetValue("100");
Pint = Pmulti->GetSection()->Add_int("xsens",Property::Changeable::Always,100);
Pint->SetMinMax(-1000,1000);
Pint = Pmulti->GetSection()->Add_int("ysens",Property::Changeable::Always,100);
Pint->SetMinMax(-1000,1000);
Pbool = sdl_sec->Add_bool("waitonerror",Property::Changeable::Always, true);
Pbool->Set_help("Wait before closing the console if dosbox has an error.");

View file

@ -429,6 +429,9 @@ bool Prop_multival::SetValue(std::string const& input) {
Property *p = section->Get_prop(0);
//No properties in this section. do nothing
if (!p) return false;
Value::Etype prevtype = Value::V_NONE;
string prevargument = "";
string::size_type loc = string::npos;
while( (p = section->Get_prop(i++)) ) {
//trim leading separators
@ -443,13 +446,32 @@ bool Prop_multival::SetValue(std::string const& input) {
in = local;
local = "";
}
//Test Value. If it fails set default
Value valtest (in,p->Get_type());
if (!p->CheckValue(valtest,true)) {
make_default_value();
return false;
if (p->Get_type() == Value::V_STRING) {
//Strings are only checked against the suggested values list.
//Test Value. If it fails set default
Value valtest (in,p->Get_type());
if (!p->CheckValue(valtest,true)) {
make_default_value();
return false;
}
p->SetValue(in);
} else {
//Non-strings can have more things, conversion alone is not enough (as invalid values as converted to 0)
bool r = p->SetValue(in);
if (!r) {
if (in.empty() && p->Get_type() == prevtype ) {
//Nothing there, but same type of variable, so repeat it (sensitivity)
in = prevargument;
p->SetValue(in);
} else {
//Something was there to be parsed or not the same type. Invalidate entire property.
make_default_value();
}
}
}
p->SetValue(in);
prevtype = p->Get_type();
prevargument = in;
}
return retval;