summaryrefslogtreecommitdiff
path: root/src/vector
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-02-15 00:35:52 -0600
committersanine <sanine.not@pm.me>2023-02-15 00:35:52 -0600
commit71af5331b108d6407c791e3859af41ef2b379483 (patch)
tree6d006cb990c396695d33302e6134e8cfc7fcdebf /src/vector
parentcb9764cddf0ed8186e78c418f066b31921fbda40 (diff)
implement basic vector bindings
Diffstat (limited to 'src/vector')
-rw-r--r--src/vector/CMakeLists.txt8
-rw-r--r--src/vector/vector.c155
2 files changed, 156 insertions, 7 deletions
diff --git a/src/vector/CMakeLists.txt b/src/vector/CMakeLists.txt
index 53032eb..d74b1af 100644
--- a/src/vector/CMakeLists.txt
+++ b/src/vector/CMakeLists.txt
@@ -1,9 +1,3 @@
project(honey_engine)
-target_sources(honey PUBLIC
- ${CMAKE_CURRENT_LIST_DIR}/vector.c
-)
-
-
-target_sources(test PUBLIC
-)
+target_sources(honey PUBLIC ${CMAKE_CURRENT_LIST_DIR}/vector.c)
diff --git a/src/vector/vector.c b/src/vector/vector.c
index 230bfdd..33f80e5 100644
--- a/src/vector/vector.c
+++ b/src/vector/vector.c
@@ -61,6 +61,146 @@ int nvg_end_frame(lua_State *L)
}
+/* --===== paths =====-- */
+
+int nvg_begin_path(lua_State *L)
+{
+ struct NVGcontext **vg = luaL_checkudata(L, 1, nvg_ctx_tname);
+ nvgBeginPath(*vg);
+ return 0;
+}
+
+
+int nvg_move_to(lua_State *L)
+{
+ struct NVGcontext **vg = luaL_checkudata(L, 1, nvg_ctx_tname);
+ float x = luaL_checknumber(L, 2);
+ float y = luaL_checknumber(L, 3);
+ nvgMoveTo(*vg, x, y);
+ return 0;
+}
+
+
+int nvg_line_to(lua_State *L)
+{
+ struct NVGcontext **vg = luaL_checkudata(L, 1, nvg_ctx_tname);
+ float x = luaL_checknumber(L, 2);
+ float y = luaL_checknumber(L, 3);
+ nvgLineTo(*vg, x, y);
+ return 0;
+}
+
+
+int nvg_bezier_to(lua_State *L)
+{
+ struct NVGcontext **vg = luaL_checkudata(L, 1, nvg_ctx_tname);
+ float c1x = luaL_checknumber(L, 2);
+ float c1y = luaL_checknumber(L, 3);
+ float c2x = luaL_checknumber(L, 4);
+ float c2y = luaL_checknumber(L, 5);
+ float x = luaL_checknumber(L, 6);
+ float y = luaL_checknumber(L, 7);
+ nvgBezierTo(*vg, c1x, c1y, c2x, c2y, x, y);
+ return 0;
+}
+
+
+int nvg_quad_to(lua_State *L)
+{
+ struct NVGcontext **vg = luaL_checkudata(L, 1, nvg_ctx_tname);
+ float cx = luaL_checknumber(L, 2);
+ float cy = luaL_checknumber(L, 3);
+ float x = luaL_checknumber(L, 4);
+ float y = luaL_checknumber(L, 5);
+ nvgQuadTo(*vg, cx, cy, x, y);
+ return 0;
+}
+
+
+int nvg_arc_to(lua_State *L)
+{
+ struct NVGcontext **vg = luaL_checkudata(L, 1, nvg_ctx_tname);
+ float x1 = luaL_checknumber(L, 2);
+ float y1 = luaL_checknumber(L, 3);
+ float x2 = luaL_checknumber(L, 4);
+ float y2 = luaL_checknumber(L, 5);
+ float radius = luaL_checknumber(L, 6);
+ nvgArcTo(*vg, x1, y1, x2, y2, radius);
+ return 0;
+}
+
+
+int nvg_close_path(lua_State *L)
+{
+ struct NVGcontext **vg = luaL_checkudata(L, 1, nvg_ctx_tname);
+ nvgClosePath(*vg);
+ return 0;
+}
+
+
+int nvg_path_winding(lua_State *L)
+{
+ struct NVGcontext **vg = luaL_checkudata(L, 1, nvg_ctx_tname);
+ int dir = luaL_checkinteger(L, 2);
+ nvgPathWinding(*vg, dir);
+ return 0;
+}
+
+
+int nvg_arc(lua_State *L)
+{
+ struct NVGcontext **vg = luaL_checkudata(L, 1, nvg_ctx_tname);
+ float cx = luaL_checknumber(L, 2);
+ float cy = luaL_checknumber(L, 3);
+ float r = luaL_checknumber(L, 4);
+ float a0 = luaL_checknumber(L, 5);
+ float a1 = luaL_checknumber(L, 6);
+ int dir = luaL_checkinteger(L, 7);
+ nvgArc(*vg, cx, cy, r, a0, a1, dir);
+ return 0;
+}
+
+/* ... */
+
+int nvg_fill(lua_State *L)
+{
+ struct NVGcontext **vg = luaL_checkudata(L, 1, nvg_ctx_tname);
+ nvgFill(*vg);
+ return 0;
+}
+
+
+int nvg_stroke(lua_State *L)
+{
+ struct NVGcontext **vg = luaL_checkudata(L, 1, nvg_ctx_tname);
+ nvgStroke(*vg);
+ return 0;
+}
+
+
+/* --===== render styles =====-- */
+
+int nvg_stroke_color(lua_State *L)
+{
+ struct NVGcontext **vg = luaL_checkudata(L, 1, nvg_ctx_tname);
+ NVGcolor color;
+ color.r = luaL_checknumber(L, 2);
+ color.g = luaL_checknumber(L, 3);
+ color.b = luaL_checknumber(L, 4);
+ color.a = luaL_checknumber(L, 5);
+ nvgStrokeColor(*vg, color);
+ return 0;
+}
+
+
+int nvg_stroke_width(lua_State *L)
+{
+ struct NVGcontext **vg = luaL_checkudata(L, 1, nvg_ctx_tname);
+ float size = luaL_checknumber(L, 2);
+ nvgStrokeWidth(*vg, size);
+ return 0;
+}
+
/* --===== complete =====-- */
@@ -77,6 +217,21 @@ void setup_nvg(lua_State *L, int honey_tbl)
hs_str_cfunc("BeginFrame", nvg_begin_frame),
hs_str_cfunc("CancelFrame", nvg_cancel_frame),
hs_str_cfunc("EndFrame", nvg_end_frame),
+
+ hs_str_cfunc("BeginPath", nvg_begin_path),
+ hs_str_cfunc("MoveTo", nvg_move_to),
+ hs_str_cfunc("LineTo", nvg_line_to),
+ hs_str_cfunc("BezierTo", nvg_bezier_to),
+ hs_str_cfunc("QuadTo", nvg_quad_to),
+ hs_str_cfunc("ArcTo", nvg_arc_to),
+ hs_str_cfunc("ClosePath", nvg_close_path),
+ hs_str_cfunc("PathWinding", nvg_path_winding),
+ hs_str_cfunc("Arc", nvg_arc),
+ hs_str_cfunc("Fill", nvg_fill),
+ hs_str_cfunc("Stroke", nvg_stroke),
+
+ hs_str_cfunc("StrokeColor", nvg_stroke_color),
+ hs_str_cfunc("StrokeWidth", nvg_stroke_width),
);
lua_setfield(L, honey_tbl, "nvg");