Skip to content

Commit

Permalink
Merge pull request #443 from markwheeler/screen-line-additions
Browse files Browse the repository at this point in the history
Expose line_cap, line_join and miter_limit in screen.lua
  • Loading branch information
tehn authored Jul 2, 2018
2 parents 557df05 + ae22225 commit 4e908e3
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lua/screen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ Screen.level = function(value) s_level(value) end
-- @param w line width (in pixels, floats permitted)
Screen.line_width = function(w) s_line_width(w) end

--- set line cap style
-- @param style line cap style string ("butt", "round" or "square"). default is "butt".
Screen.line_cap = function(style)
s_line_cap(style)
end

--- set line join style
-- @param style line join style string ("miter", "round" or "bevel"). default is "miter"
Screen.line_join = function(style)
s_line_join(style)
end

--- set miter limit
-- @param limit if the current line join style is set to "miter", the miter limit is used to determine whether the lines should be joined with a bevel instead of a miter. if the length of the miter divided by the line width is greater than the miter limit, the style is converted to a bevel. default value 10.
Screen.miter_limit = function(limit)
s_miter_limit(limit)
end

--- move drawing position
-- @param x position x
-- @param y position y
Expand Down
27 changes: 27 additions & 0 deletions matron/src/hardware/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,33 @@ void screen_line_width(double w) {
cairo_set_line_width(cr,w);
}

void screen_line_cap(const char *style) {
CHECK_CR
if(strcmp(style, "round") == 0){
cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND);
}else if(strcmp(style, "square") == 0){
cairo_set_line_cap(cr,CAIRO_LINE_CAP_SQUARE);
}else{
cairo_set_line_cap(cr,CAIRO_LINE_CAP_BUTT);
}
}

void screen_line_join(const char *style) {
CHECK_CR
if(strcmp(style, "round") == 0){
cairo_set_line_join(cr,CAIRO_LINE_JOIN_ROUND);
}else if(strcmp(style, "bevel") == 0){
cairo_set_line_join(cr,CAIRO_LINE_JOIN_BEVEL);
}else{
cairo_set_line_join(cr,CAIRO_LINE_JOIN_MITER);
}
}

void screen_miter_limit(double limit) {
CHECK_CR
cairo_set_miter_limit(cr,limit);
}

void screen_move(double x, double y) {
CHECK_CR
cairo_move_to(cr,x,y);
Expand Down
3 changes: 3 additions & 0 deletions matron/src/hardware/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ extern void screen_font_size(double z);
extern void screen_aa(int s);
extern void screen_level(int z);
extern void screen_line_width(double w);
extern void screen_line_cap(const char *style);
extern void screen_line_join(const char *style);
extern void screen_miter_limit(double limit);
extern void screen_move(double x, double y);
extern void screen_line(double x, double y);
extern void screen_move_rel(double x, double y);
Expand Down
54 changes: 54 additions & 0 deletions matron/src/weaver.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ static int _screen_font_size(lua_State *l);
static int _screen_aa(lua_State *l);
static int _screen_level(lua_State *l);
static int _screen_line_width(lua_State *l);
static int _screen_line_cap(lua_State *l);
static int _screen_line_join(lua_State *l);
static int _screen_miter_limit(lua_State *l);
static int _screen_move(lua_State *l);
static int _screen_line(lua_State *l);
static int _screen_move_rel(lua_State *l);
Expand Down Expand Up @@ -199,6 +202,9 @@ void w_init(void) {
lua_register(lvm, "s_aa", &_screen_aa);
lua_register(lvm, "s_level", &_screen_level);
lua_register(lvm, "s_line_width", &_screen_line_width);
lua_register(lvm, "s_line_cap", &_screen_line_cap);
lua_register(lvm, "s_line_join", &_screen_line_join);
lua_register(lvm, "s_miter_limit", &_screen_miter_limit);
lua_register(lvm, "s_move", &_screen_move);
lua_register(lvm, "s_line", &_screen_line);
lua_register(lvm, "s_move_rel", &_screen_move_rel);
Expand Down Expand Up @@ -439,6 +445,54 @@ int _screen_line_width(lua_State *l) {
return 0;
}

/***
* screen: set line cap
* @function s_line_cap
* @tparam string line cap style ("butt", "round" or "square"). default is "butt".
*/
int _screen_line_cap(lua_State *l) {
if (lua_gettop(l) != 1) {
return luaL_error(l, "wrong number of arguments");
}

const char *s = luaL_checkstring(l, 1);
screen_line_cap(s);
lua_settop(l, 0);
return 0;
}

/***
* screen: set line join
* @function s_line_join
* @tparam string line join style ("miter", "round" or "bevel"). default is "miter".
*/
int _screen_line_join(lua_State *l) {
if (lua_gettop(l) != 1) {
return luaL_error(l, "wrong number of arguments");
}

const char *s = luaL_checkstring(l, 1);
screen_line_join(s);
lua_settop(l, 0);
return 0;
}

/***
* screen: set miter limit
* @function s_miter_limit
* @tparam double miter limit
*/
int _screen_miter_limit(lua_State *l) {
if (lua_gettop(l) != 1) {
return luaL_error(l, "wrong number of arguments");
}

double limit = luaL_checknumber(l, 1);
screen_miter_limit(limit);
lua_settop(l, 0);
return 0;
}

/***
* screen: move position
* @function s_move
Expand Down

0 comments on commit 4e908e3

Please sign in to comment.