9 private const int ScrollRange = 1_000_000;
10 private bool updatingScrollBars;
11 private double scrollLeft, scrollTop, scrollWidth, scrollHeight;
13 private void UpdateScrollBars()
15 if (updatingScrollBars || hScrollBar ==
null || vScrollBar ==
null || viewpanel ==
null)
17 BioImage image = OverviewSelectedImage;
18 if (image ==
null || !image.isPyramidal || image.Resolution <= 0 ||
22 RectangleD bounds = OverviewWorldBounds(image);
23 double left = bounds.X;
24 double top = bounds.Y;
25 double width = bounds.W / image.Resolution;
26 double height = bounds.H / image.Resolution;
27 if (!
double.IsFinite(left) || !
double.IsFinite(top) || !
double.IsFinite(width) ||
28 !
double.IsFinite(height) || width <= 0 || height <= 0)
33 scrollWidth = Math.Max(0, bounds.W -
ViewWidth * image.Resolution);
34 scrollHeight = Math.Max(0, bounds.H -
ViewHeight * image.Resolution);
35 updatingScrollBars =
true;
38 ConfigureScrollBar(hScrollBar, image.PyramidalOrigin.X, left, scrollWidth, width,
ViewWidth);
39 ConfigureScrollBar(vScrollBar, image.PyramidalOrigin.Y, top, scrollHeight, height,
ViewHeight);
43 updatingScrollBars =
false;
47 private static void ConfigureScrollBar(ScrollBar bar,
double position,
double start,
48 double travel,
double imageSize,
int viewSize)
50 int page = (int)Math.Clamp(Math.Round(ScrollRange * Math.Min(1, viewSize / imageSize)), 1, ScrollRange);
52 bar.Maximum = ScrollRange;
53 bar.LargeChange = page;
54 bar.SmallChange = Math.Max(1, page / 10);
55 int effectiveMaximum = bar.Maximum - bar.LargeChange + 1;
56 bar.Enabled = travel > 0;
57 double fraction = travel > 0 ? Math.Clamp((position - start) / travel, 0, 1) : 0;
58 bar.Value = (int)Math.Round(fraction * effectiveMaximum);
61 private void vScrollBar_ValueChanged(
object sender, EventArgs e)
63 BioImage image = OverviewSelectedImage;
64 if (updatingScrollBars || image ==
null || !image.isPyramidal)
67 PointD origin = image.PyramidalOrigin;
68 if (sender == hScrollBar && scrollWidth > 0)
69 origin.X = scrollLeft + scrollWidth * hScrollBar.Value / (hScrollBar.Maximum - hScrollBar.LargeChange + 1.0);
70 else if (sender == vScrollBar && scrollHeight > 0)
71 origin.Y = scrollTop + scrollHeight * vScrollBar.Value / (vScrollBar.Maximum - vScrollBar.LargeChange + 1.0);
74 image.PyramidalOrigin = origin;