Improve readability of highlighted RBCs.
[master-thesis.git] / Parasitemia / Parasitemia / GUI / GUI.fs
1 module Parasitemia.GUI.Main
2
3 open System
4 open System.IO
5 open System.Linq
6 open System.Windows
7 open System.Windows.Media
8 open System.Windows.Markup
9 open System.Windows.Shapes
10 open System.Windows.Controls
11 open System.Diagnostics
12 open Microsoft.Win32 // For the common dialogs.
13
14 open Emgu.CV.WPF
15
16 open Config
17 open Types
18
19 let run (defaultConfig: Config) =
20 let app = new Application()
21 let mainWindow = Views.MainWindow()
22 let ctrl (name: string): 'a =
23 mainWindow.Root.FindName(name) :?> 'a
24
25 let colorRBCHealthy = Brushes.YellowGreen
26 let colorRBCInfected = Brushes.Red
27
28 let state = State.State()
29 let mutable currentScale = 1.
30 let mutable displayHealthy = false
31
32 let menuExit: MenuItem = ctrl "menuExit"
33 let menuSaveFile: MenuItem = ctrl "menuSave"
34 let menuLoadFile: MenuItem = ctrl "menuOpen"
35 let menuNewFile: MenuItem = ctrl "menuNew"
36 let menuAddSourceImage: MenuItem = ctrl "menuAddSourceImage"
37 let menuStartAnalysis: MenuItem = ctrl "menuStartAnalysis"
38 let menuHightlightRBC: MenuItem = ctrl "menuHightlightRBC"
39
40 let txtPatient: TextBox = ctrl "txtPatient"
41 let txtGlobalParasitemia: TextBox = ctrl "txtGlobalParasitemia"
42
43 let stackPreviews: StackPanel = ctrl "stackPreviews"
44
45 let scrollViewCurrentImage: ScrollViewer = ctrl "scrollViewCurrentImage"
46 let borderCurrentImage: Border = ctrl "borderCurrentImage"
47 let canvasCurrentImage: Canvas = ctrl "canvasCurrentImage"
48 let txtImageInformation: TextBlock = ctrl "txtImageInformation"
49
50 let scrollRBC: ScrollViewer = ctrl "scrollRBC"
51 let stackRBC: StackPanel = ctrl "stackRBC"
52
53 // Initializations.
54 menuHightlightRBC.IsChecked <- displayHealthy
55
56 // Utils.
57 let extractRBCPreview (img: Emgu.CV.Image<Emgu.CV.Structure.Bgr, byte>) (rbc: RBC) : Emgu.CV.Image<Emgu.CV.Structure.Bgr, byte> =
58 let rbcWidth = rbc.size.Width
59 let rbcHeight = rbc.size.Height
60 let x = rbc.center.X - rbcWidth / 2. |> Utils.roundInt
61 let y = rbc.center.Y - rbcHeight / 2. |> Utils.roundInt
62 let w = Utils.roundInt rbcWidth
63 let h = Utils.roundInt rbcHeight
64 //Utils.dprintfn "w: %A, h: %A, cx: %A, cy: %A, img.w: %A, img.h: %A" w h x y img.Width img.Height
65 img.GetSubRect(System.Drawing.Rectangle(System.Drawing.Point((if x < 0 then 0 else x), (if y < 0 then 0 else y)),
66 System.Drawing.Size((if x + w >= img.Width then img.Width - x else w),
67 (if y + h >= img.Height then img.Height - y else h))))
68
69 let setRBCFrameStyle (rbc: RBC) (frame: Views.RBCFrame) =
70 frame.Opacity <- if displayHealthy || rbc.setManually || rbc.infected then 1. else 0.
71 let color = if rbc.infected then colorRBCInfected else colorRBCHealthy
72 frame.manuallyAdded.Visibility <- if rbc.setManually then Visibility.Visible else Visibility.Hidden
73 frame.manuallyAdded.Fill <- color
74 frame.border.Stroke <- color
75
76 let RBCFrameFromExisting (rbc: RBC) (frame: Views.RBCFrame) : Views.RBCFrame =
77 frame.Visibility <- Visibility.Visible
78 frame.Height <- rbc.size.Height
79 frame.Width <- rbc.size.Width
80 frame.Tag <- rbc
81 setRBCFrameStyle rbc frame
82 frame.border.StrokeThickness <- 1.
83 frame.txtRBCNumber.Text <- rbc.num.ToString()
84 frame
85
86 let highlightRBCFrame (frame: Views.RBCFrame) (highlight: bool) =
87 let rbc = frame.Tag :?> RBC
88 if highlight
89 then
90 frame.border.StrokeThickness <- 3.
91 if not rbc.infected && not rbc.setManually && not displayHealthy then frame.Opacity <- 1.
92 else
93 frame.border.StrokeThickness <- 1.
94 if not rbc.infected && not rbc.setManually && not displayHealthy then frame.Opacity <- 0.
95
96 let zoomToRBC (rbc: RBC) =
97 scrollViewCurrentImage.ScrollToHorizontalOffset(rbc.center.X * currentScale - scrollViewCurrentImage.ViewportWidth / 2. + borderCurrentImage.BorderThickness.Left)
98 scrollViewCurrentImage.ScrollToVerticalOffset(rbc.center.Y * currentScale - scrollViewCurrentImage.ViewportHeight / 2. + borderCurrentImage.BorderThickness.Top)
99
100 let parasitemiaText (nbTotal: int, nbInfected: int) : string =
101 if nbTotal = 0
102 then
103 ""
104 else
105 let percent = 100. * (float nbInfected) / (float nbTotal)
106 sprintf "%.1f %% (%d / %d)" percent nbInfected nbTotal
107
108 let updateCurrentImageInformation () =
109 match state.CurrentImage with
110 | Some srcImg ->
111 let parasitemiaStr = parasitemiaText (state.ImageParasitemia srcImg)
112 txtImageInformation.Inlines.Clear()
113 txtImageInformation.Inlines.Add(Documents.Run("Parasitemia: ", FontWeight = FontWeights.Bold))
114 txtImageInformation.Inlines.Add(parasitemiaStr)
115 txtImageInformation.Inlines.Add(Documents.LineBreak())
116
117 txtImageInformation.Inlines.Add(Documents.Run("Average erytrocyte diameter: ", FontWeight = FontWeights.Bold))
118 txtImageInformation.Inlines.Add(Documents.Run(string (Utils.roundInt <| 2. * srcImg.rbcRadius)))
119 txtImageInformation.Inlines.Add(Documents.Run(" px"))
120 txtImageInformation.Inlines.Add(Documents.LineBreak())
121
122 txtImageInformation.Inlines.Add(Documents.Run("Last analysis: ", FontWeight = FontWeights.Bold))
123 txtImageInformation.Inlines.Add(Documents.Run(if srcImg.dateLastAnalysis.Ticks = 0L then "<Never>" else srcImg.dateLastAnalysis.ToLocalTime().ToString()))
124 | _ -> ()
125
126 let updateGlobalParasitemia () =
127 txtGlobalParasitemia.Text <- parasitemiaText state.GlobalParasitemia
128
129 let updateViewportPreview () =
130 for preview in stackPreviews.Children |> Seq.cast<Views.ImageSourcePreview> do
131 let srcImg = preview.Tag :?> SourceImage
132 if Some srcImg = state.CurrentImage then
133 preview.viewport.Visibility <- Visibility.Visible
134
135 let canvasWidth = canvasCurrentImage.ActualWidth * currentScale
136 let canvasHeight = canvasCurrentImage.ActualHeight * currentScale
137 let previewWidth = (preview.ActualWidth - preview.BorderThickness.Left - preview.BorderThickness.Right)
138 let previewHeight = (preview.ActualHeight - preview.BorderThickness.Top - preview.BorderThickness.Bottom)
139
140 let marginLeft = previewWidth * (scrollViewCurrentImage.HorizontalOffset - borderCurrentImage.BorderThickness.Left) / canvasWidth - 2.
141 let marginRight = previewWidth * (canvasWidth - (scrollViewCurrentImage.HorizontalOffset - borderCurrentImage.BorderThickness.Right) - scrollViewCurrentImage.ViewportWidth) / canvasWidth - 2.
142 let marginTop = previewHeight * (scrollViewCurrentImage.VerticalOffset - borderCurrentImage.BorderThickness.Top) / canvasHeight - 2.
143 let marginBottom = previewHeight * (canvasHeight - (scrollViewCurrentImage.VerticalOffset - borderCurrentImage.BorderThickness.Bottom) - scrollViewCurrentImage.ViewportHeight) / canvasHeight - 2.
144
145 preview.viewport.Margin <-
146 Thickness(
147 marginLeft,
148 marginTop,
149 marginRight,
150 marginBottom)
151 else
152 preview.viewport.Visibility <- Visibility.Hidden
153
154 let rec setAsInfected (rbc: RBC) (infected: bool) =
155 state.SetAsInfected rbc infected
156 canvasCurrentImage.Children
157 |> Seq.cast<Views.RBCFrame>
158 |> Seq.iter
159 (fun frame ->
160 if (frame.Tag :?> RBC) = rbc
161 then
162 setRBCFrameStyle rbc frame)
163 updateRBCFramesPreview ()
164 updateCurrentImageInformation ()
165 updateGlobalParasitemia ()
166
167 and RBCFrame (rbc: RBC) : Views.RBCFrame =
168 let frame = RBCFrameFromExisting rbc (Views.RBCFrame())
169 frame.SetValue(Panel.ZIndexProperty, Int32.MaxValue - rbc.num) // To be sure the
170 frame.menuRBCSetAsHealthy.Click.AddHandler(fun obj args -> setAsInfected (frame.Tag :?> RBC) false)
171 frame.menuRBCSetAsInfected.Click.AddHandler(fun obj args -> setAsInfected (frame.Tag :?> RBC) true)
172 frame.ContextMenuOpening.AddHandler(
173 fun obj args ->
174 if (frame.Tag :?> RBC).infected
175 then
176 frame.menuRBCSetAsHealthy.Visibility <- Visibility.Visible
177 frame.menuRBCSetAsInfected.Visibility <- Visibility.Collapsed
178 else
179 frame.menuRBCSetAsHealthy.Visibility <- Visibility.Collapsed
180 frame.menuRBCSetAsInfected.Visibility <- Visibility.Visible)
181
182 frame.ContextMenuClosing.AddHandler(fun obj args -> if not frame.IsMouseOver then highlightRBCFrame frame false )
183 frame.MouseEnter.AddHandler(fun obj args -> highlightRBCFrame frame true)
184 frame.MouseLeave.AddHandler(fun obj args -> if not frame.grid.ContextMenu.IsOpen then highlightRBCFrame frame false)
185 frame
186
187 and updateRBCFramesPreview () =
188 match state.CurrentImage with
189 | Some srcImg ->
190 let mutable currentPreview = 0
191 for rbc in srcImg.rbcs |> List.filter (fun rbc -> displayHealthy || rbc.infected) do
192 let previewInfected =
193 if currentPreview < stackRBC.Children.Count
194 then
195 RBCFrameFromExisting rbc (stackRBC.Children.[currentPreview] :?> Views.RBCFrame)
196 else
197 let f = RBCFrame rbc
198 f.MouseLeftButtonUp.AddHandler(fun obj args -> zoomToRBC (f.Tag :?> RBC))
199 stackRBC.Children.Add(f) |> ignore
200 f
201
202 currentPreview <- currentPreview + 1
203
204 previewInfected.Height <- stackRBC.ActualHeight
205 previewInfected.Width <- stackRBC.ActualHeight * rbc.size.Width / rbc.size.Height
206 previewInfected.border.Fill <- ImageBrush(BitmapSourceConvert.ToBitmapSource(extractRBCPreview srcImg.img rbc))
207
208 stackRBC.Children.RemoveRange(currentPreview, stackRBC.Children.Count - currentPreview)
209 | _ -> ()
210
211 updateViewportPreview ()
212
213 let updateRBCFramesCurrent () =
214 match state.CurrentImage with
215 | Some srcImg ->
216 let mutable currentCanvas = 0
217 for rbc in srcImg.rbcs do
218 let frame =
219 if currentCanvas < canvasCurrentImage.Children.Count
220 then
221 RBCFrameFromExisting rbc (canvasCurrentImage.Children.[currentCanvas] :?> Views.RBCFrame)
222 else
223 let f = RBCFrame rbc
224 f.Root.Opacity <- 0.7
225 canvasCurrentImage.Children.Add(f) |> ignore
226 f
227
228 currentCanvas <- currentCanvas + 1
229
230 Canvas.SetLeft(frame, rbc.center.X - rbc.size.Width / 2.)
231 Canvas.SetTop(frame, rbc.center.Y - rbc.size.Height / 2.)
232
233 for i in currentCanvas .. canvasCurrentImage.Children.Count - 1 do
234 canvasCurrentImage.Children.[i].Visibility <- Visibility.Hidden
235 | _ -> ()
236
237 let saveCurrentDocument () =
238 if state.FilePath = ""
239 then
240 let dialog = SaveFileDialog(AddExtension = true, DefaultExt = PiaZ.extension, Filter = PiaZ.filter);
241 let res = dialog.ShowDialog()
242 if res.HasValue && res.Value
243 then
244 state.FilePath <- dialog.FileName
245 state.Save()
246 else
247 state.Save()
248
249 // Ask the use to save the current document if neccessary.
250 let askSaveCurrent () =
251 if state.AlteredSinceLastSave
252 then
253 match MessageBox.Show("Would you like to save the current document?", "Saving the current document", MessageBoxButton.YesNo, MessageBoxImage.Question) with
254 | MessageBoxResult.Yes -> saveCurrentDocument ()
255 | _ -> ()
256
257 let updateCurrentImage () =
258 match state.CurrentImage with
259 | Some srcImg ->
260 // Highlight the preview.
261 stackPreviews.Children
262 |> Seq.cast<Views.ImageSourcePreview>
263 |> Seq.iter (fun preview -> preview.border.BorderThickness <- Thickness(if preview.Tag = (srcImg :> Object) then 3. else 0.))
264
265 canvasCurrentImage.Height <- float srcImg.img.Height
266 canvasCurrentImage.Width <- float srcImg.img.Width
267 canvasCurrentImage.Background <- ImageBrush(BitmapSourceConvert.ToBitmapSource(srcImg.img))
268
269 updateRBCFramesCurrent ()
270 updateRBCFramesPreview ()
271 updateCurrentImageInformation ()
272 | None ->
273 stackRBC.Children.Clear()
274 canvasCurrentImage.Children.Clear()
275 canvasCurrentImage.Background <- Brushes.Black
276
277 let setCurrentImage (srcImg: SourceImage) =
278 if state.CurrentImage.IsNone || state.CurrentImage.Value <> srcImg
279 then
280 state.CurrentImage <- Some srcImg
281 updateCurrentImage ()
282
283 let addPreview (srcImg: SourceImage) =
284 let imgCtrl = Views.ImageSourcePreview(Margin = Thickness(3.))
285
286 imgCtrl.menuRemoveImage.Click.AddHandler(fun obj args ->
287 stackPreviews.Children.Remove(imgCtrl)
288 let srcImg = imgCtrl.Tag :?> SourceImage
289 let currentRemoved = Some srcImg = state.CurrentImage
290 state.RemoveSourceImage srcImg
291 if currentRemoved
292 then
293 updateCurrentImage()
294 stackPreviews.Children |> Seq.cast<Views.ImageSourcePreview> |> Seq.iter (fun imgPreview -> imgPreview.txtImageNumber.Text <- (imgPreview.Tag :?> SourceImage).num.ToString()))
295
296 imgCtrl.Tag <- srcImg
297 imgCtrl.txtImageNumber.Text <- srcImg.num.ToString()
298 let width = 200
299 let height = srcImg.img.Height * width / srcImg.img.Width
300 imgCtrl.imagePreview.Source <- BitmapSourceConvert.ToBitmapSource(srcImg.img.Resize(width, height, Emgu.CV.CvEnum.Inter.Cubic))
301 stackPreviews.Children.Add(imgCtrl) |> ignore
302
303 // Zoom to a mouse position into the control 'imgCtrl'.
304 let zoomTo (mousePos: Point) =
305 let canvasW = canvasCurrentImage.ActualWidth * currentScale
306 let canvasH = canvasCurrentImage.ActualHeight * currentScale
307 let centerX = (mousePos.X - imgCtrl.BorderThickness.Left) / (imgCtrl.ActualWidth - imgCtrl.BorderThickness.Left) * canvasW
308 let centerY = (mousePos.Y - imgCtrl.BorderThickness.Top) / (imgCtrl.ActualHeight - imgCtrl.BorderThickness.Top) * canvasH
309 scrollViewCurrentImage.ScrollToHorizontalOffset(centerX - scrollViewCurrentImage.ViewportWidth / 2. + borderCurrentImage.BorderThickness.Left)
310 scrollViewCurrentImage.ScrollToVerticalOffset(centerY - scrollViewCurrentImage.ViewportHeight / 2. + borderCurrentImage.BorderThickness.Top)
311
312 imgCtrl.MouseLeftButtonDown.AddHandler(fun obj args ->
313 setCurrentImage (state.SourceImages |> Seq.find (fun srcImg -> (srcImg :> Object) = imgCtrl.Tag))
314 imgCtrl.UpdateLayout()
315 zoomTo (args.GetPosition(imgCtrl))
316 imgCtrl.CaptureMouse() |> ignore)
317
318 imgCtrl.MouseMove.AddHandler(fun obj args ->
319 if imgCtrl.IsMouseCaptured
320 then
321 zoomTo (args.GetPosition(imgCtrl)))
322
323 imgCtrl.MouseLeftButtonUp.AddHandler(fun obj args ->
324 if imgCtrl.IsMouseCaptured
325 then
326 imgCtrl.ReleaseMouseCapture())
327
328
329 let updatePreviews () =
330 stackPreviews.Children.Clear ()
331 for srcImg in state.SourceImages do
332 addPreview srcImg
333 updateCurrentImage ()
334
335 let updateGUI () =
336 txtPatient.Text <- state.PatientID
337 updatePreviews ()
338 updateGlobalParasitemia ()
339
340 txtPatient.TextChanged.AddHandler(fun obj args -> state.PatientID <- txtPatient.Text)
341
342 menuExit.Click.AddHandler(fun obj args ->
343 askSaveCurrent ()
344 mainWindow.Root.Close())
345
346 menuSaveFile.Click.AddHandler(fun obj args -> saveCurrentDocument ())
347
348 menuLoadFile.Click.AddHandler(fun obj args ->
349 // TODO: if current state not saved and not empty, ask to save it.
350 let dialog = OpenFileDialog(Filter = PiaZ.filter)
351 let res = dialog.ShowDialog()
352 if res.HasValue && res.Value
353 then
354 askSaveCurrent ()
355 state.FilePath <- dialog.FileName
356 state.Load()
357 updateGUI ())
358
359 menuNewFile.Click.AddHandler(fun obj args ->
360 askSaveCurrent ()
361 state.Reset()
362 updateGUI())
363
364 menuAddSourceImage.Click.AddHandler(fun obj args ->
365 let dialog = OpenFileDialog(Filter = "Image Files|*.png;*.jpg;*.tif;*.tiff")
366 let res = dialog.ShowDialog()
367 if res.HasValue && res.Value
368 then
369 let srcImg = state.AddSourceImage(dialog.FileName)
370 addPreview srcImg
371 updateGlobalParasitemia ()
372 if state.SourceImages.Count() = 1
373 then
374 updateCurrentImage ())
375
376 menuStartAnalysis.Click.AddHandler(fun obj args ->
377 if Analysis.showWindow mainWindow.Root state defaultConfig
378 then
379 updateGlobalParasitemia ()
380 updateCurrentImage ())
381
382 menuHightlightRBC.Click.AddHandler(fun obj args ->
383 displayHealthy <- menuHightlightRBC.IsChecked
384 updateRBCFramesPreview ()
385 updateRBCFramesCurrent ())
386
387 // Zoom on the current image.
388 let adjustCurrentImageBorders (deltaX: float) (deltaY: float) =
389 borderCurrentImage.BorderThickness <-
390 Thickness(
391 (scrollViewCurrentImage.ViewportWidth + deltaX) / 2.,
392 (scrollViewCurrentImage.ViewportHeight + deltaY) / 2.,
393 (scrollViewCurrentImage.ViewportWidth + deltaX) / 2.,
394 (scrollViewCurrentImage.ViewportHeight + deltaY) / 2.)
395
396 canvasCurrentImage.SizeChanged.AddHandler(fun obj args ->
397 let deltaX = args.NewSize.Width - args.PreviousSize.Width
398 let deltaY = args.NewSize.Height - args.PreviousSize.Height
399 if deltaX > 0.5 || deltaY > 0.5
400 then
401 adjustCurrentImageBorders 0.0 0.0
402 // Center the view at the center of the image initialy.
403 scrollViewCurrentImage.UpdateLayout()
404 scrollViewCurrentImage.ScrollToHorizontalOffset(borderCurrentImage.ActualWidth / 2. - scrollViewCurrentImage.ViewportWidth / 2.)
405 scrollViewCurrentImage.ScrollToVerticalOffset(borderCurrentImage.ActualHeight / 2. - scrollViewCurrentImage.ViewportHeight / 2.))
406
407 scrollViewCurrentImage.SizeChanged.AddHandler(fun obj args ->
408 let deltaX = args.NewSize.Width - args.PreviousSize.Width
409 let deltaY = args.NewSize.Height - args.PreviousSize.Height
410 adjustCurrentImageBorders deltaX deltaY
411 scrollViewCurrentImage.ScrollToHorizontalOffset(scrollViewCurrentImage.HorizontalOffset + deltaX / 8.)
412 scrollViewCurrentImage.ScrollToVerticalOffset(scrollViewCurrentImage.VerticalOffset + deltaY / 8.))
413
414 let mutable maxScale = 4.
415 let mutable minScale = 0.25
416 let currentImageScaleTransform = ScaleTransform()
417 canvasCurrentImage.LayoutTransform <- currentImageScaleTransform
418 borderCurrentImage.PreviewMouseWheel.AddHandler(fun obj args ->
419 let scaleFactor = if args.Delta > 0 then 2.0 else 0.5
420 if scaleFactor > 1. && currentScale < maxScale || scaleFactor < 1. && currentScale > minScale
421 then
422 let previousScale = currentScale
423 currentScale <-
424 let newScale = currentScale * scaleFactor
425 if newScale > maxScale then maxScale elif newScale < minScale then minScale else newScale
426 let realScaleFactor = currentScale / previousScale
427
428 let centerX = scrollViewCurrentImage.HorizontalOffset + scrollViewCurrentImage.ViewportWidth / 2. - borderCurrentImage.BorderThickness.Left
429 let centerY = scrollViewCurrentImage.VerticalOffset + scrollViewCurrentImage.ViewportHeight / 2. - borderCurrentImage.BorderThickness.Top
430
431 currentImageScaleTransform.ScaleX <- currentScale
432 currentImageScaleTransform.ScaleY <- currentScale
433
434 scrollViewCurrentImage.ScrollToHorizontalOffset(centerX * realScaleFactor - scrollViewCurrentImage.ViewportWidth / 2. + borderCurrentImage.BorderThickness.Left)
435 scrollViewCurrentImage.ScrollToVerticalOffset(centerY * realScaleFactor - scrollViewCurrentImage.ViewportHeight / 2. + borderCurrentImage.BorderThickness.Top)
436
437 args.Handled <- true)
438
439 // Pan on the current image.
440 let mutable scrollStartPosition = Point(0., 0.)
441 let mutable scrollStartOffsetX = 0.
442 let mutable scrollStartOffsetY = 0.
443 borderCurrentImage.PreviewMouseLeftButtonDown.AddHandler(fun obj args ->
444 scrollStartPosition <- args.GetPosition(scrollViewCurrentImage)
445 scrollStartOffsetX <- scrollViewCurrentImage.HorizontalOffset
446 scrollStartOffsetY <- scrollViewCurrentImage.VerticalOffset
447 borderCurrentImage.Cursor <- Input.Cursors.ScrollAll
448 borderCurrentImage.CaptureMouse() |> ignore
449 args.Handled <- true)
450
451 borderCurrentImage.PreviewMouseMove.AddHandler(fun obj args ->
452 if borderCurrentImage.IsMouseCaptured
453 then
454 let position = args.GetPosition(scrollViewCurrentImage)
455 let deltaX = scrollStartPosition.X - position.X
456 let deltaY = scrollStartPosition.Y - position.Y
457 scrollViewCurrentImage.ScrollToHorizontalOffset(deltaX + scrollStartOffsetX)
458 scrollViewCurrentImage.ScrollToVerticalOffset(deltaY + scrollStartOffsetY)
459
460 args.Handled <- true)
461
462 borderCurrentImage.PreviewMouseLeftButtonUp.AddHandler(fun obj args ->
463 if borderCurrentImage.IsMouseCaptured
464 then
465 borderCurrentImage.Cursor <- Input.Cursors.Arrow
466 borderCurrentImage.ReleaseMouseCapture()
467 args.Handled <- true)
468
469 // Viewport preview.
470 scrollViewCurrentImage.ScrollChanged.AddHandler(fun obj args -> updateViewportPreview ())
471
472 mainWindow.Root.Show()
473 app.Run()