Code rationalization in native plot window - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2012年11月05日 16:17:42 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2012年11月05日 16:17:42 +0100
commit6c3c3823077f90a3bf870fa75fc0818d9f31f3d3 (patch)
tree7b1cb72a430fa6b59c0690ec61e1068e1e1e57b1
parent96439321439d5919d58a3627a06460b3a2c31c4a (diff)
downloadgsl-shell-6c3c3823077f90a3bf870fa75fc0818d9f31f3d3.tar.gz
Code rationalization in native plot window
Use a template member function to visit all the plot and apply a given function.
Diffstat
-rw-r--r--agg-plot/window-cpp.h 28
-rw-r--r--agg-plot/window.cpp 58
-rw-r--r--cpp-utils/tree.h 16
3 files changed, 37 insertions, 65 deletions
diff --git a/agg-plot/window-cpp.h b/agg-plot/window-cpp.h
index 564a4160..32d294c4 100644
--- a/agg-plot/window-cpp.h
+++ b/agg-plot/window-cpp.h
@@ -45,6 +45,16 @@ public:
if (layer_buf) delete layer_buf;
};
+ void dispose_buffer()
+ {
+ valid_rect = false;
+ if (layer_buf)
+ {
+ delete [] layer_buf;
+ layer_buf = 0;
+ }
+ }
+
void save_image (agg::rendering_buffer& winbuf, agg::rect_base<int>& r,
int bpp, bool flip_y);
@@ -55,7 +65,6 @@ public:
private:
void draw_slot_by_ref(ref& ref, bool dirty);
void refresh_slot_by_ref(ref& ref, bool draw_all);
- void draw_rec(ref::node *n);
void cleanup_tree_rec (lua_State *L, int window_index, ref::node* n);
static ref *ref_lookup (ref::node *p, int slot_id);
@@ -87,13 +96,20 @@ public:
void save_slot_image(int slot_id);
void restore_slot_image(int slot_id);
- void cleanup_refs(lua_State *L, int window_index)
- {
- cleanup_tree_rec (L, window_index, m_tree);
- };
-
void draw_slot(int slot_id);
virtual void on_draw();
virtual void on_resize(int sx, int sy);
+
+private:
+ struct slot_draw_function
+ {
+ slot_draw_function(window* w): win(w) { }
+ void call(window::ref* ref) { win->draw_slot_by_ref(*ref, false); }
+ window* win;
+ };
+
+ struct dispose_buffer_function {
+ void call(window::ref* ref) { ref->dispose_buffer(); }
+ };
};
diff --git a/agg-plot/window.cpp b/agg-plot/window.cpp
index 78f43dfb..3868de85 100644
--- a/agg-plot/window.cpp
+++ b/agg-plot/window.cpp
@@ -42,18 +42,6 @@ static const struct luaL_Reg window_methods[] = {
__END_DECLS
-struct dispose_buffer {
- static void func (window::ref& ref)
- {
- ref.valid_rect = false;
- if (ref.layer_buf)
- {
- delete [] ref.layer_buf;
- ref.layer_buf = 0;
- }
- }
-};
-
void window::ref::compose(bmatrix& a, const bmatrix& b)
{
trans_affine_compose (a, b);
@@ -118,20 +106,6 @@ window::ref::save_image (agg::rendering_buffer& win_buf,
}
}
-void
-window::draw_rec(ref::node *n)
-{
- list<ref::node*> *ls;
- for (ls = n->tree(); ls != NULL; ls = ls->next())
- draw_rec(ls->content());
-
- ref *ref = n->content();
- if (ref)
- {
- draw_slot_by_ref (*ref, false);
- }
-}
-
window::ref* window::ref_lookup (ref::node *p, int slot_id)
{
list<ref::node*> *t = p->tree();
@@ -182,7 +156,7 @@ window::draw_slot(int slot_id, bool clean_req)
if (redraw)
{
draw_slot_by_ref(*ref, false);
- dispose_buffer::func(*ref);
+ ref->dispose_buffer();
}
refresh_slot_by_ref(*ref, redraw);
@@ -262,7 +236,10 @@ void
window::on_draw()
{
if (m_canvas)
- draw_rec(m_tree);
+ {
+ slot_draw_function draw_func(this);
+ this->plot_apply(draw_func);
+ }
}
void
@@ -271,23 +248,17 @@ window::on_resize(int sx, int sy)
this->canvas_window::on_resize(sx, sy);
if (m_tree)
{
- tree::walk_rec<window::ref, direction_e, dispose_buffer>(m_tree);
+ dispose_buffer_function dispose;
+ this->plot_apply(dispose);
}
}
-void
-window::cleanup_tree_rec (lua_State *L, int window_index, ref::node* n)
-{
- for (list<ref::node*> *ls = n->tree(); ls != NULL; ls = ls->next())
- cleanup_tree_rec(L, window_index, ls->content());
-
- ref *ref = n->content();
- if (ref)
- {
- if (ref->plot)
- window_refs_remove (L, ref->slot_id, window_index);
- }
-}
+struct refs_remove_function {
+ refs_remove_function(lua_State *_L, int k): L(_L), window_index(k) {}
+ void call(window::ref* ref) { if (ref->plot) window_refs_remove(L, ref->slot_id, window_index); }
+ lua_State* L;
+ int window_index;
+};
bool
window::split(const char *spec)
@@ -497,7 +468,8 @@ window_split (lua_State *L)
win->lock();
- win->cleanup_refs(L, 1);
+ refs_remove_function refs_remove_func(L, 1);
+ win->plot_apply(refs_remove_func);
if (! win->split(spec))
{
diff --git a/cpp-utils/tree.h b/cpp-utils/tree.h
index 4d546615..870013aa 100644
--- a/cpp-utils/tree.h
+++ b/cpp-utils/tree.h
@@ -69,22 +69,6 @@ namespace tree {
m_head = node_list::push_back(m_head, t);
}
};
-
- template <class base_type, class tree_data_type, class f>
- void walk_rec(node<base_type, tree_data_type> *t)
- {
- base_type *c = t->content();
- if (c)
- f::func(*c);
-
- typedef node<base_type, tree_data_type> node_type;
- list<node_type*>* ls = t->tree();
- if (ls)
- {
- for ( ; ls; ls = ls->next())
- walk_rec<base_type, tree_data_type, f> (ls->content());
- }
- }
}
#endif
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月20日 22:50:43 +0000

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