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).
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
cx | float | Center X |
cy | float | Center Y |
radius | float | Radius |
start_angle | float | Start angle in radians (0 = right, clockwise) |
end_angle | float | End angle in radians |
color | uint32_t | RGBA 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
cx | float | Center X |
cy | float | Center Y |
radius | float | Radius |
start_angle | float | Start angle in radians |
end_angle | float | End angle in radians |
color | uint32_t | RGBA color |
thickness | float | Line 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().
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
encoder | mk_encoder_t | Encoder from mk_render_ctx_encoder() or mk_encoder_begin() |
view | mk_view_id_t | View ID to draw to |
width | uint16_t | Screen width in logical pixels |
height | uint16_t | Screen 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Active operation context. |
desc | const 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
cx | float | Center X |
cy | float | Center Y |
radius | float | Radius |
color | uint32_t | RGBA color (0xRRGGBBAA) |
segments | int | Number 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
cx | float | Center X |
cy | float | Center Y |
radius | float | Radius |
color | uint32_t | RGBA color |
thickness | float | Line thickness |
dash_length | float | Length of each dash |
gap_length | float | Length of each gap |
segments | int | Number 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
cx | float | Center X |
cy | float | Center Y |
radius | float | Radius |
color | uint32_t | RGBA color (0xRRGGBBAA) |
thickness | float | Line thickness |
segments | int | Number 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Active 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
cx | float | Center X |
cy | float | Center Y |
rx | float | Radius X |
ry | float | Radius Y |
color | uint32_t | RGBA color (0xRRGGBBAA) |
segments | int | Number of segments (0 = auto) |
mk_canvas_endfunction
void mk_canvas_end(mk_canvas_t ctx)
End 2D drawing mode and flush all batched draws.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context 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).
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Active operation context. |
cx | float | Value for cx. |
cy | float | Value for cy. |
radius | float | Value for radius. |
segments | int | Value 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).
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Active operation context. |
x | float | Value for x. |
y | float | Value for y. |
w | float | Value for w. |
h | float | Value 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Active 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
x1 | float | Start point |
y1 | float | Start point |
x2 | float | End point |
y2 | float | End point |
color | uint32_t | RGBA color (0xRRGGBBAA) |
thickness | float | Line 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
x1 | float | Start point |
y1 | float | Start point |
x2 | float | End point |
y2 | float | End point |
color | uint32_t | RGBA color |
thickness | float | Line thickness |
dash_length | float | Length of each dash |
gap_length | float | Length 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Active 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Active 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Active 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
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
tex | mk_texture_t | Texture to draw |
x | float | Destination left edge |
y | float | Destination top edge |
w | float | Destination width |
h | float | Destination height |
left | float | Left border width in pixels |
right | float | Right border width in pixels |
top | float | Top border height in pixels |
bottom | float | Bottom border height in pixels |
tint | uint32_t | Color 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
sprite | mk_sprite_t | Source sprite or atlas region |
x | float | Destination left edge |
y | float | Destination top edge |
w | float | Destination width |
h | float | Destination height |
left | float | Left source border width in pixels |
right | float | Right source border width in pixels |
top | float | Top source border height in pixels |
bottom | float | Bottom source border height in pixels |
tint | uint32_t | RGBA color tint |
fill_center | bool | Draw 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
cx | float | Center X |
cy | float | Center Y |
radius | float | Radius |
start_angle | float | Start angle in radians |
end_angle | float | End angle in radians |
ccw | bool | Counter-clockwise if true |
mk_canvas_path_beginfunction
void mk_canvas_path_begin(mk_canvas_t ctx)
Begin a new path.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
c1x | float | First control point X |
c1y | float | First control point Y |
c2x | float | Second control point X |
c2y | float | Second control point Y |
x | float | End point X |
y | float | End 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.
| Parameter | Type | Description |
|---|
builder | mk_canvas_path_builder_t * | Value for builder. |
cx | float | Value for cx. |
cy | float | Value for cy. |
radius | float | Value for radius. |
start_angle | float | Value for start angle. |
end_angle | float | Value for end angle. |
ccw | bool | Value 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.
| Parameter | Type | Description |
|---|
builder | mk_canvas_path_builder_t * | Value for builder. |
c1x | float | Value for c1x. |
c1y | float | Value for c1y. |
c2x | float | Value for c2x. |
c2y | float | Value for c2y. |
x | float | Value for x. |
y | float | Value 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.
| Parameter | Type | Description |
|---|
builder | const 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.
| Parameter | Type | Description |
|---|
builder | mk_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.
| Parameter | Type | Description |
|---|
builder | mk_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.
| Parameter | Type | Description |
|---|
builder | mk_canvas_path_builder_t * | Value for builder. |
cx | float | Value for cx. |
cy | float | Value for cy. |
rx | float | Value for rx. |
ry | float | Value 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.
| Parameter | Type | Description |
|---|
builder | const 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.
| Parameter | Type | Description |
|---|
builder | mk_canvas_path_builder_t * | Value for builder. |
x | float | Value for x. |
y | float | Value 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.
| Parameter | Type | Description |
|---|
builder | mk_canvas_path_builder_t * | Value for builder. |
x | float | Value for x. |
y | float | Value 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.
| Parameter | Type | Description |
|---|
builder | mk_canvas_path_builder_t * | Value for builder. |
cx | float | Value for cx. |
cy | float | Value for cy. |
x | float | Value for x. |
y | float | Value 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.
| Parameter | Type | Description |
|---|
builder | mk_canvas_path_builder_t * | Value for builder. |
x | float | Value for x. |
y | float | Value for y. |
w | float | Value for w. |
h | float | Value for h. |
radius | float | Value 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.
| Parameter | Type | Description |
|---|
builder | mk_canvas_path_builder_t * | Value for builder. |
mk_canvas_path_closefunction
void mk_canvas_path_close(mk_canvas_t ctx)
Close current subpath.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
mk_canvas_path_destroyfunction
void mk_canvas_path_destroy(mk_canvas_path_t path)
Destroy the canvas path.
| Parameter | Type | Description |
|---|
path | mk_canvas_path_t | Value 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Active operation context. |
path | mk_canvas_path_t | Value for path. |
desc | const 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Active operation context. |
desc | const 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
cx | float | Center X |
cy | float | Center Y |
rx | float | Radius X |
ry | float | Radius Y |
mk_canvas_path_fillfunction
void mk_canvas_path_fill(mk_canvas_t ctx, uint32_t color)
Fill the current path.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
color | uint32_t | Fill color |
mk_canvas_path_is_validfunction
bool mk_canvas_path_is_valid(mk_canvas_path_t path)
Test whether the canvas path is valid.
| Parameter | Type | Description |
|---|
path | mk_canvas_path_t | Value 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
x | float | X coordinate |
y | float | Y 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).
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
x | float | X coordinate |
y | float | Y 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
cx | float | Control point X |
cy | float | Control point Y |
x | float | End point X |
y | float | End 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
x | float | Left edge |
y | float | Top edge |
w | float | Width |
h | float | Height |
radius | float | Corner radius |
mk_canvas_path_strokefunction
void mk_canvas_path_stroke(mk_canvas_t ctx, uint32_t color, float thickness)
Stroke the current path.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
color | uint32_t | Stroke color |
thickness | float | Line thickness |
mk_canvas_polygonfunction
void mk_canvas_polygon(mk_canvas_t ctx, const float *points, int count, uint32_t color)
Draw a filled polygon.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
points | const float * | Array of [x, y] pairs |
count | int | Number of points |
color | uint32_t | RGBA 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).
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
points | const float * | Array of [x, y] pairs |
count | int | Number of points |
color | uint32_t | RGBA color (0xRRGGBBAA) |
thickness | float | Line thickness |
closed | bool | If true, connect last point to first |
mk_canvas_pop_clipfunction
void mk_canvas_pop_clip(mk_canvas_t ctx)
Pop the current clip region.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context 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.
| Parameter | Type | Description |
|---|
view | mk_view_id_t | Value for view. |
width | uint16_t | Value for width. |
height | uint16_t | Value 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
x | float | Left edge |
y | float | Top edge |
w | float | Width |
h | float | Height |
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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
x | float | Left edge |
y | float | Top edge |
w | float | Width |
h | float | Height |
color | uint32_t | RGBA 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
x | float | Left edge |
y | float | Top edge |
w | float | Width |
h | float | Height |
color | uint32_t | RGBA color |
thickness | float | Line thickness |
dash_length | float | Length of each dash |
gap_length | float | Length 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
x | float | Left edge |
y | float | Top edge |
w | float | Width |
h | float | Height |
tl | uint32_t | Top-left color |
tr | uint32_t | Top-right color |
bl | uint32_t | Bottom-left color |
br | uint32_t | Bottom-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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
x | float | Left edge |
y | float | Top edge |
w | float | Width |
h | float | Height |
left_color | uint32_t | Left color (0xRRGGBBAA) |
right_color | uint32_t | Right 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
x | float | Left edge |
y | float | Top edge |
w | float | Width |
h | float | Height |
inner_color | uint32_t | Center color |
outer_color | uint32_t | Edge 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
x | float | Left edge |
y | float | Top edge |
w | float | Width |
h | float | Height |
top_color | uint32_t | Top color (0xRRGGBBAA) |
bottom_color | uint32_t | Bottom 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
x | float | Left edge |
y | float | Top edge |
w | float | Width |
h | float | Height |
color | uint32_t | RGBA color (0xRRGGBBAA) |
thickness | float | Line 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Active operation context. |
x | float | Value for x. |
y | float | Value for y. |
w | float | Value for w. |
h | float | Value for h. |
radii | mk_canvas_corner_radii | Value for radii. |
widths | mk_canvas_edge_widths | Value for widths. |
color | uint32_t | Value 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
x | float | Left edge |
y | float | Top edge |
w | float | Width |
h | float | Height |
radius | float | Corner radius |
color | uint32_t | RGBA 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Active operation context. |
x | float | Value for x. |
y | float | Value for y. |
w | float | Value for w. |
h | float | Value for h. |
radii | mk_canvas_corner_radii | Value for radii. |
color | uint32_t | Value for color. |
void mk_canvas_reset_transform(mk_canvas_t ctx)
Reset transform to identity.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
mk_canvas_restorefunction
void mk_canvas_restore(mk_canvas_t ctx)
Restore transform state from stack.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
cx | float | Center X |
cy | float | Center Y |
inner_radius | float | Inner radius |
outer_radius | float | Outer radius |
color | uint32_t | RGBA color |
segments | int | Number 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).
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
cx | float | Center X |
cy | float | Center Y |
inner_radius | float | Inner radius |
outer_radius | float | Outer radius |
start_angle | float | Start angle in radians |
end_angle | float | End angle in radians |
color | uint32_t | RGBA color |
mk_canvas_rotatefunction
void mk_canvas_rotate(mk_canvas_t ctx, float angle)
Apply rotation to current transform.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
angle | float | Rotation angle in radians (clockwise) |
mk_canvas_savefunction
void mk_canvas_save(mk_canvas_t ctx)
Save current transform state onto stack.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
mk_canvas_scalefunction
void mk_canvas_scale(mk_canvas_t ctx, float sx, float sy)
Apply scale to current transform.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
sx | float | Scale X |
sy | float | Scale 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
mode | mk_blend_mode_t | Blend 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).
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Active operation context. |
paint | mk_paint | Value for paint. |
mk_canvas_set_strokefunction
void mk_canvas_set_stroke(mk_canvas_t ctx, mk_paint paint)
Set the current stroke paint.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Active operation context. |
paint | mk_paint | Value for paint. |
void mk_canvas_set_transform(mk_canvas_t ctx, const float *mtx)
Set transform matrix directly.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
mtx | const 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
tex | mk_texture_t | Texture to draw |
x | float | Left edge |
y | float | Top edge |
w | float | Width (use 0 for texture width) |
h | float | Height (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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Active operation context. |
tex | mk_texture_t | Value for tex. |
x | float | Value for x. |
y | float | Value for y. |
w | float | Value for w. |
h | float | Value 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Active operation context. |
tex | mk_texture_t | Value for tex. |
x | float | Value for x. |
y | float | Value for y. |
w | float | Value for w. |
h | float | Value 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
tex | mk_texture_t | Texture to draw |
x | float | Center X |
y | float | Center Y |
w | float | Width |
h | float | Height |
rotation | float | Rotation in radians |
tint | uint32_t | RGBA 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
tex | mk_texture_t | Texture to draw |
x | float | Center X |
y | float | Center Y |
w | float | Width |
h | float | Height |
rotation | float | Rotation in radians |
u0 | float | Left U coordinate |
v0 | float | Top V coordinate |
u1 | float | Right U coordinate |
v1 | float | Bottom V coordinate |
tint | uint32_t | RGBA 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Active operation context. |
tex | mk_texture_t | Value for tex. |
x | float | Value for x. |
y | float | Value for y. |
w | float | Value for w. |
h | float | Value for h. |
uv | mk_rectf | Value for UV. |
tint | uint32_t | Value for tint. |
radii | mk_canvas_corner_radii | Value 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
tex | mk_texture_t | Texture to draw |
x | float | Destination left edge |
y | float | Destination top edge |
w | float | Destination width |
h | float | Destination height |
sx | float | Source U origin (0..1) |
sy | float | Source V origin (0..1) |
sw | float | Source U extent (0..1) |
sh | float | Source V extent (0..1) |
tint | uint32_t | RGBA 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
tex | mk_texture_t | Texture to draw |
x | float | Destination left edge |
y | float | Destination top edge |
w | float | Destination width |
h | float | Destination height |
sx | float | Source U origin in normalized coordinates |
sy | float | Source V origin in normalized coordinates |
sw | float | Source U extent in normalized coordinates |
sh | float | Source V extent in normalized coordinates |
tint | uint32_t | RGBA color tint |
flip | mk_flip_t | Bitmask 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
tex | mk_texture_t | Texture to draw |
x | float | Left edge |
y | float | Top edge |
w | float | Width (use 0 for texture width) |
h | float | Height (use 0 for texture height) |
tint | uint32_t | RGBA 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
x | float | X offset |
y | float | Y 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.
| Parameter | Type | Description |
|---|
ctx | mk_canvas_t | Context handle |
x1 | float | First vertex |
y1 | float | First vertex |
x2 | float | Second vertex |
y2 | float | Second vertex |
x3 | float | Third vertex |
y3 | float | Third vertex |
color | uint32_t | RGBA color (0xRRGGBBAA) |
mk_circle2dfunction
void mk_circle2d(float cx, float cy, float radius, uint32_t color)
Draw filled circle.
| Parameter | Type | Description |
|---|
cx | float | Value for cx. |
cy | float | Value for cy. |
radius | float | Value for radius. |
color | uint32_t | Value for color. |
mk_circle2d_outlinefunction
void mk_circle2d_outline(float cx, float cy, float radius, uint32_t color, float thickness)
Draw circle outline.
| Parameter | Type | Description |
|---|
cx | float | Value for cx. |
cy | float | Value for cy. |
radius | float | Value for radius. |
color | uint32_t | Value for color. |
thickness | float | Value for thickness. |
mk_line2dfunction
void mk_line2d(float x1, float y1, float x2, float y2, uint32_t color, float thickness)
Draw 2D line.
| Parameter | Type | Description |
|---|
x1 | float | Value for x1. |
y1 | float | Value for y1. |
x2 | float | Value for x2. |
y2 | float | Value for y2. |
color | uint32_t | Value for color. |
thickness | float | Value for thickness. |
mk_paint_colorfunction
mk_paint mk_paint_color(uint32_t rgba)
Solid-color paint.
| Parameter | Type | Description |
|---|
rgba | uint32_t | Value 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).
| Parameter | Type | Description |
|---|
tex | mk_texture_t | Value for tex. |
tint | uint32_t | Value 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.
| Parameter | Type | Description |
|---|
x0 | float | Value for x0. |
y0 | float | Value for y0. |
x1 | float | Value for x1. |
y1 | float | Value for y1. |
stops | const mk_paint_stop * | Value for stops. |
stop_count | uint8_t | Number 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.
| Parameter | Type | Description |
|---|
cx | float | Value for cx. |
cy | float | Value for cy. |
inner_radius | float | Value for inner radius. |
outer_radius | float | Value for outer radius. |
stops | const mk_paint_stop * | Value for stops. |
stop_count | uint8_t | Number 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).
| Parameter | Type | Description |
|---|
material | mk_material_t | Value 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.
| Parameter | Type | Description |
|---|
x | float | Value for x. |
y | float | Value for y. |
w | float | Value for w. |
h | float | Value for h. |
color | uint32_t | Value 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.
| Parameter | Type | Description |
|---|
x | float | Value for x. |
y | float | Value for y. |
w | float | Value for w. |
h | float | Value for h. |
color | uint32_t | Value for color. |
thickness | float | Value 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.
| Parameter | Type | Description |
|---|
x | float | Value for x. |
y | float | Value for y. |
w | float | Value for w. |
h | float | Value for h. |
radius | float | Value for radius. |
color | uint32_t | Value for color. |
mk_spritefunction
void mk_sprite(mk_texture_t tex, float x, float y, float w, float h)
Draw texture.
| Parameter | Type | Description |
|---|
tex | mk_texture_t | Value for tex. |
x | float | Value for x. |
y | float | Value for y. |
w | float | Value for w. |
h | float | Value 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).
| Parameter | Type | Description |
|---|
tex | mk_texture_t | Value for tex. |
x | float | Value for x. |
y | float | Value for y. |
w | float | Value for w. |
h | float | Value for h. |
u0 | float | Value for u0. |
v0 | float | Value for v0. |
u1 | float | Value for u1. |
v1 | float | Value for v1. |
tint | uint32_t | Value 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.
| Parameter | Type | Description |
|---|
tex | mk_texture_t | Value for tex. |
x | float | Value for x. |
y | float | Value for y. |
w | float | Value for w. |
h | float | Value for h. |
tint | uint32_t | Value for tint. |