예제 #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);
        }
예제 #2
0
        private bool AutoScrollIfNecessary(PointDouble position)
        {
            if (!this.autoScroll || !this.CanPan())
            {
                return(false);
            }
            RectDouble   viewportCanvasBounds = this.CanvasView.ViewportCanvasBounds;
            RectDouble   canvasBounds         = this.CanvasView.GetCanvasBounds();
            double       x     = DoubleUtil.Lerp((viewportCanvasBounds.Left + viewportCanvasBounds.Right) / 2.0, position.X, 1.02);
            PointDouble  num3  = new PointDouble(x, DoubleUtil.Lerp((viewportCanvasBounds.Top + viewportCanvasBounds.Bottom) / 2.0, position.Y, 1.02));
            double       num15 = (num3.X < viewportCanvasBounds.Left) ? ((double)(-1)) : ((num3.X > viewportCanvasBounds.Right) ? ((double)1) : ((double)0));
            double       y     = (num3.Y < viewportCanvasBounds.Top) ? ((double)(-1)) : ((num3.Y > viewportCanvasBounds.Bottom) ? ((double)1) : ((double)0));
            VectorDouble vec   = new VectorDouble(num15, y);

            if (vec.IsCloseToZero())
            {
                return(false);
            }
            TimeSpan span = (TimeSpan)(DateTime.UtcNow - this.lastAutoScrollTime);
            double   num5 = DoubleUtil.Clamp(span.TotalSeconds, 0.0, 0.1);

            if (DoubleUtil.IsCloseToZero(num5))
            {
                return(false);
            }
            double          num6                 = (double)AppSettings.Instance.Workspace.AutoScrollViewportPxPerSecond.Value;
            VectorDouble    viewportVec          = (VectorDouble)((num5 * vec) * num6);
            PointDouble     viewportCanvasOffset = this.CanvasView.ViewportCanvasOffset;
            VectorDouble    num9                 = this.CanvasView.ConvertViewportToCanvas(viewportVec);
            double          left                 = UIUtil.ScaleWidth((double)5.0);
            double          top   = UIUtil.ScaleHeight((double)5.0);
            ThicknessDouble num12 = new ThicknessDouble(left, top, left, top);
            VectorDouble    zero  = VectorDouble.Zero;

            if ((num9.X < 0.0) && (viewportCanvasBounds.Left > -num12.Left))
            {
                zero.X = Math.Max(num9.X, -(viewportCanvasBounds.Left + num12.Left));
            }
            if ((num9.Y < 0.0) && (viewportCanvasBounds.Top > -num12.Top))
            {
                zero.Y = Math.Max(num9.Y, -(viewportCanvasBounds.Top + num12.Top));
            }
            if ((num9.X > 0.0) && (viewportCanvasBounds.Right < (canvasBounds.Right + num12.Right)))
            {
                zero.X = Math.Min(num9.X, (canvasBounds.Right + num12.Right) - viewportCanvasBounds.Right);
            }
            if ((num9.Y > 0.0) && (viewportCanvasBounds.Bottom < (canvasBounds.Bottom + num12.Bottom)))
            {
                zero.Y = Math.Min(num9.Y, (canvasBounds.Bottom + num12.Bottom) - viewportCanvasBounds.Bottom);
            }
            if (zero.IsCloseToZero())
            {
                return(false);
            }
            PointDouble num14 = viewportCanvasOffset + zero;

            this.ResetLastAutoScrollTime();
            this.CanvasView.ViewportCanvasOffset = num14;
            this.Update();
            return(true);
        }