public PropertyCollection CreatePropertyCollection(ShapeRenderParameters renderParams) { Validate.IsNotNull <ShapeRenderParameters>(renderParams, "renderParams"); if (renderParams.HasPropertyValues) { throw new ArgumentException("renderParams.HasPropertyValues must be false"); } return(this.OnCreatePropertyCollection(renderParams).Clone()); }
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)); }
protected sealed override ShapeRenderData OnCreateRenderData(ShapeRenderParameters renderParams) { ShapeDrawType type = (ShapeDrawType)renderParams.SettingValues[ToolSettings.Null.Shapes.DrawType.Path]; RectDouble bounds = RectDouble.FromCorners(renderParams.StartPoint, renderParams.EndPoint); Geometry guideGeometry = this.OnCreateGuideGeometry(bounds, renderParams.SettingValues); Geometry interiorFillGeometry = null; if ((type & ShapeDrawType.Interior) == ShapeDrawType.Interior) { interiorFillGeometry = this.OnCreateInteriorFillGeometry(bounds, renderParams.SettingValues); } Geometry outlineDrawGeometry = null; Geometry outlineFillGeometry = null; if ((type & ShapeDrawType.Outline) == ShapeDrawType.Outline) { outlineDrawGeometry = this.OnCreateOutlineDrawGeometry(bounds, renderParams.SettingValues); outlineFillGeometry = this.OnCreateOutlineFillGeometry(bounds, renderParams.SettingValues); } return(new ShapeRenderData(guideGeometry, interiorFillGeometry, outlineDrawGeometry, outlineFillGeometry)); }
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()); }
private ImageResource CreateImageResource(int width, int height, double borderSize) { ImageResource resource2; double x = borderSize / 2.0; using (ISurface <ColorBgra> surface = SurfaceAllocator.Bgra.Allocate(width, height, AllocationOptions.ZeroFillNotRequired)) { using (IDrawingContext context = DrawingContext.FromSurface(surface, AlphaMode.Premultiplied, FactorySource.PerThread)) { RectDouble num4; context.Clear(null); RectDouble num2 = new RectDouble(x, x, width - borderSize, height - borderSize); double aspectRatio = this.AspectRatio; if (aspectRatio > 1.0) { double num5 = num2.Height / aspectRatio; num4 = new RectDouble(num2.X, num2.Y + ((num2.Height - num5) / 2.0), num2.Width, num5); } else if (aspectRatio < 1.0) { double num6 = num2.Width * aspectRatio; num4 = new RectDouble(num2.X + ((num2.Width - num6) / 2.0), num2.Y, num6, num2.Height); } else { num4 = num2; } IDictionary <string, object> settingValues = (from p in this.RenderSettingPaths select KeyValuePairUtil.Create <string, object>(p, AppSettings.Instance[ConvertToolsPathToToolDefaultsPath(p)].Value)).ToDictionary <string, object>(); ShapeRenderParameters renderParams = new ShapeRenderParameters(num4.TopLeft, num4.BottomRight, new VectorDouble(1.0, 1.0), settingValues, null); PropertyCollection properties = this.CreatePropertyCollection(renderParams); this.OnSetImagePropertyCollectionValues(renderParams, properties); IDictionary <object, object> propertyValues = (from p in properties select KeyValuePairUtil.Create <object, object>(p.GetOriginalNameValue(), p.Value)).ToDictionary <object, object>(); ShapeRenderParameters parameters2 = new ShapeRenderParameters(num4.TopLeft, num4.BottomRight, new VectorDouble(1.0, 1.0), settingValues, propertyValues); ShapeRenderData data = this.CreateImageRenderData(parameters2); PaintDotNet.UI.Media.Brush brush = SolidColorBrushCache.Get((ColorRgba128Float)ColorBgra.FromUInt32(0xff5894c1)); if (data.InteriorFill != null) { context.FillGeometry(data.InteriorFill.Geometry, SolidColorBrushCache.Get((ColorRgba128Float)Colors.White), null); LinearGradientBrush brush2 = new LinearGradientBrush { StartPoint = num4.TopLeft, EndPoint = num4.BottomRight }; brush2.GradientStops.Add(new GradientStop((ColorRgba128Float)ColorBgra32.FromUInt32(0xffc0e1f3), 0.0)); brush2.GradientStops.Add(new GradientStop((ColorRgba128Float)ColorBgra32.FromUInt32(0xffe0eff8), 1.0)); context.FillGeometry(data.InteriorFill.Geometry, brush2, null); } if ((data.InteriorFill != null) && (data.OutlineDraw != null)) { RenderLayer layer = RenderLayerCache.Get(); using (context.UseLayer(layer, null, data.InteriorFill.Geometry, AntialiasMode.PerPrimitive, null, 1.0, null, LayerOptions.None)) { context.DrawGeometry(data.OutlineDraw.Geometry, SolidColorBrushCache.Get((ColorRgba128Float)Colors.White), 3.0); } RenderLayerCache.Return(layer); } if (data.OutlineDraw != null) { context.DrawGeometry(data.OutlineDraw.Geometry, brush, 1.0); } if (data.OutlineFill != null) { context.FillGeometry(data.OutlineFill.Geometry, brush, null); } string imageStringOverlay = this.ImageStringOverlay; if (imageStringOverlay != string.Empty) { double num7 = (width * 7.0) / 16.0; double fontSize = UIUtil.ScaleWidth(num7); TextLayout textLayout = new TextLayout(imageStringOverlay, "Arial", FontWeight.Normal, PaintDotNet.DirectWrite.FontStyle.Normal, FontStretch.Normal, fontSize) { ParagraphAlignment = ParagraphAlignment.Center, TextAlignment = PaintDotNet.DirectWrite.TextAlignment.Center, MaxWidth = width - 2, MaxHeight = height - 2 }; context.DrawTextLayout(new PointDouble(1.0, 1.0), textLayout, SolidColorBrushCache.Get((ColorRgba128Float)ColorBgra.FromUInt32(0xff5894c1)), DrawTextOptions.None); } } surface.ConvertFromPremultipliedAlpha(); using (System.Drawing.Bitmap bitmap = surface.CreateAliasedGdipBitmap()) { System.Drawing.Bitmap image = new System.Drawing.Bitmap(bitmap); resource2 = ImageResource.FromImage(image); } } return(resource2); }
public ShapeRenderData CreateImageRenderData(ShapeRenderParameters renderParams) => this.CreateRenderDataImpl(renderParams, new Func <ShapeRenderParameters, ShapeRenderData>(this.OnCreateImageRenderData));
protected virtual void OnSetImagePropertyCollectionValues(ShapeRenderParameters renderParams, PropertyCollection properties) { }
protected abstract ShapeRenderData OnCreateRenderData(ShapeRenderParameters renderParams);
protected virtual PropertyCollection OnCreatePropertyCollection(ShapeRenderParameters renderParams) => PropertyCollection.CreateEmpty();
protected virtual ShapeRenderData OnCreateImageRenderData(ShapeRenderParameters renderParams) => this.OnCreateRenderData(renderParams);
protected sealed override ShapeRenderData OnCreateImageRenderData(ShapeRenderParameters renderParams) { RectDouble bounds = RectDouble.FromCorners(renderParams.StartPoint, renderParams.EndPoint); return(new ShapeRenderData(this.OnCreateImageGeometry(bounds, renderParams.SettingValues))); }