CanvasDrawing.js revision a89ad754cce3cfc8aee71760e10217b54020360d
var SHAPE = "canvasShape",
/**
* Creates dom element used for converting color string to rgb
*
* @method _createDummy
* @private
*/
function _createDummy()
{
if(!DUMMY)
{
}
return DUMMY;
}
/**
* 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
*/
var dummy = _createDummy();
},
/**
* 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
*/
_updatePosition: function(x, y)
{
this._updateCoords(x, y);
if(x <= this._left)
{
this._left = x;
}
else if(x >= this._right)
{
this._right = x;
}
if(y <= this._top)
{
this._top = y;
}
else if(y >= this._bottom)
{
this._bottom = y;
}
},
/**
* @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 methods for the target canvas.
*
* @property _methods
* @type Object
* @private
*/
_methods: null,
/**
* 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)
{
if(!this._methods)
{
this._methods = [];
}
},
/**
* 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, len;
if(!this._lineToMethods)
{
this._lineToMethods = [];
}
}
}
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._updateShapeProps(x, y);
this._updatePosition(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;
this._updateShapeProps(x, y);
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;
this._updateShapeProps(x, y);
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._shape = {
x:x,
y:y,
w:circum,
h:circum
};
this._drawingComplete = false;
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) {
this._shape = {
x:x,
y:y,
w:w,
h:h
};
{
w -= this._strokeWeight * 2;
h -= this._strokeWeight * 2;
x += this._strokeWeight;
y += this._strokeWeight;
}
var l = 8,
angle = 0,
radius = w/2,
yRadius = h/2,
i = 0,
for(; i < l; i++)
{
}
this._trackPos(x, y);
this._trackSize(x + w, y + h);
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._shape = {
x:x,
y:y,
w:w,
h:h
};
this._drawingComplete = false;
this.moveTo(x, y);
this.lineTo(x + w, y);
this.lineTo(x + w, y + h);
this.lineTo(x, y + h);
this.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._shape = {
x:x,
y:y,
w:w,
h:h
};
this._drawingComplete = false;
this._trackPos(x, y);
this._trackSize(w, h);
this._paint();
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 x = cfg.x,
y = cfg.y,
segs,
ax,
ay,
bx,
by,
cx,
cy,
i = 0;
this._drawingComplete = false;
// move to x,y position
this._updateRenderQueue(["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._updateRenderQueue(["lineTo", x, y]);
}
this._trackPos(x, y);
this._paint();
},
/**
* 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;
this._x = 0;
this._y = 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._width) {
this._width = w;
}
if (h > this._height) {
this._height = h;
}
},
/**
* Updates the position of the current drawing
*
* @method _trackPos
* @param {Number} x x-coordinate
* @param {Number} y y-coordinate
* @private
*/
_trackPos: function(x, y) {
if (x > this._x) {
this._x = x;
}
if (y > this._y) {
this._y = y;
}
},
/**
* Updates the position and size of the current drawing
*
* @method _updateShapeProps
* @param {Number} x x-coordinate
* @param {Number} y y-coordinate
* @private
*/
_updateShapeProps: function(x, y)
{
var w,h;
if(!this._shape)
{
this._shape = {};
}
if(!this._shape.x)
{
this._shape.x = x;
}
else
{
}
if(!this._shape.y)
{
this._shape.y = y;
}
else
{
}
if(!this._shape.w)
{
this._shape.w = w;
}
else
{
}
if(!this._shape.h)
{
this._shape.h = h;
}
else
{
}
}
};