gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat
-rw-r--r--agg-plot/window-cpp.h 13
-rw-r--r--agg-plot/window.cpp 40
2 files changed, 43 insertions, 10 deletions
diff --git a/agg-plot/window-cpp.h b/agg-plot/window-cpp.h
index e5d6292e..3f6edf53 100644
--- a/agg-plot/window-cpp.h
+++ b/agg-plot/window-cpp.h
@@ -30,17 +30,26 @@ class window : public canvas_window {
split::node<ref>* m_tree;
void draw_rec(split::node<ref> *n);
+ void cleanup_tree_rec (lua_State *L, int window_index, split::node<ref>* n);
public:
- window(agg::rgba& bgcol) : canvas_window(bgcol), m_tree(0) {};
+ window(agg::rgba& bgcol) : canvas_window(bgcol), m_tree(0)
+ {
+ this->split(".");
+ };
- ~window() { if (m_tree) delete m_tree; };
+ ~window() { delete m_tree; };
static window *check (lua_State *L, int index);
void split(const char *spec);
int attach(lua_plot *plot, const char *spec, int id);
+ void cleanup_refs(lua_State *L, int window_index)
+ {
+ cleanup_tree_rec (L, window_index, m_tree);
+ };
+
void on_draw_unprotected();
virtual void on_draw();
};
diff --git a/agg-plot/window.cpp b/agg-plot/window.cpp
index f5864eca..95b230da 100644
--- a/agg-plot/window.cpp
+++ b/agg-plot/window.cpp
@@ -36,6 +36,8 @@ static const struct luaL_Reg window_methods[] = {
__END_DECLS
+static void remove_plot_ref (lua_State *L, int window_index, int plot_id);
+
void
window::draw_rec(split::node<ref> *n)
{
@@ -63,8 +65,7 @@ window::on_draw_unprotected()
return;
m_canvas->clear();
- if (m_tree)
- draw_rec(m_tree);
+ draw_rec(m_tree);
}
void
@@ -82,8 +83,23 @@ window::check (lua_State *L, int index)
}
void
+window::cleanup_tree_rec (lua_State *L, int window_index, split::node<ref>* n)
+{
+ split::node<ref>::list *ls;
+ for (ls = n->tree(); ls != NULL; ls = ls->next())
+ cleanup_tree_rec(L, window_index, ls->content());
+
+ ref *ref = n->content();
+ if (ref->plot)
+ remove_plot_ref (L, window_index, ref->id);
+}
+
+void
window::split(const char *spec)
{
+ if (m_tree)
+ delete m_tree;
+
split::string_lexer lexbuf(spec);
m_tree = split::parse<ref, split::string_lexer>(lexbuf);
split::node<ref>::init(m_tree);
@@ -143,6 +159,8 @@ int window::attach(lua_plot *plot, const char *spec, int id)
ref new_ref(& plot->self(), id);
n->content(new_ref);
+ /* NB: here ex_ref content will be the same of new_ref */
+
return (ex_id > 0 ? ex_id : 0);
}
@@ -170,10 +188,21 @@ window_split (lua_State *L)
{
window *win = window::check (L, 1);
const char *spec = luaL_checkstring (L, 2);
+ win->cleanup_refs(L, 1);
win->split(spec);
return 0;
}
+void
+remove_plot_ref (lua_State *L, int window_index, int plot_id)
+{
+ object_index_get (L, OBJECT_PLOT, plot_id);
+
+ int plot_index = lua_gettop (L);
+ if (gs_is_userdata (L, plot_index, GS_PLOT))
+ object_ref_remove (L, window_index, plot_index);
+}
+
int
window_attach (lua_State *L)
{
@@ -197,12 +226,7 @@ window_attach (lua_State *L)
object_ref_add (L, 1, 2);
if (ex_plot_id > 0)
- {
- object_index_get (L, OBJECT_PLOT, ex_plot_id);
- int plot_index = lua_gettop (L);
- if (gs_is_userdata (L, plot_index, GS_PLOT))
- object_ref_remove (L, 1, plot_index);
- }
+ remove_plot_ref (L, 1, ex_plot_id);
}
else
{
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月20日 11:41:52 +0000

AltStyle によって変換されたページ (->オリジナル) /