aboutsummaryrefslogtreecommitdiff
path: root/backends/events/sdl
diff options
context:
space:
mode:
authorrsn88872017-02-18 11:54:39 -0600
committerrsn88872017-02-18 12:00:22 -0600
commit75004c429c2eb114b28cbb8adb10c6e34b2716c0 (patch)
treec7ca7ebfb73cdaa2106aa784ab6b94fde580d050 /backends/events/sdl
parent09a60297810009f28dbef7eb5ea5e858fbd4bce6 (diff)
downloadscummvm-rg350-75004c429c2eb114b28cbb8adb10c6e34b2716c0.tar.gz
scummvm-rg350-75004c429c2eb114b28cbb8adb10c6e34b2716c0.tar.bz2
scummvm-rg350-75004c429c2eb114b28cbb8adb10c6e34b2716c0.zip
SDL: improved internal joystick event handling
Diffstat (limited to 'backends/events/sdl')
-rw-r--r--backends/events/sdl/sdl-events.cpp49
-rw-r--r--backends/events/sdl/sdl-events.h3
2 files changed, 28 insertions, 24 deletions
diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp
index 78092f8fc1..dccdef971b 100644
--- a/backends/events/sdl/sdl-events.cpp
+++ b/backends/events/sdl/sdl-events.cpp
@@ -205,12 +205,12 @@ bool SdlEventSource::handleKbdMouse(Common::Event &event) {
if (_km.x_vel || _km.y_vel) {
if (_km.x_down_count) {
- if (curTime > _km.x_down_time + _km.delay_time * 12) {
+ if (curTime > _km.x_down_time + 300) {
if (_km.x_vel > 0)
- _km.x_vel+=_km.multiplier;
+ _km.x_vel += _km.multiplier;
else
- _km.x_vel-=_km.multiplier;
- } else if (curTime > _km.x_down_time + _km.delay_time * 8) {
+ _km.x_vel -= _km.multiplier;
+ } else if (curTime > _km.x_down_time + 200) {
if (_km.x_vel > 0)
_km.x_vel = 5 * _km.multiplier;
else
@@ -218,27 +218,33 @@ bool SdlEventSource::handleKbdMouse(Common::Event &event) {
}
}
if (_km.y_down_count) {
- if (curTime > _km.y_down_time + _km.delay_time * 12) {
+ if (curTime > _km.y_down_time + 300) {
if (_km.y_vel > 0)
_km.y_vel += _km.multiplier;
else
_km.y_vel -= _km.multiplier;
- } else if (curTime > _km.y_down_time + _km.delay_time * 8) {
+ } else if (curTime > _km.y_down_time + 200) {
if (_km.y_vel > 0)
_km.y_vel = 5 * _km.multiplier;
else
_km.y_vel = -5 * _km.multiplier;
}
}
+
// The modifier key makes the mouse movement slower
+ // The extra factor of delay/25 makes velocities
+ // independent of kbdMouse update rate
+ // all velovities were originally chosen
+ // at a delay of 25, so that is the reference
+ // operator order is important to avoid overflow
if (_km.modifier) {
- _km.x += _km.x_vel / 10;
- _km.y += _km.y_vel / 10;
+ _km.x += ((_km.x_vel / 10) * ((int16)_km.delay_time)) / 25;
+ _km.y += ((_km.y_vel / 10) * ((int16)_km.delay_time)) / 25;
} else {
- _km.x += _km.x_vel;
- _km.y += _km.y_vel;
+ _km.x += (_km.x_vel * ((int16)_km.delay_time)) / 25;
+ _km.y += (_km.y_vel * ((int16)_km.delay_time)) / 25;
}
-
+
if (_km.x < 0) {
_km.x = 0;
_km.x_vel = -1 * _km.multiplier;
@@ -260,7 +266,7 @@ bool SdlEventSource::handleKbdMouse(Common::Event &event) {
}
if (_graphicsManager) {
- _graphicsManager->getWindow()->warpMouseInWindow((Uint16) (_km.x / _km.multiplier), (Uint16) (_km.y / _km.multiplier));
+ _graphicsManager->getWindow()->warpMouseInWindow((Uint16)(_km.x / _km.multiplier), (Uint16)(_km.y / _km.multiplier));
}
if (_km.x != oldKmX || _km.y != oldKmY) {
@@ -446,9 +452,6 @@ Common::KeyCode SdlEventSource::SDLToOSystemKeycode(const SDLKey key) {
}
bool SdlEventSource::pollEvent(Common::Event &event) {
- if (handleKbdMouse(event)) {
- return true;
- }
#if SDL_VERSION_ATLEAST(2, 0, 0)
// In case we still need to send a key up event for a key down from a
@@ -474,6 +477,12 @@ bool SdlEventSource::pollEvent(Common::Event &event) {
if (dispatchSDLEvent(ev, event))
return true;
}
+
+ // Handle mouse control via analog joystick and keyboard
+ if (handleKbdMouse(event)) {
+ return true;
+ }
+
return false;
}
@@ -799,14 +808,12 @@ bool SdlEventSource::handleJoyAxisMotion(SDL_Event &ev, Common::Event &event) {
int axis = ev.jaxis.value;
#ifdef JOY_ANALOG
// conversion factor between keyboard mouse and joy axis value
- int vel_to_axis = (3000 / _km.multiplier);
+ int vel_to_axis = (1500 / _km.multiplier);
#else
if (axis > JOY_DEADZONE) {
axis -= JOY_DEADZONE;
- event.type = Common::EVENT_MOUSEMOVE;
} else if (axis < -JOY_DEADZONE) {
axis += JOY_DEADZONE;
- event.type = Common::EVENT_MOUSEMOVE;
} else
axis = 0;
#endif
@@ -855,16 +862,13 @@ bool SdlEventSource::handleJoyAxisMotion(SDL_Event &ev, Common::Event &event) {
scalingFactor = 1.0f / magnitude * (magnitude - deadZone) / (32769.0f - deadZone);
_km.x_vel = (int16) (analogX * scalingFactor * 32768.0f / vel_to_axis);
_km.y_vel = (int16) (analogY * scalingFactor * 32768.0f / vel_to_axis);
- event.type = Common::EVENT_MOUSEMOVE;
} else {
_km.y_vel = 0;
_km.x_vel = 0;
}
#endif
- processMouseEvent(event, _km.x / _km.multiplier, _km.y / _km.multiplier);
-
- return true;
+ return false;
}
bool SdlEventSource::remapKey(SDL_Event &ev, Common::Event &event) {
@@ -940,7 +944,6 @@ void SdlEventSource::resetKeyboardEmulation(int16 x_max, int16 y_max) {
_km.y_max = y_max;
_km.delay_time = 12;
_km.last_time = 0;
- _km.multiplier = 16;
_km.modifier = false;
}
diff --git a/backends/events/sdl/sdl-events.h b/backends/events/sdl/sdl-events.h
index ecbf62c464..c1d6057dac 100644
--- a/backends/events/sdl/sdl-events.h
+++ b/backends/events/sdl/sdl-events.h
@@ -58,7 +58,8 @@ protected:
//@{
struct KbdMouse {
- int16 x, y, x_vel, y_vel, x_max, y_max, x_down_count, y_down_count, multiplier;
+ int16 x, y, x_vel, y_vel, x_max, y_max, x_down_count, y_down_count;
+ static const int16 multiplier = 16;
uint32 last_time, delay_time, x_down_time, y_down_time;
bool modifier;
};