From: adam Date: Sun, 4 Apr 2004 04:06:15 +0000 (+0000) Subject: added distanceto() X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=commitdiff_plain;h=a113d1f48d1c3db8aa08c550a925360d1d664b47 added distanceto() darcs-hash:20040404040615-5007d-8f3c22abaa9f3473e8b498b8ef5a198ec2002b1a.gz --- diff --git a/src/org/ibex/Box.java b/src/org/ibex/Box.java index 3892ce9..9489a8b 100644 --- a/src/org/ibex/Box.java +++ b/src/org/ibex/Box.java @@ -423,13 +423,28 @@ public final class Box extends JSScope implements Scheduler.Task { public int localToGlobalY(int y) { return parent == null ? y : parent.globalToLocalY(y + this.y); } public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn { - if (nargs != 1 || !"indexof".equals(method)) return super.callMethod(method, a0, a1, a2, rest, nargs); - Box b = (Box)a0; - if (b.parent != this) - return (redirect == null || redirect == this) ? - N(-1) : - redirect.callMethod(method, a0, a1, a2, rest, nargs); - return N(b.getIndexInParent()); + switch (nargs) { + case 1: { + //#switch(method) + case "indexof": + Box b = (Box)a0; + if (b.parent != this) + return (redirect == null || redirect == this) ? + N(-1) : + redirect.callMethod(method, a0, a1, a2, rest, nargs); + return N(b.getIndexInParent()); + + case "distanceto": + Box b = (Box)a0; + JS ret = new JS(); + ret.put("x", N(b.localToGlobalX(0) - localToGlobalX(0))); + ret.put("y", N(b.localToGlobalY(0) - localToGlobalY(0))); + return ret; + + //#end + } + } + return super.callMethod(method, a0, a1, a2, rest, nargs); } public Enumeration keys() { throw new Error("you cannot apply for..in to a " + this.getClass().getName()); } @@ -453,6 +468,7 @@ public final class Box extends JSScope implements Scheduler.Task { //#switch(name) case "surface": return parent == null ? null : parent.getAndTriggerTraps("surface"); case "indexof": return METHOD; + case "distanceto": return METHOD; case "text": return text; case "path": throw new JSExn("cannot read from the path property"); case "fill": return colorToString(fillcolor);