コード例 #1
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);
 }
コード例 #2
0
 public MoveToolChanges(IEnumerable <KeyValuePair <string, object> > drawingSettingsValues, MoveToolPixelSource pixelSource, ISurface <ColorBgra> bitmapSource, bool leaveCopyBehind, RectDouble baseBounds, Matrix3x2Double baseTransform, Matrix3x2Double deltaTransform, TransformEditingMode editingMode, Matrix3x2Double editTransform, PointDouble?rotationAnchorOffset) : base(drawingSettingsValues)
 {
     if (((pixelSource == MoveToolPixelSource.Bitmap) && (bitmapSource == null)) || ((pixelSource != MoveToolPixelSource.Bitmap) && (bitmapSource != null)))
     {
         ExceptionUtil.ThrowArgumentException($"MoveToolPixelSource.{pixelSource} specified, but bitmapSourcePersistenceKey={this.bitmapSourcePersistenceKey}");
     }
     if (bitmapSource == null)
     {
         this.bitmapSourcePO             = null;
         this.bitmapSourcePersistenceKey = Guid.Empty;
     }
     else
     {
         this.bitmapSourcePO             = new PersistedObject <ISurface <ColorBgra> >(bitmapSource, true);
         this.bitmapSourcePersistenceKey = PersistedObjectLocker.Add <ISurface <ColorBgra> >(this.bitmapSourcePO);
     }
     this.pixelSource          = pixelSource;
     this.leaveCopyBehind      = leaveCopyBehind;
     this.baseBounds           = baseBounds;
     this.baseTransform        = baseTransform;
     this.deltaTransform       = deltaTransform;
     this.editingMode          = editingMode;
     this.editTransform        = editTransform;
     this.rotationAnchorOffset = rotationAnchorOffset;
     this.Initialize();
 }
コード例 #3
0
        public MoveToolContentRenderer(BitmapLayer activeLayer, MoveToolChanges changes, Result <IRenderer <ColorAlpha8> > lazyDeltaSelectionMask, Result <IRenderer <ColorAlpha8> > lazyFinalSelectionMask) : base(activeLayer.Width, activeLayer.Height, false)
        {
            Validate.Begin().IsNotNull <BitmapLayer>(activeLayer, "activeLayer").IsNotNull <MoveToolChanges>(changes, "changes").IsNotNull <Result <IRenderer <ColorAlpha8> > >(lazyDeltaSelectionMask, "lazyDeltaSelectionMask").IsNotNull <Result <IRenderer <ColorAlpha8> > >(lazyFinalSelectionMask, "lazyFinalSelectionMask").Check();
            this.activeLayer            = activeLayer;
            this.changes                = changes;
            this.lazyDeltaSelectionMask = lazyDeltaSelectionMask;
            this.lazyFinalSelectionMask = lazyFinalSelectionMask;
            switch (changes.PixelSource)
            {
            case MoveToolPixelSource.ActiveLayer:
                this.source = activeLayer.Surface;
                break;

            case MoveToolPixelSource.Bitmap:
                this.source = changes.BitmapSource.Object;
                break;

            default:
                throw ExceptionUtil.InvalidEnumArgumentException <MoveToolPixelSource>(changes.PixelSource, "changes.PixelSource");
            }
            Matrix3x2Double matrix = changes.DeltaTransform * changes.EditTransform;

            if ((changes.MoveToolResamplingAlgorithm == ResamplingAlgorithm.NearestNeighbor) || changes.FinalTransform.IsIntegerTranslation)
            {
                this.sourceTx = new TransformedNearestNeighborContentRenderer(activeLayer.Size(), this.source, matrix);
            }
            else
            {
                RectDouble baseBounds        = changes.BaseBounds;
                RectInt32  srcCoverageBounds = changes.BaseTransform.Transform(baseBounds).Int32Bound;
                this.sourceTx = new TransformedBilinearContentRenderer(activeLayer.Size(), this.source, srcCoverageBounds, matrix);
            }
        }
コード例 #4
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);
        }
コード例 #5
0
 public SelectionSnapshot(Result <PaintDotNet.Rendering.GeometryList> lazyGeometryList, Result <IReadOnlyList <RectInt32> > lazyPixelatedScans, Matrix3x2Double interimTransform, RectDouble fastMaxBounds, bool isEmpty, int geometryVersion)
 {
     Validate.Begin().IsNotNull <Result <PaintDotNet.Rendering.GeometryList> >(lazyGeometryList, "lazyGeometryList").IsNotNull <Result <IReadOnlyList <RectInt32> > >(lazyPixelatedScans, "lazyPixelatedScans").Check();
     this.lazyGeometryList   = lazyGeometryList;
     this.lazyPixelatedScans = lazyPixelatedScans;
     this.interimTransform   = interimTransform;
     this.fastMaxBounds      = fastMaxBounds;
     this.isEmpty            = isEmpty;
     this.geometryVersion    = geometryVersion;
     this.isRectilinear      = LazyResult.New <bool>(() => this.GeometryList.Value.IsRectilinear, LazyThreadSafetyMode.ExecutionAndPublication, new SingleUseCriticalSection());
     this.isPixelated        = LazyResult.New <bool>(() => this.GeometryList.Value.IsPixelated, LazyThreadSafetyMode.ExecutionAndPublication, new SingleUseCriticalSection());
 }
コード例 #6
0
        private ShapeRenderData CreateRenderDataImpl(ShapeRenderParameters renderParams, Func <ShapeRenderParameters, ShapeRenderData> onCreate)
        {
            Validate.IsNotNull <ShapeRenderParameters>(renderParams, "renderParams");
            VerifyRenderSettingValues(this.RenderSettingPaths, renderParams.SettingValues);
            if (((!renderParams.StartPoint.IsFinite || !renderParams.EndPoint.IsFinite) || ((this.options.Elide == ShapeElideOption.ZeroWidthOrZeroHeight) && !RectDouble.FromCorners(renderParams.StartPoint, renderParams.EndPoint).HasPositiveArea)) || ((this.options.Elide == ShapeElideOption.ZeroWidthAndZeroHeight) && (renderParams.StartPoint == renderParams.EndPoint)))
            {
                return(new ShapeRenderData(Geometry.Empty));
            }
            ShapeRenderData renderData         = onCreate(renderParams);
            RectDouble      bounds             = RectDouble.FromCorners(renderParams.StartPoint, renderParams.EndPoint);
            Matrix3x2Double alignmentTransform = GetAlignmentTransform(renderData.Guide.Bounds, bounds);

            return(ShapeRenderData.Transform(renderData, alignmentTransform));
        }
コード例 #7
0
 public ShapesToolChanges(IEnumerable <KeyValuePair <string, object> > drawingSettingsValues, string shapeInfoSettingPath, IDictionary <PaintDotNet.Shapes.ShapeInfo, IDictionary <object, object> > allShapePropertyValues, PointDouble mouseStartPoint, PointDouble mouseEndPoint, bool shouldApplySnapping, bool shouldApplyConstraint, bool isEditingStartPoint, bool isEditingEndPoint, PaintDotNet.WhichUserColor whichUserColor, Matrix3x2Double transform, PointDouble?rotationAnchorOffset) : base(drawingSettingsValues)
 {
     this.shapeInfoSettingPath = shapeInfoSettingPath;
     this.InitializeAllShapePropertyValues(allShapePropertyValues);
     this.mouseStartPoint       = mouseStartPoint;
     this.mouseEndPoint         = mouseEndPoint;
     this.shouldApplySnapping   = shouldApplySnapping;
     this.shouldApplyConstraint = shouldApplyConstraint;
     this.isEditingStartPoint   = isEditingStartPoint;
     this.isEditingEndPoint     = isEditingEndPoint;
     this.whichUserColor        = whichUserColor;
     this.transform             = transform;
     this.rotationAnchorOffset  = rotationAnchorOffset;
     this.Initialize();
 }
コード例 #8
0
        private Matrix3x2Double GetMatrixToDevice()
        {
            base.VerifyAccess();
            CanvasView view = this.canvasViews.FirstOrDefault <CanvasView>();

            if (view == null)
            {
                return(Matrix3x2Double.Identity);
            }
            double          scaleRatio           = view.ScaleRatio;
            Matrix3x2Double num2                 = Matrix3x2Double.Scaling(scaleRatio, scaleRatio);
            PointDouble     viewportCanvasOffset = view.ViewportCanvasOffset;
            Matrix3x2Double num4                 = Matrix3x2Double.Translation(-viewportCanvasOffset.X, -viewportCanvasOffset.Y);

            return(num2 * num4);
        }
コード例 #9
0
 public MoveToolChanges(IEnumerable <KeyValuePair <string, object> > drawingSettingsValues, MoveToolPixelSource pixelSource, Guid bitmapSourcePersistenceKey, bool leaveCopyBehind, RectDouble baseBounds, Matrix3x2Double baseTransform, Matrix3x2Double deltaTransform, TransformEditingMode editingMode, Matrix3x2Double editTransform, PointDouble?rotationAnchorOffset) : base(drawingSettingsValues)
 {
     if (((pixelSource == MoveToolPixelSource.Bitmap) && (bitmapSourcePersistenceKey == Guid.Empty)) || ((pixelSource != MoveToolPixelSource.Bitmap) && (bitmapSourcePersistenceKey != Guid.Empty)))
     {
         ExceptionUtil.ThrowArgumentException($"MoveToolPixelSource.{pixelSource} specified, but bitmapSourcePersistenceKey={bitmapSourcePersistenceKey}");
     }
     this.pixelSource = pixelSource;
     this.bitmapSourcePersistenceKey = bitmapSourcePersistenceKey;
     this.leaveCopyBehind            = leaveCopyBehind;
     this.baseBounds           = baseBounds;
     this.baseTransform        = baseTransform;
     this.deltaTransform       = deltaTransform;
     this.editingMode          = editingMode;
     this.editTransform        = editTransform;
     this.rotationAnchorOffset = rotationAnchorOffset;
     this.Initialize();
 }
コード例 #10
0
        private static Matrix3x2Double GetAlignmentTransform(RectDouble geometryBounds, RectDouble bounds)
        {
            if (geometryBounds == bounds)
            {
                return(Matrix3x2Double.Identity);
            }
            double          dx     = bounds.X - geometryBounds.X;
            double          dy     = bounds.Y - geometryBounds.Y;
            double          x      = bounds.Width / geometryBounds.Width;
            double          scaleX = x.IsFinite() ? x : 1.0;
            double          num5   = bounds.Height / geometryBounds.Height;
            double          scaleY = num5.IsFinite() ? num5 : 1.0;
            Matrix3x2Double num7   = Matrix3x2Double.Translation(dx, dy);
            Matrix3x2Double num8   = Matrix3x2Double.ScalingAt(scaleX, scaleY, bounds.X, bounds.Y);

            return(num7 * num8);
        }
コード例 #11
0
        public ShapesToolChanges CloneWithNewTransform(Matrix3x2Double newTransform)
        {
            if (newTransform == this.transform)
            {
                return(this);
            }
            if (!(this.transform.GetScale() == newTransform.GetScale()))
            {
                return(new ShapesToolChanges(base.DrawingSettingsValues, this.ShapeInfoSettingPath, this.AllShapePropertyValues, this.MouseStartPoint, this.MouseEndPoint, this.ShouldApplySnapping, this.ShouldApplyConstraint, this.IsEditingStartPoint, this.IsEditingEndPoint, this.WhichUserColor, newTransform, this.RotationAnchorOffset));
            }
            Matrix3x2Double   relativeTx = this.transform.Inverse * newTransform;
            ShapesToolChanges changes    = (ShapesToolChanges)base.MemberwiseClone();

            using (changes.UseChangeScope())
            {
                changes.transform       = newTransform;
                changes.shapeRenderData = LazyResult.New <PaintDotNet.Shapes.ShapeRenderData>(() => PaintDotNet.Shapes.ShapeRenderData.Transform(this.shapeRenderData.Value, relativeTx), LazyThreadSafetyMode.ExecutionAndPublication, new SingleUseCriticalSection());
                changes.InvalidateCachedMaxRenderBounds();
            }
            return(changes);
        }
コード例 #12
0
        public static Surface CreateThumbnail(Surface sourceSurface, GeometryList maskGeometry, RectInt32 maskBounds, int thumbSideLength)
        {
            Surface dst = new Surface(ThumbnailHelpers.ComputeThumbnailSize(sourceSurface.Size <ColorBgra>(), thumbSideLength));

            dst.Clear(ColorBgra.Transparent);
            sourceSurface.ResizeFant(dst.Size <ColorBgra>()).Parallelize <ColorBgra>(TilingStrategy.HorizontalSlices, 5, WorkItemQueuePriority.Normal).Render <ColorBgra>(dst);
            Surface surface = new Surface(dst.Size <ColorBgra>());

            surface.Clear(ColorBgra.Black);
            using (PdnGraphicsPath path = new PdnGraphicsPath())
            {
                path.AddGeometryList(maskGeometry);
                double          scaleX = (maskBounds.Width == 0) ? 0.0 : (((double)dst.Width) / ((double)maskBounds.Width));
                double          scaleY = (maskBounds.Height == 0) ? 0.0 : (((double)dst.Height) / ((double)maskBounds.Height));
                Matrix3x2Double m      = Matrix3x2Double.Translation((double)-maskBounds.X, (double)-maskBounds.Y) * Matrix3x2Double.Scaling(scaleX, scaleY);
                using (RenderArgs args = new RenderArgs(surface))
                {
                    args.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                    using (Matrix matrix = m.ToGdipMatrix())
                    {
                        args.Graphics.Transform = matrix;
                    }
                    args.Graphics.FillPath(Brushes.White, (GraphicsPath)path);
                    args.Graphics.DrawPath(Pens.White, (GraphicsPath)path);
                }
            }
            new IntensityMaskOp().Apply(surface, dst, surface);
            RendererBgra.Checkers(dst.Size <ColorBgra>()).Render <ColorBgra>(dst);
            CompositionOps.Normal.Static.Apply(dst, dst, surface);
            surface.Dispose();
            surface = null;
            int recommendedExtent             = DropShadow.GetRecommendedExtent(dst.Size <ColorBgra>());
            ShadowDecorationRenderer renderer = new ShadowDecorationRenderer(dst, recommendedExtent);
            Surface surface3 = new Surface(renderer.Size <ColorBgra>());

            renderer.Render <ColorBgra>(surface3);
            return(surface3);
        }
コード例 #13
0
 private static void OnMouseMove(object sender, MouseEventArgs e)
 {
     PaintDotNet.UI.FrameworkElement visual = (PaintDotNet.UI.FrameworkElement)sender;
     if (visual.IsMouseCaptured)
     {
         CompositionTarget compositionTarget = PresentationSource.FromVisual(visual).CompositionTarget;
         PointDouble       position          = e.GetPosition(visual);
         bool flag = visual.HitTestLocal(position);
         SetIsPressed(visual, flag);
         if (GetIsDragging(visual))
         {
             visual.RaiseEvent(new MouseEventArgs(e.InputDevice, DragMoveEvent, visual));
         }
         else if (GetAllowDrag(visual))
         {
             VectorDouble    num8;
             PointDouble     mouseCapturePoint = GetMouseCapturePoint(visual);
             PointDouble     pt             = e.GetPosition(visual);
             Matrix3x2Double matrixToDevice = compositionTarget.MatrixToDevice;
             PointDouble     num5           = matrixToDevice.Transform(mouseCapturePoint);
             VectorDouble    num7           = (VectorDouble)(matrixToDevice.Transform(pt) - num5);
             if (GetAllowClick(visual))
             {
                 num8 = new VectorDouble(PaintDotNet.UI.SystemParameters.MinimumHorizontalDragDistance, PaintDotNet.UI.SystemParameters.MinimumVerticalDragDistance);
             }
             else
             {
                 num8 = new VectorDouble(0.0, 0.0);
             }
             if ((Math.Abs(num7.X) >= num8.X) || (Math.Abs(num7.Y) >= num8.Y))
             {
                 SetIsDragging(visual, true);
                 visual.RaiseEvent(new MouseEventArgs(e.InputDevice, DragBeginEvent, visual));
             }
         }
         e.Handled = true;
     }
 }
コード例 #14
0
        private void Initialize()
        {
            if ((this.allShapePropertyValuesMap == null) && (this.allShapePropertyValuesArray != null))
            {
                this.allShapePropertyValuesMap = ShapePropertyValuesUtil.ToReadOnlyMap(this.allShapePropertyValuesArray);
            }
            PaintDotNet.UI.Media.DashStyle style = DashStyleUtil.ToMedia(this.PenDashStyle);
            this.outlinePen = new Pen {
                Brush     = SolidColorBrushCache.Get((ColorRgba128Float)Colors.White),
                Thickness = this.PenWidth,
                LineJoin  = PenLineJoin.Miter,
                DashStyle = style
            }.EnsureFrozen <Pen>();
            RectDouble   baseBounds = this.BaseBounds;
            VectorDouble txScale    = this.Transform.GetScale();
            VectorDouble num3       = (VectorDouble)(this.EndPoint - this.StartPoint);
            PointDouble  endPoint   = new PointDouble(this.StartPoint.X + (num3.X * txScale.X), this.StartPoint.Y + (num3.Y * txScale.Y));
            Dictionary <string, object> settingValues = (from gsp in this.Shape.RenderSettingPaths select KeyValuePairUtil.Create <string, object>(gsp, base.GetDrawingSettingValue(gsp))).ToDictionary <string, object>();

            PaintDotNet.Shapes.ShapeRenderParameters renderParams = new PaintDotNet.Shapes.ShapeRenderParameters(this.StartPoint, endPoint, txScale, settingValues, null);
            this.shapePropertySchema = this.Shape.CreatePropertyCollection(renderParams);
            foreach (Property property in this.shapePropertySchema)
            {
                property.ValueChanged += delegate(object s, ValueEventArgs <object> e) {
                    throw new ReadOnlyException();
                };
                property.ReadOnlyChanged += delegate(object s, ValueEventArgs <bool> e) {
                    throw new ReadOnlyException();
                };
            }
            this.shapeRenderParams = new PaintDotNet.Shapes.ShapeRenderParameters(this.StartPoint, endPoint, txScale, settingValues, this.ShapePropertyValues);
            this.shapeRenderData   = LazyResult.New <PaintDotNet.Shapes.ShapeRenderData>(delegate {
                PaintDotNet.Shapes.ShapeRenderData renderData = this.Shape.CreateRenderData(this.shapeRenderParams);
                Matrix3x2Double matrix = Matrix3x2Double.ScalingAt(1.0 / Math.Abs(txScale.X), 1.0 / Math.Abs(txScale.Y), this.StartPoint.X, this.StartPoint.Y);
                return(PaintDotNet.Shapes.ShapeRenderData.Transform(PaintDotNet.Shapes.ShapeRenderData.Transform(renderData, matrix), this.transform));
            }, LazyThreadSafetyMode.ExecutionAndPublication, new SingleUseCriticalSection());
        }
コード例 #15
0
        public CachedGeometry GetTransformed(Matrix3x2Double matrix)
        {
            if (matrix.IsIdentity)
            {
                return(this);
            }
            bool flag = matrix.IsScaling();

            if (this.basis == null)
            {
                CachedGeometry geometry = new CachedGeometry(this.geometry.GetTransformedGeometry(matrix))
                {
                    basis = this
                };
                if (flag)
                {
                    geometry.basisUsage = BasisUsage.FillWithRelativeTransform;
                }
                else
                {
                    geometry.basisUsage = BasisUsage.FillWithRelativeTransform | BasisUsage.DrawWithRelativeTransform;
                }
                geometry.basisRelativeTx = new Matrix3x2Double?(matrix);
                return(geometry);
            }
            if (!flag && this.basisRelativeTx.Value.IsScaling())
            {
                return(new CachedGeometry(this.geometry.GetTransformedGeometry(matrix))
                {
                    basis = this,
                    basisUsage = BasisUsage.FillWithRelativeTransform | BasisUsage.DrawWithRelativeTransform,
                    basisRelativeTx = new Matrix3x2Double?(matrix)
                });
            }
            return(this.basis.GetTransformed(this.basisRelativeTx.Value * matrix));
        }
コード例 #16
0
        private static Geometry CreateStrokedLineGeometry(Geometry lineGeometry, double strokeWidth, LineCap2 startCap, LineCap2 endCap, PaintDotNet.UI.Media.DashStyle dashStyle)
        {
            Geometry    geometry;
            Geometry    geometry2;
            Geometry    geometry3;
            Geometry    geometry4;
            Geometry    geometry5;
            double      length      = lineGeometry.GetLength(flatteningTolerance);
            StrokeStyle strokeStyle = new StrokeStyle {
                DashStyle = dashStyle,
                LineJoin  = PenLineJoin.Round
            };
            double num2 = 0.0;

            switch (startCap)
            {
            case LineCap2.Flat:
                geometry = null;
                break;

            case LineCap2.Arrow:
                geometry = CreateArrowGeometry(5.0, 5.0, strokeWidth, 1.0, false, false).EnsureFrozen <Geometry>();
                num2     = 0.5;
                break;

            case LineCap2.ArrowFilled:
                geometry = CreateArrowGeometry(5.0, 5.0, strokeWidth, 1.0, true, true).EnsureFrozen <Geometry>();
                num2     = 1.5;
                break;

            case LineCap2.Rounded:
                strokeStyle.StartLineCap = PenLineCap.Round;
                geometry = null;
                break;

            default:
                throw ExceptionUtil.InvalidEnumArgumentException <LineCap2>(startCap, "startCap");
            }
            double num3 = 0.0;

            switch (endCap)
            {
            case LineCap2.Flat:
                geometry2 = null;
                break;

            case LineCap2.Arrow:
                geometry2 = CreateArrowGeometry(5.0, 5.0, strokeWidth, 1.0, false, false).EnsureFrozen <Geometry>();
                num3      = 0.5;
                break;

            case LineCap2.ArrowFilled:
                geometry2 = CreateArrowGeometry(5.0, 5.0, strokeWidth, 1.0, true, true).EnsureFrozen <Geometry>();
                num3      = 1.5;
                break;

            case LineCap2.Rounded:
                strokeStyle.EndLineCap = PenLineCap.Round;
                geometry2 = null;
                break;

            default:
                throw ExceptionUtil.InvalidEnumArgumentException <LineCap2>(endCap, "endCap");
            }
            strokeStyle.Freeze();
            if (geometry == null)
            {
                geometry3 = null;
            }
            else
            {
                PointAndTangentDouble pointAtLength = lineGeometry.GetPointAtLength(0.0, flatteningTolerance);
                double          radians             = Math.Atan2(pointAtLength.Tangent.Y, pointAtLength.Tangent.X) + 3.1415926535897931;
                Matrix3x2Double num9   = Matrix3x2Double.RotationByRadians(radians);
                Matrix3x2Double num10  = Matrix3x2Double.Translation(pointAtLength.Point.X, pointAtLength.Point.Y);
                Matrix3x2Double matrix = num9 * num10;
                geometry3 = geometry.GetTransformedGeometry(matrix).EnsureFrozen <Geometry>();
            }
            if (geometry2 == null)
            {
                geometry4 = null;
            }
            else
            {
                double num14 = lineGeometry.GetLength(flatteningTolerance);
                PointAndTangentDouble num15 = lineGeometry.GetPointAtLength(num14, flatteningTolerance);
                Matrix3x2Double       num18 = Matrix3x2Double.RotationByRadians(Math.Atan2(num15.Tangent.Y, num15.Tangent.X));
                Matrix3x2Double       num19 = Matrix3x2Double.Translation(num15.Point.X, num15.Point.Y);
                Matrix3x2Double       num20 = num18 * num19;
                geometry4 = geometry2.GetTransformedGeometry(num20).EnsureFrozen <Geometry>();
            }
            double startLength = 0.0;
            double endLength   = length;

            if (num2 != 0.0)
            {
                startLength = strokeWidth * num2;
            }
            if (num3 != 0.0)
            {
                endLength = length - (strokeWidth * num3);
            }
            if ((startLength != 0.0) || (endLength != length))
            {
                geometry5 = GetTrimmedGeometry(lineGeometry, startLength, endLength).EnsureFrozen <Geometry>();
            }
            else
            {
                geometry5 = lineGeometry;
            }
            Geometry item = new WidenedGeometry(geometry5, strokeWidth, strokeStyle)
            {
                FlatteningTolerance = flatteningTolerance
            }.EnsureFrozen <WidenedGeometry>();
            GeometryGroup group = new GeometryGroup {
                FillRule = FillRule.Nonzero
            };

            group.Children.Add(item);
            if (geometry3 != null)
            {
                group.Children.Add(geometry3);
            }
            if (geometry4 != null)
            {
                group.Children.Add(geometry4);
            }
            group.Freeze();
            return(group);
        }
コード例 #17
0
        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();
            }
        }
コード例 #18
0
 public MoveHandleCanvasLayer()
 {
     this.calculateInvalidRect = new CalculateInvalidRectCallback(this.CalculateInvalidRect);
     this.handleTransform      = Matrix3x2Double.Identity;
 }
コード例 #19
0
 public static Matrix ToGdipMatrix(this Matrix3x2Double m) =>
 new Matrix((float)m.M11, (float)m.M12, (float)m.M21, (float)m.M22, (float)m.OffsetX, (float)m.OffsetY);
コード例 #20
0
 public SelectionInterimTransformHistoryMemento(string name, ImageResource image, IHistoryWorkspace historyWorkspace) : base(name, image)
 {
     this.historyWorkspace = historyWorkspace;
     this.interimTx        = historyWorkspace.Selection.GetInterimTransform();
 }
コード例 #21
0
ファイル: ShapeRenderData.cs プロジェクト: ykafia/Paint.Net4
        public static ShapeRenderData Transform(ShapeRenderData renderData, Matrix3x2Double matrix)
        {
            Validate.IsNotNull <ShapeRenderData>(renderData, "renderData");
            if (matrix.IsIdentity)
            {
                return(renderData);
            }
            CachedGeometry transformed  = renderData.Guide.GetTransformed(matrix);
            CachedGeometry interiorFill = null;

            if (renderData.InteriorFill != null)
            {
                if (renderData.InteriorFill.Equals(renderData.Guide))
                {
                    interiorFill = transformed;
                }
                else
                {
                    interiorFill = renderData.InteriorFill.GetTransformed(matrix);
                }
            }
            CachedGeometry outlineDraw = null;

            if (renderData.OutlineDraw != null)
            {
                if (renderData.OutlineDraw.Equals(renderData.Guide))
                {
                    outlineDraw = transformed;
                }
                else if (renderData.OutlineDraw.Equals(renderData.InteriorFill))
                {
                    outlineDraw = interiorFill;
                }
                else
                {
                    outlineDraw = renderData.OutlineDraw.GetTransformed(matrix);
                }
            }
            CachedGeometry outlineFill = null;

            if (renderData.OutlineFill != null)
            {
                if (renderData.OutlineFill.Equals(renderData.Guide))
                {
                    outlineFill = transformed;
                }
                else if (renderData.OutlineFill.Equals(renderData.InteriorFill))
                {
                    outlineFill = interiorFill;
                }
                else if (renderData.OutlineFill.Equals(renderData.OutlineDraw))
                {
                    outlineFill = outlineDraw;
                }
                else
                {
                    outlineFill = renderData.OutlineFill.GetTransformed(matrix);
                }
            }
            return(new ShapeRenderData(transformed, interiorFill, outlineDraw, outlineFill));
        }