aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2011-01-05 03:56:59 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2011-01-05 03:56:59 +0100
commitc4b8f092b7afa12349f8bf6c8a395f48dbef631b (patch)
treed1b35f86febda69b47a774f103db58200ee20136 /src
parent25f1186000ec33e0c51d97df550b05363df23ac9 (diff)
downloadlogdiag-c4b8f092b7afa12349f8bf6c8a395f48dbef631b.tar.gz
logdiag-c4b8f092b7afa12349f8bf6c8a395f48dbef631b.tar.xz
logdiag-c4b8f092b7afa12349f8bf6c8a395f48dbef631b.zip
Export cairo_{get,set}_line_width to Lua symbols.
Diffstat (limited to 'src')
-rw-r--r--src/ld-lua.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/ld-lua.c b/src/ld-lua.c
index 66b1d1f..67b9435 100644
--- a/src/ld-lua.c
+++ b/src/ld-lua.c
@@ -2,7 +2,7 @@
* ld-lua.c
*
* This file is a part of logdiag.
- * Copyright Přemysl Janouch 2010. All rights reserved.
+ * Copyright Přemysl Janouch 2010 - 2011. All rights reserved.
*
* See the file LICENSE for licensing information.
*
@@ -92,6 +92,9 @@ static gchar *get_translation (lua_State *L, int index);
static gboolean read_symbol_area (lua_State *L, int index, LdSymbolArea *area);
static void push_cairo_object (lua_State *L, cairo_t *cr);
+static gdouble get_cairo_scale (cairo_t *cr);
+static int ld_lua_cairo_get_line_width (lua_State *L);
+static int ld_lua_cairo_set_line_width (lua_State *L);
static int ld_lua_cairo_move_to (lua_State *L);
static int ld_lua_cairo_line_to (lua_State *L);
static int ld_lua_cairo_stroke (lua_State *L);
@@ -108,6 +111,8 @@ static luaL_Reg ld_lua_logdiag_lib[] =
static luaL_Reg ld_lua_cairo_table[] =
{
+ {"get_line_width", ld_lua_cairo_get_line_width},
+ {"set_line_width", ld_lua_cairo_set_line_width},
{"move_to", ld_lua_cairo_move_to},
{"line_to", ld_lua_cairo_line_to},
{"stroke", ld_lua_cairo_stroke},
@@ -557,10 +562,41 @@ push_cairo_object (lua_State *L, cairo_t *cr)
}
}
+static gdouble
+get_cairo_scale (cairo_t *cr)
+{
+ double dx = 1, dy = 0;
+
+ cairo_user_to_device_distance (cr, &dx, &dy);
+ return dx;
+}
+
/* TODO: More functions. Possibly put it into another file
* and generate it automatically.
*/
static int
+ld_lua_cairo_get_line_width (lua_State *L)
+{
+ cairo_t *cr;
+
+ cr = lua_touserdata (L, lua_upvalueindex (1));
+ lua_pushnumber (L, cairo_get_line_width (cr) * get_cairo_scale (cr));
+ return 1;
+}
+
+static int
+ld_lua_cairo_set_line_width (lua_State *L)
+{
+ cairo_t *cr;
+ lua_Number width;
+
+ cr = lua_touserdata (L, lua_upvalueindex (1));
+ width = luaL_checknumber (L, 1);
+ cairo_set_line_width (cr, width / get_cairo_scale (cr));
+ return 0;
+}
+
+static int
ld_lua_cairo_move_to (lua_State *L)
{
cairo_t *cr;