From fe551c1eceaf8206f0cc9b697b5693ee2b3e6ead Mon Sep 17 00:00:00 2001 From: Eric Rowell Date: Sun, 1 Sep 2013 13:28:52 -0700 Subject: [PATCH] added more pass through methods for the new context class, and added more unit tests --- src/Context.js | 51 ++++++++++++++++++++++--------- src/Util.js | 16 ++++++++++ src/shapes/Rect.js | 25 ++++++++------- test/unit/Rect-test.js | 69 ++++++++++++++++++++++++++++++++---------- 4 files changed, 117 insertions(+), 44 deletions(-) diff --git a/src/Context.js b/src/Context.js index 91dc2ece..87a9b8cc 100644 --- a/src/Context.js +++ b/src/Context.js @@ -6,9 +6,15 @@ EQUALS = '=', SET = 'set', CONTEXT_METHODS = [ + 'arc', + 'arcTo', + 'beginPath', 'clearRect', + 'closePath', 'fill', 'fillText', + 'lineTo', + 'moveTo', 'rect', 'restore', 'save', @@ -43,6 +49,16 @@ this._enableTrace(); } }, + /** + * get context trace if trace is enabled + * @method + * @memberof Kinetic.Context.prototype + * @returns {String} + */ + getTrace: function() { + return this.traceArr.join(';'); + + }, _trace: function(str) { var traceArr = this.traceArr, len; @@ -124,20 +140,6 @@ this._stroke(shape, shape.hasShadow() && shape.hasFill() && fillEnabled); } }, - /** - * apply shadow - * @method - * @memberof Kinetic.Context.prototype - * @param {Kinetic.Shape} shape - * @param {Function} drawFunc - */ - applyShadow: function(shape, drawFunc) { - context.save(); - this._applyShadow(shape); - drawFunc(); - context.restore(); - drawFunc(); - }, _applyLineCap: function(shape) { var lineCap = shape.getLineCap(); if(lineCap) { @@ -189,15 +191,33 @@ }, // context pass through methods + arc: function() { + var a = arguments; + this._context.arc(a[0], a[1], a[2], a[3], a[4], a[5]); + }, + beginPath: function() { + this._context.beginPath(); + }, clearRect: function(x, y, width, height) { this._context.clearRect(x, y, width, height); }, + closePath: function() { + this._context.closePath(); + }, fill: function() { this._context.fill(); }, fillText: function(str, x, y) { this._context.fillText(str, x, y); }, + lineTo: function() { + var a = arguments; + this._context.lineTo(a[0], a[1]); + }, + moveTo: function() { + var a = arguments; + this._context.moveTo(a[0], a[1]); + }, rect: function(x, y, width, height) { this._context.rect(x, y, width, height); }, @@ -222,6 +242,7 @@ _enableTrace: function() { var that = this, len = CONTEXT_METHODS.length, + _roundArrValues = Kinetic.Util._roundArrValues, n; // methods @@ -231,7 +252,7 @@ args; that[contextMethod] = function() { - args = Array.prototype.slice.call(arguments, 0); + args = _roundArrValues(Array.prototype.slice.call(arguments, 0)); method.apply(that, arguments); that._trace(contextMethod + OPEN_PAREN + args.join(COMMA) + CLOSE_PAREN); }; diff --git a/src/Util.js b/src/Util.js index 556ef97d..2a83e107 100644 --- a/src/Util.js +++ b/src/Util.js @@ -346,6 +346,22 @@ } return false; }, + _roundArrValues: function(arr) { + var retArr = [], + len = arr.length, + _isNumber = Kinetic.Util._isNumber, + n, val; + + for (n=0; n