public static IntVector2 GetVectorFromCase(DirectionCase dc) { switch (dc) { #if VECTOR_CLOCKWISE || VECTOR_TO_RIGHT || VECTOR_TO_DOWN || VECTOR_TO_MINUS_ONE case DirectionCase.RIGHT_OR_ONE: #endif #if VECTOR_COUNTERCLOCKWISE || VECTOR_TO_RIGHT || VECTOR_TO_ONE || VECTOR_TO_UP case DirectionCase.DOWN_OR_RIGHT: #endif case DirectionCase.RIGHT: return(IntVector2.RIGHT); #if VECTOR_CLOCKWISE || VECTOR_TO_ONE || VECTOR_TO_RIGHT || VECTOR_TO_DOWN case DirectionCase.ONE_OR_UP: #endif #if VECTOR_COUNTERCLOCKWISE || VECTOR_TO_ONE || VECTOR_TO_UP || VECTOR_TO_LEFT case DirectionCase.RIGHT_OR_ONE: #endif case DirectionCase.ONE: return(IntVector2.ONE); #if VECTOR_CLOCKWISE || VECTOR_TO_UP || VECTOR_TO_ONE || VECTOR_TO_RIGHT case DirectionCase.UP_OR_LEFT: #endif #if VECTOR_COUNTERCLOCKWISE || VECTOR_TO_UP || VECTOR_TO_LEFT || VECTOR_TO_MINUS_ONE case DirectionCase.ONE_OR_UP: #endif case DirectionCase.UP: return(IntVector2.UP); #if VECTOR_CLOCKWISE || VECTOR_TO_LEFT || VECTOR_TO_UP || VECTOR_TO_ONE case DirectionCase.LEFT_OR_MINUS_ONE: #endif #if VECTOR_COUNTERCLOCKWISE || VECTOR_TO_LEFT || VECTOR_TO_MINUS_ONE || VECTOR_TO_DOWN case DirectionCase.UP_OR_LEFT: #endif case DirectionCase.LEFT: return(-IntVector2.RIGHT); #if VECTOR_CLOCKWISE || VECTOR_TO_MINUS_ONE || VECTOR_TO_LEFT || VECTOR_TO_UP case DirectionCase.MINUS_ONE_OR_DOWN: #endif #if VECTOR_COUNTERCLOCKWISE || VECTOR_TO_MINUS_ONE || VECTOR_TO_DOWN || VECTOR_TO_RIGHT case DirectionCase.LEFT_OR_MINUS_ONE: #endif case DirectionCase.MINUS_ONE: return(-IntVector2.ONE); #if VECTOR_CLOCKWISE || VECTOR_TO_DOWN || VECTOR_TO_MINUS_ONE || VECTOR_TO_LEFT case DirectionCase.DOWN_OR_RIGHT: #endif #if VECTOR_COUNTERCLOCKWISE || VECTOR_TO_DOWN || VECTOR_TO_RIGHT || VECTOR_TO_ONE case DirectionCase.MINUS_ONE_OR_DOWN: #endif case DirectionCase.DOWN: return(-IntVector2.UP); default: case DirectionCase.ZERO: return(_ZERO); } }
public void ResizeMe(MouseEventArgs e, DirectionCase directionCase) { var startx1 = (Annotation.X - Annotation.Width / 2) * parent.img.ActualWidth; var starty1 = (Annotation.Y - Annotation.Height / 2) * parent.img.ActualHeight; var startx2 = (Annotation.X + Annotation.Width / 2) * parent.img.ActualWidth; var starty2 = (Annotation.Y + Annotation.Height / 2) * parent.img.ActualHeight; var timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromMilliseconds(11); timer.Tick += delegate { if (Mouse.LeftButton == MouseButtonState.Released) { timer.Stop(); } var nowPt = Mouse.GetPosition(parent.img); var nowx = nowPt.X; var nowy = nowPt.Y; double newx1 = 0, newx2 = 0, newy1 = 0, newy2 = 0; switch (directionCase) { case DirectionCase.LeftTop: newx1 = Math.Min(startx2, nowx); newx2 = Math.Max(startx2, nowx); newy1 = Math.Min(starty2, nowy); newy2 = Math.Max(starty2, nowy); break; case DirectionCase.LeftCenter: newx1 = Math.Min(startx2, nowx); newx2 = Math.Max(startx2, nowx); newy1 = starty1; newy2 = starty2; break; case DirectionCase.LeftBottom: newx1 = Math.Min(startx2, nowx); newx2 = Math.Max(startx2, nowx); newy1 = Math.Min(starty1, nowy); newy2 = Math.Max(starty1, nowy); break; case DirectionCase.CenterTop: newx1 = startx1; newx2 = startx2; newy1 = Math.Min(starty2, nowy); newy2 = Math.Max(starty2, nowy); break; case DirectionCase.CenterBottom: newx1 = startx1; newx2 = startx2; newy1 = Math.Min(starty1, nowy); newy2 = Math.Max(starty1, nowy); break; case DirectionCase.RightTop: newx1 = Math.Min(startx1, nowx); newx2 = Math.Max(startx1, nowx); newy1 = Math.Min(starty2, nowy); newy2 = Math.Max(starty2, nowy); break; case DirectionCase.RightCenter: newx1 = Math.Min(startx1, nowx); newx2 = Math.Max(startx1, nowx); newy1 = starty1; newy2 = starty2; break; case DirectionCase.RightBottom: newx1 = Math.Min(startx1, nowx); newx2 = Math.Max(startx1, nowx); newy1 = Math.Min(starty1, nowy); newy2 = Math.Max(starty1, nowy); break; } newx1 = Math.Min(parent.img.ActualWidth, Math.Max(0, newx1)); newx2 = Math.Min(parent.img.ActualWidth, Math.Max(0, newx2)); newy1 = Math.Min(parent.img.ActualHeight, Math.Max(0, newy1)); newy2 = Math.Min(parent.img.ActualHeight, Math.Max(0, newy2)); Annotation.X = newx1 / parent.img.ActualWidth + Annotation.Width / 2; Annotation.Y = newy1 / parent.img.ActualHeight + Annotation.Height / 2; Annotation.Width = Math.Max(3, newx2 - newx1) / parent.img.ActualWidth; Annotation.Height = Math.Max(3, newy2 - newy1) / parent.img.ActualHeight; UpdatePos(); }; timer.Start(); }