Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove lastRendered logic #3111

Merged
merged 2 commits into from
Jul 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 14 additions & 37 deletions dist/fabric.js
Original file line number Diff line number Diff line change
Expand Up @@ -8427,15 +8427,6 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
*/
altActionKey: 'shiftKey',

/**
* Indicates which key enable last rendered selection independently of stack position
* values: altKey, shiftKey, ctrlKey
* @since 1.6.3
* @type String
* @default
*/
lastRenderedKey: 'altKey',

/**
* Indicates that canvas is interactive. This property should not be changed.
* @type Boolean
Expand Down Expand Up @@ -8676,9 +8667,11 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
isTargetTransparent: function (target, x, y) {
var hasBorders = target.hasBorders,
transparentCorners = target.transparentCorners,
ctx = this.contextCache;
ctx = this.contextCache,
originalColor = target.selectionBackgroundColor;

target.hasBorders = target.transparentCorners = false;
target.selectionBackgroundColor = '';

ctx.save();
ctx.transform.apply(ctx, this.viewportTransform);
Expand All @@ -8689,6 +8682,7 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab

target.hasBorders = hasBorders;
target.transparentCorners = transparentCorners;
target.selectionBackgroundColor = originalColor;

var isTransparent = fabric.util.isTransparent(
ctx, x, y, this.targetFindTolerance);
Expand Down Expand Up @@ -9257,19 +9251,6 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
}
},

/**
* @private
*/
_isLastRenderedObject: function(pointer, e) {
var lastRendered = this.lastRenderedWithControls;
return (
(this.preserveObjectStacking || e[this.lastRenderedKey]) &&
lastRendered &&
lastRendered.visible &&
(this.containsPoint(null, lastRendered, pointer) ||
lastRendered._findTargetCorner(pointer)));
},

/**
* Method that determines what object we are clicking on
* @param {Event} e mouse event
Expand All @@ -9281,7 +9262,8 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
}

var pointer = this.getPointer(e, true),
activeGroup = this.getActiveGroup();
activeGroup = this.getActiveGroup(),
activeObject = this.getActiveObject();

// first check current group (if one exists)
// active group does not check sub targets like normal groups.
Expand All @@ -9290,14 +9272,13 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
return activeGroup;
}

var objects = this._objects;
this.targets = [ ];

if (this._isLastRenderedObject(pointer, e)) {
objects = [this.lastRenderedWithControls];
if (activeObject && this._checkTarget(pointer, activeObject)) {
return activeObject;
}

var target = this._searchPossibleTargets(objects, pointer);
this.targets = [ ];

var target = this._searchPossibleTargets(this._objects, pointer);
this._fireOverOutEvents(target, e);
return target;
},
Expand Down Expand Up @@ -9694,7 +9675,6 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
continue;
}
this._objects[i]._renderControls(ctx);
this.lastRenderedWithControls = this._objects[i];
}
},

Expand All @@ -9703,9 +9683,6 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
* @param {fabric.Object} obj Object that was removed
*/
_onObjectRemoved: function(obj) {
if (obj === this.lastRenderedWithControls) {
delete this.lastRenderedWithControls;
}
this.callSuper('_onObjectRemoved', obj);
},

Expand All @@ -9715,7 +9692,6 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
* @chainable
*/
clear: function () {
delete this.lastRenderedWithControls;
return this.callSuper('clear');
}
});
Expand Down Expand Up @@ -11998,7 +11974,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
* @param {Boolean} fromLeft When true, context is transformed to object's top/left corner. This is used when rendering text on Node
*/
transform: function(ctx, fromLeft) {
if (this.group && this.canvas.preserveObjectStacking && this.group === this.canvas._activeGroup) {
if (this.group && !this.group._transformDone && this.group === this.canvas._activeGroup) {
this.group.transform(ctx);
}
var center = fromLeft ? this._getLeftTopCoords() : this.getCenterPoint();
Expand Down Expand Up @@ -17534,14 +17510,15 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot
this.transform(ctx);
this._setShadow(ctx);
this.clipTo && fabric.util.clipContext(this, ctx);
this._transformDone = true;
// the array is now sorted in order of highest first, so start from end
for (var i = 0, len = this._objects.length; i < len; i++) {
this._renderObject(this._objects[i], ctx);
}

this.clipTo && ctx.restore();

ctx.restore();
this._transformDone = false;
},

/**
Expand Down
14 changes: 7 additions & 7 deletions dist/fabric.min.js

Large diffs are not rendered by default.

Binary file modified dist/fabric.min.js.gz
Binary file not shown.
29 changes: 11 additions & 18 deletions dist/fabric.require.js
Original file line number Diff line number Diff line change
Expand Up @@ -4197,7 +4197,6 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, {
centeredRotation: false,
centeredKey: "altKey",
altActionKey: "shiftKey",
lastRenderedKey: "altKey",
interactive: true,
selection: true,
selectionKey: "shiftKey",
Expand Down Expand Up @@ -4287,15 +4286,17 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, {
};
},
isTargetTransparent: function(target, x, y) {
var hasBorders = target.hasBorders, transparentCorners = target.transparentCorners, ctx = this.contextCache;
var hasBorders = target.hasBorders, transparentCorners = target.transparentCorners, ctx = this.contextCache, originalColor = target.selectionBackgroundColor;
target.hasBorders = target.transparentCorners = false;
target.selectionBackgroundColor = "";
ctx.save();
ctx.transform.apply(ctx, this.viewportTransform);
target.render(ctx);
ctx.restore();
target.active && target._renderControls(ctx);
target.hasBorders = hasBorders;
target.transparentCorners = transparentCorners;
target.selectionBackgroundColor = originalColor;
var isTransparent = fabric.util.isTransparent(ctx, x, y, this.targetFindTolerance);
this.clearContext(ctx);
return isTransparent;
Expand Down Expand Up @@ -4613,24 +4614,19 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, {
ctx.strokeRect(groupSelector.ex + STROKE_OFFSET - (left > 0 ? 0 : aleft), groupSelector.ey + STROKE_OFFSET - (top > 0 ? 0 : atop), aleft, atop);
}
},
_isLastRenderedObject: function(pointer, e) {
var lastRendered = this.lastRenderedWithControls;
return (this.preserveObjectStacking || e[this.lastRenderedKey]) && lastRendered && lastRendered.visible && (this.containsPoint(null, lastRendered, pointer) || lastRendered._findTargetCorner(pointer));
},
findTarget: function(e, skipGroup) {
if (this.skipTargetFind) {
return;
}
var pointer = this.getPointer(e, true), activeGroup = this.getActiveGroup();
var pointer = this.getPointer(e, true), activeGroup = this.getActiveGroup(), activeObject = this.getActiveObject();
if (activeGroup && !skipGroup && this._checkTarget(pointer, activeGroup)) {
return activeGroup;
}
var objects = this._objects;
this.targets = [];
if (this._isLastRenderedObject(pointer, e)) {
objects = [ this.lastRenderedWithControls ];
if (activeObject && this._checkTarget(pointer, activeObject)) {
return activeObject;
}
var target = this._searchPossibleTargets(objects, pointer);
this.targets = [];
var target = this._searchPossibleTargets(this._objects, pointer);
this._fireOverOutEvents(target, e);
return target;
},
Expand Down Expand Up @@ -4894,17 +4890,12 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, {
continue;
}
this._objects[i]._renderControls(ctx);
this.lastRenderedWithControls = this._objects[i];
}
},
_onObjectRemoved: function(obj) {
if (obj === this.lastRenderedWithControls) {
delete this.lastRenderedWithControls;
}
this.callSuper("_onObjectRemoved", obj);
},
clear: function() {
delete this.lastRenderedWithControls;
return this.callSuper("clear");
}
});
Expand Down Expand Up @@ -5792,7 +5783,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, {
this._initClipping(options);
},
transform: function(ctx, fromLeft) {
if (this.group && this.canvas.preserveObjectStacking && this.group === this.canvas._activeGroup) {
if (this.group && !this.group._transformDone && this.group === this.canvas._activeGroup) {
this.group.transform(ctx);
}
var center = fromLeft ? this._getLeftTopCoords() : this.getCenterPoint();
Expand Down Expand Up @@ -8378,11 +8369,13 @@ fabric.util.object.extend(fabric.Object.prototype, {
this.transform(ctx);
this._setShadow(ctx);
this.clipTo && fabric.util.clipContext(this, ctx);
this._transformDone = true;
for (var i = 0, len = this._objects.length; i < len; i++) {
this._renderObject(this._objects[i], ctx);
}
this.clipTo && ctx.restore();
ctx.restore();
this._transformDone = false;
},
_renderControls: function(ctx, noTransform) {
this.callSuper("_renderControls", ctx, noTransform);
Expand Down
46 changes: 11 additions & 35 deletions src/canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,6 @@
*/
altActionKey: 'shiftKey',

/**
* Indicates which key enable last rendered selection independently of stack position
* values: altKey, shiftKey, ctrlKey
* @since 1.6.3
* @type String
* @default
*/
lastRenderedKey: 'altKey',

/**
* Indicates that canvas is interactive. This property should not be changed.
* @type Boolean
Expand Down Expand Up @@ -350,9 +341,11 @@
isTargetTransparent: function (target, x, y) {
var hasBorders = target.hasBorders,
transparentCorners = target.transparentCorners,
ctx = this.contextCache;
ctx = this.contextCache,
originalColor = target.selectionBackgroundColor;

target.hasBorders = target.transparentCorners = false;
target.selectionBackgroundColor = '';

ctx.save();
ctx.transform.apply(ctx, this.viewportTransform);
Expand All @@ -363,6 +356,7 @@

target.hasBorders = hasBorders;
target.transparentCorners = transparentCorners;
target.selectionBackgroundColor = originalColor;

var isTransparent = fabric.util.isTransparent(
ctx, x, y, this.targetFindTolerance);
Expand Down Expand Up @@ -931,19 +925,6 @@
}
},

/**
* @private
*/
_isLastRenderedObject: function(pointer, e) {
var lastRendered = this.lastRenderedWithControls;
return (
(this.preserveObjectStacking || e[this.lastRenderedKey]) &&
lastRendered &&
lastRendered.visible &&
(this.containsPoint(null, lastRendered, pointer) ||
lastRendered._findTargetCorner(pointer)));
},

/**
* Method that determines what object we are clicking on
* @param {Event} e mouse event
Expand All @@ -955,7 +936,8 @@
}

var pointer = this.getPointer(e, true),
activeGroup = this.getActiveGroup();
activeGroup = this.getActiveGroup(),
activeObject = this.getActiveObject();

// first check current group (if one exists)
// active group does not check sub targets like normal groups.
Expand All @@ -964,14 +946,13 @@
return activeGroup;
}

var objects = this._objects;
this.targets = [ ];

if (this._isLastRenderedObject(pointer, e)) {
objects = [this.lastRenderedWithControls];
if (activeObject && this._checkTarget(pointer, activeObject)) {
return activeObject;
}

var target = this._searchPossibleTargets(objects, pointer);
this.targets = [ ];

var target = this._searchPossibleTargets(this._objects, pointer);
this._fireOverOutEvents(target, e);
return target;
},
Expand Down Expand Up @@ -1368,7 +1349,6 @@
continue;
}
this._objects[i]._renderControls(ctx);
this.lastRenderedWithControls = this._objects[i];
}
},

Expand All @@ -1377,9 +1357,6 @@
* @param {fabric.Object} obj Object that was removed
*/
_onObjectRemoved: function(obj) {
if (obj === this.lastRenderedWithControls) {
delete this.lastRenderedWithControls;
}
this.callSuper('_onObjectRemoved', obj);
},

Expand All @@ -1389,7 +1366,6 @@
* @chainable
*/
clear: function () {
delete this.lastRenderedWithControls;
return this.callSuper('clear');
}
});
Expand Down
3 changes: 2 additions & 1 deletion src/shapes/group.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,15 @@
this.transform(ctx);
this._setShadow(ctx);
this.clipTo && fabric.util.clipContext(this, ctx);
this._transformDone = true;
// the array is now sorted in order of highest first, so start from end
for (var i = 0, len = this._objects.length; i < len; i++) {
this._renderObject(this._objects[i], ctx);
}

this.clipTo && ctx.restore();

ctx.restore();
this._transformDone = false;
},

/**
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@
* @param {Boolean} fromLeft When true, context is transformed to object's top/left corner. This is used when rendering text on Node
*/
transform: function(ctx, fromLeft) {
if (this.group && this.canvas.preserveObjectStacking && this.group === this.canvas._activeGroup) {
if (this.group && !this.group._transformDone && this.group === this.canvas._activeGroup) {
this.group.transform(ctx);
}
var center = fromLeft ? this._getLeftTopCoords() : this.getCenterPoint();
Expand Down
Loading