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:
Diffstat (limited to 'agg-plot')
-rw-r--r--agg-plot/agg-parse-trans.cpp 89
-rw-r--r--agg-plot/agg-parse-trans.h 30
-rw-r--r--agg-plot/agg_platform_support_win32.cpp 58
-rw-r--r--agg-plot/bitmap-plot.cpp 43
-rw-r--r--agg-plot/lua-cpp-utils.h 23
-rw-r--r--agg-plot/lua-draw.cpp 11
-rw-r--r--agg-plot/lua-plot.cpp 28
-rw-r--r--agg-plot/window.cpp 17
8 files changed, 116 insertions, 183 deletions
diff --git a/agg-plot/agg-parse-trans.cpp b/agg-plot/agg-parse-trans.cpp
index 5363ac66..4ae1cdbc 100644
--- a/agg-plot/agg-parse-trans.cpp
+++ b/agg-plot/agg-parse-trans.cpp
@@ -41,14 +41,6 @@ struct property_reg line_join_properties[] = {
{0, NULL}
};
-const char *agg_spec_error::m_msg[] = {
- "invalid specification tag",
- "invalid specification table",
- "missing specification parameter",
- "invalid graphical object",
- "generic error during graphical operation"
-};
-
static int
property_lookup (struct property_reg *prop, const char *key)
{
@@ -167,14 +159,16 @@ sg_object* build_scale (lua_State *L, int specindex, sg_object* src)
{
lua_rawgeti (L, specindex, 2);
- if (! lua_isnumber (L, -1))
- throw agg_spec_error(agg_spec_error::missing_parameter);
+ if (lua_isnumber (L, -1))
+ {
+ double s = luaL_optnumber (L, -1, 1.0);
+ lua_pop (L, 1);
- double s = lua_tonumber (L, -1);
- lua_pop (L, 1);
+ agg::trans_affine mtx(s, 0.0, 0.0, s, 0.0, 0.0);
+ return affine_object_compose(src, mtx);
+ }
- agg::trans_affine mtx(s, 0.0, 0.0, s, 0.0, 0.0);
- return affine_object_compose(src, mtx);
+ return src;
}
sg_object* build_rotate (lua_State *L, int specindex, sg_object* src)
@@ -224,85 +218,100 @@ const builder::reg builder::builder_table[] = {
{NULL, NULL}
};
-sg_object* parse_spec (lua_State *L, int specindex, sg_object* src)
+sg_object* parse_spec (lua_State *L, int specindex, sg_object* src,
+ gslshell::ret_status& st)
{
const char *tag;
INDEX_SET_ABS(L, specindex);
if (lua_type (L, specindex) != LUA_TTABLE)
- throw agg_spec_error(agg_spec_error::invalid_spec);
+ {
+ st.error("invalid specification table", "plot add");
+ return 0;
+ }
lua_rawgeti (L, specindex, 1);
- if (! lua_isstring (L, -1))
- throw agg_spec_error(agg_spec_error::invalid_tag);
-
tag = lua_tostring (L, -1);
lua_pop (L, 1);
+ if (!tag)
+ {
+ st.error("invalid specification tag", "plot add");
+ return 0;
+ }
+
builder::func_type* f = builder::lookup(tag);
- if (f == 0) throw agg_spec_error(agg_spec_error::invalid_tag);
+ if (f == 0)
+ {
+ st.error("invalid specification tag", "plot add");
+ return 0;
+ }
return f(L, specindex, src);
}
-sg_object* parse_spec_pipeline (lua_State* L, int index, sg_object* obj)
+sg_object* parse_spec_pipeline (lua_State* L, int index, sg_object* src,
+ gslshell::ret_status& st)
{
if (lua_type (L, index) != LUA_TTABLE)
- throw agg_spec_error(agg_spec_error::invalid_spec);
+ {
+ st.error("invalid specification table", "plot add");
+ return 0;
+ }
size_t k, nb = lua_objlen (L, index);
- for (k = nb; k > 0; k--)
+ sg_object* obj = src;
+ for (k = nb; k > 0 && src; k--, src = obj)
{
lua_rawgeti (L, index, k);
- obj = parse_spec(L, -1, obj);
+ obj = parse_spec(L, -1, src, st);
+ if (obj == 0)
+ delete src;
lua_pop (L, 1);
}
return obj;
}
-sg_object* parse_graph_args (lua_State *L, agg::rgba8& color)
+sg_object* parse_graph_args (lua_State *L, agg::rgba8& color,
+ gslshell::ret_status& st)
{
color = color_arg_lookup (L, 3);
- std::auto_ptr<sg_object> wobj;
+ sg_object* wobj;
if (gs_is_userdata (L, 2, GS_DRAW_SCALABLE))
{
sg_object* vs = (sg_object*) lua_touserdata (L, 2);
- std::auto_ptr<sg_object> sobj(new sg_object_ref<manage_not_owner>(vs));
+ sg_object* sobj = new sg_object_ref<manage_not_owner>(vs);
if (! lua_isnoneornil (L, 5))
{
- sg_object* st = parse_spec_pipeline(L, 5, sobj.get());
- sobj.release();
- sobj = std::auto_ptr<sg_object>(st);
+ sobj = parse_spec_pipeline(L, 5, sobj, st);
+ if (!sobj)
+ return 0;
}
-
- sg_object* ws = new trans::scaling(sobj.get());
- sobj.release();
- wobj = std::auto_ptr<sg_object>(ws);
+ wobj = new trans::scaling(sobj);
}
else if (gs_is_userdata (L, 2, GS_DRAW_DRAWABLE))
{
sg_object* vs = (sg_object*) lua_touserdata (L, 2);
- wobj = std::auto_ptr<sg_object>(new sg_object_ref<manage_not_owner>(vs));
+ wobj = new sg_object_ref<manage_not_owner>(vs);
}
else
{
- throw agg_spec_error(agg_spec_error::invalid_object);
+ st.error("invalid graphical object", "plot add");
+ return 0;
}
- sg_object* w = wobj.get();
if (! lua_isnoneornil (L, 4))
{
- w = parse_spec_pipeline(L, 4, w);
+ wobj = parse_spec_pipeline(L, 4, wobj, st);
}
- wobj.release();
- return w;
+ return wobj;
}
diff --git a/agg-plot/agg-parse-trans.h b/agg-plot/agg-parse-trans.h
index 2e8c8bfb..58a172f5 100644
--- a/agg-plot/agg-parse-trans.h
+++ b/agg-plot/agg-parse-trans.h
@@ -5,35 +5,11 @@ extern "C" {
#include "lua.h"
}
-#include <exception>
-
+#include "lua-cpp-utils.h"
#include "sg_object.h"
#include "agg_color_rgba.h"
-class agg_spec_error : public std::exception {
-public:
- enum err_e {
- invalid_tag = 0,
- invalid_spec,
- missing_parameter,
- invalid_object,
- generic_error
- };
-
- agg_spec_error(enum err_e err) : m_code(err) {};
- agg_spec_error() : m_code(generic_error) {};
-
- virtual const char* what() const throw()
- {
- return m_msg[(int) m_code];
- }
-
-private:
- err_e m_code;
-
- static const char *m_msg[];
-};
-
-extern sg_object* parse_graph_args (lua_State *L, agg::rgba8& color);
+extern sg_object* parse_graph_args (lua_State *L, agg::rgba8& color,
+ gslshell::ret_status& st);
#endif
diff --git a/agg-plot/agg_platform_support_win32.cpp b/agg-plot/agg_platform_support_win32.cpp
index dbda9a80..112e5435 100644
--- a/agg-plot/agg_platform_support_win32.cpp
+++ b/agg-plot/agg_platform_support_win32.cpp
@@ -306,20 +306,12 @@ namespace agg
//--------------------------------------------------------------------
case WM_SIZE:
- try
- {
- app->m_specific->create_pmap(LOWORD(lParam), HIWORD(lParam),
- &app->rbuf_window());
-
- app->trans_affine_resizing(LOWORD(lParam), HIWORD(lParam));
- app->on_resize(LOWORD(lParam), HIWORD(lParam));
- app->force_redraw();
- }
- catch (std::bad_alloc&)
- {
- ::PostQuitMessage(1);
- }
+ app->m_specific->create_pmap(LOWORD(lParam), HIWORD(lParam),
+ &app->rbuf_window());
+ app->trans_affine_resizing(LOWORD(lParam), HIWORD(lParam));
+ app->on_resize(LOWORD(lParam), HIWORD(lParam));
+ app->force_redraw();
app->m_specific->m_is_ready = false;
break;
@@ -423,32 +415,24 @@ namespace agg
return false;
}
+ RECT rct;
+ ::GetClientRect(m_specific->m_hwnd, &rct);
- try
- {
- RECT rct;
- ::GetClientRect(m_specific->m_hwnd, &rct);
-
- ::MoveWindow(m_specific->m_hwnd, // handle to window
- 100, // horizontal position
- 100, // vertical position
- width + (width - (rct.right - rct.left)),
- height + (height - (rct.bottom - rct.top)),
- FALSE);
+ ::MoveWindow(m_specific->m_hwnd, // handle to window
+ 100, // horizontal position
+ 100, // vertical position
+ width + (width - (rct.right - rct.left)),
+ height + (height - (rct.bottom - rct.top)),
+ FALSE);
- ::SetWindowLong(m_specific->m_hwnd, GWL_USERDATA, (LONG)this);
- m_specific->create_pmap(width, height, &m_rbuf_window);
- m_initial_width = width;
- m_initial_height = height;
- on_init();
- m_specific->m_redraw_flag = true;
- ::ShowWindow(m_specific->m_hwnd, g_windows_cmd_show);
- ::SetForegroundWindow(m_specific->m_hwnd);
- }
- catch (std::bad_alloc&)
- {
- return false;
- }
+ ::SetWindowLong(m_specific->m_hwnd, GWL_USERDATA, (LONG)this);
+ m_specific->create_pmap(width, height, &m_rbuf_window);
+ m_initial_width = width;
+ m_initial_height = height;
+ on_init();
+ m_specific->m_redraw_flag = true;
+ ::ShowWindow(m_specific->m_hwnd, g_windows_cmd_show);
+ ::SetForegroundWindow(m_specific->m_hwnd);
return true;
}
diff --git a/agg-plot/bitmap-plot.cpp b/agg-plot/bitmap-plot.cpp
index ec92f131..5807c74e 100644
--- a/agg-plot/bitmap-plot.cpp
+++ b/agg-plot/bitmap-plot.cpp
@@ -15,32 +15,35 @@ extern "C" {
void
bitmap_save_image_cpp (sg_plot *p, const char *fn, unsigned w, unsigned h,
- gslshell::ret_status& st)
+ gslshell::ret_status& st)
{
- try {
- agg::rendering_buffer rbuf_tmp;
- unsigned row_size = w * (gslshell::bpp / 8);
- unsigned buf_size = h * row_size;
- agg::pod_array<unsigned char> buffer(buf_size);
- rbuf_tmp.attach(buffer.data(), w, h, gslshell::flip_y ? row_size : -row_size);
+ agg::rendering_buffer rbuf_tmp;
+ unsigned row_size = w * (gslshell::bpp / 8);
+ unsigned buf_size = h * row_size;
- canvas can(rbuf_tmp, w, h, colors::white);
- agg::trans_affine mtx(w, 0.0, 0.0, h, 0.0, 0.0);
+ unsigned char* buffer = new(std::nothrow) unsigned char[buf_size];
+ if (!buffer)
+ {
+ st.error("cannot allocate memory", "plot save");
+ return;
+ }
+
+ rbuf_tmp.attach(buffer, w, h, gslshell::flip_y ? row_size : -row_size);
+
+ canvas can(rbuf_tmp, w, h, colors::white);
+ agg::trans_affine mtx(w, 0.0, 0.0, h, 0.0, 0.0);
- agg::rect_base<int> r = rect_of_slot_matrix<int>(mtx);
- can.clear_box(r);
+ agg::rect_base<int> r = rect_of_slot_matrix<int>(mtx);
+ can.clear_box(r);
- p->draw(can, mtx);
+ p->draw(can, mtx);
- bool success = platform_support_ext::save_image_file (rbuf_tmp, fn);
+ bool success = platform_support_ext::save_image_file (rbuf_tmp, fn);
- if (! success)
- st.error("cannot save image file", "plot save");
- }
- catch (std::exception& e)
- {
- st.error(e.what(), "plot save");
- }
+ if (! success)
+ st.error("cannot save image file", "plot save");
+
+ delete [] buffer;
}
int
diff --git a/agg-plot/lua-cpp-utils.h b/agg-plot/lua-cpp-utils.h
index b2d506a5..7111aa5f 100644
--- a/agg-plot/lua-cpp-utils.h
+++ b/agg-plot/lua-cpp-utils.h
@@ -1,7 +1,6 @@
#ifndef LUA_CPP_UTILS_H
#define LUA_CPP_UTILS_H
-#include <exception>
#include <new>
#include "defs.h"
@@ -45,31 +44,13 @@ inline void* operator new(size_t nbytes, lua_State *L, enum gs_type_e tp)
template <class T>
T* push_new_object (lua_State *L, enum gs_type_e tp)
{
- try
- {
- return new(L, tp) T();
- }
- catch (std::bad_alloc&)
- {
- luaL_error (L, "out of memory");
- }
-
- return 0;
+ return new(L, tp) T();
}
template <class T, class init_type>
T* push_new_object (lua_State *L, enum gs_type_e tp, init_type& init)
{
- try
- {
- return new(L, tp) T(init);
- }
- catch (std::bad_alloc&)
- {
- luaL_error (L, "out of memory");
- }
-
- return 0;
+ return new(L, tp) T(init);
}
template <class T>
diff --git a/agg-plot/lua-draw.cpp b/agg-plot/lua-draw.cpp
index d533e745..ea1e8f61 100644
--- a/agg-plot/lua-draw.cpp
+++ b/agg-plot/lua-draw.cpp
@@ -182,16 +182,7 @@ agg_path_cmd (lua_State *L)
}
pthread_mutex_lock (agg_mutex);
- try
- {
- path_cmd (p, id, s);
- }
- catch (std::bad_alloc&)
- {
- pthread_mutex_unlock (agg_mutex);
- luaL_error (L, "out of memory");
- return 0;
- }
+ path_cmd (p, id, s);
pthread_mutex_unlock (agg_mutex);
return 0;
}
diff --git a/agg-plot/lua-plot.cpp b/agg-plot/lua-plot.cpp
index 252b2c56..8ea2ab81 100644
--- a/agg-plot/lua-plot.cpp
+++ b/agg-plot/lua-plot.cpp
@@ -165,23 +165,19 @@ plot_free (lua_State *L)
void
plot_add_gener_cpp (lua_State *L, sg_plot *p, bool as_line,
- gslshell::ret_status& st)
+ gslshell::ret_status& st)
{
- try {
- agg::rgba8 color;
- sg_object* obj = parse_graph_args(L, color);
-
- AGG_LOCK();
- p->add(obj, color, as_line);
- AGG_UNLOCK();
-
- if (p->sync_mode())
- plot_flush (L);
- }
- catch (std::exception& e)
- {
- st.error(e.what(), "plot add or addline");
- }
+ agg::rgba8 color;
+ sg_object* obj = parse_graph_args(L, color, st);
+
+ if (!obj) return;
+
+ AGG_LOCK();
+ p->add(obj, color, as_line);
+ AGG_UNLOCK();
+
+ if (p->sync_mode())
+ plot_flush (L);
}
static void
diff --git a/agg-plot/window.cpp b/agg-plot/window.cpp
index 02aeab85..7625b73e 100644
--- a/agg-plot/window.cpp
+++ b/agg-plot/window.cpp
@@ -159,11 +159,7 @@ void window::draw_slot_by_ref(window::ref& ref, bool draw_image)
if (ref.plot)
{
AGG_LOCK();
- try
- {
ref.plot->draw(*m_canvas, mtx);
- }
- catch (std::bad_alloc&) { }
AGG_UNLOCK();
}
@@ -242,14 +238,11 @@ window::refresh_slot_by_ref(ref& ref, bool draw_all)
rect.set(rect_of_slot_matrix<double>(mtx));
AGG_LOCK();
- try {
- opt_rect<double> draw_rect;
- ref.plot->draw_queue(*m_canvas, mtx, draw_rect);
- rect.add<rect_union>(draw_rect);
- rect.add<rect_union>(ref.dirty_rect);
- ref.dirty_rect = draw_rect;
- }
- catch (std::bad_alloc&) { }
+ opt_rect<double> draw_rect;
+ ref.plot->draw_queue(*m_canvas, mtx, draw_rect);
+ rect.add<rect_union>(draw_rect);
+ rect.add<rect_union>(ref.dirty_rect);
+ ref.dirty_rect = draw_rect;
AGG_UNLOCK();
if (rect.is_defined())
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月16日 15:05:10 +0000

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