Class RenderContext
- Namespace
- Myra.Graphics2D
- Assembly
- Myra.dll
Provides rendering context for drawing 2D graphics including shapes, text, and textured regions.
public class RenderContext : IDisposable
- Inheritance
-
RenderContext
- Implements
- Inherited Members
Constructors
RenderContext()
Initializes a new instance of the RenderContext class.
public RenderContext()
Properties
Opacity
Gets or sets the opacity (alpha) value for rendering, ranging from 0.0 (fully transparent) to 1.0 (fully opaque).
public float Opacity { get; set; }
Property Value
Scissor
Gets or sets the scissor rectangle for clipping rendered output.
public Rectangle Scissor { get; set; }
Property Value
- Rectangle
Methods
AddOpacity(float)
Applies opacity
public void AddOpacity(float opacity)
Parameters
opacityfloat
Begin()
Begins rendering.
public void Begin()
Dispose()
Disposes resources used by the RenderContext.
public void Dispose()
Draw(Texture2D, Rectangle, Color)
Draws a texture
public void Draw(Texture2D texture, Rectangle destinationRectangle, Color color)
Parameters
textureTexture2DdestinationRectangleRectanglecolorColor
Draw(Texture2D, Rectangle, Rectangle?, Color)
Draws a texture
public void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle? sourceRectangle, Color color)
Parameters
textureTexture2DdestinationRectangleRectanglesourceRectangleRectangle?colorColor
Draw(Texture2D, Rectangle, Rectangle?, Color, float)
Draws a texture
public void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle? sourceRectangle, Color color, float rotation)
Parameters
textureTexture2DdestinationRectangleRectanglesourceRectangleRectangle?colorColorrotationfloat
Draw(Texture2D, Rectangle, Rectangle?, Color, float, float)
Draws a texture
public void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle? sourceRectangle, Color color, float rotation, float depth = 0)
Parameters
textureTexture2DdestinationRectangleRectanglesourceRectangleRectangle?colorColorrotationfloatdepthfloat
Draw(Texture2D, Vector2, Color)
Draws a texture
public void Draw(Texture2D texture, Vector2 position, Color color)
Parameters
textureTexture2DpositionVector2colorColor
Draw(Texture2D, Vector2, Color, Vector2, float)
Draws a texture
public void Draw(Texture2D texture, Vector2 pos, Color color, Vector2 scale, float rotation = 0)
Parameters
textureTexture2DposVector2colorColorscaleVector2rotationfloat
Draw(Texture2D, Vector2, Rectangle?, Color)
Draws a texture
public void Draw(Texture2D texture, Vector2 position, Rectangle? sourceRectangle, Color color)
Parameters
textureTexture2DpositionVector2sourceRectangleRectangle?colorColor
Draw(Texture2D, Vector2, Rectangle?, Color, float)
Draws a texture
public void Draw(Texture2D texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation)
Parameters
textureTexture2DpositionVector2sourceRectangleRectangle?colorColorrotationfloat
Draw(Texture2D, Vector2, Rectangle?, Color, float, Vector2, float)
Draws a texture
public void Draw(Texture2D texture, Vector2 position, Rectangle? sourceRectangle, Color color, float rotation, Vector2 scale, float depth = 0)
Parameters
textureTexture2DpositionVector2sourceRectangleRectangle?colorColorrotationfloatscaleVector2depthfloat
DrawArc(Vector2, float, int, Color, float, float, float)
Draw an Arc
public void DrawArc(Vector2 center, float radius, int sides, Color color, float startAngle, float endAngle, float thickness = 1)
Parameters
centerVector2The center of the Arc
radiusfloatThe radius of the Arc
sidesintThe number of sides to generate
colorColorThe color of the Arc
startAnglefloatThe start angle of the line in radians
endAnglefloatThe end angle of the line in radians
thicknessfloatThe thickness of the lines used
DrawArc(float, float, float, int, Color, float, float, float)
Draw a Arc
public void DrawArc(float x, float y, float radius, int sides, Color color, float startAngle, float endAngle, float thickness = 1)
Parameters
xfloatThe center X of the Arc
yfloatThe center Y of the Arc
radiusfloatThe radius of the Arc
sidesintThe number of sides to generate
colorColorThe color of the Arc
startAnglefloatThe start angle of the line in radians
endAnglefloatThe end angle of the line in radians
thicknessfloatThe thickness of the line
DrawCircle(Vector2, float, int, Color, float)
Draw a circle
public void DrawCircle(Vector2 center, float radius, int sides, Color color, float thickness = 1)
Parameters
centerVector2The center of the circle
radiusfloatThe radius of the circle
sidesintThe number of sides to generate
colorColorThe color of the circle
thicknessfloatThe thickness of the lines used
DrawCircle(float, float, float, int, Color, float)
Draw a circle
public void DrawCircle(float x, float y, float radius, int sides, Color color, float thickness = 1)
Parameters
xfloatThe center X of the circle
yfloatThe center Y of the circle
radiusfloatThe radius of the circle
sidesintThe number of sides to generate
colorColorThe color of the circle
thicknessfloatThe thickness of the line
DrawLine(Vector2, Vector2, Color, float)
Draws a line from point1 to point2 with an offset
public void DrawLine(Vector2 point1, Vector2 point2, Color color, float thickness = 1)
Parameters
point1Vector2The first point
point2Vector2The second point
colorColorThe color to use
thicknessfloatThe thickness of the line
DrawLine(Vector2, float, float, Color, float)
Draws a line from point1 to point2 with an offset
public void DrawLine(Vector2 point, float length, float angle, Color color, float thickness = 1)
Parameters
pointVector2The starting point
lengthfloatThe length of the line
anglefloatThe angle of this line from the starting point
colorColorThe color to use
thicknessfloatThe thickness of the line
DrawLine(float, float, float, float, Color, float)
Draws a line from point1 to point2 with an offset
public void DrawLine(float x1, float y1, float x2, float y2, Color color, float thickness = 1)
Parameters
x1floatThe X coord of the first point
y1floatThe Y coord of the first point
x2floatThe X coord of the second point
y2floatThe Y coord of the second point
colorColorThe color to use
thicknessfloatThe thickness of the line
DrawPoint(Vector2, Color, float)
Draws a point at the specified position. The center of the point will be at the position.
public void DrawPoint(Vector2 position, Color color, float size = 1)
Parameters
positionVector2colorColorsizefloat
DrawPoint(float, float, Color, float)
Draws a point at the specified x, y position. The center of the point will be at the position.
public void DrawPoint(float x, float y, Color color, float size = 1)
Parameters
DrawPolygon(Vector2, Vector2[], Color, float)
Draws a closed polygon from an array of points
public void DrawPolygon(Vector2 offset, Vector2[] points, Color color, float thickness = 1)
Parameters
offsetVector2Where to offset the points
pointsVector2[]The points to connect with lines
colorColorThe color to use
thicknessfloatThe thickness of the lines
DrawRectangle(Rectangle, Color, float)
Draws a rectangle with the thickness provided
public void DrawRectangle(Rectangle rectangle, Color color, float thickness = 1)
Parameters
rectangleRectangleThe rectangle to draw
colorColorThe color to draw the rectangle in
thicknessfloatThe thickness of the lines
DrawRectangle(Vector2, Vector2, Color, float)
Draws a rectangle with the thickness provided
public void DrawRectangle(Vector2 location, Vector2 size, Color color, float thickness = 1)
Parameters
locationVector2Where to draw
sizeVector2The size of the rectangle
colorColorThe color to draw the rectangle in
thicknessfloatThe thickness of the line
DrawRichText(RichTextLayout, Vector2, Color, Vector2?, float, float, TextHorizontalAlignment)
Draws a rich text
public void DrawRichText(RichTextLayout richText, Vector2 position, Color color, Vector2? sourceScale = null, float rotation = 0, float layerDepth = 0, TextHorizontalAlignment horizontalAlignment = TextHorizontalAlignment.Left)
Parameters
richTextRichTextLayoutThe text which will be drawn.
positionVector2The drawing location on screen.
colorColorA color mask.
sourceScaleVector2?A scaling of this text.
rotationfloatA rotation of this text in radians.
layerDepthfloatA depth of the layer of this string.
horizontalAlignmentTextHorizontalAlignmentThe horizontal alignment of the text.
DrawString(SpriteFontBase, string, Vector2, Color, Vector2, float)
Draws a text
public void DrawString(SpriteFontBase font, string text, Vector2 position, Color color, Vector2 scale, float layerDepth = 0)
Parameters
fontSpriteFontBaseThe font to use for drawing.
textstringThe text which will be drawn.
positionVector2The drawing location on screen.
colorColorA color mask.
scaleVector2A scaling of this text.
layerDepthfloatA depth of the layer of this string.
DrawString(SpriteFontBase, string, Vector2, Color, Vector2, float, float)
Draws a text
public void DrawString(SpriteFontBase font, string text, Vector2 position, Color color, Vector2 scale, float rotation, float layerDepth = 0)
Parameters
fontSpriteFontBaseThe font to use for drawing.
textstringThe text which will be drawn.
positionVector2The drawing location on screen.
colorColorA color mask.
scaleVector2A scaling of this text.
rotationfloatA rotation of this text in radians.
layerDepthfloatA depth of the layer of this string.
DrawString(SpriteFontBase, string, Vector2, Color, float)
Draws a text
public void DrawString(SpriteFontBase font, string text, Vector2 position, Color color, float layerDepth = 0)
Parameters
fontSpriteFontBaseThe font to use for drawing.
textstringThe text which will be drawn.
positionVector2The drawing location on screen.
colorColorA color mask.
layerDepthfloatA depth of the layer of this string.
End()
Ends rendering.
public void End()
FillRectangle(Rectangle, Color)
Draws a filled rectangle
public void FillRectangle(Rectangle rectangle, Color color)
Parameters
rectangleRectangleThe rectangle to draw
colorColorThe color to draw the rectangle in
FillRectangle(Vector2, Vector2, Color)
Draws a filled rectangle
public void FillRectangle(Vector2 location, Vector2 size, Color color)
Parameters
locationVector2Where to draw
sizeVector2The size of the rectangle
colorColorThe color to draw the rectangle in
FillRectangle(float, float, float, float, Color)
Draws a filled rectangle
public void FillRectangle(float x, float y, float width, float height, Color color)
Parameters
xfloatThe X coord of the left side
yfloatThe Y coord of the upper side
widthfloatWidth
heightfloatHeight
colorColorThe color to draw the rectangle in
~RenderContext()
Finalizer that releases unmanaged resources.
protected ~RenderContext()
Flush()
Flushes pending render operations.
public void Flush()
SetAnisotropicFilteringMode(bool)
Sets whether anisotropic filtering mode is enabled.
public void SetAnisotropicFilteringMode(bool isAnisotropicFiltering)
Parameters
isAnisotropicFilteringboolTrue to enable anisotropic filtering; false to disable.