author | Francesco Abbate <francesco.bbt@gmail.com> | 2012年04月20日 17:01:49 +0200 |
---|---|---|
committer | Francesco Abbate <francesco.bbt@gmail.com> | 2012年04月20日 17:01:49 +0200 |
commit | ae75456d5b2d098d2da97aa79d0c91667095543c (patch) | |
tree | ad0d325b31794d69cbbc0413cf98a6305b3b9eb2 | |
parent | 10cfdf7af613c1355135b00d930657453ade4ce4 (diff) | |
download | gsl-shell-ae75456d5b2d098d2da97aa79d0c91667095543c.tar.gz |
-rw-r--r-- | agg-plot/lua-draw.cpp | 5 | ||||
-rw-r--r-- | agg-plot/lua-draw.h | 14 | ||||
-rw-r--r-- | agg-plot/lua-graph.cpp | 4 | ||||
-rw-r--r-- | agg-plot/lua-plot.cpp | 1 | ||||
-rw-r--r-- | agg-plot/window.cpp | 1 | ||||
-rw-r--r-- | fox-gui/fx_plot_canvas.cpp | 29 | ||||
-rw-r--r-- | fox-gui/fx_plot_canvas.h | 5 | ||||
-rw-r--r-- | fox-gui/lua_plot_window.cpp | 24 | ||||
-rw-r--r-- | lua-graph.h | 7 |
diff --git a/agg-plot/lua-draw.cpp b/agg-plot/lua-draw.cpp index ad2cd4c6..3bb53ac8 100644 --- a/agg-plot/lua-draw.cpp +++ b/agg-plot/lua-draw.cpp @@ -26,6 +26,7 @@ extern "C" { } #include "lua-draw.h" +#include "lua-graph.h" #include "text-shape.h" #include "lua-cpp-utils.h" #include "gs-types.h" @@ -33,8 +34,6 @@ extern "C" { #include "colors.h" #include "sg_marker.h" -pthread_mutex_t agg_mutex[1]; - enum path_cmd_e { CMD_ERROR = -1, CMD_MOVE_TO = 0, @@ -312,8 +311,6 @@ marker_free (lua_State *L) void draw_register (lua_State *L) { - pthread_mutex_init (agg_mutex, NULL); - luaL_newmetatable (L, GS_METATABLE(GS_DRAW_PATH)); luaL_register (L, NULL, agg_path_methods); lua_pop (L, 1); diff --git a/agg-plot/lua-draw.h b/agg-plot/lua-draw.h index aa6ca2b7..a858b73c 100644 --- a/agg-plot/lua-draw.h +++ b/agg-plot/lua-draw.h @@ -1,11 +1,8 @@ #ifndef LUA_DRAW_H #define LUA_DRAW_H - #include "defs.h" -#include <pthread.h> - __BEGIN_DECLS #include "lua.h" __END_DECLS @@ -26,17 +23,6 @@ extern draw::path* check_agg_path (lua_State *L, int index); __BEGIN_DECLS -extern pthread_mutex_t agg_mutex[1]; - -#define AGG_LOCK() pthread_mutex_lock (agg_mutex); -#define AGG_UNLOCK() pthread_mutex_unlock (agg_mutex); - -#define AGG_PROTECT(op) { \ - pthread_mutex_lock (agg_mutex); \ - op; \ - pthread_mutex_unlock (agg_mutex); \ - } - extern void draw_register (lua_State *L); __END_DECLS diff --git a/agg-plot/lua-graph.cpp b/agg-plot/lua-graph.cpp index 609c9722..4be70d35 100644 --- a/agg-plot/lua-graph.cpp +++ b/agg-plot/lua-graph.cpp @@ -37,6 +37,8 @@ extern "C" { static const struct luaL_Reg methods_dummy[] = {{NULL, NULL}}; +pthread_mutex_t agg_mutex[1]; + void graph_close_windows (lua_State *L) { @@ -46,6 +48,8 @@ graph_close_windows (lua_State *L) void register_graph (lua_State *L) { + pthread_mutex_init (agg_mutex, NULL); + window_registry_prepare (L); luaL_register (L, MLUA_GRAPHLIBNAME, methods_dummy); diff --git a/agg-plot/lua-plot.cpp b/agg-plot/lua-plot.cpp index 8ba21bbc..6af30eab 100644 --- a/agg-plot/lua-plot.cpp +++ b/agg-plot/lua-plot.cpp @@ -25,6 +25,7 @@ extern "C" { #include "lua-plot.h" #include "lua-plot-cpp.h" +#include "lua-graph.h" #include "lua-cpp-utils.h" #include "bitmap-plot.h" #include "window.h" diff --git a/agg-plot/window.cpp b/agg-plot/window.cpp index f48a725c..100aebf3 100644 --- a/agg-plot/window.cpp +++ b/agg-plot/window.cpp @@ -8,6 +8,7 @@ extern "C" { #include "window-cpp.h" #include "window_registry.h" #include "lua-draw.h" +#include "lua-graph.h" #include "lua-cpp-utils.h" #include "gs-types.h" #include "colors.h" diff --git a/fox-gui/fx_plot_canvas.cpp b/fox-gui/fx_plot_canvas.cpp index a6a0c90f..e2c17dec 100644 --- a/fox-gui/fx_plot_canvas.cpp +++ b/fox-gui/fx_plot_canvas.cpp @@ -1,4 +1,5 @@ #include "fx_plot_canvas.h" +#include "fatal.h" FXDEFMAP(fx_plot_canvas) fx_plot_canvas_map[]={ FXMAPFUNC(SEL_PAINT, 0, fx_plot_canvas::on_cmd_paint), @@ -70,30 +71,31 @@ void fx_plot_canvas::draw(FXEvent* event) m_dirty_flag = false; } -void fx_plot_canvas::update_region(const FXRectangle& r) +void fx_plot_canvas::update_region(const agg::rect_base<short>& r) { if (!m_canvas || !m_plot) return; - FXImage img(getApp(), NULL, IMAGE_OWNED|IMAGE_SHMI|IMAGE_SHMP, r.w, r.h); + FXshort ww = r.x2 - r.x1, hh= r.y2 - r.y1; + FXImage img(getApp(), NULL, IMAGE_OWNED|IMAGE_SHMI|IMAGE_SHMP, ww, hh); const unsigned bpp = 32; const unsigned pixel_size = bpp / 8; agg::rendering_buffer dest; - dest.attach((agg::int8u*) img.getData(), r.w, r.h, -r.w * pixel_size); + dest.attach((agg::int8u*) img.getData(), ww, hh, -ww * pixel_size); - agg::int8u* dd = m_rbuf.row_ptr(r.y) + r.x * pixel_size; + agg::int8u* dd = m_rbuf.row_ptr(r.y1) + r.x1 * pixel_size; // m_img_data + (m_img_width * (m_img_height - r.y - 1) + r.x) * pixel_size; agg::rendering_buffer src; - src.attach(dd, r.w, r.h, m_rbuf.stride()); + src.attach(dd, ww, hh, m_rbuf.stride()); dest.copy_from(src); img.create(); FXDCWindow dc(this); - dc.drawImage(&img, r.x, r.y); + dc.drawImage(&img, r.x1, getHeight() - r.y2); } void fx_plot_canvas::attach(plot_type* p) @@ -102,6 +104,21 @@ void fx_plot_canvas::attach(plot_type* p) m_dirty_flag = true; } +opt_rect<double> fx_plot_canvas::incremental_draw() +{ + if (!m_plot) fatal_exception("Incremental draw on NULL plot"); + + int ww = getWidth(), hh = getHeight(); + opt_rect<double> r, draw_rect; + + agg::trans_affine m(double(ww), 0.0, 0.0, double(hh), 0.0, 0.0); + m_plot->draw_queue(*m_canvas, m, draw_rect); + r.add<rect_union>(draw_rect); + r.add<rect_union>(m_dirty_rect); + m_dirty_rect = draw_rect; + + return r; +} long fx_plot_canvas::on_cmd_paint(FXObject *, FXSelector, void *ptr) { diff --git a/fox-gui/fx_plot_canvas.h b/fox-gui/fx_plot_canvas.h index fcbd787a..7f25c374 100644 --- a/fox-gui/fx_plot_canvas.h +++ b/fox-gui/fx_plot_canvas.h @@ -7,6 +7,7 @@ #include "sg_object.h" #include "plot-auto.h" #include "canvas.h" +#include "rect.h" class fx_plot_canvas : public FXCanvas { FXDECLARE(fx_plot_canvas) @@ -22,7 +23,8 @@ public: void attach(plot_type* p); void draw(FXEvent* event); - void update_region(const FXRectangle& r); + opt_rect<double> incremental_draw(); + void update_region(const agg::rect_base<short>& r); long on_cmd_paint(FXObject *, FXSelector, void *); long on_update(FXObject *, FXSelector, void *); @@ -40,6 +42,7 @@ private: plot_type* m_plot; canvas* m_canvas; bool m_dirty_flag; + opt_rect<double> m_dirty_rect; }; #endif diff --git a/fox-gui/lua_plot_window.cpp b/fox-gui/lua_plot_window.cpp index 50c2ac85..c2541af4 100644 --- a/fox-gui/lua_plot_window.cpp +++ b/fox-gui/lua_plot_window.cpp @@ -9,6 +9,7 @@ extern "C" { #include "window_registry.h" #include "fx_plot_window.h" #include "lua-cpp-utils.h" +#include "lua-graph.h" #include "gs-types.h" #include "plot.h" @@ -18,6 +19,7 @@ static int fox_window_new (lua_State *L); static int fox_window_free (lua_State *L); static int fox_window_close (lua_State *L); static int fox_window_attach (lua_State *L); +static int fox_window_slot_refresh (lua_State *L); static const struct luaL_Reg fox_window_functions[] = { {"window", fox_window_new}, @@ -27,6 +29,7 @@ static const struct luaL_Reg fox_window_functions[] = { static const struct luaL_Reg fox_window_methods[] = { {"attach", fox_window_attach }, {"close", fox_window_close }, + {"refresh", fox_window_slot_refresh }, {"__gc", fox_window_free }, {NULL, NULL} }; @@ -79,6 +82,27 @@ fox_window_close (lua_State *L) } int +fox_window_slot_refresh (lua_State *L) +{ + fx_plot_window *win = object_check<fx_plot_window>(L, 1, GS_FOX_WINDOW); + fx_plot_canvas& canvas = win->canvas(); + + AGG_LOCK(); + opt_rect<double> rect = canvas.incremental_draw(); + AGG_UNLOCK(); + + if (rect.is_defined()) + { + const int m = 4; + const agg::rect_base<double>& r = rect.rect(); + const agg::rect_base<short> ri(r.x1 - m, r.y1 - m, r.x2 + m, r.y2 + m); + canvas.update_region(ri); + } + + return 0; +} + +int fox_window_register (lua_State *L) { luaL_newmetatable (L, GS_METATABLE(GS_FOX_WINDOW)); diff --git a/lua-graph.h b/lua-graph.h index e7bb621f..6a98fbee 100644 --- a/lua-graph.h +++ b/lua-graph.h @@ -1,6 +1,8 @@ #ifndef LUA_GRAPH_H #define LUA_GRAPH_H +#include <pthread.h> + #include "defs.h" __BEGIN_DECLS @@ -11,6 +13,11 @@ extern void graph_close_windows (lua_State *L); extern void register_graph (lua_State *L); extern void gsl_shell_close_with_graph (struct gsl_shell_state* gs); +extern pthread_mutex_t agg_mutex[1]; + +#define AGG_LOCK() pthread_mutex_lock (agg_mutex); +#define AGG_UNLOCK() pthread_mutex_unlock (agg_mutex); + __END_DECLS #endif |