Skip to content

Commit

Permalink
Improve pen input handling
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Nov 29, 2022
1 parent 827d77d commit 56cc632
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Sources/iron/system/Input.hx
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ class Mouse extends VirtualInput {
}

function downListener(index: Int, x: Int, y: Int) {
if (Input.getPen().inUse) return;

buttonsDown[index] = true;
buttonsStarted[index] = true;
this.x = x;
Expand All @@ -231,6 +233,8 @@ class Mouse extends VirtualInput {
}

function upListener(index: Int, x: Int, y: Int) {
if (Input.getPen().inUse) return;

buttonsDown[index] = false;
buttonsReleased[index] = true;
this.x = x;
Expand Down Expand Up @@ -332,6 +336,7 @@ class Pen extends VirtualInput {
public var movementY(default, null) = 0.0;
public var pressure(default, null) = 0.0;
public var connected = false;
public var inUse = false;
var lastX = -1.0;
var lastY = -1.0;

Expand All @@ -345,6 +350,7 @@ class Pen extends VirtualInput {
moved = false;
movementX = 0;
movementY = 0;
inUse = false;
}

public function reset() {
Expand Down Expand Up @@ -374,14 +380,21 @@ class Pen extends VirtualInput {
this.x = x;
this.y = y;
this.pressure = pressure;

@:privateAccess Input.getMouse().downListener(0, x, y);
}

function upListener(x: Int, y: Int, pressure: Float) {
if (buttonsStarted[0]) { buttonsStarted[0] = false; inUse = true; return; }

buttonsDown[0] = false;
buttonsReleased[0] = true;
this.x = x;
this.y = y;
this.pressure = pressure;

@:privateAccess Input.getMouse().upListener(0, x, y);
inUse = true; // On pen release, additional mouse down & up events are fired at once - filter those out
}

function moveListener(x: Int, y: Int, pressure: Float) {
Expand Down

0 comments on commit 56cc632

Please sign in to comment.