|
@@ -793,7 +793,7 @@ Object2D.prototype.updateMatrix = function(context)
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Apply the transform to the rendering context.
|
|
|
+ * Apply the transform to the rendering context, it is assumed that the viewport transform is pre-applied to the context.
|
|
|
*
|
|
|
* Can also be used for pre rendering logic.
|
|
|
*/
|
|
@@ -809,7 +809,7 @@ Object2D.prototype.transform = function(context, viewport)
|
|
|
*
|
|
|
* @param context Canvas 2d drawing context.
|
|
|
*/
|
|
|
-Object2D.prototype.draw = function(context, viewport){};
|
|
|
+Object2D.prototype.draw = function(context, viewport, canvas){};
|
|
|
|
|
|
/**
|
|
|
* Callback method called every time before the object is draw into the canvas.
|
|
@@ -1374,6 +1374,20 @@ function Renderer(canvas)
|
|
|
this.autoClear = true;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Creates a infinite render loop to render the group into a viewport each frame.
|
|
|
+ *
|
|
|
+ * The render loop cannot be destroyed.
|
|
|
+ *
|
|
|
+ * @param {Object2D} group Group to be rendererd.
|
|
|
+ * @param {Viewport} viewport Viewport into the objects.
|
|
|
+ * @param {Function} onUpdate Function called before rendering the frame.
|
|
|
+ */
|
|
|
+Renderer.prototype.createRenderLoop = function(group, viewport, onUpdate)
|
|
|
+{
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
/**
|
|
|
* Update the renderer state, update the input handlers, calculate the object and viewport transformation matrices.
|
|
|
*
|
|
@@ -1381,7 +1395,7 @@ function Renderer(canvas)
|
|
|
*
|
|
|
* The canvas state is saved and restored for each individual object, ensuring that the code of one object does not affect another one.
|
|
|
*
|
|
|
- * Should be called at a fixed rate preferably using the requestAnimationFrame() method.
|
|
|
+ * Should be called at a fixed rate preferably using the requestAnimationFrame() method, its also possible to use the createRenderLoop() method, that automatically creates a infinite render loop.
|
|
|
*
|
|
|
* @param object Object to be updated.
|
|
|
* @param viewport Viewport to be updated (should be the one where the objects will be rendered after).
|
|
@@ -1549,8 +1563,8 @@ Renderer.prototype.update = function(object, viewport)
|
|
|
this.context.setTransform(1, 0, 0, 1, 0, 0);
|
|
|
}
|
|
|
|
|
|
- objects[i].transform(this.context, viewport);
|
|
|
- objects[i].draw(this.context, viewport);
|
|
|
+ objects[i].transform(this.context, viewport, this.canvas);
|
|
|
+ objects[i].draw(this.context, viewport, this.canvas);
|
|
|
|
|
|
if(objects[i].restoreContextState)
|
|
|
{
|
|
@@ -1649,28 +1663,6 @@ Viewport.prototype.updateMatrix = function()
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-/**
|
|
|
- * A stencil can be used to set the drawing region.
|
|
|
- *
|
|
|
- * Stencils are treated as objects their shaphe is used to filter other objects shape.
|
|
|
- *
|
|
|
- * Multiple stencil objects can be active simulatenously.
|
|
|
- *
|
|
|
- * @class
|
|
|
- */
|
|
|
-function Stencil()
|
|
|
-{
|
|
|
- //TODO <ADD CODE HERE>
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Activate the stencil.
|
|
|
- */
|
|
|
-Stencil.prototype.draw = function()
|
|
|
-{
|
|
|
- // body...
|
|
|
-};
|
|
|
-
|
|
|
/**
|
|
|
* Box is described by a minimum and maximum points.
|
|
|
*
|
|
@@ -1864,6 +1856,22 @@ Box2.prototype.equals = function(box)
|
|
|
return box.min.equals(this.min) && box.max.equals(this.max);
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * A stencil can be used to set the drawing region.
|
|
|
+ *
|
|
|
+ * Stencils are treated as objects their shaphe is used to filter other objects shape.
|
|
|
+ *
|
|
|
+ * Multiple stencil objects can be active simulatenously.
|
|
|
+ *
|
|
|
+ * @class
|
|
|
+ */
|
|
|
+function Stencil()
|
|
|
+{
|
|
|
+ Object2D.call(this);
|
|
|
+}
|
|
|
+
|
|
|
+Stencil.prototype = Object.create(Object2D.prototype);
|
|
|
+
|
|
|
/**
|
|
|
* Circle object draw a circular object, into the canvas.
|
|
|
*
|
|
@@ -1906,7 +1914,7 @@ Circle.prototype.onPointerLeave = function(pointer, viewport)
|
|
|
this.fillStyle = "#FFFFFF";
|
|
|
};
|
|
|
|
|
|
-Circle.prototype.draw = function(context)
|
|
|
+Circle.prototype.draw = function(context, viewport, canvas)
|
|
|
{
|
|
|
context.fillStyle = this.fillStyle;
|
|
|
|
|
@@ -1922,11 +1930,19 @@ Circle.prototype.draw = function(context)
|
|
|
context.stroke();
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * Class contains helper functions to create editing object tools.
|
|
|
+ *
|
|
|
+ * @class
|
|
|
+ */
|
|
|
function Helpers(){}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
- * Create a rotation tool
|
|
|
+ * Create a rotation tool helper.
|
|
|
+ *
|
|
|
+ * When the object is dragged is changes the parent object rotation.
|
|
|
+ *
|
|
|
+ * @static
|
|
|
*/
|
|
|
Helpers.rotateTool = function(object)
|
|
|
{
|
|
@@ -1946,6 +1962,8 @@ Helpers.rotateTool = function(object)
|
|
|
* Each helper is positioned on one corner of the box, and the value of the corner is copied to the boxes as they are dragged.
|
|
|
*
|
|
|
* This method required to object to have a box property.
|
|
|
+ *
|
|
|
+ * @static
|
|
|
*/
|
|
|
Helpers.boxResizeTool = function(object)
|
|
|
{
|
|
@@ -2062,7 +2080,7 @@ Box.prototype.isInside = function(point)
|
|
|
return this.box.containsPoint(point);
|
|
|
};
|
|
|
|
|
|
-Box.prototype.draw = function(context)
|
|
|
+Box.prototype.draw = function(context, viewport, canvas)
|
|
|
{
|
|
|
var width = this.box.max.x - this.box.min.x;
|
|
|
var height = this.box.max.y - this.box.min.y;
|
|
@@ -2116,7 +2134,7 @@ function Line()
|
|
|
|
|
|
Line.prototype = Object.create(Object2D.prototype);
|
|
|
|
|
|
-Line.prototype.draw = function(context)
|
|
|
+Line.prototype.draw = function(context, viewport, canvas)
|
|
|
{
|
|
|
context.lineWidth = this.lineWidth;
|
|
|
context.strokeStyle = this.strokeStyle;
|
|
@@ -2160,7 +2178,7 @@ function Text()
|
|
|
|
|
|
Text.prototype = Object.create(Object2D.prototype);
|
|
|
|
|
|
-Text.prototype.draw = function(context)
|
|
|
+Text.prototype.draw = function(context, viewport, canvas)
|
|
|
{
|
|
|
context.font = this.font;
|
|
|
context.textAlign = this.textAlign;
|
|
@@ -2221,7 +2239,7 @@ Image.prototype.isInside = function(point)
|
|
|
return this.box.containsPoint(point);
|
|
|
};
|
|
|
|
|
|
-Image.prototype.draw = function(context)
|
|
|
+Image.prototype.draw = function(context, viewport, canvas)
|
|
|
{
|
|
|
context.drawImage(this.image, 0, 0, this.image.naturalWidth, this.image.naturalHeight, this.box.min.x, this.box.min.y, this.box.max.x - this.box.min.x, this.box.max.y - this.box.min.y);
|
|
|
};
|
|
@@ -2261,7 +2279,7 @@ function DOM(parent, type)
|
|
|
|
|
|
DOM.prototype = Object.create(Object2D.prototype);
|
|
|
|
|
|
-DOM.prototype.draw = function(context, viewport)
|
|
|
+DOM.prototype.draw = function(context, viewport, canvas)
|
|
|
{
|
|
|
// CSS trasnformation matrix
|
|
|
var projection = viewport.matrix.clone();
|
|
@@ -2329,7 +2347,7 @@ Pattern.prototype.isInside = function(point)
|
|
|
return this.box.containsPoint(point);
|
|
|
};
|
|
|
|
|
|
-Pattern.prototype.draw = function(context, viewport)
|
|
|
+Pattern.prototype.draw = function(context, viewport, canvas)
|
|
|
{
|
|
|
var width = this.box.max.x - this.box.min.x;
|
|
|
var height = this.box.max.y - this.box.min.y;
|