added window stroke method - 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月24日 22:57:31 +0200
committerFrancesco Abbate <francesco.bbt@gmail.com>2010年07月24日 22:57:31 +0200
commit8031ba95fd21382ff6c239d05203b25bc44cd98f (patch)
tree9a3e758986ae6996aad2364074361f1b33484352 /agg-plot
parentdbe3ed247ea783b1a8087bf19b9be91c2e246b0b (diff)
downloadgsl-shell-8031ba95fd21382ff6c239d05203b25bc44cd98f.tar.gz
added window stroke method
Diffstat (limited to 'agg-plot')
-rw-r--r--agg-plot/Makefile 2
-rw-r--r--agg-plot/agg-parse-trans.cpp 41
-rw-r--r--agg-plot/agg-parse-trans.h 2
-rw-r--r--agg-plot/canvas-window-cpp.h 8
-rw-r--r--agg-plot/canvas-window.cpp 52
-rw-r--r--agg-plot/colors.cpp 6
-rw-r--r--agg-plot/colors.h 1
-rw-r--r--agg-plot/lua-plot.cpp 280
-rw-r--r--agg-plot/lua-plot.h 37
-rw-r--r--agg-plot/plot-window.cpp 33
-rw-r--r--agg-plot/xwin-show.cpp 103
-rw-r--r--agg-plot/xwin-show.h 9
12 files changed, 81 insertions, 493 deletions
diff --git a/agg-plot/Makefile b/agg-plot/Makefile
index 584b9da9..0f431a9d 100644
--- a/agg-plot/Makefile
+++ b/agg-plot/Makefile
@@ -44,7 +44,7 @@ endif
INCLUDES += $(AGG_INCLUDES) -I$(GSH_BASE_DIR) -I$(LUADIR)/src
-AGGPLOT_SRC_FILES = $(PLATSUP_SRC_FILES) utils.cpp units.cpp colors.cpp trans.cpp lua-draw.cpp lua-plot.cpp agg-parse-trans.cpp xwin-show.cpp canvas-window.cpp plot-window.cpp
+AGGPLOT_SRC_FILES = $(PLATSUP_SRC_FILES) utils.cpp units.cpp colors.cpp trans.cpp lua-draw.cpp agg-parse-trans.cpp canvas-window.cpp plot-window.cpp
AGGPLOT_OBJ_FILES := $(AGGPLOT_SRC_FILES:%.cpp=%.o)
diff --git a/agg-plot/agg-parse-trans.cpp b/agg-plot/agg-parse-trans.cpp
index 30657622..f3b5e40b 100644
--- a/agg-plot/agg-parse-trans.cpp
+++ b/agg-plot/agg-parse-trans.cpp
@@ -7,7 +7,9 @@ extern "C" {
#include "agg-parse-trans.h"
#include "lua-cpp-utils.h"
#include "lua-utils.h"
+#include "lua-draw.h"
#include "gs-types.h"
+#include "colors.h"
#include "trans.h"
struct property_reg {
@@ -199,3 +201,42 @@ parse_spec_pipeline (lua_State *L, int index, vertex_source *obj)
return obj;
}
+
+vertex_source *
+parse_graph_args (lua_State *L)
+{
+ int narg = lua_gettop (L);
+ agg::rgba8 *color;
+
+ if (narg <= 2)
+ color = rgba8_push_default (L);
+ else
+ color = color_arg_lookup (L, 3);
+
+ if (narg > 5)
+ {
+ luaL_error (L, "too much arguments if add or addline plot method");
+ return NULL;
+ }
+
+ vertex_source *curr = check_agg_obj (L, 2);
+
+ if (narg > 4)
+ {
+ curr = parse_spec_pipeline (L, 5, curr);
+ lua_pop (L, 1);
+ }
+
+ if (curr->need_resize())
+ {
+ curr = new trans::resize(curr);
+ }
+
+ if (narg > 3)
+ {
+ curr = parse_spec_pipeline (L, 4, curr);
+ lua_pop (L, 1);
+ }
+
+ return curr;
+}
diff --git a/agg-plot/agg-parse-trans.h b/agg-plot/agg-parse-trans.h
index 87973582..da51e172 100644
--- a/agg-plot/agg-parse-trans.h
+++ b/agg-plot/agg-parse-trans.h
@@ -13,4 +13,6 @@ extern vertex_source * parse_spec (lua_State *L, int specindex,
extern vertex_source * parse_spec_pipeline (lua_State *L, int index,
vertex_source *obj);
+extern vertex_source * parse_graph_args (lua_State *L);
+
#endif
diff --git a/agg-plot/canvas-window-cpp.h b/agg-plot/canvas-window-cpp.h
index 2e48aa08..673ae8f7 100644
--- a/agg-plot/canvas-window-cpp.h
+++ b/agg-plot/canvas-window-cpp.h
@@ -59,12 +59,16 @@ public:
void start_new_thread (lua_State *L);
- bool draw(vertex_source *obj, agg::rgba8 *color)
+ bool draw(vertex_source *obj, agg::rgba8 *color, bool as_line)
{
if (! m_canvas)
return false;
- m_canvas->draw(*obj, *color);
+ if (as_line)
+ m_canvas->draw_outline(*obj, *color);
+ else
+ m_canvas->draw(*obj, *color);
+
return true;
};
diff --git a/agg-plot/canvas-window.cpp b/agg-plot/canvas-window.cpp
index 78d35a25..20c727b5 100644
--- a/agg-plot/canvas-window.cpp
+++ b/agg-plot/canvas-window.cpp
@@ -24,12 +24,14 @@ __BEGIN_DECLS
static int canvas_window_new (lua_State *L);
static int canvas_window_free (lua_State *L);
static int canvas_window_draw (lua_State *L);
+static int canvas_window_stroke (lua_State *L);
static int canvas_window_clear (lua_State *L);
static int canvas_window_refresh (lua_State *L);
static int canvas_window_set_box_trans (lua_State *L);
static void * canvas_thread_function (void *_win);
static int canvas_window_index_protected (lua_State *L);
+static int canvas_window_draw_gener (lua_State *L, bool as_line);
static const struct luaL_Reg canvas_win_functions[] = {
{"window", canvas_window_new},
@@ -44,6 +46,7 @@ static const struct luaL_Reg canvas_window_methods[] = {
static const struct luaL_Reg canvas_window_methods_protected[] = {
{"draw", canvas_window_draw},
+ {"stroke", canvas_window_stroke},
{"clear", canvas_window_clear},
{"refresh", canvas_window_refresh},
{"setview", canvas_window_set_box_trans},
@@ -169,42 +172,18 @@ canvas_window_free (lua_State *L)
}
int
-canvas_window_draw (lua_State *L)
+canvas_window_draw_gener (lua_State *L, bool as_line)
{
canvas_window *win = canvas_window::check (L, 1);
- int narg = lua_gettop (L);
- agg::rgba8 *color;
-
- if (narg <= 2)
- color = rgba8_push_default (L);
- else
- color = color_arg_lookup (L, 3);
-
- vertex_source *curr = check_agg_obj (L, 2);
-
- if (narg > 4)
- {
- curr = parse_spec_pipeline (L, 5, curr);
- lua_pop (L, 1);
- }
-
- if (curr->need_resize())
- {
- curr = new trans::resize(curr);
- }
-
- if (narg > 3)
- {
- curr = parse_spec_pipeline (L, 4, curr);
- lua_pop (L, 1);
- }
+ vertex_source *obj = parse_graph_args (L);
+ agg::rgba8 *color = check_color_rgba8 (L, 3);
const agg::trans_affine& mtx = win->transform();
- curr->apply_transform(mtx, 1.0);
+ obj->apply_transform(mtx, 1.0);
- bool success = win->draw(curr, color);
+ bool success = win->draw(obj, color, as_line);
- lua_management::dispose(curr);
+ lua_management::dispose(obj);
if (! success)
return luaL_error (L, "canvas not ready");
@@ -213,6 +192,18 @@ canvas_window_draw (lua_State *L)
}
int
+canvas_window_draw (lua_State *L)
+{
+ return canvas_window_draw_gener (L, false);
+}
+
+int
+canvas_window_stroke (lua_State *L)
+{
+ return canvas_window_draw_gener (L, true);
+}
+
+int
canvas_window_clear (lua_State *L)
{
canvas_window *win = canvas_window::check (L, 1);
@@ -259,7 +250,6 @@ canvas_window_index_protected (lua_State *L)
int
canvas_window_index (lua_State *L)
{
- canvas_window *win = canvas_window::check(L, 1);
const char *key = luaL_checkstring (L, 2);
const struct luaL_Reg *r = mlua_find_method (canvas_window_methods, key);
diff --git a/agg-plot/colors.cpp b/agg-plot/colors.cpp
index a972a809..ec17f536 100644
--- a/agg-plot/colors.cpp
+++ b/agg-plot/colors.cpp
@@ -75,5 +75,11 @@ color_arg_lookup (lua_State *L, int index)
return c;
}
+agg::rgba8 *
+check_color_rgba8 (lua_State *L, int index)
+{
+ return (agg::rgba8 *) gs_check_userdata (L, index, GS_RGBA_COLOR);
+}
+
agg::rgba colors::white(1, 1, 1);
agg::rgba colors::black(0, 0, 0);
diff --git a/agg-plot/colors.h b/agg-plot/colors.h
index def5a92d..84b47056 100644
--- a/agg-plot/colors.h
+++ b/agg-plot/colors.h
@@ -11,6 +11,7 @@ extern "C" {
extern agg::rgba8 * rgba8_push_lookup (lua_State *L, const char *color_str);
extern agg::rgba8 * rgba8_push_default (lua_State *L);
extern agg::rgba8 * color_arg_lookup (lua_State *L, int index);
+extern agg::rgba8 * check_color_rgba8 (lua_State *L, int index);
namespace colors {
diff --git a/agg-plot/lua-plot.cpp b/agg-plot/lua-plot.cpp
deleted file mode 100644
index e80a76fe..00000000
--- a/agg-plot/lua-plot.cpp
+++ /dev/null
@@ -1,280 +0,0 @@
-
-#include <pthread.h>
-
-extern "C" {
-#include "lua.h"
-#include "lauxlib.h"
-}
-
-#include "agg_color_rgba.h"
-
-#include "lua-plot.h"
-#include "lua-draw.h"
-#include "lua-cpp-utils.h"
-#include "lua-utils.h"
-#include "gs-types.h"
-#include "vertex-source.h"
-#include "trans.h"
-#include "colors.h"
-#include "xwin-show.h"
-#include "agg-parse-trans.h"
-
-__BEGIN_DECLS
-
-static int agg_plot_new (lua_State *L);
-static int agg_plot_show (lua_State *L);
-static int agg_plot_add (lua_State *L);
-static int agg_plot_update (lua_State *L);
-static int agg_plot_add_line (lua_State *L);
-static int agg_plot_index (lua_State *L);
-static int agg_plot_newindex (lua_State *L);
-static int agg_plot_free (lua_State *L);
-static int agg_plot_title_set (lua_State *L);
-static int agg_plot_title_get (lua_State *L);
-static int agg_plot_units_set (lua_State *L);
-static int agg_plot_units_get (lua_State *L);
-
-static const struct luaL_Reg plot_functions[] = {
- {"plot", agg_plot_new},
- {NULL, NULL}
-};
-
-static const struct luaL_Reg agg_plot_methods[] = {
- {"show", agg_plot_show },
- {"add", agg_plot_add },
- {"addline", agg_plot_add_line },
- {"update", agg_plot_update },
- {"__index", agg_plot_index },
- {"__newindex", agg_plot_newindex },
- {"__gc", agg_plot_free },
- {NULL, NULL}
-};
-
-static const struct luaL_Reg agg_plot_properties_get[] = {
- {"title", agg_plot_title_get },
- {"units", agg_plot_units_get },
- {NULL, NULL}
-};
-
-static const struct luaL_Reg agg_plot_properties_set[] = {
- {"title", agg_plot_title_set },
- {"units", agg_plot_units_set },
- {NULL, NULL}
-};
-
-__END_DECLS
-
-void agg_plot::wait_update()
-{
- if (this->window)
- update_callback (this->window);
-};
-
-agg_plot* agg_plot::arg_check(lua_State *L, int index)
-{
- return (agg_plot *) gs_check_userdata (L, index, GS_DRAW_PLOT);
-}
-
-int
-agg_plot_new (lua_State *L)
-{
- agg_plot *p = new(L, GS_DRAW_PLOT) agg_plot();
-
- lua_newtable (L);
- lua_setfenv (L, -2);
-
- if (lua_isstring (L, 1))
- {
- const char *title = lua_tostring (L, 1);
- if (title)
- p->set_title(title);
- }
-
- return 1;
-}
-
-int
-agg_plot_free (lua_State *L)
-{
- agg_plot *p = agg_plot::arg_check(L, 1);
- p->~agg_plot();
- return 0;
-}
-
-int
-agg_plot_index (lua_State *L)
-{
- return mlua_index_with_properties (L, agg_plot_properties_get, false);
-}
-
-int
-agg_plot_title_set (lua_State *L)
-{
- agg_plot *p = agg_plot::arg_check(L, 1);
- const char *title = lua_tostring (L, 2);
-
- if (title == NULL)
- return gs_type_error (L, 2, "string");
-
- AGG_LOCK();
-
- p->set_title(title);
- p->wait_update();
-
- AGG_UNLOCK();
-
- return 0;
-}
-
-int
-agg_plot_title_get (lua_State *L)
-{
- agg_plot *p = agg_plot::arg_check(L, 1);
- const char *title = p->get_title();
- lua_pushstring (L, title);
- return 1;
-}
-
-int
-agg_plot_units_set (lua_State *L)
-{
- agg_plot *p = agg_plot::arg_check(L, 1);
- bool request = (bool) lua_toboolean (L, 2);
- bool current = p->use_units();
-
- if (current != request)
- {
- AGG_LOCK();
- p->set_units(request);
- p->wait_update();
- AGG_UNLOCK();
- }
-
- return 0;
-}
-
-int
-agg_plot_units_get (lua_State *L)
-{
- agg_plot *p = agg_plot::arg_check(L, 1);
- lua_pushboolean (L, p->use_units());
- return 1;
-}
-
-int
-agg_plot_newindex (lua_State *L)
-{
- return mlua_newindex_with_properties (L, agg_plot_properties_set);
-}
-
-static int
-agg_plot_add_gener (lua_State *L, bool as_line)
-{
- agg_plot *p = agg_plot::arg_check(L, 1);
- int narg = lua_gettop (L);
- agg::rgba8 *color;
-
- if (narg <= 2)
- color = rgba8_push_default (L);
- else
- color = color_arg_lookup (L, 3);
-
- if (narg > 5)
- return luaL_error (L, "too much arguments if add or addline plot method");
-
- vertex_source *curr = check_agg_obj (L, 2);
-
- if (narg > 4)
- {
- curr = parse_spec_pipeline (L, 5, curr);
- lua_pop (L, 1);
- }
-
- if (curr->need_resize())
- {
- curr = new trans::resize(curr);
- }
-
- if (narg > 3)
- {
- curr = parse_spec_pipeline (L, 4, curr);
- lua_pop (L, 1);
- }
-
- lua_pushvalue (L, 1);
- mlua_fenv_addref (L, 2);
- lua_pop (L, 1);
-
- AGG_LOCK();
- p->add(curr, color, as_line);
- p->wait_update();
- AGG_UNLOCK();
-
- return 0;
-}
-
-int
-agg_plot_add (lua_State *L)
-{
- return agg_plot_add_gener (L, false);
-}
-
-int
-agg_plot_add_line (lua_State *L)
-{
- return agg_plot_add_gener (L, true);
-}
-
-int
-agg_plot_update (lua_State *L)
-{
- agg_plot *p = agg_plot::arg_check(L, 1);
- AGG_PROTECT(p->wait_update());
- return 0;
-}
-
-int
-agg_plot_show (lua_State *L)
-{
- agg_plot *p = agg_plot::arg_check(L, 1);
- pthread_t xwin_thread[1];
- pthread_attr_t attr[1];
-
- AGG_LOCK();
-
- if (! p->is_shown)
- {
- p->id = mlua_window_ref(L, 1);
-
- pthread_attr_init (attr);
- pthread_attr_setdetachstate (attr, PTHREAD_CREATE_DETACHED);
-
- if (pthread_create(xwin_thread, attr, xwin_thread_function, (void*) p))
- {
- pthread_attr_destroy (attr);
- mlua_window_unref(L, p->id);
- p->id = -1;
- AGG_UNLOCK();
- return luaL_error(L, "error creating thread.");
- }
-
- p->is_shown = 1;
- pthread_attr_destroy (attr);
- }
-
- AGG_UNLOCK();
-
- return 0;
-}
-
-void
-plot_register (lua_State *L)
-{
- /* plot declaration */
- luaL_newmetatable (L, GS_METATABLE(GS_DRAW_PLOT));
- luaL_register (L, NULL, agg_plot_methods);
- lua_pop (L, 1);
-
- /* gsl module registration */
- luaL_register (L, NULL, plot_functions);
-}
diff --git a/agg-plot/lua-plot.h b/agg-plot/lua-plot.h
deleted file mode 100644
index 9eb7b646..00000000
--- a/agg-plot/lua-plot.h
+++ /dev/null
@@ -1,37 +0,0 @@
-#ifndef LUA_CPLOT_H
-#define LUA_CPLOT_H
-
-#include "defs.h"
-
-__BEGIN_DECLS
-#include "lua.h"
-__END_DECLS
-
-#ifdef __cplusplus
-
-#include "plot.h"
-#include "resource-manager.h"
-
-typedef plot<vertex_source, lua_management> plot_type;
-
-struct agg_plot : public plot_type {
- bool is_shown;
- void *window;
- int id;
-
- agg_plot() : plot_type(), is_shown(false), window(NULL), id(0) {};
-
- void wait_update();
-
- static agg_plot* arg_check(lua_State *L, int index);
-};
-
-#endif
-
-__BEGIN_DECLS
-
-extern void plot_register (lua_State *L);
-
-__END_DECLS
-
-#endif
diff --git a/agg-plot/plot-window.cpp b/agg-plot/plot-window.cpp
index 9d71e16a..d1fe86c6 100644
--- a/agg-plot/plot-window.cpp
+++ b/agg-plot/plot-window.cpp
@@ -158,35 +158,8 @@ int
plot_window_add_gener (lua_State *L, bool as_line)
{
plot_window *p = plot_window::check(L, 1);
- int narg = lua_gettop (L);
- agg::rgba8 *color;
-
- if (narg <= 2)
- color = rgba8_push_default (L);
- else
- color = color_arg_lookup (L, 3);
-
- if (narg > 5)
- return luaL_error (L, "too much arguments if add or addline plot method");
-
- vertex_source *curr = check_agg_obj (L, 2);
-
- if (narg > 4)
- {
- curr = parse_spec_pipeline (L, 5, curr);
- lua_pop (L, 1);
- }
-
- if (curr->need_resize())
- {
- curr = new trans::resize(curr);
- }
-
- if (narg > 3)
- {
- curr = parse_spec_pipeline (L, 4, curr);
- lua_pop (L, 1);
- }
+ vertex_source *obj = parse_graph_args (L);
+ agg::rgba8 *color = check_color_rgba8 (L, 3);
lua_pushvalue (L, 1);
mlua_fenv_addref (L, 2);
@@ -195,7 +168,7 @@ plot_window_add_gener (lua_State *L, bool as_line)
AGG_LOCK();
plot_window::plot_type& plt = p->get_plot();
- plt.add(curr, color, as_line);
+ plt.add(obj, color, as_line);
if (p->status == plot_window::running)
{
diff --git a/agg-plot/xwin-show.cpp b/agg-plot/xwin-show.cpp
deleted file mode 100644
index f96c401c..00000000
--- a/agg-plot/xwin-show.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-
-#include "platform/agg_platform_support.h"
-
-#include "xwin-show.h"
-#include "gsl-shell.h"
-#include "canvas.h"
-#include "lua-plot.h"
-#include "lua-cpp-utils.h"
-#include "lua-draw.h"
-
-
-extern void platform_support_prepare ();
-extern void platform_support_lock (agg::platform_support *app);
-extern void platform_support_unlock (agg::platform_support *app);
-extern bool platform_support_is_mapped (agg::platform_support *app);
-
-enum flip_y_e { flip_y = true };
-
-class the_application : public agg::platform_support
-{
-public:
- the_application(agg::pix_format_e format, bool flip_y, agg_plot *p) :
- agg::platform_support(format, flip_y), m_plot(p)
- {
- };
-
- virtual ~the_application()
- {
- }
-
- void on_draw_unprotected()
- {
- canvas can(rbuf_window(), width(), height(), agg::rgba(1.0, 1.0, 1.0));
- can.clear();
- this->m_plot->draw(can);
- }
-
- virtual void on_draw()
- {
- AGG_PROTECT(on_draw_unprotected());
- }
-
-private:
- agg_plot *m_plot;
-};
-
-int update_callback (void *_app)
-{
- the_application *app = (the_application *) _app;
- int status = 0;
-
- platform_support_lock (app);
-
- if (platform_support_is_mapped (app))
- {
- app->on_draw_unprotected();
- app->update_window();
- status = 1;
- }
-
- platform_support_unlock (app);
- return status;
-};
-
-void *
-xwin_thread_function (void *_plot)
-{
- agg_plot *p = (agg_plot *) _plot;
-
- platform_support_prepare();
-
- AGG_LOCK();
-
- the_application app(agg::pix_format_bgr24, flip_y, p);
- app.caption("GSL shell plot");
-
- platform_support_lock (&app);
-
- if(app.init(780, 400, agg::window_resize))
- {
- p->window = (void *) &app;
- AGG_UNLOCK();
-
- /* start main loop for the plot window */
- app.run();
-
- AGG_LOCK();
- p->window = NULL;
- p->is_shown = 0;
- AGG_UNLOCK();
-
- GSL_SHELL_LOCK();
- gsl_shell_unref_plot (p->id);
- GSL_SHELL_UNLOCK();
- }
-
- platform_support_unlock (&app);
-
- return NULL;
-}
diff --git a/agg-plot/xwin-show.h b/agg-plot/xwin-show.h
deleted file mode 100644
index 62b47b75..00000000
--- a/agg-plot/xwin-show.h
+++ /dev/null
@@ -1,9 +0,0 @@
-
-#include "defs.h"
-
-__BEGIN_DECLS
-
-extern int update_callback (void *_app);
-extern void * xwin_thread_function (void *_cplot);
-
-__END_DECLS
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月18日 05:04:20 +0000

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