From: Greg Burri Date: Wed, 13 Jan 2016 12:30:53 +0000 (+0100) Subject: Add a way to pan from the preview. X-Git-Tag: 1.0.11~55 X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=be36fca8c64100b448f268077bcb0726e19f05f7;p=master-thesis.git Add a way to pan from the preview. --- diff --git a/Parasitemia/Parasitemia/GUI/GUI.fs b/Parasitemia/Parasitemia/GUI/GUI.fs index f88bc3c..2132363 100644 --- a/Parasitemia/Parasitemia/GUI/GUI.fs +++ b/Parasitemia/Parasitemia/GUI/GUI.fs @@ -295,7 +295,32 @@ let run (defaultConfig: Config) = let height = srcImg.img.Height * width / srcImg.img.Width imgCtrl.imagePreview.Source <- BitmapSourceConvert.ToBitmapSource(srcImg.img.Resize(width, height, Emgu.CV.CvEnum.Inter.Cubic)) stackPreviews.Children.Add(imgCtrl) |> ignore - imgCtrl.MouseLeftButtonUp.AddHandler(fun obj args -> setCurrentImage (state.SourceImages |> Seq.find (fun srcImg -> (srcImg :> Object) = imgCtrl.Tag))) + + // Zoom to a mouse position into the control 'imgCtrl'. + let zoomTo (mousePos: Point) = + let canvasW = canvasCurrentImage.ActualWidth * currentScale + let canvasH = canvasCurrentImage.ActualHeight * currentScale + let centerX = (mousePos.X - imgCtrl.BorderThickness.Left) / (imgCtrl.ActualWidth - imgCtrl.BorderThickness.Left) * canvasW + let centerY = (mousePos.Y - imgCtrl.BorderThickness.Top) / (imgCtrl.ActualHeight - imgCtrl.BorderThickness.Top) * canvasH + scrollViewCurrentImage.ScrollToHorizontalOffset(centerX - scrollViewCurrentImage.ViewportWidth / 2. + borderCurrentImage.BorderThickness.Left) + scrollViewCurrentImage.ScrollToVerticalOffset(centerY - scrollViewCurrentImage.ViewportHeight / 2. + borderCurrentImage.BorderThickness.Top) + + imgCtrl.MouseLeftButtonDown.AddHandler(fun obj args -> + setCurrentImage (state.SourceImages |> Seq.find (fun srcImg -> (srcImg :> Object) = imgCtrl.Tag)) + imgCtrl.UpdateLayout() + zoomTo (args.GetPosition(imgCtrl)) + imgCtrl.CaptureMouse() |> ignore) + + imgCtrl.MouseMove.AddHandler(fun obj args -> + if imgCtrl.IsMouseCaptured + then + zoomTo (args.GetPosition(imgCtrl))) + + imgCtrl.MouseLeftButtonUp.AddHandler(fun obj args -> + if imgCtrl.IsMouseCaptured + then + imgCtrl.ReleaseMouseCapture()) + let updatePreviews () = stackPreviews.Children.Clear ()