Comparing version 2.8.10 to 2.9.0
/** | ||
* oCanvas v2.8.10 | ||
* oCanvas v2.9.0 | ||
* http://ocanvas.org/ | ||
@@ -4,0 +4,0 @@ * |
{ | ||
"name": "ocanvas", | ||
"version": "2.8.10", | ||
"version": "2.9.0", | ||
"author": "Johannes Koggdal <johannes@koggdal.com>", | ||
@@ -5,0 +5,0 @@ "description": "Library for HTML5 Canvas, based on objects instead of pixels.", |
# [oCanvas](http://ocanvas.org/) - Object-based canvas drawing | ||
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fkoggdal%2Focanvas.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fkoggdal%2Focanvas?ref=badge_shield) | ||
oCanvas makes canvas development easier to understand and do, by creating a bridge between the native pixel drawing approach and objects that are created and added to canvas. It is now possible to very easily create objects, change properties of these objects and add events to them — and everything just works because oCanvas handles the background stuff for you. | ||
@@ -30,1 +32,5 @@ | ||
I have two main branches, `master` and `develop`, where `develop` is the branch where everything happens. When a new version is about to be released, it gets merged to `master`, where the version number is updated. So if you want to help out, make sure you're working on top of `develop`. | ||
## License | ||
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fkoggdal%2Focanvas.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fkoggdal%2Focanvas?ref=badge_large) |
@@ -7,3 +7,3 @@ (function(window, document, undefined){ | ||
// Version number of this oCanvas release. | ||
version: "2.8.10", | ||
version: "2.9.0", | ||
@@ -255,3 +255,12 @@ // Array containing all canvases created by oCanvas on the current page | ||
}, | ||
// Method for adding an object to the canvas at a specific index | ||
// If index < 0, then the child is added to the beginning of children array | ||
// If index >= children.length, then the child is added at the end of children array | ||
addChildAt: function (displayobj, index, redraw) { | ||
displayobj.addAt(index, redraw); | ||
return this; | ||
}, | ||
// Method for removing an object from the canvas | ||
@@ -263,3 +272,12 @@ removeChild: function (displayobj, redraw) { | ||
}, | ||
// Method for removing a child at a specific index | ||
removeChildAt: function (index, redraw) { | ||
if (this.children[index] !== undefined) { | ||
this.children[index].remove(redraw); | ||
} | ||
return this; | ||
}, | ||
// Shorthand method for clearing the canvas | ||
@@ -266,0 +284,0 @@ clear: function (keepBackground) { |
@@ -354,2 +354,9 @@ (function(oCanvas, window, document, undefined){ | ||
add: function (redraw) { | ||
return this.addAt(this.core.children.length, redraw); | ||
}, | ||
// Method for adding the object to the canvas at a specific index | ||
// If index < 0, then the child is added to the beginning of children array | ||
// If index >= children.length, then the child is added at the end of children array | ||
addAt: function (index, redraw) { | ||
if (!this.added) { | ||
@@ -359,5 +366,12 @@ | ||
redraw = redraw !== undefined ? redraw : true; | ||
// Add this object | ||
this.core.children.push(this); | ||
if (index >= this.core.children.length) { | ||
this.core.children.push(this); | ||
} else if (index < 0) { | ||
this.core.children.unshift(this); | ||
} else { | ||
this.core.children.splice(index, 0, this); | ||
} | ||
this.added = true; | ||
@@ -368,3 +382,3 @@ this.parent = this.core; | ||
this.core.draw.objects.push(this); | ||
// Redraw the canvas with the new object | ||
@@ -375,6 +389,6 @@ if (redraw) { | ||
} | ||
return this; | ||
}, | ||
// Method for removing the object from the canvas | ||
@@ -735,9 +749,27 @@ remove: function (redraw) { | ||
addChild: function (childObj, returnIndex) { | ||
return this.addChildAt(childObj, this.children.length, returnIndex); | ||
}, | ||
// Method for adding a child to the display object at a specific index | ||
// If index < 0, then the child is added to the beginning of children array | ||
// If index >= children.length, then the child is added at the end of children array | ||
// Children will transform accordingly when this display object transforms | ||
addChildAt: function (childObj, index, returnIndex) { | ||
// Check if the child object doesn't already have a parent | ||
if (childObj.parent === undefined) { | ||
var realIndex; | ||
// Add the object as a child | ||
var index = this.children.push(childObj) - 1; | ||
if (index >= this.children.length) { | ||
realIndex = this.children.push(childObj) - 1; | ||
} else if (index < 0) { | ||
this.children.unshift(childObj); | ||
realIndex = 0; | ||
} else { | ||
this.children.splice(index, 0, childObj); | ||
realIndex = index; | ||
} | ||
// Update child | ||
@@ -750,3 +782,3 @@ childObj.parent = this; | ||
this.core.draw.objects.push(childObj); | ||
// Redraw the canvas if this object is drawn, to show the new child object | ||
@@ -756,5 +788,5 @@ if (this.drawn) { | ||
} | ||
if (returnIndex) { | ||
return index; | ||
return realIndex; | ||
} | ||
@@ -764,7 +796,7 @@ } else if (returnIndex) { | ||
} | ||
// Return the object itself if user chose to not get the index in return | ||
return this; | ||
}, | ||
// Method for removing a child | ||
@@ -771,0 +803,0 @@ removeChild: function (childObj, redraw) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
3894764
61
79406
35