Skip to content
modkitv0.2

canvas.h

#include <modkit/canvas.h>105 functions · 10 structs · 5 enums · 20 typedefs · 5 macros

Context-based 2D drawing primitives for multi-threaded rendering.

Provides thread-safe 2D shape rendering using transient buffers. All coordinates are in screen pixels with origin at top-left. Each thread should use its own draw2d context:

Functions

mk_canvas_arcfunction

void mk_canvas_arc(mk_canvas_t ctx, float cx, float cy, float radius, float start_angle, float end_angle, uint32_t color)

Draw a filled arc (pie slice).

ParameterTypeDescription
ctxmk_canvas_tContext handle
cxfloatCenter X
cyfloatCenter Y
radiusfloatRadius
start_anglefloatStart angle in radians (0 = right, clockwise)
end_anglefloatEnd angle in radians
coloruint32_tRGBA color (0xRRGGBBAA)

mk_canvas_arc_outlinefunction

void mk_canvas_arc_outline(mk_canvas_t ctx, float cx, float cy, float radius, float start_angle, float end_angle, uint32_t color, float thickness)

Draw an arc outline.

ParameterTypeDescription
ctxmk_canvas_tContext handle
cxfloatCenter X
cyfloatCenter Y
radiusfloatRadius
start_anglefloatStart angle in radians
end_anglefloatEnd angle in radians
coloruint32_tRGBA color
thicknessfloatLine thickness

mk_canvas_beginfunction

void mk_canvas_begin(mk_canvas_t ctx, mk_encoder_t encoder, mk_view_id_t view, uint16_t width, uint16_t height)

Begin 2D drawing mode.

Uses a view previously configured by mk_canvas_prepare_view().

ParameterTypeDescription
ctxmk_canvas_tContext handle
encodermk_encoder_tEncoder from mk_render_ctx_encoder() or mk_encoder_begin()
viewmk_view_id_tView ID to draw to
widthuint16_tScreen width in logical pixels
heightuint16_tScreen height in logical pixels

mk_canvas_begin_exfunction

bool mk_canvas_begin_ex(mk_canvas_t ctx, const mk_canvas_begin_desc *desc)

Begin Canvas drawing with independent logical and framebuffer dimensions.

ParameterTypeDescription
ctxmk_canvas_tActive operation context.
descconst mk_canvas_begin_desc *Configuration descriptor.

Returns True when the operation succeeds.

mk_canvas_circlefunction

void mk_canvas_circle(mk_canvas_t ctx, float cx, float cy, float radius, uint32_t color, int segments)

Draw a filled circle.

ParameterTypeDescription
ctxmk_canvas_tContext handle
cxfloatCenter X
cyfloatCenter Y
radiusfloatRadius
coloruint32_tRGBA color (0xRRGGBBAA)
segmentsintNumber of segments (higher = smoother, 0 = auto)

mk_canvas_circle_dashedfunction

void mk_canvas_circle_dashed(mk_canvas_t ctx, float cx, float cy, float radius, uint32_t color, float thickness, float dash_length, float gap_length, int segments)

Draw a dashed circle outline.

ParameterTypeDescription
ctxmk_canvas_tContext handle
cxfloatCenter X
cyfloatCenter Y
radiusfloatRadius
coloruint32_tRGBA color
thicknessfloatLine thickness
dash_lengthfloatLength of each dash
gap_lengthfloatLength of each gap
segmentsintNumber of segments (0 = auto)

mk_canvas_circle_outlinefunction

void mk_canvas_circle_outline(mk_canvas_t ctx, float cx, float cy, float radius, uint32_t color, float thickness, int segments)

Draw a circle outline.

ParameterTypeDescription
ctxmk_canvas_tContext handle
cxfloatCenter X
cyfloatCenter Y
radiusfloatRadius
coloruint32_tRGBA color (0xRRGGBBAA)
thicknessfloatLine thickness
segmentsintNumber of segments (0 = auto)

mk_canvas_createfunction

mk_canvas_t mk_canvas_create(void)

Create a new draw2d context.

Each context has its own batch buffers for thread-safe rendering.

Returns Context handle, or MK_CANVAS_CTX_INVALID on failure

mk_canvas_default_ctxfunction

mk_canvas_t mk_canvas_default_ctx(void)

Get default draw2d context (auto-created).

Returns The resulting handle or value.

mk_canvas_default_viewfunction

mk_view_id_t mk_canvas_default_view(void)

Get default 2D view ID.

Returns The resulting handle or value.

mk_canvas_destroyfunction

void mk_canvas_destroy(mk_canvas_t ctx)

Destroy a draw2d context.

Context must not be in draw mode.

ParameterTypeDescription
ctxmk_canvas_tActive operation context.

mk_canvas_ellipsefunction

void mk_canvas_ellipse(mk_canvas_t ctx, float cx, float cy, float rx, float ry, uint32_t color, int segments)

Draw a filled ellipse.

ParameterTypeDescription
ctxmk_canvas_tContext handle
cxfloatCenter X
cyfloatCenter Y
rxfloatRadius X
ryfloatRadius Y
coloruint32_tRGBA color (0xRRGGBBAA)
segmentsintNumber of segments (0 = auto)

mk_canvas_endfunction

void mk_canvas_end(mk_canvas_t ctx)

End 2D drawing mode and flush all batched draws.

ParameterTypeDescription
ctxmk_canvas_tContext handle

mk_canvas_fill_circlefunction

void mk_canvas_fill_circle(mk_canvas_t ctx, float cx, float cy, float radius, int segments)

Filled circle using the current fill paint (solid / shader; image => tint).

ParameterTypeDescription
ctxmk_canvas_tActive operation context.
cxfloatValue for cx.
cyfloatValue for cy.
radiusfloatValue for radius.
segmentsintValue for segments.

mk_canvas_fill_rectfunction

void mk_canvas_fill_rect(mk_canvas_t ctx, float x, float y, float w, float h)

Filled rect using the current fill paint (solid / image / shader).

ParameterTypeDescription
ctxmk_canvas_tActive operation context.
xfloatValue for x.
yfloatValue for y.
wfloatValue for w.
hfloatValue for h.

mk_canvas_flushfunction

void mk_canvas_flush(void)

Flush pending simple API draws (called automatically at frame end).

mk_canvas_initfunction

bool mk_canvas_init(void)

Initialize 2D drawing system (called automatically by mk_app_run).

Loads shared shaders used by all contexts.

Returns true on success

mk_canvas_is_drawingfunction

bool mk_canvas_is_drawing(mk_canvas_t ctx)

Check if context is in draw mode.

ParameterTypeDescription
ctxmk_canvas_tActive operation context.

Returns True when the condition holds.

mk_canvas_linefunction

void mk_canvas_line(mk_canvas_t ctx, float x1, float y1, float x2, float y2, uint32_t color, float thickness)

Draw a line.

ParameterTypeDescription
ctxmk_canvas_tContext handle
x1floatStart point
y1floatStart point
x2floatEnd point
y2floatEnd point
coloruint32_tRGBA color (0xRRGGBBAA)
thicknessfloatLine thickness

mk_canvas_line_dashedfunction

void mk_canvas_line_dashed(mk_canvas_t ctx, float x1, float y1, float x2, float y2, uint32_t color, float thickness, float dash_length, float gap_length)

Draw a dashed line.

ParameterTypeDescription
ctxmk_canvas_tContext handle
x1floatStart point
y1floatStart point
x2floatEnd point
y2floatEnd point
coloruint32_tRGBA color
thicknessfloatLine thickness
dash_lengthfloatLength of each dash
gap_lengthfloatLength of each gap

mk_canvas_mask_beginfunction

void mk_canvas_mask_begin(mk_canvas_t ctx)

Begin a stencil mask.

Shapes drawn before mk_canvas_mask_end() update the stencil buffer without writing color.

ParameterTypeDescription
ctxmk_canvas_tActive operation context.

mk_canvas_mask_clearfunction

void mk_canvas_mask_clear(mk_canvas_t ctx)

Clear the canvas stencil buffer and disable the active mask test.

ParameterTypeDescription
ctxmk_canvas_tActive operation context.

mk_canvas_mask_endfunction

void mk_canvas_mask_end(mk_canvas_t ctx)

Finish the mask shape and stencil-test subsequent canvas draws against it.

ParameterTypeDescription
ctxmk_canvas_tActive operation context.

mk_canvas_nine_slicefunction

void mk_canvas_nine_slice(mk_canvas_t ctx, mk_texture_t tex, float x, float y, float w, float h, float left, float right, float top, float bottom, uint32_t tint)

Draw a nine-slice (9-patch) sprite.

The texture is divided into 9 regions that scale appropriately:Corners: fixed sizeEdges: stretch in one directionCenter: stretches in both directions

ParameterTypeDescription
ctxmk_canvas_tContext handle
texmk_texture_tTexture to draw
xfloatDestination left edge
yfloatDestination top edge
wfloatDestination width
hfloatDestination height
leftfloatLeft border width in pixels
rightfloatRight border width in pixels
topfloatTop border height in pixels
bottomfloatBottom border height in pixels
tintuint32_tColor tint (0xffffffff = no tint)

mk_canvas_nine_slice_spritefunction

void mk_canvas_nine_slice_sprite(mk_canvas_t ctx, mk_sprite_t sprite, float x, float y, float w, float h, float left, float right, float top, float bottom, uint32_t tint, bool fill_center)

Draw a nine-slice from one sprite or atlas region.

Borders are measured in source pixels and retain that size at the destination. If the destination is smaller than the opposing borders, both are reduced proportionally so quads never invert.

ParameterTypeDescription
ctxmk_canvas_tContext handle
spritemk_sprite_tSource sprite or atlas region
xfloatDestination left edge
yfloatDestination top edge
wfloatDestination width
hfloatDestination height
leftfloatLeft source border width in pixels
rightfloatRight source border width in pixels
topfloatTop source border height in pixels
bottomfloatBottom source border height in pixels
tintuint32_tRGBA color tint
fill_centerboolDraw the center region when true

mk_canvas_path_arc_tofunction

void mk_canvas_path_arc_to(mk_canvas_t ctx, float cx, float cy, float radius, float start_angle, float end_angle, bool ccw)

Add arc to path.

ParameterTypeDescription
ctxmk_canvas_tContext handle
cxfloatCenter X
cyfloatCenter Y
radiusfloatRadius
start_anglefloatStart angle in radians
end_anglefloatEnd angle in radians
ccwboolCounter-clockwise if true

mk_canvas_path_beginfunction

void mk_canvas_path_begin(mk_canvas_t ctx)

Begin a new path.

ParameterTypeDescription
ctxmk_canvas_tContext handle

mk_canvas_path_bezier_tofunction

void mk_canvas_path_bezier_to(mk_canvas_t ctx, float c1x, float c1y, float c2x, float c2y, float x, float y)

Add cubic bezier curve to path.

ParameterTypeDescription
ctxmk_canvas_tContext handle
c1xfloatFirst control point X
c1yfloatFirst control point Y
c2xfloatSecond control point X
c2yfloatSecond control point Y
xfloatEnd point X
yfloatEnd point Y

mk_canvas_path_builder_arc_tofunction

bool mk_canvas_path_builder_arc_to(mk_canvas_path_builder_t *builder, float cx, float cy, float radius, float start_angle, float end_angle, bool ccw)

Perform the canvas path builder arc to operation.

ParameterTypeDescription
buildermk_canvas_path_builder_t *Value for builder.
cxfloatValue for cx.
cyfloatValue for cy.
radiusfloatValue for radius.
start_anglefloatValue for start angle.
end_anglefloatValue for end angle.
ccwboolValue for ccw.

Returns True when the operation succeeds.

mk_canvas_path_builder_bezier_tofunction

bool mk_canvas_path_builder_bezier_to(mk_canvas_path_builder_t *builder, float c1x, float c1y, float c2x, float c2y, float x, float y)

Perform the canvas path builder bezier to operation.

ParameterTypeDescription
buildermk_canvas_path_builder_t *Value for builder.
c1xfloatValue for c1x.
c1yfloatValue for c1y.
c2xfloatValue for c2x.
c2yfloatValue for c2y.
xfloatValue for x.
yfloatValue for y.

Returns True when the operation succeeds.

mk_canvas_path_builder_buildfunction

mk_canvas_path_t mk_canvas_path_builder_build(const mk_canvas_path_builder_t *builder)

Build canvas path builder.

ParameterTypeDescription
builderconst mk_canvas_path_builder_t *Value for builder.

Returns The resulting handle or value.

mk_canvas_path_builder_closefunction

bool mk_canvas_path_builder_close(mk_canvas_path_builder_t *builder)

Close canvas path builder.

ParameterTypeDescription
buildermk_canvas_path_builder_t *Value for builder.

Returns True when the operation succeeds.

mk_canvas_path_builder_createfunction

mk_canvas_path_builder_t * mk_canvas_path_builder_create(void)

Create canvas path builder.

Returns A borrowed pointer, or NULL when unavailable.

mk_canvas_path_builder_destroyfunction

void mk_canvas_path_builder_destroy(mk_canvas_path_builder_t *builder)

Destroy the canvas path builder.

ParameterTypeDescription
buildermk_canvas_path_builder_t *Value for builder.

mk_canvas_path_builder_ellipsefunction

bool mk_canvas_path_builder_ellipse(mk_canvas_path_builder_t *builder, float cx, float cy, float rx, float ry)

Perform the canvas path builder ellipse operation.

ParameterTypeDescription
buildermk_canvas_path_builder_t *Value for builder.
cxfloatValue for cx.
cyfloatValue for cy.
rxfloatValue for rx.
ryfloatValue for ry.

Returns True when the operation succeeds.

mk_canvas_path_builder_is_validfunction

bool mk_canvas_path_builder_is_valid(const mk_canvas_path_builder_t *builder)

Test whether the canvas path builder is valid.

ParameterTypeDescription
builderconst mk_canvas_path_builder_t *Value for builder.

Returns True when the condition holds.

mk_canvas_path_builder_line_tofunction

bool mk_canvas_path_builder_line_to(mk_canvas_path_builder_t *builder, float x, float y)

Perform the canvas path builder line to operation.

ParameterTypeDescription
buildermk_canvas_path_builder_t *Value for builder.
xfloatValue for x.
yfloatValue for y.

Returns True when the operation succeeds.

mk_canvas_path_builder_move_tofunction

bool mk_canvas_path_builder_move_to(mk_canvas_path_builder_t *builder, float x, float y)

Perform the canvas path builder move to operation.

ParameterTypeDescription
buildermk_canvas_path_builder_t *Value for builder.
xfloatValue for x.
yfloatValue for y.

Returns True when the operation succeeds.

mk_canvas_path_builder_quad_tofunction

bool mk_canvas_path_builder_quad_to(mk_canvas_path_builder_t *builder, float cx, float cy, float x, float y)

Perform the canvas path builder quad to operation.

ParameterTypeDescription
buildermk_canvas_path_builder_t *Value for builder.
cxfloatValue for cx.
cyfloatValue for cy.
xfloatValue for x.
yfloatValue for y.

Returns True when the operation succeeds.

mk_canvas_path_builder_rectfunction

bool mk_canvas_path_builder_rect(mk_canvas_path_builder_t *builder, float x, float y, float w, float h, float radius)

Perform the canvas path builder rect operation.

ParameterTypeDescription
buildermk_canvas_path_builder_t *Value for builder.
xfloatValue for x.
yfloatValue for y.
wfloatValue for w.
hfloatValue for h.
radiusfloatValue for radius.

Returns True when the operation succeeds.

mk_canvas_path_builder_resetfunction

void mk_canvas_path_builder_reset(mk_canvas_path_builder_t *builder)

Reset the canvas path builder.

ParameterTypeDescription
buildermk_canvas_path_builder_t *Value for builder.

mk_canvas_path_closefunction

void mk_canvas_path_close(mk_canvas_t ctx)

Close current subpath.

ParameterTypeDescription
ctxmk_canvas_tContext handle

mk_canvas_path_destroyfunction

void mk_canvas_path_destroy(mk_canvas_path_t path)

Destroy the canvas path.

ParameterTypeDescription
pathmk_canvas_path_tValue for path.

mk_canvas_path_drawfunction

bool mk_canvas_path_draw(mk_canvas_t ctx, mk_canvas_path_t path, const mk_canvas_path_draw_desc_t *desc)

Draw an immutable retained path.

ParameterTypeDescription
ctxmk_canvas_tActive operation context.
pathmk_canvas_path_tValue for path.
descconst mk_canvas_path_draw_desc_t *Configuration descriptor.

Returns True when the operation succeeds.

mk_canvas_path_draw_currentfunction

bool mk_canvas_path_draw_current(mk_canvas_t ctx, const mk_canvas_path_draw_desc_t *desc)

Draw the current immediate path with rich fill, stroke, and effects.

ParameterTypeDescription
ctxmk_canvas_tActive operation context.
descconst mk_canvas_path_draw_desc_t *Configuration descriptor.

Returns True when the operation succeeds.

mk_canvas_path_ellipsefunction

void mk_canvas_path_ellipse(mk_canvas_t ctx, float cx, float cy, float rx, float ry)

Add ellipse to path.

ParameterTypeDescription
ctxmk_canvas_tContext handle
cxfloatCenter X
cyfloatCenter Y
rxfloatRadius X
ryfloatRadius Y

mk_canvas_path_fillfunction

void mk_canvas_path_fill(mk_canvas_t ctx, uint32_t color)

Fill the current path.

ParameterTypeDescription
ctxmk_canvas_tContext handle
coloruint32_tFill color

mk_canvas_path_is_validfunction

bool mk_canvas_path_is_valid(mk_canvas_path_t path)

Test whether the canvas path is valid.

ParameterTypeDescription
pathmk_canvas_path_tValue for path.

Returns True when the condition holds.

mk_canvas_path_line_tofunction

void mk_canvas_path_line_to(mk_canvas_t ctx, float x, float y)

Add line to current path.

ParameterTypeDescription
ctxmk_canvas_tContext handle
xfloatX coordinate
yfloatY coordinate

mk_canvas_path_move_tofunction

void mk_canvas_path_move_to(mk_canvas_t ctx, float x, float y)

Move to a point (start new subpath).

ParameterTypeDescription
ctxmk_canvas_tContext handle
xfloatX coordinate
yfloatY coordinate

mk_canvas_path_quad_tofunction

void mk_canvas_path_quad_to(mk_canvas_t ctx, float cx, float cy, float x, float y)

Add quadratic bezier curve to path.

ParameterTypeDescription
ctxmk_canvas_tContext handle
cxfloatControl point X
cyfloatControl point Y
xfloatEnd point X
yfloatEnd point Y

mk_canvas_path_rectfunction

void mk_canvas_path_rect(mk_canvas_t ctx, float x, float y, float w, float h, float radius)

Add rounded rectangle to path.

ParameterTypeDescription
ctxmk_canvas_tContext handle
xfloatLeft edge
yfloatTop edge
wfloatWidth
hfloatHeight
radiusfloatCorner radius

mk_canvas_path_strokefunction

void mk_canvas_path_stroke(mk_canvas_t ctx, uint32_t color, float thickness)

Stroke the current path.

ParameterTypeDescription
ctxmk_canvas_tContext handle
coloruint32_tStroke color
thicknessfloatLine thickness

mk_canvas_polygonfunction

void mk_canvas_polygon(mk_canvas_t ctx, const float *points, int count, uint32_t color)

Draw a filled polygon.

ParameterTypeDescription
ctxmk_canvas_tContext handle
pointsconst float *Array of [x, y] pairs
countintNumber of points
coloruint32_tRGBA color (0xRRGGBBAA)

mk_canvas_polylinefunction

void mk_canvas_polyline(mk_canvas_t ctx, const float *points, int count, uint32_t color, float thickness, bool closed)

Draw a polyline (connected line segments).

ParameterTypeDescription
ctxmk_canvas_tContext handle
pointsconst float *Array of [x, y] pairs
countintNumber of points
coloruint32_tRGBA color (0xRRGGBBAA)
thicknessfloatLine thickness
closedboolIf true, connect last point to first

mk_canvas_pop_clipfunction

void mk_canvas_pop_clip(mk_canvas_t ctx)

Pop the current clip region.

ParameterTypeDescription
ctxmk_canvas_tContext handle

mk_canvas_prepare_viewfunction

bool mk_canvas_prepare_view(mk_view_id_t view, uint16_t width, uint16_t height)

Configure the canvas view on the API thread before encoder submission.

ParameterTypeDescription
viewmk_view_id_tValue for view.
widthuint16_tValue for width.
heightuint16_tValue for height.

Returns True when the operation succeeds.

mk_canvas_push_clipfunction

void mk_canvas_push_clip(mk_canvas_t ctx, float x, float y, float w, float h)

Push a rectangular clip region in the current local coordinate space.

The transformed rectangle's screen-space AABB is intersected with the current clip. This intentionally differs from the pre-0.1 screen-space behavior.

ParameterTypeDescription
ctxmk_canvas_tContext handle
xfloatLeft edge
yfloatTop edge
wfloatWidth
hfloatHeight

mk_canvas_rectfunction

void mk_canvas_rect(mk_canvas_t ctx, float x, float y, float w, float h, uint32_t color)

Draw a filled rectangle.

ParameterTypeDescription
ctxmk_canvas_tContext handle
xfloatLeft edge
yfloatTop edge
wfloatWidth
hfloatHeight
coloruint32_tRGBA color (0xRRGGBBAA)

mk_canvas_rect_dashedfunction

void mk_canvas_rect_dashed(mk_canvas_t ctx, float x, float y, float w, float h, uint32_t color, float thickness, float dash_length, float gap_length)

Draw a dashed rectangle outline.

ParameterTypeDescription
ctxmk_canvas_tContext handle
xfloatLeft edge
yfloatTop edge
wfloatWidth
hfloatHeight
coloruint32_tRGBA color
thicknessfloatLine thickness
dash_lengthfloatLength of each dash
gap_lengthfloatLength of each gap

mk_canvas_rect_gradient_4function

void mk_canvas_rect_gradient_4(mk_canvas_t ctx, float x, float y, float w, float h, uint32_t tl, uint32_t tr, uint32_t bl, uint32_t br)

Draw a rectangle with 4-corner gradient.

ParameterTypeDescription
ctxmk_canvas_tContext handle
xfloatLeft edge
yfloatTop edge
wfloatWidth
hfloatHeight
tluint32_tTop-left color
truint32_tTop-right color
bluint32_tBottom-left color
bruint32_tBottom-right color

mk_canvas_rect_gradient_hfunction

void mk_canvas_rect_gradient_h(mk_canvas_t ctx, float x, float y, float w, float h, uint32_t left_color, uint32_t right_color)

Draw a rectangle with horizontal gradient.

ParameterTypeDescription
ctxmk_canvas_tContext handle
xfloatLeft edge
yfloatTop edge
wfloatWidth
hfloatHeight
left_coloruint32_tLeft color (0xRRGGBBAA)
right_coloruint32_tRight color (0xRRGGBBAA)

mk_canvas_rect_gradient_radialfunction

void mk_canvas_rect_gradient_radial(mk_canvas_t ctx, float x, float y, float w, float h, uint32_t inner_color, uint32_t outer_color)

Draw a rectangle with radial gradient.

ParameterTypeDescription
ctxmk_canvas_tContext handle
xfloatLeft edge
yfloatTop edge
wfloatWidth
hfloatHeight
inner_coloruint32_tCenter color
outer_coloruint32_tEdge color

mk_canvas_rect_gradient_vfunction

void mk_canvas_rect_gradient_v(mk_canvas_t ctx, float x, float y, float w, float h, uint32_t top_color, uint32_t bottom_color)

Draw a rectangle with vertical gradient.

ParameterTypeDescription
ctxmk_canvas_tContext handle
xfloatLeft edge
yfloatTop edge
wfloatWidth
hfloatHeight
top_coloruint32_tTop color (0xRRGGBBAA)
bottom_coloruint32_tBottom color (0xRRGGBBAA)

mk_canvas_rect_outlinefunction

void mk_canvas_rect_outline(mk_canvas_t ctx, float x, float y, float w, float h, uint32_t color, float thickness)

Draw a rectangle outline.

ParameterTypeDescription
ctxmk_canvas_tContext handle
xfloatLeft edge
yfloatTop edge
wfloatWidth
hfloatHeight
coloruint32_tRGBA color (0xRRGGBBAA)
thicknessfloatLine thickness

mk_canvas_rect_outline_rounded_exfunction

void mk_canvas_rect_outline_rounded_ex(mk_canvas_t ctx, float x, float y, float w, float h, mk_canvas_corner_radii radii, mk_canvas_edge_widths widths, uint32_t color)

Draw an inset rounded border with independent corner radii and edge widths.

Negative radii and widths are treated as zero.

ParameterTypeDescription
ctxmk_canvas_tActive operation context.
xfloatValue for x.
yfloatValue for y.
wfloatValue for w.
hfloatValue for h.
radiimk_canvas_corner_radiiValue for radii.
widthsmk_canvas_edge_widthsValue for widths.
coloruint32_tValue for color.

mk_canvas_rect_roundedfunction

void mk_canvas_rect_rounded(mk_canvas_t ctx, float x, float y, float w, float h, float radius, uint32_t color)

Draw a filled rectangle with rounded corners.

ParameterTypeDescription
ctxmk_canvas_tContext handle
xfloatLeft edge
yfloatTop edge
wfloatWidth
hfloatHeight
radiusfloatCorner radius
coloruint32_tRGBA color (0xRRGGBBAA)

mk_canvas_rect_rounded_exfunction

void mk_canvas_rect_rounded_ex(mk_canvas_t ctx, float x, float y, float w, float h, mk_canvas_corner_radii radii, uint32_t color)

Draw a filled rectangle with independent corner radii.

ParameterTypeDescription
ctxmk_canvas_tActive operation context.
xfloatValue for x.
yfloatValue for y.
wfloatValue for w.
hfloatValue for h.
radiimk_canvas_corner_radiiValue for radii.
coloruint32_tValue for color.

mk_canvas_reset_transformfunction

void mk_canvas_reset_transform(mk_canvas_t ctx)

Reset transform to identity.

ParameterTypeDescription
ctxmk_canvas_tContext handle

mk_canvas_restorefunction

void mk_canvas_restore(mk_canvas_t ctx)

Restore transform state from stack.

ParameterTypeDescription
ctxmk_canvas_tContext handle

mk_canvas_ringfunction

void mk_canvas_ring(mk_canvas_t ctx, float cx, float cy, float inner_radius, float outer_radius, uint32_t color, int segments)

Draw a ring (donut) shape.

ParameterTypeDescription
ctxmk_canvas_tContext handle
cxfloatCenter X
cyfloatCenter Y
inner_radiusfloatInner radius
outer_radiusfloatOuter radius
coloruint32_tRGBA color
segmentsintNumber of segments (0 = auto)

mk_canvas_ring_arcfunction

void mk_canvas_ring_arc(mk_canvas_t ctx, float cx, float cy, float inner_radius, float outer_radius, float start_angle, float end_angle, uint32_t color)

Draw a partial ring (arc with thickness).

ParameterTypeDescription
ctxmk_canvas_tContext handle
cxfloatCenter X
cyfloatCenter Y
inner_radiusfloatInner radius
outer_radiusfloatOuter radius
start_anglefloatStart angle in radians
end_anglefloatEnd angle in radians
coloruint32_tRGBA color

mk_canvas_rotatefunction

void mk_canvas_rotate(mk_canvas_t ctx, float angle)

Apply rotation to current transform.

ParameterTypeDescription
ctxmk_canvas_tContext handle
anglefloatRotation angle in radians (clockwise)

mk_canvas_savefunction

void mk_canvas_save(mk_canvas_t ctx)

Save current transform state onto stack.

ParameterTypeDescription
ctxmk_canvas_tContext handle

mk_canvas_scalefunction

void mk_canvas_scale(mk_canvas_t ctx, float sx, float sy)

Apply scale to current transform.

ParameterTypeDescription
ctxmk_canvas_tContext handle
sxfloatScale X
syfloatScale Y

mk_canvas_set_blend_modefunction

void mk_canvas_set_blend_mode(mk_canvas_t ctx, mk_blend_mode_t mode)

Set blend mode for subsequent draws.

ParameterTypeDescription
ctxmk_canvas_tContext handle
modemk_blend_mode_tBlend mode

mk_canvas_set_fillfunction

void mk_canvas_set_fill(mk_canvas_t ctx, mk_paint paint)

Set the current fill paint (default: solid white).

ParameterTypeDescription
ctxmk_canvas_tActive operation context.
paintmk_paintValue for paint.

mk_canvas_set_strokefunction

void mk_canvas_set_stroke(mk_canvas_t ctx, mk_paint paint)

Set the current stroke paint.

ParameterTypeDescription
ctxmk_canvas_tActive operation context.
paintmk_paintValue for paint.

mk_canvas_set_transformfunction

void mk_canvas_set_transform(mk_canvas_t ctx, const float *mtx)

Set transform matrix directly.

ParameterTypeDescription
ctxmk_canvas_tContext handle
mtxconst float *3x2 transform matrix [a, b, c, d, tx, ty]

mk_canvas_shutdownfunction

void mk_canvas_shutdown(void)

Shutdown 2D drawing system (called automatically on cleanup).

mk_canvas_spritefunction

void mk_canvas_sprite(mk_canvas_t ctx, mk_texture_t tex, float x, float y, float w, float h)

Draw a textured sprite.

ParameterTypeDescription
ctxmk_canvas_tContext handle
texmk_texture_tTexture to draw
xfloatLeft edge
yfloatTop edge
wfloatWidth (use 0 for texture width)
hfloatHeight (use 0 for texture height)

mk_canvas_sprite_fbfunction

void mk_canvas_sprite_fb(mk_canvas_t ctx, mk_texture_t tex, float x, float y, float w, float h)

Draw a framebuffer/render-target texture as a sprite.

Automatically flips V coordinates on OpenGL (where framebuffer origin is bottom-left). Use this instead of mk_canvas_sprite when displaying render-to-texture results.

ParameterTypeDescription
ctxmk_canvas_tActive operation context.
texmk_texture_tValue for tex.
xfloatValue for x.
yfloatValue for y.
wfloatValue for w.
hfloatValue for h.

mk_canvas_sprite_fb_srgbfunction

void mk_canvas_sprite_fb_srgb(mk_canvas_t ctx, mk_texture_t tex, float x, float y, float w, float h)

Draw a linear framebuffer/render-target texture as a display-ready sRGB sprite.

Automatically flips V coordinates on OpenGL (where framebuffer origin is bottom-left). Use for final presentation of tone-mapped linear scene color to a normal backbuffer.

ParameterTypeDescription
ctxmk_canvas_tActive operation context.
texmk_texture_tValue for tex.
xfloatValue for x.
yfloatValue for y.
wfloatValue for w.
hfloatValue for h.

mk_canvas_sprite_rotatedfunction

void mk_canvas_sprite_rotated(mk_canvas_t ctx, mk_texture_t tex, float x, float y, float w, float h, float rotation, uint32_t tint)

Draw a textured sprite with rotation.

ParameterTypeDescription
ctxmk_canvas_tContext handle
texmk_texture_tTexture to draw
xfloatCenter X
yfloatCenter Y
wfloatWidth
hfloatHeight
rotationfloatRotation in radians
tintuint32_tRGBA color tint

mk_canvas_sprite_rotated_subfunction

void mk_canvas_sprite_rotated_sub(mk_canvas_t ctx, mk_texture_t tex, float x, float y, float w, float h, float rotation, float u0, float v0, float u1, float v1, uint32_t tint)

Draw a rotated sprite with a normalized UV sub-region.

ParameterTypeDescription
ctxmk_canvas_tContext handle
texmk_texture_tTexture to draw
xfloatCenter X
yfloatCenter Y
wfloatWidth
hfloatHeight
rotationfloatRotation in radians
u0floatLeft U coordinate
v0floatTop V coordinate
u1floatRight U coordinate
v1floatBottom V coordinate
tintuint32_tRGBA color tint

mk_canvas_sprite_rounded_exfunction

void mk_canvas_sprite_rounded_ex(mk_canvas_t ctx, mk_texture_t tex, float x, float y, float w, float h, mk_rectf uv, uint32_t tint, mk_canvas_corner_radii radii)

Draw a normalized UV rectangle from a texture with independent destination corner radii.

ParameterTypeDescription
ctxmk_canvas_tActive operation context.
texmk_texture_tValue for tex.
xfloatValue for x.
yfloatValue for y.
wfloatValue for w.
hfloatValue for h.
uvmk_rectfValue for UV.
tintuint32_tValue for tint.
radiimk_canvas_corner_radiiValue for radii.

mk_canvas_sprite_subfunction

void mk_canvas_sprite_sub(mk_canvas_t ctx, mk_texture_t tex, float x, float y, float w, float h, float sx, float sy, float sw, float sh, uint32_t tint)

Draw a portion of a texture (for sprite sheets).

The source rect is in NORMALIZED texture coordinates (0..1), not pixels. Convert with mk_texture_get_size() at the call site; negative sw/sh flip the region. mk_sprite_draw() does this conversion for you.

ParameterTypeDescription
ctxmk_canvas_tContext handle
texmk_texture_tTexture to draw
xfloatDestination left edge
yfloatDestination top edge
wfloatDestination width
hfloatDestination height
sxfloatSource U origin (0..1)
syfloatSource V origin (0..1)
swfloatSource U extent (0..1)
shfloatSource V extent (0..1)
tintuint32_tRGBA color tint (0xffffffff = no tint)

mk_canvas_sprite_sub_flipfunction

void mk_canvas_sprite_sub_flip(mk_canvas_t ctx, mk_texture_t tex, float x, float y, float w, float h, float sx, float sy, float sw, float sh, uint32_t tint, mk_flip_t flip)

Draw a portion of a texture with a texture-space flip applied.

Same normalized-UV convention as mk_canvas_sprite_sub(). This is the single point where flips are resolved; MK_FLIP_DIAG cannot be expressed by negative scale, which is why it exists.

ParameterTypeDescription
ctxmk_canvas_tContext handle
texmk_texture_tTexture to draw
xfloatDestination left edge
yfloatDestination top edge
wfloatDestination width
hfloatDestination height
sxfloatSource U origin in normalized coordinates
syfloatSource V origin in normalized coordinates
swfloatSource U extent in normalized coordinates
shfloatSource V extent in normalized coordinates
tintuint32_tRGBA color tint
flipmk_flip_tBitmask of mk_flip_t, applied DIAG then H then V (Tiled's order)

mk_canvas_sprite_tintedfunction

void mk_canvas_sprite_tinted(mk_canvas_t ctx, mk_texture_t tex, float x, float y, float w, float h, uint32_t tint)

Draw a textured sprite with color tint.

ParameterTypeDescription
ctxmk_canvas_tContext handle
texmk_texture_tTexture to draw
xfloatLeft edge
yfloatTop edge
wfloatWidth (use 0 for texture width)
hfloatHeight (use 0 for texture height)
tintuint32_tRGBA color tint (0xRRGGBBAA, 0xffffffff = no tint)

mk_canvas_translatefunction

void mk_canvas_translate(mk_canvas_t ctx, float x, float y)

Apply translation to current transform.

ParameterTypeDescription
ctxmk_canvas_tContext handle
xfloatX offset
yfloatY offset

mk_canvas_trianglefunction

void mk_canvas_triangle(mk_canvas_t ctx, float x1, float y1, float x2, float y2, float x3, float y3, uint32_t color)

Draw a filled triangle.

ParameterTypeDescription
ctxmk_canvas_tContext handle
x1floatFirst vertex
y1floatFirst vertex
x2floatSecond vertex
y2floatSecond vertex
x3floatThird vertex
y3floatThird vertex
coloruint32_tRGBA color (0xRRGGBBAA)

mk_circle2dfunction

void mk_circle2d(float cx, float cy, float radius, uint32_t color)

Draw filled circle.

ParameterTypeDescription
cxfloatValue for cx.
cyfloatValue for cy.
radiusfloatValue for radius.
coloruint32_tValue for color.

mk_circle2d_outlinefunction

void mk_circle2d_outline(float cx, float cy, float radius, uint32_t color, float thickness)

Draw circle outline.

ParameterTypeDescription
cxfloatValue for cx.
cyfloatValue for cy.
radiusfloatValue for radius.
coloruint32_tValue for color.
thicknessfloatValue for thickness.

mk_line2dfunction

void mk_line2d(float x1, float y1, float x2, float y2, uint32_t color, float thickness)

Draw 2D line.

ParameterTypeDescription
x1floatValue for x1.
y1floatValue for y1.
x2floatValue for x2.
y2floatValue for y2.
coloruint32_tValue for color.
thicknessfloatValue for thickness.

mk_paint_colorfunction

mk_paint mk_paint_color(uint32_t rgba)

Solid-color paint.

ParameterTypeDescription
rgbauint32_tValue for RGBA.

Returns The resulting value.

mk_paint_imagefunction

mk_paint mk_paint_image(mk_texture_t tex, uint32_t tint)

Image (texture) paint with a tint (0 => white).

ParameterTypeDescription
texmk_texture_tValue for tex.
tintuint32_tValue for tint.

Returns The resulting value.

mk_paint_linear_gradientfunction

mk_paint mk_paint_linear_gradient(float x0, float y0, float x1, float y1, const mk_paint_stop *stops, uint8_t stop_count)

Create an ordered linear gradient.

Invalid stops are normalized at draw time.

ParameterTypeDescription
x0floatValue for x0.
y0floatValue for y0.
x1floatValue for x1.
y1floatValue for y1.
stopsconst mk_paint_stop *Value for stops.
stop_countuint8_tNumber of stop entries.

Returns The resulting value.

mk_paint_radial_gradientfunction

mk_paint mk_paint_radial_gradient(float cx, float cy, float inner_radius, float outer_radius, const mk_paint_stop *stops, uint8_t stop_count)

Create an ordered radial gradient with concentric inner and outer circles.

ParameterTypeDescription
cxfloatValue for cx.
cyfloatValue for cy.
inner_radiusfloatValue for inner radius.
outer_radiusfloatValue for outer radius.
stopsconst mk_paint_stop *Value for stops.
stop_countuint8_tNumber of stop entries.

Returns The resulting value.

mk_paint_shaderfunction

mk_paint mk_paint_shader(mk_material_t material)

Custom-shader paint (the shared custom-shading primitive).

ParameterTypeDescription
materialmk_material_tValue for material.

Returns The resulting value.

mk_rect2dfunction

void mk_rect2d(float x, float y, float w, float h, uint32_t color)

Draw filled rectangle.

ParameterTypeDescription
xfloatValue for x.
yfloatValue for y.
wfloatValue for w.
hfloatValue for h.
coloruint32_tValue for color.

mk_rect2d_outlinefunction

void mk_rect2d_outline(float x, float y, float w, float h, uint32_t color, float thickness)

Draw rectangle outline.

ParameterTypeDescription
xfloatValue for x.
yfloatValue for y.
wfloatValue for w.
hfloatValue for h.
coloruint32_tValue for color.
thicknessfloatValue for thickness.

mk_rect2d_roundedfunction

void mk_rect2d_rounded(float x, float y, float w, float h, float radius, uint32_t color)

Draw rounded rectangle.

ParameterTypeDescription
xfloatValue for x.
yfloatValue for y.
wfloatValue for w.
hfloatValue for h.
radiusfloatValue for radius.
coloruint32_tValue for color.

mk_spritefunction

void mk_sprite(mk_texture_t tex, float x, float y, float w, float h)

Draw texture.

ParameterTypeDescription
texmk_texture_tValue for tex.
xfloatValue for x.
yfloatValue for y.
wfloatValue for w.
hfloatValue for h.

mk_sprite_subfunction

void mk_sprite_sub(mk_texture_t tex, float x, float y, float w, float h, float u0, float v0, float u1, float v1, uint32_t tint)

Draw texture region (for sprite sheets, using UV coordinates 0-1).

ParameterTypeDescription
texmk_texture_tValue for tex.
xfloatValue for x.
yfloatValue for y.
wfloatValue for w.
hfloatValue for h.
u0floatValue for u0.
v0floatValue for v0.
u1floatValue for u1.
v1floatValue for v1.
tintuint32_tValue for tint.

mk_sprite_tintedfunction

void mk_sprite_tinted(mk_texture_t tex, float x, float y, float w, float h, uint32_t tint)

Draw texture with tint.

ParameterTypeDescription
texmk_texture_tValue for tex.
xfloatValue for x.
yfloatValue for y.
wfloatValue for w.
hfloatValue for h.
tintuint32_tValue for tint.

Structs

mk_canvas_begin_descstruct

Extended begin parameters, including logical and physical target sizes.

FieldTypeDescription
encodermk_encoder_tThe encoder.
viewmk_view_id_tThe view.
logical_widthuint16_tThe logical width.
logical_heightuint16_tThe logical height.
framebuffer_widthuint16_tThe framebuffer width.
framebuffer_heightuint16_tThe framebuffer height.

mk_canvas_corner_radiistruct

Independent radii for the four corners of a Canvas rectangle.

FieldTypeDescription
top_leftfloatThe top left.
top_rightfloatThe top right.
bottom_rightfloatThe bottom right.
bottom_leftfloatThe bottom left.

mk_canvas_edge_widthsstruct

Independent inset widths for the four edges of a Canvas border.

FieldTypeDescription
leftfloatThe left.
topfloatThe top.
rightfloatThe right.
bottomfloatThe bottom.

mk_canvas_pathstruct

A retained, immutable Canvas path.

Zero initialization is invalid.

FieldTypeDescription
implvoid *The impl.

mk_canvas_path_draw_descstruct

Data for canvas path draw desc.

FieldTypeDescription
backendmk_canvas_path_backend_tThe backend.
fill_rulemk_canvas_fill_rule_tThe fill rule.
fillboolThe fill.
fill_paintmk_paintThe fill paint.
strokeboolThe stroke.
stroke_stylemk_canvas_stroke_style_tThe stroke style.
effectsmk_canvas_path_effects_tThe effects.

mk_canvas_path_effectsstruct

Data for canvas path effects.

FieldTypeDescription
outline_widthfloatThe outline width.
outline_coloruint32_tThe outline color.
shadow_offset_xfloatThe shadow offset x.
shadow_offset_yfloatThe shadow offset y.
shadow_softnessfloatThe shadow softness.
shadow_coloruint32_tThe shadow color.
glow_sizefloatThe glow size.
glow_coloruint32_tThe glow color.

mk_canvas_stroke_stylestruct

Data for canvas stroke style.

FieldTypeDescription
paintmk_paintThe paint.
widthfloatThe width.
capmk_canvas_line_cap_tThe cap.
joinmk_canvas_line_join_tThe join.
miter_limitfloatThe miter limit.
dash_arrayconst float *The dash array.
dash_countuint8_tThe dash count.
dash_offsetfloatThe dash offset.

mk_paintstruct

Data for paint.

FieldTypeDescription
kindmk_paint_kind_tThe kind.
uunion mk_paint::@376024025226024055373057212033032317313122107014The u.
u.image.texmk_texture_tSource texture.
u.image.tintuint32_tRGBA tint multiplied with the sampled image.
u.linear.x0floatGradient start X coordinate.
u.linear.y0floatGradient start Y coordinate.
u.linear.x1floatGradient end X coordinate.
u.linear.y1floatGradient end Y coordinate.
u.linear.gradientmk_paint_gradientThe gradient.
u.radial.cxfloatGradient center X coordinate.
u.radial.cyfloatGradient center Y coordinate.
u.radial.inner_radiusfloatRadius at the first color stop.
u.radial.outer_radiusfloatRadius at the last color stop.
u.radial.gradientmk_paint_gradientThe gradient.
u.soliduint32_tSOLID: 0xRRGGBBAA.
u.imagestruct mk_paint::@376024025226024055373057212033032317313122107014::@332374144312014174351343272345225053136121376352IMAGE.
u.materialmk_material_tSHADER.
u.linearstruct mk_paint::@376024025226024055373057212033032317313122107014::@016341000356304303263262001147170125336112054217The linear.
u.radialstruct mk_paint::@376024025226024055373057212033032317313122107014::@325352324356163202124322146311214232136064044030The radial.

mk_paint_gradientstruct

Data for paint gradient.

FieldTypeDescription
stopsmk_paint_stopThe stops.
stop_countuint8_tThe stop count.

mk_paint_stopstruct

Data for paint stop.

FieldTypeDescription
offsetfloatThe offset.
coloruint32_tThe color.

Enums

mk_canvas_fill_ruleenum

Values for canvas fill rule.

ValueDescription
MK_CANVAS_FILL_NONZEROSelects nonzero.
MK_CANVAS_FILL_EVEN_ODDSelects even odd.

mk_canvas_line_capenum

Values for canvas line cap.

ValueDescription
MK_CANVAS_LINE_CAP_BUTTSelects butt.
MK_CANVAS_LINE_CAP_SQUARESelects square.
MK_CANVAS_LINE_CAP_ROUNDSelects round.

mk_canvas_line_joinenum

Values for canvas line join.

ValueDescription
MK_CANVAS_LINE_JOIN_MITERSelects miter.
MK_CANVAS_LINE_JOIN_BEVELSelects bevel.
MK_CANVAS_LINE_JOIN_ROUNDSelects round.

mk_canvas_path_backendenum

Values for canvas path backend.

ValueDescription
MK_CANVAS_PATH_BACKEND_AUTOSelects auto.
MK_CANVAS_PATH_BACKEND_ANALYTICALSelects analytical.
MK_CANVAS_PATH_BACKEND_TESSELLATEDSelects tessellated.

mk_paint_kindenum

Values for paint kind.

ValueDescription
MK_PAINT_SOLIDsingle RGBA color
MK_PAINT_IMAGEtextured fill (rect)
MK_PAINT_SHADERcustom: wraps an mk_material
MK_PAINT_LINEAR_GRADIENTSelects linear gradient.
MK_PAINT_RADIAL_GRADIENTSelects radial gradient.

Typedefs

mk_canvas_begin_desctypedef

typedef struct mk_canvas_begin_desc mk_canvas_begin_desc

Extended begin parameters, including logical and physical target sizes.

mk_canvas_corner_radiitypedef

typedef struct mk_canvas_corner_radii mk_canvas_corner_radii

Independent radii for the four corners of a Canvas rectangle.

mk_canvas_edge_widthstypedef

typedef struct mk_canvas_edge_widths mk_canvas_edge_widths

Independent inset widths for the four edges of a Canvas border.

mk_canvas_fill_rule_ttypedef

typedef enum mk_canvas_fill_rule mk_canvas_fill_rule_t

Values for canvas fill rule.

mk_canvas_line_cap_ttypedef

typedef enum mk_canvas_line_cap mk_canvas_line_cap_t

Values for canvas line cap.

mk_canvas_line_join_ttypedef

typedef enum mk_canvas_line_join mk_canvas_line_join_t

Values for canvas line join.

mk_canvas_path_backend_ttypedef

typedef enum mk_canvas_path_backend mk_canvas_path_backend_t

Values for canvas path backend.

mk_canvas_path_builder_ttypedef

typedef struct mk_canvas_path_builder mk_canvas_path_builder_t

Opaque mutable builder used to create retained paths.

mk_canvas_path_draw_desc_ttypedef

typedef struct mk_canvas_path_draw_desc mk_canvas_path_draw_desc_t

Data for canvas path draw desc.

mk_canvas_path_effects_ttypedef

typedef struct mk_canvas_path_effects mk_canvas_path_effects_t

Data for canvas path effects.

mk_canvas_path_ttypedef

typedef struct mk_canvas_path mk_canvas_path_t

A retained, immutable Canvas path.

Zero initialization is invalid.

mk_canvas_stroke_style_ttypedef

typedef struct mk_canvas_stroke_style mk_canvas_stroke_style_t

Data for canvas stroke style.

mk_canvas_ttypedef

typedef struct mk_canvas* mk_canvas_t

Opaque canvas context handle.

Each context owns its own batch buffers for thread-safe rendering.

mk_corner_radii_ttypedef

typedef mk_canvas_corner_radii mk_corner_radii_t

Type used for corner radii.

mk_edge_widths_ttypedef

typedef mk_canvas_edge_widths mk_edge_widths_t

Type used for edge widths.

mk_painttypedef

typedef struct mk_paint mk_paint

Data for paint.

mk_paint_gradienttypedef

typedef struct mk_paint_gradient mk_paint_gradient

Data for paint gradient.

mk_paint_kind_ttypedef

typedef enum mk_paint_kind mk_paint_kind_t

Values for paint kind.

mk_paint_stoptypedef

typedef struct mk_paint_stop mk_paint_stop

Data for paint stop.

mk_sprite_ttypedef

typedef struct mk_sprite mk_sprite_t

Type used for sprite.

Macros

MK_CANVAS_CTX_INVALIDdefine

MK_CANVAS_CTX_INVALID

Invalid sentinel for canvas ctx.

MK_CANVAS_PATH_DRAW_DEFAULTdefine

MK_CANVAS_PATH_DRAW_DEFAULT

Constant for canvas path draw default.

MK_CANVAS_PATH_INVALIDdefine

MK_CANVAS_PATH_INVALID

Invalid sentinel for canvas path.

MK_CANVAS_STROKE_STYLE_DEFAULTdefine

MK_CANVAS_STROKE_STYLE_DEFAULT

Constant for canvas stroke style default.

MK_PAINT_MAX_STOPSdefine

MK_PAINT_MAX_STOPS

Maximum supported paint stops.