CanvasDrawing.js revision 828c58761d90445b8b9d20a82d85dc1479317f71
828c58761d90445b8b9d20a82d85dc1479317f71Trippvar SHAPE = "canvasShape",
828c58761d90445b8b9d20a82d85dc1479317f71Tripp AttributeLite = Y.AttributeLite,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp PluginHost = Y.Plugin.Host,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp CanvasShape,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp CanvasPath,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp CanvasRect,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp CanvasEllipse,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp CanvasCircle,
828c58761d90445b8b9d20a82d85dc1479317f71Tripp DUMMY;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp/**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Creates dom element used for converting color string to rgb
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _createDummy
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTrippfunction _createDummy()
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp{
828c58761d90445b8b9d20a82d85dc1479317f71Tripp if(!DUMMY)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
828c58761d90445b8b9d20a82d85dc1479317f71Tripp DUMMY = Y.config.doc.createElement('div');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
828c58761d90445b8b9d20a82d85dc1479317f71Tripp DUMMY.style.height = 0;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp DUMMY.style.width = 0;
828c58761d90445b8b9d20a82d85dc1479317f71Tripp DUMMY.style.overflow = 'hidden';
828c58761d90445b8b9d20a82d85dc1479317f71Tripp Y.config.doc.documentElement.appendChild(DUMMY);
828c58761d90445b8b9d20a82d85dc1479317f71Tripp return DUMMY;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp}
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp/**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Set of drawing apis for canvas based classes.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @class CanvasDrawing
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @constructor
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTrippfunction CanvasDrawing()
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp{
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp}
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTrippCanvasDrawing.prototype = {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Regex expression used for converting hex strings to rgb
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @property _reHex
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _reHex: /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Parses hex color string and alpha value to rgba
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _2RGBA
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _2RGBA: function(val, alpha) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp alpha = (alpha !== undefined) ? alpha : 1;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (this._reHex.exec(val)) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp val = 'rgba(' + [
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp parseInt(RegExp.$1, 16),
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp parseInt(RegExp.$2, 16),
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp parseInt(RegExp.$3, 16)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp ].join(',') + ',' + alpha + ')';
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return val;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Converts color to rgb format
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _2RGB
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _2RGB: function(val) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var dummy = _createDummy();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp dummy.style.background = val;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return dummy.style.backgroundColor;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Sets the size of the graphics object.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method setSize
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param w {Number} width to set for the instance.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param h {Number} height to set for the instance.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp setSize: function(w, h) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(this.get("autoSize"))
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(w > this.node.getAttribute("width"))
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.node.style.width = w + "px";
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.node.setAttribute("width", w);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(h > this.node.getAttribute("height"))
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.node.style.height = h + "px";
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.node.setAttribute("height", h);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
9eaaa502227248d304ac9170902697d02158c1d9Tripp * @private
9eaaa502227248d304ac9170902697d02158c1d9Tripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _updatePosition: function(x, y)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateCoords(x, y);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(x <= this._left)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._left = x;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp else if(x >= this._right)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._right = x;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(y <= this._top)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._top = y;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp else if(y >= this._bottom)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._bottom = y;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._width = this._right - this._left;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._height = this._bottom - this._top;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
9eaaa502227248d304ac9170902697d02158c1d9Tripp * @private
9eaaa502227248d304ac9170902697d02158c1d9Tripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _updateCoords: function(x, y)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._xcoords.push(x);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._ycoords.push(y);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
9eaaa502227248d304ac9170902697d02158c1d9Tripp * @private
9eaaa502227248d304ac9170902697d02158c1d9Tripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _clearAndUpdateCoords: function()
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var x = this._xcoords.pop() || 0,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y = this._ycoords.pop() || 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateCoords(x, y);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
9eaaa502227248d304ac9170902697d02158c1d9Tripp * @private
9eaaa502227248d304ac9170902697d02158c1d9Tripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _updateNodePosition: function()
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var node = this.get("node"),
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x = this.get("x"),
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y = this.get("y");
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp node.style.position = "absolute";
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp node.style.left = (x + this._left) + "px";
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp node.style.top = (y + this._top) + "px";
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Holds queue of methods for the target canvas.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @property _methods
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type Object
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _methods: null,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Holds queue of properties for the target canvas.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @property _properties
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type Object
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _properties: null,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Adds a method to the drawing queue
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _updateDrawingQueue: function(val)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(!this._methods)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._methods = [];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._methods.push(val);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Draws a line segment using the current line style from the current drawing position to the specified x and y coordinates.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method lineTo
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} point1 x-coordinate for the end point.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} point2 y-coordinate for the end point.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp lineTo: function(point1, point2, etc) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var args = arguments,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp i, len;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(!this._lineToMethods)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._lineToMethods = [];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (typeof point1 === 'string' || typeof point1 === 'number') {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp args = [[point1, point2]];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for (i = 0, len = args.length; i < len; ++i) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateDrawingQueue(["lineTo", args[i][0], args[i][1]]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._lineToMethods[this._lineToMethods.length] = this._methods[this._methods.length - 1];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateShapeProps.apply(this, args[i]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updatePosition(args[i][0], args[i][1]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._drawingComplete = false;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return this;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Moves the current drawing position to specified x and y coordinates.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method moveTo
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} x x-coordinate for the end point.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} y y-coordinate for the end point.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp moveTo: function(x, y) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateDrawingQueue(["moveTo", x, y]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateShapeProps(x, y);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updatePosition(x, y);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._drawingComplete = false;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return this;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Draws a bezier curve.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method curveTo
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} cp1x x-coordinate for the first control point.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} cp1y y-coordinate for the first control point.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} cp2x x-coordinate for the second control point.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} cp2y y-coordinate for the second control point.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} x x-coordinate for the end point.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} y y-coordinate for the end point.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp curveTo: function(cp1x, cp1y, cp2x, cp2y, x, y) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var hiX,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp hiY,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loX,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loY;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateDrawingQueue(["bezierCurveTo", cp1x, cp1y, cp2x, cp2y, x, y]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._drawingComplete = false;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateShapeProps(x, y);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp hiX = Math.max(x, Math.max(cp1x, cp2x));
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp hiY = Math.max(y, Math.max(cp1y, cp2y));
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loX = Math.min(x, Math.min(cp1x, cp2x));
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loY = Math.min(y, Math.min(cp1y, cp2y));
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updatePosition(hiX, hiY);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updatePosition(loX, loY);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return this;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Draws a quadratic bezier curve.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method quadraticCurveTo
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} cpx x-coordinate for the control point.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} cpy y-coordinate for the control point.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} x x-coordinate for the end point.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} y y-coordinate for the end point.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp quadraticCurveTo: function(cpx, cpy, x, y) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var hiX,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp hiY,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loX,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loY;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateDrawingQueue(["quadraticCurveTo", cpx, cpy, x, y]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._drawingComplete = false;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateShapeProps(x, y);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp hiX = Math.max(x, cpx);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp hiY = Math.max(y, cpy);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loX = Math.min(x, cpx);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp loY = Math.min(y, cpy);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updatePosition(hiX, hiY);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updatePosition(loX, loY);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return this;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Draws a circle.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method drawCircle
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} x y-coordinate
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} y x-coordinate
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} r radius
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp drawCircle: function(x, y, radius) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var startAngle = 0,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp endAngle = 2 * Math.PI,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp circum = radius * 2;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._shape = {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x:x,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y:y,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp w:circum,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h:circum
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp };
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._drawingComplete = false;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updatePosition(x + circum, y + circum);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateDrawingQueue(["arc", x + radius, y + radius, radius, startAngle, endAngle, false]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return this;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Draws an ellipse.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method drawEllipse
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} x x-coordinate
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} y y-coordinate
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} w width
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} h height
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp drawEllipse: function(x, y, w, h) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._shape = {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x:x,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y:y,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp w:w,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h:h
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp };
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(this._stroke && this._strokeWeight > 0)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp w -= this._strokeWeight * 2;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h -= this._strokeWeight * 2;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x += this._strokeWeight;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y += this._strokeWeight;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var l = 8,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp theta = -(45/180) * Math.PI,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp angle = 0,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp angleMid,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp radius = w/2,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp yRadius = h/2,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp i = 0,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp centerX = x + radius,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp centerY = y + yRadius,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp ax, ay, bx, by, cx, cy;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp ax = centerX + Math.cos(0) * radius;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp ay = centerY + Math.sin(0) * yRadius;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.moveTo(ax, ay);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for(; i < l; i++)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp angle += theta;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp angleMid = angle - (theta / 2);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp bx = centerX + Math.cos(angle) * radius;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp by = centerY + Math.sin(angle) * yRadius;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp cx = centerX + Math.cos(angleMid) * (radius / Math.cos(theta / 2));
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp cy = centerY + Math.sin(angleMid) * (yRadius / Math.cos(theta / 2));
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.quadraticCurveTo(cx, cy, bx, by);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._trackPos(x, y);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._trackSize(x + w, y + h);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return this;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Draws a rectangle.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method drawRect
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} x x-coordinate
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} y y-coordinate
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} w width
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} h height
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp drawRect: function(x, y, w, h) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._shape = {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x:x,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y:y,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp w:w,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h:h
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp };
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._drawingComplete = false;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.moveTo(x, y);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.lineTo(x + w, y);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.lineTo(x + w, y + h);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.lineTo(x, y + h);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.lineTo(x, y);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return this;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Draws a rectangle with rounded corners.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method drawRect
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} x x-coordinate
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} y y-coordinate
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} w width
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} h height
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} ew width of the ellipse used to draw the rounded corners
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} eh height of the ellipse used to draw the rounded corners
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp drawRoundRect: function(x, y, w, h, ew, eh) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._shape = {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x:x,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y:y,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp w:w,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h:h
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp };
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._drawingComplete = false;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateDrawingQueue(["moveTo", x, y + eh]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateDrawingQueue(["lineTo", x, y + h - eh]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateDrawingQueue(["quadraticCurveTo", x, y + h, x + ew, y + h]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateDrawingQueue(["lineTo", x + w - ew, y + h]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateDrawingQueue(["quadraticCurveTo", x + w, y + h, x + w, y + h - eh]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateDrawingQueue(["lineTo", x + w, y + eh]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateDrawingQueue(["quadraticCurveTo", x + w, y, x + w - ew, y]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateDrawingQueue(["lineTo", x + ew, y]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateDrawingQueue(["quadraticCurveTo", x, y, x, y + eh]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._trackPos(x, y);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._trackSize(w, h);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._paint();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return this;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Draws a wedge.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param x x component of the wedge's center point
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param y y component of the wedge's center point
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param startAngle starting angle in degrees
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param arc sweep of the wedge. Negative values draw clockwise.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param radius radius of wedge. If [optional] yRadius is defined, then radius is the x radius.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param yRadius [optional] y radius for wedge.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp drawWedge: function(cfg)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var x = cfg.x,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y = cfg.y,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp startAngle = cfg.startAngle,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp arc = cfg.arc,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp radius = cfg.radius,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp yRadius = cfg.yRadius,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp segs,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp segAngle,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp theta,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp angle,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp angleMid,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp ax,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp ay,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp bx,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp by,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp cx,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp cy,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp i = 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._drawingComplete = false;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // move to x,y position
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateRenderQueue(["moveTo", x, y]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp yRadius = yRadius || radius;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // limit sweep to reasonable numbers
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(Math.abs(arc) > 360)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp arc = 360;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // First we calculate how many segments are needed
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // for a smooth arc.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp segs = Math.ceil(Math.abs(arc) / 45);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // Now calculate the sweep of each segment.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp segAngle = arc / segs;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // The math requires radians rather than degrees. To convert from degrees
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // use the formula (degrees/180)*Math.PI to get radians.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp theta = -(segAngle / 180) * Math.PI;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // convert angle startAngle to radians
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp angle = -(startAngle / 180) * Math.PI;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // draw the curve in segments no larger than 45 degrees.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(segs > 0)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // draw a line from the center to the start of the curve
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp ax = x + Math.cos(startAngle / 180 * Math.PI) * radius;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp ay = y + Math.sin(-startAngle / 180 * Math.PI) * yRadius;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.lineTo(ax, ay);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // Loop for drawing curve segments
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for(; i < segs; ++i)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp angle += theta;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp angleMid = angle - (theta / 2);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp bx = x + Math.cos(angle) * radius;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp by = y + Math.sin(angle) * yRadius;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp cx = x + Math.cos(angleMid) * (radius / Math.cos(theta / 2));
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp cy = y + Math.sin(angleMid) * (yRadius / Math.cos(theta / 2));
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateRenderQueue(["quadraticCurveTo", cx, cy, bx, by]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // close the wedge by drawing a line to the center
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._updateRenderQueue(["lineTo", x, y]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._trackPos(x, y);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._trackSize(radius, radius);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._paint();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Completes a drawing operation.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method end
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp end: function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._paint();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return this;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Returns a linear gradient fill
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _getLinearGradient
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _getLinearGradient: function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var isNumber = Y.Lang.isNumber,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp fill = this.get("fill"),
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp stops = fill.stops,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp opacity,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp color,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp stop,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp i = 0,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp len = stops.length,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp gradient,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x = 0,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y = 0,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp w = this.get("width"),
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h = this.get("height"),
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp r = fill.rotation,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x1, x2, y1, y2,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp cx = x + w/2,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp cy = y + h/2,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp offset,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp radCon = Math.PI/180,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp tanRadians = parseFloat(parseFloat(Math.tan(r * radCon)).toFixed(8));
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(Math.abs(tanRadians) * w/2 >= h/2)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(r < 180)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y1 = y;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y2 = y + h;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp else
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y1 = y + h;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y2 = y;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x1 = cx - ((cy - y1)/tanRadians);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x2 = cx - ((cy - y2)/tanRadians);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp else
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(r > 90 && r < 270)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x1 = x + w;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x2 = x;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp else
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x1 = x;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x2 = x + w;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y1 = ((tanRadians * (cx - x1)) - cy) * -1;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y2 = ((tanRadians * (cx - x2)) - cy) * -1;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp gradient = this._context.createLinearGradient(x1, y1, x2, y2);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for(; i < len; ++i)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp stop = stops[i];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp opacity = stop.opacity;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp color = stop.color;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp offset = stop.offset;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(isNumber(opacity))
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp opacity = Math.max(0, Math.min(1, opacity));
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp color = this._2RGBA(color, opacity);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp else
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp color = this._2RGB(color);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp offset = stop.offset || i/(len - 1);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp gradient.addColorStop(offset, color);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return gradient;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Returns a radial gradient fill
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _getRadialGradient
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _getRadialGradient: function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var isNumber = Y.Lang.isNumber,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp fill = this.get("fill"),
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp r = fill.r,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp fx = fill.fx,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp fy = fill.fy,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp stops = fill.stops,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp opacity,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp color,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp stop,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp i = 0,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp len = stops.length,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp gradient,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x = 0,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y = 0,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp w = this.get("width"),
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h = this.get("height"),
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x1, x2, y1, y2, r2,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp xc, yc, xn, yn, d,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp offset,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp ratio,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp stopMultiplier;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp xc = x + w/2;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp yc = y + h/2;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x1 = w * fx;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y1 = h * fy;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x2 = x + w/2;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y2 = y + h/2;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp r2 = w * r;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp d = Math.sqrt( Math.pow(Math.abs(xc - x1), 2) + Math.pow(Math.abs(yc - y1), 2) );
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(d >= r2)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp ratio = d/r2;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp //hack. gradient won't show if it is exactly on the edge of the arc
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(ratio === 1)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp ratio = 1.01;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp xn = (x1 - xc)/ratio;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp yn = (y1 - yc)/ratio;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp xn = xn > 0 ? Math.floor(xn) : Math.ceil(xn);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp yn = yn > 0 ? Math.floor(yn) : Math.ceil(yn);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x1 = xc + xn;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y1 = yc + yn;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp //If the gradient radius is greater than the circle's, adjusting the radius stretches the gradient properly.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp //If the gradient radius is less than the circle's, adjusting the radius of the gradient will not work.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp //Instead, adjust the color stops to reflect the smaller radius.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(r >= 0.5)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp gradient = this._context.createRadialGradient(x1, y1, r, x2, y2, r * w);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp stopMultiplier = 1;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp else
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp gradient = this._context.createRadialGradient(x1, y1, r, x2, y2, w/2);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp stopMultiplier = r * 2;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for(; i < len; ++i)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp stop = stops[i];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp opacity = stop.opacity;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp color = stop.color;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp offset = stop.offset;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(isNumber(opacity))
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp opacity = Math.max(0, Math.min(1, opacity));
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp color = this._2RGBA(color, opacity);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp else
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp color = this._2RGB(color);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp offset = stop.offset || i/(len - 1);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp offset *= stopMultiplier;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(offset <= 1)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp gradient.addColorStop(offset, color);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return gradient;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Clears all values
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _initProps
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _initProps: function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._methods = [];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._lineToMethods = [];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._xcoords = [0];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._ycoords = [0];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._width = 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._height = 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._left = 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._top = 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._right = 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._bottom = 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._x = 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._y = 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _drawingComplete: false,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Creates canvas element
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _createGraphic
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _createGraphic: function(config) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var graphic = Y.config.doc.createElement('canvas');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return graphic;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Updates the size of the graphics object
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _trackSize
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} w width
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} h height
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _trackSize: function(w, h) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (w > this._width) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._width = w;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (h > this._height) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._height = h;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Updates the position of the current drawing
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _trackPos
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} x x-coordinate
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} y y-coordinate
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _trackPos: function(x, y) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (x > this._x) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._x = x;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (y > this._y) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._y = y;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Updates the position and size of the current drawing
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _updateShapeProps
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} x x-coordinate
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} y y-coordinate
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _updateShapeProps: function(x, y)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var w,h;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(!this._shape)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._shape = {};
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(!this._shape.x)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._shape.x = x;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp else
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._shape.x = Math.min(this._shape.x, x);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(!this._shape.y)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._shape.y = y;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp else
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._shape.y = Math.min(this._shape.y, y);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp w = Math.abs(x - this._shape.x);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(!this._shape.w)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._shape.w = w;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp else
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._shape.w = Math.max(w, this._shape.w);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h = Math.abs(y - this._shape.y);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(!this._shape.h)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._shape.h = h;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp else
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._shape.h = Math.max(h, this._shape.h);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp};
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTrippY.CanvasDrawing = CanvasDrawing;