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);
 }
        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));
        }
Exemple #3
0
        protected override SegmentedList <PointDouble> CreateShape(SegmentedList <PointDouble> tracePoints)
        {
            RectDouble        num3;
            double            num6;
            double            num7;
            PointDouble       a           = tracePoints[0];
            PointDouble       b           = tracePoints[tracePoints.Count - 1];
            SelectionDrawMode mode        = base.ToolSettings.Selection.DrawMode.Value;
            double            num4        = base.ToolSettings.Selection.DrawWidth.Value;
            double            num5        = base.ToolSettings.Selection.DrawHeight.Value;
            MeasurementUnit   sourceUnits = base.ToolSettings.Selection.DrawUnits.Value;

            switch (mode)
            {
            case SelectionDrawMode.FixedRatio:
            case SelectionDrawMode.FixedSize:
                num6 = Math.Abs(num4);
                num7 = Math.Abs(num5);
                break;

            default:
                num6 = num4;
                num7 = num5;
                break;
            }
            switch (mode)
            {
            case SelectionDrawMode.Normal:
                if ((base.ModifierKeys & Keys.Shift) == Keys.None)
                {
                    num3 = RectDoubleUtil.FromPixelPoints(a, b);
                    break;
                }
                num3 = RectDoubleUtil.FromPixelPointsConstrained(a, b);
                break;

            case SelectionDrawMode.FixedRatio:
                try
                {
                    double num13 = b.X - a.X;
                    double num14 = b.Y - a.Y;
                    double num15 = num13 / num6;
                    double num16 = Math.Sign(num15);
                    double num17 = num14 / num7;
                    double num18 = Math.Sign(num17);
                    double num19 = num6 / num7;
                    if (num15 < num17)
                    {
                        double x      = a.X;
                        double y      = a.Y;
                        double right  = a.X + num13;
                        double bottom = a.Y + (num18 * Math.Abs((double)(num13 / num19)));
                        num3 = RectDouble.FromEdges(x, y, right, bottom);
                    }
                    else
                    {
                        double left  = a.X;
                        double top   = a.Y;
                        double num26 = a.X + (num16 * Math.Abs((double)(num14 * num19)));
                        double num27 = a.Y + num14;
                        num3 = RectDouble.FromEdges(left, top, num26, num27);
                    }
                }
                catch (ArithmeticException)
                {
                    num3 = new RectDouble(a.X, a.Y, 0.0, 0.0);
                }
                break;

            case SelectionDrawMode.FixedSize:
            {
                double width  = Document.ConvertMeasurement(num6, sourceUnits, base.Document.DpuUnit, base.Document.DpuX, MeasurementUnit.Pixel);
                double height = Document.ConvertMeasurement(num7, sourceUnits, base.Document.DpuUnit, base.Document.DpuY, MeasurementUnit.Pixel);
                num3 = new RectDouble(b.X, b.Y, width, height);
                break;
            }

            default:
                throw ExceptionUtil.InvalidEnumArgumentException <SelectionDrawMode>(mode, "drawMode");
            }
            RectDouble num8  = RectDouble.Intersect(num3, base.Document.Bounds());
            RectDouble num10 = num8.Int32Bound;

            if (num8.HasPositiveArea)
            {
                SegmentedList <PointDouble> list = new SegmentedList <PointDouble>(5, 7)
                {
                    new PointDouble(num10.Left, num10.Top),
                    new PointDouble(num10.Right, num10.Top),
                    new PointDouble(num10.Right, num10.Bottom),
                    new PointDouble(num10.Left, num10.Bottom)
                };
                list.Add(list[0]);
                return(list);
            }
            return(new SegmentedList <PointDouble>(0, 7));
        }
        private void RedrawOnBackgroundThread()
        {
            if (base.CheckAccess())
            {
                ExceptionUtil.ThrowInvalidOperationException();
            }
            if (this.redrawThreadFactory == null)
            {
                this.redrawThreadFactory = new Direct2DFactory(Direct2DFactoryType.MultiThreaded, DebugLevel.None);
            }
            if ((this.redrawThreadGeometryCache == null) || (this.redrawThreadGeometryCache.SelectionSnapshot != this.redrawRenderParams.SelectionSnapshot))
            {
                DisposableUtil.Free <SelectionGeometryCache>(ref this.redrawThreadGeometryCache);
                this.redrawThreadGeometryCache = new SelectionGeometryCache(this.redrawThreadFactory, this.redrawRenderParams.SelectionSnapshot);
            }
            double      scaleRatio           = this.redrawRenderParams.ScaleRatio;
            PointDouble location             = this.redrawRenderParams.ViewportCanvasBounds.Location;
            SizeDouble  viewportSize         = this.redrawRenderParams.ViewportSize;
            SizeInt32   num5                 = SizeDouble.Ceiling(viewportSize);
            RectDouble  b                    = RectDouble.Inflate(CanvasCoordinateConversions.ConvertExtentToViewport(CanvasCoordinateConversions.ConvertCanvasToExtent(this.redrawRenderParams.SelectionSnapshot.GeometryList.Value.Bounds, scaleRatio), scaleRatio, location), (double)this.outlineStrokeWidthPx, (double)this.outlineStrokeWidthPx);
            RectDouble  a                    = new RectDouble(PointDouble.Zero, viewportSize);
            RectDouble  renderViewportBounds = RectDouble.Intersect(a, b);
            RectInt32   viewportRect         = renderViewportBounds.Int32Bound;
            RectDouble  extentRect           = CanvasCoordinateConversions.ConvertViewportToExtent(viewportRect, scaleRatio, location);
            RectDouble  renderCanvasBounds   = CanvasCoordinateConversions.ConvertExtentToCanvas(extentRect, scaleRatio);

            if (!viewportRect.HasPositiveArea)
            {
                base.SyncContext.Post((SendOrPostCallback)(_ => this.EndRedraw(renderViewportBounds, RectFloat.Zero, null, null)));
            }
            else
            {
                IBitmap <ColorAlpha8> interiorMask;
                float                   scale;
                PointFloat              offset;
                Result <IGeometry>      lazyGeometry;
                IBitmap <ColorAlpha8>[] dashedOutlineMasks;
                RectFloat               maskSourceRect;
                SelectionSnapshot       selectionSnapshot         = this.redrawRenderParams.SelectionSnapshot;
                SelectionGeometryCache  redrawThreadGeometryCache = this.redrawThreadGeometryCache;
                bool flag = this.redrawRenderParams.SelectionRenderingQuality == SelectionRenderingQuality.Aliased;
                if (!flag)
                {
                    lazyGeometry = redrawThreadGeometryCache.Geometry;
                }
                else
                {
                    bool flag3 = selectionSnapshot.IsRectilinear.Value;
                    bool flag4 = selectionSnapshot.IsPixelated.Value;
                    if (flag3 & flag4)
                    {
                        lazyGeometry = redrawThreadGeometryCache.Geometry;
                    }
                    else
                    {
                        lazyGeometry = redrawThreadGeometryCache.PixelatedGeometry;
                    }
                }
                bool          flag2         = !flag && this.redrawRenderParams.IsOutlineAntialiased;
                AntialiasMode antialiasMode = ((flag || !flag2) || selectionSnapshot.IsRectilinear.Value) ? AntialiasMode.Aliased : AntialiasMode.PerPrimitive;
                if (this.CanContinueRedrawing(null, null))
                {
                    scale = (float)this.redrawRenderParams.ScaleRatio;
                    float x = -((float)renderCanvasBounds.X);
                    float y = -((float)renderCanvasBounds.Y);
                    offset       = new PointFloat(x, y);
                    interiorMask = BitmapAllocator.Alpha8.Allocate(viewportRect.Size, AllocationOptions.ZeroFillNotRequired);
                    try
                    {
                        RetryManager.RunMemorySensitiveOperation(delegate {
                            using (IDrawingContext context = DrawingContext.FromBitmap(this.redrawThreadFactory, interiorMask))
                            {
                                context.Clear(null);
                                IBrush interiorBrush = context.GetCachedOrCreateResource <IBrush>(whiteBrush);
                                this.RenderSelection(context, scale, offset, this.redrawRenderParams, lazyGeometry, interiorBrush, null, null, antialiasMode);
                            }
                        });
                    }
                    catch (OutOfMemoryException)
                    {
                    }
                    if (this.CanContinueRedrawing(interiorMask, null))
                    {
                        int num15;
                        dashedOutlineMasks = new IBitmap <ColorAlpha8> [SelectionCanvasLayer.DashLength];
                        for (int i = 0; i < dashedOutlineMasks.Length; i = num15)
                        {
                            if ((!this.redrawRenderParams.IsOutlineAnimated && (i != 0)) && (i != (SelectionCanvasLayer.DashLength / 2)))
                            {
                                dashedOutlineMasks[i] = null;
                            }
                            else
                            {
                                dashedOutlineMasks[i] = BitmapAllocator.Alpha8.Allocate(viewportRect.Size, AllocationOptions.ZeroFillNotRequired);
                                try
                                {
                                    RetryManager.RunMemorySensitiveOperation(delegate {
                                        using (IDrawingContext context = DrawingContext.FromBitmap(this.redrawThreadFactory, dashedOutlineMasks[i]))
                                        {
                                            context.Clear(null);
                                            StrokeStyle resourceSource      = SelectionCanvasLayer.GetDashedStrokeStyle(i);
                                            IStrokeStyle outlineStrokeStyle = context.GetCachedOrCreateResource <IStrokeStyle>(resourceSource);
                                            IBrush cachedOrCreateResource   = context.GetCachedOrCreateResource <IBrush>(whiteBrush);
                                            this.RenderSelection(context, scale, offset, this.redrawRenderParams, lazyGeometry, null, cachedOrCreateResource, outlineStrokeStyle, antialiasMode);
                                        }
                                    });
                                }
                                catch (OutOfMemoryException)
                                {
                                }
                                if (!this.CanContinueRedrawing(interiorMask, dashedOutlineMasks))
                                {
                                    return;
                                }
                            }
                            num15 = i + 1;
                        }
                        maskSourceRect = new RectFloat(PointFloat.Zero, interiorMask.Size);
                        base.SyncContext.Post(_ => this.EndRedraw(renderCanvasBounds, maskSourceRect, interiorMask, dashedOutlineMasks), null);
                    }
                }
            }
        }