mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-27 22:44:00 +00:00
Merge pull request #1638 from joerozek/stacking
Support for preserving object stacking. Closes #1636.
This commit is contained in:
commit
e524c13521
3 changed files with 24 additions and 2 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,4 +1,5 @@
|
|||
.DS_Store
|
||||
*.iml
|
||||
/node_modules/
|
||||
/npm-debug.log
|
||||
before_commit
|
||||
|
|
|
|||
|
|
@ -133,6 +133,13 @@
|
|||
*/
|
||||
imageSmoothingEnabled: true,
|
||||
|
||||
/**
|
||||
* Indicates whether objects should remain in current stack position when selected. When false objects are brought to top and rendered as part of the selection group
|
||||
* @type Boolean
|
||||
* @default
|
||||
*/
|
||||
preserveObjectStacking: false,
|
||||
|
||||
/**
|
||||
* The transformation (in the format of Canvas transform) which focuses the viewport
|
||||
* @type Array
|
||||
|
|
@ -702,13 +709,22 @@
|
|||
ctx.save();
|
||||
var v = this.viewportTransform;
|
||||
ctx.transform(v[0], v[1], v[2], v[3], v[4], v[5]);
|
||||
object.render(ctx);
|
||||
if (this._shouldRenderObject(object)) {
|
||||
object.render(ctx);
|
||||
}
|
||||
ctx.restore();
|
||||
if (!this.controlsAboveOverlay) {
|
||||
object._renderControls(ctx);
|
||||
}
|
||||
},
|
||||
|
||||
_shouldRenderObject: function(object) {
|
||||
if (!object) {
|
||||
return false;
|
||||
}
|
||||
return (object !== this.getActiveGroup() || !this.preserveObjectStacking);
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {fabric.Object} obj Object that was added
|
||||
|
|
@ -830,7 +846,7 @@
|
|||
var i, length;
|
||||
|
||||
// fast path
|
||||
if (!activeGroup) {
|
||||
if (!activeGroup || this.preserveObjectStacking) {
|
||||
for (i = 0, length = this._objects.length; i < length; ++i) {
|
||||
this._draw(ctx, this._objects[i]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -423,6 +423,11 @@
|
|||
equal(canvas, canvas.renderAll());
|
||||
});
|
||||
|
||||
test('preserveObjectStacking', function() {
|
||||
ok(typeof canvas.preserveObjectStacking == 'boolean');
|
||||
ok(!canvas.preserveObjectStacking);
|
||||
});
|
||||
|
||||
test('renderTop', function() {
|
||||
ok(typeof canvas.renderTop == 'function');
|
||||
equal(canvas, canvas.renderTop());
|
||||
|
|
|
|||
Loading…
Reference in a new issue