author | Francesco Abbate <francesco.bbt@gmail.com> | 2010年09月09日 16:32:50 +0200 |
---|---|---|
committer | Francesco Abbate <francesco.bbt@gmail.com> | 2010年09月09日 16:32:50 +0200 |
commit | ce828e868c0c97521b9d2f8d0f4c49431881378e (patch) | |
tree | 6671b014da423834891e681b9fa202982f9048bb | |
parent | e34ad362e880d7e2e1b6e367b6949eab4cba11d1 (diff) | |
download | gsl-shell-ce828e868c0c97521b9d2f8d0f4c49431881378e.tar.gz |
-rw-r--r-- | agg-plot/lua-plot.cpp | 35 | ||||
-rw-r--r-- | agg-plot/plot.h | 14 |
diff --git a/agg-plot/lua-plot.cpp b/agg-plot/lua-plot.cpp index 7a2e654e..68474f13 100644 --- a/agg-plot/lua-plot.cpp +++ b/agg-plot/lua-plot.cpp @@ -53,10 +53,12 @@ static int plot_title_set (lua_State *L); 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 plot_set_limits (lua_State *L); static int canvas_new (lua_State *L); -static int plot_add_gener (lua_State *L, bool as_line); +static int plot_add_gener (lua_State *L, bool as_line); +static void plot_update_raw (lua_State *L, lua_plot *p, int plot_index); static const struct luaL_Reg plot_functions[] = { {"plot", plot_new}, @@ -69,6 +71,7 @@ static const struct luaL_Reg plot_methods[] = { {"addline", plot_add_line }, {"update", plot_update }, {"show", plot_show }, + {"limits", plot_set_limits }, {"__index", plot_index }, {"__newindex", plot_newindex }, {"__gc", plot_free }, @@ -171,7 +174,7 @@ plot_title_set (lua_State *L) p->set_title(title); AGG_UNLOCK(); - plot_update (L); + plot_update_raw (L, p, 1); return 0; } @@ -205,7 +208,7 @@ plot_units_set (lua_State *L) { p->set_units(request); AGG_UNLOCK(); - plot_update (L); + plot_update_raw (L, p, 1); } else { @@ -239,12 +242,18 @@ plot_newindex (lua_State *L) return mlua_newindex_with_properties (L, plot_properties_set); } +void +plot_update_raw (lua_State *L, lua_plot *p, int plot_index) +{ + window_plot_rev_lookup_apply (L, plot_index, window_slot_update); + p->redraw_done(); +} + int plot_update (lua_State *L) { lua_plot *p = object_check<lua_plot>(L, 1, GS_PLOT); - window_plot_rev_lookup_apply (L, 1, window_slot_update); - p->redraw_done(); + plot_update_raw (L, p, 1); return 0; } @@ -268,6 +277,22 @@ plot_show (lua_State *L) return 0; } +int +plot_set_limits (lua_State *L) +{ + lua_plot *p = object_check<lua_plot>(L, 1, GS_PLOT); + + agg::rect_base<double> r; + r.x1 = gs_check_number (L, 2, true); + r.y1 = gs_check_number (L, 3, true); + r.x2 = gs_check_number (L, 4, true); + r.y2 = gs_check_number (L, 5, true); + + p->set_limits(r); + plot_update_raw (L, p, 1); + return 0; +} + void plot_register (lua_State *L) { diff --git a/agg-plot/plot.h b/agg-plot/plot.h index fcf17752..275b2898 100644 --- a/agg-plot/plot.h +++ b/agg-plot/plot.h @@ -90,6 +90,8 @@ public: void set_units(bool use_units); bool use_units() const { return m_use_units; }; + void set_limits(const agg::rect_base<double>& r); + virtual void add(VertexSource* vs, agg::rgba8 *color, bool outline); virtual void on_draw() { }; @@ -422,7 +424,17 @@ template<class VS, class RM> void plot<VS,RM>::set_units(bool use_units) { m_use_units = use_units; - this->compute_user_trans(); + compute_user_trans(); +} + +template<class VS, class RM> +void plot<VS,RM>::set_limits(const agg::rect_base<double>& r) +{ + m_rect = r; + m_ux = units(r.x1, r.x2); + m_uy = units(r.y1, r.y2); + m_need_redraw = true; + compute_user_trans(); } #endif |