-rw-r--r-- | agg-plot/plot-window.cpp | 139 | ||||
-rw-r--r-- | scripts/project-dir-compare.py | 75 |
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); diff --git a/scripts/project-dir-compare.py b/scripts/project-dir-compare.py index 67f14943..42bc15ae 100644 --- a/scripts/project-dir-compare.py +++ b/scripts/project-dir-compare.py @@ -1,6 +1,11 @@ +#!/usr/bin/python + +import sys import os import re -import sys +import shutil + +from optparse import OptionParser def differs(fna, fnb): fa, fb = open(fna, 'r'), open(fnb, 'r') @@ -15,19 +20,17 @@ def exists(fn): except: return False -fulldira = sys.argv[1] -fulldirb = sys.argv[2] - -# basedir = '/home/francesco/sviluppo' +parser = OptionParser() +parser.add_option("-r", "--report", action="store_false", dest="write") +parser.add_option("-w", "--write", action="store_true", dest="write", default=False) -# dira = 'gsl-shell' -# dirb = 'gsl-shell-win-branch' +(options, args) = parser.parse_args() -# fulldira = os.path.join(basedir, dira) -# fulldirb = os.path.join(basedir, dirb) +dira = args[0] +dirb = args[1] dir_ignore = [r'\.(git|svn|deps|libs)$', r'^doc/html$', r'^www$'] -file_ignore = [r'~$', r'\.o$'] +file_ignore = ['^\.gitignore', '^gsl-shell$', r'^lua/src/luac?$', r'~$', r'\.o$', r'\.a$'] treated, absenta, absentb, differ = [], [], [], [] @@ -65,11 +68,11 @@ def project_scan(basedir): yield rel dir_filter(dirnames, rpath, basedir) -for filename in project_scan(fulldira): +for filename in project_scan(dira): treated.append(filename) - filenamea = os.path.join(fulldira, filename) - filenameb = os.path.join(fulldirb, filename) + filenamea = os.path.join(dira, filename) + filenameb = os.path.join(dirb, filename) if not exists(filenameb): absentb.append(filename) @@ -77,15 +80,45 @@ for filename in project_scan(fulldira): if differs(filenamea, filenameb): differ.append(filename) -for filename in project_scan(fulldirb): +for filename in project_scan(dirb): if not filename in treated: absenta.append(filename) -print 'Absent A:' +def copy_files(flist, src, dst): + for nm in flist: + sf = os.path.join(src, nm) + df = os.path.join(dst, nm) + print 'Copying', nm, 'into', dst, '...', + try: + mdestdir = os.path.dirname(df) + if not exists(mdestdir): + os.makedirs(mdestdir) + shutil.copy(sf, df) + shutil.copystat(sf, df) + except OSError as oserr: + print 'error:', oserr.strerror + else: + print 'ok' + +def sync_directories(): + for nm in absenta: + nmb = os.path.join(dirb, nm) + print 'Removing', nmb, '...', + try: + os.remove(nmb) + except OSError as oserr: + print 'error:', oserr.strerror + else: + print 'ok' + + copy_files(absentb, dira, dirb) + copy_files(differ, dira, dirb) + +print 'Absent from SOURCE project:' for nm in absenta: print '+ ', nm -print 'Absent B:' +print 'Absent from DESTINATION project:' for nm in absentb: print '- ', nm @@ -95,7 +128,15 @@ for nm in differ: print '-'*25 + ' DIFF OUTPUT ' + '-'*25 for nm in differ: - cmd = 'diff -U 4 %s %s' % (os.path.join(fulldira, nm), os.path.join(fulldirb, nm)) + cmd = 'diff -U 4 %s %s' % (os.path.join(dira, nm), os.path.join(dirb, nm)) diffout = os.popen(cmd) for ln in diffout: print ln, + +if options.write: + print 'Proceed to sync DESTINATION (%s) from SOURCE (%s) [Y/n] ? ' % (dirb, dira), + ans = sys.stdin.readline() + ans = ans.rstrip('\n') + if ans in ['Y', 'Yes', 'y', 'yes']: + print 'Syncing' + sync_directories() |