Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate pointer event coordinates to screen coordinates. #72

Merged
merged 2 commits into from
Sep 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions core/src/main/java/tripleplay/ui/util/XYFlicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import react.Signal;

import playn.scene.Pointer;
import playn.scene.Layer;
import playn.scene.LayerUtil;

/**
* Translates pointer input on a layer into an x, y offset. With a sufficiently large drag delta,
Expand Down Expand Up @@ -65,17 +67,18 @@ public IPoint position () {
_vel.set(0, 0);
_maxDeltaSq = 0;
_origPos.set(_position);
getPosition(iact.event, _start);
getPosition(iact, _start);
_prev.set(_start);
_cur.set(_start);
_prevStamp = 0;
_curStamp = iact.event.time;
_layer = iact.hitLayer;
}

@Override public void onDrag (Pointer.Interaction iact) {
_prev.set(_cur);
_prevStamp = _curStamp;
getPosition(iact.event, _cur);
getPosition(iact, _cur);
_curStamp = iact.event.time;
float dx = _cur.x - _start.x, dy = _cur.y - _start.y;
setPosition(_origPos.x + dx, _origPos.y + dy);
Expand Down Expand Up @@ -153,8 +156,8 @@ public void positionChanged (float x, float y) {
}

/** Translates a pointer event into a position. */
protected void getPosition (Pointer.Event event, Point dest) {
dest.set(-event.x(), -event.y());
protected void getPosition (Pointer.Interaction iact, Point dest) {
dest.set(-iact.local.x, -iact.local.y);
}

/** Sets the current position, clamping the values between min and max. */
Expand All @@ -179,4 +182,5 @@ protected static float applyAccelertion (float v, float a, float dt) {
protected final Point _start = new Point(), _cur = new Point(), _prev = new Point();
protected final Point _max = new Point(), _min = new Point();
protected double _prevStamp, _curStamp;
protected Layer _layer;
}