8 private const int ScrollRange = 1_000_000;
9 private bool updatingScrollBars;
10 private double scrollLeft, scrollTop, scrollWidth, scrollHeight;
12 private void UpdateScrollBars()
14 if (updatingScrollBars || hScrollBar ==
null || vScrollBar ==
null || viewport ==
null)
16 BioImage image = OverviewSelectedImage;
17 if (image ==
null || !image.isPyramidal || image.Resolution <= 0 ||
21 RectangleD bounds = OverviewWorldBounds(image);
22 double left = bounds.X / image.Resolution;
23 double top = bounds.Y / image.Resolution;
24 double width = bounds.W / image.Resolution;
25 double height = bounds.H / image.Resolution;
26 if (!
double.IsFinite(left) || !
double.IsFinite(top) || !
double.IsFinite(width) ||
27 !
double.IsFinite(height) || width <= 0 || height <= 0)
32 scrollWidth = Math.Max(0, width -
ViewWidth);
33 scrollHeight = Math.Max(0, height -
ViewHeight);
34 updatingScrollBars =
true;
37 ConfigureScrollBar(hScrollBar, image.PyramidalOrigin.X, left, scrollWidth, width,
ViewWidth);
38 ConfigureScrollBar(vScrollBar, image.PyramidalOrigin.Y, top, scrollHeight, height,
ViewHeight);
42 updatingScrollBars =
false;
46 private static void ConfigureScrollBar(ScrollBar bar,
double position,
double start,
47 double travel,
double imageSize,
int viewSize)
49 int page = (int)Math.Clamp(Math.Round(ScrollRange * Math.Min(1, viewSize / imageSize)), 1, ScrollRange);
51 bar.Maximum = ScrollRange;
52 bar.LargeChange = page;
53 bar.SmallChange = Math.Max(1, page / 10);
54 int effectiveMaximum = bar.Maximum - bar.LargeChange + 1;
55 bar.Enabled = travel > 0;
56 double fraction = travel > 0 ? Math.Clamp((position - start) / travel, 0, 1) : 0;
57 bar.Value = (int)Math.Round(fraction * effectiveMaximum);
60 private void vScrollBar_ValueChanged(
object sender, EventArgs e)
62 BioImage image = OverviewSelectedImage;
63 if (updatingScrollBars || image ==
null || !image.isPyramidal)
66 PointD origin = image.PyramidalOrigin;
67 if (sender == hScrollBar && scrollWidth > 0)
68 origin.X = scrollLeft + scrollWidth * hScrollBar.Value / (hScrollBar.Maximum - hScrollBar.LargeChange + 1.0);
69 else if (sender == vScrollBar && scrollHeight > 0)
70 origin.Y = scrollTop + scrollHeight * vScrollBar.Value / (vScrollBar.Maximum - vScrollBar.LargeChange + 1.0);
73 image.PyramidalOrigin = origin;