gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/agg-plot/window.cpp
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2010年08月19日 00:19:58 +0200
committerFrancesco Abbate <francesco.bbt@gmail.com>2010年08月19日 00:19:58 +0200
commitbef124c9c9e081062a457f6d0b2ab1eda6283a3e (patch)
tree5a757e1c2a84900feb642a9790dad5d61f870509 /agg-plot/window.cpp
parent7cdb95a74e7f352620cd500940b73bf221f9e91a (diff)
downloadgsl-shell-bef124c9c9e081062a457f6d0b2ab1eda6283a3e.tar.gz
improved window slot identification vs plot
The code to generate a tree, to parse a split spec and to store window plot tree information is now factored. Now each plot area get a slot_id and redraw is made only in the region when required.
Diffstat (limited to 'agg-plot/window.cpp')
-rw-r--r--agg-plot/window.cpp 149
1 files changed, 126 insertions, 23 deletions
diff --git a/agg-plot/window.cpp b/agg-plot/window.cpp
index 7ed70e61..27d787cb 100644
--- a/agg-plot/window.cpp
+++ b/agg-plot/window.cpp
@@ -12,7 +12,7 @@ extern "C" {
#include "object-index.h"
#include "colors.h"
#include "lua-plot-cpp.h"
-#include "split-spec-parser.h"
+#include "split-parser.h"
__BEGIN_DECLS
@@ -36,28 +36,112 @@ static const struct luaL_Reg window_methods[] = {
__END_DECLS
+void window::ref::compose(bmatrix& a, const bmatrix& b)
+{
+ trans_affine_compose (a, b);
+};
+
+int window::ref::calculate(window::ref::node* t, const bmatrix& m, int id)
+{
+ ref *r = t->content();
+ if (r)
+ {
+ r->slot_id = id++;
+ r->matrix = m;
+ }
+
+ int nb = list::length(t->tree());
+
+ if (nb > 0)
+ {
+ double frac = 1 / (double) nb;
+
+ direction_e dir;
+ ref::node::list *ls = t->tree(dir);
+ if (ls)
+ {
+ bmatrix lm;
+
+ double* p = (dir == along_x ? &lm.tx : &lm.ty);
+ double* s = (dir == along_x ? &lm.sx : &lm.sy);
+
+ *s = frac;
+
+ for ( ; ls; ls = ls->next(), *p += frac)
+ {
+ bmatrix sm(lm);
+ window::ref::compose(sm, m);
+ id = window::ref::calculate (ls->content(), sm, id);
+ }
+ }
+ }
+
+ return id;
+}
+
static void remove_plot_ref (lua_State *L, int window_index, int plot_id);
void
-window::draw_rec(split::node<ref> *n)
+window::clear_box(const bmatrix& m)
+{
+ int x1 = (int) m.tx, y1 = (int) m.ty;
+ int x2 = (int) (m.tx + m.sx), y2 = (int) (m.ty + m.sy);
+ m_canvas->clear_box(x1, y1, x2 - x1, y2 - y1);
+}
+
+void
+window::draw_rec(ref::node *n)
{
- split::node<ref>::list *ls;
+ ref::node::list *ls;
for (ls = n->tree(); ls != NULL; ls = ls->next())
draw_rec(ls->content());
ref *ref = n->content();
- matrix* m = n->get_matrix();
- if (ref && m)
+ if (ref)
{
if (ref->plot)
{
- agg::trans_affine mtx(*m);
+ agg::trans_affine mtx(ref->matrix);
this->scale(mtx);
ref->plot->draw(*m_canvas, mtx);
}
}
}
+window::ref* window::ref_lookup (ref::node *p, int slot_id)
+{
+ ref::node::list *t = p->tree();
+ for (/* */; t; t = t->next())
+ {
+ ref *ref = window::ref_lookup(t->content(), slot_id);
+ if (ref)
+ return ref;
+ }
+
+ ref *ref = p->content();
+ if (ref)
+ {
+ if (ref->slot_id == slot_id)
+ return ref;
+ }
+
+ return NULL;
+}
+
+
+void
+window::draw_slot(int slot_id)
+{
+ ref *ref = window::ref_lookup (this->m_tree, slot_id);
+ if (ref && m_canvas)
+ {
+ agg::trans_affine mtx(ref->matrix);
+ this->scale(mtx);
+ this->clear_box(mtx);
+ ref->plot->draw(*m_canvas, mtx);
+ }
+}
+
void
window::on_draw_unprotected()
{
@@ -83,17 +167,16 @@ window::check (lua_State *L, int index)
}
void
-window::cleanup_tree_rec (lua_State *L, int window_index, split::node<ref>* n)
+window::cleanup_tree_rec (lua_State *L, int window_index, ref::node* n)
{
- split::node<ref>::list *ls;
- for (ls = n->tree(); ls != NULL; ls = ls->next())
+ for (ref::node::list *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)
- remove_plot_ref (L, window_index, ref->id);
+ remove_plot_ref (L, window_index, ref->plot_id);
}
}
@@ -102,9 +185,12 @@ 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);
+
+ ::split<ref>::lexer lexbuf(spec);
+ m_tree = ::split<ref>::parse(lexbuf);
+
+ bmatrix m0;
+ ref::calculate(m_tree, m0, 0);
}
static const char *
@@ -130,15 +216,15 @@ next_int (const char *str, int& val)
/* Returns the existing plot ref id, 0 if there isn't any.
It does return -1 in case of error.*/
-int window::attach(lua_plot *plot, const char *spec, int id)
+int window::attach(lua_plot *plot, const char *spec, int plot_id, int& slot_id)
{
- split::node<ref> *n = m_tree;
+ ref::node *n = m_tree;
const char *ptr;
int k;
for (ptr = next_int (spec, k); ptr; ptr = next_int (ptr, k))
{
- split::node<ref>::list* list = n->tree();
+ ref::node::list* list = n->tree();
if (! list)
return -1;
@@ -153,15 +239,16 @@ int window::attach(lua_plot *plot, const char *spec, int id)
n = list->content();
}
- ref* ex_ref = n->content();
- if (! ex_ref)
+ ref* r = n->content();
+ if (! r)
return -1;
- int ex_id = ex_ref->id;
- ref new_ref(& plot->self(), id);
- n->content(new_ref);
+ int ex_id = r->plot_id;
- /* NB: here ex_ref content will be the same of new_ref */
+ r->plot = & plot->self();
+ r->plot_id = plot_id;
+
+ slot_id = r->slot_id;
return (ex_id > 0 ? ex_id : 0);
}
@@ -217,14 +304,16 @@ window_attach (lua_State *L)
window *win = window::check (L, 1);
lua_plot *plot = lua_plot::check (L, 2);
const char *spec = luaL_checkstring (L, 3);
+ int slot_id;
win->lock();
- int ex_plot_id = win->attach (plot, spec, plot->id);
+ int ex_plot_id = win->attach (plot, spec, plot->id, slot_id);
if (ex_plot_id >= 0)
{
plot->window_id = win->id;
+ plot->slot_id = slot_id;
win->on_draw();
win->update_window();
@@ -246,6 +335,20 @@ window_attach (lua_State *L)
}
int
+window_slot_update_unprotected (lua_State *L)
+{
+ window *win = window::check (L, 1);
+ int slot_id = luaL_checkinteger (L, 2);
+
+ win->lock();
+ win->draw_slot(slot_id);
+ win->update_window();
+ win->unlock();
+
+ return 0;
+}
+
+int
window_update_unprotected (lua_State *L)
{
window *win = window::check (L, 1);
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月29日 03:40:54 +0000

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