author | Francesco Abbate <francesco.bbt@gmail.com> | 2010年09月07日 23:40:05 +0200 |
---|---|---|
committer | Francesco Abbate <francesco.bbt@gmail.com> | 2010年09月07日 23:40:05 +0200 |
commit | d50cced431bcf32ded6a58a8ffad6e642b7d410b (patch) | |
tree | cb5c33a3bfe359d1b8a78901e3297f56a985cbd8 /agg-plot | |
parent | 8b197f7c910e80c791082e925da4535b780a90be (diff) | |
download | gsl-shell-d50cced431bcf32ded6a58a8ffad6e642b7d410b.tar.gz |
-rw-r--r-- | agg-plot/lua-plot-cpp.h | 14 | ||||
-rw-r--r-- | agg-plot/lua-plot.cpp | 72 | ||||
-rw-r--r-- | agg-plot/plot-auto.h | 121 | ||||
-rw-r--r-- | agg-plot/plot-window.cpp | 317 | ||||
-rw-r--r-- | agg-plot/plot-window.h | 13 | ||||
-rw-r--r-- | agg-plot/plot.h | 179 | ||||
-rw-r--r-- | agg-plot/window.cpp | 2 |
diff --git a/agg-plot/lua-plot-cpp.h b/agg-plot/lua-plot-cpp.h index a3420708..d360decd 100644 --- a/agg-plot/lua-plot-cpp.h +++ b/agg-plot/lua-plot-cpp.h @@ -7,20 +7,10 @@ extern "C" { #include "lua.h" } -#include "plot.h" +#include "plot-auto.h" #include "resource-manager.h" #include "drawable.h" -class lua_plot { -public: - typedef plot<drawable, lua_management> plot_type; - - lua_plot() : m_plot() { }; - - plot_type& self() { return m_plot; }; - -private: - plot_type m_plot; -}; +typedef plot<drawable, lua_management> lua_plot; #endif diff --git a/agg-plot/lua-plot.cpp b/agg-plot/lua-plot.cpp index b053d26d..7a2e654e 100644 --- a/agg-plot/lua-plot.cpp +++ b/agg-plot/lua-plot.cpp @@ -43,6 +43,7 @@ __BEGIN_DECLS static int plot_new (lua_State *L); static int plot_add (lua_State *L); static int plot_update (lua_State *L); +static int plot_flush (lua_State *L); static int plot_add_line (lua_State *L); static int plot_index (lua_State *L); static int plot_newindex (lua_State *L); @@ -53,12 +54,13 @@ static int plot_title_get (lua_State *L); static int plot_units_set (lua_State *L); static int plot_units_get (lua_State *L); +static int canvas_new (lua_State *L); + static int plot_add_gener (lua_State *L, bool as_line); -static void plot_update_raw (lua_State *L, int plot_index); -static void plot_flush (lua_State *L, int plot_index); static const struct luaL_Reg plot_functions[] = { {"plot", plot_new}, + {"canvas", canvas_new}, {NULL, NULL} }; @@ -90,13 +92,29 @@ __END_DECLS int plot_new (lua_State *L) { + typedef plot_auto<drawable, lua_management> plot_type; + lua_plot *p = push_new_object<plot_type>(L, GS_PLOT); + + if (lua_isstring (L, 1)) + { + const char *title = lua_tostring (L, 1); + if (title) + p->set_title(title); + } + + return 1; +} + +int +canvas_new (lua_State *L) +{ lua_plot *p = push_new_object<lua_plot>(L, GS_PLOT); if (lua_isstring (L, 1)) { const char *title = lua_tostring (L, 1); if (title) - p->self().set_title(title); + p->set_title(title); } return 1; @@ -119,11 +137,11 @@ plot_add_gener (lua_State *L, bool as_line) AGG_LOCK(); - p->self().add(obj, color, as_line); + p->add(obj, color, as_line); AGG_UNLOCK(); - plot_flush (L, 1); + plot_flush (L); return 0; } @@ -150,12 +168,10 @@ plot_title_set (lua_State *L) return gs_type_error (L, 2, "string"); AGG_LOCK(); - - p->self().set_title(title); - + p->set_title(title); AGG_UNLOCK(); - plot_update_raw (L, 1); + plot_update (L); return 0; } @@ -167,7 +183,7 @@ plot_title_get (lua_State *L) AGG_LOCK(); - const char *title = p->self().get_title(); + const char *title = p->title(); lua_pushstring (L, title); AGG_UNLOCK(); @@ -183,14 +199,13 @@ plot_units_set (lua_State *L) AGG_LOCK(); - lua_plot::plot_type& plt = p->self(); - bool current = plt.use_units(); + bool current = p->use_units(); if (current != request) { - plt.set_units(request); + p->set_units(request); AGG_UNLOCK(); - plot_update_raw (L, 1); + plot_update (L); } else { @@ -206,10 +221,7 @@ plot_units_get (lua_State *L) lua_plot *p = object_check<lua_plot>(L, 1, GS_PLOT); AGG_LOCK(); - - lua_plot::plot_type& plt = p->self(); - lua_pushboolean (L, plt.use_units()); - + lua_pushboolean (L, p->use_units()); AGG_UNLOCK(); return 1; @@ -227,27 +239,21 @@ plot_newindex (lua_State *L) return mlua_newindex_with_properties (L, plot_properties_set); } -void -plot_update_raw (lua_State *L, int plot_index) -{ - lua_plot *p = object_check<lua_plot>(L, 1, GS_PLOT); - window_plot_rev_lookup_apply (L, plot_index, window_slot_update); - p->self().redraw_done(); -} - -void -plot_flush (lua_State *L, int plot_index) +int +plot_update (lua_State *L) { lua_plot *p = object_check<lua_plot>(L, 1, GS_PLOT); - window_plot_rev_lookup_apply (L, plot_index, window_slot_refresh); - p->self().redraw_done(); + window_plot_rev_lookup_apply (L, 1, window_slot_update); + p->redraw_done(); + return 0; } int -plot_update (lua_State *L) +plot_flush (lua_State *L) { - object_check<lua_plot>(L, 1, GS_PLOT); - plot_update_raw (L, 1); + lua_plot *p = object_check<lua_plot>(L, 1, GS_PLOT); + window_plot_rev_lookup_apply (L, 1, window_slot_refresh); + p->redraw_done(); return 0; } diff --git a/agg-plot/plot-auto.h b/agg-plot/plot-auto.h new file mode 100644 index 00000000..e93216f2 --- /dev/null +++ b/agg-plot/plot-auto.h @@ -0,0 +1,121 @@ + +/* plot-auto.h + * + * Copyright (C) 2009, 2010 Francesco Abbate + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef AGGPLOT_PLOT_AUTO_H +#define AGGPLOT_PLOT_AUTO_H + +#include "plot.h" + +#include "agg_array.h" +#include "agg_basics.h" + +template<class VertexSource, class resource_manager = no_management> +class plot_auto : public plot<VertexSource, resource_manager> { +public: + + plot_auto() : + plot<VertexSource, resource_manager>(true), + m_bbox_updated(true), m_is_empty(true) + { }; + + virtual ~plot_auto() { }; + + virtual void add(VertexSource* vs, agg::rgba8 *color, bool outline); + virtual void on_draw() { check_bounding_box(); }; + +private: + void check_bounding_box(); + void calc_bounding_box(); + bool fit_inside(VertexSource *obj) const; + + // bounding box + bool m_bbox_updated; + bool m_is_empty; +}; + +template <class VS, class RM> +void plot_auto<VS,RM>::add(VS* vs, agg::rgba8 *color, bool outline) +{ + typedef typename plot_auto<VS,RM>::container cnt_type; + cnt_type d(vs, color, outline); + + if (!this->fit_inside(vs)) + { + this->m_bbox_updated = false; + this->m_need_redraw = true; + this->m_elements.add(d); + } + else + { + this->m_drawing_queue = new pod_list<cnt_type>(d, this->m_drawing_queue); + } + + this->m_is_empty = false; + + RM::acquire(vs); +} + +template<class VS, class RM> +void plot_auto<VS,RM>::check_bounding_box() + { + if (this->m_bbox_updated || this->m_is_empty) + return; + + this->calc_bounding_box(); + + const agg::rect_base<double>& bb = this->m_rect; + this->m_ux = units(bb.x1, bb.x2); + this->m_uy = units(bb.y1, bb.y2); + + this->compute_user_trans(); + this->m_bbox_updated = true; + } + +template<class VS, class RM> +void plot_auto<VS,RM>::calc_bounding_box() +{ + for (unsigned j = 0; j < this->m_elements.size(); j++) + { + typename plot_auto<VS,RM>::container& d = this->m_elements[j]; + agg::rect_base<double> r; + + d.vs->bounding_box(&r.x1, &r.y1, &r.x2, &r.y2); + + if (j == 0) + this->m_rect = r; + else + this->m_rect = agg::unite_rectangles(this->m_rect, r); + } +} + +template<class VS, class RM> +bool plot_auto<VS,RM>::fit_inside(VS* obj) const +{ + if (this->m_is_empty || !this->m_bbox_updated) + return false; + + agg::rect_base<double> r; + obj->bounding_box(&r.x1, &r.y1, &r.x2, &r.y2); + + const agg::rect_base<double>& bb = this->m_rect; + return bb.hit_test(r.x1, r.y1) && bb.hit_test(r.x2, r.y2); +} + +#endif diff --git a/agg-plot/plot-window.cpp b/agg-plot/plot-window.cpp deleted file mode 100644 index f9e51555..00000000 --- a/agg-plot/plot-window.cpp +++ /dev/null @@ -1,317 +0,0 @@ - -/* plot-window.cpp - * - * Copyright (C) 2009, 2010 Francesco Abbate - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -extern "C" { -#include "lua.h" -#include "lauxlib.h" -} - -#include "plot-window.h" -#include "canvas-window-cpp.h" -#include "gs-types.h" -#include "lua-utils.h" -#include "object-refs.h" -#include "lua-cpp-utils.h" -#include "lua-draw.h" -#include "colors.h" -#include "plot.h" -#include "drawable.h" -#include "resource-manager.h" -#include "agg-parse-trans.h" - -__BEGIN_DECLS - -static int plot_window_new (lua_State *L); -static int plot_window_add (lua_State *L); -static int plot_window_update (lua_State *L); -static int plot_window_add_line (lua_State *L); -static int plot_window_index (lua_State *L); -static int plot_window_newindex (lua_State *L); -static int plot_window_free (lua_State *L); -static int plot_window_show (lua_State *L); -static int plot_window_title_set (lua_State *L); -static int plot_window_title_get (lua_State *L); -static int plot_window_units_set (lua_State *L); -static int plot_window_units_get (lua_State *L); - -static int plot_window_add_gener (lua_State *L, bool as_line); - -static const struct luaL_Reg plot_window_functions[] = { - {"plot", plot_window_new}, - {NULL, NULL} -}; - -static const struct luaL_Reg plot_window_methods[] = { - {"add", plot_window_add }, - {"addline", plot_window_add_line }, - {"update", plot_window_update }, - {"show", plot_window_show }, - {"__index", plot_window_index }, - {"__newindex", plot_window_newindex }, - {"__gc", plot_window_free }, - {NULL, NULL} -}; - -static const struct luaL_Reg plot_window_properties_get[] = { - {"title", plot_window_title_get }, - {"units", plot_window_units_get }, - {NULL, NULL} -}; - -static const struct luaL_Reg plot_window_properties_set[] = { - {"title", plot_window_title_set }, - {"units", plot_window_units_set }, - {NULL, NULL} -}; - -__END_DECLS - -class plot_window : public canvas_window { -public: - typedef plot<drawable, lua_management> plot_type; - - plot_window(): canvas_window(colors::white), m_plot() {}; - - plot_type& get_plot() { return m_plot; }; - - void on_draw_unprotected(); - virtual void on_draw(); - - virtual void user_transform(agg::trans_affine& m); - - // this method should be used only when AGG is locked - void plot_update() - { - this->lock(); - if (this->status == plot_window::running) - { - this->on_draw_unprotected(); - this->update_window(); - } - this->unlock(); - }; - - static plot_window *check(lua_State *L, int index); - -private: - plot_type m_plot; -}; - -plot_window * -plot_window::check(lua_State *L, int index) -{ - return (plot_window *) gs_check_userdata (L, index, GS_PLOT_WINDOW); -} - -void -plot_window::on_draw_unprotected() -{ - canvas& canvas = *this->m_canvas; - canvas.clear(); - m_plot.draw(canvas); -} - -void -plot_window::on_draw() -{ - AGG_PROTECT(this->on_draw_unprotected()); -} - - -void -plot_window::user_transform(agg::trans_affine& m) -{ - m_plot.user_transform(m); -} - -int -plot_window_new (lua_State *L) -{ - plot_window *p = new(L, GS_PLOT_WINDOW) plot_window(); - - if (lua_isstring (L, 1)) - { - const char *title = lua_tostring (L, 1); - if (title) - { - plot_window::plot_type& plt = p->get_plot(); - plt.set_title(title); - } - } - - return 1; -} - -int -plot_window_free (lua_State *L) -{ - plot_window *p = plot_window::check(L, 1); - p->~plot_window(); - return 0; -} - -int -plot_window_add_gener (lua_State *L, bool as_line) -{ - plot_window *p = plot_window::check(L, 1); - drawable *obj = parse_graph_args (L); - agg::rgba8 *color = check_color_rgba8 (L, 3); - - object_ref_add (L, 1, 2); - - AGG_LOCK(); - - plot_window::plot_type& plt = p->get_plot(); - plt.add(obj, color, as_line); - - if (p->status == plot_window::running) - { - p->plot_update(); - } - - AGG_UNLOCK(); - - return 0; -} - -int -plot_window_add (lua_State *L) -{ - return plot_window_add_gener (L, false); -} - -int -plot_window_add_line (lua_State *L) -{ - return plot_window_add_gener (L, true); -} - -int -plot_window_title_set (lua_State *L) -{ - plot_window *p = plot_window::check(L, 1); - const char *title = lua_tostring (L, 2); - - if (title == NULL) - return gs_type_error (L, 2, "string"); - - AGG_LOCK(); - - plot_window::plot_type& plt = p->get_plot(); - plt.set_title(title); - - p->plot_update(); - - AGG_UNLOCK(); - - return 0; -} - -int -plot_window_title_get (lua_State *L) -{ - plot_window *p = plot_window::check(L, 1); - - AGG_LOCK(); - plot_window::plot_type& plt = p->get_plot(); - const char *title = plt.get_title(); - lua_pushstring (L, title); - AGG_UNLOCK(); - - return 1; -} - -int -plot_window_units_set (lua_State *L) -{ - plot_window *p = plot_window::check(L, 1); - bool request = (bool) lua_toboolean (L, 2); - - AGG_LOCK(); - - plot_window::plot_type& plt = p->get_plot(); - bool current = plt.use_units(); - - if (current != request) - { - plt.set_units(request); - p->plot_update(); - } - - AGG_UNLOCK(); - - return 0; -} - -int -plot_window_units_get (lua_State *L) -{ - plot_window *p = plot_window::check(L, 1); - - AGG_LOCK(); - plot_window::plot_type& plt = p->get_plot(); - lua_pushboolean (L, plt.use_units()); - AGG_UNLOCK(); - - return 1; -} - -int -plot_window_index (lua_State *L) -{ - return mlua_index_with_properties (L, plot_window_properties_get, false); -} - -int -plot_window_newindex (lua_State *L) -{ - return mlua_newindex_with_properties (L, plot_window_properties_set); -} - -int -plot_window_update (lua_State *L) -{ - plot_window *p = plot_window::check(L, 1); - AGG_PROTECT(p->plot_update()); - return 0; -} - -int -plot_window_show (lua_State *L) -{ - plot_window *p = plot_window::check(L, 1); - p->start_new_thread (L); - return 1; -} - -void -plot_window_register (lua_State *L) -{ - /* plot declaration */ - luaL_newmetatable (L, GS_METATABLE(GS_PLOT_WINDOW)); - lua_pushstring (L, "__superindex"); - lua_pushcfunction (L, canvas_window_index); - lua_rawset (L, -3); - luaL_register (L, NULL, plot_window_methods); - lua_pop (L, 1); - - /* gsl module registration */ - luaL_register (L, NULL, plot_window_functions); -} diff --git a/agg-plot/plot-window.h b/agg-plot/plot-window.h deleted file mode 100644 index 5f735efb..00000000 --- a/agg-plot/plot-window.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef PLOT_WINDOW_H -#define PLOT_WINDOW_H - -#include "defs.h" - -__BEGIN_DECLS -#include "lua.h" - -extern void plot_window_register (lua_State *L); - -__END_DECLS - -#endif diff --git a/agg-plot/plot.h b/agg-plot/plot.h index d707252b..71ec1f05 100644 --- a/agg-plot/plot.h +++ b/agg-plot/plot.h @@ -41,19 +41,10 @@ extern agg::rect_base<int> rect_of_slot_matrix (const agg::trans_affine& mtx); -static void -bbox_enlarge(double *x1, double* y1, double* x2, double* y2, - double x, double y) -{ - if (x < *x1) *x1 = x; - if (y < *y1) *y1 = y; - if (x > *x2) *x2 = x; - if (y > *y2) *y2 = y; -} - template<class VertexSource, class resource_manager = no_management> class plot { +protected: class container { public: VertexSource* vs; @@ -77,29 +68,22 @@ class plot { VertexSource& vertex_source() { return *vs; }; }; - void push_drawing_rev(pod_list<container> *c) - { - if (c) - { - push_drawing_rev (c->next()); - m_elements.add(c->content()); - } - } - public: typedef pod_list<container> iterator; - plot() : - m_elements(), m_trans(), m_drawing_queue(0), - m_need_redraw(true), m_bbox_updated(true), m_is_empty(true), - m_title_buf(), m_use_units(true), m_ux(), m_uy() + plot(bool use_units = true) : + m_elements(), m_drawing_queue(0), + m_need_redraw(true), m_rect(), + m_use_units(use_units), m_title_buf() { + compute_user_trans(); + m_title_buf.capacity(32); m_title = m_title_buf.data(); m_title[0] = '0円'; }; - ~plot() + virtual ~plot() { for (unsigned j = 0; j < m_elements.size(); j++) { @@ -109,13 +93,14 @@ public: }; void set_title(const char *text); - const char *get_title() const { return m_title; }; + const char *title() const { return m_title; }; - bool use_units() const { return m_use_units; }; void set_units(bool use_units); + bool use_units() const { return m_use_units; }; - void add(VertexSource* vs, agg::rgba8 *color, bool outline = false); - + virtual void add(VertexSource* vs, agg::rgba8 *color, bool outline); + virtual void on_draw() { }; + void draw(canvas &canvas, agg::trans_affine& m); /* drawing queue related methods */ @@ -130,11 +115,8 @@ public: iterator*& current); iterator* drawing_start() { return m_drawing_queue; }; - - /* transform matrix methods */ - void trans_matrix_update(); -private: +protected: void draw_elements(canvas &canvas, agg::trans_affine& m); void draw_element(container& c, canvas &canvas, agg::trans_affine& m); void draw_title(canvas& canvas, agg::trans_affine& m); @@ -142,35 +124,40 @@ private: agg::trans_affine get_scaled_matrix(agg::trans_affine& canvas_mtx); - void update_viewport_trans(); + void compute_user_trans(); static void viewport_scale(agg::trans_affine& trans); - void calc_bounding_box(); bool fit_inside(VertexSource *obj) const; - agg::pod_bvector<container> m_elements; + void push_drawing_rev(pod_list<container> *c); - /* transformation matrix */ + agg::pod_bvector<container> m_elements; agg::trans_affine m_trans; - pod_list<container> *m_drawing_queue; - // bounding box bool m_need_redraw; - bool m_bbox_updated; - bool m_is_empty; - double m_x1, m_y1; - double m_x2, m_y2; - - agg::pod_vector<char> m_title_buf; - char *m_title; + agg::rect_base<double> m_rect; bool m_use_units; units m_ux, m_uy; + +private: + agg::pod_vector<char> m_title_buf; + char *m_title; }; template <class VS, class RM> +void plot<VS,RM>::push_drawing_rev(pod_list<plot<VS,RM>::container> *c) +{ + if (c) + { + push_drawing_rev (c->next()); + m_elements.add(c->content()); + } +} + +template <class VS, class RM> void plot<VS,RM>::redraw_done() { push_drawing_queue(); @@ -181,20 +168,7 @@ template <class VS, class RM> void plot<VS,RM>::add(VS* vs, agg::rgba8 *color, bool outline) { container d(vs, color, outline); - - if (!this->fit_inside(vs)) - { - m_bbox_updated = false; - m_need_redraw = true; - m_elements.add(d); - } - else - { - m_drawing_queue = new pod_list<container>(d, m_drawing_queue); - } - - m_is_empty = false; - + m_drawing_queue = new pod_list<container>(d, m_drawing_queue); RM::acquire(vs); } @@ -219,7 +193,7 @@ void plot<VS,RM>::push_drawing_queue() template <class VS, class RM> void plot<VS,RM>::draw(canvas &canvas, agg::trans_affine& canvas_mtx) { - trans_matrix_update(); + on_draw(); draw_title(canvas, canvas_mtx); if (m_use_units) draw_axis(canvas, canvas_mtx); @@ -307,94 +281,29 @@ bool plot<VS,RM>::draw_queue(canvas &canvas, agg::trans_affine& canvas_mtx, } template<class VS, class RM> -void plot<VS,RM>::update_viewport_trans() +void plot<VS,RM>::compute_user_trans() { - double xi, yi, xs, ys; + agg::rect_base<double> r; if (m_use_units) { int ixi, ixs, iyi, iys; double xd, yd; m_ux.limits(ixi, ixs, xd); - xi = ixi * xd; - xs = ixs * xd; + r.x1 = ixi * xd; + r.x2 = ixs * xd; m_uy.limits(iyi, iys, yd); - yi = iyi * yd; - ys = iys * yd; + r.y1 = iyi * yd; + r.y2 = iys * yd; } else { - xi = m_x1; - yi = m_y1; - xs = m_x2; - ys = m_y2; - } - - double fx = 1/(xs - xi), fy = 1/(ys - yi); - this->m_trans = agg::trans_affine(fx, 0.0, 0.0, fy, -xi*fx, -yi*fy); -} - -template<class VS, class RM> -void plot<VS,RM>::trans_matrix_update() - { - if (this->m_bbox_updated || this->m_is_empty) - return; - - this->calc_bounding_box(); - - m_ux = units(this->m_x1, this->m_x2); - m_uy = units(this->m_y1, this->m_y2); - - this->update_viewport_trans(); - this->m_bbox_updated = true; - } - -template<class VS, class RM> -void plot<VS,RM>::calc_bounding_box() -{ - bool is_set = false; - - for (unsigned j = 0; j < m_elements.size(); j++) - { - container& d = m_elements[j]; - - double sx1, sy1, sx2, sy2; - d.vs->bounding_box(&sx1, &sy1, &sx2, &sy2); - - if (! is_set) - { - m_x1 = sx1; - m_x2 = sx2; - m_y1 = sy1; - m_y2 = sy2; - - is_set = true; + r = m_rect; } - else - { - bbox_enlarge(&m_x1, &m_y1, &m_x2, &m_y2, sx1, sy1); - bbox_enlarge(&m_x1, &m_y1, &m_x2, &m_y2, sx2, sy2); - } - } -} - -template<class VS, class RM> -bool plot<VS,RM>::fit_inside(VS* obj) const -{ - if (this->m_is_empty || !this->m_bbox_updated) - return false; - double sx1, sy1, sx2, sy2; - obj->bounding_box(&sx1, &sy1, &sx2, &sy2); - - if (sx1 < m_x1 || sx1 > m_x2 || sy1 < m_y1 || sy1 > m_y2) - return false; - - if (sx2 < m_x1 || sx2 > m_x2 || sy2 < m_y1 || sy2 > m_y2) - return false; - - return true; + double fx = 1/(r.x2 - r.x1), fy = 1/(r.y2 - r.y1); + this->m_trans = agg::trans_affine(fx, 0.0, 0.0, fy, -r.x1 * fx, -r.y1 * fy); } template <class VS, class RM> @@ -522,7 +431,7 @@ template<class VS, class RM> void plot<VS,RM>::set_units(bool use_units) { m_use_units = use_units; - this->update_viewport_trans(); + this->compute_user_trans(); } #endif diff --git a/agg-plot/window.cpp b/agg-plot/window.cpp index 0d7f6c8b..fb4c86a5 100644 --- a/agg-plot/window.cpp +++ b/agg-plot/window.cpp @@ -263,7 +263,7 @@ int window::attach(lua_plot *plot, const char *spec) if (! r) return -1; - r->plot = & plot->self(); + r->plot = plot; return r->slot_id; } |