GLIB - Graphics Library

Description

Silicon Labs Graphics Library.

Graphics Library

Silicon Labs Graphics Library. Feature rich graphics library for memory constrained applications.


Introduction

GLIB is a graphics library that can be used to draw pixels, common shapes, text or bitmaps to a display connected to an MCU. The main goal of this library is easy of use and small code and memory footprint. In this way GLIB can be used on even the smallest Cortex-M0 devices.

GLIB treats the display as a matrix of pixels which is a model of the physical display. This matrix is exposed to GLIB via an API called DMD (Dot Matrix Display). So in order to draw something on a physical display the user application needs to provide GLIB with a single implementation of the DMD interface. Sample DMD implementations are provided for the displays that are connected to the Silion Labs Starter Kits and the Silicon Labs Development Kits.


Initialization

There are two things that must be initialized before GLIB can be used to draw pixels on the display. First the user needs to initialize the DMD implementation for the actual hardware display which is used. This initialization is display hardware specific.

After the DMD is initialized the user needs to initialize a GLIB_Context_t that can be used for all the drawing operations. A GLIB_Context_t structure is initialized using the GLIB_contextInit() function.

Every GLIB drawing function will require a GLIB_Context_t as one of the functions arguments. The GBLI context contains important configuration values that all the drawing functions use. It contains the foreground and background color, and it also contains information on what font to use when rendering text on the display.


Color

GLIB represent color in a pixel as three 8 bit color values representing red, green and blue, giving the user support for a 24 bit color depth. The GLIB_rgbColor() function can be used to convert from distinct red, green and blue values to an 32-bit integer representing the color of single pixel. Similarly the GLIB_colorTranslate24bpp() function can be used to convert from the 32-bit integer representation into the 3 separate red, green and blue components. The 32-bit integer representation of a pixel color is used when configuring the foreground and background color.

GLIB also contains some common predefined colors for use in places where a 32-bit integer is used to represent the color. These predefined colors include White, Black, Brown, Orange, and many more. See the GLIB Colors for the full list of colors.

Some displays are monochrome, meaning that they only support 2 colors. When using GLIB to draw shapes on these displays the applications should use only the 2 colors White and Black.


Draw Shapes

GLIB contains functions for drawing common shapes to a display. Here is a list containing all the drawing functions.


Draw Pixels

These are functions that GLIB provides for drawing one pixel.


Font rendering

GLIB Supports fixed width font rendering. The functions GLIB_drawString() and GLIB_drawChar() are used to render text on the display.

GLIB provides these fonts for the user

  • GLIB_FontNormal8x8 A normal 8x8 pixel font which is the defaul font if nothing else is configured.
  • GLIB_FontNarrow6x8 A narrow 6x8 pixel font which can be used if the default font is to wide.
  • GLIB_FontNumber16x20 A large font for use with only numbers. This font is 16x20 pixels.

To change the font the user calls GLIB_setFont() with a pointer to a GLIB_Font_t structure which describes the whole font. The GLIB_Font_t structure contains a pointer to the bitmap for each character and it describes attributes of the font like the width and height of each character and it also contains the bitmap of each character.


Draw Bitmap

To draw an image or custom bitmaps on the display the GLIB_drawBitmap() function can be used. The color displays typically use a bitmap format where each pixel is represented by 3 consecutive bytes representing the red, green and blue color components. While monochrome displays typically use a bitmap format where 1 byte represents 8 pixels where a 1 bit is white and a 0 bit is black. Note that bitmaps are insensitive to the foreground and background color settings, and that the format of the bitmap depends on the DMD implementation of the display.


Example

This examples shows how to initialize a GLIB context and draw something on a display.

static GLIB_Context_t context;
static const char * msg = "Hello GLIB!";
void glibExample(void)
{
// Setup the dot matrix and initialize the GLIB context - these should be called once
GLIB_contextInit(&context);
// Write our message into the GLIB instance.
GLIB_drawString(&context, msg, strlen(msg), 10, 10, true);
// Needs to be called each time there is a change to GLIB to mirror
// GLIB context data model changes to the physical LCD.
}

Modules

DMD - Dot Matrix Display
Hardware abstraction layer for dot matrix displays.
 
GLIB BMP
Bitmap Support.
 
GLIB Colors
Predefined Colors.
 

Data Structures

struct  __GLIB_Font_t
 Font definition structure.
 
struct  __GLIB_Rectangle_t
 Rectangle structure.
 
struct  __GLIB_Context_t
 GLIB Drawing Context (Multiple instances of GLIB_Context_t can exist)
 

Functions

EMSTATUS GLIB_contextInit (GLIB_Context_t *pContext)
 Initialize the GLIB_Context_t.
 
EMSTATUS GLIB_displayWakeUp (void)
 Returns the display from sleep mode.
 
EMSTATUS GLIB_displaySleep (void)
 Sets the display in sleep mode.
 
EMSTATUS GLIB_clear (GLIB_Context_t *pContext)
 Clears the display with the background color of the GLIB_Context_t.
 
EMSTATUS GLIB_clearRegion (const GLIB_Context_t *pContext)
 Clears the clipping region by filling it with the background color of the GLIB_Context_t.
 
EMSTATUS GLIB_resetDisplayClippingArea (GLIB_Context_t *pContext)
 Reset the display driver clipping area to the whole display.
 
EMSTATUS GLIB_resetClippingRegion (GLIB_Context_t *pContext)
 Reset the GLIB_Context_t clipping region to the whole display.
 
EMSTATUS GLIB_applyClippingRegion (const GLIB_Context_t *pContext)
 Apply the clipping region from the GLIB_Context_t in the DMD driver.
 
void GLIB_colorTranslate24bpp (uint32_t color, uint8_t *red, uint8_t *green, uint8_t *blue)
 Extracts the color components from the 32-bit color passed and puts them in the passed in 8-bits ints.
 
uint32_t GLIB_rgbColor (uint8_t red, uint8_t green, uint8_t blue)
 Convert 3 uint8_t color components into a 24-bit color.
 
bool GLIB_rectContainsPoint (const GLIB_Rectangle_t *pRect, int32_t xCenter, int32_t yCenter)
 Checks if the point passed in is in the interior of the rectangle passed in.
 
void GLIB_normalizeRect (GLIB_Rectangle_t *pRect)
 Normalize the rectangle that is passed in.
 
EMSTATUS GLIB_setClippingRegion (GLIB_Context_t *pContext, const GLIB_Rectangle_t *pRect)
 Sets the clippingRegion of the passed in GLIB_Context_t.
 
EMSTATUS GLIB_drawCircle (GLIB_Context_t *pContext, int32_t x, int32_t y, uint32_t radius)
 Draws a circle with center at x, y, and a radius.
 
EMSTATUS GLIB_drawCircleFilled (GLIB_Context_t *pContext, int32_t x, int32_t y, uint32_t radius)
 Draws a filled circle with center at x, y, and a radius.
 
EMSTATUS GLIB_drawPartialCircle (GLIB_Context_t *pContext, int32_t xCenter, int32_t yCenter, uint32_t radius, uint8_t bitMask)
 Draws a partial circle with center at x, y, and a radius.
 
EMSTATUS GLIB_setFont (GLIB_Context_t *pContext, GLIB_Font_t *pFont)
 Set new font for the library.
 
EMSTATUS GLIB_drawString (GLIB_Context_t *pContext, const char *pString, uint32_t sLength, int32_t x0, int32_t y0, bool opaque)
 Draws a string using the font supplied with the library.
 
EMSTATUS GLIB_drawStringOnLine (GLIB_Context_t *pContext, const char *pString, uint8_t line, GLIB_Align_t align, int32_t xOffset, int32_t yOffset, bool opaque)
 Draws a string on the specified line on the display.
 
EMSTATUS GLIB_drawChar (GLIB_Context_t *pContext, char myChar, int32_t x, int32_t y, bool opaque)
 Draws a char using the font supplied with the library.
 
EMSTATUS GLIB_drawBitmap (GLIB_Context_t *pContext, int32_t x, int32_t y, uint32_t width, uint32_t height, const uint8_t *picData)
 Draws a bitmap.
 
void GLIB_invertBitmap (GLIB_Context_t *pContext, uint32_t bitmapSize, uint8_t *picData)
 Inverts each bit of the bitmap.
 
EMSTATUS GLIB_drawLine (GLIB_Context_t *pContext, int32_t x1, int32_t y1, int32_t x2, int32_t y2)
 Draws a line from x1,y1 to x2, y2.
 
EMSTATUS GLIB_drawLineH (GLIB_Context_t *pContext, int32_t x1, int32_t y1, int32_t x2)
 Draws a horizontal line from x1, y1 to x2, y2.
 
EMSTATUS GLIB_drawLineV (GLIB_Context_t *pContext, int32_t x1, int32_t y1, int32_t y2)
 Draws a vertical line from x1, y1 to x1, y2.
 
EMSTATUS GLIB_drawRect (GLIB_Context_t *pContext, const GLIB_Rectangle_t *pRect)
 Draws a rectangle outline defined by the passed in rectangle.
 
EMSTATUS GLIB_drawRectFilled (GLIB_Context_t *pContext, const GLIB_Rectangle_t *pRect)
 Draws a filled rectangle defined by the passed in rectangle.
 
EMSTATUS GLIB_drawPolygon (GLIB_Context_t *pContext, uint32_t numPoints, const int32_t *polyPoints)
 Draws a polygon using Bresnham's Midpoint Line Algorithm.
 
EMSTATUS GLIB_drawPolygonFilled (GLIB_Context_t *pContext, uint32_t numPoints, const int32_t *polyPoints)
 Draws a filled polygon using a scan line algorithm.
 
EMSTATUS GLIB_drawPixelRGB (GLIB_Context_t *pContext, int32_t x, int32_t y, uint8_t red, uint8_t green, uint8_t blue)
 Draws a pixel at x, y with color defined by red, green and blue 1 byte per channel.
 
EMSTATUS GLIB_drawPixel (GLIB_Context_t *pContext, int32_t x, int32_t y)
 Draws a pixel at x, y using foregroundColor defined in the GLIB_Context_t.
 
EMSTATUS GLIB_drawPixelColor (GLIB_Context_t *pContext, int32_t x, int32_t y, uint32_t color)
 Draws a pixel at x, y using the color parameter.
 

Macros

#define ECODE_GLIB_BASE   0x00000000
 GLIB Base error code.
 
#define GLIB_OK   0x00000000
 Successful call.
 
#define GLIB_ERROR_NOTHING_TO_DRAW   (ECODE_GLIB_BASE | 0x0001)
 Function did not draw.
 
#define GLIB_ERROR_INVALID_CHAR   (ECODE_GLIB_BASE | 0x0002)
 Invalid char.
 
#define GLIB_OUT_OF_BOUNDS   (ECODE_GLIB_BASE | 0x0003)
 Coordinates out of bounds.
 
#define GLIB_ERROR_INVALID_CLIPPINGREGION   (ECODE_GLIB_BASE | 0x0004)
 Invalid coordinates (ex.
 
#define GLIB_ERROR_INVALID_ARGUMENT   (ECODE_GLIB_BASE | 0x0005)
 Invalid argument.
 
#define GLIB_ERROR_OUT_OF_MEMORY   (ECODE_GLIB_BASE | 0x0006)
 Out of memory.
 
#define GLIB_ERROR_FILE_NOT_SUPPORTED   (ECODE_GLIB_BASE | 0x0007)
 File not supported.
 
#define GLIB_ERROR_IO   (ECODE_GLIB_BASE | 0x0008)
 General IO Error.
 
#define GLIB_ERROR_INVALID_FILE   (ECODE_GLIB_BASE | 0x0009)
 Invalid file.
 

Enumerations

enum  __GLIB_Font_Class {
  InvalidFont = 0,
  FullFont,
  NumbersOnlyFont
}
 Font classes.
 
enum  __GLIB_Align {
  GLIB_ALIGN_LEFT,
  GLIB_ALIGN_CENTER,
  GLIB_ALIGN_RIGHT
}
 Alignment types.
 

Variables

const GLIB_Font_t GLIB_FontNormal8x8
 Normal 8x8 pixels font containing characters and numbers.
 
const GLIB_Font_t GLIB_FontNarrow6x8
 Narrow 6x8 pixels font containing characters and numbers.
 
const GLIB_Font_t GLIB_FontNumber16x20
 Large 16x20 pixels font containing only numbers.
 

Function Documentation

◆ GLIB_contextInit()

EMSTATUS GLIB_contextInit ( GLIB_Context_t *  pContext)

Initialize the GLIB_Context_t.

The context is set to default values and gets information about the display from the display driver.

Parameters
pContextPointer to a GLIB_Context_t
Returns
Returns GLIB_OK on success, or else error code

◆ GLIB_displayWakeUp()

EMSTATUS GLIB_displayWakeUp ( )

Returns the display from sleep mode.

Returns
Returns DMD_OK on success, or else error code

◆ GLIB_displaySleep()

EMSTATUS GLIB_displaySleep ( )

Sets the display in sleep mode.

Returns
Returns DMD_OK on success, or else error code

◆ GLIB_clear()

EMSTATUS GLIB_clear ( GLIB_Context_t *  pContext)

Clears the display with the background color of the GLIB_Context_t.

Parameters
pContextPointer to a GLIB_Context_t which holds the background color.
Returns
Returns GLIB_OK on success, or else error code

◆ GLIB_clearRegion()

EMSTATUS GLIB_clearRegion ( const GLIB_Context_t *  pContext)

Clears the clipping region by filling it with the background color of the GLIB_Context_t.

Parameters
pContextPointer to a GLIB_Context_t which holds the background color.
Returns
Returns GLIB_OK on success, or else error code

◆ GLIB_resetDisplayClippingArea()

EMSTATUS GLIB_resetDisplayClippingArea ( GLIB_Context_t *  pContext)

Reset the display driver clipping area to the whole display.

Parameters
pContextPointer to a GLIB_Context_t
Returns
Returns GLIB_OK on success, or else error code

◆ GLIB_resetClippingRegion()

EMSTATUS GLIB_resetClippingRegion ( GLIB_Context_t *  pContext)

Reset the GLIB_Context_t clipping region to the whole display.

Parameters
pContextPointer to a GLIB_Context_t
Returns
Returns GLIB_OK on success, or else error code

◆ GLIB_applyClippingRegion()

EMSTATUS GLIB_applyClippingRegion ( const GLIB_Context_t *  pContext)

Apply the clipping region from the GLIB_Context_t in the DMD driver.

Parameters
pContextPointer to a GLIB_Context_t
Returns
Returns GLIB_OK on success, or else error code

◆ GLIB_colorTranslate24bpp()

void GLIB_colorTranslate24bpp ( uint32_t  color,
uint8_t *  red,
uint8_t *  green,
uint8_t *  blue 
)

Extracts the color components from the 32-bit color passed and puts them in the passed in 8-bits ints.

The color is 24-bit RGB.

Example: color = 0x00FFFF00 -> red = 0xFF, green = 0xFF, blue = 0x00.

Parameters
colorThe color which is to be translated
redPointer to a uint8_t holding the red component
greenPointer to a uint8_t holding the green component
bluePointer to a uint8_t holding the blue component

◆ GLIB_rgbColor()

uint32_t GLIB_rgbColor ( uint8_t  red,
uint8_t  green,
uint8_t  blue 
)

Convert 3 uint8_t color components into a 24-bit color.

Example: red = 0xFF, green = 0xFF, blue = 0x00 -> 0x00FFFF00 = Yellow

Parameters
redRed component
greenGreen component
blueBlue component
Returns
Returns a 32-bit unsigned integer representing the color. The 8 LSB is blue, the next 8 is green and the next 8 is red. 0x00RRGGBB

◆ GLIB_rectContainsPoint()

bool GLIB_rectContainsPoint ( const GLIB_Rectangle_t *  pRect,
int32_t  x,
int32_t 
)

Checks if the point passed in is in the interior of the rectangle passed in.

If the point is on the edge of the rectangle the function returns 1.

Parameters
pRectPointer to a rectangle structure
xX-coordinate of point
yY-coordinate of point
Returns
  • Returns false if coordinate is outside the rectangle
  • Returns true otherwise

◆ GLIB_normalizeRect()

void GLIB_normalizeRect ( GLIB_Rectangle_t *  pRect)

Normalize the rectangle that is passed in.

Sets yMin to the minimum value of yMin and yMax. Sets yMax to the maximum value of yMin and yMax. And the same for xMin and xMax

Parameters
pRectPointer to a rectangle structure

◆ GLIB_setClippingRegion()

EMSTATUS GLIB_setClippingRegion ( GLIB_Context_t *  pContext,
const GLIB_Rectangle_t *  pRect 
)

Sets the clippingRegion of the passed in GLIB_Context_t.

Parameters
pContextPointer to a GLIB_Context_t
pRectPointer to a GLIB_Rectangle_t which is the clipping region to be set.
Returns
  • Returns GLIB_OK on success
  • Returns GLIB_ERROR_INVALID_CLIPPINGREGION if invalid coordinates
  • Returns GLIB_OUT_OF_BOUNDS if clipping region is bigger than display clipping area

◆ GLIB_drawCircle()

EMSTATUS GLIB_drawCircle ( GLIB_Context_t *  pContext,
int32_t  xCenter,
int32_t  yCenter,
uint32_t  radius 
)

Draws a circle with center at x, y, and a radius.

Draws a circle using the Midpoint Circle Algorithm. See Wikipedia for algorithm. Algorithm is optimized to use only integer arithmetic, so no floating point arithmetic is needed.

Parameters
pContextPointer to a GLIB_Context_t in which the circle is drawn. The circle is drawn using the foreground color.
xCenterCenter x-coordinate
yCenterCenter y-coordinate
radiusRadius of the circle
Returns
Returns GLIB_OK on success, or else error code

◆ GLIB_drawCircleFilled()

EMSTATUS GLIB_drawCircleFilled ( GLIB_Context_t *  pContext,
int32_t  xCenter,
int32_t  yCenter,
uint32_t  radius 
)

Draws a filled circle with center at x, y, and a radius.

Draws a circle using the Midpoint Circle Algorithm and using horizontal lines. See Wikipedia for algorithm.

Parameters
pContextPointer to a GLIB_Context_t in which the circle is drawn. The circle is drawn using the foreground color.
xCenterCenter x-coordinate
yCenterCenter y-coordinate
radiusRadius of the circle
Returns
Returns GLIB_OK on succes. Returns GLIB_ERROR_NOTHING_TO_DRAW if none of the pixel coordinates were inside the clipping region. Returns error code otherwise.

◆ GLIB_drawPartialCircle()

EMSTATUS GLIB_drawPartialCircle ( GLIB_Context_t *  pContext,
int32_t  xCenter,
int32_t  yCenter,
uint32_t  radius,
uint8_t  bitMask 
)

Draws a partial circle with center at x, y, and a radius.

Draws a partial circle using the Midpoint Circle Algorithm. Algorithm is optimized to use only integer arithmetic, so no floating point arithmetic is needed. The bitMask passed in decides which octant that should be drawn. The octants is numbered 1 to 8 in counterclockwise order.

Example: bitMask == 4 draws only pixels in 3. octant (00000100). bitMask == 5 draws only pixels in 3. and 1. octant (00000101).

Parameters
pContextPointer to a GLIB_Context_t in which the circle is drawn. The circle is drawn using the foreground color.
xCenterCenter x-coordinate
yCenterCenter y-coordinate
radiusRadius of the circle
bitMaskBitmask which decides which octants pixels should be drawn. The LSB is 1. octant, and the MSB is 8. octant.
Returns
Returns GLIB_OK on success, or else error code

◆ GLIB_setFont()

EMSTATUS GLIB_setFont ( GLIB_Context_t *  pContext,
GLIB_Font_t *  pFont 
)

Set new font for the library.

Note that GLIB defines a default font in glib.c. Redefine GLIB_DEFAULT_FONT to change the default font.

Parameters
pContextPointer to the GLIB_Context_t
pFontPointer to the new font
Returns
Returns GLIB_OK on success, or else error code

◆ GLIB_drawString()

EMSTATUS GLIB_drawString ( GLIB_Context_t *  pContext,
const char *  pString,
uint32_t  sLength,
int32_t  x0,
int32_t  y0,
bool  opaque 
)

Draws a string using the font supplied with the library.

Parameters
pContextPointer to a GLIB_Context_t
pStringPointer to the string that is drawn
sLengthnumber of characters in the string
x0Start x-coordinate for the string (Upper left corner)
y0Start y-coordinate for the string (Upper left corner)
opaqueDetermines whether to show the background or color it with the background color specified by the GLIB_Context_t. If opaque == 1, the background color is used.
Returns
Returns GLIB_OK on success, or else error code

◆ GLIB_drawStringOnLine()

EMSTATUS GLIB_drawStringOnLine ( GLIB_Context_t *  pContext,
const char *  pString,
uint8_t  line,
GLIB_Align_t  align,
int32_t  xOffset,
int32_t  yOffset,
bool  opaque 
)

Draws a string on the specified line on the display.

Parameters
pContextPointer to a GLIB_Context_t
pStringPointer to the string that is drawn
lineSpecifies which line on the display to draw on.
alignHorizontal alignment of the string on the line. This can be left, right or center. Note that left alignment is default.
xOffsetThis parameter can be used to create a margin on the left or right side of the string. Note that this argument accepts a negative value which can be useful when aligning the string to the right.
yOffsetThis parameter can be used to move the string further down or up a certain number of pixels. A positive value would move the string down, while a negative value would move the string up.
opaqueDetermines whether to show the background or color it with the background color specified by the GLIB_Context_t. If opaque == 1, the background color is used.
Returns
Returns GLIB_OK on success, or else error code

◆ GLIB_drawChar()

EMSTATUS GLIB_drawChar ( GLIB_Context_t *  pContext,
char  myChar,
int32_t  x,
int32_t  y,
bool  opaque 
)

Draws a char using the font supplied with the library.

Parameters
pContextPointer to the GLIB_Context_t
myCharChar to be drawn
xStart x-coordinate for the char (Upper left corner)
yStart y-coordinate for the char (Upper left corner)
opaqueDetermines whether to show the background or color it with the background color specified by the GLIB_Context_t. If opaque == true, the background color is used.
Returns
Returns GLIB_OK on success, or else error code

◆ GLIB_drawBitmap()

EMSTATUS GLIB_drawBitmap ( GLIB_Context_t *  pContext,
int32_t  x,
int32_t  y,
uint32_t  width,
uint32_t  height,
const uint8_t *  picData 
)

Draws a bitmap.

Sets up a bitmap that starts at x0,y0 and draws bitmap.

For monochrome displays, each 8-bit element contains 8 pixel values. A bit value of 1 indicates a white pixel, while 0 indicates a black pixel. Note that this format may vary with the DMD implementation.

For 3-bit RGB displays, each bit in the array are one color component (red, green and blue) of the pixel, so that 3 bits represent one pixel (0xBGR). Pixel 0: Bits 2:0 (0bBGR) of byte 0 Pixel 1: Bits 5:3 (0bBGR) of byte 0 Pixel 2: Bits 7:6 (0bGR) of byte 0 and bit 0 (0bB) of byte 1 Pixel 3: Bits 3:1 (0bBGR) of byte 1 ...

For RGB displays with 8-bits per color, each pixel is represented by 24-bits, with one byte for each of the red, green and blue components. The data has to be organized like this: picData = { R, G, B, R, G, B, R, G, B ... }

The pixels are ordered by increasing x coordinate, after the last pixel of a row, the next pixel will be the first pixel on the next row.

Parameters
pContextPointer to a GLIB_Context_t in which the bitmap is drawn.
xStart x-coordinate for bitmap
yStart y-coordinate for bitmap
widthWidth of picture
heightHeight of picture
picDataBitmap data
Returns
Returns GLIB_OK on success, or else error code

◆ GLIB_invertBitmap()

void GLIB_invertBitmap ( GLIB_Context_t *  pContext,
uint32_t  bitmapSize,
uint8_t *  picData 
)

Inverts each bit of the bitmap.

For monochrome displays, the result is an inversion of the image.

For RGB displays, the result is the negative of the input image.

Note
The function inverts entire bytes, meaning that any bits contained within the array that may not be part of the image will also be inverted.
Parameters
pContextPointer to a GLIB_Context_t in which the bitmap is drawn.
bitmapSizeSize of the bitmap array in terms of bytes.
picDataBitmap data.

◆ GLIB_drawLine()

EMSTATUS GLIB_drawLine ( GLIB_Context_t *  pContext,
int32_t  x1,
int32_t  y1,
int32_t  x2,
int32_t  y2 
)

Draws a line from x1,y1 to x2, y2.

Draws a straight line using the Bresnham's Midpoint Line Algorithm. Checks for vertical and horizontal line.

Parameters
pContextPointer to the GLIB_Context_t which holds the clipping region
x1Start x-coordinate
y1Start y-coordinate
x2End x-coordinate
y2End y-coordinate
Returns
Returns GLIB_OK on success, or else error code

◆ GLIB_drawLineH()

EMSTATUS GLIB_drawLineH ( GLIB_Context_t *  pContext,
int32_t  x1,
int32_t  y1,
int32_t  x2 
)

Draws a horizontal line from x1, y1 to x2, y2.

Parameters
pContextPointer to a GLIB_Context_t in which the line is drawn. The line is drawn using the foreground color.
x1Start x-coordinate
y1Start y-coordinate
x2End x-coordinate
Returns
Returns GLIB_OK on success, or else error code

◆ GLIB_drawLineV()

EMSTATUS GLIB_drawLineV ( GLIB_Context_t *  pContext,
int32_t  x1,
int32_t  y1,
int32_t  y2 
)

Draws a vertical line from x1, y1 to x1, y2.

Parameters
pContextPointer to a GLIB_Context_t which the line is drawn. The line is drawn using the foreground color.
x1Start x-coordinate
y1Start y-coordinate
y2End y-coordinate
Returns
Returns GLIB_OK on success, or else error code

◆ GLIB_drawRect()

EMSTATUS GLIB_drawRect ( GLIB_Context_t *  pContext,
const GLIB_Rectangle_t *  pRect 
)

Draws a rectangle outline defined by the passed in rectangle.

Parameters
pContextPointer to a GLIB_Context_t in which the rectangle is drawn. The rectangle is drawn using the foreground color.
pRectPointer to a rectangle structure
Returns
Returns GLIB_OK on success, or else error code

◆ GLIB_drawRectFilled()

EMSTATUS GLIB_drawRectFilled ( GLIB_Context_t *  pContext,
const GLIB_Rectangle_t *  pRect 
)

Draws a filled rectangle defined by the passed in rectangle.

The filled rectangle is drawn from (xMin, yMin) to (xMax, yMax), inclusive, of the rectangle passed in.

Parameters
pContextPointer to a GLIB_Context_t in which the rectangle is drawn. The rectangle is filled with the foreground color.
pRectPointer to a rectangle structure
Returns
Returns GLIB_OK on success, or else error code

◆ GLIB_drawPolygon()

EMSTATUS GLIB_drawPolygon ( GLIB_Context_t *  pContext,
uint32_t  numPoints,
const int32_t *  polyPoints 
)

Draws a polygon using Bresnham's Midpoint Line Algorithm.

This function draws a line between all points outlining the polygon. The first and last point doesn't have to be the same. The function automatically draws a line from the start point to the end point.

Parameters
pContextPointer to a GLIB_Context_t which the line is drawn. The lines are drawn using the foreground color.
numPointsNumber of points in the polygon ( Has to be greater than 1 )
polyPointsPointer to array of polygon points. The points are laid out like this: polyPoints = {x1,y1,x2,y2 ... } Polypoints has to contain at least (numPoints * 2) entries
Returns
Returns GLIB_OK on if at least one element was drawn, or else error code

◆ GLIB_drawPolygonFilled()

EMSTATUS GLIB_drawPolygonFilled ( GLIB_Context_t *  pContext,
uint32_t  numPoints,
const int32_t *  polyPoints 
)

Draws a filled polygon using a scan line algorithm.

This function draws a line between all points outlining the polygon. The first and last point doesn't have to be the same. The function automatically draws a line from the start point to the end point.

Parameters
pContextPointer to a GLIB_Context_t where the polygon is drawn. The polygon drawn using the foreground color.
numPointsNumber of points in the polygon ( Has to be greater than 1 )
polyPointsPointer to array of polygon points. The points are laid out like this: polyPoints = {x1,y1,x2,y2 ... } Polypoints has to contain at least (numPoints * 2) entries
Returns
Returns GLIB_OK on success, otherwise a GLIB error code.

◆ GLIB_drawPixelRGB()

EMSTATUS GLIB_drawPixelRGB ( GLIB_Context_t *  pContext,
int32_t  x,
int32_t  y,
uint8_t  red,
uint8_t  green,
uint8_t  blue 
)

Draws a pixel at x, y with color defined by red, green and blue 1 byte per channel.

Example: To draw a yellow pixel at (10, 10). x = 10, y = 10, red = 0xFF, green = 0xFF, blue = 0x00

Parameters
pContextPointer to a GLIB_Context_t which holds the clipping region
xX-coordinate
yY-coordinate
red8-bit red code
green8-bit green code
blue8-bit blue code
Returns
Returns DMD_OK on success, or else error code

◆ GLIB_drawPixel()

EMSTATUS GLIB_drawPixel ( GLIB_Context_t *  pContext,
int32_t  x,
int32_t 
)

Draws a pixel at x, y using foregroundColor defined in the GLIB_Context_t.

Parameters
pContextPointer to a GLIB_Context_t which holds the foreground color and clipping region
xX-coordinate
yY-coordinate
Returns
Returns GLIB_OK on success, or else error code

◆ GLIB_drawPixelColor()

EMSTATUS GLIB_drawPixelColor ( GLIB_Context_t *  pContext,
int32_t  x,
int32_t  y,
uint32_t  color 
)

Draws a pixel at x, y using the color parameter.

Parameters
pContextPointer to a GLIB_Context_t which holds the clipping region
xX-coordinate
yY-coordinate
color32-bit int defining the RGB color. The 24 LSB defines the RGB color like this: RRRRRRRRGGGGGGGGBBBBBBBB. Example: Yellow = 0x00FFFF00
Returns
Returns DMD_OK on success, or else error code

Macro Definition Documentation

◆ ECODE_GLIB_BASE

#define ECODE_GLIB_BASE   0x00000000

GLIB Base error code.

◆ GLIB_OK

#define GLIB_OK   0x00000000

Successful call.

◆ GLIB_ERROR_NOTHING_TO_DRAW

#define GLIB_ERROR_NOTHING_TO_DRAW   (ECODE_GLIB_BASE | 0x0001)

Function did not draw.

◆ GLIB_ERROR_INVALID_CHAR

#define GLIB_ERROR_INVALID_CHAR   (ECODE_GLIB_BASE | 0x0002)

Invalid char.

◆ GLIB_OUT_OF_BOUNDS

#define GLIB_OUT_OF_BOUNDS   (ECODE_GLIB_BASE | 0x0003)

Coordinates out of bounds.

◆ GLIB_ERROR_INVALID_CLIPPINGREGION

#define GLIB_ERROR_INVALID_CLIPPINGREGION   (ECODE_GLIB_BASE | 0x0004)

Invalid coordinates (ex.

xMin > xMax)

◆ GLIB_ERROR_INVALID_ARGUMENT

#define GLIB_ERROR_INVALID_ARGUMENT   (ECODE_GLIB_BASE | 0x0005)

Invalid argument.

◆ GLIB_ERROR_OUT_OF_MEMORY

#define GLIB_ERROR_OUT_OF_MEMORY   (ECODE_GLIB_BASE | 0x0006)

Out of memory.

◆ GLIB_ERROR_FILE_NOT_SUPPORTED

#define GLIB_ERROR_FILE_NOT_SUPPORTED   (ECODE_GLIB_BASE | 0x0007)

File not supported.

◆ GLIB_ERROR_IO

#define GLIB_ERROR_IO   (ECODE_GLIB_BASE | 0x0008)

General IO Error.

◆ GLIB_ERROR_INVALID_FILE

#define GLIB_ERROR_INVALID_FILE   (ECODE_GLIB_BASE | 0x0009)

Invalid file.

Enumeration Type Documentation

◆ __GLIB_Font_Class

Font classes.

Enumerator
InvalidFont 

Invalid font.

FullFont 

Characters and numbers font.

NumbersOnlyFont 

Numbers only font.

◆ __GLIB_Align

Alignment types.

Variable Documentation

◆ GLIB_FontNormal8x8

const GLIB_Font_t GLIB_FontNormal8x8

Normal 8x8 pixels font containing characters and numbers.

◆ GLIB_FontNarrow6x8

const GLIB_Font_t GLIB_FontNarrow6x8

Narrow 6x8 pixels font containing characters and numbers.

◆ GLIB_FontNumber16x20

const GLIB_Font_t GLIB_FontNumber16x20

Large 16x20 pixels font containing only numbers.