/// <summary> /// params length center,lefttop,righttop,leftbottom,rightbottom /// </summary> /// <param name="rects"></param> public MoveRect(double length, Button button, Rectangle[] rects) { StopMove = false; Length = length; Center = button; for (int i = 0; i < rects.Length; i++) { Rects[i] = new RectMsg(rects[i]); } Rects[1].addRow = -1; Rects[2].addCol = -1; Rects[3].addRow = -1; Rects[3].addCol = -1; }
private void MoveOne(RectMsg rectMsg) { if (rectMsg.actualLeft < 0.0 || rectMsg.actualLeft > Length - rectMsg.width) { rectMsg.addRow = -rectMsg.addRow; } if (rectMsg.actualTop < 0.0 || rectMsg.actualTop > Length - rectMsg.height) { rectMsg.addCol = -rectMsg.addCol; } rectMsg.actualLeft += rectMsg.addRow; rectMsg.actualTop += 0.8 * rectMsg.addCol; rectMsg.rect.Dispatcher.Invoke(new Action(() => { rectMsg.rect.SetValue(Canvas.LeftProperty, rectMsg.actualLeft); rectMsg.rect.SetValue(Canvas.TopProperty, rectMsg.actualTop); })); }
private bool Judgement(RectMsg rect) { double centerLeft, centerTop, centerRight, centerBottom; centerLeft = Center.Dispatcher.Invoke(new Func <double>(() => (double)Center.GetValue(Canvas.LeftProperty))); centerTop = Center.Dispatcher.Invoke(new Func <double>(() => (double)Center.GetValue(Canvas.TopProperty))); centerRight = Center.Dispatcher.Invoke(new Func <double>(() => Center.ActualWidth)) + centerLeft; centerBottom = Center.Dispatcher.Invoke(new Func <double>(() => Center.ActualHeight)) + centerTop; double minLeft = rect.actualLeft > centerLeft ? rect.actualLeft : centerLeft; double minTop = rect.actualTop > centerTop ? rect.actualTop : centerTop; double maxRight = rect.actualLeft + rect.width > centerRight ? centerRight : rect.actualLeft + rect.width; double maxBottom = rect.actualTop > centerBottom ? centerBottom : rect.actualTop + rect.height; return((minLeft < maxRight) && (minTop < maxBottom)); }