private void RenderSelection(IDrawingContext dc, float scale, PointFloat offset, SelectionRenderParameters renderParams, Result <IGeometry> lazyGeometry, IBrush interiorBrush, IBrush outlineBrush, IStrokeStyle outlineStrokeStyle, AntialiasMode antialiasMode) { using (dc.UseScaleTransform(scale, scale, MatrixMultiplyOrder.Prepend)) { using (dc.UseTranslateTransform(offset.X, offset.Y, MatrixMultiplyOrder.Prepend)) { if (renderParams.IsInteriorFilled && (interiorBrush != null)) { using (dc.UseAntialiasMode(AntialiasMode.Aliased)) { dc.FillGeometry(lazyGeometry.Value, interiorBrush, null); } } if (renderParams.IsOutlineEnabled && (outlineBrush != null)) { float strokeWidth = this.outlineStrokeWidthPx / scale; using (dc.UseAntialiasMode(antialiasMode)) { using (dc.UseTranslateTransform(0.5f, 0.5f, MatrixMultiplyOrder.Append)) { dc.DrawGeometry(lazyGeometry.Value, outlineBrush, strokeWidth, outlineStrokeStyle); } } } } } }
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); }
public void Fill(IDrawingContext dc, IBrush brush) { if ((this.basis != null) && ((this.basisUsage & BasisUsage.FillWithRelativeTransform) == BasisUsage.FillWithRelativeTransform)) { using (dc.UseTransformMultiply((Matrix3x2Float)this.basisRelativeTx.Value, MatrixMultiplyOrder.Prepend)) { this.basis.Fill(dc, brush); return; } } dc.FillGeometry(this.GetPerThreadDirect2DGeometry(), brush, null); }
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); }
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); }
private void DrawToDrawingContext(IDrawingContext dc) { RectInt32 rect = base.ClientRectangle.ToRectInt32(); dc.Clear(new ColorRgba128Float?(this.BackColor)); using (dc.UseTranslateTransform(0.5f, 0.5f, MatrixMultiplyOrder.Append)) { using (dc.UseAntialiasMode(AntialiasMode.PerPrimitive)) { RectInt32 num2 = RectInt32.Inflate(rect, -2, -2); int num3 = Math.Min(num2.Width, num2.Height); PointInt32 center = new PointInt32(num2.X + (num3 / 2), num2.Y + (num3 / 2)); double radius = ((double)num3) / 2.0; double scale = ((double)num3) / 3.0; double num7 = ((double)num3) / 2.0; double d = -MathUtil.DegreesToRadians(this.angle); double num9 = Math.Cos(d); double num10 = Math.Sin(d); double rx = (this.rollAmount * Math.Cos(MathUtil.DegreesToRadians(this.rollDirection))) / 90.0; double num12 = (this.rollAmount * Math.Sin(MathUtil.DegreesToRadians(this.rollDirection))) / 90.0; double num13 = rx / (((num12 * num12) < 0.99) ? Math.Sqrt(1.0 - (num12 * num12)) : 1.0); double num14 = num12 / (((rx * rx) < 0.99) ? Math.Sqrt(1.0 - (rx * rx)) : 1.0); double thickness = (this.mouseEntered && !this.onSphere) ? 2.0 : 1.0; if (this.ringOuterEllipseGeometry == null) { this.ringOuterEllipseGeometry = new EllipseGeometry(); } if (this.ringInnerEllipseGeometry == null) { this.ringInnerEllipseGeometry = new EllipseGeometry(); } if (this.ringFillGeometry == null) { this.ringFillGeometry = new CombinedGeometry(GeometryCombineMode.Exclude, this.ringOuterEllipseGeometry, this.ringInnerEllipseGeometry); } this.ringOuterEllipseGeometry.Center = center; this.ringOuterEllipseGeometry.RadiusX = radius - 0.5; this.ringOuterEllipseGeometry.RadiusY = radius - 0.5; this.ringInnerEllipseGeometry.Center = center; this.ringInnerEllipseGeometry.RadiusX = radius; this.ringInnerEllipseGeometry.RadiusY = radius; dc.FillGeometry(this.ringFillGeometry, ringFillBrush, null); if (this.ringOutlinePen == null) { this.ringOutlinePen = new PaintDotNet.UI.Media.Pen(); } this.ringOutlinePen.Brush = ringOutlineBrush; this.ringOutlinePen.Thickness = thickness; dc.DrawCircle(center, radius, this.ringOutlinePen); double num16 = (this.mouseEntered && !this.onSphere) ? ((double)2) : ((double)1); dc.DrawLine(center.X + (scale * num9), center.Y + (scale * num10), center.X + (num7 * num9), center.Y + (num7 * num10), thetaLineBrush, num16); using (dc.UseTranslateTransform((float)center.X, (float)center.Y, MatrixMultiplyOrder.Prepend)) { double num17 = (this.angle * 3.1415926535897931) / 180.0; float num18 = (this.mouseEntered && this.onSphere) ? 1.5f : 1f; int num19 = 0x18; for (int i = 0; i >= (-num19 / 2); i--) { double num22 = (i * 3.1415926535897931) / ((double)num19); double num23 = -num17 - 3.1415926535897931; double xs = Math.Cos(num23) * Math.Cos(num22); double ys = Math.Sin(num23) * Math.Cos(num22); double zs = Math.Sin(num22); double num30 = ((double)(i + (num19 / 2))) / ((double)(num19 / 2)); byte index = Int32Util.ClampToByte((int)(num30 * 255.0)); if (this.latBrushCache[index] == null) { ColorBgra bgra = ColorBgra.Blend(latGradStart, latGradEnd, index); this.latBrushCache[index] = SolidColorBrushCache.Get((ColorRgba128Float)bgra); } SolidColorBrush brush = this.latBrushCache[index]; for (int k = -num19 * 6; k <= (num19 * 6); k++) { num23 = -num17 + ((k * 3.1415926535897931) / ((double)(num19 * 6))); double num33 = Math.Cos(num22); double num34 = Math.Sin(num22); double xe = Math.Cos(num23) * Math.Cos(num22); double ye = Math.Sin(num23) * Math.Cos(num22); double ze = Math.Sin(num22); double num35 = (this.mouseEntered && this.onSphere) ? 1.5 : 1.0; this.Draw3DLine(dc, rx, -num12, scale, xs, ys, zs, xe, ye, ze, brush, num35); xs = xe; ys = ye; zs = ze; } } int num20 = 4; for (int j = -num20; j < num20; j++) { double num37 = -num17 + ((j * 3.1415926535897931) / ((double)num20)); double num38 = -1.5707963267948966; double num39 = Math.Cos(num37) * Math.Cos(num38); double num40 = Math.Sin(num37) * Math.Cos(num38); double num41 = Math.Sin(num38); for (int m = -num20 * 4; m <= 0; m++) { num38 = (m * 3.1415926535897931) / ((double)(num20 * 8)); double num42 = Math.Cos(num37) * Math.Cos(num38); double num43 = Math.Sin(num37) * Math.Cos(num38); double num44 = Math.Sin(num38); double num46 = (this.mouseEntered && this.onSphere) ? 2.0 : 1.0; this.Draw3DLine(dc, rx, -num12, scale, num39, num40, num41, num42, num43, num44, lightBrush, num46); num39 = num42; num40 = num43; num41 = num44; } } } dc.DrawCircle(center, scale, ringInlineBrush, thickness); } } }