/** * Converts the supplied point from screen coordinates to coordinates * relative to the specified layer. */ public static Point screenToLayer(Layer layer, float x, float y) { Point into = new Point(x, y); return screenToLayer(layer, into, into); }
/** * Transforms a point from one Layer's coordinate system to another's. */ public static Point transform (IPoint p, Layer from, Layer to, Point result) { LayerUtil.layerToScreen(from, p, result); LayerUtil.screenToLayer(to, result, result); return result; }
/** * Converts the supplied point from screen coordinates to coordinates * relative to the specified layer. The results are stored into {@code into} * , which is returned for convenience. */ public static Point screenToLayer(Layer layer, XY point, Point into) { Layer parent = layer.parent(); XY cur = (parent == null) ? point : screenToLayer(parent, point, into); return parentToLayer(layer, cur, into); }
@Override public void onEmit (Pointer.Event e) { Point pt = LayerUtil.screenToLayer(content.layer, e.x(), e.y()); click.text.update(pt.x + ", " + pt.y); } });
/** Gets the item underneath the given event. */ protected MenuItem getHover (Event.XY e) { // manual hit detection Layer hit = layer.hitTest(LayerUtil.screenToLayer(layer, e.x(), e.y())); for (MenuItem item : _items) { if (item.isVisible() && item.layer == hit) { return item; } } return null; }
/** * Returns true if a coordinate on the screen touches a {@link Layer}. Note: if the supplied * layer has no size, this will always return false. */ public static boolean hitTest(Layer layer, float x, float y) { Point point = screenToLayer(layer, x, y); return (point.x() >= 0 && point.y() >= 0 && point.x() <= layer.width() && point.y() <= layer.height()); }
/** * Removes {@code layer} from its current parent and adds it to {@code target}, modifying its * transform in the process so that it stays in the same position on the screen. */ public static void reparent (Layer layer, GroupLayer target) { Point pos = new Point(layer.tx(), layer.ty()); LayerUtil.layerToScreen(layer.parent(), pos, pos); target.add(layer); LayerUtil.screenToLayer(layer.parent(), pos, pos); layer.setTranslation(pos.x, pos.y); }
void dispatch (E event) { // if this interaction has been manually canceled, ignore further dispatch requests if (canceled) return; assert event != null; LayerUtil.screenToLayer(hitLayer, local.set(event.x, event.y), local); this.event = event; try { if (bubble) { Depth depth = Depth.BELOW; for (Layer target = hitLayer; target != null; target = target.parent()) { if (target == capturingLayer) depth = Depth.AT; else if (depth == Depth.AT) depth = Depth.ABOVE; if (captureMode != null && !captureMode.allow(depth)) continue; dispatch(target); // the above dispatch may have caused a capture, in which case capturing layer will have // just been set and we need to update our depth accordingly if (target == capturingLayer) depth = Depth.AT; } } else { dispatch(hitLayer); } } finally { this.event = null; } local.set(0, 0); }
bounds.setLocation(LayerUtil.screenToLayer(elems.layer, bounds.x, bounds.y));