/// <summary> /// 参数构造器 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="cursor"></param> /// <param name="refPoint"></param> public AnchorPoint(double x, double y, AnchorPointType anchorPointType, Point[] refPoints) { this.X = x; this.Y = y; this.AnchorPointType = anchorPointType; this.Width = 8; this.Height = 8; this.Key = Guid.NewGuid().ToString(); this.RefPoint = refPoints; switch (this.AnchorPointType) { case AnchorPointType.NS: this.Cursor = Cursors.SizeNS; break; case WPFCanvas.AnchorPointType.WE: this.Cursor = Cursors.SizeWE; break; case WPFCanvas.AnchorPointType.NE: case WPFCanvas.AnchorPointType.SW: this.Cursor = Cursors.SizeNESW; break; case WPFCanvas.AnchorPointType.NW: case WPFCanvas.AnchorPointType.SE: this.Cursor = Cursors.SizeNWSE; break; } }
public static void AnchorEx(ModelElement rect, AnchorPointType type, Vector2 offset, Vector2 p, Vector2 psize) { var pivot = Anchors[(int)type]; float ox = (p.x - 1) * psize.x; //原点x float oy = (p.y - 1) * psize.y; //原点y float tx = ox + pivot.x * psize.x; //锚点x float ty = oy + pivot.y * psize.y; //锚点y offset.x += tx; //偏移点x offset.y += ty; //偏移点y rect.data.localPosition = new Vector3(offset.x, offset.y, 0); }
public static void AlignmentEx(ModelElement rect, AnchorPointType type, Vector2 offset, Vector2 p, Vector2 psize) { Vector2 pivot = Anchors[(int)type]; float ox = (p.x - 1) * psize.x; //原点x float oy = (p.y - 1) * psize.y; //原点y float tx = ox + pivot.x * psize.x; //锚点x float ty = oy + pivot.y * psize.y; //锚点y offset.x += tx; //偏移点x offset.y += ty; //偏移点y switch (type) { case AnchorPointType.Left: offset.x += rect.data.sizeDelta.x * 0.5f; break; case AnchorPointType.Right: offset.x -= rect.data.sizeDelta.x * 0.5f; break; case AnchorPointType.Top: offset.y -= rect.data.sizeDelta.y * 0.5f; break; case AnchorPointType.Down: offset.y += rect.data.sizeDelta.y * 0.5f; break; case AnchorPointType.LeftDown: offset.x += rect.data.sizeDelta.x * 0.5f; offset.y += rect.data.sizeDelta.y * 0.5f; break; case AnchorPointType.LeftTop: offset.x += rect.data.sizeDelta.x * 0.5f; offset.y -= rect.data.sizeDelta.y * 0.5f; break; case AnchorPointType.RightDown: offset.x -= rect.data.sizeDelta.x * 0.5f; offset.y += rect.data.sizeDelta.y * 0.5f; break; case AnchorPointType.RightTop: offset.x -= rect.data.sizeDelta.x * 0.5f; offset.y -= rect.data.sizeDelta.y * 0.5f; break; } rect.data.localPosition = new Vector3(offset.x, offset.y, 0); }
public static void AlignmentEx(RectTransform rect, AnchorPointType type, Vector2 offset, Vector2 p, Vector2 psize) { Vector2 pivot = Anchors[(int)type]; float ox = (p.x - 1) * psize.x; //原点x float oy = (p.y - 1) * psize.y; //原点y float tx = ox + pivot.x * psize.x; //锚点x float ty = oy + pivot.y * psize.y; //锚点y float x = offset.x + tx; float y = offset.y + ty; switch (type) { case AnchorPointType.Left: x += rect.sizeDelta.x * 0.5f; break; case AnchorPointType.Right: x -= rect.sizeDelta.x * 0.5f; break; case AnchorPointType.Top: y -= rect.sizeDelta.y * 0.5f; break; case AnchorPointType.Down: y += rect.sizeDelta.y * 0.5f; break; case AnchorPointType.LeftDown: x += rect.sizeDelta.x * 0.5f; y += rect.sizeDelta.y * 0.5f; break; case AnchorPointType.LeftTop: x += rect.sizeDelta.x * 0.5f; y -= rect.sizeDelta.y * 0.5f; break; case AnchorPointType.RightDown: x -= rect.sizeDelta.x * 0.5f; y += rect.sizeDelta.y * 0.5f; break; case AnchorPointType.RightTop: x -= rect.sizeDelta.x * 0.5f; y -= rect.sizeDelta.y * 0.5f; break; } rect.localPosition = new Vector3(x, y, 0); }
public static void AnchorEx(UIElement script, AnchorPointType type, Vector2 offset, Vector2 p, Vector2 psize) { Vector2 pivot = Anchors[(int)type]; float x = psize.x; float y = psize.y; float px = p.x; float py = p.y; float lx = x * -px; float dy = y * -py; float tx = lx + pivot.x * psize.x; //锚点x float ty = dy + pivot.y * psize.y; //锚点y offset.x += tx; //偏移点x offset.y += ty; //偏移点y script.transform.localPosition = new Vector3(offset.x, offset.y, 0); }
/// <summary> /// 参数构造器 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="cursor"></param> /// <param name="refPoint"></param> public AnchorPoint(double x,double y,AnchorPointType anchorPointType,Point[] refPoints) { this.X = x; this.Y = y; this.AnchorPointType = anchorPointType; this.Width = 8; this.Height = 8; this.Key = Guid.NewGuid().ToString(); this.RefPoint = refPoints; switch (this.AnchorPointType) { case AnchorPointType.NS: this.Cursor = Cursors.SizeNS; break; case WPFCanvas.AnchorPointType.WE: this.Cursor = Cursors.SizeWE; break; case WPFCanvas.AnchorPointType.NE: case WPFCanvas.AnchorPointType.SW: this.Cursor = Cursors.SizeNESW; break; case WPFCanvas.AnchorPointType.NW: case WPFCanvas.AnchorPointType.SE: this.Cursor = Cursors.SizeNWSE; break; } }
public static void AlignmentEx(UIElement script, AnchorPointType type, Vector2 offset, Vector2 p, Vector2 psize) { Vector2 pivot = Anchors[(int)type]; float ax = psize.x; float ay = psize.y; float apx = p.x; float apy = p.y; float alx = ax * -apx; float ady = ay * -apy; //float aox = ax * apx;//原点x //float aoy = ay * apy;//原点y float x = script.SizeDelta.x; float y = script.SizeDelta.y; float px = script.Pivot.x; float py = script.Pivot.y; float lx = x * -px; float dy = y * -py; //float ox = x * px;//原点x //float oy = y * py;//原点y switch (type) { case AnchorPointType.Left: x = alx - lx; y = (ady + ay * 0.5f) - (dy + y * 0.5f); break; case AnchorPointType.Right: x = (ax + alx) - (x + lx); y = (ady + ay * 0.5f) - (dy + y * 0.5f); break; case AnchorPointType.Top: x = (alx + ax * 0.5f) - (lx + x * 0.5f); y = (ay + ady) - (y + dy); break; case AnchorPointType.Down: x = (alx + ax * 0.5f) - (lx + x * 0.5f); y = ady - dy; break; case AnchorPointType.LeftDown: x = alx - lx; y = ady - dy; break; case AnchorPointType.LeftTop: x = alx - lx; y = (ay + ady) - (y + dy); break; case AnchorPointType.RightDown: x = (ax + alx) - (x + lx); y = ady - dy; break; case AnchorPointType.RightTop: x = (ax + alx) - (x + lx); y = (ay + ady) - (y + dy); break; default: x = (alx + ax * 0.5f) - (lx + x * 0.5f); y = (ady + ay * 0.5f) - (dy + y * 0.5f); break; } x += offset.x; y += offset.y; script.transform.localPosition = new Vector3(x, y, 0); }
/// <summary> /// 带参数的构造器 /// </summary> /// <param name="X">X</param> /// <param name="y">Y</param> /// <param name="cursor">鼠标</param> public AnchorPoint(double x, double y, AnchorPointType anchorPointType) : this(x, y, anchorPointType, new Point[0]) { }
/// <summary> /// 带参数的构造器 /// </summary> /// <param name="X">X</param> /// <param name="y">Y</param> /// <param name="cursor">鼠标</param> public AnchorPoint(double x, double y, AnchorPointType anchorPointType) : this(x,y,anchorPointType,new Point[0]) { }