Use fractional scroll delta

This commit is contained in:
Simon Chan 2022-07-03 07:02:17 +00:00
parent ed84e18b1a
commit 1c3e33c776
5 changed files with 16 additions and 14 deletions

View file

@ -747,8 +747,8 @@ sc_input_manager_process_mouse_wheel(struct sc_input_manager *im,
.point = sc_screen_convert_window_to_frame_coords(im->screen,
mouse_x, mouse_y),
},
.hscroll = event->x,
.vscroll = event->y,
.hscroll = (int32_t)(event->preciseX * 1000),
.vscroll = (int32_t)(event->preciseY * 1000),
.buttons_state =
sc_mouse_buttons_state_from_sdl(buttons, im->forward_all_clicks),
};

View file

@ -33,8 +33,8 @@ public final class ControlMessage {
private long pointerId;
private float pressure;
private Position position;
private int hScroll;
private int vScroll;
private float hScroll;
private float vScroll;
private int copyKey;
private boolean paste;
private int repeat;
@ -71,7 +71,7 @@ public final class ControlMessage {
return msg;
}
public static ControlMessage createInjectScrollEvent(Position position, int hScroll, int vScroll, int buttons) {
public static ControlMessage createInjectScrollEvent(Position position, float hScroll, float vScroll, int buttons) {
ControlMessage msg = new ControlMessage();
msg.type = TYPE_INJECT_SCROLL_EVENT;
msg.position = position;
@ -156,11 +156,11 @@ public final class ControlMessage {
return position;
}
public int getHScroll() {
public float getHScroll() {
return hScroll;
}
public int getVScroll() {
public float getVScroll() {
return vScroll;
}

View file

@ -152,8 +152,10 @@ public class ControlMessageReader {
return null;
}
Position position = readPosition(buffer);
int hScroll = buffer.getInt();
int vScroll = buffer.getInt();
int hScrollInt = buffer.getInt();
int vScrollInt = buffer.getInt();
float hScroll = hScrollInt / 1000f;
float vScroll = vScrollInt / 1000f;
int buttons = buffer.getInt();
return ControlMessage.createInjectScrollEvent(position, hScroll, vScroll, buttons);
}

View file

@ -223,7 +223,7 @@ public class Controller {
return device.injectEvent(event, Device.INJECT_MODE_ASYNC);
}
private boolean injectScroll(Position position, int hScroll, int vScroll, int buttons) {
private boolean injectScroll(Position position, float hScroll, float vScroll, int buttons) {
long now = SystemClock.uptimeMillis();
Point point = device.getPhysicalPoint(position);
if (point == null) {

View file

@ -126,8 +126,8 @@ public class ControlMessageReaderTest {
dos.writeInt(1026);
dos.writeShort(1080);
dos.writeShort(1920);
dos.writeInt(1);
dos.writeInt(-1);
dos.writeInt(1000);
dos.writeInt(-1000);
dos.writeInt(1);
byte[] packet = bos.toByteArray();
@ -143,8 +143,8 @@ public class ControlMessageReaderTest {
Assert.assertEquals(1026, event.getPosition().getPoint().getY());
Assert.assertEquals(1080, event.getPosition().getScreenSize().getWidth());
Assert.assertEquals(1920, event.getPosition().getScreenSize().getHeight());
Assert.assertEquals(1, event.getHScroll());
Assert.assertEquals(-1, event.getVScroll());
Assert.assertEquals(1f, event.getHScroll(), 0f);
Assert.assertEquals(-1f, event.getVScroll(), 0f);
Assert.assertEquals(1, event.getButtons());
}