protected CanvasLayerView(TCanvasLayer owner, PaintDotNet.Canvas.CanvasView canvasView) { Validate.Begin().IsNotNull <TCanvasLayer>(owner, "owner").IsNotNull <PaintDotNet.Canvas.CanvasView>(canvasView, "canvasView").Check(); this.owner = owner; this.canvasView = canvasView; this.canvasView.IsVisibleChanged += new ValueChangedEventHandler <bool>(this.OnCanvasViewIsVisibleChanged); }
public CanvasControl() : base(FactorySource.PerThread) { base.UseBackColor = false; base.UseHwndRenderTarget = AppSettings.Instance.UI.EnableCanvasHwndRenderTarget.Value; this.UpdateRenderTargetType(); AppSettings.Instance.UI.EnableHardwareAcceleration.ValueChangedT += new ValueChangedEventHandler <bool>(this.OnEnableHardwareAccelerationChanged); this.canvasView = new PaintDotNet.Canvas.CanvasView(); this.canvasView.CanvasChanged += new ValueChangedEventHandler <PaintDotNet.Canvas.Canvas>(this.OnCanvasViewCanvasChanged); this.canvasView.CanvasSizeChanged += new ValueChangedEventHandler <SizeDouble>(this.OnCanvasViewCanvasSizeChanged); this.canvasView.Invalidated += new EventHandler <RectDoubleInvalidatedEventArgs>(this.OnCanvasViewInvalidated); this.canvasView.ScaleRatioChanged += new ValueChangedEventHandler <double>(this.OnCanvasViewScaleRatioChanged); this.canvasView.ViewportCanvasOffsetChanged += new ValueChangedEventHandler <PointDouble>(this.OnCanvasViewViewportCanvasOffsetChanged); this.UpdateOverscroll(); AppSettings.Instance.UI.EnableOverscroll.ValueChangedT += new ValueChangedEventHandler <bool>(this.OnEnableOverscrollChanged); WeakReference <CanvasControl> weakThis = new WeakReference <CanvasControl>(this); ValueChangedEventHandler <RenderingPriority> renderingPriorityChangedHandler = null; renderingPriorityChangedHandler = delegate(object sender, ValueChangedEventArgs <RenderingPriority> e) { CanvasControl control; if (weakThis.TryGetTarget(out control)) { control.OnRenderingPriorityChanged(null, e); } else { RenderingPriorityManager.RenderingPriorityChanged -= renderingPriorityChangedHandler; } }; this.renderingPriorityChangedHandler = renderingPriorityChangedHandler; RenderingPriorityManager.RenderingPriorityChanged += this.renderingPriorityChangedHandler; }
protected virtual void Dispose(bool disposing) { if (disposing) { this.InvalidateDeviceResources(); if (this.canvasView != null) { this.canvasView.IsVisibleChanged -= new ValueChangedEventHandler <bool>(this.OnCanvasViewIsVisibleChanged); this.canvasView = null; } } }
private void Dispose(bool disposing) { if (disposing) { DisposableUtil.FreeContents <DocumentCanvasLayerViewMipLayer>(this.mipLayers); this.tileCaches = null; if (this.canvasView != null) { this.canvasView.IsVisibleChanged -= new ValueChangedEventHandler <bool>(this.OnCanvasViewIsVisibleChanged); this.canvasView = null; } } }
private void OnCanvasInvalidated(object sender, CanvasInvalidatedEventArgs e) { base.VerifyAccess(); if (this.Canvas != sender) { throw new PaintDotNet.InternalErrorException("this.canvas != sender"); } PaintDotNet.Canvas.CanvasView canvasView = this.CanvasView; RectDouble invalidCanvasRect = e.GetInvalidCanvasRect(canvasView); RectDouble extentRect = this.canvasView.ConvertCanvasToExtent(invalidCanvasRect); RectInt32 rect = this.canvasView.ConvertExtentToViewport(extentRect).Int32Bound; base.Invalidate(rect); }
public DocumentCanvasLayerView(DocumentCanvasLayer owner, PaintDotNet.Canvas.CanvasView canvasView, IList <DocumentCanvasTileCache> tileCaches) { Validate.Begin().IsNotNull <DocumentCanvasLayer>(owner, "owner").IsNotNull <PaintDotNet.Canvas.CanvasView>(canvasView, "canvasView").IsNotNull <IList <DocumentCanvasTileCache> >(tileCaches, "tileCaches").Check(); this.owner = owner; this.document = this.owner.Document; this.canvasView = canvasView; this.canvasView.IsVisibleChanged += new ValueChangedEventHandler <bool>(this.OnCanvasViewIsVisibleChanged); this.tileCaches = tileCaches; this.mipLayers = new DocumentCanvasLayerViewMipLayer[this.tileCaches.Count]; for (int i = 0; i < this.mipLayers.Length; i++) { this.mipLayers[i] = new DocumentCanvasLayerViewMipLayer(this, this.tileCaches[i].TileMathHelper.TileEdgeLog2, i, this.tileCaches[i]); } this.deviceBitmapPool = new ObjectPool <SizeInt32, IDeviceBitmap>(new Func <SizeInt32, IDeviceBitmap>(this.CreateDeviceBitmap), new Action <SizeInt32, IDeviceBitmap>(this.DisposeDeviceBitmap)); this.mipLayerZOrder = new List <DocumentCanvasLayerViewMipLayer>(); }
private bool OnLayoutImpl() { Rectangle clientRectangle = base.ClientRectangle; Size size = clientRectangle.Size; if ((size.Width >= 0) && (size.Height >= 0)) { RectDouble viewportRect = clientRectangle.ToRectDouble(); SizeDouble num2 = size.ToSizeDouble(); int horizontalScrollBarHeight = SystemInformation.HorizontalScrollBarHeight; int verticalScrollBarWidth = SystemInformation.VerticalScrollBarWidth; PaintDotNet.Canvas.Canvas canvas = this.canvasControl.Canvas; PaintDotNet.Canvas.CanvasView canvasView = this.canvasControl.CanvasView; SizeDouble canvasSize = canvasView.CanvasSize; RectDouble canvasBounds = canvasView.GetCanvasBounds(); SizeDouble viewportSize = canvasView.ViewportSize; SizeDouble num9 = canvasView.ViewportCanvasBounds.Size; PointDouble viewportCanvasOffset = canvasView.ViewportCanvasOffset; PointDouble viewportCanvasOffsetMin = canvasView.ViewportCanvasOffsetMin; PointDouble viewportCanvasOffsetMax = canvasView.ViewportCanvasOffsetMax; SizeDouble num14 = canvasView.ConvertViewportToCanvas(viewportRect).Size; SizeDouble num15 = new SizeDouble(Math.Max((double)0.0, (double)(num2.Width - verticalScrollBarWidth)), Math.Max((double)0.0, (double)(num2.Height - horizontalScrollBarHeight))); RectDouble num16 = new RectDouble(viewportRect.Location, num15); SizeDouble num18 = canvasView.ConvertViewportToCanvas(num16).Size; ThicknessDouble frameCanvasPadding = canvasView.FrameCanvasPadding; RectDouble framedCanvasBounds = canvasView.FramedCanvasBounds; bool flag = false; bool flag2 = false; if ((this.canvasControl == null) || (canvasView.ScaleBasis == ScaleBasis.FitToViewport)) { flag = false; flag2 = false; } else { if (framedCanvasBounds.Width > num14.Width) { flag = true; if (framedCanvasBounds.Height > num18.Height) { flag2 = true; } } if (framedCanvasBounds.Height > num14.Height) { flag2 = true; if (framedCanvasBounds.Width > num18.Width) { flag = true; } } } int num21 = size.Width - (flag2 ? verticalScrollBarWidth : 0); int width = Math.Max(0, num21); int num23 = size.Height - (flag ? horizontalScrollBarHeight : 0); int height = Math.Max(0, num23); Rectangle rectangle2 = new Rectangle(0, 0, width, height); double scaleRatio = canvasView.ScaleRatio; this.canvasControl.Bounds = rectangle2; this.canvasControl.PerformLayout(); canvasView.CoerceValue(PaintDotNet.Canvas.CanvasView.ScaleRatioProperty); if ((canvasView.ScaleRatio != scaleRatio) || (canvasView.ViewportSize != viewportSize)) { return(false); } if (flag) { Rectangle newBounds = new Rectangle(0, size.Height - horizontalScrollBarHeight, size.Width - (flag2 ? verticalScrollBarWidth : 0), horizontalScrollBarHeight); int min = this.ConvertToScrollBar(viewportCanvasOffsetMin.X); int max = this.ConvertToScrollBar(viewportCanvasOffsetMax.X + num9.Width); int newLargeChange = this.ConvertToScrollBar(num9.Width); int newSmallChange = this.ConvertToScrollBar(num9.Width / 10.0); int newValue = Int32Util.Clamp(this.ConvertToScrollBar(viewportCanvasOffset.X), min, max); UpdateScrollBar(this.hScrollBar, newBounds, min, max, newLargeChange, newSmallChange, newValue); } if (flag2) { Rectangle rectangle4 = new Rectangle(size.Width - verticalScrollBarWidth, 0, verticalScrollBarWidth, size.Height - (flag ? horizontalScrollBarHeight : 0)); int num31 = this.ConvertToScrollBar(viewportCanvasOffsetMin.Y); int num32 = this.ConvertToScrollBar(viewportCanvasOffsetMax.Y + num9.Height); int num33 = this.ConvertToScrollBar(num9.Height); int num34 = this.ConvertToScrollBar(num9.Height / 10.0); int num35 = Int32Util.Clamp(this.ConvertToScrollBar(viewportCanvasOffset.Y), num31, num32); UpdateScrollBar(this.vScrollBar, rectangle4, num31, num32, num33, num34, num35); } this.hScrollBar.Visible = flag; this.vScrollBar.Visible = flag2; } return(true); }
protected override void OnKeyDown(KeyEventArgs e) { if (e.Handled) { goto Label_0347; } PaintDotNet.Canvas.CanvasView canvasView = this.CanvasView; if (canvasView == null) { goto Label_0347; } bool flag = false; switch (e.KeyCode) { case Keys.PageUp: if (!e.Shift) { canvasView.ViewportCanvasOffset -= new VectorDouble(0.0, canvasView.ViewportCanvasBounds.Height); } else { canvasView.ViewportCanvasOffset -= new VectorDouble(canvasView.ViewportCanvasBounds.Width, 0.0); } flag = true; e.Handled = true; goto Label_032E; case Keys.Next: if (!e.Shift) { canvasView.ViewportCanvasOffset += new VectorDouble(0.0, canvasView.ViewportCanvasBounds.Height); break; } canvasView.ViewportCanvasOffset += new VectorDouble(canvasView.ViewportCanvasBounds.Width, 0.0); break; case Keys.End: if (!e.Control || !e.Alt) { if (e.Control) { canvasView.ViewportCanvasOffset = canvasView.ViewportCanvasOffsetMax; } else { RectDouble visibleCanvasBounds = canvasView.GetVisibleCanvasBounds(); SizeDouble size = canvasView.ViewportCanvasBounds.Size; PointDouble bottomRight = canvasView.GetCanvasBounds().BottomRight; if ((visibleCanvasBounds.Left <= (bottomRight.X - 1.0)) && (visibleCanvasBounds.Right >= bottomRight.X)) { if ((visibleCanvasBounds.Top > (bottomRight.Y - 1.0)) || (visibleCanvasBounds.Bottom < bottomRight.Y)) { canvasView.ViewportCanvasOffset = new PointDouble(canvasView.ViewportCanvasOffset.X, bottomRight.Y - size.Height); } } else { canvasView.ViewportCanvasOffset = new PointDouble(bottomRight.X - size.Width, canvasView.ViewportCanvasOffset.Y); } } } flag = true; e.Handled = true; goto Label_032E; case Keys.Home: if (!e.Control || !e.Alt) { if (e.Control) { canvasView.ViewportCanvasOffset = canvasView.ViewportCanvasOffsetMin; } else { RectDouble num2 = canvasView.GetVisibleCanvasBounds(); PointDouble topLeft = canvasView.GetCanvasBounds().TopLeft; if ((num2.Left <= topLeft.X) && (num2.Right >= (topLeft.X + 1.0))) { if ((num2.Top > topLeft.Y) || (num2.Bottom < (topLeft.Y + 1.0))) { canvasView.ViewportCanvasOffset -= new VectorDouble(0.0, num2.Top - topLeft.Y); } } else { canvasView.ViewportCanvasOffset -= new VectorDouble(num2.Left - topLeft.X, 0.0); } } } flag = true; e.Handled = true; goto Label_032E; default: goto Label_032E; } flag = true; e.Handled = true; Label_032E: if (flag) { canvasView.SetValue(PaintDotNet.Canvas.CanvasView.ViewportCanvasOffsetProperty, canvasView.GetValue(PaintDotNet.Canvas.CanvasView.ViewportCanvasOffsetProperty)); } Label_0347: base.OnKeyDown(e); }