mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-04-23 23:34:41 +00:00
Make fabric.Canvas#isTargetTransparent public. Closes #595
This commit is contained in:
parent
e8825bc581
commit
f5b88b4045
4 changed files with 33 additions and 19 deletions
23
dist/all.js
vendored
23
dist/all.js
vendored
|
|
@ -8057,12 +8057,18 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
|
|||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Returns true if object is transparent at a certain location
|
||||
* @param {fabric.Object} target Object to check
|
||||
* @param {Number} x Left coordinate
|
||||
* @param {Number} y Top coordinate
|
||||
* @return {Boolean}
|
||||
*/
|
||||
_isTargetTransparent: function (target, x, y) {
|
||||
isTargetTransparent: function (target, x, y) {
|
||||
var cacheContext = this.contextCache;
|
||||
|
||||
var hasBorders = target.hasBorders, transparentCorners = target.transparentCorners;
|
||||
var hasBorders = target.hasBorders,
|
||||
transparentCorners = target.transparentCorners;
|
||||
|
||||
target.hasBorders = target.transparentCorners = false;
|
||||
|
||||
this._draw(cacheContext, target);
|
||||
|
|
@ -8091,14 +8097,15 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
|
|||
x, y, (this.targetFindTolerance * 2) || 1, (this.targetFindTolerance * 2) || 1);
|
||||
|
||||
// Split image data - for tolerance > 1, pixelDataSize = 4;
|
||||
for (var i = 3; i < imageData.data.length; i += 4) {
|
||||
var temp = imageData.data[i];
|
||||
isTransparent = temp <= 0;
|
||||
if (isTransparent === false) break; //Stop if colour found
|
||||
for (var i = 3, l = imageData.data.length; i < l; i += 4) {
|
||||
var temp = imageData.data[i];
|
||||
isTransparent = temp <= 0;
|
||||
if (isTransparent === false) break; //Stop if colour found
|
||||
}
|
||||
|
||||
imageData = null;
|
||||
this.clearContext(cacheContext);
|
||||
|
||||
return isTransparent;
|
||||
},
|
||||
|
||||
|
|
@ -8539,7 +8546,7 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
|
|||
}
|
||||
for (var j = 0, len = possibleTargets.length; j < len; j++) {
|
||||
pointer = this.getPointer(e);
|
||||
var isTransparent = this._isTargetTransparent(possibleTargets[j], pointer.x, pointer.y);
|
||||
var isTransparent = this.isTargetTransparent(possibleTargets[j], pointer.x, pointer.y);
|
||||
if (!isTransparent) {
|
||||
target = possibleTargets[j];
|
||||
this.relatedTarget = target;
|
||||
|
|
|
|||
6
dist/all.min.js
vendored
6
dist/all.min.js
vendored
File diff suppressed because one or more lines are too long
BIN
dist/all.min.js.gz
vendored
BIN
dist/all.min.js.gz
vendored
Binary file not shown.
|
|
@ -237,12 +237,18 @@
|
|||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Returns true if object is transparent at a certain location
|
||||
* @param {fabric.Object} target Object to check
|
||||
* @param {Number} x Left coordinate
|
||||
* @param {Number} y Top coordinate
|
||||
* @return {Boolean}
|
||||
*/
|
||||
_isTargetTransparent: function (target, x, y) {
|
||||
isTargetTransparent: function (target, x, y) {
|
||||
var cacheContext = this.contextCache;
|
||||
|
||||
var hasBorders = target.hasBorders, transparentCorners = target.transparentCorners;
|
||||
var hasBorders = target.hasBorders,
|
||||
transparentCorners = target.transparentCorners;
|
||||
|
||||
target.hasBorders = target.transparentCorners = false;
|
||||
|
||||
this._draw(cacheContext, target);
|
||||
|
|
@ -271,14 +277,15 @@
|
|||
x, y, (this.targetFindTolerance * 2) || 1, (this.targetFindTolerance * 2) || 1);
|
||||
|
||||
// Split image data - for tolerance > 1, pixelDataSize = 4;
|
||||
for (var i = 3; i < imageData.data.length; i += 4) {
|
||||
var temp = imageData.data[i];
|
||||
isTransparent = temp <= 0;
|
||||
if (isTransparent === false) break; //Stop if colour found
|
||||
for (var i = 3, l = imageData.data.length; i < l; i += 4) {
|
||||
var temp = imageData.data[i];
|
||||
isTransparent = temp <= 0;
|
||||
if (isTransparent === false) break; //Stop if colour found
|
||||
}
|
||||
|
||||
imageData = null;
|
||||
this.clearContext(cacheContext);
|
||||
|
||||
return isTransparent;
|
||||
},
|
||||
|
||||
|
|
@ -719,7 +726,7 @@
|
|||
}
|
||||
for (var j = 0, len = possibleTargets.length; j < len; j++) {
|
||||
pointer = this.getPointer(e);
|
||||
var isTransparent = this._isTargetTransparent(possibleTargets[j], pointer.x, pointer.y);
|
||||
var isTransparent = this.isTargetTransparent(possibleTargets[j], pointer.x, pointer.y);
|
||||
if (!isTransparent) {
|
||||
target = possibleTargets[j];
|
||||
this.relatedTarget = target;
|
||||
|
|
|
|||
Loading…
Reference in a new issue