fillRect(canvas, x, y, w, h, r, g, b, a) {
canvasCtx.fillStyle = `rgba(${r * 255}, ${g * 255}, ${b * 255}, ${a})`;
canvasCtx.fillRect(x, y, w, h);
+ },
+
+ fillText(canvas, text_ptr, text_len, x, y, max_width) {
+ const data = new Uint8Array(wasm_instance.exports.memory.buffer, text_ptr, text_len);
+ const str = new TextDecoder().decode(data);
+
+ canvasCtx.fillStyle = "#ffffff";
+
+ if (max_width > 0) canvasCtx.fillText(str, x, y, max_width);
+ else canvasCtx.fillText(str, x, y);
}
}
fill_rect :: (handle: Handle,
x: f32, y: f32, w: f32, h: f32,
r: f32, g: f32, b: f32, a := 1.0f) -> void #foreign "canvas" "fillRect" ---
+
+ fill_text :: (handle: Handle, text: str, x: f32, y: f32, max_width: f32 = -1.0f) -> void #foreign "canvas" "fillText" ---
}
setup_canvas :: () {
width, height := cast(f32) get_width(canvas), cast(f32) get_height(canvas);
fill_rect(canvas, width / 2, height / 2, width / 2, height / 2, 1, 0, 0);
+
+ fill_text(canvas, "Hello, World!!", width / 2, height / 2);
}
main :: (args: [] cstr) {