public static bool TryGetPos(TjsValue pos, out Point p) { TjsArray xy = pos as TjsArray; if (xy != null && xy.val.Count == 2) { TjsNumber x = xy.val[0] as TjsNumber; TjsNumber y = xy.val[1] as TjsNumber; if (x != null && y != null) { p = new Point((int)x.val, (int)y.val); return(true); } else { Debug.Assert(false, "invalid element in pos struct"); } } else { Debug.Assert(false, "invalid pos struct"); } p = Point.Empty; return(false); }
public static TjsArray ScaleButton(TjsDict dict, string name, double scaleX, double scaleY) { TjsValue v = null; if (dict.val.TryGetValue(name, out v)) { // 按钮上多记录了一个是否显示: x, y, shown TjsArray xys = v as TjsArray; if (xys != null && xys.val.Count == 3) { TjsNumber x = xys.val[0] as TjsNumber; TjsNumber y = xys.val[1] as TjsNumber; TjsNumber s = xys.val[2] as TjsNumber; if (x != null && y != null && s != null) { TjsArray xysnew = CreatePos((int)(x.val * scaleX), (int)(y.val * scaleY)); xysnew.val.Add(new TjsNumber(s.val)); dict.val[name] = xysnew; return(xysnew); } else { Debug.Assert(false, "invalid element in button struct"); } } else { Debug.Assert(false, "invalid button struct"); } } return(null); }