Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }