added native circle and ellipse objects - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
diff options
context:
space:
mode:
authorfrancesco-ST <francesco.abbate@st.com>2010年08月05日 14:29:43 +0200
committerfrancesco-ST <francesco.abbate@st.com>2010年08月05日 14:29:43 +0200
commit2dd683d5721fbd9d740feacf90caee564752696c (patch)
tree84eed8a5523fee1c8def4684307ef70eb388ca0d
parent19b34676bbbb009b5a60c572eebe82c447185b67 (diff)
downloadgsl-shell-2dd683d5721fbd9d740feacf90caee564752696c.tar.gz
added native circle and ellipse objects
Diffstat
-rw-r--r--agg-plot/lua-draw.cpp 48
-rw-r--r--agg-plot/path.h 3
-rw-r--r--examples/graphics.lua 24
-rw-r--r--gs-types.c 2
-rw-r--r--gs-types.h 1
5 files changed, 77 insertions, 1 deletions
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");
diff --git a/agg-plot/path.h b/agg-plot/path.h
index c16a8cef..6ad7b2ea 100644
--- a/agg-plot/path.h
+++ b/agg-plot/path.h
@@ -4,11 +4,12 @@
#include "scalable.h"
#include "agg_path_storage.h"
+#include "agg_ellipse.h"
namespace draw {
typedef vs_proxy<agg::path_storage, true> path;
-
+ typedef vs_proxy_approx<agg::ellipse, true> ellipse;
}
#endif
diff --git a/examples/graphics.lua b/examples/graphics.lua
index 4316d9c0..f813858f 100644
--- a/examples/graphics.lua
+++ b/examples/graphics.lua
@@ -85,5 +85,29 @@ function demo2()
return p
end
+function demo3()
+ local n = 24
+ local color = {'red', 'yellow', 'blue', 'darkgreen', 'cyan'}
+ local p = window('black')
+ local txt = text()
+ txt.text = 'Hello world!'
+
+ p:setview(-1, -1, 1, 1)
+
+ local N = 128
+ for j=0, N do
+ local th = 2*pi*j/N
+ txt.angle = th
+ p:clear()
+ for k=0, n-1 do
+ local a = 2*pi*k/n - pi/2
+ local ch = |t| t[(k % #t)+1]
+ p:draw(txt, ch(color), {{'translate', x = 100*cos(a), y= 100*sin(a)}})
+ end
+ p:refresh()
+ end
+ return p
+end
+
p1 = demo1()
p2 = demo2()
diff --git a/gs-types.c b/gs-types.c
index 4e4fa765..0750ff66 100644
--- a/gs-types.c
+++ b/gs-types.c
@@ -25,6 +25,7 @@ static int gs_type_string (lua_State *L);
#define GS_DRAW_PLOT_NAME_DEF "GSL.plot"
#define GS_DRAW_SCALABLE_NAME_DEF NULL
#define GS_DRAW_PATH_NAME_DEF "GSL.path"
+#define GS_DRAW_ELLIPSE_NAME_DEF "GSL.ellipse"
#define GS_DRAW_DRAWABLE_NAME_DEF NULL
#define GS_DRAW_TEXT_NAME_DEF "GSL.text"
#define GS_RGBA_COLOR_NAME_DEF "GSL.rgba"
@@ -57,6 +58,7 @@ const struct gs_type gs_type_table[] = {
MY_EXPAND(DRAW_PLOT, "plot"),
MY_EXPAND(DRAW_SCALABLE, "graphical object"),
MY_EXPAND_DER(DRAW_PATH, "geometric line", DRAW_SCALABLE),
+ MY_EXPAND_DER(DRAW_ELLIPSE, "geometric ellipse", DRAW_SCALABLE),
MY_EXPAND(DRAW_DRAWABLE, "window graphical object"),
MY_EXPAND_DER(DRAW_TEXT, "graphical text", DRAW_DRAWABLE),
MY_EXPAND(RGBA_COLOR, "color"),
diff --git a/gs-types.h b/gs-types.h
index b580b42d..8e14a575 100644
--- a/gs-types.h
+++ b/gs-types.h
@@ -27,6 +27,7 @@ enum gs_type_e {
GS_DRAW_PLOT,
GS_DRAW_SCALABLE,
GS_DRAW_PATH,
+ GS_DRAW_ELLIPSE,
GS_DRAW_DRAWABLE,
GS_DRAW_TEXT,
GS_RGBA_COLOR,
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月15日 06:23:53 +0000

AltStyle によって変換されたページ (->オリジナル) /