mirror of
https://github.com/cyanfish/naps2.git
synced 2024-08-16 10:40:35 +03:00
Max zoom for preview form
This commit is contained in:
parent
390432b376
commit
0d427ae202
@ -19,7 +19,11 @@ public class MacPreviewForm : PreviewForm
|
||||
DoubleValue = 0,
|
||||
ToolTip = UiStrings.Zoom
|
||||
}.WithAction(ZoomUpdated);
|
||||
ImageViewer.ZoomChanged += (_, _) => { _zoomSlider.DoubleValue = Math.Log10(ImageViewer.ZoomFactor); };
|
||||
ImageViewer.ZoomChanged += (_, _) =>
|
||||
{
|
||||
_zoomSlider.DoubleValue = Math.Log10(ImageViewer.ZoomFactor);
|
||||
_zoomSlider.MaxValue = Math.Log10(ImageViewer.MaxZoom);
|
||||
};
|
||||
}
|
||||
|
||||
protected override void CreateToolbar()
|
||||
|
@ -123,6 +123,9 @@ public class ScrollZoomImageViewer
|
||||
|
||||
public float ZoomFactor => _renderFactor;
|
||||
|
||||
// GDI doesn't like when the render size (4 bytes per pixel) exceeds int.MaxValue
|
||||
public float MaxZoom => (float) Math.Sqrt(int.MaxValue * 0.99 / (Image!.Width * Image.Height * 4));
|
||||
|
||||
public void ChangeZoom(float step, bool anchorToMouse = false)
|
||||
{
|
||||
SetZoom(_renderFactor * (float) Math.Pow(1.2, step), anchorToMouse);
|
||||
@ -130,9 +133,7 @@ public class ScrollZoomImageViewer
|
||||
|
||||
public void SetZoom(float value, bool anchorToMouse = false)
|
||||
{
|
||||
// TODO: Adjust clamp values based on image size
|
||||
// (and also propagate that to the Mac slider limits)
|
||||
_renderFactor = value.Clamp(0.01f, 10);
|
||||
_renderFactor = value.Clamp(0.01f, MaxZoom);
|
||||
_scrollable.SuspendLayout();
|
||||
var anchor = GetMouseAnchor(anchorToMouse);
|
||||
RenderSize =
|
||||
@ -219,7 +220,6 @@ public class ScrollZoomImageViewer
|
||||
_scrollable.ScrollPosition = Point.Round(new PointF(xScroll, yScroll));
|
||||
}
|
||||
|
||||
|
||||
public static implicit operator LayoutElement(ScrollZoomImageViewer control)
|
||||
{
|
||||
return control._scrollable;
|
||||
|
Loading…
Reference in New Issue
Block a user