summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2020-12-17 01:44:34 -0600
committersanine-a <sanine.not@pm.me>2020-12-17 01:44:34 -0600
commit505b497cb1afed4a2b3c78292adaeca59fac12c3 (patch)
treeb06baee6c998d1b4f0f9093f85f0d6ed9371c3e8
parentb4edd1f5ee3817f94641b41d93ea4b63c716784b (diff)
add basic stroke functions
-rw-r--r--src/cairo_bindings.c70
-rw-r--r--src/cairo_bindings.h10
2 files changed, 78 insertions, 2 deletions
diff --git a/src/cairo_bindings.c b/src/cairo_bindings.c
index 7dc4ef8..3becfb9 100644
--- a/src/cairo_bindings.c
+++ b/src/cairo_bindings.c
@@ -9,9 +9,13 @@ int honey_setup_cairo(lua_State* L)
{
honey_lua_create_table
(L, 2,
- HONEY_TABLE, "__index", 2,
+ HONEY_TABLE, "__index", 6,
HONEY_FUNCTION, "getTexture", honey_cairo_get_texture,
HONEY_FUNCTION, "updateTexture", honey_cairo_update_texture,
+ HONEY_FUNCTION, "moveTo", honey_cairo_move_to,
+ HONEY_FUNCTION, "lineTo", honey_cairo_line_to,
+ HONEY_FUNCTION, "stroke", honey_cairo_stroke,
+ HONEY_FUNCTION, "setColor", honey_cairo_set_color,
HONEY_FUNCTION, "__gc", honey_cairo_destroy);
honey_cairo_mt_ref = luaL_ref(L, LUA_REGISTRYINDEX);
@@ -140,7 +144,7 @@ int honey_cairo_get_texture(lua_State* L)
int honey_cairo_destroy(lua_State* L)
{
- cairo_surface_t** cr;
+ cairo_t** cr;
honey_lua_parse_arguments(L, 1, 1, HONEY_USERDATA, &cr);
cairo_destroy(*cr);
@@ -148,4 +152,66 @@ int honey_cairo_destroy(lua_State* L)
return 0;
}
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * Drawing functions
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+int honey_cairo_move_to(lua_State* L)
+{
+ cairo_t** cr;
+ float x, y;
+ honey_lua_parse_arguments
+ (L, 1, 3, HONEY_USERDATA, &cr, HONEY_NUMBER, &x, HONEY_NUMBER, &y);
+
+ cairo_move_to(*cr, x, y);
+ return 0;
+}
+
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+
+int honey_cairo_line_to(lua_State* L)
+{
+ cairo_t** cr;
+ float x, y;
+ honey_lua_parse_arguments
+ (L, 1, 3, HONEY_USERDATA, &cr, HONEY_NUMBER, &x, HONEY_NUMBER, &y);
+
+ cairo_line_to(*cr, x, y);
+ return 0;
+}
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+
+int honey_cairo_stroke(lua_State* L)
+{
+ cairo_t** cr;
+ honey_lua_parse_arguments(L, 1, 1, HONEY_USERDATA, &cr);
+
+ cairo_stroke(*cr);
+}
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+
+int honey_cairo_set_color(lua_State* L)
+{
+ cairo_t** cr;
+ float r, g, b, a;
+ int choice = honey_lua_parse_arguments
+ (L, 2,
+ 4,
+ HONEY_USERDATA, &cr,
+ HONEY_NUMBER, &r, HONEY_NUMBER, &g, HONEY_NUMBER, &b,
+ 5,
+ HONEY_USERDATA, &cr,
+ HONEY_NUMBER, &r, HONEY_NUMBER, &g, HONEY_NUMBER, &b, HONEY_NUMBER, &a);
+
+ if (choice == 0)
+ cairo_set_source_rgb(*cr, r, g, b);
+ else
+ cairo_set_source_rgba(*cr, r, g, b, a);
+
+ return 0;
+}
diff --git a/src/cairo_bindings.h b/src/cairo_bindings.h
index 0256ce5..1170406 100644
--- a/src/cairo_bindings.h
+++ b/src/cairo_bindings.h
@@ -20,4 +20,14 @@ int honey_cairo_get_texture(lua_State* L);
int honey_cairo_destroy(lua_State* L);
+/* drawing functions */
+
+int honey_cairo_move_to(lua_State* L);
+
+int honey_cairo_line_to(lua_State* L);
+
+int honey_cairo_stroke(lua_State* L);
+
+int honey_cairo_set_color(lua_State* L);
+
#endif