gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/agg-plot/lua-draw.cpp
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2012年10月15日 13:11:54 +0200
committerFrancesco Abbate <francesco.bbt@gmail.com>2012年10月15日 13:11:54 +0200
commit137e4d264c73b3087a5d0968362c5b9ca3108f2d (patch)
treea80691d187615ec2e63f25182be7895b9a8a313f /agg-plot/lua-draw.cpp
parent7d157c5bd8ddf920094907a35c9329ce0688e3d4 (diff)
downloadgsl-shell-137e4d264c73b3087a5d0968362c5b9ca3108f2d.tar.gz
Using AStyle of all the C and C++ source and header files
Using default AStyle formatting, "allman" style.
Diffstat (limited to 'agg-plot/lua-draw.cpp')
-rw-r--r--agg-plot/lua-draw.cpp 287
1 files changed, 144 insertions, 143 deletions
diff --git a/agg-plot/lua-draw.cpp b/agg-plot/lua-draw.cpp
index 0add8765..7181dfb2 100644
--- a/agg-plot/lua-draw.cpp
+++ b/agg-plot/lua-draw.cpp
@@ -36,23 +36,23 @@ extern "C" {
#include "sg_marker.h"
enum path_cmd_e {
- CMD_MOVE_TO = 0,
- CMD_LINE_TO,
- CMD_CLOSE,
- CMD_ARC_TO,
- CMD_CURVE3,
- CMD_CURVE4,
- CMD_ERROR,
+ CMD_MOVE_TO = 0,
+ CMD_LINE_TO,
+ CMD_CLOSE,
+ CMD_ARC_TO,
+ CMD_CURVE3,
+ CMD_CURVE4,
+ CMD_ERROR,
};
struct cmd_call_stack {
- double f[6];
- int b[2];
+ double f[6];
+ int b[2];
};
struct path_cmd_reg {
- const char *cmd;
- const char *signature;
+ const char *cmd;
+ const char *signature;
};
static int agg_path_free (lua_State *L);
@@ -70,257 +70,258 @@ static int marker_free (lua_State *L);
static void path_cmd (draw::path *p, int cmd, struct cmd_call_stack *stack);
static struct path_cmd_reg cmd_table[] = {
- {"move_to", "ff"},
- {"line_to", "ff"},
- {"close", ""},
- {"arc_to", "fffbbff"},
- {"curve3", "ffff"},
- {"curve4", "ffffff"},
- {NULL, NULL}
+ {"move_to", "ff"},
+ {"line_to", "ff"},
+ {"close", ""},
+ {"arc_to", "fffbbff"},
+ {"curve3", "ffff"},
+ {"curve4", "ffffff"},
+ {NULL, NULL}
};
static const struct luaL_Reg draw_functions[] = {
- {"path", agg_path_new},
- {"ellipse", agg_ellipse_new},
- {"circle", agg_circle_new},
- {"textshape", textshape_new},
- {"marker", marker_new},
- {NULL, NULL}
+ {"path", agg_path_new},
+ {"ellipse", agg_ellipse_new},
+ {"circle", agg_circle_new},
+ {"textshape", textshape_new},
+ {"marker", marker_new},
+ {NULL, NULL}
};
static const struct luaL_Reg agg_path_methods[] = {
- {"__gc", agg_path_free},
- {NULL, NULL}
+ {"__gc", agg_path_free},
+ {NULL, NULL}
};
static const struct luaL_Reg textshape_methods[] = {
- {"__gc", textshape_free},
- {NULL, NULL}
+ {"__gc", textshape_free},
+ {NULL, NULL}
};
static const struct luaL_Reg agg_ellipse_methods[] = {
- {"__gc", agg_ellipse_free},
- {NULL, NULL}
+ {"__gc", agg_ellipse_free},
+ {NULL, NULL}
};
static const struct luaL_Reg marker_methods[] = {
- {"__gc", marker_free},
- {NULL, NULL}
+ {"__gc", marker_free},
+ {NULL, NULL}
};
int
agg_path_new (lua_State *L)
{
- draw::path *vs = push_new_object<draw::path>(L, GS_DRAW_PATH);
+ draw::path *vs = push_new_object<draw::path>(L, GS_DRAW_PATH);
- if (lua_gettop (L) >= 2)
+ if (lua_gettop (L) >= 2)
{
- double x = gs_check_number (L, 1, FP_CHECK_NORMAL);
- double y = gs_check_number (L, 2, FP_CHECK_NORMAL);
- struct cmd_call_stack s[1];
+ double x = gs_check_number (L, 1, FP_CHECK_NORMAL);
+ double y = gs_check_number (L, 2, FP_CHECK_NORMAL);
+ struct cmd_call_stack s[1];
- s->f[0] = x;
- s->f[1] = y;
+ s->f[0] = x;
+ s->f[1] = y;
- path_cmd (vs, CMD_MOVE_TO, s);
+ path_cmd (vs, CMD_MOVE_TO, s);
}
- return 1;
+ return 1;
}
draw::path *
check_agg_path (lua_State *L, int index)
{
- return (draw::path *) gs_check_userdata (L, index, GS_DRAW_PATH);
+ return (draw::path *) gs_check_userdata (L, index, GS_DRAW_PATH);
}
int
agg_path_free (lua_State *L)
{
- return object_free<draw::path>(L, 1, GS_DRAW_PATH);
+ return object_free<draw::path>(L, 1, GS_DRAW_PATH);
}
void
path_cmd (draw::path *p, int _cmd, struct cmd_call_stack *s)
{
- agg::path_storage& ps = p->self();
- path_cmd_e cmd = (path_cmd_e) _cmd;
+ agg::path_storage& ps = p->self();
+ path_cmd_e cmd = (path_cmd_e) _cmd;
- switch (cmd)
+ switch (cmd)
{
case CMD_MOVE_TO:
- ps.move_to (s->f[0], s->f[1]);
- break;
- case CMD_LINE_TO:
- if (ps.total_vertices() == 0)
ps.move_to (s->f[0], s->f[1]);
- else
- ps.line_to (s->f[0], s->f[1]);
- break;
+ break;
+ case CMD_LINE_TO:
+ if (ps.total_vertices() == 0)
+ ps.move_to (s->f[0], s->f[1]);
+ else
+ ps.line_to (s->f[0], s->f[1]);
+ break;
case CMD_CLOSE:
- ps.close_polygon ();
- break;
+ ps.close_polygon ();
+ break;
case CMD_ARC_TO:
- ps.arc_to (s->f[0], s->f[1], s->f[2], s->b[0], s->b[1], s->f[3], s->f[4]);
- break;
+ ps.arc_to (s->f[0], s->f[1], s->f[2], s->b[0], s->b[1], s->f[3], s->f[4]);
+ break;
case CMD_CURVE3:
- ps.curve3 (s->f[0], s->f[1], s->f[2], s->f[3]);
- break;
+ ps.curve3 (s->f[0], s->f[1], s->f[2], s->f[3]);
+ break;
case CMD_CURVE4:
- ps.curve4 (s->f[0], s->f[1], s->f[2], s->f[3], s->f[4], s->f[5]);
- break;
+ ps.curve4 (s->f[0], s->f[1], s->f[2], s->f[3], s->f[4], s->f[5]);
+ break;
default:
- /* */;
+ /* */
+ ;
}
}
static int
agg_path_cmd (lua_State *L)
{
- draw::path *p = check_agg_path (L, 1);
- int id = lua_tointeger (L, lua_upvalueindex(1));
+ draw::path *p = check_agg_path (L, 1);
+ int id = lua_tointeger (L, lua_upvalueindex(1));
- assert(id >= 0 && id < CMD_ERROR);
+ assert(id >= 0 && id < CMD_ERROR);
- path_cmd_reg* cmd = cmd_table + id;
- const char *signature = cmd->signature;
- int argc = 2, f_count = 0, b_count = 0;
- struct cmd_call_stack s[1];
- const char *fc;
+ path_cmd_reg* cmd = cmd_table + id;
+ const char *signature = cmd->signature;
+ int argc = 2, f_count = 0, b_count = 0;
+ struct cmd_call_stack s[1];
+ const char *fc;
- for (fc = signature; fc[0]; fc++)
+ for (fc = signature; fc[0]; fc++)
{
- switch (fc[0])
+ switch (fc[0])
{
case 'f':
- s->f[f_count++] = gs_check_number (L, argc++, FP_CHECK_NORMAL);
- break;
+ s->f[f_count++] = gs_check_number (L, argc++, FP_CHECK_NORMAL);
+ break;
case 'b':
- if (lua_isboolean (L, argc))
- s->b[b_count++] = lua_toboolean (L, argc++);
- else
- return luaL_error (L, "expected boolean for argument #%i", argc);
+ if (lua_isboolean (L, argc))
+ s->b[b_count++] = lua_toboolean (L, argc++);
+ else
+ return luaL_error (L, "expected boolean for argument #%i", argc);
}
}
- pthread_mutex_lock (agg_mutex);
- path_cmd (p, id, s);
- pthread_mutex_unlock (agg_mutex);
- return 0;
+ pthread_mutex_lock (agg_mutex);
+ path_cmd (p, id, s);
+ pthread_mutex_unlock (agg_mutex);
+ return 0;
}
int
agg_ellipse_new (lua_State *L)
{
- draw::ellipse *vs = push_new_object<draw::ellipse>(L, GS_DRAW_ELLIPSE);
- double x = luaL_checknumber (L, 1);
- double y = luaL_checknumber (L, 2);
- double rx = luaL_checknumber (L, 3);
- double ry = luaL_checknumber (L, 4);
- vs->self().init(x, y, rx, ry, 0, false);
- return 1;
+ draw::ellipse *vs = push_new_object<draw::ellipse>(L, GS_DRAW_ELLIPSE);
+ double x = luaL_checknumber (L, 1);
+ double y = luaL_checknumber (L, 2);
+ double rx = luaL_checknumber (L, 3);
+ double ry = luaL_checknumber (L, 4);
+ vs->self().init(x, y, rx, ry, 0, false);
+ return 1;
}
int
agg_circle_new (lua_State *L)
{
- draw::ellipse *vs = push_new_object<draw::ellipse>(L, GS_DRAW_ELLIPSE);
- double x = luaL_checknumber (L, 1);
- double y = luaL_checknumber (L, 2);
- double r = luaL_checknumber (L, 3);
- vs->self().init(x, y, r, r, 0, false);
- return 1;
+ draw::ellipse *vs = push_new_object<draw::ellipse>(L, GS_DRAW_ELLIPSE);
+ double x = luaL_checknumber (L, 1);
+ double y = luaL_checknumber (L, 2);
+ double r = luaL_checknumber (L, 3);
+ vs->self().init(x, y, r, r, 0, false);
+ return 1;
}
int
agg_ellipse_free (lua_State *L)
{
- return object_free<draw::ellipse>(L, 1, GS_DRAW_ELLIPSE);
+ return object_free<draw::ellipse>(L, 1, GS_DRAW_ELLIPSE);
}
int
textshape_new (lua_State *L)
{
- double x = luaL_checknumber(L, 1);
- double y = luaL_checknumber(L, 2);
- const char* text = luaL_checkstring(L, 3);
- double ts = luaL_checknumber(L, 4);
- new(L, GS_DRAW_TEXTSHAPE) draw::text_shape(x, y, text, ts);
- return 1;
+ double x = luaL_checknumber(L, 1);
+ double y = luaL_checknumber(L, 2);
+ const char* text = luaL_checkstring(L, 3);
+ double ts = luaL_checknumber(L, 4);
+ new(L, GS_DRAW_TEXTSHAPE) draw::text_shape(x, y, text, ts);
+ return 1;
}
int
textshape_free (lua_State *L)
{
- return object_free<draw::text_shape>(L, 1, GS_DRAW_TEXTSHAPE);
+ return object_free<draw::text_shape>(L, 1, GS_DRAW_TEXTSHAPE);
}
int
marker_new (lua_State *L)
{
- const double x = luaL_checknumber(L, 1);
- const double y = luaL_checknumber(L, 2);
- const char *sym_name = luaL_optstring(L, 3, "");
- const double size = luaL_optnumber(L, 4, 5.0);
+ const double x = luaL_checknumber(L, 1);
+ const double y = luaL_checknumber(L, 2);
+ const char *sym_name = luaL_optstring(L, 3, "");
+ const double size = luaL_optnumber(L, 4, 5.0);
- bool stroke;
- sg_object* sym = new_marker_symbol_raw(sym_name, stroke);
- draw::marker* marker = new draw::marker(x, y, sym, size);
+ bool stroke;
+ sg_object* sym = new_marker_symbol_raw(sym_name, stroke);
+ draw::marker* marker = new draw::marker(x, y, sym, size);
- if (stroke)
- new(L, GS_DRAW_MARKER) trans::stroke(marker);
- else
- new(L, GS_DRAW_MARKER) sg_object_ref<manage_owner>(marker);
+ if (stroke)
+ new(L, GS_DRAW_MARKER) trans::stroke(marker);
+ else
+ new(L, GS_DRAW_MARKER) sg_object_ref<manage_owner>(marker);
- return 1;
+ return 1;
}
int
marker_free (lua_State *L)
{
- return object_free<sg_object>(L, 1, GS_DRAW_MARKER);
+ return object_free<sg_object>(L, 1, GS_DRAW_MARKER);
}
/* create a __index table with methods for agg_path */
static void
agg_path_create_index (lua_State* L)
{
- /* we assume that on top of the stack we have the metatable */
- lua_pushstring(L, "__index");
- lua_newtable(L); /* creata a new table to hold the methods */
- for (int k = 0; cmd_table[k].cmd; k++) /* for each possible command */
- {
- path_cmd_reg* r = cmd_table + k;
- lua_pushstring(L, r->cmd); /* push the name of the command */
- lua_pushinteger(L, k); /* use the id of the command as an upvalue */
- lua_pushcclosure(L, agg_path_cmd, 1); /* to create a closure, the actual method */
- lua_rawset(L, -3); /* and associate the method to the command name */
- }
- lua_rawset(L, -3); /* bind the the new table to the __index key */
+ /* we assume that on top of the stack we have the metatable */
+ lua_pushstring(L, "__index");
+ lua_newtable(L); /* creata a new table to hold the methods */
+ for (int k = 0; cmd_table[k].cmd; k++) /* for each possible command */
+ {
+ path_cmd_reg* r = cmd_table + k;
+ lua_pushstring(L, r->cmd); /* push the name of the command */
+ lua_pushinteger(L, k); /* use the id of the command as an upvalue */
+ lua_pushcclosure(L, agg_path_cmd, 1); /* to create a closure, the actual method */
+ lua_rawset(L, -3); /* and associate the method to the command name */
+ }
+ lua_rawset(L, -3); /* bind the the new table to the __index key */
}
void
draw_register (lua_State *L)
{
- luaL_newmetatable (L, GS_METATABLE(GS_DRAW_PATH));
- agg_path_create_index(L);
- luaL_register (L, NULL, agg_path_methods);
- lua_pop (L, 1);
+ luaL_newmetatable (L, GS_METATABLE(GS_DRAW_PATH));
+ agg_path_create_index(L);
+ luaL_register (L, NULL, agg_path_methods);
+ lua_pop (L, 1);
- luaL_newmetatable (L, GS_METATABLE(GS_DRAW_ELLIPSE));
- luaL_register (L, NULL, agg_ellipse_methods);
- lua_pop (L, 1);
+ luaL_newmetatable (L, GS_METATABLE(GS_DRAW_ELLIPSE));
+ luaL_register (L, NULL, agg_ellipse_methods);
+ lua_pop (L, 1);
- luaL_newmetatable (L, GS_METATABLE(GS_DRAW_TEXTSHAPE));
- luaL_register (L, NULL, textshape_methods);
- lua_pop (L, 1);
+ luaL_newmetatable (L, GS_METATABLE(GS_DRAW_TEXTSHAPE));
+ luaL_register (L, NULL, textshape_methods);
+ lua_pop (L, 1);
- luaL_newmetatable (L, GS_METATABLE(GS_DRAW_MARKER));
- luaL_register (L, NULL, marker_methods);
- lua_pop (L, 1);
+ luaL_newmetatable (L, GS_METATABLE(GS_DRAW_MARKER));
+ luaL_register (L, NULL, marker_methods);
+ lua_pop (L, 1);
- /* gsl module registration */
- luaL_register (L, NULL, draw_functions);
+ /* gsl module registration */
+ luaL_register (L, NULL, draw_functions);
}
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月16日 03:12:13 +0000

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