BSB Developer Docs
Loading...
Searching...
No Matches
canvas.h File Reference

A canvas widget for drawing arbitrary graphics. More...

#include <gui/widget.h>
#include <toolbox/color.h>

Go to the source code of this file.

Typedefs

typedef struct Canvas Canvas
 Canvas opaque structure.
 

Functions

Canvas * canvas_alloc (Widget *parent, int32_t width, int32_t height)
 Create a new Canvas instance.
 
void canvas_free (Canvas *instance)
 Delete a Canvas instance.
 
void canvas_draw_begin (Canvas *instance)
 Initialize the drawing process.
 
void canvas_draw_end (Canvas *instance)
 Finalize the drawing process.
 
Widget * canvas_get_base (Canvas *instance)
 Get a pointer to the base class instance.
 
void canvas_set_fill_color (Canvas *instance, Color color)
 Set the color for fill operations.
 
void canvas_set_fill_opacity (Canvas *instance, uint8_t opacity)
 Set the opacity for fill operations.
 
void canvas_set_line_color (Canvas *instance, Color color)
 Set the color for line drawing operations.
 
void canvas_set_line_width (Canvas *instance, int32_t width)
 Set the line width for line drawing operations.
 
void canvas_set_line_opacity (Canvas *instance, uint8_t opacity)
 Set the opacity for line drawing operations.
 
void canvas_clear (Canvas *instance)
 Clear all canvas contents.
 
void canvas_fill (Canvas *instance)
 Fill the canvas with solid color.
 
void canvas_draw_pixel (Canvas *instance, int32_t x, int32_t y, Color color)
 Draw a single pixel with the given coordinates and color.
 
void canvas_draw_line (Canvas *instance, int32_t x1, int32_t y1, int32_t x2, int32_t y2)
 Draw a single segment between two points.
 
void canvas_draw_rect (Canvas *instance, int32_t x, int32_t y, int32_t w, int32_t h, bool fill)
 Draw a rectangle based on its top-left corner and dimensions.
 
void canvas_draw_text (Canvas *instance, int32_t x, int32_t y, const char *text)
 Draw a plain text label.
 

Detailed Description

A canvas widget for drawing arbitrary graphics.

Note
Currently, only the RBG888 color format is supported.

Function Documentation

◆ canvas_alloc()

Canvas * canvas_alloc ( Widget * parent,
int32_t width,
int32_t height )

Create a new Canvas instance.

Parameters
[in,out]parentpointer to the parent Widget instance
[in]widthcanvas width in pixels
[in]heightcanvas height in pixels
Returns
pointer to the newly created Canvas instance

◆ canvas_clear()

void canvas_clear ( Canvas * instance)

Clear all canvas contents.

Previously set drawing parameters will remain unchanged.

Parameters
[in,out]instancepointer to the Canvas instance to be cleared

◆ canvas_draw_begin()

void canvas_draw_begin ( Canvas * instance)

Initialize the drawing process.

This function must be called before any drawing operations.

Parameters
[in,out]instancepointer to the Canvas instance to be drawn on

◆ canvas_draw_end()

void canvas_draw_end ( Canvas * instance)

Finalize the drawing process.

This function must be called after all drawing operations.

Parameters
[in,out]instancepointer to the Canvas instance to be drawn on

◆ canvas_draw_line()

void canvas_draw_line ( Canvas * instance,
int32_t x1,
int32_t y1,
int32_t x2,
int32_t y2 )

Draw a single segment between two points.

Parameters
[in,out]instancepointer to the Canvas instance to be drawn on
[in]x1horizontal (x) coordinate of the starting point
[in]y1vertical (y) coordinate of the starting point
[in]x2horizontal (x) coordinate of the ending point
[in]y2vertical (y) coordinate of the ending point

◆ canvas_draw_pixel()

void canvas_draw_pixel ( Canvas * instance,
int32_t x,
int32_t y,
Color color )

Draw a single pixel with the given coordinates and color.

Note
Drawing pixel-by pixel is relatively slow, prefer using drawing primitives if performance is required.
The color of the pixel is given during the call, it is independent fron the set fill/line colors.
Parameters
[in,out]instancepointer to the Canvas instance to be drawn on
[in]xhorizontal (x) coordinate of the pixel
[in]yvertical (y) coordinate of the pixel
[in]colorcolor of the pixel

◆ canvas_draw_rect()

void canvas_draw_rect ( Canvas * instance,
int32_t x,
int32_t y,
int32_t w,
int32_t h,
bool fill )

Draw a rectangle based on its top-left corner and dimensions.

Parameters
[in,out]instancepointer to the Canvas instance to be drawn on
[in]xhorizontal (x) coordinate of the corner
[in]yvertical (y) coordinate of the corner
[in]whorizontal dimension of the rectangle
[in]hvertical dimension of the rectangle
[in]fillif true, fill the rectangle with the fill color, otherwise draw only its border

◆ canvas_draw_text()

void canvas_draw_text ( Canvas * instance,
int32_t x,
int32_t y,
const char * text )

Draw a plain text label.

Parameters
[in,out]instancepointer to the Canvas instance to be drawn on
[in]xhorizontal (x) offset of the text
[in]yvertical (y) offset of the text
[in]textzero-terminated string containing the text to be shown

◆ canvas_fill()

void canvas_fill ( Canvas * instance)

Fill the canvas with solid color.

Parameters
[in,out]instancepointer to the Canvas instance to be filled

◆ canvas_free()

void canvas_free ( Canvas * instance)

Delete a Canvas instance.

Parameters
[in,out]instancepointer to the Canvas instance to be deleted

◆ canvas_get_base()

Widget * canvas_get_base ( Canvas * instance)

Get a pointer to the base class instance.

The return value can be used in all Widget methods.

Parameters
[in,out]instancepointer to the Canvas instance to be queried
Returns
pointer to the base class instance

◆ canvas_set_fill_color()

void canvas_set_fill_color ( Canvas * instance,
Color color )

Set the color for fill operations.

Parameters
[in,out]instancepointer to the Canvas instance to be modified
[in]colorColor to be used as fill color

◆ canvas_set_fill_opacity()

void canvas_set_fill_opacity ( Canvas * instance,
uint8_t opacity )

Set the opacity for fill operations.

Parameters
[in,out]instancepointer to the Canvas instance to be modified
[in]opacityopacity value for fills (0 - transparent, 255 - fully opaque)

◆ canvas_set_line_color()

void canvas_set_line_color ( Canvas * instance,
Color color )

Set the color for line drawing operations.

Parameters
[in,out]instancepointer to the Canvas instance to be modified
[in]colorColor to be used as line color

◆ canvas_set_line_opacity()

void canvas_set_line_opacity ( Canvas * instance,
uint8_t opacity )

Set the opacity for line drawing operations.

Parameters
[in,out]instancepointer to the Canvas instance to be modified
[in]opacityopacity value for lines (0 - transparent, 255 - fully opaque)

◆ canvas_set_line_width()

void canvas_set_line_width ( Canvas * instance,
int32_t width )

Set the line width for line drawing operations.

Parameters
[in,out]instancepointer to the Canvas instance to be modified
[in]widthline width in pixels (0 - no lines)