// // primitives // // Created by Christian Swinehart on 2010-12-08. // Copyright (c) 2011 Samizdat Drafting Co. All rights reserved. // var Primitives = function(ctx, _drawStyle, _fontStyle){ ///MACRO:primitives-start var _Oval = function(x,y,w,h,style){ this.x = x this.y = y this.w = w this.h = h this.style = (style!==undefined) ? style : {} } _Oval.prototype = { draw:function(overrideStyle){ this._draw(overrideStyle) }, _draw:function(x,y,w,h, style){ if (objcontains(x, 'stroke', 'fill', 'width')) style = x if (this.x!==undefined){ x=this.x, y=this.y, w=this.w, h=this.h; style = objmerge(this.style, style) } style = objmerge(_drawStyle, style) if (!style.stroke && !style.fill) return var kappa = .5522848; ox = (w / 2) * kappa, // control point offset horizontal oy = (h / 2) * kappa, // control point offset vertical xe = x + w, // x-end ye = y + h, // y-end xm = x + w / 2, // x-middle ym = y + h / 2; // y-middle ctx.save() ctx.beginPath(); ctx.moveTo(x, ym); ctx.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); ctx.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); ctx.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); ctx.closePath(); // trace(style.fill, style.stroke) if (style.fill!==null){ // trace("fill",fillColor, Colors.encode(fillColor)) if (style.alpha!==undefined) ctx.fillStyle = Colors.blend(style.fill, style.alpha) else ctx.fillStyle = Colors.encode(style.fill) ctx.fill() } if (style.stroke!==null){ ctx.strokeStyle = Colors.encode(style.stroke) if (!isNaN(style.width)) ctx.lineWidth = style.width ctx.stroke() } ctx.restore() } } var _Rect = function(x,y,w,h,r,style){ if (objcontains(r, 'stroke', 'fill', 'width')){ style = r r = 0 } this.x = x this.y = y this.w = w this.h = h this.r = (r!==undefined) ? r : 0 this.style = (style!==undefined) ? style : {} } _Rect.prototype = { draw:function(overrideStyle){ this._draw(overrideStyle) }, _draw:function(x,y,w,h,r, style){ if (objcontains(r, 'stroke', 'fill', 'width', 'alpha')){ style = r; r=0; }else if (objcontains(x, 'stroke', 'fill', 'width', 'alpha')){ style = x } if (this.x!==undefined){ x=this.x, y=this.y, w=this.w, h=this.h; style = objmerge(this.style, style) } style = objmerge(_drawStyle, style) if (!style.stroke && !style.fill) return var rounded = (r>0) ctx.save() ctx.beginPath(); ctx.moveTo(x+r, y); ctx.lineTo(x+w-r, y); if (rounded) ctx.quadraticCurveTo(x+w, y, x+w, y+r); ctx.lineTo(x+w, y+h-r); if (rounded) ctx.quadraticCurveTo(x+w, y+h, x+w-r, y+h); ctx.lineTo(x+r, y+h); if (rounded) ctx.quadraticCurveTo(x, y+h, x, y+h-r); ctx.lineTo(x, y+r); if (rounded) ctx.quadraticCurveTo(x, y, x+r, y); if (style.fill!==null){ if (style.alpha!==undefined) ctx.fillStyle = Colors.blend(style.fill, style.alpha) else ctx.fillStyle = Colors.encode(style.fill) ctx.fill() } if (style.stroke!==null){ ctx.strokeStyle = Colors.encode(style.stroke) if (!isNaN(style.width)) ctx.lineWidth = style.width ctx.stroke() } ctx.restore() } } var _Path = function(x1, y1, x2, y2, style){ // calling patterns: // ƒ( x1, y1, x2, y2,