From 0fc44eb3ff820e67918069c9a2e7bfdd374ee6a4 Mon Sep 17 00:00:00 2001 From: Eric Rowell Date: Sun, 1 Sep 2013 02:03:24 -0700 Subject: [PATCH] finished up all of the context traces for a simple rectangle rendering, and added unit test --- src/Context.js | 90 ++++++++++++++++++++++++++++++++---------- src/Shape.js | 16 ++++---- src/shapes/Line.js | 2 +- src/shapes/Spline.js | 2 +- src/shapes/Text.js | 8 ++-- test/unit/Rect-test.js | 16 +++++++- 6 files changed, 97 insertions(+), 37 deletions(-) diff --git a/src/Context.js b/src/Context.js index b17f3700..91dc2ece 100644 --- a/src/Context.js +++ b/src/Context.js @@ -3,8 +3,25 @@ OPEN_PAREN = '(', CLOSE_PAREN = ')', EMPTY_STRING = '', - CONTEXT_METHODS = ['clearRect', 'rect', 'restore', 'save', 'setTransform', 'transform'], - CONTEXT_PROPERTIES = ['fillStyle', 'lineWidth', 'strokeStyle']; + EQUALS = '=', + SET = 'set', + CONTEXT_METHODS = [ + 'clearRect', + 'fill', + 'fillText', + 'rect', + 'restore', + 'save', + 'setTransform', + 'stroke', + 'strokeText', + 'transform' + ], + CONTEXT_PROPERTIES = [ + 'fillStyle', + 'lineWidth', + 'strokeStyle' + ]; /** * Canvas Context constructor @@ -73,7 +90,7 @@ * @memberof Kinetic.Context.prototype * @param {Kinetic.Shape} shape */ - fill: function(shape) { + fillShape: function(shape) { if(shape.getFillEnabled()) { this._fill(shape); } @@ -84,7 +101,7 @@ * @memberof Kinetic.Context.prototype * @param {Kinetic.Shape} shape */ - stroke: function(shape) { + strokeShape: function(shape) { if(shape.getStrokeEnabled()) { this._stroke(shape); } @@ -159,10 +176,28 @@ container._drawChildren(this.getCanvas()); this.restore(); }, + + // context property setters + setFillStyle: function(val) { + this._context.fillStyle = val; + }, + setLineWidth: function(val) { + this._context.lineWidth = val; + }, + setStrokeStyle: function(val) { + this._context.strokeStyle = val; + }, + // context pass through methods clearRect: function(x, y, width, height) { this._context.clearRect(x, y, width, height); }, + fill: function() { + this._context.fill(); + }, + fillText: function(str, x, y) { + this._context.fillText(str, x, y); + }, rect: function(x, y, width, height) { this._context.rect(x, y, width, height); }, @@ -175,6 +210,12 @@ setTransform: function(a, b, c, d, e, f) { this._context.setTransform(a, b, c, d, e, f); }, + stroke: function() { + this._context.stroke(); + }, + strokeText: function(str, x, y) { + this._context.strokeText(str, x, y); + }, transform: function(a, b, c, d, e, f) { this._context.transform(a, b, c, d, e, f); }, @@ -199,9 +240,16 @@ // properties len = CONTEXT_PROPERTIES.length; - for (n=0; n