public void TestGetTouchPointerStyle() { var sourceImage = new CodedImage { Size = new Size(200, 150) }; var cropController = new ImageCropController(new ImageCropManipulator(sourceImage)); var visualZoomedCropController = new VisualZoomCropController(cropController, new Size(60, 50)); visualZoomedCropController.ZoomPercent = 100; visualZoomedCropController.CropKind = ImageCropper.CropKind.Rectangle; visualZoomedCropController.SetCropRectForTest(new Rectangle(20, 10, 160, 130)); visualZoomedCropController.ZoomPercent = 50; Assert.AreEqual(new Rectangle(10, 5, 80, 65), visualZoomedCropController.CropRect); AssertGetTouchPointerStyle(visualZoomedCropController, VisualController.TouchPointerStyle.Shift, false, new Point(0, 0), new Point(99, 74)); visualZoomedCropController.OnTouched(new Point(0, 0)); visualZoomedCropController.OnShift(new Point(-20, -10)); // Shift on distance (-20, -10) visualZoomedCropController.OnUntouched(new Point(0, 0)); Assert.AreEqual(new Rectangle(20, 10, 60, 50), visualZoomedCropController.VisualImageFrame); AssertGetTouchPointerStyle(visualZoomedCropController, VisualController.TouchPointerStyle.ResizeAll, false, new Point(0, 0), new Point(20, 30)); AssertGetTouchPointerStyle(visualZoomedCropController, VisualController.TouchPointerStyle.ResizeLeftTop_RightBottom, true, new Point(-10, -5), new Point(70, 60)); AssertGetTouchPointerStyle(visualZoomedCropController, VisualController.TouchPointerStyle.ResizeRightTop_LeftBottom, true, new Point(70, -5), new Point(-10, 60)); AssertGetTouchPointerStyle(visualZoomedCropController, VisualController.TouchPointerStyle.ResizeHorizontal, true, new Point(-10, 27), new Point(70, 27)); AssertGetTouchPointerStyle(visualZoomedCropController, VisualController.TouchPointerStyle.ResizeVertical, true, new Point(30, -5), new Point(30, 60)); }
public void TestShift() { var sourceImage = new CodedImage { Size = new Size(200, 150) }; var cropController = new ImageCropController(new ImageCropManipulator(sourceImage)); var visualZoomedCropController = new VisualZoomCropController(cropController, new Size(60, 50)); using (visualZoomedCropController.SuspendUpdateVisualImage()) { visualZoomedCropController.ZoomPercent = 50; visualZoomedCropController.CropKind = ImageCropper.CropKind.Rectangle; visualZoomedCropController.SetCropRectForTest(new Rectangle(0, 0, 100, 75)); } visualZoomedCropController.OnTouched(new Point(20, 20)); visualZoomedCropController.OnShift(new Point(0, 10)); // Shift on distance (-20, -10) visualZoomedCropController.OnUntouched(new Point(0, 10)); AssertShift(visualZoomedCropController, new Rectangle(10, 5, 50, 40), new Point(-10, -5), new Size(5, 10), new Rectangle(15, 15, 45, 30)); // Left-top AssertShift(visualZoomedCropController, new Rectangle(10, 5, 50, 40), new Point(40, -5), new Size(5, 10), new Rectangle(10, 15, 55, 30)); // Right-top AssertShift(visualZoomedCropController, new Rectangle(10, 5, 50, 40), new Point(-10, 35), new Size(5, 10), new Rectangle(15, 5, 45, 50)); // Left-bottom AssertShift(visualZoomedCropController, new Rectangle(10, 5, 50, 40), new Point(40, 35), new Size(5, 10), new Rectangle(10, 5, 55, 50)); // Right-bottom AssertShift(visualZoomedCropController, new Rectangle(10, 5, 50, 40), new Point(-10, 15), new Size(5, 10), new Rectangle(15, 5, 45, 40)); // Left AssertShift(visualZoomedCropController, new Rectangle(10, 5, 50, 40), new Point(15, -5), new Size(5, 10), new Rectangle(10, 15, 50, 30)); // Top AssertShift(visualZoomedCropController, new Rectangle(10, 5, 50, 40), new Point(40, 15), new Size(5, 10), new Rectangle(10, 5, 55, 40)); // Right AssertShift(visualZoomedCropController, new Rectangle(10, 5, 50, 40), new Point(15, 35), new Size(5, 10), new Rectangle(10, 5, 50, 50)); // Bottom }
void AssertShift(VisualZoomCropController visualZoomCropController, Rectangle initialCropRect, Point initialPoint, Size shiftSize, Rectangle expectedCropRect) { visualZoomCropController.SetCropRectForTest(initialCropRect); visualZoomCropController.OnTouched(initialPoint); var newPoint = new Point(initialPoint.X + shiftSize.Width, initialPoint.Y + shiftSize.Height); visualZoomCropController.OnShift(newPoint); Assert.AreEqual(expectedCropRect, visualZoomCropController.CropRect); visualZoomCropController.OnUntouched(newPoint); // To prevent further unexpected shifting }