-rw-r--r-- | agg-plot/lua-plot.cpp | 24 | ||||
-rw-r--r-- | agg-plot/plot.h | 20 | ||||
-rw-r--r-- | examples/bspline.lua | 1 | ||||
-rw-r--r-- | examples/nlinfit.lua | 4 | ||||
-rw-r--r-- | examples/vandermonde.lua | 1 |
diff --git a/agg-plot/lua-plot.cpp b/agg-plot/lua-plot.cpp index 826204b6..d953ac50 100644 --- a/agg-plot/lua-plot.cpp +++ b/agg-plot/lua-plot.cpp @@ -63,6 +63,8 @@ static int plot_sync_mode_get (lua_State *L); static int plot_sync_mode_set (lua_State *L); static int plot_pad_mode_get (lua_State *L); static int plot_pad_mode_set (lua_State *L); +static int plot_clip_mode_get (lua_State *L); +static int plot_clip_mode_set (lua_State *L); static int canvas_new (lua_State *L); @@ -101,6 +103,7 @@ static const struct luaL_Reg plot_properties_get[] = { {"units", plot_units_get }, {"sync", plot_sync_mode_get }, {"pad", plot_pad_mode_get }, + {"clip", plot_clip_mode_get }, {NULL, NULL} }; @@ -109,6 +112,7 @@ static const struct luaL_Reg plot_properties_set[] = { {"units", plot_units_set }, {"sync", plot_sync_mode_set }, {"pad", plot_pad_mode_set }, + {"clip", plot_clip_mode_set }, {NULL, NULL} }; @@ -437,6 +441,26 @@ static int plot_pad_mode_get (lua_State *L) return 1; } +static int plot_clip_mode_set (lua_State *L) +{ + lua_plot *p = object_check<lua_plot>(L, 1, GS_PLOT); + bool request = (bool) lua_toboolean (L, 2); + AGG_LOCK(); + p->set_clip_mode(request); + AGG_UNLOCK(); + plot_update_raw (L, p, 1); + return 0; +} + +static int plot_clip_mode_get (lua_State *L) +{ + lua_plot *p = object_check<lua_plot>(L, 1, GS_PLOT); + AGG_LOCK(); + lua_pushboolean (L, p->clip_is_active()); + AGG_UNLOCK(); + return 1; +} + int plot_sync_mode_get (lua_State *L) { diff --git a/agg-plot/plot.h b/agg-plot/plot.h index 6550de74..1ef8bd0e 100644 --- a/agg-plot/plot.h +++ b/agg-plot/plot.h @@ -70,7 +70,7 @@ public: plot(bool use_units = true) : m_root_layer(), m_layers(), m_current_layer(&m_root_layer), - m_drawing_queue(0), + m_drawing_queue(0), m_clip_flag(true), m_need_redraw(true), m_rect(), m_use_units(use_units), m_pad_units(false), m_title_buf(), m_sync_mode(true) @@ -115,6 +115,9 @@ public: void clear_current_layer(); int current_layer_index(); + bool clip_is_active() const { return m_clip_flag; }; + void set_clip_mode(bool flag) { m_clip_flag = flag; }; + bool need_redraw() const { return m_need_redraw; }; void commit_pending_draw(); @@ -162,6 +165,8 @@ protected: agg::trans_affine m_trans; pod_list<item> *m_drawing_queue; + bool m_clip_flag; + bool m_need_redraw; opt_rect<double> m_rect; @@ -306,11 +311,14 @@ agg::trans_affine plot<VS,RM>::get_scaled_matrix(agg::trans_affine& canvas_mtx) template<class VS, class RM> void plot<VS,RM>::clip_plot_area(canvas &canvas, agg::trans_affine& canvas_mtx) { - agg::trans_affine mvp; - viewport_scale(mvp); - trans_affine_compose (mvp, canvas_mtx); - agg::rect_base<int> clip = rect_of_slot_matrix<int>(mvp); - canvas.clip_box(clip); + if (this->clip_is_active()) + { + agg::trans_affine mvp; + viewport_scale(mvp); + trans_affine_compose (mvp, canvas_mtx); + agg::rect_base<int> clip = rect_of_slot_matrix<int>(mvp); + canvas.clip_box(clip); + } } template<class VS, class RM> diff --git a/examples/bspline.lua b/examples/bspline.lua index a24120b2..7df29a11 100644 --- a/examples/bspline.lua +++ b/examples/bspline.lua @@ -29,6 +29,7 @@ function demo1() local p = plot('B-splines curve approximation') p:addline(xyline(x, X * c)) p:addline(xyline(x, y), 'blue', {{'marker', size=5}}) + p.clip = false p:show() return p diff --git a/examples/nlinfit.lua b/examples/nlinfit.lua index 09c32f0f..e746337e 100644 --- a/examples/nlinfit.lua +++ b/examples/nlinfit.lua @@ -47,8 +47,10 @@ function demo1() local p = graph.plot('Non-linear fit example') local pts = graph.ipath(gsl.sequence(function(i) return i, yrf[i] end, 0, n-1)) local fitln = graph.fxline(function(t) return model(s.x, t) end, 0, n-1) - p:addline(pts, 'blue', {{'marker', size=4}}) + p:addline(pts, 'blue', {{'marker', size=5}}) p:addline(fitln) + p.clip = false + p.pad = true p:show() end diff --git a/examples/vandermonde.lua b/examples/vandermonde.lua index 33f03d54..374a5cf5 100644 --- a/examples/vandermonde.lua +++ b/examples/vandermonde.lua @@ -17,6 +17,7 @@ function demo1() p:addline(graph.xyline(x, y), 'blue', {{'marker', size=5}}) p:addline(graph.fxline(|x| poly_eval(us, x), x[0], x[#x-1])) p.title = 'Polynomial interpolation' + p.clip = false p:show() return p end |