improved text class - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/agg-plot/lua-text.cpp
diff options
context:
space:
mode:
authorfrancesco-ST <francesco.abbate@st.com>2010年08月05日 13:58:06 +0200
committerfrancesco-ST <francesco.abbate@st.com>2010年08月05日 13:58:06 +0200
commit19b34676bbbb009b5a60c572eebe82c447185b67 (patch)
tree3356c71e184649f7ec942c88844c8d9c381c497e /agg-plot/lua-text.cpp
parent342f6c89dc388883f174e37627fb013190311a2d (diff)
downloadgsl-shell-19b34676bbbb009b5a60c572eebe82c447185b67.tar.gz
improved text class
Diffstat (limited to 'agg-plot/lua-text.cpp')
-rw-r--r--agg-plot/lua-text.cpp 177
1 files changed, 177 insertions, 0 deletions
diff --git a/agg-plot/lua-text.cpp b/agg-plot/lua-text.cpp
new file mode 100644
index 00000000..91e8f45b
--- /dev/null
+++ b/agg-plot/lua-text.cpp
@@ -0,0 +1,177 @@
+
+extern "C" {
+#include <lua.h>
+#include <lauxlib.h>
+}
+
+#include "lua-text.h"
+#include "gs-types.h"
+#include "lua-utils.h"
+#include "lua-cpp-utils.h"
+
+#include "text.h"
+
+static int agg_text_new (lua_State *L);
+static int agg_text_free (lua_State *L);
+static int agg_text_set_point (lua_State *L);
+static int agg_text_index (lua_State *L);
+static int agg_text_newindex (lua_State *L);
+
+static int agg_text_text_set (lua_State *L);
+static int agg_text_angle_set (lua_State *L);
+static int agg_text_justif_set (lua_State *L);
+
+
+static draw::text* check_agg_text (lua_State *L, int index);
+
+static const struct luaL_Reg text_functions[] = {
+ {"text", agg_text_new},
+ {NULL, NULL}
+};
+
+static const struct luaL_Reg text_methods[] = {
+ {"__gc", agg_text_free},
+ {"__index", agg_text_index},
+ {"__newindex", agg_text_newindex},
+ {"set", agg_text_set_point},
+ {NULL, NULL}
+};
+
+static const struct luaL_Reg text_properties_get[] = {
+ {NULL, NULL}
+};
+
+static const struct luaL_Reg text_properties_set[] = {
+ {"text", agg_text_text_set },
+ {"angle", agg_text_angle_set },
+ {"justif", agg_text_justif_set },
+ {NULL, NULL}
+};
+
+draw::text *
+check_agg_text (lua_State *L, int index)
+{
+ return (draw::text *) gs_check_userdata (L, index, GS_DRAW_TEXT);
+}
+
+int
+agg_text_new (lua_State *L)
+{
+ double size = luaL_optnumber (L, 1, 10.0);
+ double width = luaL_optnumber (L, 2, 1.0);
+ new(L, GS_DRAW_TEXT) draw::text(size, width);
+ return 1;
+}
+
+int
+agg_text_free (lua_State *L)
+{
+ typedef draw::text text_type;
+ text_type *t = check_agg_text (L, 1);
+ t->~text_type();
+ return 0;
+}
+
+int
+agg_text_text_set (lua_State *L)
+{
+ draw::text *t = check_agg_text (L, 1);
+ const char *str_text = luaL_checkstring (L, 2);
+ t->set_text(str_text);
+ return 0;
+}
+
+int
+agg_text_angle_set (lua_State *L)
+{
+ draw::text *t = check_agg_text (L, 1);
+ double th = luaL_checknumber (L, 2);
+ t->angle(th);
+ return 0;
+}
+
+int
+agg_text_justif_set (lua_State *L)
+{
+ draw::text *t = check_agg_text (L, 1);
+ const char *justif = luaL_checkstring (L, 2);
+ size_t len = strlen (justif);
+
+ if (len > 0)
+ {
+ char ch = justif[0];
+ double hjf;
+ switch (ch)
+ {
+ case 'l':
+ hjf = 0.0;
+ break;
+ case 'c':
+ hjf = 0.5;
+ break;
+ case 'r':
+ hjf = 1.0;
+ break;
+ default:
+ luaL_error (L, "invalid text justification");
+ }
+
+ t->hjustif(hjf);
+ }
+
+ if (len > 1)
+ {
+ char ch = justif[1];
+ double vjf;
+ switch (ch)
+ {
+ case 'b':
+ vjf = 0.0;
+ break;
+ case 'c':
+ vjf = 0.5;
+ break;
+ case 't':
+ vjf = 1.0;
+ break;
+ default:
+ luaL_error (L, "invalid text justification");
+ }
+
+ t->vjustif(vjf);
+ }
+
+ return 0;
+}
+
+int
+agg_text_set_point (lua_State *L)
+{
+ draw::text *t = check_agg_text (L, 1);
+ double x = luaL_checknumber (L, 2);
+ double y = luaL_checknumber (L, 3);
+ t->set_point(x, y);
+ return 0;
+}
+
+int
+agg_text_index (lua_State *L)
+{
+ return mlua_index_with_properties (L, text_properties_get, false);
+}
+
+int
+agg_text_newindex (lua_State *L)
+{
+ return mlua_newindex_with_properties (L, text_properties_set);
+}
+
+void
+text_register (lua_State *L)
+{
+ luaL_newmetatable (L, GS_METATABLE(GS_DRAW_TEXT));
+ luaL_register (L, NULL, text_methods);
+ lua_pop (L, 1);
+
+ luaL_register (L, NULL, text_functions);
+}
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月14日 00:28:53 +0000

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