Пример #1
0
        public static RectDouble GetCanvasViewportBounds(this CanvasView canvasView)
        {
            RectDouble canvasBounds = canvasView.GetCanvasBounds();
            RectDouble extentRect   = canvasView.ConvertCanvasToExtent(canvasBounds);

            return(canvasView.ConvertExtentToViewport(extentRect));
        }
Пример #2
0
 private void OnCanvasViewIsHighQualityScalingEnabledChanged(object sender, ValueChangedEventArgs <bool> e)
 {
     if (!base.CheckAccess())
     {
         PaintDotNet.Canvas.Canvas owner = base.Owner;
         if ((owner != null) && (owner.Dispatcher != null))
         {
             try
             {
                 object[] args = new object[] { sender, e };
                 base.Owner.Dispatcher.BeginInvoke(new Action <object, ValueChangedEventArgs <bool> >(this.OnCanvasViewIsHighQualityScalingEnabledChanged), args);
             }
             catch (Exception)
             {
             }
         }
     }
     else if (!base.IsDisposed)
     {
         CanvasView key = (CanvasView)sender;
         if (this.documentCanvasLayerViews.ContainsKey(key))
         {
             this.RecreateDocumentCanvasLayerView(key);
             key.Invalidate(key.GetCanvasBounds());
         }
     }
 }
Пример #3
0
        private RectDouble GetCursorOutlineRect(CanvasView canvasView, RectDouble cursorBounds)
        {
            double canvasHairWidth = canvasView.CanvasHairWidth;
            double num2            = (1.0 * canvasHairWidth) / 2.0;

            return(RectDouble.Inflate(cursorBounds, canvasHairWidth, canvasHairWidth));
        }
Пример #4
0
        public static RectDouble GetVisibleCanvasBounds(this CanvasView canvasView)
        {
            RectDouble visibleCanvasViewportBounds = canvasView.GetVisibleCanvasViewportBounds();
            RectDouble extentRect = canvasView.ConvertViewportToExtent(visibleCanvasViewportBounds);

            return(canvasView.ConvertExtentToCanvas(extentRect));
        }
Пример #5
0
        protected override void OnViewUnregistered(CanvasView canvasView)
        {
            SizeDouble canvasExtentPadding = canvasView.CanvasExtentPadding;

            canvasView.CanvasExtentPadding = new SizeDouble(canvasExtentPadding.Width - 8.0, canvasExtentPadding.Height - 8.0);
            base.OnViewUnregistered(canvasView);
        }
Пример #6
0
 protected override void OnRender(IDrawingContext dc, RectFloat clipRect, CanvasView canvasView)
 {
     if ((canvasView.ScaleRatio >= 2.0) && GetIsPixelGridEnabled(canvasView))
     {
         SizeDouble      canvasSize = base.Owner.CanvasSize;
         RectDouble      b          = new RectDouble(PointDouble.Zero, canvasSize);
         RectInt32       rect       = RectDouble.Intersect(clipRect, b).Int32Bound;
         Matrix3x2Double transform  = dc.Transform;
         double          num6       = 1.0 / canvasView.CanvasHairWidth;
         RectDouble      num7       = transform.Transform(rect);
         double          num9       = DoubleUtil.Clamp((canvasView.ScaleRatio - 2.0) / 4.0, 0.0, 1.0) / 2.0;
         this.stippleBitmapBrush.Opacity = num9;
         using (dc.UseAntialiasMode(AntialiasMode.Aliased))
         {
             using (dc.UseTransform(Matrix3x2Float.Identity))
             {
                 using (dc.UseAxisAlignedClip((RectFloat)num7, AntialiasMode.Aliased))
                 {
                     for (int i = -(rect.Width & 1); i <= rect.Width; i++)
                     {
                         dc.DrawLine(num7.X + (i * num6), num7.Y, num7.X + (i * num6), num7.Y + num7.Height, this.stippleBitmapBrush, 1.0);
                     }
                     for (int j = -(rect.Height & 1); j <= rect.Height; j++)
                     {
                         dc.DrawLine(num7.X, num7.Y + (j * num6), num7.X + num7.Width, num7.Y + (j * num6), this.stippleBitmapBrush, 1.0);
                     }
                 }
             }
         }
     }
     base.OnRender(dc, clipRect, canvasView);
 }
Пример #7
0
        private static void OnIsPixelGridEnabledPropertyChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
        {
            CanvasView canvasView = (CanvasView)target;

            canvasView.Invalidate(canvasView.GetCanvasBounds());
            RaiseIsPixelGridEnabledChanged(canvasView, e);
        }
Пример #8
0
        public static void AddIsPixelGridEnabledChangedHandler(CanvasView canvasView, ValueChangedEventHandler <bool> handler)
        {
            ValueChangedEventHandler <bool> a        = (ValueChangedEventHandler <bool>)canvasView.GetValue(IsPixelGridEnabledChangedEvent);
            ValueChangedEventHandler <bool> handler3 = (ValueChangedEventHandler <bool>)Delegate.Combine(a, handler);

            canvasView.SetValue(IsPixelGridEnabledChangedEvent, handler3);
        }
Пример #9
0
        public static void RemoveIsPixelGridEnabledChangedHandler(CanvasView canvasView, ValueChangedEventHandler <bool> handler)
        {
            ValueChangedEventHandler <bool> source   = (ValueChangedEventHandler <bool>)canvasView.GetValue(IsPixelGridEnabledChangedEvent);
            ValueChangedEventHandler <bool> handler3 = (ValueChangedEventHandler <bool>)Delegate.Remove(source, handler);

            canvasView.SetValue(IsPixelGridEnabledChangedEvent, handler3);
        }
Пример #10
0
        protected override void OnRender(IDrawingContext dc, RectFloat clipRect, CanvasView canvasView)
        {
            PointDouble     viewportCanvasOffset = canvasView.ViewportCanvasOffset;
            Matrix3x2Double num2 = dc.Transform.Inverse * Matrix3x2Double.Translation(-viewportCanvasOffset.X, -viewportCanvasOffset.Y);

            this.checkerboardTx.Matrix = num2;
            SizeDouble canvasSize = base.Owner.CanvasSize;
            RectDouble rect       = new RectDouble(PointDouble.Zero, canvasSize);

            using (dc.UseAntialiasMode(AntialiasMode.Aliased))
            {
                using (CastOrRefHolder <IDrawingContext1> holder = dc.TryCastOrCreateRef <IDrawingContext1>())
                {
                    if (holder.HasRef)
                    {
                        using (holder.ObjectRef.UsePrimitiveBlend(PrimitiveBlend.Copy))
                        {
                            dc.FillRectangle(rect, this.checkerboardBitmapBrush);
                            goto Label_00CC;
                        }
                    }
                    dc.FillRectangle(rect, this.checkerboardBitmapBrush);
                }
            }
Label_00CC:
            base.OnRender(dc, clipRect, canvasView);
        }
Пример #11
0
 protected override void OnViewRegistered(CanvasView canvasView)
 {
     if (this.Document != null)
     {
         this.RecreateDocumentCanvasLayerView(canvasView);
     }
     base.OnViewRegistered(canvasView);
 }
Пример #12
0
 public SelectionCanvasLayerView(SelectionCanvasLayer owner, CanvasView canvasView) : base(owner, canvasView)
 {
     this.deviceBitmapPool          = new ConcurrentQueue <IDeviceBitmap>();
     this.outlineStrokeWidthPx      = 1f;
     this.queuedBeginRedrawCallback = new Action(this.QueuedBeginRedrawCallback);
     this.redrawOnBackgroundThread  = new WaitCallback(this.RedrawOnBackgroundThread);
     CleanupService.RegisterTrimmableObject(this);
 }
Пример #13
0
        public bool IsPointTouchingHandle(CanvasView canvasView, PointDouble canvasPt)
        {
            base.VerifyAccess();
            double      canvasHairWidth = canvasView.CanvasHairWidth;
            PointDouble center          = this.handleTransform.Transform(this.handleLocation) + ((PointDouble)(this.handleLocationScreenOffset * canvasHairWidth));
            double      edgeLength      = this.handleDiameter * canvasHairWidth;

            return(RectDouble.FromCenter(center, edgeLength).Contains(canvasPt));
        }
Пример #14
0
        private RectDouble GetHandleCanvasRect(CanvasView canvasView)
        {
            double      canvasHairWidth = canvasView.CanvasHairWidth;
            double      num2            = canvasHairWidth * this.handleDiameter;
            double      num3            = num2 / 2.0;
            PointDouble center          = this.handleTransform.Transform(this.handleLocation) + ((PointDouble)(this.handleLocationScreenOffset * canvasHairWidth));

            return(RectDouble.FromCenter(center, (double)((num3 + canvasHairWidth) * 2.0)));
        }
Пример #15
0
        public static RectDouble GetVisibleCanvasViewportBounds(this CanvasView canvasView)
        {
            RectDouble viewportCanvasBounds = canvasView.ViewportCanvasBounds;
            RectDouble extentRect           = canvasView.ConvertCanvasToExtent(viewportCanvasBounds);
            RectDouble a = canvasView.ConvertExtentToViewport(extentRect);
            RectDouble canvasViewportBounds = canvasView.GetCanvasViewportBounds();

            return(RectDouble.Intersect(a, canvasViewportBounds));
        }
Пример #16
0
 protected override void OnViewRegistered(CanvasView canvasView)
 {
     base.VerifyAccess();
     if (!this.canvasViews.Contains(canvasView))
     {
         this.canvasViews.Add(canvasView);
     }
     base.OnViewRegistered(canvasView);
 }
Пример #17
0
        protected TCanvasLayerView TryGetCanvasLayerView(CanvasView canvasView)
        {
            TCanvasLayerView local;

            base.VerifyAccess();
            Validate.IsNotNull <CanvasView>(canvasView, "canvasView");
            this.canvasLayerViews.TryGetValue(canvasView, out local);
            return(local);
        }
Пример #18
0
        protected override void OnInvalidateDeviceResources(CanvasView canvasView)
        {
            TCanvasLayerView local;

            if (this.canvasLayerViews.TryGetValue(canvasView, out local))
            {
                local.InvalidateDeviceResources();
            }
            base.OnInvalidateDeviceResources(canvasView);
        }
Пример #19
0
        public void PreRenderSync(CanvasView canvasView)
        {
            DocumentCanvasLayerView view;

            base.VerifyAccess();
            if (this.documentCanvasLayerViews.TryGetValue(canvasView, out view))
            {
                view.PreRenderSync();
            }
        }
Пример #20
0
        protected override void OnRender(IDrawingContext dc, RectFloat clipRect, CanvasView canvasView)
        {
            DocumentCanvasLayerView view;

            if ((this.document != null) && this.documentCanvasLayerViews.TryGetValue(canvasView, out view))
            {
                view.Render(dc, clipRect);
            }
            base.OnRender(dc, clipRect, canvasView);
        }
Пример #21
0
        protected override void OnInvalidateDeviceResources(CanvasView canvasView)
        {
            DocumentCanvasLayerView view;

            if (this.documentCanvasLayerViews.TryGetValue(canvasView, out view))
            {
                view.InvalidateDeviceResources();
            }
            base.OnInvalidateDeviceResources(canvasView);
        }
Пример #22
0
        protected override void OnBeforeRender(RectFloat clipRect, CanvasView canvasView)
        {
            TCanvasLayerView local;

            if (this.canvasLayerViews.TryGetValue(canvasView, out local))
            {
                local.BeforeRender(clipRect);
            }
            base.OnBeforeRender(clipRect, canvasView);
        }
Пример #23
0
        protected override void OnBeforeRender(RectFloat clipRect, CanvasView canvasView)
        {
            DocumentCanvasLayerView view;

            if ((this.document != null) && this.documentCanvasLayerViews.TryGetValue(canvasView, out view))
            {
                view.BeforeRender(clipRect);
            }
            base.OnBeforeRender(clipRect, canvasView);
        }
Пример #24
0
        protected override void OnRender(IDrawingContext dc, RectFloat clipRect, CanvasView canvasView)
        {
            TCanvasLayerView local;

            if (this.canvasLayerViews.TryGetValue(canvasView, out local))
            {
                local.Render(dc, clipRect);
            }
            base.OnRender(dc, clipRect, canvasView);
        }
Пример #25
0
        protected virtual void ZoomToWithCentering(PaintDotNet.ScaleFactor newScaleFactor, Func <PointDouble> anchorPtCanvasFn)
        {
            PaintDotNet.ScaleFactor scaleFactor = this.ScaleFactor;
            PointDouble             num         = anchorPtCanvasFn();

            this.ScaleFactor = newScaleFactor;
            VectorDouble num3 = anchorPtCanvasFn() - num;

            PaintDotNet.Canvas.CanvasView canvasView = this.CanvasView;
            canvasView.ViewportCanvasOffset -= num3;
        }
Пример #26
0
        protected override void OnViewUnregistered(CanvasView canvasView)
        {
            DocumentCanvasLayerView view;

            if (this.documentCanvasLayerViews.TryGetValue(canvasView, out view))
            {
                view.Dispose();
                this.documentCanvasLayerViews.Remove(canvasView);
            }
            base.OnViewUnregistered(canvasView);
        }
Пример #27
0
 protected override void OnBeforeRender(RectFloat clipRect, CanvasView canvasView)
 {
     if (!LayoutManager.IsUpdatingLayout)
     {
         Visual rootVisual = this.compositionTarget.RootVisual;
         if ((rootVisual != null) && (PresentationSource.FromVisual(rootVisual) != null))
         {
             LayoutManager.UpdateLayout();
         }
     }
     base.OnBeforeRender(clipRect, canvasView);
 }
Пример #28
0
        protected override void OnRender(IDrawingContext dc, RectFloat clipRect, CanvasView canvasView)
        {
            RectDouble cursorBounds      = this.CursorBounds;
            RectDouble cursorOutlineRect = this.GetCursorOutlineRect(canvasView, cursorBounds);
            double     opacity           = this.opacityAnimation.Value;

            dc.FillRectangle(cursorBounds, SolidColorBrushCache.Get((ColorRgba128Float)Colors.Black, opacity));
            double canvasHairWidth = canvasView.CanvasHairWidth;
            double thickness       = 1.0 * canvasHairWidth;

            dc.DrawRectangle(cursorOutlineRect, SolidColorBrushCache.Get((ColorRgba128Float)Colors.White, opacity), thickness);
            base.OnRender(dc, clipRect, canvasView);
        }
Пример #29
0
        protected override void OnRender(IDrawingContext dc, RectFloat clipRect, CanvasView canvasView)
        {
            Matrix3x2Float transform         = dc.Transform;
            SizeDouble     canvasSize        = canvasView.CanvasSize;
            RectFloat      rect              = new RectFloat(0f, 0f, (float)canvasSize.Width, (float)canvasSize.Height);
            RectFloat      num4              = transform.Transform(rect);
            int            recommendedExtent = this.dropShadowRenderer.GetRecommendedExtent(num4.Int32Bound.Size);

            using (dc.UseTransform(Matrix3x2Float.Identity))
            {
                this.dropShadowRenderer.RenderOutside(dc, new ColorRgba128Float(0f, 0f, 0f, 0.5f), num4, recommendedExtent);
            }
            base.OnRender(dc, clipRect, canvasView);
        }
Пример #30
0
        private void RecreateDocumentCanvasLayerView(CanvasView canvasView)
        {
            DocumentCanvasLayerView view;

            if (this.documentCanvasLayerViews.TryGetValue(canvasView, out view))
            {
                view.Dispose();
                this.documentCanvasLayerViews.Remove(canvasView);
            }
            bool isHighQualityScalingEnabled = GetIsHighQualityScalingEnabled(canvasView);
            DocumentCanvasLayerView view2    = new DocumentCanvasLayerView(this, canvasView, isHighQualityScalingEnabled ? this.tileCachesHQRO : this.tileCachesRO);

            this.documentCanvasLayerViews.Add(canvasView, view2);
        }