private RectDouble GetCursorOutlineRect(CanvasView canvasView, RectDouble cursorBounds)
        {
            double canvasHairWidth = canvasView.CanvasHairWidth;
            double num2            = (1.0 * canvasHairWidth) / 2.0;

            return(RectDouble.Inflate(cursorBounds, canvasHairWidth, canvasHairWidth));
        }
Example #2
0
        public override void OnDraw()
        {
            if (m_Selecting)
            {
                IVector <T> selectPosition = m_TextWidget.GetOffsetLeftOfCharacterIndex(m_SelectionIndexToStartBefore);

                IVector <T> screenSelectStart = selectPosition;
                screenSelectStart[0].AddEquals(2);
                IVector <T> screenSelectEnd = MatrixFactory <T> .CreateVector2D(screenSelectStart[0], screenSelectStart[1].Add(Bounds.Height));

                PointToScreen(ref screenSelectStart);
                PointToScreen(ref screenSelectEnd);
                GetRenderer().Line(screenSelectStart, screenSelectEnd, new RGBA_Bytes(0, 1.0, 0));
            }

            base.OnDraw();

            RectDouble <T> boundsPlusPoint5 = Bounds;

            boundsPlusPoint5.Inflate(M.New <T>(.5));
            RoundedRect <T> borderRect = new RoundedRect <T>(boundsPlusPoint5, M.Zero <T>());
            ConvStroke <T>  borderLine = new ConvStroke <T>(borderRect);

            GetRenderer().Render(borderLine, new RGBA_Bytes(0, 0, 0));

            IVector <T> screenStart = m_BarPosition;

            screenStart[0].AddEquals(2);
            IVector <T> screenEnd = MatrixFactory <T> .CreateVector2D(screenStart[0], screenStart[1].Add(Bounds.Height));

            PointToScreen(ref screenStart);
            PointToScreen(ref screenEnd);
            GetRenderer().Line(screenStart, screenEnd, new RGBA_Bytes(0, 0, 1.0));
        }
Example #3
0
 protected override void OnRender(IDrawingContext dc, RectFloat clipRect)
 {
     dc.Clear(new ColorRgba128Float?(this.BackColor));
     using (dc.UseTranslateTransform(0.5f, 0.5f, MatrixMultiplyOrder.Append))
     {
         RectDouble    num       = RectDouble.Inflate(base.ClientRectangle.ToRectInt32(), -1.0, -1.0);
         double        num3      = Math.Min(num.Width, num.Height) / 2.0;
         PointDouble   center    = new PointDouble(num.X + num3, num.Y + num3);
         double        d         = MathUtil.DegreesToRadians(this.value);
         EllipseDouble ellipse   = new EllipseDouble(center, num3 - 0.5, num3 - 0.5);
         double        thickness = this.hover ? 2.0 : 1.0;
         double        num8      = this.maxValue - this.minValue;
         if (num8 >= 360.0)
         {
             dc.FillEllipse(ellipse, validAnglesFillBrush);
             dc.DrawEllipse(ellipse, outlineBrush, thickness);
         }
         else
         {
             dc.FillEllipse(ellipse, invalidAnglesFillBrush);
             double      width = num3;
             PointDouble num14 = new PointDouble(center.X + (width * Math.Cos(MathUtil.DegreesToRadians(this.minValue))), center.Y - (width * Math.Sin(MathUtil.DegreesToRadians(this.minValue))));
             PointDouble num15 = new PointDouble(center.X + (width * Math.Cos(MathUtil.DegreesToRadians(this.maxValue))), center.Y - (width * Math.Sin(MathUtil.DegreesToRadians(this.maxValue))));
             SizeDouble  num16 = new SizeDouble(width, width);
             if (this.validRangeGeometry == null)
             {
                 this.validRangeGeometry        = new PathGeometry();
                 this.validRangeFigure          = new PathFigure();
                 this.validRangeFigure.IsFilled = true;
                 this.validRangeFigure.IsClosed = true;
                 this.validRangeGeometry.Figures.Add(this.validRangeFigure);
                 this.validRangeLineSegment1 = new LineSegment();
                 this.validRangeFigure.Segments.Add(this.validRangeLineSegment1);
                 this.validRangeArcSegment = new ArcSegment();
                 this.validRangeArcSegment.SweepDirection = SweepDirection.Counterclockwise;
                 this.validRangeFigure.Segments.Add(this.validRangeArcSegment);
                 this.validRangeLineSegment2 = new LineSegment();
                 this.validRangeFigure.Segments.Add(this.validRangeLineSegment2);
             }
             this.validRangeFigure.StartPoint     = center;
             this.validRangeLineSegment1.Point    = num14;
             this.validRangeArcSegment.Point      = num15;
             this.validRangeArcSegment.IsLargeArc = num8 >= 180.0;
             this.validRangeArcSegment.Size       = num16;
             this.validRangeLineSegment2.Point    = num15;
             dc.FillGeometry(this.validRangeGeometry, validAnglesFillBrush, null);
             dc.DrawEllipse(ellipse, outlineBrush, thickness);
             dc.DrawLine(center, num14, outlineBrush, 0.5);
             dc.DrawLine(center, num15, outlineBrush, 0.5);
         }
         double        num9   = num3 - 2.0;
         PointDouble   num10  = new PointDouble(center.X + (num9 * Math.Cos(d)), center.Y - (num9 * Math.Sin(d)));
         double        radius = 2.5;
         EllipseDouble num12  = new EllipseDouble(center, radius);
         dc.FillEllipse(num12, gripFillBrush);
         dc.DrawLine(center, num10, gripBrush, this.hover ? 2.0 : 1.5);
     }
     base.OnRender(dc, clipRect);
 }
        internal void InvalidateSelectionArea()
        {
            base.VerifyAccess();
            SelectionSnapshot selectionSnapshot = base.Owner.SelectionSnapshot;
            RectDouble        fastMaxBounds     = selectionSnapshot.FastMaxBounds;

            if (!selectionSnapshot.IsEmpty && !fastMaxBounds.IsEmpty)
            {
                double     canvasHairWidth = base.CanvasView.CanvasHairWidth;
                double     dx         = this.outlineStrokeWidthPx * canvasHairWidth;
                RectDouble canvasRect = RectDouble.Inflate(fastMaxBounds, dx, dx);
                base.CanvasView.Invalidate(canvasRect);
            }
        }
Example #5
0
 protected override void OnRender(IDrawingContext dc, RectFloat clipRect, CanvasView canvasView)
 {
     if ((this.brushSize > 0.0) && (this.brushAlpha > 0))
     {
         double     opacity         = ((double)this.brushAlpha) / 255.0;
         Brush      brush           = SolidColorBrushCache.Get((ColorRgba128Float)ColorBgra.White, opacity);
         Brush      brush2          = SolidColorBrushCache.Get((ColorRgba128Float)ColorBgra.Black, opacity);
         double     canvasHairWidth = canvasView.CanvasHairWidth;
         RectDouble brushRect       = this.BrushRect;
         brushRect.Inflate((double)(-canvasHairWidth * 2.0), (double)(-canvasHairWidth * 2.0));
         if (brushRect.HasPositiveArea)
         {
             this.ellipseGeometryInner.RadiusX  = this.brushSize - (canvasHairWidth * 2.0);
             this.ellipseGeometryInner.RadiusY  = this.brushSize - (canvasHairWidth * 2.0);
             this.ellipseGeometryMiddle.RadiusX = this.brushSize - canvasHairWidth;
             this.ellipseGeometryMiddle.RadiusY = this.brushSize - canvasHairWidth;
             this.ellipseGeometryOuter.RadiusX  = this.brushSize;
             this.ellipseGeometryOuter.RadiusY  = this.brushSize;
             using (dc.UseTranslateTransform(-((VectorFloat)this.brushLocation), MatrixMultiplyOrder.Prepend))
             {
                 using (CastOrRefHolder <IDrawingContext2> holder = dc.TryCastOrCreateRef <IDrawingContext2>())
                 {
                     if (holder.HasRef)
                     {
                         this.ellipseRealizationInner            = this.ellipseRealizationInner ?? new StrokedGeometryRealization(this.ellipseGeometryInner);
                         this.ellipseRealizationMiddle           = this.ellipseRealizationMiddle ?? new StrokedGeometryRealization(this.ellipseGeometryMiddle);
                         this.ellipseRealizationOuter            = this.ellipseRealizationOuter ?? new StrokedGeometryRealization(this.ellipseGeometryOuter);
                         this.ellipseRealizationInner.Thickness  = canvasHairWidth;
                         this.ellipseRealizationMiddle.Thickness = canvasHairWidth;
                         this.ellipseRealizationOuter.Thickness  = canvasHairWidth;
                         holder.ObjectRef.DrawGeometryRealization(this.ellipseRealizationInner, brush);
                         holder.ObjectRef.DrawGeometryRealization(this.ellipseRealizationMiddle, brush2);
                         holder.ObjectRef.DrawGeometryRealization(this.ellipseRealizationOuter, brush);
                     }
                     else
                     {
                         dc.DrawGeometry(this.ellipseGeometryInner, brush, canvasHairWidth);
                         dc.DrawGeometry(this.ellipseGeometryMiddle, brush2, canvasHairWidth);
                         dc.DrawGeometry(this.ellipseGeometryOuter, brush, canvasHairWidth);
                     }
                 }
             }
         }
     }
     base.OnRender(dc, clipRect, canvasView);
 }
Example #6
0
 protected override void OnRender(IDrawingContext dc, RectFloat clipRect)
 {
     using (dc.UseAntialiasMode(AntialiasMode.Aliased))
     {
         SizeInt32 num;
         Size      clientSize = base.ClientSize;
         if ((clientSize.Width < 2) || (clientSize.Height < 2))
         {
             num = new SizeInt32(3, 3);
         }
         else
         {
             num = new SizeInt32(clientSize.Width, clientSize.Height);
         }
         dc.Clear(new ColorRgba128Float?((ColorRgba128Float)PaintDotNet.Imaging.SystemColors.Window));
         int    num2 = (int)(this.tolerance * 100f);
         string text = string.Format(percentageFormat, num2);
         if (this.textLayout == null)
         {
             this.textLayout = UIText.CreateLayout(dc, text, this.Font, null, HotkeyRenderMode.Ignore, 65535.0, 65535.0);
             this.textLayout.ParagraphAlignment = ParagraphAlignment.Center;
             this.textLayout.FontSize          *= 0.9;
         }
         else
         {
             this.textLayout.Text = text;
         }
         this.textLayout.MaxWidth  = num.Width - 6;
         this.textLayout.MaxHeight = num.Height - 6;
         PointDouble origin = new PointDouble(3.0, 3.0);
         dc.DrawTextLayout(origin, this.textLayout, SolidColorBrushCache.Get(base.Enabled ? ((ColorRgba128Float)PaintDotNet.Imaging.SystemColors.WindowText) : ((ColorRgba128Float)PaintDotNet.Imaging.SystemColors.GrayText)), DrawTextOptions.None);
         RectDouble rect = new RectDouble(0.0, 0.0, (double)num.Width, (double)num.Height);
         RectDouble num5 = RectDouble.Inflate(rect, -0.5, -0.5);
         dc.DrawRectangle(num5, SolidColorBrushCache.Get(base.Enabled ? ((ColorRgba128Float)PaintDotNet.Imaging.SystemColors.ControlDark) : ((ColorRgba128Float)PaintDotNet.Imaging.SystemColors.ControlDark)), 1.0);
         RectDouble num6 = new RectDouble(1.0, 1.0, (num.Width - 2.0) * this.tolerance, (double)(num.Height - 2));
         PaintDotNet.UI.Media.Brush brush = SolidColorBrushCache.Get(base.Enabled ? (this.hovering ? ((ColorRgba128Float)PaintDotNet.Imaging.SystemColors.HotTrack) : ((ColorRgba128Float)PaintDotNet.Imaging.SystemColors.Highlight)) : ((ColorRgba128Float)PaintDotNet.Imaging.SystemColors.Control));
         dc.FillRectangle(num6, brush);
         using (dc.UseAxisAlignedClip((RectFloat)num6, AntialiasMode.PerPrimitive))
         {
             dc.DrawTextLayout(origin, this.textLayout, SolidColorBrushCache.Get(base.Enabled ? ((ColorRgba128Float)PaintDotNet.Imaging.SystemColors.HighlightText) : ((ColorRgba128Float)PaintDotNet.Imaging.SystemColors.GrayText)), DrawTextOptions.None);
         }
     }
     base.OnRender(dc, clipRect);
 }
Example #7
0
        public override void OnDraw()
        {
            T totalExtra               = BorderWidth.Add(TextPadding);
            RectDouble <T>  Bounds     = new RectDouble <T>(totalExtra.Negative(), totalExtra.Negative(), m_ButtonText.Width.Add(totalExtra), m_ButtonText.Height.Add(totalExtra));
            RoundedRect <T> rectBorder = new RoundedRect <T>(Bounds, m_BorderRadius);

            GetRenderer().Render(rectBorder, new RGBA_Bytes(0, 0, 0));
            RectDouble <T> insideBounds = Bounds;

            insideBounds.Inflate(BorderWidth.Negative());
            RoundedRect <T> rectInside  = new RoundedRect <T>(insideBounds, M.New <T>(Math.Max(m_BorderRadius.Subtract(BorderWidth).ToDouble(), 0)));
            RGBA_Bytes      insideColor = new RGBA_Bytes(1.0, 1.0, 1.0);

            if (MouseOverButton)
            {
                if (MouseDownOnButton)
                {
                    insideColor = new RGBA_Bytes(255, 110, 110);
                }
                else
                {
                    insideColor = new RGBA_Bytes(225, 225, 255);
                }
            }

            GetRenderer().Render(rectInside, insideColor);

#if false
            double x1, y1, x2, y2;
            m_ButtonText.GetTextBounds(out x1, out y1, out x2, out y2);
            RoundedRect rectText    = new RoundedRect(x1, y1, x2, y2, 0);
            conv_stroke rectOutline = new conv_stroke(rectText);
            GetRenderer().Render(rectOutline, new RGBA_Bytes(1.0, 0, 0));
#endif
#if false
            RoundedRect rectText2    = new RoundedRect(m_ButtonText.Bounds, 0);
            conv_stroke rectOutline2 = new conv_stroke(rectText2);
            GetRenderer().Render(rectOutline, new RGBA_Bytes(0, 0, 1.0));
#endif

            base.OnDraw();
        }
 protected override void OnRender(IDrawingContext dc, RectFloat clipRect, CanvasView canvasView)
 {
     if ((this.brushSize > 0.0) && (this.brushAlpha > 0))
     {
         double     opacity         = ((double)this.brushAlpha) / 255.0;
         Brush      brush           = SolidColorBrushCache.Get((ColorRgba128Float)ColorBgra.White, opacity);
         Brush      brush2          = SolidColorBrushCache.Get((ColorRgba128Float)ColorBgra.Black, opacity);
         double     canvasHairWidth = canvasView.CanvasHairWidth;
         RectDouble brushRect       = this.BrushRect;
         brushRect.Inflate(-canvasHairWidth, -canvasHairWidth);
         if (brushRect.HasPositiveArea)
         {
             RectFloat num4 = (RectFloat)brushRect;
             using (dc.UseAntialiasMode(AntialiasMode.Aliased))
             {
                 dc.DrawRectangle(brushRect, brush2, canvasHairWidth * 3.0);
                 dc.DrawRectangle(brushRect, brush, canvasHairWidth);
             }
         }
     }
     base.OnRender(dc, clipRect, canvasView);
 }
Example #9
0
 protected override RectInt32 OnGetMaxRenderBounds() =>
 RectDouble.Inflate(this.GetMaximumBoundsRects().Bounds(), 1.0, 1.0).Int32Bound;
 private RectDouble CalculateInvalidRect(CanvasView canvasView, RectDouble canvasRect) =>
 RectDouble.Inflate(this.GetCursorOutlineRect(canvasView, canvasRect), 1.0, 1.0);
Example #11
0
        protected override void OnRender(IDrawingContext dc, RectFloat clipRect, CanvasView canvasView)
        {
            double canvasHairWidth = canvasView.CanvasHairWidth;

            if (this.handleDiameter > 2.0)
            {
                double         rotationAngle = this.handleTransform.GetRotationAngle();
                PointDouble    location      = this.handleTransform.Transform(this.handleLocation) + ((PointDouble)(this.handleLocationScreenOffset * canvasHairWidth));
                VectorDouble[] vecs          = new VectorDouble[] { new VectorDouble(-1.0, -1.0), new VectorDouble(1.0, -1.0), new VectorDouble(1.0, 1.0), new VectorDouble(-1.0, 1.0), new VectorDouble(-1.0, 0.0), new VectorDouble(1.0, 0.0), new VectorDouble(0.0, -1.0), new VectorDouble(0.0, 1.0) };
                vecs.RotateInPlace(rotationAngle);
                vecs.NormalizeInPlace();
                double num5 = ((double)this.handleAlpha) / 255.0;
                this.whiteBrush.Opacity = num5;
                this.blackBrush.Opacity = num5;
                if (this.handleShape != MoveHandleShape.Circle)
                {
                    PointDouble[] numArray2 = new PointDouble[] { location + (vecs[0] * (this.handleDiameter * canvasHairWidth)), location + (vecs[1] * (this.handleDiameter * canvasHairWidth)), location + (vecs[2] * (this.handleDiameter * canvasHairWidth)), location + (vecs[3] * (this.handleDiameter * canvasHairWidth)) };
                    PointDouble[] numArray3 = new PointDouble[] { location + (vecs[0] * ((this.handleDiameter - 1.0) * canvasHairWidth)), location + (vecs[1] * ((this.handleDiameter - 1.0) * canvasHairWidth)), location + (vecs[2] * ((this.handleDiameter - 1.0) * canvasHairWidth)), location + (vecs[3] * ((this.handleDiameter - 1.0) * canvasHairWidth)) };
                    PointDouble[] numArray4 = new PointDouble[] { location + (vecs[0] * ((this.handleDiameter - 2.0) * canvasHairWidth)), location + (vecs[1] * ((this.handleDiameter - 2.0) * canvasHairWidth)), location + (vecs[2] * ((this.handleDiameter - 2.0) * canvasHairWidth)), location + (vecs[3] * ((this.handleDiameter - 2.0) * canvasHairWidth)) };
                    dc.DrawLine(numArray2[0], numArray2[1], this.whiteBrush, canvasHairWidth);
                    dc.DrawLine(numArray2[1], numArray2[2], this.whiteBrush, canvasHairWidth);
                    dc.DrawLine(numArray2[2], numArray2[3], this.whiteBrush, canvasHairWidth);
                    dc.DrawLine(numArray2[3], numArray2[0], this.whiteBrush, canvasHairWidth);
                    dc.DrawLine(numArray3[0], numArray3[1], this.blackBrush, canvasHairWidth);
                    dc.DrawLine(numArray3[1], numArray3[2], this.blackBrush, canvasHairWidth);
                    dc.DrawLine(numArray3[2], numArray3[3], this.blackBrush, canvasHairWidth);
                    dc.DrawLine(numArray3[3], numArray3[0], this.blackBrush, canvasHairWidth);
                    dc.DrawLine(numArray4[0], numArray4[1], this.whiteBrush, canvasHairWidth);
                    dc.DrawLine(numArray4[1], numArray4[2], this.whiteBrush, canvasHairWidth);
                    dc.DrawLine(numArray4[2], numArray4[3], this.whiteBrush, canvasHairWidth);
                    dc.DrawLine(numArray4[3], numArray4[0], this.whiteBrush, canvasHairWidth);
                }
                else if (this.handleShape == MoveHandleShape.Circle)
                {
                    RectDouble rect = new RectDouble(location, SizeDouble.Zero);
                    rect.Inflate((double)((this.handleDiameter - 1.0) * canvasHairWidth), (double)((this.handleDiameter - 1.0) * canvasHairWidth));
                    dc.DrawEllipse(EllipseDouble.FromRect(rect), this.whiteBrush, canvasHairWidth);
                    rect.Inflate(-canvasHairWidth, -canvasHairWidth);
                    dc.DrawEllipse(EllipseDouble.FromRect(rect), this.blackBrush, canvasHairWidth);
                    rect.Inflate(-canvasHairWidth, -canvasHairWidth);
                    dc.DrawEllipse(EllipseDouble.FromRect(rect), this.whiteBrush, canvasHairWidth);
                }
                if (this.handleShape == MoveHandleShape.Compass)
                {
                    PointDouble  num7     = location + ((PointDouble)(vecs[0] * ((this.handleDiameter - 1.0) * canvasHairWidth)));
                    PointDouble  point    = location + ((PointDouble)(vecs[1] * ((this.handleDiameter - 1.0) * canvasHairWidth)));
                    PointDouble  num9     = location + ((PointDouble)(vecs[2] * ((this.handleDiameter - 1.0) * canvasHairWidth)));
                    PointDouble  num10    = location + ((PointDouble)(vecs[3] * ((this.handleDiameter - 1.0) * canvasHairWidth)));
                    PointDouble  num11    = new PointDouble(num7.X, (num7.Y + num10.Y) / 2.0);
                    PointDouble  num12    = new PointDouble((num7.X + point.X) / 2.0, num7.Y);
                    PointDouble  num13    = new PointDouble(point.X, (point.Y + num9.Y) / 2.0);
                    PointDouble  num14    = new PointDouble((num10.X + num9.X) / 2.0, num9.Y);
                    PointDouble  num15    = new PointDouble(num12.X, num11.Y);
                    PathGeometry geometry = new PathGeometry();
                    PathFigure   item     = new PathFigure {
                        IsClosed   = true,
                        IsFilled   = true,
                        StartPoint = num7
                    };
                    item.Segments.Add(new LineSegment(point));
                    item.Segments.Add(new LineSegment(num9));
                    item.Segments.Add(new LineSegment(num10));
                    geometry.Figures.Add(item);
                    dc.FillGeometry(geometry, this.whiteBrush, null);
                    PathGeometry geometry2 = new PathGeometry();
                    double       num16     = canvasHairWidth;
                    double       num17     = 1.35 * canvasHairWidth;
                    double       num18     = (num17 * 3.0) / 2.0;
                    double       num19     = num16 / 2.0;
                    double       num20     = (num17 * Math.Sqrt(27.0)) / 2.0;
                    PathFigure   figure2   = new PathFigure {
                        IsFilled   = true,
                        IsClosed   = true,
                        StartPoint = num11
                    };
                    figure2.Segments.Add(new LineSegment(new PointDouble(num11.X + num20, num11.Y + num18)));
                    figure2.Segments.Add(new LineSegment(new PointDouble(num11.X + num20, num11.Y + num19)));
                    figure2.Segments.Add(new LineSegment(new PointDouble(num15.X - num19, num15.Y + num19)));
                    figure2.Segments.Add(new LineSegment(new PointDouble(num14.X - num19, num14.Y - num20)));
                    figure2.Segments.Add(new LineSegment(new PointDouble(num14.X - num18, num14.Y - num20)));
                    figure2.Segments.Add(new LineSegment(num14));
                    figure2.Segments.Add(new LineSegment(new PointDouble(num14.X + num18, num14.Y - num20)));
                    figure2.Segments.Add(new LineSegment(new PointDouble(num14.X + num19, num14.Y - num20)));
                    figure2.Segments.Add(new LineSegment(new PointDouble(num15.X + num19, num15.Y + num19)));
                    figure2.Segments.Add(new LineSegment(new PointDouble(num13.X - num20, num13.Y + num19)));
                    figure2.Segments.Add(new LineSegment(new PointDouble(num13.X - num20, num13.Y + num18)));
                    figure2.Segments.Add(new LineSegment(num13));
                    figure2.Segments.Add(new LineSegment(new PointDouble(num13.X - num20, num13.Y - num18)));
                    figure2.Segments.Add(new LineSegment(new PointDouble(num13.X - num20, num13.Y - num19)));
                    figure2.Segments.Add(new LineSegment(new PointDouble(num15.X + num19, num15.Y - num19)));
                    figure2.Segments.Add(new LineSegment(new PointDouble(num12.X + num19, num12.Y + num20)));
                    figure2.Segments.Add(new LineSegment(new PointDouble(num12.X + num18, num12.Y + num20)));
                    figure2.Segments.Add(new LineSegment(num12));
                    figure2.Segments.Add(new LineSegment(new PointDouble(num12.X - num18, num12.Y + num20)));
                    figure2.Segments.Add(new LineSegment(new PointDouble(num12.X - num19, num12.Y + num20)));
                    figure2.Segments.Add(new LineSegment(new PointDouble(num15.X - num19, num15.Y - num19)));
                    figure2.Segments.Add(new LineSegment(new PointDouble(num11.X + num20, num11.Y - num19)));
                    figure2.Segments.Add(new LineSegment(new PointDouble(num11.X + num20, num11.Y - num18)));
                    geometry2.Figures.Add(figure2);
                    dc.FillGeometry(geometry2, this.blackBrush, null);
                }
            }
            base.OnRender(dc, clipRect, canvasView);
        }
Example #12
0
 private RectDouble CalculateInvalidRect(CanvasView canvasView, RectDouble canvasRect) =>
 RectDouble.Inflate(this.GetHandleCanvasRect(canvasView), 1.0, 1.0);
        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);
                    }
                }
            }
        }
        private void OnRenderSelection(IDrawingContext dc, RectFloat clipRect)
        {
            IDeviceBitmap bitmap;
            IDeviceBitmap bitmap2;
            IDeviceBitmap bitmap3;
            bool          flag = false;

            try
            {
                this.GetInitializedRenderBitmaps(dc, out bitmap, out bitmap2, out bitmap3);
            }
            catch (RecreateTargetException)
            {
                bitmap  = null;
                bitmap2 = null;
                bitmap3 = null;
            }
            if (((bitmap == null) || (bitmap2 == null)) || (bitmap3 == null))
            {
                flag = true;
            }
            else
            {
                using (dc.UseAntialiasMode(AntialiasMode.Aliased))
                {
                    Matrix3x2Float  identity;
                    RectFloat       renderedMaskSourceRect = this.renderedMaskSourceRect;
                    RectFloat       renderedCanvasBounds   = (RectFloat)this.renderedCanvasBounds;
                    Matrix3x2Double interimTransform       = this.renderedRenderParams.SelectionSnapshot.InterimTransform;
                    VectorDouble    scale = interimTransform.GetScale();
                    if (((interimTransform.HasInverse && (Math.Abs(scale.X) > 0.001)) && (Math.Abs(scale.Y) > 0.001)) && (base.Owner.SelectionSnapshot.GeometryVersion == this.renderedRenderParams.SelectionSnapshot.GeometryVersion))
                    {
                        Matrix3x2Double inverse = interimTransform.Inverse;
                        Matrix3x2Double num9    = base.Owner.Selection.GetInterimTransform();
                        Matrix3x2Double num10   = inverse * num9;
                        identity = (Matrix3x2Float)num10;
                    }
                    else
                    {
                        identity = Matrix3x2Float.Identity;
                    }
                    RectFloat num6 = (RectFloat)RectDouble.Inflate(renderedCanvasBounds, 1.0, 1.0);
                    RectFloat num7 = new RectFloat(PointFloat.Zero, (SizeFloat)this.renderedRenderParams.CanvasSize);
                    using (dc.UseAxisAlignedClip(num7, AntialiasMode.Aliased))
                    {
                        using (dc.UseTransformMultiply(identity, MatrixMultiplyOrder.Prepend))
                        {
                            IBrush cachedOrCreateResource = dc.GetCachedOrCreateResource <IBrush>(this.renderedRenderParams.InteriorBrush);
                            dc.FillOpacityMask(bitmap, cachedOrCreateResource, OpacityMaskContent.Graphics, new RectFloat?(renderedCanvasBounds), new RectFloat?(renderedMaskSourceRect));
                        }
                    }
                    using (dc.UseTransformMultiply(identity, MatrixMultiplyOrder.Prepend))
                    {
                        using (dc.UseAxisAlignedClip(num6, AntialiasMode.Aliased))
                        {
                            IBrush brush = dc.GetCachedOrCreateResource <IBrush>(blackBrush);
                            dc.FillOpacityMask(bitmap2, brush, OpacityMaskContent.Graphics, new RectFloat?(renderedCanvasBounds), new RectFloat?(renderedMaskSourceRect));
                            IBrush brush3 = dc.GetCachedOrCreateResource <IBrush>(whiteBrush);
                            dc.FillOpacityMask(bitmap3, brush3, OpacityMaskContent.Graphics, new RectFloat?(renderedCanvasBounds), new RectFloat?(renderedMaskSourceRect));
                        }
                    }
                }
                if (this.renderedRenderParams.ViewportCanvasBounds != base.CanvasView.ViewportCanvasBounds)
                {
                    flag = true;
                }
            }
            if (flag && !this.isRedrawing)
            {
                this.QueueBeginRedraw();
            }
        }
Example #15
0
        private static RectDouble CalculateInvalidRect(CanvasView canvasView, RectDouble canvasRect)
        {
            double canvasHairWidth = canvasView.CanvasHairWidth;

            return(RectDouble.Inflate(canvasRect, canvasHairWidth, canvasHairWidth));
        }