author | francesco-ST <francesco.abbate@st.com> | 2010年10月26日 14:22:07 +0200 |
---|---|---|
committer | francesco-ST <francesco.abbate@st.com> | 2010年10月26日 14:22:07 +0200 |
commit | 7e665c04ea2063264a6415bfbd03ae0de2da0bcd (patch) | |
tree | 93667d65eff9d3e910cfb25edcd0c98a6c875f1f /agg-plot | |
parent | 071e8359e6c9019b3f3ddc41d8185d391458906b (diff) | |
download | gsl-shell-7e665c04ea2063264a6415bfbd03ae0de2da0bcd.tar.gz |
-rw-r--r-- | agg-plot/window-cpp.h | 11 | ||||
-rw-r--r-- | agg-plot/window.cpp | 47 |
diff --git a/agg-plot/window-cpp.h b/agg-plot/window-cpp.h index 1af65010..0bb13e91 100644 --- a/agg-plot/window-cpp.h +++ b/agg-plot/window-cpp.h @@ -18,6 +18,11 @@ extern "C" { class window : public canvas_window { public: + enum error_e { + invalid_split_string, + invalid_slot, + }; + typedef plot<drawable, lua_management> plot_type; typedef agg::trans_affine bmatrix; @@ -62,12 +67,12 @@ private: public: window(agg::rgba& bgcol) : canvas_window(bgcol), m_tree(0) { - this->split("."); + this->split("."); }; ~window() { if (m_tree) delete m_tree; }; - void split(const char *spec); + bool split(const char *spec); int attach(lua_plot *plot, const char *spec); void draw_slot(int slot_id, bool update_req); void refresh_slot(int slot_id); @@ -84,4 +89,6 @@ public: virtual void on_draw(); virtual void on_resize(int sx, int sy); + + static const char * error_message(error_e code); }; diff --git a/agg-plot/window.cpp b/agg-plot/window.cpp index a2501c25..ef5fd42b 100644 --- a/agg-plot/window.cpp +++ b/agg-plot/window.cpp @@ -293,17 +293,24 @@ window::cleanup_tree_rec (lua_State *L, int window_index, ref::node* n) } } -void +bool window::split(const char *spec) { - if (m_tree) - delete m_tree; - ::split<ref>::lexer lexbuf(spec); - m_tree = ::split<ref>::parse(lexbuf); + tree::node<ref, direction_e> *new_tree = ::split<ref>::parse(lexbuf); + + if (new_tree) + { + if (m_tree) + delete m_tree; + + m_tree = new_tree; + bmatrix m0; + ref::calculate(m_tree, m0, 0); + return true; + } - bmatrix m0; - ref::calculate(m_tree, m0, 0); + return false; } static const char * @@ -360,6 +367,22 @@ int window::attach(lua_plot *plot, const char *spec) return r->slot_id; } +const char * +window::error_message(window::error_e code) +{ + switch (code) + { + case invalid_split_string: + return "invalid window subdivision specification"; + case invalid_slot: + return "invalid slot specification"; + default: + ; + } + return "unknown error"; +} + + typedef void (window::*window_slot_method_type)(int slot_id); int window_generic_oper (lua_State *L, window_slot_method_type method) @@ -406,6 +429,7 @@ window_new (lua_State *L) if (spec) { win->split(spec); + // return luaL_error(L, window::error_message(window::invalid_split_string)); } return 1; @@ -434,7 +458,12 @@ window_split (lua_State *L) win->lock(); win->cleanup_refs(L, 1); - win->split(spec); + if (!win->split(spec)) + { + win->do_window_update(); + win->unlock(); + return luaL_error(L, window::error_message(window::invalid_split_string)); + } win->on_draw(); win->do_window_update(); @@ -463,7 +492,7 @@ window_attach (lua_State *L) else { win->unlock(); - luaL_error (L, "invalid slot"); + luaL_error (L, window::error_message(window::invalid_slot)); } return 0; |