Remarks

GraphicsLibrary
Status
Source code GitHub
NuGet package
Characteristic Locus
Inheritance System.Object > GraphicsLibrary
Namespace Meadow.Foundation.Graphics
Assembly GraphicsLibrary.dll

Syntax

public class GraphicsLibrary : ITextDisplay

Constructors

GraphicsLibrary(DisplayBase)

Declaration
public GraphicsLibrary(DisplayBase display)

Parameters

Type Name Description
DisplayBase display

Fields

canvasState

Declaration
protected GraphicsLibrary.CanvasState canvasState

Field Value

Type Description
GraphicsLibrary.CanvasState

Properties

CurrentFont

Current font used for displaying text on the display.

Declaration
public FontBase CurrentFont { get; set; }

Property Value

Type Description
FontBase

CursorColumn

Declaration
public byte CursorColumn { get; }

Property Value

Type Description
System.Byte

CursorLine

Declaration
public byte CursorLine { get; }

Property Value

Type Description
System.Byte

DisplayConfig

Declaration
public TextDisplayConfig DisplayConfig { get; }

Property Value

Type Description
TextDisplayConfig

Height

Return the height of the display after accounting for the rotation.

Declaration
public uint Height { get; }

Property Value

Type Description
System.UInt32

Rotation

Current rotation used for drawing pixels to the display

Declaration
public GraphicsLibrary.RotationType Rotation { get; set; }

Property Value

Type Description
GraphicsLibrary.RotationType

Stroke

Stroke / line thickness when drawing lines or shape outlines

Declaration
public int Stroke { get; set; }

Property Value

Type Description
System.Int32

Width

Return the width of the display after accounting for the rotation.

Declaration
public uint Width { get; }

Property Value

Type Description
System.UInt32

Methods

Clear(Color, Boolean)

Clear the display to a color

Declaration
public void Clear(Color color, bool updateDisplay = false)

Parameters

Type Name Description
Color color

Color to set display.

System.Boolean updateDisplay

Update the display immediately when true.

Clear(Boolean)

Clear the display.

Declaration
public void Clear(bool updateDisplay = false)

Parameters

Type Name Description
System.Boolean updateDisplay

Update the display immediately when true.

ClearLine(Byte)

Declaration
public void ClearLine(byte lineNumber)

Parameters

Type Name Description
System.Byte lineNumber

ClearLines()

Declaration
public void ClearLines()

DrawBitmap(Int32, Int32, Int32, Int32, Byte[], Color, GraphicsLibrary.ScaleFactor)

Display a 1-bit bitmap

This method simply calls a similar method in the display hardware.

Declaration
public void DrawBitmap(int x, int y, int width, int height, byte[] bitmap, Color color, GraphicsLibrary.ScaleFactor scaleFactor = GraphicsLibrary.ScaleFactor.X1)

Parameters

Type Name Description
System.Int32 x

Abscissa of the top left corner of the bitmap.

System.Int32 y

Ordinate of the top left corner of the bitmap.

System.Int32 width

Width of the bitmap in pixels.

System.Int32 height

Height of the bitmap in pixels.

System.Byte[] bitmap

Bitmap to display.

Color color

The color of the bitmap.

GraphicsLibrary.ScaleFactor scaleFactor

DrawBitmap(Int32, Int32, Int32, Int32, Byte[], DisplayBase.BitmapMode, GraphicsLibrary.ScaleFactor)

Display a 1-bit bitmap

This method simply calls a similar method in the display hardware.

Declaration
public void DrawBitmap(int x, int y, int width, int height, byte[] bitmap, DisplayBase.BitmapMode bitmapMode, GraphicsLibrary.ScaleFactor scaleFactor = GraphicsLibrary.ScaleFactor.X1)

Parameters

Type Name Description
System.Int32 x

Abscissa of the top left corner of the bitmap.

System.Int32 y

Ordinate of the top left corner of the bitmap.

System.Int32 width

Width of the bitmap in pixels.

System.Int32 height

Height of the bitmap in pixels.

System.Byte[] bitmap

Bitmap to display.

DisplayBase.BitmapMode bitmapMode

How should the bitmap be transferred to the display?

GraphicsLibrary.ScaleFactor scaleFactor

DrawCircle(Int32, Int32, Int32, Color, Boolean, Boolean)

Draw a dircle.

Declaration
public void DrawCircle(int centerX, int centerY, int radius, Color color, bool filled = false, bool centerBetweenPixels = false)

Parameters

Type Name Description
System.Int32 centerX

Abscissa of the centre point of the circle.

System.Int32 centerY

Ordinate of the centre point of the circle.

System.Int32 radius

Radius of the circle.

Color color

The color of the circle.

System.Boolean filled

Draw a filled circle?

System.Boolean centerBetweenPixels

Remarks

This algorithm draws the circle by splitting the full circle into eight segments. This method uses the Midpoint algorithm: https://en.wikipedia.org/wiki/Midpoint_circle_algorithm A C# implementation can be found here: https://rosettacode.org/wiki/Bitmap/Midpoint_circle_algorithm#C.23

DrawCircle(Int32, Int32, Int32, Boolean, Boolean, Boolean)

Draw a dircle.

Declaration
public void DrawCircle(int centerX, int centerY, int radius, bool colored = true, bool filled = false, bool centerBetweenPixels = false)

Parameters

Type Name Description
System.Int32 centerX

Abscissa of the centre point of the circle.

System.Int32 centerY

Ordinate of the centre point of the circle.

System.Int32 radius

Radius of the circle.

System.Boolean colored

Show the circle when true.

System.Boolean filled

Draw a filled circle?

System.Boolean centerBetweenPixels

Remarks

This algorithm draws the circle by splitting the full circle into eight segments. This method uses the Midpoint algorithm: https://en.wikipedia.org/wiki/Midpoint_circle_algorithm A C# implementation can be found here: https://rosettacode.org/wiki/Bitmap/Midpoint_circle_algorithm#C.23

DrawCircleQuadrant(Int32, Int32, Int32, Int32, Color, Boolean, Boolean)

Declaration
public void DrawCircleQuadrant(int centerX, int centerY, int radius, int quadrant, Color color, bool filled = false, bool centerBetweenPixels = false)

Parameters

Type Name Description
System.Int32 centerX
System.Int32 centerY
System.Int32 radius
System.Int32 quadrant
Color color
System.Boolean filled
System.Boolean centerBetweenPixels

DrawCircleQuadrant(Int32, Int32, Int32, Int32, Boolean, Boolean, Boolean)

Declaration
public void DrawCircleQuadrant(int centerX, int centerY, int radius, int quadrant, bool colored = true, bool filled = false, bool centerBetweenPixels = false)

Parameters

Type Name Description
System.Int32 centerX
System.Int32 centerY
System.Int32 radius
System.Int32 quadrant
System.Boolean colored
System.Boolean filled
System.Boolean centerBetweenPixels

DrawHorizontalLine(Int32, Int32, Int32, Color)

Draw a horizontal line.

Declaration
public void DrawHorizontalLine(int x, int y, int length, Color color)

Parameters

Type Name Description
System.Int32 x

Abscissa of the starting point of the line.

System.Int32 y

Ordinate of the starting point of the line.

System.Int32 length

Length of the line to draw.

Color color

The color of the line.

DrawHorizontalLine(Int32, Int32, Int32, Boolean)

Draw a horizontal line.

Declaration
public void DrawHorizontalLine(int x, int y, int length, bool colored)

Parameters

Type Name Description
System.Int32 x

Abscissa of the starting point of the line.

System.Int32 y

Ordinate of the starting point of the line.

System.Int32 length

Length of the line to draw.

System.Boolean colored

Turn the pixel on (true) or off (false).

DrawLine(Int32, Int32, Int32, Int32, Color)

Draw a line using Bresenhams line drawing algorithm.

Declaration
public void DrawLine(int x0, int y0, int x1, int y1, Color color)

Parameters

Type Name Description
System.Int32 x0

Abscissa of the starting point of the line.

System.Int32 y0

Ordinate of the starting point of the line

System.Int32 x1

Abscissa of the end point of the line.

System.Int32 y1

Ordinate of the end point of the line

Color color

The color of the line.

Remarks

DrawLine(Int32, Int32, Int32, Int32, Boolean)

Draw a line using Bresenhams line drawing algorithm.

Declaration
public void DrawLine(int x0, int y0, int x1, int y1, bool colored)

Parameters

Type Name Description
System.Int32 x0

Abscissa of the starting point of the line.

System.Int32 y0

Ordinate of the starting point of the line

System.Int32 x1

Abscissa of the end point of the line.

System.Int32 y1

Ordinate of the end point of the line

System.Boolean colored

Turn the pixel on (true) or off (false).

Remarks

DrawLine(Int32, Int32, Int32, Single, Color)

Draw a line from a point to a position defined by a radius and an angle

Declaration
public void DrawLine(int x, int y, int length, float angle, Color color)

Parameters

Type Name Description
System.Int32 x
System.Int32 y

Ordinate of the starting point of the line

System.Int32 length

length of line

System.Single angle

angle to draw line in radians

Color color

The color of the line

DrawLine(Int32, Int32, Int32, Single, Boolean)

Declaration
public void DrawLine(int x, int y, int length, float angle, bool colored)

Parameters

Type Name Description
System.Int32 x
System.Int32 y
System.Int32 length
System.Single angle
System.Boolean colored

DrawPixel(Int32)

Draw a single pixel using the pen color

Declaration
public void DrawPixel(int index)

Parameters

Type Name Description
System.Int32 index

pixel location in buffer

DrawPixel(Int32, Int32)

Draw a single pixel using the pen color

Declaration
public void DrawPixel(int x, int y)

Parameters

Type Name Description
System.Int32 x

x location

System.Int32 y

y location

DrawPixel(Int32, Int32, Color)

Draw a single pixel

Declaration
public void DrawPixel(int x, int y, Color color)

Parameters

Type Name Description
System.Int32 x

x location

System.Int32 y

y location

Color color

Color of pixel.

DrawPixel(Int32, Int32, Boolean)

Draw a single pixel

Declaration
public void DrawPixel(int x, int y, bool colored)

Parameters

Type Name Description
System.Int32 x

x location

System.Int32 y

y location

System.Boolean colored

Turn the pixel on (true) or off (false).

DrawRectangle(Int32, Int32, Int32, Int32, Color, Boolean)

Draw a rectangle.

Declaration
public void DrawRectangle(int x, int y, int width, int height, Color color, bool filled = false)

Parameters

Type Name Description
System.Int32 x

Abscissa of the top left corner.

System.Int32 y

Ordinate of the top left corner.

System.Int32 width

Width of the rectangle.

System.Int32 height

Height of the rectangle.

Color color

The color of the rectangle.

System.Boolean filled

Fill the rectangle (true) or draw the outline (false, default).

DrawRectangle(Int32, Int32, Int32, Int32, Boolean, Boolean)

Draw a rectangle.

Declaration
public void DrawRectangle(int x, int y, int width, int height, bool colored = true, bool filled = false)

Parameters

Type Name Description
System.Int32 x

Abscissa of the top left corner.

System.Int32 y

Ordinate of the top left corner.

System.Int32 width

Width of the rectangle.

System.Int32 height

Height of the rectangle.

System.Boolean colored

Draw the pixel (true) or turn the pixel off (false).

System.Boolean filled

Fill the rectangle (true) or draw the outline (false, default).

DrawRoundedRectangle(Int32, Int32, Int32, Int32, Int32, Color, Boolean)

Draw a rounded rectangle.

Declaration
public void DrawRoundedRectangle(int x, int y, int width, int height, int cornerRadius, Color color, bool filled = false)

Parameters

Type Name Description
System.Int32 x

Abscissa of the top left corner.

System.Int32 y

Ordinate of the top left corner.

System.Int32 width

Width of the rectangle.

System.Int32 height

Height of the rectangle.

System.Int32 cornerRadius

Radius of the corners of the rectangle.

Color color

The color of the rectangle.

System.Boolean filled

Fill the rectangle (true) or draw the outline (false, default).

DrawText(Int32, Int32, String, Color, GraphicsLibrary.ScaleFactor, GraphicsLibrary.TextAlignment)

Draw a text message on the display using the current font.

Declaration
public void DrawText(int x, int y, string text, Color color, GraphicsLibrary.ScaleFactor scaleFactor = GraphicsLibrary.ScaleFactor.X1, GraphicsLibrary.TextAlignment alignment = GraphicsLibrary.TextAlignment.Left)

Parameters

Type Name Description
System.Int32 x

Abscissa of the location of the text.

System.Int32 y

Ordinate of the location of the text.

System.String text

Text to display.

Color color

Color of the text.

GraphicsLibrary.ScaleFactor scaleFactor
GraphicsLibrary.TextAlignment alignment

DrawText(Int32, Int32, String, GraphicsLibrary.ScaleFactor, GraphicsLibrary.TextAlignment)

Draw a text message on the display using the current font.

Declaration
public void DrawText(int x, int y, string text, GraphicsLibrary.ScaleFactor scaleFactor = GraphicsLibrary.ScaleFactor.X1, GraphicsLibrary.TextAlignment alignment = GraphicsLibrary.TextAlignment.Left)

Parameters

Type Name Description
System.Int32 x

Abscissa of the location of the text.

System.Int32 y

Ordinate of the location of the text.

System.String text

Text to display.

GraphicsLibrary.ScaleFactor scaleFactor
GraphicsLibrary.TextAlignment alignment

DrawTriangle(Int32, Int32, Int32, Int32, Int32, Int32, Color, Boolean)

Draw a triangle

Declaration
public void DrawTriangle(int x0, int y0, int x1, int y1, int x2, int y2, Color color, bool filled = false)

Parameters

Type Name Description
System.Int32 x0

Vertex #0 x coordinate

System.Int32 y0

Vertex #0 y coordinate

System.Int32 x1

Vertex #1 x coordinate

System.Int32 y1

Vertex #1 y coordinate

System.Int32 x2

Vertex #2 x coordinate

System.Int32 y2

Vertex #2 y coordinate

Color color

Color of triangle

System.Boolean filled

Draw a filled triangle?

DrawTriangle(Int32, Int32, Int32, Int32, Int32, Int32, Boolean, Boolean)

Draw a triangle

Declaration
public void DrawTriangle(int x0, int y0, int x1, int y1, int x2, int y2, bool colored = true, bool filled = false)

Parameters

Type Name Description
System.Int32 x0

Vertex #0 x coordinate

System.Int32 y0

Vertex #0 y coordinate

System.Int32 x1

Vertex #1 x coordinate

System.Int32 y1

Vertex #1 y coordinate

System.Int32 x2

Vertex #2 x coordinate

System.Int32 y2

Vertex #2 y coordinate

System.Boolean colored

Should the triangle add (true) or remove (false)

System.Boolean filled

Draw a filled triangle?

Remarks

Draw triangle method for 1 bit displays

DrawVerticalLine(Int32, Int32, Int32, Color)

Draw a vertical line.

Declaration
public void DrawVerticalLine(int x, int y, int length, Color color)

Parameters

Type Name Description
System.Int32 x

Abscissa of the starting point of the line.

System.Int32 y

Ordinate of the starting point of the line.

System.Int32 length

Length of the line to draw.

Color color

The color of the line.

DrawVerticalLine(Int32, Int32, Int32, Boolean)

Draw a vertical line.

Declaration
public void DrawVerticalLine(int x, int y, int length, bool colored)

Parameters

Type Name Description
System.Int32 x

Abscissa of the starting point of the line.

System.Int32 y

Ordinate of the starting point of the line.

System.Int32 length

Length of the line to draw.

System.Boolean colored

Show the line when (true) or off (false).

GetXForRotation(Int32, Int32)

Declaration
public int GetXForRotation(int x, int y)

Parameters

Type Name Description
System.Int32 x
System.Int32 y

Returns

Type Description
System.Int32

GetYForRotation(Int32, Int32)

Declaration
public int GetYForRotation(int x, int y)

Parameters

Type Name Description
System.Int32 x
System.Int32 y

Returns

Type Description
System.Int32

InvertPixel(Int32, Int32)

Invert the color of the pixel at the given location

Declaration
public void InvertPixel(int x, int y)

Parameters

Type Name Description
System.Int32 x

x location

System.Int32 y

y location

InvertRectangle(Int32, Int32, Int32, Int32)

Invert all pixels within a rectangle

Declaration
public void InvertRectangle(int x, int y, int width, int height)

Parameters

Type Name Description
System.Int32 x

x start

System.Int32 y

y start

System.Int32 width

width of area to invert

System.Int32 height

height of area to invert

RestoreState()

Declaration
public void RestoreState()

SaveCustomCharacter(Byte[], Byte)

Declaration
public void SaveCustomCharacter(byte[] characterMap, byte address)

Parameters

Type Name Description
System.Byte[] characterMap
System.Byte address

SaveState()

Declaration
public void SaveState()

SetCursorPosition(Byte, Byte)

Declaration
public void SetCursorPosition(byte column, byte line)

Parameters

Type Name Description
System.Byte column
System.Byte line

Show()

Show the changes on the display.

Declaration
public void Show()

Write(String)

Declaration
public void Write(string text)

Parameters

Type Name Description
System.String text

WriteLine(String, Byte, Boolean)

Declaration
public void WriteLine(string text, byte lineNumber, bool showCursor = false)

Parameters

Type Name Description
System.String text
System.Byte lineNumber
System.Boolean showCursor