gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/agg-plot
diff options
context:
space:
mode:
Diffstat (limited to 'agg-plot')
-rw-r--r--agg-plot/canvas-window.cpp 6
-rw-r--r--agg-plot/lua-plot-cpp.h 3
-rw-r--r--agg-plot/lua-plot.cpp 6
-rw-r--r--agg-plot/split-spec-parser.h 35
-rw-r--r--agg-plot/window-cpp.h 14
-rw-r--r--agg-plot/window.cpp 103
6 files changed, 85 insertions, 82 deletions
diff --git a/agg-plot/canvas-window.cpp b/agg-plot/canvas-window.cpp
index 9302b46e..a997c4b7 100644
--- a/agg-plot/canvas-window.cpp
+++ b/agg-plot/canvas-window.cpp
@@ -31,7 +31,7 @@ extern "C" {
#include "agg-parse-trans.h"
#include "lua-cpp-utils.h"
#include "lua-utils.h"
-#include "window-refs.h"
+#include "object-index.h"
#include "lua-draw.h"
#include "gs-types.h"
#include "colors.h"
@@ -109,7 +109,7 @@ canvas_window::start_new_thread (lua_State *L)
if (status != not_ready && status != closed)
return;
- this->id = window_ref_add (L, lua_gettop (L));
+ this->id = object_index_add (L, OBJECT_WINDOW, -1);
pthread_attr_t attr[1];
pthread_t win_thread[1];
@@ -121,7 +121,7 @@ canvas_window::start_new_thread (lua_State *L)
if (pthread_create(win_thread, attr, canvas_thread_function, (void*) this))
{
- window_ref_remove (L, this->id);
+ object_index_remove (L, OBJECT_WINDOW, this->id);
pthread_attr_destroy (attr);
this->status = canvas_window::error;
diff --git a/agg-plot/lua-plot-cpp.h b/agg-plot/lua-plot-cpp.h
index 5e318dd0..6bfbe751 100644
--- a/agg-plot/lua-plot-cpp.h
+++ b/agg-plot/lua-plot-cpp.h
@@ -19,7 +19,7 @@ private:
plot_type m_plot;
public:
- lua_plot() : m_plot(), id(-1) { };
+ lua_plot() : m_plot(), window_id(-1), id(-1) { };
void update_window(lua_State *L);
@@ -27,6 +27,7 @@ public:
static lua_plot *check(lua_State *L, int index);
+ int window_id;
int id;
};
diff --git a/agg-plot/lua-plot.cpp b/agg-plot/lua-plot.cpp
index 5f780f88..ae046e38 100644
--- a/agg-plot/lua-plot.cpp
+++ b/agg-plot/lua-plot.cpp
@@ -25,7 +25,7 @@ extern "C" {
#include "lua-plot.h"
#include "lua-plot-cpp.h"
-#include "window-refs.h"
+#include "object-index.h"
#include "window.h"
#include "gs-types.h"
#include "lua-utils.h"
@@ -94,7 +94,7 @@ lua_plot::check(lua_State *L, int index)
void
lua_plot::update_window(lua_State *L)
{
- window_ref_get (L, this->id);
+ object_index_get (L, OBJECT_WINDOW, this->window_id);
if (gs_is_userdata (L, lua_gettop (L), GS_WINDOW))
{
@@ -120,6 +120,8 @@ plot_new (lua_State *L)
p->self().set_title(title);
}
+ p->id = object_index_add (L, OBJECT_PLOT, -1);
+
return 1;
}
diff --git a/agg-plot/split-spec-parser.h b/agg-plot/split-spec-parser.h
index 1ccae7c6..dd2aee75 100644
--- a/agg-plot/split-spec-parser.h
+++ b/agg-plot/split-spec-parser.h
@@ -12,27 +12,36 @@ enum direction_e { along_x, along_y };
namespace split {
template <class base_type>
- class node {
- public:
+ struct node {
typedef pod_list<node*> list;
+ virtual void transform(matrix& m) = 0;
+
virtual list* tree() { return 0; };
virtual base_type* content() { return 0; };
virtual void content(const base_type& src) { };
- virtual void transform(matrix& m) = 0;
virtual matrix* get_matrix() { return 0; };
virtual ~node() {};
+
+ static void init(node* tree);
};
template <class base_type>
+ void node<base_type>::init(node<base_type>* tree)
+ {
+ matrix m;
+ tree->transform(m);
+ }
+
+ template <class base_type>
class node_leaf : public node<base_type> {
base_type m_content;
matrix m_matrix;
public:
- node_leaf(const base_type& src) : m_content(src), m_matrix() {};
+ node_leaf() : m_content(), m_matrix() {};
virtual base_type* content() { return &m_content; };
virtual void content(const base_type& src) { m_content = src; };
@@ -116,17 +125,17 @@ namespace split {
};
template <class base_type, class lexer>
- extern node<base_type>* parse (lexer& lex, const base_type& seed);
+ extern node<base_type>* parse (lexer& lex);
template <class base_type, class lexer>
- node<base_type>* subtree (lexer& lex, const base_type& seed, direction_e dir)
+ node<base_type>* subtree (lexer& lex, direction_e dir)
{
node_tree<base_type> * ls = new node_tree<base_type>(dir);
int c;
for (c = 0; ; c++)
{
- node<base_type>* child = parse<base_type, lexer>(lex, seed);
+ node<base_type>* child = parse<base_type, lexer>(lex);
if (! child)
break;
ls->add(child);
@@ -138,25 +147,23 @@ namespace split {
}
template <class base_type, class lexer>
- node<base_type>* parse (lexer& lex, const base_type& seed)
+ node<base_type>* parse (lexer& lex)
{
char t = lex.next();
switch (t)
{
case '.':
- return new node_leaf<base_type>(seed);
+ return new node_leaf<base_type>();
case 'h':
- return subtree<base_type, lexer>(lex, seed, along_x);
+ return subtree<base_type, lexer>(lex, along_x);
case 'v':
- return subtree<base_type, lexer>(lex, seed, along_y);
+ return subtree<base_type, lexer>(lex, along_y);
case '(':
{
- node<base_type> *nd = parse<base_type, lexer>(lex, seed);
-
+ node<base_type> *nd = parse<base_type, lexer>(lex);
if (! lex.checknext(')'))
return NULL;
-
return nd;
}
case ')':
diff --git a/agg-plot/window-cpp.h b/agg-plot/window-cpp.h
index 44beaa30..e5d6292e 100644
--- a/agg-plot/window-cpp.h
+++ b/agg-plot/window-cpp.h
@@ -19,9 +19,17 @@ extern "C" {
class window : public canvas_window {
typedef plot<drawable, lua_management> plot_type;
- split::node<plot_type*>* m_tree;
+ struct ref {
+ plot_type *plot;
+ int id;
- void draw_rec(split::node<plot_type*> *n);
+ ref() : plot(0), id(-1) {};
+ ref(plot_type *p, int _id) : plot(p), id(_id) {};
+ };
+
+ split::node<ref>* m_tree;
+
+ void draw_rec(split::node<ref> *n);
public:
window(agg::rgba& bgcol) : canvas_window(bgcol), m_tree(0) {};
@@ -31,7 +39,7 @@ public:
static window *check (lua_State *L, int index);
void split(const char *spec);
- bool attach(lua_plot *plot, const char *spec);
+ int attach(lua_plot *plot, const char *spec, int id);
void on_draw_unprotected();
virtual void on_draw();
diff --git a/agg-plot/window.cpp b/agg-plot/window.cpp
index ba9cd088..f5864eca 100644
--- a/agg-plot/window.cpp
+++ b/agg-plot/window.cpp
@@ -9,6 +9,7 @@ extern "C" {
#include "lua-cpp-utils.h"
#include "gs-types.h"
#include "object-refs.h"
+#include "object-index.h"
#include "colors.h"
#include "lua-plot-cpp.h"
#include "split-spec-parser.h"
@@ -36,21 +37,21 @@ static const struct luaL_Reg window_methods[] = {
__END_DECLS
void
-window::draw_rec(split::node<plot_type*> *n)
+window::draw_rec(split::node<ref> *n)
{
- split::node<plot_type*>::list *ls;
+ split::node<ref>::list *ls;
for (ls = n->tree(); ls != NULL; ls = ls->next())
draw_rec(ls->content());
- plot_type **p = n->content();
+ ref *ref = n->content();
matrix* m = n->get_matrix();
- if (p && m)
+ if (ref && m)
{
- if (*p)
+ if (ref->plot)
{
agg::trans_affine mtx(*m);
m_canvas->premultiply(mtx);
- (*p)->draw(*m_canvas, mtx);
+ ref->plot->draw(*m_canvas, mtx);
}
}
}
@@ -61,11 +62,9 @@ window::on_draw_unprotected()
if (! m_canvas)
return;
+ m_canvas->clear();
if (m_tree)
- {
- m_canvas->clear();
- draw_rec(m_tree);
- }
+ draw_rec(m_tree);
}
void
@@ -82,48 +81,12 @@ window::check (lua_State *L, int index)
return (window *) gs_check_userdata (L, index, GS_WINDOW);
}
-/*
-static void
-set_matrix(agg::trans_affine& m, double x, double y, double sx, double sy)
-{
- m.tx = x;
- m.ty = y;
- m.sx = sx;
- m.sy = sy;
-}
-
-typedef pod_list<plot_matrix> pm_list;
-
-pm_list * build_list(node *tree)
-{
- pm_list *ls = NULL;
-
- node_list *childs = tree->get_tree();
- for ( ; childs != NULL; childs = childs->next())
- {
- pm_list *sub = build_list(childs->content());
- ls = pm_list::push_back(ls, sub);
- }
-
- matrix *m = tree->get_matrix();
- if (m)
- {
- plot_matrix pm(NULL, *m);
- ls = new pm_list(pm, ls);
- }
-
- return ls;
-}
-*/
-
void
window::split(const char *spec)
{
split::string_lexer lexbuf(spec);
- m_tree = split::parse<plot_type*, split::string_lexer>(lexbuf, (plot_type*) 0);
-
- agg::trans_affine m;
- m_tree->transform(m);
+ m_tree = split::parse<ref, split::string_lexer>(lexbuf);
+ split::node<ref>::init(m_tree);
}
static const char *
@@ -147,28 +110,40 @@ next_int (const char *str, int& val)
return eptr;
}
-bool
-window::attach(lua_plot *plot, const char *spec)
+/* 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)
{
- split::node<plot_type*> *n = m_tree;
+ split::node<ref> *n = m_tree;
const char *ptr;
int k;
for (ptr = next_int (spec, k); ptr; ptr = next_int (ptr, k))
{
- split::node<plot_type*>::list* list = n->tree();
+ split::node<ref>::list* list = n->tree();
if (! list)
- break;
+ return -1;
- for (int j = 1; j < k && list; j++)
- list = list->next();
+ for (int j = 1; j < k; j++)
+ {
+ list = list->next();
+ if (! list)
+ return -1;
+ }
n = list->content();
}
- n->content(& plot->self());
- return true;
+ ref* ex_ref = n->content();
+ if (! ex_ref)
+ return -1;
+ int ex_id = ex_ref->id;
+
+ ref new_ref(& plot->self(), id);
+ n->content(new_ref);
+
+ return (ex_id > 0 ? ex_id : 0);
}
int
@@ -208,9 +183,11 @@ window_attach (lua_State *L)
win->lock();
- if (win->attach (plot, spec))
+ int ex_plot_id = win->attach (plot, spec, plot->id);
+
+ if (ex_plot_id >= 0)
{
- plot->id = win->id;
+ plot->window_id = win->id;
win->on_draw();
win->update_window();
@@ -218,6 +195,14 @@ window_attach (lua_State *L)
win->unlock();
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);
+ }
}
else
{
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月18日 02:36:29 +0000

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