CanvasDrawing.js revision cff2b8ec796b9316395b305e8867408a6d7c3549
var SHAPE = "canvasShape",
/**
* Set of drawing apis for canvas based classes.
*
* @class CanvasDrawing
* @constructor
*/
function CanvasDrawing()
{
}
/**
* Regex expression used for converting hex strings to rgb
*
* @property _reHex
* @private
*/
/**
* Parses hex color string and alpha value to rgba
*
* @method _2RGBA
* @private
*/
val = 'rgba(' + [
}
return val;
},
/**
* Converts color to rgb format
*
* @method _2RGB
* @private
*/
},
/**
* Sets the size of the graphics object.
*
* @method setSize
* @param w {Number} width to set for the instance.
* @param h {Number} height to set for the instance.
*/
setSize: function(w, h) {
if(this.get("autoSize"))
{
{
}
{
}
}
},
/**
* @private
*/
_updateCoords: function(x, y)
{
},
/**
* @private
*/
_clearAndUpdateCoords: function()
{
this._updateCoords(x, y);
},
/**
* @private
*/
_updateNodePosition: function()
{
x = this.get("x"),
y = this.get("y");
},
/**
* Holds queue of properties for the target canvas.
*
* @property _properties
* @type Object
* @private
*/
_properties: null,
/**
* Adds a method to the drawing queue
*/
_updateDrawingQueue: function(val)
{
},
/**
* Draws a line segment using the current line style from the current drawing position to the specified x and y coordinates.
*
* @method lineTo
* @param {Number} point1 x-coordinate for the end point.
* @param {Number} point2 y-coordinate for the end point.
*/
{
i = 0,
len,
x,
y,
if(!this._lineToMethods)
{
this._lineToMethods = [];
}
}
for (; i < len; ++i)
{
if(args[i])
{
x = args[i][0];
y = args[i][1];
this._updateDrawingQueue(["lineTo", x, y]);
this._updateCoords(x, y);
}
}
this._drawingComplete = false;
return this;
},
/**
* Moves the current drawing position to specified x and y coordinates.
*
* @method moveTo
* @param {Number} x x-coordinate for the end point.
* @param {Number} y y-coordinate for the end point.
*/
moveTo: function(x, y) {
this._updateDrawingQueue(["moveTo", x, y]);
this._updateCoords(x, y);
this._drawingComplete = false;
return this;
},
/**
* Draws a bezier curve.
*
* @method curveTo
* @param {Number} cp1x x-coordinate for the first control point.
* @param {Number} cp1y y-coordinate for the first control point.
* @param {Number} cp2x x-coordinate for the second control point.
* @param {Number} cp2y y-coordinate for the second control point.
* @param {Number} x x-coordinate for the end point.
* @param {Number} y y-coordinate for the end point.
*/
var hiX,
hiY,
loX,
loY;
this._drawingComplete = false;
return this;
},
/**
* Draws a quadratic bezier curve.
*
* @method quadraticCurveTo
* @param {Number} cpx x-coordinate for the control point.
* @param {Number} cpy y-coordinate for the control point.
* @param {Number} x x-coordinate for the end point.
* @param {Number} y y-coordinate for the end point.
*/
var hiX,
hiY,
loX,
loY,
this._drawingComplete = false;
return this;
},
/**
* Draws a circle.
*
* @method drawCircle
* @param {Number} x y-coordinate
* @param {Number} y x-coordinate
* @param {Number} r radius
*/
drawCircle: function(x, y, radius) {
var startAngle = 0,
this._drawingComplete = false;
this._updateCoords(x, y);
return this;
},
/**
* Draws an ellipse.
*
* @method drawEllipse
* @param {Number} x x-coordinate
* @param {Number} y y-coordinate
* @param {Number} w width
* @param {Number} h height
*/
drawEllipse: function(x, y, w, h) {
var l = 8,
angle = 0,
radius = w/2,
yRadius = h/2,
i = 0,
for(; i < l; i++)
{
}
this._updateCoords(x, y);
return this;
},
/**
* Draws a rectangle.
*
* @method drawRect
* @param {Number} x x-coordinate
* @param {Number} y y-coordinate
* @param {Number} w width
* @param {Number} h height
*/
drawRect: function(x, y, w, h) {
this._drawingComplete = false;
this._updateDrawingQueue(["moveTo", x, y]);
this._updateDrawingQueue(["lineTo", x + w, y]);
this._updateDrawingQueue(["lineTo", x + w, y + h]);
this._updateDrawingQueue(["lineTo", x, y + h]);
this._updateDrawingQueue(["lineTo", x, y]);
return this;
},
/**
* Draws a rectangle with rounded corners.
*
* @method drawRect
* @param {Number} x x-coordinate
* @param {Number} y y-coordinate
* @param {Number} w width
* @param {Number} h height
* @param {Number} ew width of the ellipse used to draw the rounded corners
* @param {Number} eh height of the ellipse used to draw the rounded corners
*/
this._drawingComplete = false;
this._updateCoords(w, h);
return this;
},
/**
* @private
* Draws a wedge.
*
* @param x x component of the wedge's center point
* @param y y component of the wedge's center point
* @param startAngle starting angle in degrees
* @param arc sweep of the wedge. Negative values draw clockwise.
* @param radius radius of wedge. If [optional] yRadius is defined, then radius is the x radius.
* @param yRadius [optional] y radius for wedge.
*/
{
var segs,
ax,
ay,
bx,
by,
cx,
cy,
i = 0;
this._drawingComplete = false;
// move to x,y position
this._updateDrawingQueue(["moveTo", x, y]);
// limit sweep to reasonable numbers
{
arc = 360;
}
// First we calculate how many segments are needed
// for a smooth arc.
// Now calculate the sweep of each segment.
// The math requires radians rather than degrees. To convert from degrees
// use the formula (degrees/180)*Math.PI to get radians.
// convert angle startAngle to radians
// draw the curve in segments no larger than 45 degrees.
if(segs > 0)
{
// draw a line from the center to the start of the curve
// Loop for drawing curve segments
for(; i < segs; ++i)
{
}
// close the wedge by drawing a line to the center
this._updateDrawingQueue(["lineTo", x, y]);
}
return this;
},
/**
* Completes a drawing operation.
*
* @method end
*/
end: function() {
this._paint();
return this;
},
/**
* Returns a linear gradient fill
*
* @method _getLinearGradient
* @private
*/
_getLinearGradient: function() {
stop,
i = 0,
x = 0,
y = 0,
w = this.get("width"),
h = this.get("height"),
cx = x + w/2,
cy = y + h/2,
{
if(r < 180)
{
y1 = y;
y2 = y + h;
}
else
{
y1 = y + h;
y2 = y;
}
}
else
{
if(r > 90 && r < 270)
{
x1 = x + w;
x2 = x;
}
else
{
x1 = x;
x2 = x + w;
}
}
for(; i < len; ++i)
{
{
}
else
{
}
}
return gradient;
},
/**
* Returns a radial gradient fill
*
* @method _getRadialGradient
* @private
*/
_getRadialGradient: function() {
r = fill.r,
stop,
i = 0,
x = 0,
y = 0,
w = this.get("width"),
h = this.get("height"),
xc = x + w/2;
yc = y + h/2;
x2 = x + w/2;
y2 = y + h/2;
r2 = w * r;
if(d >= r2)
{
//hack. gradient won't show if it is exactly on the edge of the arc
if(ratio === 1)
{
ratio = 1.01;
}
}
//If the gradient radius is greater than the circle's, adjusting the radius stretches the gradient properly.
//If the gradient radius is less than the circle's, adjusting the radius of the gradient will not work.
//Instead, adjust the color stops to reflect the smaller radius.
if(r >= 0.5)
{
stopMultiplier = 1;
}
else
{
stopMultiplier = r * 2;
}
for(; i < len; ++i)
{
{
}
else
{
}
offset *= stopMultiplier;
if(offset <= 1)
{
}
}
return gradient;
},
/**
* Clears all values
*
* @method _initProps
* @private
*/
_initProps: function() {
this._methods = [];
this._lineToMethods = [];
this._xcoords = [0];
this._ycoords = [0];
this._width = 0;
this._height = 0;
this._left = 0;
this._top = 0;
this._right = 0;
this._bottom = 0;
},
/**
* @private
*/
_drawingComplete: false,
/**
* Creates canvas element
*
* @method _createGraphic
* @private
*/
_createGraphic: function(config) {
return graphic;
},
/**
* Updates the size of the graphics object
*
* @method _trackSize
* @param {Number} w width
* @param {Number} h height
* @private
*/
_trackSize: function(w, h) {
if (w > this._right) {
this._right = w;
}
if(w < this._left)
{
this._left = w;
}
if (h < this._top)
{
this._top = h;
}
if (h > this._bottom)
{
this._bottom = h;
}
}
};