use of pythagoras.f.Point in project playn by threerings.
the class GroupLayerImpl method hitTest.
public Layer hitTest(GroupLayer self, Point point) {
float x = point.x, y = point.y;
boolean sawInteractiveChild = false;
// we check back to front as children are ordered "lowest" first
for (int ii = children.size() - 1; ii >= 0; ii--) {
L child = children.get(ii);
// ignore non-interactive children
if (!child.interactive())
continue;
// note that we saw an interactive child
sawInteractiveChild = true;
// ignore invisible children
if (!child.visible())
continue;
try {
// transform the point into the child's coordinate system
child.transform().inverseTransform(point.set(x, y), point);
point.x += child.originX();
point.y += child.originY();
Layer l = child.hitTest(point);
if (l != null)
return l;
} catch (NoninvertibleTransformException nte) {
// Degenerate transform means no hit
continue;
}
}
// interactive children have been deactivated or removed
if (!sawInteractiveChild && !((AbstractLayer) self).hasInteractors())
self.setInteractive(false);
return null;
}
use of pythagoras.f.Point in project playn by threerings.
the class MouseImpl method onMouseMove.
protected boolean onMouseMove(MotionEvent.Impl event) {
if (!enabled)
return false;
event.flags().setPreventDefault(false);
if (listener != null) {
listener.onMouseMove(event);
}
GroupLayer root = PlayN.graphics().rootLayer();
if (root.interactive()) {
Point p = new Point(event.x(), event.y());
root.transform().inverseTransform(p, p);
p.x += root.originX();
p.y += root.originY();
AbstractLayer lastHoverLayer = hoverLayer;
hoverLayer = (AbstractLayer) root.hitTest(p);
// handle onMouseDrag if we have an active layer, onMouseMove otherwise
if (activeLayer != null) {
dispatcher.dispatch(activeLayer, LayerListener.class, event, DRAG);
} else if (hoverLayer != null) {
dispatcher.dispatch(hoverLayer, LayerListener.class, event, MOVE);
}
// handle onMouseOut
if (lastHoverLayer != hoverLayer && lastHoverLayer != null) {
dispatcher.dispatch(lastHoverLayer, LayerListener.class, event, OUT);
}
// handle onMouseOver
if (hoverLayer != lastHoverLayer && hoverLayer != null) {
dispatcher.dispatch(hoverLayer, LayerListener.class, event, OVER);
}
}
return event.flags().getPreventDefault();
}
use of pythagoras.f.Point in project playn by threerings.
the class MouseImpl method onMouseDown.
protected boolean onMouseDown(ButtonEvent.Impl event) {
if (!enabled)
return false;
event.flags().setPreventDefault(false);
if (listener != null) {
listener.onMouseDown(event);
}
GroupLayer root = PlayN.graphics().rootLayer();
if (root.interactive()) {
Point p = new Point(event.x(), event.y());
root.transform().inverseTransform(p, p);
p.x += root.originX();
p.y += root.originY();
activeLayer = (AbstractLayer) root.hitTest(p);
if (activeLayer != null) {
dispatcher.dispatch(activeLayer, LayerListener.class, event, DOWN);
}
}
return event.flags().getPreventDefault();
}
use of pythagoras.f.Point in project playn by threerings.
the class PointerImpl method onPointerStart.
protected boolean onPointerStart(Event.Impl event, boolean preventDefault) {
if (!enabled)
return preventDefault;
event.flags().setPreventDefault(preventDefault);
if (listener != null) {
listener.onPointerStart(event);
}
GroupLayer root = PlayN.graphics().rootLayer();
if (root.interactive()) {
Point p = new Point(event.x(), event.y());
root.transform().inverseTransform(p, p);
p.x += root.originX();
p.y += root.originY();
active.layer = (AbstractLayer) root.hitTest(p);
if (active.layer != null) {
event.captureState = active;
dispatcher.dispatch(Listener.class, event, START, CANCEL);
}
}
return event.flags().getPreventDefault();
}
use of pythagoras.f.Point in project playn by threerings.
the class TouchImpl method onTouchStart.
public void onTouchStart(Event.Impl[] touches) {
if (!enabled)
return;
if (listener != null)
listener.onTouchStart(touches);
GroupLayer root = PlayN.graphics().rootLayer();
if (root.interactive()) {
for (Event.Impl event : touches) {
Point p = new Point(event.x(), event.y());
root.transform().inverseTransform(p, p);
p.x += root.originX();
p.y += root.originY();
AbstractLayer hitLayer = (AbstractLayer) root.hitTest(p);
if (hitLayer != null) {
activeLayers.put(event.id(), hitLayer);
dispatcher.dispatch(hitLayer, LayerListener.class, event, START);
}
}
}
}
Aggregations