-rw-r--r-- | agg-plot/agg-parse-trans.cpp | 6 | ||||
-rw-r--r-- | agg-plot/drawable.h | 33 | ||||
-rw-r--r-- | agg-plot/markers.cpp | 28 | ||||
-rw-r--r-- | agg-plot/markers.h | 2 | ||||
-rw-r--r-- | agg-plot/path.h | 4 | ||||
-rw-r--r-- | agg-plot/scalable.h | 48 | ||||
-rw-r--r-- | agg-plot/text.cpp | 13 | ||||
-rw-r--r-- | agg-plot/text.h | 4 | ||||
-rw-r--r-- | agg-plot/trans.h | 8 |
diff --git a/agg-plot/agg-parse-trans.cpp b/agg-plot/agg-parse-trans.cpp index 147aa8a3..d7f11d17 100644 --- a/agg-plot/agg-parse-trans.cpp +++ b/agg-plot/agg-parse-trans.cpp @@ -305,7 +305,8 @@ parse_graph_args (lua_State *L, agg::rgba8& color) if (gs_is_userdata (L, 2, GS_DRAW_SCALABLE)) { - scalable *s = (scalable *) lua_touserdata (L, 2); + vertex_source *vs = (vertex_source *) lua_touserdata (L, 2); + scalable *s = new boxed_scalable(vs); if (narg > 4) { @@ -323,7 +324,8 @@ parse_graph_args (lua_State *L, agg::rgba8& color) } else if (gs_is_userdata (L, 2, GS_DRAW_DRAWABLE)) { - w = (drawable *) lua_touserdata (L, 2); + vertex_source *vs = (vertex_source *) lua_touserdata (L, 2); + w = new boxed_drawable(vs); } else { diff --git a/agg-plot/drawable.h b/agg-plot/drawable.h index 9ecd4284..56ac7ccf 100644 --- a/agg-plot/drawable.h +++ b/agg-plot/drawable.h @@ -6,19 +6,38 @@ #include "agg_trans_affine.h" #include "agg_conv_transform.h" +#include "agg_bounding_rect.h" -struct drawable { - - virtual void rewind(unsigned path_id) = 0; - virtual unsigned vertex(double* x, double* y) = 0; - - virtual void apply_transform(const agg::trans_affine& m, double as) = 0; +struct drawable : public vertex_source { virtual void bounding_box(double *x1, double *y1, double *x2, double *y2) = 0; virtual bool dispose() = 0; virtual ~drawable() { }; }; +class boxed_drawable : public drawable { + vertex_source *m_object; + + public: + boxed_drawable(vertex_source *p) : drawable(), m_object(p) {}; + + ~boxed_drawable() { }; + + virtual void rewind(unsigned path_id) { m_object->rewind(path_id); }; + virtual unsigned vertex(double* x, double* y) { return m_object->vertex(x, y); }; + virtual void apply_transform(const agg::trans_affine& m, double as) { m_object->apply_transform(m, as); }; + + virtual void bounding_box(double *x1, double *y1, double *x2, double *y2) + { + agg::bounding_rect_single (*m_object, 0, x1, y1, x2, y2); + }; + + virtual bool dispose() { return false; }; + + private: + boxed_drawable(); +}; + /* this class take a "scalable" object and it does transform it to a "drawable" by adding a conv_transform taht manage the window size transformation. */ @@ -58,7 +77,7 @@ public: virtual void bounding_box(double *x1, double *y1, double *x2, double *y2) { - this->m_source->bounding_box(x1, y1, x2, y2); + agg::bounding_rect_single (*this->m_source, 0, x1, y1, x2, y2); }; }; diff --git a/agg-plot/markers.cpp b/agg-plot/markers.cpp index f1aff020..d3094cd9 100644 --- a/agg-plot/markers.cpp +++ b/agg-plot/markers.cpp @@ -9,12 +9,12 @@ struct symbol_reg { const char *name; - scalable *(*builder)(); + vertex_source *(*builder)(); }; -static scalable *build_circle(); -static scalable *build_square(); -static scalable *build_triangle(); +static vertex_source *build_circle(); +static vertex_source *build_square(); +static vertex_source *build_triangle(); static struct symbol_reg builder_table[] = { {"circle", build_circle}, @@ -23,19 +23,19 @@ static struct symbol_reg builder_table[] = { {NULL, NULL} }; -scalable * +vertex_source * build_circle() { - typedef vs_proxy<agg::ellipse, false, true> circle_type; + typedef vs_proxy<agg::ellipse, true> circle_type; circle_type *circle = new circle_type(); circle->self().init(0.0, 0.0, 0.5, 0.5); - return (scalable *) circle; + return (vertex_source *) circle; } -scalable * +vertex_source * build_square() { - typedef vs_proxy<agg::path_storage> path_type; + typedef vs_proxy<agg::path_storage, false> path_type; path_type *p = new path_type(); agg::path_storage& square = p->self(); @@ -45,13 +45,13 @@ build_square() square.line_to(-0.5, 0.5); square.close_polygon(); - return (scalable *) p; + return (vertex_source *) p; } -scalable * +vertex_source * build_triangle() { - typedef vs_proxy<agg::path_storage> path_type; + typedef vs_proxy<agg::path_storage, false> path_type; path_type *p = new path_type(); agg::path_storage& triangle = p->self(); @@ -62,10 +62,10 @@ build_triangle() triangle.line_to( 0.0, 2*ht/3); triangle.close_polygon(); - return (scalable *) p; + return (vertex_source *) p; } -scalable* +vertex_source* new_marker_symbol (const char *req_name) { struct symbol_reg *reg; diff --git a/agg-plot/markers.h b/agg-plot/markers.h index 41fd94c5..d8b6a8bd 100644 --- a/agg-plot/markers.h +++ b/agg-plot/markers.h @@ -3,6 +3,6 @@ #include "scalable.h" -extern scalable* new_marker_symbol(const char *name); +extern vertex_source* new_marker_symbol(const char *name); #endif diff --git a/agg-plot/path.h b/agg-plot/path.h index b48a7b9a..c59518a4 100644 --- a/agg-plot/path.h +++ b/agg-plot/path.h @@ -8,8 +8,8 @@ namespace draw { - typedef vs_proxy<agg::path_storage, true, false> path; - typedef vs_proxy<agg::ellipse, true, true> ellipse; + typedef vs_proxy<agg::path_storage, false> path; + typedef vs_proxy<agg::ellipse, true> ellipse; } #endif diff --git a/agg-plot/scalable.h b/agg-plot/scalable.h index 1fa5c1b9..fae4a31a 100644 --- a/agg-plot/scalable.h +++ b/agg-plot/scalable.h @@ -23,58 +23,70 @@ #include "agg_trans_affine.h" -struct scalable { - +struct vertex_source { virtual void rewind(unsigned path_id) = 0; virtual unsigned vertex(double* x, double* y) = 0; - virtual void apply_transform(const agg::trans_affine& m, double as) = 0; - virtual bool dispose() = 0; + virtual ~vertex_source() { }; +}; +struct scalable : public vertex_source { + virtual bool dispose() = 0; virtual ~scalable() { }; }; -/* This class is basically a wrapper around a native AGG vertex_source object. - The wrapper implements the "scalable" interface. */ -template <class T, bool system_managed = false, bool approx = false> -class vs_proxy : public scalable { +template <class T, bool approx> +class vs_proxy : public vertex_source { protected: T m_base; public: - vs_proxy(): scalable(), m_base() {}; + vs_proxy(): vertex_source(), m_base() {}; virtual void rewind(unsigned path_id) { m_base.rewind(path_id); }; virtual unsigned vertex(double* x, double* y) { return m_base.vertex(x, y); }; - virtual void apply_transform(const agg::trans_affine& m, double as) { }; - virtual bool dispose() { return (system_managed ? false : true); }; T& self() { return m_base; }; }; /* The same as vs_proxy but with approximation_scale. */ -template <class T, bool SM> -class vs_proxy<T, SM, true> : public scalable { +template <class T> +class vs_proxy<T, true> : public vertex_source { protected: T m_base; public: - vs_proxy(): scalable(), m_base() {}; + vs_proxy(): vertex_source(), m_base() {}; virtual void rewind(unsigned path_id) { m_base.rewind(path_id); }; virtual unsigned vertex(double* x, double* y) { return m_base.vertex(x, y); }; - virtual void apply_transform(const agg::trans_affine& m, double as) { this->m_base.approximation_scale(as); }; - virtual bool dispose() { return (SM ? false : true); }; - T& self() { return m_base; }; }; +class boxed_scalable : public scalable { + vertex_source *m_object; + + public: + boxed_scalable(vertex_source *p) : scalable(), m_object(p) {}; + + ~boxed_scalable() { }; + + virtual void rewind(unsigned path_id) { m_object->rewind(path_id); }; + virtual unsigned vertex(double* x, double* y) { return m_object->vertex(x, y); }; + virtual void apply_transform(const agg::trans_affine& m, double as) { m_object->apply_transform(m, as); }; + + virtual bool dispose() { return false; }; + + private: + boxed_scalable(); +}; + /* this class does work does permit to perform an AGG transformation like conv_stroke, conv_dash or any other transform. This adapter is meant to preserve the scalable or the window_drawable interface. */ @@ -112,7 +124,7 @@ public: conv_type& self() { return m_output; }; }; -template<class conv_type, bool approx = false> +template<class conv_type, bool approx> class scalable_adapter : public vs_adapter<conv_type, scalable> { typedef vs_adapter<conv_type, scalable> root_type; diff --git a/agg-plot/text.cpp b/agg-plot/text.cpp index 2fe93702..04d6f137 100644 --- a/agg-plot/text.cpp +++ b/agg-plot/text.cpp @@ -29,17 +29,4 @@ namespace draw { m_stroke.approximation_scale(as); m_text.start_point (-m_hjustif * m_text_width, -m_vjustif * m_text_height); } - - void - text::bounding_box(double *x1, double *y1, double *x2, double *y2) - { - *x1 = *x2 = m_x; - *y1 = *y2 = m_y; - } - - bool - text::dispose() - { - return false; - } } diff --git a/agg-plot/text.h b/agg-plot/text.h index ac594238..e5e5a6ff 100644 --- a/agg-plot/text.h +++ b/agg-plot/text.h @@ -10,7 +10,7 @@ namespace draw { - class text : public drawable { + class text : public vertex_source { typedef agg::gsv_text vs_text; typedef agg::conv_transform<vs_text> vs_trans_text; typedef agg::conv_stroke<vs_trans_text> vs_stroked_text; @@ -90,8 +90,6 @@ namespace draw { virtual unsigned vertex(double* x, double* y); virtual void apply_transform(const agg::trans_affine& m, double as); - virtual void bounding_box(double *x1, double *y1, double *x2, double *y2); - virtual bool dispose(); vs_text& self() { return m_text; }; }; diff --git a/agg-plot/trans.h b/agg-plot/trans.h index 9249cb2a..00bd40c2 100644 --- a/agg-plot/trans.h +++ b/agg-plot/trans.h @@ -88,15 +88,15 @@ struct trans { }; }; - typedef agg::conv_transform<scalable> symbol_type; + typedef agg::conv_transform<vertex_source> symbol_type; typedef my::conv_simple_marker<base_type, symbol_type> marker_base; typedef typename context::template adapter<marker_base, false> vs_marker; class marker : public vs_marker { double m_size; - scalable* m_symbol; + vertex_source* m_symbol; agg::trans_affine m_matrix; - agg::conv_transform<scalable> m_trans; + agg::conv_transform<vertex_source> m_trans; public: marker(base_type* src, double size, const char *sym): @@ -109,7 +109,7 @@ struct trans { ~marker() { - lua_management::dispose(m_symbol); + delete m_symbol; }; virtual void apply_transform(const agg::trans_affine& m, double as) |