gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/agg-plot/agg-parse-trans.cpp
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2010年08月01日 19:48:08 +0200
committerFrancesco Abbate <francesco.bbt@gmail.com>2010年08月01日 19:48:08 +0200
commit5a132340703270e5de65fed6499e475846a56dd5 (patch)
tree963941b3abe7a99cbce0edd4fc17d18c39be93ac /agg-plot/agg-parse-trans.cpp
parent975bbb0229edfb8ca2be826994f5422a0c8d6c38 (diff)
downloadgsl-shell-5a132340703270e5de65fed6499e475846a56dd5.tar.gz
complete the template code for drawable objects.
The class hierarchy is completely parametrized using templates. The Lua binding are there but not tested.
Diffstat (limited to 'agg-plot/agg-parse-trans.cpp')
-rw-r--r--agg-plot/agg-parse-trans.cpp 193
1 files changed, 134 insertions, 59 deletions
diff --git a/agg-plot/agg-parse-trans.cpp b/agg-plot/agg-parse-trans.cpp
index f3b5e40b..3424c0e1 100644
--- a/agg-plot/agg-parse-trans.cpp
+++ b/agg-plot/agg-parse-trans.cpp
@@ -1,4 +1,6 @@
+#include <string.h>
+
extern "C" {
#include "lua.h"
#include "lauxlib.h"
@@ -10,6 +12,11 @@ extern "C" {
#include "lua-draw.h"
#include "gs-types.h"
#include "colors.h"
+
+#include "scalable.h"
+#include "drawable.h"
+#include "path.h"
+#include "text.h"
#include "trans.h"
struct property_reg {
@@ -17,11 +24,7 @@ struct property_reg {
const char *name;
};
-struct builder_reg {
- const char *name;
- vertex_source *(*func)(lua_State *, int, vertex_source *);
-};
-
+/*
static vertex_source * build_stroke (lua_State *L, int i, vertex_source *s);
static vertex_source * build_curve (lua_State *L, int i, vertex_source *s);
static vertex_source * build_marker (lua_State *L, int i, vertex_source *s);
@@ -29,6 +32,7 @@ static vertex_source * build_dash (lua_State *L, int i, vertex_source *s);
static vertex_source * build_extend (lua_State *L, int i, vertex_source *s);
static vertex_source * build_translate (lua_State *L, int i, vertex_source *s);
static vertex_source * build_rotate (lua_State *L, int i, vertex_source *s);
+*/
struct property_reg line_cap_properties[] = {
{(int) agg::butt_cap, "butt" },
@@ -46,17 +50,6 @@ struct property_reg line_join_properties[] = {
{0, NULL}
};
-const builder_reg builder_table[] = {
- {"stroke", build_stroke },
- {"dash", build_dash},
- {"curve", build_curve},
- {"marker", build_marker},
- {"extend", build_extend},
- {"translate", build_translate},
- {"rotate", build_rotate},
- {NULL, NULL}
-};
-
static int
property_lookup (struct property_reg *prop, const char *key)
{
@@ -74,63 +67,105 @@ property_lookup (struct property_reg *prop, const char *key)
return default_value;
}
-vertex_source *
-build_stroke (lua_State *L, int specindex, vertex_source *obj)
+template <class context>
+typename context::base_type* build_stroke (lua_State *L, int specindex, typename context::base_type *obj)
{
- double width = mlua_named_optnumber (L, specindex, "width", 1.0);
+ typedef typename trans<context>::stroke stroke_type;
+
+ double width = mlua_named_optnumber (L, specindex, "width", 1.0);
const char *cap_str = mlua_named_optstring (L, specindex, "cap", NULL);
const char *join_str = mlua_named_optstring (L, specindex, "join", NULL);
- trans::stroke *stroke = new trans::stroke(obj, width);
+ stroke_type *s = new stroke_type(obj);
+
+ typename trans<context>::stroke_base& stroke = s->self();
+
+ stroke.width(width);
if (cap_str)
{
int cap = property_lookup (line_cap_properties, cap_str);
- stroke->line_cap((agg::line_cap_e) cap);
+ stroke.line_cap((agg::line_cap_e) cap);
}
if (join_str)
{
int join = property_lookup (line_join_properties, join_str);
- stroke->line_join((agg::line_join_e) join);
+ stroke.line_join((agg::line_join_e) join);
}
- return (vertex_source *) stroke;
+ return (typename context::base_type *) s;
}
-vertex_source *
-build_curve (lua_State *L, int specindex, vertex_source *obj)
+template <class context> typename context::base_type*
+build_curve (lua_State *L, int specindex, typename context::base_type *obj)
{
- trans::curve *c = new trans::curve(obj);
- return (vertex_source *) c;
+ typedef typename trans<context>::curve curve_type;
+ return (typename context::base_type *) new curve_type(obj);
}
-vertex_source *
-build_marker (lua_State *L, int specindex, vertex_source *obj)
+template <class context> typename context::base_type*
+build_marker (lua_State *L, int specindex, typename context::base_type *obj)
{
+ typedef typename trans<context>::marker marker_type;
+
double size = mlua_named_optnumber (L, specindex, "size", 3.0);
- return (vertex_source *) new trans::marker(obj, size);
+ const char *mark = mlua_named_optstring (L, specindex, "mark", "circle");
+ marker_type *m = new marker_type(obj, size, mark);
+ return (typename context::base_type *) m;
}
-vertex_source *
-build_dash (lua_State *L, int specindex, vertex_source *obj)
+template <class context> typename context::base_type *
+build_dash (lua_State *L, int specindex, typename context::base_type *obj)
{
- double a = mlua_named_optnumber (L, specindex, "a", 10.0);
- double b = mlua_named_optnumber (L, specindex, "b", a);
+ typedef typename trans<context>::dash dash_type;
- trans::dash *dash = new trans::dash(obj);
- dash->add_dash(a, b);
+ dash_type *d = new dash_type(obj);
+ typename trans<context>::dash_base& dash = d->self();
+
+ for (int j = 2; /* */; j += 2)
+ {
+ lua_rawgeti (L, specindex, j);
+
+ if (lua_isnumber (L, -1))
+ {
+ double a = lua_tonumber (L, -1);
+ lua_pop (L, 1);
+
+ lua_rawgeti (L, specindex, j+1);
+ if (lua_isnumber (L, -1))
+ {
+ double b = lua_tonumber (L, -1);
+ dash.add_dash(a, b);
+ lua_pop (L,1);
+ }
+ else
+ break;
+ }
+ else
+ break;
+ }
+ lua_pop (L, 1);
- return (vertex_source *) dash;
+ return (typename context::base_type *) d;
}
-vertex_source *
-build_extend (lua_State *L, int specindex, vertex_source *obj)
+template <class context> typename context::base_type*
+build_extend (lua_State *L, int specindex, typename context::base_type *obj)
{
+ typedef typename trans<context>::extend extend_type;
+
double width = mlua_named_optnumber (L, specindex, "width", 1.0);
- return (vertex_source *) new trans::extend(obj, width);
+ extend_type *m = new extend_type(obj);
+
+ typename trans<context>::extend_base& e = m->self();
+ e.width(width);
+ e.auto_detect_orientation(true);
+
+ return (typename context::base_type *) m;
}
+/*
vertex_source *
build_translate (lua_State *L, int specindex, vertex_source *obj)
{
@@ -153,10 +188,54 @@ build_rotate (lua_State *L, int specindex, vertex_source *obj)
return (vertex_source *) t;
}
+*/
+
+template <class context>
+class builder {
+ typedef typename context::base_type base_type;
+public:
+ typedef base_type *(func_type)(lua_State *, int, base_type *);
+
+ struct reg {
+ const char *name;
+ func_type *func;
+ };
+
+private:
+
+ static const reg builder_table[];
+
+public:
+ static func_type* lookup(const char *key)
+ {
+ const reg *p;
+ for (p = builder_table; p->name != NULL; p++)
+ {
+ if (strcmp (p->name, key) == 0)
+ return p->func;
+ }
+
+ return NULL;
+ }
+};
-vertex_source *
-parse_spec (lua_State *L, int specindex, vertex_source *obj)
+template <class context>
+const typename builder<context>::reg builder<context>::builder_table[] = {
+ {"stroke", build_stroke<context> },
+ {"dash", build_dash <context> },
+ {"curve", build_curve <context> },
+ {"marker", build_marker<context> },
+ {"extend", build_extend<context> },
+ // {"translate", build_translate},
+ // {"rotate", build_rotate},
+ {NULL, NULL}
+};
+
+template <class context> typename context::base_type *
+parse_spec (lua_State *L, int specindex, typename context::base_type *obj)
{
+ typedef builder<context> builder_type;
+
const char *tag;
lua_rawgeti (L, specindex, 1);
@@ -169,18 +248,17 @@ parse_spec (lua_State *L, int specindex, vertex_source *obj)
tag = lua_tostring (L, -1);
lua_pop (L, 1);
- for (const builder_reg *b = builder_table; b->name != NULL; b++)
- {
- if (strcmp (b->name, tag) == 0)
- return b->func (L, specindex, obj);
- }
+ typename builder_type::func_type *f = builder_type::lookup(tag);
+
+ if (f)
+ return f (L, specindex, obj);
luaL_error (L, "invalid trasformation tag");
return NULL;
}
-vertex_source *
-parse_spec_pipeline (lua_State *L, int index, vertex_source *obj)
+template <class context> typename context::base_type *
+parse_spec_pipeline (lua_State *L, int index, typename context::base_type *obj)
{
size_t k, nb;
@@ -195,14 +273,14 @@ parse_spec_pipeline (lua_State *L, int index, vertex_source *obj)
for (k = nb; k > 0; k--)
{
lua_rawgeti (L, index, k);
- obj = parse_spec (L, index+1, obj);
+ obj = parse_spec<context> (L, index+1, obj);
lua_pop (L, 1);
}
return obj;
}
-vertex_source *
+drawable *
parse_graph_args (lua_State *L)
{
int narg = lua_gettop (L);
@@ -219,24 +297,21 @@ parse_graph_args (lua_State *L)
return NULL;
}
- vertex_source *curr = check_agg_obj (L, 2);
+ scalable *s = check_agg_scalable (L, 2);
if (narg > 4)
{
- curr = parse_spec_pipeline (L, 5, curr);
+ s = parse_spec_pipeline<scalable_context> (L, 5, s);
lua_pop (L, 1);
}
- if (curr->need_resize())
- {
- curr = new trans::resize(curr);
- }
+ drawable *w = new window_scalable(s);
if (narg > 3)
{
- curr = parse_spec_pipeline (L, 4, curr);
+ w = parse_spec_pipeline<drawable_context> (L, 4, w);
lua_pop (L, 1);
}
- return curr;
+ return w;
}
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月14日 03:20:16 +0000

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