-rw-r--r-- | agg-plot/Makefile | 2 | ||||
-rw-r--r-- | agg-plot/agg-parse-trans.cpp | 193 | ||||
-rw-r--r-- | agg-plot/agg-parse-trans.h | 11 | ||||
-rw-r--r-- | agg-plot/canvas-window-cpp.h | 4 | ||||
-rw-r--r-- | agg-plot/canvas-window.cpp | 4 | ||||
-rw-r--r-- | agg-plot/drawable.h | 2 | ||||
-rw-r--r-- | agg-plot/graphical-object.h | 14 | ||||
-rw-r--r-- | agg-plot/lua-draw.cpp | 51 | ||||
-rw-r--r-- | agg-plot/lua-draw.h | 14 | ||||
-rw-r--r-- | agg-plot/plot-window.cpp | 6 | ||||
-rw-r--r-- | agg-plot/plot.h | 6 | ||||
-rw-r--r-- | agg-plot/trans.h | 372 |
diff --git a/agg-plot/Makefile b/agg-plot/Makefile index 196eb2d2..bdd4c421 100644 --- a/agg-plot/Makefile +++ b/agg-plot/Makefile @@ -44,7 +44,7 @@ endif INCLUDES += $(AGG_INCLUDES) -I$(GSH_BASE_DIR) -I$(LUADIR)/src -AGGPLOT_SRC_FILES = $(PLATSUP_SRC_FILES) utils.cpp units.cpp colors.cpp trans.cpp markers.cpp lua-draw.cpp agg-parse-trans.cpp canvas-window.cpp plot-window.cpp +AGGPLOT_SRC_FILES = $(PLATSUP_SRC_FILES) utils.cpp units.cpp colors.cpp markers.cpp lua-draw.cpp text.cpp drawable.cpp agg-parse-trans.cpp canvas-window.cpp plot-window.cpp AGGPLOT_OBJ_FILES := $(AGGPLOT_SRC_FILES:%.cpp=%.o) 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; } diff --git a/agg-plot/agg-parse-trans.h b/agg-plot/agg-parse-trans.h index da51e172..f7ecc72a 100644 --- a/agg-plot/agg-parse-trans.h +++ b/agg-plot/agg-parse-trans.h @@ -5,14 +5,9 @@ extern "C" { #include "lua.h" } -#include "vertex-source.h" +#include "scalable.h" +#include "drawable.h" -extern vertex_source * parse_spec (lua_State *L, int specindex, - vertex_source *obj); - -extern vertex_source * parse_spec_pipeline (lua_State *L, int index, - vertex_source *obj); - -extern vertex_source * parse_graph_args (lua_State *L); +extern drawable * parse_graph_args (lua_State *L); #endif diff --git a/agg-plot/canvas-window-cpp.h b/agg-plot/canvas-window-cpp.h index 673ae8f7..df9f02e2 100644 --- a/agg-plot/canvas-window-cpp.h +++ b/agg-plot/canvas-window-cpp.h @@ -7,7 +7,7 @@ #include "defs.h" #include "canvas-window.h" -#include "vertex-source.h" +#include "drawable.h" #include "canvas.h" #include "utils.h" @@ -59,7 +59,7 @@ public: void start_new_thread (lua_State *L); - bool draw(vertex_source *obj, agg::rgba8 *color, bool as_line) + bool draw(drawable *obj, agg::rgba8 *color, bool as_line) { if (! m_canvas) return false; diff --git a/agg-plot/canvas-window.cpp b/agg-plot/canvas-window.cpp index 20c727b5..b8a21e11 100644 --- a/agg-plot/canvas-window.cpp +++ b/agg-plot/canvas-window.cpp @@ -175,11 +175,11 @@ int canvas_window_draw_gener (lua_State *L, bool as_line) { canvas_window *win = canvas_window::check (L, 1); - vertex_source *obj = parse_graph_args (L); + drawable *obj = parse_graph_args (L); agg::rgba8 *color = check_color_rgba8 (L, 3); const agg::trans_affine& mtx = win->transform(); - obj->apply_transform(mtx, 1.0); + obj->apply_transform(mtx); bool success = win->draw(obj, color, as_line); diff --git a/agg-plot/drawable.h b/agg-plot/drawable.h index 67304ba1..66e4e5f8 100644 --- a/agg-plot/drawable.h +++ b/agg-plot/drawable.h @@ -62,7 +62,7 @@ public: drawable_adapter(drawable *src) : root_type(src) { }; template <class init_type> - drawable_adapter(scalable* src, init_type& val): root_type(src, val) {}; + drawable_adapter(drawable* src, init_type& val): root_type(src, val) {}; virtual void apply_transform(const agg::trans_affine& m) { diff --git a/agg-plot/graphical-object.h b/agg-plot/graphical-object.h deleted file mode 100644 index 656607dd..00000000 --- a/agg-plot/graphical-object.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef GRAPHICAL_OBJECT_H -#define GRAPHICAL_OBJECT_H - -#include "agg_trans_affine.h" - -class graphical_object : public vertex_source { -public: - virtual void apply_transform(const agg::trans_affine& m, double as) = 0; - virtual void bounding_box(double *x1, double *y1, double *x2, double *y2) = 0; - virtual bool dispose() { return false; }; - virtual bool need_resize() { return true; }; -}; - -#endif diff --git a/agg-plot/lua-draw.cpp b/agg-plot/lua-draw.cpp index 16ae5ea3..6b280368 100644 --- a/agg-plot/lua-draw.cpp +++ b/agg-plot/lua-draw.cpp @@ -42,14 +42,14 @@ static int agg_path_index (lua_State *L); static int agg_text_free (lua_State *L); static int agg_text_set_text (lua_State *L); static int agg_text_set_point (lua_State *L); -static int agg_text_rotate (lua_State *L); +// static int agg_text_rotate (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); static int agg_rgba_set_alpha (lua_State *L); -static void path_cmd (my::path *p, int cmd, struct cmd_call_stack *stack); +static void path_cmd (draw::path *p, int cmd, struct cmd_call_stack *stack); static struct path_cmd_reg cmd_table[] = { {CMD_MOVE_TO, "move_to", "ff"}, @@ -87,14 +87,14 @@ static const struct luaL_Reg agg_text_methods[] = { {"__gc", agg_text_free}, {"set_point", agg_text_set_point}, {"set_text", agg_text_set_text}, - {"rotate", agg_text_rotate}, + // {"rotate", agg_text_rotate}, {NULL, NULL} }; int agg_path_new (lua_State *L) { - my::path *vs = new(L, GS_DRAW_PATH) my::path(); + draw::path *vs = new(L, GS_DRAW_PATH) draw::path(); if (lua_gettop (L) >= 2) { @@ -111,25 +111,25 @@ agg_path_new (lua_State *L) return 1; } -my::path * +draw::path * check_agg_path (lua_State *L, int index) { - return (my::path *) gs_check_userdata (L, index, GS_DRAW_PATH); + return (draw::path *) gs_check_userdata (L, index, GS_DRAW_PATH); } int agg_path_free (lua_State *L) { - typedef my::path path_type; + typedef draw::path path_type; path_type *path = check_agg_path (L, 1); path->~path_type(); return 0; } void -path_cmd (my::path *p, int _cmd, struct cmd_call_stack *s) +path_cmd (draw::path *p, int _cmd, struct cmd_call_stack *s) { - agg::path_storage& ps = p->get_path(); + agg::path_storage& ps = p->self(); path_cmd_e cmd = (path_cmd_e) _cmd; switch (cmd) @@ -160,7 +160,7 @@ path_cmd (my::path *p, int _cmd, struct cmd_call_stack *s) static int agg_path_cmd (lua_State *L) { - my::path *p = check_agg_path (L, 1); + draw::path *p = check_agg_path (L, 1); int id = lua_tointeger (L, lua_upvalueindex(1)); const char *signature = lua_tostring (L, lua_upvalueindex(2)); int argc = 2, f_count = 0, b_count = 0; @@ -215,10 +215,11 @@ agg_path_index (lua_State *L) return 0; } -vertex_source * -check_agg_obj (lua_State *L, int index) +/* NB: for the moment we have only one kind of "scalable" object. */ +scalable * +check_agg_scalable (lua_State *L, int index) { - int tplist[] = {GS_DRAW_PATH, GS_DRAW_TEXT, GS_INVALID_TYPE}; + int tplist[] = {GS_DRAW_PATH, GS_INVALID_TYPE}; void *p = NULL; int j; @@ -232,13 +233,13 @@ check_agg_obj (lua_State *L, int index) if (p == NULL) gs_type_error (L, index, "drawing object"); - return (vertex_source *) p; + return (scalable *) p; } -my::text * +draw::text * check_agg_text (lua_State *L, int index) { - return (my::text *) gs_check_userdata (L, index, GS_DRAW_TEXT); + return (draw::text *) gs_check_userdata (L, index, GS_DRAW_TEXT); } int @@ -246,14 +247,14 @@ 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) my::text(size, width); + new(L, GS_DRAW_TEXT) draw::text(size, width); return 1; } int agg_text_free (lua_State *L) { - typedef my::text text_type; + typedef draw::text text_type; text_type *t = check_agg_text (L, 1); t->~text_type(); return 0; @@ -262,30 +263,32 @@ agg_text_free (lua_State *L) int agg_text_set_text (lua_State *L) { - my::text *t = check_agg_text (L, 1); + draw::text *t = check_agg_text (L, 1); const char *text = luaL_checkstring (L, 2); - t->set_text(text); + t->self().text(text); return 0; } int agg_text_set_point (lua_State *L) { - my::text *t = check_agg_text (L, 1); + draw::text *t = check_agg_text (L, 1); double x = luaL_checknumber (L, 2); double y = luaL_checknumber (L, 3); - t->start_point(x, y); + t->self().start_point(x, y); return 0; } +/* int agg_text_rotate (lua_State *L) { - my::text *t = check_agg_text (L, 1); + draw::text *t = check_agg_text (L, 1); double a = luaL_checknumber (L, 2); t->rotate(a); return 0; }; +*/ static unsigned int double2uint8 (double x) { @@ -384,6 +387,8 @@ draw_register (lua_State *L) { pthread_mutex_init (agg_mutex, NULL); + markers::init(); + luaL_newmetatable (L, GS_METATABLE(GS_DRAW_PATH)); luaL_register (L, NULL, agg_path_methods); lua_pop (L, 1); diff --git a/agg-plot/lua-draw.h b/agg-plot/lua-draw.h index 3df6fc9d..08b68568 100644 --- a/agg-plot/lua-draw.h +++ b/agg-plot/lua-draw.h @@ -12,8 +12,12 @@ __END_DECLS #ifdef __cplusplus -#include "vertex-source.h" -#include "drawables.h" +#include "agg_color_rgba.h" + +#include "scalable.h" +#include "drawable.h" +#include "path.h" +#include "text.h" #include "trans.h" extern int agg_text_new (lua_State *L); @@ -21,9 +25,9 @@ extern int agg_path_new (lua_State *L); extern int agg_rgb_new (lua_State *L); extern int agg_rgba_new (lua_State *L); -extern vertex_source* check_agg_obj (lua_State *L, int index); -extern my::path* check_agg_path (lua_State *L, int index); -extern my::text* check_agg_text (lua_State *L, int index); +extern scalable* check_agg_scalable (lua_State *L, int index); +extern draw::path* check_agg_path (lua_State *L, int index); +extern draw::text* check_agg_text (lua_State *L, int index); extern agg::rgba8* check_agg_rgba8 (lua_State *L, int index); #endif diff --git a/agg-plot/plot-window.cpp b/agg-plot/plot-window.cpp index d1fe86c6..74005134 100644 --- a/agg-plot/plot-window.cpp +++ b/agg-plot/plot-window.cpp @@ -12,7 +12,7 @@ extern "C" { #include "lua-draw.h" #include "colors.h" #include "plot.h" -#include "vertex-source.h" +#include "drawable.h" #include "resource-manager.h" #include "agg-parse-trans.h" @@ -65,7 +65,7 @@ __END_DECLS class plot_window : public canvas_window { public: - typedef plot<vertex_source, lua_management> plot_type; + typedef plot<drawable, lua_management> plot_type; plot_window(): canvas_window(colors::white), m_plot() {}; @@ -158,7 +158,7 @@ int plot_window_add_gener (lua_State *L, bool as_line) { plot_window *p = plot_window::check(L, 1); - vertex_source *obj = parse_graph_args (L); + drawable *obj = parse_graph_args (L); agg::rgba8 *color = check_color_rgba8 (L, 3); lua_pushvalue (L, 1); diff --git a/agg-plot/plot.h b/agg-plot/plot.h index 8754360c..32771507 100644 --- a/agg-plot/plot.h +++ b/agg-plot/plot.h @@ -5,10 +5,8 @@ #include <stdlib.h> #include <limits.h> -#include "vertex-source.h" - #include "utils.h" -#include "drawables.h" +#include "drawable.h" #include "canvas.h" #include "units.h" #include "resource-manager.h" @@ -184,7 +182,7 @@ void plot<VS,RM>::draw_elements(canvas &canvas) { container& d = m_elements[j]; VS& vs = d.get_vertex_source(); - vs.apply_transform(m, 1.0); + vs.apply_transform(m); if (d.outline) canvas.draw_outline(vs, d.color); diff --git a/agg-plot/trans.h b/agg-plot/trans.h index 9d5a1dbf..e92bc0e8 100644 --- a/agg-plot/trans.h +++ b/agg-plot/trans.h @@ -15,47 +15,7 @@ #include "agg_conv_transform.h" #include "agg_conv_contour.h" -/* -template <class conv_type> -class scalable_adapter : public vs_adapter<conv_type, scalable> -{ - typedef vs_adapter<conv_type, scalable> root_type; - -public: - scalable_adapter(scalable *src) : root_type(src) { }; - - template <class init_type> - scalable_adapter(scalable* src, init_type& val): - root_type(src, val) - { }; - - virtual void approximation_scale(double as) - { - this->m_source->approximation_scale(as); - }; -}; - - -template <class conv_type> -class scalable_adapter_approx : public vs_adapter<conv_type, scalable> -{ - typedef vs_adapter<conv_type, scalable> root_type; - -public: - scalable_adapter_approx(scalable *src) : root_type(src) { }; - - template <class init_type> - scalable_adapter_approx(scalable* src, init_type& val): - root_type(src, val) - { }; - - virtual void approximation_scale(double as) - { - this->m_output.approximation_scale(as); - this->m_source->approximation_scale(as); - }; -}; -*/ +#include "my_conv_simple_marker.h" struct scalable_context { @@ -108,12 +68,20 @@ struct trans { typedef typename context::base_type base_type; - typedef typename context::template approx<agg::conv_stroke<base_type> > stroke; - typedef typename context::template approx<agg::conv_curve<base_type> > curve; - typedef typename context::template simple<agg::conv_dash<base_type> > dash; - typedef typename context::template approx<agg::conv_contour<base_type> > extend; + typedef agg::conv_stroke<base_type> stroke_base; + typedef typename context::template approx<stroke_base> stroke; - typedef typename context::template simple<agg::conv_transform<base_type> > vs_affine; + typedef agg::conv_curve<base_type> curve_base; + typedef typename context::template approx<curve_base> curve; + + typedef agg::conv_dash<base_type> dash_base; + typedef typename context::template simple<dash_base> dash; + + typedef agg::conv_contour<base_type> extend_base; + typedef typename context::template approx<extend_base> extend; + + typedef agg::conv_transform<base_type> affine_base; + typedef typename context::template simple<affine_base> vs_affine; class affine : public vs_affine { agg::trans_affine m_matrix; @@ -125,16 +93,11 @@ struct trans { { m_norm = m_matrix.scale(); }; - - virtual void approximation_scale(double as) - { - this->m_source->approximation_scale(m_norm * as); - }; }; typedef agg::conv_transform<scalable> symbol_type; - typedef my::conv_simple_marker<base_type, symbol_type> conv_marker; - typedef typename context::template simple<conv_marker> vs_marker; + typedef my::conv_simple_marker<base_type, symbol_type> marker_base; + typedef typename context::template simple<marker_base> vs_marker; class marker : public vs_marker { scalable& m_symbol; @@ -145,313 +108,10 @@ struct trans { marker(base_type* src, double size, const char *sym): vs_marker(src, m_trans), m_symbol(markers::get(sym)), m_matrix(), m_trans(m_symbol, m_matrix) - { - m_matrix.scale(size); - }; - }; -}; - -#if 0 -struct trans { - - typedef scalable_adapter_approx<agg::conv_stroke<scalable> > stroke; - typedef scalable_adapter_approx<agg::conv_curve<scalable> > curve; - typedef scalable_adapter<agg::conv_dash<scalable> > dash; - typedef scalable_adapter_approx<agg::conv_curve<scalable> > extend; - - typedef scalable_adapter<agg::conv_transform<scalable> > vs_affine; - - class affine : public vs_affine { - agg::trans_affine m_matrix; - double m_norm; - - public: - affine(scalable *src, const agg::trans_affine& mtx) : - vs_affine(src, m_matrix), m_matrix(mtx) - { - m_norm = trans_affine_max_norm (m_matrix); - }; - - virtual void approximation_scale(double as) { - this->m_source->approximation_scale(m_norm * as); - }; - }; - - typedef my::conv_simple_marker<scalable, agg::conv_transform<agg::path_storage> > conv_marker; - typedef scalable_adapter<conv_marker> vs_marker; - - class marker : public vs_marker { - agg::path_storage& m_symbol; - agg::trans_affine m_matrix; - agg::conv_transform<agg::path_storage> m_trans; - - public: - marker(scalable* src, double size, const char *sym): - vs_marker(src, m_trans), - m_symbol(markers::get(sym)), m_matrix(), m_trans(m_symbol, m_matrix) - { m_matrix.scale(size); }; }; - - /* - template <class symbol_type> - class marker_gen : public my::conv_simple_marker<scalable, symbol_type> { - typedef my::conv_simple_marker<scalable, symbol_type> base_type; - - symbol_type m_symbol; - agg::trans_affine m_matrix; - agg::conv_transform<symbol_type> m_trans; - - public: - marker_gen(scalable* src, double size): - base_type(src, m_trans), m_symbol(), m_matrix(), m_trans(m_symbol, m_matrix) - { }; - - virtual void approximation_scale(double as) - { - m_symbol.approximation_scale(as); - m_source->approximation_scale(as); - }; - - }; - */ }; -#endif - -#if 0 -namespace trans { - - // -------------------- stroke -------------------- - class stroke : public vs_stroke { - public: - typedef agg::conv_stroke<scalable> base_type; - - stroke(scalable* src, double width = 1.0): vs_stroke(src) - { - base_type& v = self(); - v.width(width); - }; - - void line_cap(agg::line_cap_e cap) - { - m_output.line_cap(cap); - }; - - void line_join(agg::line_join_e join) - { - m_output.line_join(join); - }; - }; - - - // -------------------- curve -------------------- - typedef vs_curve curve; - - - // -------------------- dash -------------------- - class dash : public vs_dash { - public: - dash(scalable *src) : vs_dash(src) { }; - - void add_dash(double dash_len, double gap_len) - { - m_output.add_dash(dash_len, gap_len); - }; - }; - - // -------------------- marker -------------------- - class marker : public vs_marker_ellipse { - agg::ellipse m_ellipse; - - public: - marker(scalable* src, double size): vs_marker_ellipse(src, m_ellipse) - { - m_ellipse.init(0.0, 0.0, size/2, size/2); - }; - - virtual void approximation_scale(double as) - { - m_ellipse.approximation_scale(as); - m_source->approximation_scale(as); - }; - }; - -} -#endif - -#endif - -#if 0 -template<class T> -class vs_adapter : public vertex_source { -protected: - T m_output; - vertex_source* m_source; - -public: - vs_adapter(vertex_source* src): m_output(*src), m_source(src) - { - }; - - template <class init_type> - vs_adapter(vertex_source* src, init_type& val): - m_output(*src, val), m_source(src) - {}; - - virtual void rewind(unsigned path_id) { m_output.rewind(path_id); }; - virtual unsigned vertex(double* x, double* y) { return m_output.vertex(x, y); }; - - virtual bool dispose() - { - if (m_source->dispose()) - delete m_source; - return true; - }; - - virtual void apply_transform(const agg::trans_affine& m, double as) - { - m_source->apply_transform(m, as); - }; - - virtual void bounding_box(double *x1, double *y1, double *x2, double *y2) - { - m_source->bounding_box(x1, y1, x2, y2); - }; - - T& self() { return m_output; }; -}; - -typedef vs_adapter<agg::conv_stroke<vertex_source> > vs_stroke; -typedef vs_adapter<agg::conv_curve<vertex_source> > vs_curve; -typedef vs_adapter<agg::conv_dash<vertex_source> > vs_dash; -typedef vs_adapter<agg::conv_transform<vertex_source> > vs_transform; -typedef vs_adapter<agg::conv_contour<vertex_source> > vs_contour; - -namespace trans { - - class stroke : public vs_stroke { - public: - typedef agg::conv_stroke<vertex_source> base_type; - - stroke(vertex_source* src, double width = 1.0): vs_stroke(src) - { - base_type& v = self(); - v.width(width); - }; - - void line_cap(agg::line_cap_e cap) - { - m_output.line_cap(cap); - }; - - void line_join(agg::line_join_e join) - { - m_output.line_join(join); - }; - }; - - class curve : public vs_curve { - public: - curve(vertex_source* src): vs_curve(src) {}; - - virtual void apply_transform(const agg::trans_affine& m, double as) - { - m_output.approximation_scale(as); - m_source->apply_transform(m, as); - }; - }; - - class dash : public vs_dash { - public: - dash(vertex_source* src): vs_dash(src) {}; - - void add_dash(double dash_len, double gap_len) - { - m_output.add_dash(dash_len, gap_len); - } - }; - - typedef vs_adapter<my::conv_simple_marker<vertex_source, agg::ellipse> > vs_marker_ellipse; - - class marker : public vs_marker_ellipse { - agg::ellipse m_ellipse; - - public: - marker(vertex_source* src, double size): vs_marker_ellipse(src, m_ellipse) - { - m_ellipse.init(0.0, 0.0, size/2, size/2); - }; - - virtual void apply_transform(const agg::trans_affine& m, double as) - { - m_ellipse.approximation_scale(as); - m_source->apply_transform(m, as); - }; - }; - - class extend : public vs_contour { - public: - typedef agg::conv_contour<vertex_source> base_type; - - extend(vertex_source* src, double width): vs_contour(src) - { - base_type& v = self(); - v.width(width); - v.auto_detect_orientation(true); - }; - - virtual void apply_transform(const agg::trans_affine& m, double as) - { - m_output.approximation_scale(as); - m_source->apply_transform(m, as); - }; - }; - - class resize : public vs_transform { - agg::trans_affine m_matrix; - - static agg::trans_affine m_unit; - - public: - resize(vertex_source* src): - vs_transform(src, m_matrix), m_matrix(m_unit) {}; - - virtual void apply_transform(const agg::trans_affine& m, double as) - { - m_matrix = m; - as *= trans_affine_max_norm(m); - m_source->apply_transform(m, as); - }; - - virtual void bounding_box(double *x1, double *y1, double *x2, double *y2) - { - agg::bounding_rect_single(*m_source, 0, x1, y1, x2, y2); - }; - - private: - }; - - - class affine : public vs_transform { - agg::trans_affine m_matrix; - - public: - affine(vertex_source* src): vs_transform(src, m_matrix), m_matrix() {}; - - virtual void bounding_box(double *x1, double *y1, double *x2, double *y2) - { - agg::bounding_rect_single(m_output, 0, x1, y1, x2, y2); - }; - - const trans_affine& rotate(double a) { return m_matrix.rotate(a); }; - const trans_affine& translate(double x, double y) { return m_matrix.translate(x, y); }; - - void set_matrix(const agg::trans_affine& m) { m_matrix = m; }; - - agg::trans_affine& matrix() { return m_matrix; }; - }; -} #endif |