Drawing Functions¶
#include <eglib/drawing.h>
These are generic drawing functions.
- See also
Color¶
Various drawing functions do not take a color argument and instead use the color from a previously defined index.
-
void
eglib_SetIndexColor
(eglib_t * eglib, size_t idx, color_channel_t r, color_channel_t g, color_channel_t b)¶ Set color for given index, which other drawing functions may use.
Pixel¶
-
void
eglib_DrawPixelColor
(eglib_t * eglib, coordinate_t x, coordinate_t y, color_t color)¶ Draw given pixel coordinates with given color.
Example:
eglib_SetIndexColor(&eglib, 0, 0, 255, 0); eglib_DrawPixelColor( &eglib, 10, 10, (color_t){ .r = 0, .g = 255, .b = 0, } );
Output:
-
void
eglib_DrawPixel
(eglib_t * eglib, coordinate_t x, coordinate_t y)¶ Draw given pixel coordinates using color from index 0.
Example:
eglib_SetIndexColor(&eglib, 0, 0, 255, 0); eglib_DrawPixel(&eglib, 10, 10);
Output:
- See also
Lines¶
-
void
eglib_DrawLine
(eglib_t * eglib, coordinate_t x1, coordinate_t y1, coordinate_t x2, coordinate_t y2)¶ Draw line from coordinates (x1, y1) to (x2, y2) using color from index 0.
Example:
eglib_SetIndexColor(&eglib, 0, 0, 255, 0); eglib_DrawLine(&eglib, 0, 0, 99, 0); eglib_DrawLine(&eglib, 0, 0, 50, 50); eglib_DrawLine(&eglib, 0, 0, 0, 99); eglib_DrawLine(&eglib, 99, 99, 99, 0); eglib_DrawLine(&eglib, 99, 99, 50, 50); eglib_DrawLine(&eglib, 99, 99, 0, 99); eglib_DrawLine(&eglib, 0, 99, 50, 50); eglib_DrawLine(&eglib, 99, 0, 50, 50);
Output:
- See also
-
eglib_DrawHLine
(eglib, x, y, len)¶ Draw horizontal line starting at (x, y) with length len using color from index 0.
Example:
eglib_SetIndexColor(&eglib, 0, 0, 255, 0); eglib_DrawHLine(&eglib, 10, 20, 30);
Output:
- See also
-
eglib_DrawVLine
(eglib, x, y, len)¶ Draw vertical line starting at (x, y) with length len using color from index 0.
Example:
eglib_SetIndexColor(&eglib, 0, 0, 255, 0); eglib_DrawVLine(&eglib, 10, 20, 30);
Output:
- See also
-
void
eglib_DrawGradientLine
(eglib_t * eglib, coordinate_t x1, coordinate_t y1, coordinate_t x2, coordinate_t y2)¶ Draw line from coordinates (x1, y1) to (x2, y2).
Line color will be a gradient from index 0 at (x1, y1) to color from index 1 at (x2, y2).
Example:
eglib_SetIndexColor(&eglib, 0, 0, 255, 0); eglib_SetIndexColor(&eglib, 1, 255, 255, 255); eglib_DrawGradientLine(&eglib, 0, 0, 99, 0); eglib_DrawGradientLine(&eglib, 0, 0, 50, 50); eglib_DrawGradientLine(&eglib, 0, 0, 0, 99); eglib_DrawGradientLine(&eglib, 99, 99, 99, 0); eglib_DrawGradientLine(&eglib, 99, 99, 50, 50); eglib_DrawGradientLine(&eglib, 99, 99, 0, 99); eglib_DrawGradientLine(&eglib, 0, 99, 50, 50); eglib_DrawGradientLine(&eglib, 99, 0, 50, 50);
Output:
- See also
-
eglib_DrawGradientHLine
(eglib, x, y, len)¶ Draw horizontal gradient line from coordinates (x, y) to (x + len, y).
Example:
eglib_SetIndexColor(&eglib, 0, 0, 255, 0); eglib_SetIndexColor(&eglib, 1, 255, 255, 255); eglib_DrawGradientHLine(&eglib, 10, 20, 30);
Output:
- See also
-
eglib_DrawGradientVLine
(eglib, x, y, len)¶ Draw vertical gradient line from coordinates (x, y) to (x, y + len).
Example:
eglib_SetIndexColor(&eglib, 0, 0, 255, 0); eglib_SetIndexColor(&eglib, 1, 255, 255, 255); eglib_DrawGradientVLine(&eglib, 10, 20, 30);
Output:
- See also
Triangles¶
-
void
eglib_DrawTriangle
(eglib_t * eglib, coordinate_t x1, coordinate_t y1, coordinate_t x2, coordinate_t y2, coordinate_t x3, coordinate_t y3)¶ Draw triangle for coordinates (x1, y1), (x2, y2) and (x3, y3) using color from index 0.
Example:
eglib_SetIndexColor(&eglib, 0, 0, 255, 0); eglib_DrawTriangle( &eglib, 50, 0, 0, 99, 99, 99 );
Output:
- See also
Frames¶
-
void
eglib_DrawFrame
(eglib_t * eglib, coordinate_t x, coordinate_t y, coordinate_t width, coordinate_t height)¶ Draw frame starting at
(x, y)
withwidth
andheight
using color from index 0.Example:
eglib_SetIndexColor(&eglib, 0, 0, 255, 0); eglib_DrawFrame(&eglib, 10, 10, 80, 80);
Output:
- See also
-
void
eglib_DrawGradientFrame
(eglib_t * eglib, coordinate_t x, coordinate_t y, coordinate_t width, coordinate_t height)¶ Draw frame starting at
(x, y)
withwidth
andheight
.Its colors will be a gradient:
Top left: color index 0.
Top right: color index 1.
Bottom left: color index 2.
Bottom right: color index 3.
Example:
eglib_SetIndexColor(&eglib, 0, 255, 0, 0); eglib_SetIndexColor(&eglib, 1, 0, 255, 0); eglib_SetIndexColor(&eglib, 2, 0, 0, 255); eglib_SetIndexColor(&eglib, 3, 255, 255, 255); eglib_DrawGradientFrame(&eglib, 10, 10, 80, 80);
Output:
- See also
-
void
eglib_DrawRoundFrame
(eglib_t * eglib, coordinate_t x, coordinate_t y, coordinate_t width, coordinate_t height, coordinate_t radius)¶ Draw frame starting at
(x, y)
, withwidth
andheight
and rounded edges withradius
, using color from index 0.Both
width
andheight
must be greater than2 * radius
.Example:
eglib_SetIndexColor(&eglib, 0, 0, 255, 0); eglib_DrawRoundFrame(&eglib, 10, 10, 80, 80, 10);
Output:
- See also
Boxes¶
-
void
eglib_DrawBox
(eglib_t * eglib, coordinate_t x, coordinate_t y, coordinate_t width, coordinate_t height)¶ Draw box starting at
(x, y)
withwidth
andheight
using color from index 0.Example:
eglib_SetIndexColor(&eglib, 0, 0, 255, 0); eglib_DrawBox(&eglib, 10, 10, 80, 80);
Output:
- See also
-
void
eglib_DrawGradientBox
(eglib_t * eglib, coordinate_t x, coordinate_t y, coordinate_t width, coordinate_t height)¶ Draw box starting at
(x, y)
withwidth
andheight
.Its colors will be a gradient:
Top left: color index 0.
Top right: color index 1.
Bottom left: color index 2.
Bottom right: color index 3.
Example:
eglib_SetIndexColor(&eglib, 0, 255, 0, 0); eglib_SetIndexColor(&eglib, 1, 0, 255, 0); eglib_SetIndexColor(&eglib, 2, 0, 0, 255); eglib_SetIndexColor(&eglib, 3, 255, 255, 255); eglib_DrawGradientBox(&eglib, 10, 10, 80, 80);
Output:
- See also
-
void
eglib_DrawRoundBox
(eglib_t * eglib, coordinate_t x, coordinate_t y, coordinate_t width, coordinate_t height, coordinate_t radius)¶ Draw frame starting at
(x, y)
, withwidth
andheight
and rounded edges withradius
, using color from index 0.Both
width
andheight
must be greater than2 * radius
.Example:
eglib_SetIndexColor(&eglib, 0, 0, 255, 0); eglib_DrawRoundBox(&eglib, 10, 10, 80, 80, 10);
Output:
- See also
Round things¶
-
void
eglib_DrawArc
(eglib_t * eglib, coordinate_t x, coordinate_t y, coordinate_t radius, float start_angle, float end_angle)¶ Draw an arc with color from index 0
- Parameters
x – Center x.
y – Center y.
radius – Radius.
start_angle – Start angle from 0 to 360, where 0 is “up” and 90 is “right”.
end_angle – End angle, bigger than
start_angle
and less or equal to 360.
Example:
eglib_SetIndexColor(&eglib, 0, 0, 255, 0); eglib_DrawArc(&eglib, 50, 50, 25, 0, 135);
Output:
-
void
eglib_DrawGradientArc
(eglib_t * eglib, coordinate_t x, coordinate_t y, coordinate_t radius, float start_angle, float end_angle)¶ Draw an arc with color gradient from index 0 to index 1.
- Parameters
x – Center x.
y – Center y.
radius – Radius.
start_angle – Start angle from 0 to 360, where 0 is “up” and 90 is “right”.
end_angle – End angle, bigger than
start_angle
and less or equal to 360.
Example:
eglib_SetIndexColor(&eglib, 0, 0, 255, 0); eglib_SetIndexColor(&eglib, 1, 0, 0, 255); eglib_DrawGradientArc(&eglib, 50, 50, 25, 0, 135);
Output:
-
eglib_DrawCircle
(eglib, x, y, radius)¶ Draw an arc with color from index 0
- Parameters
x – Center x.
y – Center y.
radius – Radius.
Example:
eglib_SetIndexColor(&eglib, 0, 0, 255, 0); eglib_DrawCircle(&eglib, 50, 50, 25);
Output:
-
void
eglib_DrawFilledArc
(eglib_t * eglib, coordinate_t x, coordinate_t y, coordinate_t radius, float start_angle, float end_angle)¶ Draw a filled arc with color from index 0
- Parameters
x – Center x.
y – Center y.
radius – Radius.
start_angle – Start angle from 0 to 360, where 0 is “up” and 90 is “right”.
end_angle – End angle, bigger than
start_angle
and less or equal to 360.
Example:
eglib_SetIndexColor(&eglib, 0, 0, 255, 0); eglib_DrawFilledArc(&eglib, 50, 50, 25, 0, 135);
Output:
-
void
eglib_DrawGradientFilledArc
(eglib_t * eglib, coordinate_t x, coordinate_t y, coordinate_t radius, float start_angle, float end_angle)¶ Draw a filled arc with color gradient from index 0 at the center and index 1 at the radius.
- Parameters
x – Center x.
y – Center y.
radius – Radius.
start_angle – Start angle from 0 to 360, where 0 is “up” and 90 is “right”.
end_angle – End angle, bigger than
start_angle
and less or equal to 360.
Example:
eglib_SetIndexColor(&eglib, 0, 0, 255, 0); eglib_SetIndexColor(&eglib, 1, 0, 0, 255); eglib_DrawGradientFilledArc(&eglib, 50, 50, 25, 0, 135);
Output:
-
eglib_DrawDisc
(eglib, x, y, radius)¶ Draw a disc with color from index 0
- Parameters
x – Center x.
y – Center y.
radius – Radius.
Example:
eglib_SetIndexColor(&eglib, 0, 0, 255, 0); eglib_DrawDisc(&eglib, 50, 50, 25);
Output:
-
eglib_DrawGradientDisc
(eglib, x, y, radius)¶ Draw a disc with color gradient from index 0 at the center and index 1 at the radius.
- Parameters
x – Center x.
y – Center y.
radius – Radius.
Example:
eglib_SetIndexColor(&eglib, 0, 0, 255, 0); eglib_SetIndexColor(&eglib, 1, 0, 0, 255); eglib_DrawGradientDisc(&eglib, 50, 50, 25);
Output:
Bitmaps¶
-
struct
bitmap_t
¶ A bitmap definition.
- See also
-
coordinate_t
width
¶ Width
-
coordinate_t
height
¶ Height
-
enum bitmap_format_t
format
¶ Data format
-
uint8_t *
data
¶ Pointer to bitmap data
-
void
eglib_DrawBitmap
(eglib_t * eglib, coordinate_t x, coordinate_t y, const struct bitmap_t * bitmap)¶ Draw given bitmap at
(x, y)
.Example:
const struct bitmap_t bitmap_bw = { .width = 12, .height = 8, .format = BITMAP_BW, .data = (uint8_t []){0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f}, }; const struct bitmap_t bitmap_rgb = { .width = 9, .height = 9, .format = BITMAP_RGB24, .data = (uint8_t []){ 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, }, }; eglib_DrawBitmap(&eglib, 44, 26, &bitmap_bw); eglib_DrawBitmap(&eglib, 46, 57, &bitmap_rgb);
Output:
Text¶
-
struct
glyph_t
¶ A glyph.
- See also
glyph_block_t
.
-
uint8_t
width
¶ Bitmap width.
-
uint8_t
height
¶ Bitmap height.
-
int8_t
left
¶ Left padding before bitmap.
-
uint8_t
advance
¶ Distance to increment the pen position after rendering this glyph.
-
int8_t
top
¶ Distance from baseline to glyph’s highest pixel.
-
const uint8_t *
data
¶ Bitmap data.
-
struct
glyph_unicode_block_t
¶ Glyphs for a Unicode block.
- See also
-
wchar_t
charcode_start
¶ First unicode character code this font supports.
-
wchar_t
charcode_end
¶ Last unicode character code this font supports.
-
struct
font_t
¶ A Font definition.
-
uint8_t
pixel_size
¶ Font pixel size.
-
int16_t
ascent
¶ The distance from the baseline to the highest or upper grid coordinate used to place an outline point.
-
int16_t
descent
¶ The distance from the baseline to the lowest grid coordinate used to place an outline point.
-
uint16_t
line_space
¶ The distance that must be placed between two lines of text.
-
const struct glyph_unicode_block_t *[5]
unicode_blocks
¶ Array of glyph unicode blocks.
-
uint8_t
unicode_blocks_count
¶ Number of
unicode_blocks
.
-
uint8_t
-
void
eglib_SetFont
(eglib_t * eglib, const struct font_t * font)¶ Set font to be used by other font functions.
- See also
- See also
-
_Bool
eglib_AddUnicodeBlockToFont
(struct font_t * font, const struct glyph_unicode_block_t * unicode_block)¶ Add given unicode block to font.
Returns true in case of error, false on success.
Example:
coordinate_t x, y; x = 40 - 14; y = 30 + 14 / 2; eglib_SetIndexColor(&eglib, 0, 0, 0, 128); eglib_DrawLine(&eglib, 0, y, 100, y); eglib_DrawLine(&eglib, 0, y * 2, 100, y * 2); eglib_DrawLine(&eglib, x, 0, x, 100); eglib_SetFont(&eglib, &font_Liberation_SansRegular_20px); eglib_SetIndexColor(&eglib, 0, 255, 255, 255); eglib_DrawText(&eglib, x, y, "Fábio"); eglib_AddUnicodeBlockToFont( &font_Liberation_SansRegular_20px, &unicode_block_Liberation_SansRegular_20px_Latin1Supplement ); eglib_DrawText(&eglib, x, y * 2, "Fábio");
Output:
- See also
- See also
-
const struct glyph_t *
eglib_GetGlyph
(eglib_t * eglib, wchar_t unicode_char)¶ Return given unicode character’s
glyph_t
or NULL if unsupported by font.
-
void
eglib_DrawGlyph
(eglib_t * eglib, coordinate_t x, coordinate_t y, const struct glyph_t * glyph)¶ Draw given
glyph_t
at(x, y)
.Example:
coordinate_t x, y; x = 50 - 14; y = 50 + 14 / 2; eglib_SetIndexColor(&eglib, 0, 0, 0, 128); eglib_DrawLine(&eglib, 0, y, 100, y); eglib_DrawLine(&eglib, x, 0, x, 100); eglib_SetFont(&eglib, &font_Liberation_SansRegular_20px); eglib_SetIndexColor(&eglib, 0, 255, 255, 255); eglib_DrawGlyph(&eglib, x, y, eglib_GetGlyph(&eglib, 'A'));
Output:
-
void
eglib_DrawWChar
(eglib_t * eglib, coordinate_t x, coordinate_t y, wchar_t unicode_char)¶ Draw given unicode character glyph at
(x, y)
.Example:
coordinate_t x, y; x = 50 - 14; y = 30 + 14 / 2; eglib_SetIndexColor(&eglib, 0, 0, 0, 128); eglib_DrawLine(&eglib, 0, y, 100, y); eglib_DrawLine(&eglib, 0, y * 2, 100, y * 2); eglib_DrawLine(&eglib, x, 0, x, 100); eglib_SetFont(&eglib, &font_Liberation_SansRegular_20px); eglib_SetIndexColor(&eglib, 0, 255, 255, 255); eglib_DrawWChar(&eglib, x, y, 'g'); eglib_DrawWChar(&eglib, x, y * 2, 9999); // Unsupported by font
Output:
-
void
eglib_DrawFilledWChar
(eglib_t * eglib, coordinate_t x, coordinate_t y, wchar_t unicode_char)¶ Similar to
eglib_DrawWChar()
, but fills the background using color from index 1.Example:
coordinate_t x, y; x = 50 - 14; y = 50; eglib_SetIndexColor(&eglib, 0, 0, 0, 128); eglib_DrawLine(&eglib, 0, y, 100, y); eglib_DrawLine(&eglib, x, 0, x, 100); eglib_SetFont(&eglib, &font_Liberation_SansRegular_20px); eglib_SetIndexColor(&eglib, 0, 255, 255, 255); eglib_SetIndexColor(&eglib, 1, 64, 64, 64); eglib_DrawFilledWChar(&eglib, x, y, '!');
Output:
-
void
eglib_DrawText
(eglib_t * eglib, coordinate_t x, coordinate_t y, const char * utf8_text)¶ Draw given UTF-8 text starting at
(x, y)
.Example:
coordinate_t x, y; x = 50 - 20; y = 50 + 14 / 2; eglib_SetIndexColor(&eglib, 0, 0, 0, 128); eglib_DrawLine(&eglib, 0, y, 99, y); eglib_DrawLine(&eglib, x, 0, x, 99); eglib_SetFont(&eglib, &font_Liberation_SansRegular_20px); eglib_AddUnicodeBlockToFont( &font_Liberation_SansRegular_20px, &unicode_block_Liberation_SansRegular_20px_Latin1Supplement ); eglib_SetIndexColor(&eglib, 0, 255, 255, 255); eglib_DrawText(&eglib, x, y, "Olá!");
Output:
-
eglib_DrawTextCentered
(eglib, x, y, utf8_text)¶ Similar to
eglib_DrawText()
, but centers text horizontally at given coordinatesExample:
coordinate_t x, y; x = 50 - 20; y = 50 + 14 / 2; eglib_SetIndexColor(&eglib, 0, 0, 0, 128); eglib_DrawLine(&eglib, 0, y, 99, y); eglib_DrawLine(&eglib, x, 0, x, 99); eglib_SetFont(&eglib, &font_Liberation_SansRegular_20px); eglib_SetIndexColor(&eglib, 0, 255, 255, 255); eglib_DrawTextCentered(&eglib, x, y, "Hello!");
Output:
-
coordinate_t
eglib_GetTextWidth
(eglib_t * eglib, const char * utf8_text)¶ Return the width in pixels of the given UTF-8 text.
- See also