Example #1
0
        public static void DrawText(this ID2D1RenderTarget renderTarget,
                                    string text,
                                    IDWriteTextFormat format,
                                    D2D_RECT_F rect,
                                    ID2D1Brush brush,
                                    D2D1_DRAW_TEXT_OPTIONS options      = D2D1_DRAW_TEXT_OPTIONS.D2D1_DRAW_TEXT_OPTIONS_NONE,
                                    DWRITE_MEASURING_MODE measuringMode = DWRITE_MEASURING_MODE.DWRITE_MEASURING_MODE_NATURAL)
        {
            if (renderTarget == null)
            {
                throw new ArgumentNullException(nameof(renderTarget));
            }

            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }

            if (text == null)
            {
                return;
            }

            renderTarget.DrawTextW(text, (uint)text.Length, format, ref rect, brush, options, measuringMode);
        }
Example #2
0
        public static void DrawText(this ID2D1DeviceContext context,
                                    string text,
                                    IDWriteTextFormat format,
                                    D2D_RECT_F rect,
                                    ID2D1Brush defaultFillBrush,
                                    D2D1_DRAW_TEXT_OPTIONS options      = D2D1_DRAW_TEXT_OPTIONS.D2D1_DRAW_TEXT_OPTIONS_NONE,
                                    DWRITE_MEASURING_MODE measuringMode = DWRITE_MEASURING_MODE.DWRITE_MEASURING_MODE_NATURAL)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }

            if (defaultFillBrush == null)
            {
                throw new ArgumentNullException(nameof(defaultFillBrush));
            }

            if (text == null)
            {
                return;
            }

            context.DrawTextW(text, (uint)text.Length, format, ref rect, defaultFillBrush, options, measuringMode);
        }
        public static void DrawText(this ID2D1DeviceContext device,
                                    string text,
                                    IDWriteTextFormat format,
                                    D2D_RECT_F rect,
                                    ID2D1Brush brush,
                                    D2D1_DRAW_TEXT_OPTIONS options      = D2D1_DRAW_TEXT_OPTIONS.D2D1_DRAW_TEXT_OPTIONS_NONE,
                                    DWRITE_MEASURING_MODE measuringMode = DWRITE_MEASURING_MODE.DWRITE_MEASURING_MODE_NATURAL)
        {
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }

            if (text == null)
            {
                return;
            }

#pragma warning disable CA2010 // Always consume the value returned by methods marked with PreserveSigAttribute
            device.DrawTextW(text, (uint)text.Length, format, ref rect, brush, options, measuringMode);
#pragma warning restore CA2010 // Always consume the value returned by methods marked with PreserveSigAttribute
        }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="D2D1LayerParameters"/> struct.
 /// </summary>
 /// <param name="contentBounds">The content bounds of the layer. Content outside these bounds is not guaranteed to render.</param>
 /// <param name="geometricMask">The geometric mask specifies the area of the layer that is composited into the render target.</param>
 /// <param name="maskAntialiasMode">A value that specifies the antialiasing mode for the geometricMask.</param>
 /// <param name="maskTransform">A value that specifies the transform that is applied to the geometric mask when composing the layer.</param>
 /// <param name="opacity">An opacity value that is applied uniformly to all resources in the layer when compositing to the target.</param>
 /// <param name="opacityBrush">A brush that is used to modify the opacity of the layer. The brush is mapped to the layer, and the alpha channel of each mapped brush pixel is multiplied against the corresponding layer pixel.</param>
 /// <param name="layerOptions">A value that specifies whether the layer intends to render text with ClearType antialiasing.</param>
 public D2D1LayerParameters(
     D2D1RectF contentBounds,
     D2D1Geometry geometricMask,
     D2D1AntialiasMode maskAntialiasMode,
     D2D1Matrix3X2F maskTransform,
     float opacity,
     D2D1Brush opacityBrush,
     D2D1LayerOptions layerOptions)
 {
     this.contentBounds     = contentBounds;
     this.geometricMask     = geometricMask == null ? null : geometricMask.GetHandle <ID2D1Geometry>();
     this.maskAntialiasMode = maskAntialiasMode;
     this.maskTransform     = maskTransform;
     this.opacity           = opacity;
     this.opacityBrush      = opacityBrush == null ? null : opacityBrush.GetHandle <ID2D1Brush>();
     this.layerOptions      = layerOptions;
 }
Example #5
0
        public static void DrawTextLayout(this ID2D1RenderTarget context,
                                          D2D_POINT_2F origin,
                                          IDWriteTextLayout layout,
                                          ID2D1Brush defaultFillBrush    = null,
                                          D2D1_DRAW_TEXT_OPTIONS options = D2D1_DRAW_TEXT_OPTIONS.D2D1_DRAW_TEXT_OPTIONS_NONE)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (layout == null)
            {
                throw new ArgumentNullException(nameof(layout));
            }

            context.DrawTextLayout(origin, layout, defaultFillBrush, options);
        }
Example #6
0
        public static void DrawGeometry(this ID2D1RenderTarget renderTarget,
                                        ID2D1Geometry geometry,
                                        ID2D1Brush brush,
                                        float strokeWidth,
                                        ID2D1StrokeStyle strokeStyle = null)
        {
            if (renderTarget == null)
            {
                throw new ArgumentNullException(nameof(renderTarget));
            }

            if (brush == null)
            {
                throw new ArgumentNullException(nameof(brush));
            }

            renderTarget.DrawGeometry(geometry, brush, strokeWidth, strokeStyle);
        }
 internal D2D1BrushBase(ID2D1Brush brush)
 {
     this.brush = brush;
 }
        public void DrawText(string text, IDWriteTextFormat textFormat, Rect layoutRect, ID2D1Brush defaultFillBrush, DrawTextOptions options = DrawTextOptions.None, MeasuringMode measuringMode = MeasuringMode.Natural)
        {
            Guard.NotNullOrEmpty(text, nameof(text));

            DrawText(text, text.Length, textFormat, layoutRect, defaultFillBrush, options, measuringMode);
        }
Example #9
0
 /// <summary>
 /// Draws a line between the specified points using given brush.
 /// </summary>
 /// <param name="point0">The start point of the line, in device-independent pixels. </param>
 /// <param name="point1">The end point of the line, in device-independent pixels. </param>
 /// <param name="brush">The <see cref="ID2D1Brush"/> used to paint the line's stroke. </param>
 public void DrawLine(PointF point0, PointF point1, ID2D1Brush brush)
 {
     DrawLine(point0, point1, brush, 1.0f, null);
 }
Example #10
0
 /// <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);
 }
Example #11
0
 /// <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);
 }
Example #12
0
 internal D2D1BrushBase(ID2D1Brush brush)
 {
     this.brush = brush;
 }
 /// <summary>
 /// Draws a line between the specified points using given brush and stroke width.
 /// </summary>
 /// <param name="point0">The start point of the line, in device-independent pixels. </param>
 /// <param name="point1">The end point of the line, in device-independent pixels. </param>
 /// <param name="brush">The brush used to paint the line's stroke. </param>
 /// <param name="strokeWidth">A value greater than or equal to 0.0f that specifies the width of the stroke. If this parameter isn't specified, it defaults to 1.0f.  The stroke is centered on the line. </param>
 public void DrawLine(Vector2 point0, Vector2 point1, ID2D1Brush brush, float strokeWidth)
 {
     DrawLine(point0, point1, brush, strokeWidth, null);
 }
Example #14
0
        public static void DrawEllipse(this ID2D1RenderTarget context, D2D1_ELLIPSE ellipse, ID2D1Brush brush, float strokeWidth, ID2D1StrokeStyle strokeStyle = null)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (brush == null)
            {
                throw new ArgumentNullException(nameof(brush));
            }

            context.DrawEllipse(ref ellipse, brush, strokeWidth, strokeStyle);
        }
Example #15
0
        public static void DrawRectangle(this ID2D1RenderTarget context, D2D_RECT_F rect, ID2D1Brush brush, float strokeWidth, ID2D1StrokeStyle strokeStyle = null)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (brush == null)
            {
                throw new ArgumentNullException(nameof(brush));
            }

            context.DrawRectangle(ref rect, brush, strokeWidth, strokeStyle);
        }
Example #16
0
        public static void FillGeometry(this ID2D1RenderTarget context, ID2D1Geometry geometry, ID2D1Brush brush, ID2D1Brush opacityBrush = null)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (geometry == null)
            {
                throw new ArgumentNullException(nameof(geometry));
            }

            if (brush == null)
            {
                throw new ArgumentNullException(nameof(brush));
            }

            context.FillGeometry(geometry, brush, opacityBrush);
        }
 /// <summary>
 /// Draws the outline of the specified rounded rectangle.
 /// </summary>
 /// <param name="roundedRect">The dimensions of the rounded rectangle to draw, in device-independent pixels. </param>
 /// <param name="brush">The <see cref="ID2D1Brush"/> used to paint the rounded rectangle's outline.  </param>
 /// <param name="strokeWidth">The width of the rounded rectangle's stroke. The stroke is centered on the rounded rectangle's outline. The default value is 1.0f.  </param>
 public void DrawRoundedRectangle(RoundedRectangle roundedRect, ID2D1Brush brush, float strokeWidth)
 {
     DrawRoundedRectangle(ref roundedRect, brush, strokeWidth, null);
 }
 /// <summary>
 /// Draws the outline of the specified rounded rectangle.
 /// </summary>
 /// <param name="roundedRect">The dimensions of the rounded rectangle to draw, in device-independent pixels. </param>
 /// <param name="brush">The <see cref="ID2D1Brush"/> used to paint the rounded rectangle's outline.  </param>
 public void DrawRoundedRectangle(RoundedRectangle roundedRect, ID2D1Brush brush)
 {
     DrawRoundedRectangle(ref roundedRect, brush, 1.0f, null);
 }
 /// <summary>
 /// Draws the outline of a rectangle that has the specified dimensions and stroke style.
 /// </summary>
 /// <param name="rect">The dimensions of the rectangle to draw, in device-independent pixels.</param>
 /// <param name="brush">The <see cref="ID2D1Brush"/> used to paint the rectangle's stroke.</param>
 /// <param name="strokeWidth">A value greater than or equal to 0.0f that specifies the width of the rectangle's stroke. The stroke is centered on the rectangle's outline.</param>
 public void DrawRectangle(RawRectangleF rect, ID2D1Brush brush, float strokeWidth)
 {
     DrawRectangle(rect, brush, strokeWidth, null);
 }
 /// <summary>
 /// Draws the outline of a rectangle that has the specified dimensions.
 /// </summary>
 /// <param name="rect">The dimensions of the rectangle to draw, in device-independent pixels. </param>
 /// <param name="brush">The <see cref="ID2D1Brush"/> used to paint the rectangle's stroke. </param>
 public void DrawRectangle(RawRectangleF rect, ID2D1Brush brush)
 {
     DrawRectangle(rect, brush, 1.0f, null);
 }
Example #21
0
 public static void DrawTextLayout(this IComObject <ID2D1RenderTarget> context,
                                   D2D_POINT_2F origin,
                                   IDWriteTextLayout layout,
                                   ID2D1Brush defaultFillBrush    = null,
                                   D2D1_DRAW_TEXT_OPTIONS options = D2D1_DRAW_TEXT_OPTIONS.D2D1_DRAW_TEXT_OPTIONS_NONE) => DrawTextLayout(context?.Object, origin, layout, defaultFillBrush, options);
 /// <summary>
 /// Draws the outline of the specified rounded rectangle using the specified stroke style.
 /// </summary>
 /// <param name="roundedRect">The dimensions of the rounded rectangle to draw, in device-independent pixels.</param>
 /// <param name="brush">The brush used to paint the rounded rectangle's outline.</param>
 /// <param name="strokeWidth">The width of the rounded rectangle's stroke. The stroke is centered on the rounded rectangle's outline. The default value is 1.0f.</param>
 /// <param name="strokeStyle">The style of the rounded rectangle's stroke, or NULL to paint a solid stroke. The default value is NULL. </param>
 public void DrawRoundedRectangle(RoundedRectangle roundedRect, ID2D1Brush brush, float strokeWidth, ID2D1StrokeStyle strokeStyle)
 {
     DrawRoundedRectangle(ref roundedRect, brush, strokeWidth, strokeStyle);
 }
 /// <summary>
 /// Draws a line between the specified points using given brush.
 /// </summary>
 /// <param name="point0">The start point of the line, in device-independent pixels. </param>
 /// <param name="point1">The end point of the line, in device-independent pixels. </param>
 /// <param name="brush">The <see cref="ID2D1Brush"/> used to paint the line's stroke. </param>
 public void DrawLine(Vector2 point0, Vector2 point1, ID2D1Brush brush)
 {
     DrawLine(point0, point1, brush, 1.0f, null);
 }
Example #24
0
        public static void DrawLine(this ID2D1RenderTarget context, D2D_POINT_2F point0, D2D_POINT_2F point1, ID2D1Brush brush, float strokeWidth, ID2D1StrokeStyle strokeStyle = null)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (brush == null)
            {
                throw new ArgumentNullException(nameof(brush));
            }

            context.DrawLine(point0, point1, brush, strokeWidth, strokeStyle);
        }
        /// <summary>
        /// Draws the specified text using the format information provided by an <see cref="T:SharpDX.DirectWrite.TextFormat" /> object.
        /// </summary>
        /// <remarks>
        /// To create an <see cref="IDWriteTextFormat"/> object, create an <see cref="IDWriteFactory"/> and call its CreateTextFormat method.
        /// </remarks>
        /// <param name="text">A reference to an array of Unicode characters to draw.  </param>
        /// <param name="textFormat">An object that describes formatting details of the text to draw, such as the font, the font size, and flow direction.   </param>
        /// <param name="layoutRect">The size and position of the area in which the text is drawn.  </param>
        /// <param name="defaultForegroundBrush">The brush used to paint the text. </param>
        /// <param name="options">A value that indicates whether the text should be snapped to pixel boundaries and whether the text should be clipped to the layout rectangle. The default value is <see cref="F:SharpDX.Direct2D1.DrawTextOptions.None" />, which indicates that text should be snapped to pixel boundaries and it should not be clipped to the layout rectangle. </param>
        /// <param name="measuringMode">A value that indicates how glyph metrics are used to measure text when it is formatted.  The default value is DWRITE_MEASURING_MODE_NATURAL.  </param>
        public void DrawText(string text, IDWriteTextFormat textFormat, RawRectangleF layoutRect, ID2D1Brush defaultForegroundBrush, DrawTextOptions options, MeasuringMode measuringMode)
        {
            Guard.NotNullOrEmpty(text, nameof(text));

            DrawText(text, text.Length, textFormat, layoutRect, defaultForegroundBrush, options, measuringMode);
        }
Example #26
0
        public static void FillRectangle(this ID2D1RenderTarget context, D2D_RECT_F rect, ID2D1Brush brush)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (brush == null)
            {
                throw new ArgumentNullException(nameof(brush));
            }

            context.FillRectangle(ref rect, brush);
        }
 /// <summary>
 /// Draws the formatted text described by the specified <see cref="IDWriteTextLayout"/> object.
 /// </summary>
 /// <param name="origin">The point, described in device-independent pixels, at which the upper-left corner of the text described by textLayout is drawn. </param>
 /// <param name="textLayout">The formatted text to draw. Any drawing effects that do not inherit from <see cref="ID2D1Resource" /> are ignored. If there are drawing effects that inherit from <see cref="ID2D1Resource"/> that are not brushes, this method fails and the render target is put in an error state.  </param>
 /// <param name="defaultForegroundBrush">The <see cref="ID2D1Brush"/> used to paint any text in textLayout that does not already have a brush associated with it as a drawing effect (specified by the <see cref="IDWriteTextLayout.SetDrawingEffect(IUnknown, TextRange)"/> method).</param>
 public void DrawTextLayout(Vector2 origin, IDWriteTextLayout textLayout, ID2D1Brush defaultForegroundBrush)
 {
     DrawTextLayout(origin, textLayout, defaultForegroundBrush, DrawTextOptions.None);
 }
Example #28
0
        public static void FillEllipse(this ID2D1RenderTarget context, D2D1_ELLIPSE ellipse, ID2D1Brush brush)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (brush == null)
            {
                throw new ArgumentNullException(nameof(brush));
            }

            context.FillEllipse(ref ellipse, brush);
        }
Example #29
0
 /// <summary>
 /// Draws the outline of the specified ellipse using the specified brush.
 /// </summary>
 /// <param name="ellipse">The position and radius of the ellipse to draw, in device-independent pixels.</param>
 /// <param name="brush">The brush used to paint the ellipse's outline.</param>
 public void DrawEllipse(Ellipse ellipse, ID2D1Brush brush)
 {
     DrawEllipse(ellipse, brush, 1.0f, null);
 }
Example #30
0
 /// <summary>
 /// Draws the outline of the specified ellipse using the brush and stroke width.
 /// </summary>
 /// <param name="ellipse">The position and radius of the ellipse to draw, in device-independent pixels. </param>
 /// <param name="brush">The brush used to paint the ellipse's outline. </param>
 /// <param name="strokeWidth">The thickness of the ellipse's stroke. The stroke is centered on the ellipse's outline. </param>
 public void DrawEllipse(Ellipse ellipse, ID2D1Brush brush, float strokeWidth)
 {
     DrawEllipse(ellipse, brush, strokeWidth, null);
 }
Example #31
0
 /// <summary>
 /// Draws the specified text using the format information provided by an <see cref="T:SharpDX.DirectWrite.TextFormat" /> object.
 /// </summary>
 /// <remarks>
 /// To create an <see cref="IDWriteTextFormat"/> object, create an <see cref="IDWriteFactory"/> and call its CreateTextFormat method.
 /// </remarks>
 /// <param name="text">A reference to an array of Unicode characters to draw.  </param>
 /// <param name="textFormat">An object that describes formatting details of the text to draw, such as the font, the font size, and flow direction.   </param>
 /// <param name="layoutRect">The size and position of the area in which the text is drawn.  </param>
 /// <param name="defaultForegroundBrush">The brush used to paint the text. </param>
 /// <param name="options">A value that indicates whether the text should be snapped to pixel boundaries and whether the text should be clipped to the layout rectangle. The default value is <see cref="F:SharpDX.Direct2D1.DrawTextOptions.None" />, which indicates that text should be snapped to pixel boundaries and it should not be clipped to the layout rectangle. </param>
 /// <param name="measuringMode">A value that indicates how glyph metrics are used to measure text when it is formatted.  The default value is DWRITE_MEASURING_MODE_NATURAL.  </param>
 public void DrawText(string text, IDWriteTextFormat textFormat, RectF layoutRect, ID2D1Brush defaultForegroundBrush, DrawTextOptions options, MeasuringMode measuringMode)
 {
     DrawText(text, text.Length, textFormat, layoutRect, defaultForegroundBrush, options, measuringMode);
 }