Skip to content

Commit

Permalink
Add canvas::drawTrig (#208)
Browse files Browse the repository at this point in the history
Signed-off-by: Marek Maškarinec <[email protected]>
  • Loading branch information
marekmaskarinec authored Jul 19, 2024
1 parent b1215db commit c748ee1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions samples/canvas/main.um
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ fn init*() {
window::onFrame.register({
canvas::drawRectLines(0x000000FF, {30, 30, 100, 100}, 3)
canvas::drawRectLines(0xFF000066, {80, 80, 100, 110}, 5)
canvas::drawTrig(0x00FF0066, { 30, 200 }, { 120, 200 }, { 30, 300 })
})
}
13 changes: 13 additions & 0 deletions src/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,18 @@ umth_canvas_draw_quad(UmkaStackSlot *p, UmkaStackSlot *r)
th_canvas_quad(q, color);
}

// fn umth_canvas_draw_trig(color: uint32, a, b, c: th::Vf2)
void
umth_canvas_draw_trig(UmkaStackSlot *p, UmkaStackSlot *r)
{
uint32_t color = umkaGetParam(p, 0)->uintVal;
th_vf2 a = *(th_vf2 *)umkaGetParam(p, 1);
th_vf2 b = *(th_vf2 *)umkaGetParam(p, 2);
th_vf2 c = *(th_vf2 *)umkaGetParam(p, 3);

th_canvas_triangle(color, a, b, c);
}

// fn umth_canvas_begin_scissor_rect(r: rect::Rect)
void
umth_canvas_begin_scissor_rect(UmkaStackSlot *p, UmkaStackSlot *r)
Expand Down Expand Up @@ -1593,6 +1605,7 @@ _th_umka_bind(void *umka)
umkaAddFunc(umka, "umth_canvas_draw_line", &umth_canvas_draw_line);
umkaAddFunc(umka, "umth_canvas_draw_rect_lines", &umth_canvas_draw_rect_lines);
umkaAddFunc(umka, "umth_canvas_draw_quad", &umth_canvas_draw_quad);
umkaAddFunc(umka, "umth_canvas_draw_trig", &umth_canvas_draw_trig);
umkaAddFunc(umka, "umth_canvas_begin_scissor_rect", &umth_canvas_begin_scissor_rect);
umkaAddFunc(umka, "umth_canvas_end_scissor", &umth_canvas_end_scissor);

Expand Down
16 changes: 16 additions & 0 deletions src/staembed.c
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,14 @@ const char *th_em_modulesrc[] = {
"\tumth_canvas_draw_quad(color, q)\n"
"}\n"
"\n"
"fn umth_canvas_draw_trig(color: uint32, a, b, c: th::Vf2)\n"
"//~~fn drawTrig\n"
"// Draws a triangle.\n"
"fn drawTrig*(color: uint32, a, b, c: th::Vf2) {\n"
"//~~\n"
"\tumth_canvas_draw_trig(color, a, b, c)\n"
"}\n"
"\n"
"var scissor: []rect::Rect\n"
"\n"
"fn umth_canvas_begin_scissor_rect(r: rect::Rect)\n"
Expand Down Expand Up @@ -5073,6 +5081,14 @@ const char *th_em_moduledocs[] = {
"\n"
"---------\n"
"\n"
"fn drawTrig\n"
"\n"
"fn drawTrig*(color: uint32, a, b, c: th::Vf2) {\n"
"\n"
"Draws a triangle.\n"
"\n"
"---------\n"
"\n"
"fn beginScissorRect\n"
"\n"
"fn beginScissorRect*(r: rect::Rect, debug: bool = false) {\n"
Expand Down
8 changes: 8 additions & 0 deletions umka/canvas.um
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ fn drawQuad*(color: uint32, q: th::Quad) {
umth_canvas_draw_quad(color, q)
}

fn umth_canvas_draw_trig(color: uint32, a, b, c: th::Vf2)
//~~fn drawTrig
// Draws a triangle.
fn drawTrig*(color: uint32, a, b, c: th::Vf2) {
//~~
umth_canvas_draw_trig(color, a, b, c)
}

var scissor: []rect::Rect

fn umth_canvas_begin_scissor_rect(r: rect::Rect)
Expand Down

0 comments on commit c748ee1

Please sign in to comment.