added protected methods for drawing - 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:
authorFrancesco Abbate <francesco.bbt@gmail.com>2010年07月12日 23:12:21 +0200
committerFrancesco Abbate <francesco.bbt@gmail.com>2010年07月12日 23:12:21 +0200
commit100a221e36810b5087af6e2af73fe0337bab0734 (patch)
tree49f6a49456cd1c494cc846a346e64974965c4fa2 /agg-plot
parent672a38519fcdaf698f459a9c222c2071cff49220 (diff)
downloadgsl-shell-100a221e36810b5087af6e2af73fe0337bab0734.tar.gz
added protected methods for drawing
Diffstat (limited to 'agg-plot')
-rw-r--r--agg-plot/plot-window.cpp 139
1 files changed, 109 insertions, 30 deletions
diff --git a/agg-plot/plot-window.cpp b/agg-plot/plot-window.cpp
index 2d7f44d7..50b802ee 100644
--- a/agg-plot/plot-window.cpp
+++ b/agg-plot/plot-window.cpp
@@ -29,9 +29,10 @@ static void * win_thread_function (void *_win);
static int plot_window_new (lua_State *L);
static int plot_window_free (lua_State *L);
-static int plot_window_prepare (lua_State *L);
+static int plot_window_index (lua_State *L);
static int plot_window_draw (lua_State *L);
-static int plot_window_render (lua_State *L);
+static int plot_window_clear (lua_State *L);
+static int plot_window_update (lua_State *L);
static const struct luaL_Reg plotwin_functions[] = {
{"window", plot_window_new},
@@ -40,9 +41,15 @@ static const struct luaL_Reg plotwin_functions[] = {
static const struct luaL_Reg plot_window_methods[] = {
{"__gc", plot_window_free},
- {"prepare", plot_window_prepare},
+ {"__index", plot_window_index},
+ {NULL, NULL}
+};
+
+/* NB: this methods should return no values */
+static const struct luaL_Reg plot_window_methods_protected[] = {
{"draw", plot_window_draw},
- {"render", plot_window_render},
+ {"clear", plot_window_clear},
+ {"update", plot_window_update},
{NULL, NULL}
};
@@ -53,16 +60,17 @@ __END_DECLS
class plot_window : public agg::platform_support {
private:
canvas *m_canvas;
-
+ agg::rgba m_bgcolor;
+
public:
enum win_status_e { not_ready, starting, running, error, closed };
int id;
enum win_status_e status;
- plot_window() :
+ plot_window(agg::rgba& bgcol) :
agg::platform_support(agg::pix_format_bgr24, true),
- m_canvas(NULL), id(-1), status(not_ready)
+ m_canvas(NULL), m_bgcolor(bgcol), id(-1), status(not_ready)
{ };
virtual ~plot_window()
@@ -71,23 +79,12 @@ public:
delete m_canvas;
};
- virtual void on_draw()
- {
- printf("on draw!\n");
- canvas can(rbuf_window(), width(), height(), agg::rgba(1.0, 1.0, 1.0));
- can.clear();
- };
-
- void canvas_prepare()
- {
- if (m_canvas)
- delete m_canvas;
-
- m_canvas = new canvas(rbuf_window(), width(), height(),
- agg::rgba(1.0, 1.0, 1.0));
- };
+ virtual void on_draw();
+ virtual void on_init();
+ virtual void on_resize(int sx, int sy);
void start();
+ void clear() { if (m_canvas) m_canvas->clear(); };
bool draw(vertex_source *obj, agg::rgba8 *color)
{
@@ -102,6 +99,34 @@ public:
};
void
+plot_window::on_init()
+{
+ if (m_canvas)
+ delete m_canvas;
+
+ m_canvas = new canvas(rbuf_window(), width(), height(), m_bgcolor);
+}
+
+void
+plot_window::on_draw()
+{
+ printf("on draw!\n");
+ if (! m_canvas)
+ return;
+
+ m_canvas->clear();
+};
+
+void
+plot_window::on_resize(int sx, int sy)
+{
+ if (m_canvas)
+ delete m_canvas;
+
+ m_canvas = new canvas(rbuf_window(), sx, sy, m_bgcolor);
+}
+
+void
plot_window::start()
{
WINDOW_LOCK();
@@ -122,8 +147,10 @@ plot_window::start()
gsl_shell_unref_plot (this->id);
GSL_SHELL_UNLOCK();
}
-
- WINDOW_UNLOCK();
+ else
+ {
+ WINDOW_UNLOCK();
+ }
}
void *
@@ -147,7 +174,16 @@ plot_window::check (lua_State *L, int index)
int
plot_window_new (lua_State *L)
{
- plot_window *win = new(L, GS_AGG_WINDOW) plot_window;
+ agg::rgba8 *c8;
+
+ if (lua_gettop (L) == 0)
+ c8 = rgba8_push_default (L);
+ else
+ c8 = color_arg_lookup (L, 1);
+
+ const double bs = (double) agg::rgba8::base_mask;
+ agg::rgba color(c8->r / bs, c8->g / bs, c8->b / bs, c8->a / bs);
+ plot_window *win = new(L, GS_AGG_WINDOW) plot_window(color);
WINDOW_LOCK();
@@ -214,29 +250,72 @@ plot_window_draw (lua_State *L)
}
int
-plot_window_prepare (lua_State *L)
+plot_window_clear (lua_State *L)
{
plot_window *win = plot_window::check (L, 1);
- win->canvas_prepare();
+ win->clear();
return 0;
}
int
-plot_window_render (lua_State *L)
+plot_window_update (lua_State *L)
{
plot_window *win = plot_window::check (L, 1);
win->update_window();
return 0;
}
+static int
+plot_window_index_protected (lua_State *L)
+{
+ plot_window *win = plot_window::check(L, lua_upvalueindex(2));
+
+ int narg = lua_gettop (L);
+
+ lua_pushvalue (L, lua_upvalueindex(1));
+ lua_insert (L, 1);
+
+ platform_support_lock (win);
+ if (lua_pcall (L, narg, 0, 0) != 0)
+ {
+ platform_support_unlock (win);
+ return lua_error (L);
+ }
+
+ platform_support_unlock (win);
+ return 0;
+}
+
+int
+plot_window_index (lua_State *L)
+{
+ const char *key = luaL_checkstring (L, 2);
+
+ const struct luaL_Reg *r = mlua_find_method (plot_window_methods, key);
+ if (r)
+ {
+ lua_pushcfunction (L, r->func);
+ return 1;
+ }
+
+ r = mlua_find_method (plot_window_methods_protected, key);
+ if (r)
+ {
+ lua_pushcfunction (L, r->func);
+ lua_pushvalue (L, 1);
+ lua_pushcclosure (L, plot_window_index_protected, 2);
+ return 1;
+ }
+
+ return 0;
+}
+
void
plot_window_register (lua_State *L)
{
pthread_mutex_init (window_mutex, NULL);
luaL_newmetatable (L, GS_METATABLE(GS_AGG_WINDOW));
- lua_pushvalue (L, -1);
- lua_setfield (L, -2, "__index");
luaL_register (L, NULL, plot_window_methods);
lua_pop (L, 1);
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月16日 19:34:05 +0000

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