author | francesco-ST <francesco.abbate@st.com> | 2010年08月05日 14:29:43 +0200 |
---|---|---|
committer | francesco-ST <francesco.abbate@st.com> | 2010年08月05日 14:29:43 +0200 |
commit | 2dd683d5721fbd9d740feacf90caee564752696c (patch) | |
tree | 84eed8a5523fee1c8def4684307ef70eb388ca0d /agg-plot/lua-draw.cpp | |
parent | 19b34676bbbb009b5a60c572eebe82c447185b67 (diff) | |
download | gsl-shell-2dd683d5721fbd9d740feacf90caee564752696c.tar.gz |
-rw-r--r-- | agg-plot/lua-draw.cpp | 48 |
diff --git a/agg-plot/lua-draw.cpp b/agg-plot/lua-draw.cpp index 36c2abd7..829a26f3 100644 --- a/agg-plot/lua-draw.cpp +++ b/agg-plot/lua-draw.cpp @@ -58,6 +58,10 @@ struct path_cmd_reg { static int agg_path_free (lua_State *L); static int agg_path_index (lua_State *L); +static int agg_ellipse_new (lua_State *L); +static int agg_circle_new (lua_State *L); +static int agg_ellipse_free (lua_State *L); + static int agg_rgba_free (lua_State *L); static int agg_rgba_add (lua_State *L); static int agg_rgba_mul (lua_State *L); @@ -77,6 +81,8 @@ static struct path_cmd_reg cmd_table[] = { static const struct luaL_Reg draw_functions[] = { {"path", agg_path_new}, + {"ellipse", agg_ellipse_new}, + {"circle", agg_circle_new}, {"rgba", agg_rgba_new}, {"rgb", agg_rgb_new}, {NULL, NULL} @@ -88,6 +94,12 @@ static const struct luaL_Reg agg_path_methods[] = { {NULL, NULL} }; + +static const struct luaL_Reg agg_ellipse_methods[] = { + {"__gc", agg_ellipse_free}, + {NULL, NULL} +}; + static const struct luaL_Reg rgba_methods[] = { {"__gc", agg_rgba_free}, {"__add", agg_rgba_add }, @@ -220,6 +232,38 @@ agg_path_index (lua_State *L) return 0; } +int +agg_ellipse_new (lua_State *L) +{ + draw::ellipse *vs = new(L, GS_DRAW_ELLIPSE) draw::ellipse(); + double x = luaL_checknumber (L, 1); + double y = luaL_checknumber (L, 2); + double rx = luaL_checknumber (L, 3); + double ry = luaL_checknumber (L, 4); + vs->self().init(x, y, rx, ry, 0, false); + return 1; +} + +int +agg_circle_new (lua_State *L) +{ + draw::ellipse *vs = new(L, GS_DRAW_ELLIPSE) draw::ellipse(); + double x = luaL_checknumber (L, 1); + double y = luaL_checknumber (L, 2); + double r = luaL_checknumber (L, 3); + vs->self().init(x, y, r, r, 0, false); + return 1; +} + +int +agg_ellipse_free (lua_State *L) +{ + typedef draw::ellipse ellipse_type; + ellipse_type *ellipse = (ellipse_type *) gs_check_userdata (L, 1, GS_DRAW_ELLIPSE); + ellipse->~ellipse_type(); + return 0; +} + static unsigned int double2uint8 (double x) { int u = x * 255.0; @@ -321,6 +365,10 @@ draw_register (lua_State *L) luaL_register (L, NULL, agg_path_methods); lua_pop (L, 1); + luaL_newmetatable (L, GS_METATABLE(GS_DRAW_ELLIPSE)); + luaL_register (L, NULL, agg_ellipse_methods); + lua_pop (L, 1); + luaL_newmetatable (L, GS_METATABLE(GS_RGBA_COLOR)); lua_pushvalue (L, -1); lua_setfield (L, -2, "__index"); |