-rw-r--r-- | agg-plot/drawable.h | 4 | ||||
-rw-r--r-- | agg-plot/path.h | 17 | ||||
-rw-r--r-- | agg-plot/scalable.h | 20 | ||||
-rw-r--r-- | agg-plot/text.cpp | 2 | ||||
-rw-r--r-- | agg-plot/text.h | 13 | ||||
-rw-r--r-- | agg-plot/trans.h | 22 | ||||
-rw-r--r-- | agg-plot/utils.cpp | 4 | ||||
-rw-r--r-- | agg-plot/wtest.cpp | 26 |
diff --git a/agg-plot/drawable.h b/agg-plot/drawable.h index 01c5e107..a8b4abb9 100644 --- a/agg-plot/drawable.h +++ b/agg-plot/drawable.h @@ -30,7 +30,9 @@ public: virtual ~drawable() { }; }; -// implementation of a window_object type object based on a "scalable" +/* 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. */ class window_scalable : public drawable { static agg::trans_affine dummy_matrix; diff --git a/agg-plot/path.h b/agg-plot/path.h index ce8d92ce..28b3c151 100644 --- a/agg-plot/path.h +++ b/agg-plot/path.h @@ -7,23 +7,8 @@ namespace draw { - template <class T, bool system_managed> - class vs_proxy : public scalable { - T m_base; - - public: - vs_proxy(): scalable(), 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 approximation_scale(double as) { }; - virtual bool dispose() { return (system_managed ? false : true); }; - - T& get_base() { return m_base; }; - }; - typedef vs_proxy<agg::path_storage, true> path; + } #endif diff --git a/agg-plot/scalable.h b/agg-plot/scalable.h index 154a8338..30ee655d 100644 --- a/agg-plot/scalable.h +++ b/agg-plot/scalable.h @@ -28,9 +28,27 @@ public: virtual ~scalable() { }; }; +/* This class is basically a wrapper around a native AGG vertex_source object + that implements the "scalable" interface. */ +template <class T, bool system_managed> +class vs_proxy : public scalable { + T m_base; + +public: + vs_proxy(): scalable(), 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 approximation_scale(double as) { }; + virtual bool dispose() { return (system_managed ? false : true); }; + + T& get_base() { return m_base; }; +}; + /* this class does work does permit to perform an AGG transformation like conv_stroke, conv_dash or any other transform. This adapter - is mean to preserve the scalable or the window_drawable interface. */ + is meant to preserve the scalable or the window_drawable interface. */ template<class conv_type, class base_type> class vs_adapter : public base_type { protected: diff --git a/agg-plot/text.cpp b/agg-plot/text.cpp index 36e5c332..70c8ab6b 100644 --- a/agg-plot/text.cpp +++ b/agg-plot/text.cpp @@ -16,7 +16,7 @@ namespace draw { } void - text::apply_transform(agg::trans_affine& m) + text::apply_transform(const agg::trans_affine& m) { double& x = m_matrix.tx; double& y = m_matrix.ty; diff --git a/agg-plot/text.h b/agg-plot/text.h index 7a2a8f21..5e3949ee 100644 --- a/agg-plot/text.h +++ b/agg-plot/text.h @@ -1,5 +1,5 @@ -#ifndef AGGPLOT_DRAWABLES_H -#define AGGPLOT_DRAWABLES_H +#ifndef AGGPLOT_TEXT_H +#define AGGPLOT_TEXT_H #include "drawable.h" @@ -10,7 +10,7 @@ namespace draw { - class text : public window_drawable { + class text : public drawable { 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; @@ -40,15 +40,14 @@ namespace draw { m_matrix.sy = c; }; - void set_text(const char *s) { m_text.text(s); }; - void start_point(double x, double y) { m_text.start_point (x, y); }; - virtual void rewind(unsigned path_id); virtual unsigned vertex(double* x, double* y); - virtual void apply_transform(agg::trans_affine& m); + virtual void apply_transform(const agg::trans_affine& m); 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 db64c9d5..069d9489 100644 --- a/agg-plot/trans.h +++ b/agg-plot/trans.h @@ -2,10 +2,13 @@ #define AGGPLOT_TRANS_H #include "scalable.h" +#include "utils.h" #include "agg_conv_stroke.h" #include "agg_conv_curve.h" #include "agg_conv_dash.h" +#include "agg_trans_affine.h" +#include "agg_conv_transform.h" #include "my_conv_simple_marker.h" #include "agg_ellipse.h" @@ -50,6 +53,7 @@ public: }; }; +typedef scalable_adapter<agg::conv_transform<scalable> > vs_affine; namespace trans { @@ -59,6 +63,24 @@ namespace trans { typedef my::conv_simple_marker<scalable, agg::ellipse> conv_ellipse; typedef scalable_adapter<conv_ellipse> marker; + + 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); + }; + }; + } #if 0 diff --git a/agg-plot/utils.cpp b/agg-plot/utils.cpp index 139772e6..145c27e1 100644 --- a/agg-plot/utils.cpp +++ b/agg-plot/utils.cpp @@ -21,7 +21,9 @@ trans_affine_compose (agg::trans_affine& a, const agg::trans_affine& b) double trans_affine_max_norm (const agg::trans_affine& m) { - return max(m.sx, m.sy); + double c1 = sqrt(m.sx*m.sx + m.shx*m.shx); + double c2 = sqrt(m.shy*m.shy + m.sy*m.sy); + return max(c1, c2); } void bbox_enlarge(double *x1, double* y1, double* x2, double* y2, diff --git a/agg-plot/wtest.cpp b/agg-plot/wtest.cpp index f527ae8c..7b8e75df 100644 --- a/agg-plot/wtest.cpp +++ b/agg-plot/wtest.cpp @@ -2,6 +2,7 @@ #include "trans.h" #include "window-trans.h" #include "path.h" +#include "text.h" int main() @@ -10,16 +11,20 @@ main() agg::path_storage& pc = p->get_base(); pc.move_to(0.0, 0.0); - pc.line_to(1.0, 0.0); - pc.line_to(1.0, 1.0); - pc.line_to(0.0, 1.0); + pc.line_to(20.0, 0.0); + pc.line_to(20.0, 20.0); + pc.line_to(0.0, 20.0); pc.close_polygon(); trans::stroke *s1 = new trans::stroke(p); - s1->self().width(10.0); + s1->self().width(4.0); s1->self().line_cap(agg::round_cap); - window_scalable *ws1 = new window_scalable(s1); + double c = 0.707, s= 0.707; + agg::trans_affine rmat(c, s, -s, c, 0.0, 0.0); + trans::affine *rs1 = new trans::affine(s1, rmat); + + window_scalable *ws1 = new window_scalable(rs1); window::stroke *s2 = new window::stroke(ws1); s2->self().width(1.0); @@ -31,9 +36,20 @@ main() agg::trans_affine mtx(200.0, 0.0, 0.0, 100.0, 0.0, 0.0); s2->apply_transform(mtx); + draw::text *txt = new draw::text(12.0); + txt->self().text("Hello world!"); + txt->self().start_point(4.0, 5.0); + + window::dash *d2 = new window::dash(txt); + d2->self().add_dash(2.0, 2.0); + if (s2->dispose()) delete s2; + if (d2->dispose()) + delete d2; + + delete txt; delete p; return 0; |