1
0
Fork 0

canvas/api.nas: add square, ellipse and circle to path; update svg.nas accordingly

This commit is contained in:
Henning Stahlke 2018-12-08 19:24:19 +01:00
parent f6e3628b50
commit f3548c561e
2 changed files with 37 additions and 2 deletions

View file

@ -991,6 +991,41 @@ var Path = {
return me.close();
},
# Add a (rounded) square to the path
#
# @param x Position of left border
# @param y Position of top border
# @param l length
# @param cfg Optional settings (eg. {"border-top-radius": 5})
square: func(x, y, l, cfg = nil) {
return me.rect(x, y, l, l, cfg);
},
# Add an ellipse to the path
#
# @param rx radius x
# @param ry radius y
# @param cx (optional) center x coordinate
# @param cy (optional) center y coordinate
ellipse: func(rx, ry, cx = nil, cy = nil) {
cx = num(cx) or 0;
cy = num(cy) or 0;
me.moveTo(cx - rx, cy)
.arcSmallCW(rx, ry, 0, 2*rx, 0)
.arcSmallCW(rx, ry, 0, -2*rx, 0);
return me;
},
# Add a circle to the path
#
# @param r radius
# @param cx (optional) center x coordinate
# @param cy (optional) center y coordinate
circle: func(r, cx = nil, cy = nil) {
return me.ellipse(r, r, cx, cy);
},
setColor: func me.setStroke(_getColor(arg)),
getColor: func me.getStroke(),

View file

@ -527,14 +527,14 @@ var parsesvg = func(group, path, options = nil)
var cx = evalCSSNum(attr['cx']);
var cy = evalCSSNum(attr['cy']);
var r = evalCSSNum(attr['r']);
stack[-1].moveTo(cx-r,cy).arcSmallCW(r,r,0,2*r,0).arcSmallCW(r,r,0,-2*r,0);
stack[-1].circle(r, cx, cy);
}
if (name == "ellipse") {
var cx = evalCSSNum(attr['cx']);
var cy = evalCSSNum(attr['cy']);
var rx = evalCSSNum(attr['rx']);
var ry = evalCSSNum(attr['ry']);
stack[-1].moveTo(cx-rx,cy).arcSmallCW(rx,ry,0,2*rx,0).arcSmallCW(rx,ry,0,-2*rx,0);
stack[-1].ellipse(rx, ry, cx, cy);
}
if (name == "path") {
parsePath(attr['d']);