/// <summary> /// Draws the outline of the specified geometry with given brush. /// </summary> /// <param name="geometry">The <see cref="ID2D1Geometry"/> to draw. </param> /// <param name="brush">The <see cref="ID2D1Brush"/> used to paint the geometry's stroke. </param> /// <param name="strokeWidth">The thickness of the geometry's stroke. The stroke is centered on the geometry's outline.</param> public void DrawGeometry(ID2D1Geometry geometry, ID2D1Brush brush, float strokeWidth) { DrawGeometry(geometry, brush, strokeWidth, null); }
public ID2D1TransformedGeometry CreateTransformedGeometry(ID2D1Geometry sourceGeometry, Matrix3x2 transform) { return(CreateTransformedGeometry(sourceGeometry, ref transform)); }
/// <summary> /// Draws the outline of the specified geometry. /// </summary> /// <param name="geometry">The <see cref="ID2D1Geometry"/> to draw.</param> /// <param name="brush">The brush used to paint the geometry's stroke.</param> public void DrawGeometry(ID2D1Geometry geometry, ID2D1Brush brush) { DrawGeometry(geometry, brush, 1.0f, null); }
/// <summary> /// Sets the current geometry of this object. /// </summary> /// <param name="geometry">The new geometry to be set.</param> /// <param name="flatteningTolerance">The maximum bounds on the distance between points in the polygonal approximation of the geometry. Smaller values produce more accurate results but cause slower execution.</param> /// <param name="extrudeOptions">Additional options for extruding.</param> internal void SetGeometry( D2D.ID2D1Geometry geometry, float flatteningTolerance, ExtrudeGeometryOptions extrudeOptions = ExtrudeGeometryOptions.None) { // Get triangles out of given geometry List <D2D.Triangle[]>?generatedTriangles = null; using (var tessellationSink = new ExtruderTessellationSink()) { geometry.Tessellate(flatteningTolerance, tessellationSink); generatedTriangles = tessellationSink.Triangles; } // Ensure that triangle list is created if (_generatedTriangles == null) { _generatedTriangles = new List <D2D.Triangle[]>(); } // Define methods for calculating bounds var minX = float.MaxValue; var maxX = float.MinValue; var minY = float.MaxValue; var maxY = float.MinValue; var minPoint = Vector2.Zero; void UpdateMinWidthHeight(PointF actCorner) { if (actCorner.X < minX) { minX = actCorner.X; } if (actCorner.X > maxX) { maxX = actCorner.X; } if (actCorner.Y < minY) { minY = actCorner.Y; } if (actCorner.Y > maxY) { maxY = actCorner.Y; } } // Do some postprocessing var triangleCount = 0; var bounds = new SizeF(); foreach (var actTriangleArray in generatedTriangles) { foreach (var actTriangle in actTriangleArray) { UpdateMinWidthHeight(actTriangle.Point1); UpdateMinWidthHeight(actTriangle.Point2); UpdateMinWidthHeight(actTriangle.Point3); triangleCount++; } } if (triangleCount > 0) { bounds = new SizeF(maxX - minX, maxY - minY); minPoint = new Vector2(minX, minY); } // Change with / height of the geometry depending on ExtrudeGeometryOptions if (extrudeOptions.HasFlag(ExtrudeGeometryOptions.RescaleToUnitSize)) { var scaleFactorX = !EngineMath.EqualsWithTolerance(bounds.Width, 0f) ? 1f / bounds.Width : 1f; var scaleFactorY = !EngineMath.EqualsWithTolerance(bounds.Height, 0f) ? 1f / bounds.Height : 1f; if (scaleFactorX < scaleFactorY) { scaleFactorY = scaleFactorX; } else { scaleFactorX = scaleFactorY; } foreach (var actTriangleArray in generatedTriangles) { for (var loop = 0; loop < actTriangleArray.Length; loop++) { var actTriangle = actTriangleArray[loop]; actTriangle.Point1 = new PointF(actTriangle.Point1.X * scaleFactorX, actTriangle.Point1.Y * scaleFactorY); actTriangle.Point2 = new PointF(actTriangle.Point2.X * scaleFactorX, actTriangle.Point2.Y * scaleFactorY); actTriangle.Point3 = new PointF(actTriangle.Point3.X * scaleFactorX, actTriangle.Point3.Y * scaleFactorY); actTriangleArray[loop] = actTriangle; } } bounds = new SizeF( bounds.Width * scaleFactorX, bounds.Height * scaleFactorY); minPoint = new Vector2(minPoint.X * scaleFactorX, minPoint.Y * scaleFactorY); } // Change the origin depending on ExtrudeGeometryOptions if (extrudeOptions.HasFlag(ExtrudeGeometryOptions.ChangeOriginToCenter)) { var newOrigin = new Vector2( minPoint.X + bounds.Width / 2f, minPoint.Y + bounds.Height / 2f); foreach (var actTriangleArray in generatedTriangles) { for (var loop = 0; loop < actTriangleArray.Length; loop++) { var actTriangle = actTriangleArray[loop]; actTriangle.Point1 = MathConverter.RawFromVector2(MathConverter.Vector2FromRaw(actTriangle.Point1) - newOrigin); actTriangle.Point2 = MathConverter.RawFromVector2(MathConverter.Vector2FromRaw(actTriangle.Point2) - newOrigin); actTriangle.Point3 = MathConverter.RawFromVector2(MathConverter.Vector2FromRaw(actTriangle.Point3) - newOrigin); actTriangleArray[loop] = actTriangle; } } minPoint = new Vector2(0f, 0f); } // Apply values this.TriangleCount = triangleCount; this.Bounds = bounds; _generatedTriangles = generatedTriangles; }
/// <summary> /// Sets the current geometry of this object. /// </summary> /// <param name="geometry">The new geometry to be set.</param> /// <param name="flatteningTolerance">The maximum bounds on the distance between points in the polygonal approximation of the geometry. Smaller values produce more accurate results but cause slower execution.</param> /// <param name="extrudeOptions">Additional options for extruding.</param> public void SetGeometry( D2D.ID2D1Geometry geometry, float flatteningTolerance, ExtrudeGeometryOptions extrudeOptions = ExtrudeGeometryOptions.None) { _owner.SetGeometry(geometry, flatteningTolerance, extrudeOptions); }
/// <summary> /// Describes the intersection between this geometry and the specified geometry. The comparison is performed by using the specified flattening tolerance. /// </summary> /// <remarks> /// When interpreting the returned relation value, it is important to remember that the member <see cref="F:SharpDX.Direct2D1.GeometryRelation.IsContained" /> of the D2D1_GEOMETRY_RELATION enumeration type means that this geometry is contained inside inputGeometry, not that this geometry contains inputGeometry. For more information about how to interpret other possible return values, see <see cref="T:SharpDX.Direct2D1.GeometryRelation" />. /// </remarks> /// <param name="inputGeometry">The geometry to test. </param> /// <param name="flatteningTolerance">The maximum bounds on the distance between points in the polygonal approximation of the geometries. Smaller values produce more accurate results but cause slower execution. </param> /// <returns>When this method returns, contains a reference to a value that describes how this geometry is related to inputGeometry. You must allocate storage for this parameter. </returns> /// <unmanaged>HRESULT ID2D1Geometry::CompareWithGeometry([In] ID2D1Geometry* inputGeometry,[In, Optional] const D2D1_MATRIX_3X2_F* inputGeometryTransform,[None] float flatteningTolerance,[Out] D2D1_GEOMETRY_RELATION* relation)</unmanaged> public GeometryRelation CompareWithGeometry(ID2D1Geometry inputGeometry, float flatteningTolerance) { return(CompareWithGeometry(inputGeometry, null, flatteningTolerance)); }
/// <summary> /// Combines this geometry with the specified geometry and stores the result in an <see cref="ID2D1SimplifiedGeometrySink"/>. /// </summary> /// <param name="inputGeometry">The geometry to combine with this instance.</param> /// <param name="combineMode">The type of combine operation to perform.</param> /// <param name="flatteningTolerance">The maximum bounds on the distance between points in the polygonal approximation of the geometries. Smaller values produce more accurate results but cause slower execution. </param> /// <param name="geometrySink">The result of the combine operation.</param> /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns> /// <unmanaged>HRESULT CombineWithGeometry([In] ID2D1Geometry* inputGeometry,[None] D2D1_COMBINE_MODE combineMode,[In, Optional] const D2D1_MATRIX_3X2_F* inputGeometryTransform,[None] FLOAT flatteningTolerance,[In] ID2D1SimplifiedGeometrySink* geometrySink)</unmanaged> public void CombineWithGeometry(ID2D1Geometry inputGeometry, CombineMode combineMode, float flatteningTolerance, ID2D1GeometrySink geometrySink) { CombineWithGeometry(inputGeometry, combineMode, null, flatteningTolerance, geometrySink); }