-rw-r--r-- | fox-gui/Makefile | 2 | ||||
-rw-r--r-- | fox-gui/fx_console.cpp | 8 | ||||
-rw-r--r-- | fox-gui/fx_plot_canvas.cpp | 2 | ||||
-rw-r--r-- | fox-gui/fx_plot_canvas.h | 10 | ||||
-rw-r--r-- | fox-gui/fx_plot_window.cpp | 24 | ||||
-rw-r--r-- | fox-gui/fx_plot_window.h | 29 | ||||
-rw-r--r-- | fox-gui/lua_plot_window.cpp | 88 | ||||
-rw-r--r-- | fox-gui/lua_plot_window.h | 14 | ||||
-rw-r--r-- | lua-gsl/gs-types.c | 2 | ||||
-rw-r--r-- | lua-gsl/gs-types.h | 1 |
diff --git a/fox-gui/Makefile b/fox-gui/Makefile index 625a1f9c..048379c0 100644 --- a/fox-gui/Makefile +++ b/fox-gui/Makefile @@ -35,7 +35,7 @@ LIBS += $(LUADIR)/src/libluajit.a $(GSH_BASE_DIR)/agg-plot/libaggplot.a $(GSH_BA INCLUDES += $(PTHREADS_CFLAGS) LIBS += $(AGG_LIBS) $(PTHREADS_LIBS) $(GSL_LIBS) -FOXGUI_SRC_FILES = fx_console.cpp redirect.cpp gsl_shell_interp.cpp gsl_shell_thread.cpp gsl_shell_window.cpp fx_plot_canvas.cpp gsl-shell-fox.cpp +FOXGUI_SRC_FILES = fx_console.cpp redirect.cpp gsl_shell_interp.cpp gsl_shell_thread.cpp gsl_shell_window.cpp fx_plot_canvas.cpp fx_plot_window.cpp lua_plot_window.cpp gsl-shell-fox.cpp FOXGUI_OBJ_FILES := $(FOXGUI_SRC_FILES:%.cpp=%.o) DEP_FILES := $(FOXGUI_SRC_FILES:%.cpp=.deps/%.P) diff --git a/fox-gui/fx_console.cpp b/fox-gui/fx_console.cpp index 92968022..48926921 100644 --- a/fox-gui/fx_console.cpp +++ b/fox-gui/fx_console.cpp @@ -4,6 +4,8 @@ #include "fx_console.h" #include "gsl_shell_thread.h" +#include "lua_plot_window.h" +#include "fx_plot_window.h" FXDEFMAP(fx_console) fx_console_map[]={ FXMAPFUNC(SEL_KEYPRESS, 0, fx_console::on_key_press), @@ -43,6 +45,12 @@ void fx_console::create() init("Welcome to GSL Shell 2.1\n"); setFocus(); m_engine.start(); + + lua_State* L = m_engine.L; + lua_pushlightuserdata(L, (void*) getApp()); + lua_setfield(L, LUA_REGISTRYINDEX, "__fox_app"); + + fox_window_register(L); } void fx_console::init(const FXString& greeting) diff --git a/fox-gui/fx_plot_canvas.cpp b/fox-gui/fx_plot_canvas.cpp index c6bad2fc..c1d9c117 100644 --- a/fox-gui/fx_plot_canvas.cpp +++ b/fox-gui/fx_plot_canvas.cpp @@ -67,7 +67,7 @@ void fx_plot_canvas::draw(FXEvent* event) m_dirty_flag = false; } -void fx_plot_canvas::attach(plot* p) +void fx_plot_canvas::attach(plot_type* p) { m_plot = p; m_dirty_flag = true; diff --git a/fox-gui/fx_plot_canvas.h b/fox-gui/fx_plot_canvas.h index 48fac503..03cedd02 100644 --- a/fox-gui/fx_plot_canvas.h +++ b/fox-gui/fx_plot_canvas.h @@ -1,5 +1,5 @@ -#ifndef FOXGUI_PLOT_CANVAS_H -#define FOXGUI_PLOT_CANVAS_H +#ifndef FOXGUI_FX_PLOT_CANVAS_H +#define FOXGUI_FX_PLOT_CANVAS_H #include <fx.h> #include <agg_rendering_buffer.h> @@ -12,7 +12,7 @@ class fx_plot_canvas : public FXCanvas { FXDECLARE(fx_plot_canvas) public: - typedef plot_auto<sg_object, manage_owner> plot; + typedef plot<sg_object, manage_owner> plot_type; fx_plot_canvas(FXComposite* p, FXObject* tgt=NULL, FXSelector sel=0, FXuint opts=FRAME_NORMAL, @@ -20,7 +20,7 @@ public: ~fx_plot_canvas(); - void attach(plot* p); + void attach(plot_type* p); void draw(FXEvent* event); long on_cmd_paint(FXObject *, FXSelector, void *); @@ -35,7 +35,7 @@ private: FXImage* m_img; agg::rendering_buffer m_rbuf; - plot* m_plot; + plot_type* m_plot; canvas* m_canvas; bool m_dirty_flag; }; diff --git a/fox-gui/fx_plot_window.cpp b/fox-gui/fx_plot_window.cpp new file mode 100644 index 00000000..e5d6049d --- /dev/null +++ b/fox-gui/fx_plot_window.cpp @@ -0,0 +1,24 @@ + +#include "fx_plot_window.h" + +FXDEFMAP(fx_plot_window) fx_plot_window_map[]={ +}; + +FXIMPLEMENT(fx_plot_window,FXMainWindow,fx_plot_window_map,ARRAYNUMBER(fx_plot_window_map)) + +fx_plot_window::fx_plot_window(FXApp* app, const FXString& name, FXIcon *ic, FXIcon *mi, FXint w, FXint h): + FXMainWindow(app, name, ic, mi, DECOR_ALL, 0, 0, w, h) +{ + m_menu_bar = new FXMenuBar(this, LAYOUT_SIDE_TOP|LAYOUT_FILL_X); + + m_plot_menu = new FXMenuPane(this); + new FXMenuCommand(m_plot_menu, "&Close\tCtl-C", NULL, app, FXApp::ID_QUIT); + new FXMenuTitle(m_menu_bar, "&Plot", NULL, m_plot_menu); + + FXVerticalFrame* frame = new FXVerticalFrame(this, LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y); + + // Sunken border for text widget + FXHorizontalFrame *cbox = new FXHorizontalFrame(frame, FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0, 0,0,0,0); + + m_canvas = new fx_plot_canvas(cbox, NULL, 0, LAYOUT_FILL_X|LAYOUT_FILL_Y); +} diff --git a/fox-gui/fx_plot_window.h b/fox-gui/fx_plot_window.h new file mode 100644 index 00000000..ece75f29 --- /dev/null +++ b/fox-gui/fx_plot_window.h @@ -0,0 +1,29 @@ +#ifndef FOXGUI_FX_PLOT_WINDOW_H +#define FOXGUI_FX_PLOT_WINDOW_H + +#include <fx.h> + +#include "fx_plot_canvas.h" + +class fx_plot_window : public FXMainWindow { + FXDECLARE(fx_plot_window) +public: + fx_plot_window(FXApp* a, const FXString& name, FXIcon *ic=NULL, FXIcon *mi=NULL, FXint w=0, FXint h=0); + + ~fx_plot_window() + { + delete m_plot_menu; + } + + fx_plot_canvas& canvas() { return *m_canvas; } + +protected: + fx_plot_window() {} + +private: + FXMenuBar* m_menu_bar; + FXMenuPane* m_plot_menu; + fx_plot_canvas* m_canvas; +}; + +#endif diff --git a/fox-gui/lua_plot_window.cpp b/fox-gui/lua_plot_window.cpp new file mode 100644 index 00000000..061b95bb --- /dev/null +++ b/fox-gui/lua_plot_window.cpp @@ -0,0 +1,88 @@ + +extern "C" { +#include "lua.h" +#include "lauxlib.h" +} + +#include "lua_plot_window.h" +#include "fx_plot_window.h" +#include "lua-cpp-utils.h" +#include "gs-types.h" +#include "plot.h" + +__BEGIN_DECLS + +static int fox_window_new (lua_State *L); +static int fox_window_free (lua_State *L); +static int fox_window_close (lua_State *L); +static int fox_window_attach (lua_State *L); + +static const struct luaL_Reg fox_window_functions[] = { + {"window", fox_window_new}, + {NULL, NULL} +}; + +static const struct luaL_Reg fox_window_methods[] = { + {"attach", fox_window_attach }, + {"close", fox_window_close }, + {"__gc", fox_window_free }, + {NULL, NULL} +}; + +__END_DECLS + +typedef plot<sg_object, manage_owner> sg_plot; + +int +fox_window_new (lua_State *L) +{ + lua_getfield(L, LUA_REGISTRYINDEX, "__fox_app"); + FXApp* app = (FXApp*) lua_touserdata(L, -1); + lua_pop(L, 1); + + if (unlikely(app == NULL)) + return luaL_error(L, "cannot create window: FOX application not found"); + + fx_plot_window* win = new(L, GS_FOX_WINDOW) fx_plot_window(app, "GSL Shell FX plot", NULL, NULL, 640, 480); + + win->create(); + win->show(PLACEMENT_SCREEN); + + return 1; +} + +int +fox_window_free (lua_State *L) +{ + fx_plot_window *win = object_check<fx_plot_window>(L, 1, GS_FOX_WINDOW); + win->~fx_plot_window(); + return 0; +} + +int +fox_window_attach (lua_State *L) +{ + fx_plot_window *win = object_check<fx_plot_window>(L, 1, GS_FOX_WINDOW); + sg_plot* p = object_check<sg_plot>(L, 2, GS_PLOT); + win->canvas().attach(p); + return 0; +} + +int +fox_window_close (lua_State *L) +{ + return 0; +} + +int +fox_window_register (lua_State *L) +{ + luaL_newmetatable (L, GS_METATABLE(GS_FOX_WINDOW)); + lua_pushvalue (L, -1); + lua_setfield (L, -2, "__index"); + luaL_register (L, NULL, fox_window_methods); + lua_pop (L, 1); + + luaL_register (L, "fox", fox_window_functions); + return 0; +} diff --git a/fox-gui/lua_plot_window.h b/fox-gui/lua_plot_window.h new file mode 100644 index 00000000..d6888543 --- /dev/null +++ b/fox-gui/lua_plot_window.h @@ -0,0 +1,14 @@ +#ifndef FOXGUI_FOX_WINDOW_H +#define FOXGUI_FOX_WINDOW_H + +#include "defs.h" + +__BEGIN_DECLS + +#include "lua.h" + +extern int fox_window_register (lua_State *L); + +__END_DECLS + +#endif diff --git a/lua-gsl/gs-types.c b/lua-gsl/gs-types.c index 4d56cabe..3f6b68a6 100644 --- a/lua-gsl/gs-types.c +++ b/lua-gsl/gs-types.c @@ -9,6 +9,7 @@ #include <math.h> #define GS_WINDOW_NAME_DEF "GSL.window" +#define GS_FOX_WINDOW_NAME_DEF "GSL.FOXwindow" #define GS_DRAW_SCALABLE_NAME_DEF NULL #define GS_DRAW_PATH_NAME_DEF "GSL.path" #define GS_DRAW_ELLIPSE_NAME_DEF "GSL.ellipse" @@ -27,6 +28,7 @@ #define MY_EXPAND_DER(NM,DESCR,BASE) {MYCAT2(GS,NM), MYCAT3(GS,NM,NAME_DEF), DESCR, MYCAT2(GS,BASE)} const struct gs_type gs_type_table[] = { + MY_EXPAND(FOX_WINDOW, "FOX graphical window"), MY_EXPAND(WINDOW, "graphical window"), MY_EXPAND(DRAW_SCALABLE, "graphical object"), MY_EXPAND_DER(DRAW_PATH, "geometric line", DRAW_SCALABLE), diff --git a/lua-gsl/gs-types.h b/lua-gsl/gs-types.h index ed90f8c0..5437696f 100644 --- a/lua-gsl/gs-types.h +++ b/lua-gsl/gs-types.h @@ -11,6 +11,7 @@ __BEGIN_DECLS enum gs_type_e { GS_NO_TYPE = -1, GS_WINDOW = 0, + GS_FOX_WINDOW, GS_DRAW_SCALABLE, /* derived types are declared only after their base class */ GS_DRAW_PATH, GS_DRAW_ELLIPSE, |