libg19draw Reference

libg19draw is a library that allows you to construct a virtual 4 byte per pixel bitmap. Currently a few of the features are: line draw, filling, circle drawing and filling, inserting other drawing on each other, loading 24 and 32 bit(aplha) bitmaps.

Macros:

Structures

Functions:

 

LIBG19DRAW_VERSION_MAJOR

The major version of libg19draw. (x.0.0)

LIBG19DRAW_VERSION_MINOR

The minor version of libg19draw. (0.x.0)

LIBG19DRAW_VERSION_MICRO

The micro version of libg19draw. (0.0.x)

LIBG19DRAW_VERSION

The version of libg19draw as a string.

G19_WIDTH

The width of the G19’s LCD in pixels.

G19_HEIGHT

The height of the G19’s LCD in pixels.

 

G19ColorA(r, g, b, a)

This takes four colors: red, green, blue, and alpha. It with turn them into a unsigned int color.

Parameters:

int r The amount of red. (0 – 255)
int g The amount of green. (0 – 255)
int b The amount of blue. (0 – 255)
int a The amount of alpha. (0 – 255)

Return:

An unsigned int containing the color.

 

G19Color(r, g, b)

This is the same as G19ColorA but it does not use the alpha byte.

Parameters:

int r The amount of red. (0 – 255)
int g The amount of green. (0 – 255)
int b The amount of blue. (0 – 255)

Return:

An unsigned int containing the color.

 

G19SetA(c, a)

Sets the alpha byte on a color.

Parameters:

unsigned int c An unsigned int containing the color.
int a The amount of alpha. (0 – 255)

Return:

An unsigned int containing the color.

 

G19R(c)

Gets the amount of red in a color.

Parameters:

int c An unsigned int containing the color.

Return:

The amount of red in the color. (0 – 255)

 

G19G(c)

Gets the amount of green in a color.

Parameters:

int c An unsigned int containing the color.

Return:

The amount of green in the color. (0 – 255)

 

G19B(c)

Gets the amount of blue in a color.

Parameters:

int c An unsigned int containing the color.

Return:

The amount of blue in the color. (0 – 255)

 

G19A(c)

Gets the amount of alpha in a color.

Parameters:

int c An unsigned int containing the color.

Return:

The amount of alpha in the color. (0 – 255)

 

G19Draw

The drawing structure.

Fields:

int width The width of the draw in pixels.
int height The height of the draw in pixels.
size_t size The size of the draw data. (width * height * 4)
unsigned char * data The data for the draw. A 4 byte per pixel bitmap. Note that it is just bitmap data. There is no bitmap header.

 

G19Font

The font structure.

Fields:

FT_Library lib “A handle to a FreeType library instance.” – FreeType.org
FT_Face face “A handle to a given typographic face object.” – FreeType.org
int width The width of the font character(s) in pixels.
int height The height of the font character(s) in pixels.
int space The amout of space between charaters in pixels.
unsigned int color The color to use. You can use G19Color or G19ColorA.

 

G19Draw * g19_draw_new(int width, int height)

Creates a new G19Draw to the specified width and height.

Parameters:

int width The width of the image in pixels.
int height The height of the image in pixels.

Return:

A pointer to a G19Draw.

 

G19Draw * g19_draw_bmp(char * path)

Loads a bitmap into a new G19Draw. Currently only 24 bit and 32 bit alpha bitmaps are supported.

Parameters:

char * path The path to the bitmap to load.

Return:

A pointer to a G19Draw or NULL on error.

 

void g19_draw_free(G19Draw * draw)

Frees the data inside a G19Draw and then the G19Draw.

Parameters:

G19Draw * draw A pointer to a G19Draw.

 

void g19_draw_to_bmp(G19Draw * draw)

Writes the data from a G19Draw to a 24-bit bitmap at the specified path.

Parameters:

G19Draw * draw A pointer to a G19Draw.
char * path A string containing the path.

Return:

Non-zero on error.

 

G19Draw * g19_draw_resize(G19Draw * draw, int width, int height, unsigned int color, int free_old)

Resizes a G19Draw. It creates a new drawing at the new size then copies over the old data. It will also free the old drawing if specified.

Parameters:

G19Draw * draw A pointer to a G19Draw.
int width The width of the new G19Draw.
int height The height of the new G19Draw.
unsigned int color The color to use set the background to if the old image is smaller that the new one. You can use G19Color or G19ColorA.
int free_old 0 to leave the old G19Draw or 1 to free it.

Return:

A pointer to a new G19Draw.

 

void g19_draw_insert(G19Draw * draw, G19Draw * idraw, int ix, int iy)

Inserts a G19Draw onto another G19Draw.

Parameters:

G19Draw * draw A pointer to the The G19Draw that should be inserted onto.
G19Draw * idraw A pointer to the G19Draw that should be inserted.
int ix The starting x point on draw for the upper-left corner of idraw.
int iy The starting y point on draw for the upper-left corner of idraw.

 

void g19_draw_insert_ab(G19Draw * draw, G19Draw * idraw, int ix, int iy, int opac)

This function is the same as g19_draw_insert except that it supports alpha blending.

Parameters:

G19Draw * draw A pointer to the G19Draw that should be inserted onto.
G19Draw * idraw A pointer to the G19Draw that should be inserted.
int ix The starting x point on draw for the upper-left corner of idraw.
int iy The starting y point on draw for the upper-left corner of idraw.
int opac The level of alpha to use. (0 – 255) If it is less than 0, it will uses the value stored in the alpha byte.

 

unsigned int g19_draw_get_pixel(G19Draw * draw, int x, int y)

Gets a pixel from a G19Draw.

Parameters:

G19Draw * draw A pointer to a G19Draw.
int x The x coordinate of the pixel.
int y The y coordinate of the pixel.

Return:

An unsigned int containing the pixel’s color. G19R, G19G, G19B, and G19A can be used to extract values from the color.

 

void g19_draw_set_pixel(G19Draw * draw, int x, int y, unsigned int color)

Sets a single pixel on the G19Draw.

Parameters:

G19Draw * draw A pointer to a G19Draw.
int x The x coordinate of the pixel.
int y The y coordinate of the pixel.
unsigned int color The color to use. You can use G19Color or G19ColorA.

 

void g19_draw_fill(G19Draw * draw, unsigned int color)

Fills a G19Draw with the specified color.

Parameters:

G19Draw * draw A pointer to a G19Draw.
unsigned int color The color to use. You can use G19Color or G19ColorA.

 

void g19_draw_line(G19Draw * draw, int x1, int y1, int x2, int y2, unsigned int color)

Draws a line on a G19Draw between two points.

Parameters:

G19Draw * draw A pointer to a G19Draw.
int x1 The x coordinate of the first point.
int y1 The y coordinate of the first point.
int x2 The x coordinate of the second point.
int y2 The y coordinate of the second point.
unsigned int color The color to use. You can use G19Color or G19ColorA.

 

void g19_draw_rect(G19Draw * draw, int left, int top, int right, int bottom, int fill, unsigned int color)

Draws a rectangle on G19Draw.

Parameters:

G19Draw * draw A pointer to a G19Draw.
int left The left-most point of the rectangle. (x coordinate)
int top The top-most point of the rectangle. (y coordinate)
int right The right-most point of the rectangle. (x coordinate)
int bottom The bottom-most point of the rectangle. (y coordinate)
int fill Non-zero fills the rectangle. If it is 0, a 1 pixel border will be drawn.
unsigned int color The color to use. You can use G19Color or G19ColorA.

 

void g19_draw_circle(G19Draw * draw, int cx, int cy, int cr, int fill, unsigned int color)

Draws a circle on a G19Draw.

Parameters:

G19Draw * draw A pointer to a G19Draw.
int cx The x coordinate of the circle’s center.
int cy The y coordinate of the circle’s center.
int cr The radius of the circle in pixels.
int fill Non-zero fills the circle. If it is 0, a 1 pixel border will be drawn.
unsigned int color The color to use. You can use G19Color or G19ColorA.

 

G19Font * g19_font_new(char * ttf_path, int width, int height, int space, unsigned int color)

Creates a new G19Font.

Parameters:

char * ttf_path The path of the ttf font file to use.
int width The width of the font character(s).
int height The height of the font character(s).
int space The space between characters in pixels.
unsigned int color The color to use. You can use G19Color or G19ColorA.

Return:

A pointer to a G19Font.

 

void g19_font_set_size(G19Font * font, int width, int height)

Sets the font size on a G19Font.

Parameters:

G19Font * font A pointer to a G19Font.
int width The width of the character(s) in pixels.
int height The height of the character(s) in pixels.

 

void g19_font_set_space(G19Font * font, int space)

Sets the character spacing on a G19Font.

Parameters:

G19Font * font A pointer to a G19Font.
int space The space between characters in pixels.

 

void g19_font_set_color(G19Font * font, unsigned int color)

Sets the color of the font a G19Font.

Parameters:

G19Font * font A pointer to a G19Font.
unsigned int color The color to use. You can use G19Color or G19ColorA.

 

int g19_font_draw(G19Font * font, G19Draw * draw, int x, int y, char * text)

Draws font onto a G19Draw

Parameters:

G19Font * font A pointer to a G19Font.
G19Draw * draw A pointer to a G19Draw.
int x The x coordinate on draw to start at.
int y The y coordinate on draw to start at.
char * text The text to draw.

Return:

 

void g19_font_free(G19Font * font)

Frees a G19Font.

Parameters:

G19Font * font A pointer to a G19Font.

 

libg19 Reference

libg19 is the library that is used to interface with the g19.  It will control the back-lighting color, M-Key leds, M-Key presses, G-Key presses, L-Key presses and sending data to the LCD.

Macros:

Enumerations:

Typedefs:

Functions:

 

LIBG19_VERSION_MAJOR

The major version of libg19. (x.0.0)

LIBG19_VERSION_MINOR

The minor version of libg19. (0.x.0)

LIBG19_VERSION_MICRO

The micro version of libg19. (0.0.x)

LIBG19_VERSION

The verion of libg19 as a string.

G19_BMP_SIZE

The size of the BMP data sent to the LCD with header data.

G19_BMP_DSIZE

The size of the BMP data with with out hdata that is sent to the LCD.

 

enum G19UpdateFlags

Flags that are used by g19_update_lcd.

Enumerators:

G19_SCREEN_DEFAULT Specifies the default. You don’t have to specify this. Will be used in the future.
G19_PREPEND_HDATA Specifies that the header data should be applied to the data before it is sent.
G19_DATA_TYPE_RAW Specifies that nothing is to be done to the data and it should be directly sent to the LCD.
G19_DATA_TYPE_BMP Flags the data as being 4 bytes per pixel data. This is what libg19draw produces. Use this option if you updating from libg19draw data.

 

enum G19Keys

The keys used by various things.

Enumerators:

G19_KEY_G1 The G1 key.
G19_KEY_G2 The G2 key.
G19_KEY_G3 The G3 key.
G19_KEY_G4 The G4 key.
G19_KEY_G5 The G5 key.
G19_KEY_G6 The G6 key.
G19_KEY_G7 The G7 key.
G19_KEY_G8 The G8 key.
G19_KEY_G9 The G9 key.
G19_KEY_G10 The G10 key.
G19_KEY_G11 The G11 key.
G19_KEY_G12 The G12 key.
G19_KEY_M1 The M1 key.
G19_KEY_M2 The M2 key.
G19_KEY_M3 The M3 key.
G19_KEY_MR The MR key.
G19_KEY_LHOME The home key. The key that has a square with a gray gear in the lower right.
G19_KEY_LCANCEL The cancel key. The that looks lie <-
G19_KEY_LMENU The menu key.
G19_KEY_LOK The OK key.
G19_KEY_LRIGHT The right arrow key.
G19_KEY_LLEFT The left arrow key.
G19_KEY_LDOWN The down arrow key.
G19_KEY_LUP The up arrow key.

 

typedef void(* g19_keys_cb)(unsigned int keys)

Callback function for a keypress of either a L-Key(s) or G-Key(s). You can set the callback to be called with either g19_set_gkeys_cb or g19_set_lkeys_cb.

Parameters:

unsigned int keys The key(s) that invoked the function. The keys are joined with a bitwise OR. Use a bitwise AND to see if the key you are looking for was pressed.

 

int g19_init(int level)

Initializes the g19 library. During this process it looks for a g19 device. If one is found, it claims it and detaches the OS’s driver.

Parameters:

int level
  • 0: no messages ever printed by the library (default)
  • 1: error messages are printed to stderr
  • 2: warning and error messages are printed to stderr
  • 3: informational messages are printed to stdout, warning and error messages are printed to stderr

Return:

Non-Zero on error.

 

void g19_deinit(void)

This frees up things on the libraries end, releases the device, and resets the devie to the OS.

 

void g19_set_gkeys_cb(g19_keys_cb cb)

Sets a callback that will be invoked when a G-Key or an M-Key is pressed.

Parameters:

g19_keys_cb cb The callback function to be invoked.

 

void g19_set_leys_cb(g19_keys_cb cb)

Sets a callback that will be invoked when a L-Key is pressed.

Parameters:

g19_keys_cb cb The callback function to be invoked.

 

void g19_update_lcd(unsigned char * data, size_t size, unsigned int flags)

Sends screen data to the LCD.

Parameters:

unsigned char * data The data to be sent to the LCD.
size_t size The size of the data to be sent to the LCD.
unsigned int flags The flags that should be applied to the data.

 

int g19_set_backlight(unsigned char r, unsigned char g, unsigned char b)

Sets the keyboards backlight. Note that the keyboard’s default white color is not 255, 255, 255. It’s 110, 255, 110. Thanks to dutchfish for this.

Parameters:

unsigned char r The amount of red. (0 – 255)
unsigned char g The amount of green. (0 – 255)
unsigned char b The amount of blue. (0 – 255)

Return:

Non-zero on error.

 

int g19_set_mkey_led(unsigned int keys)

Sets the M-Keys led lights.

Parameters:

unsigned int keys The key(s) to set the led on for. You can use G19_KEY_M1, G19_KEY_M2, G19_KEY_M3, and G19_KEY_MR. For more than one use bitwise OR.

Return:

Non-zero on error.