-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
patch(): Control#shouldActivate
#8934
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,31 +184,27 @@ export class InteractiveFabricObject< | |
* @param {boolean} forTouch indicates if we are looking for interaction area with a touch action | ||
* @return {String|Boolean} corner code (tl, tr, bl, br, etc.), or 0 if nothing is found. | ||
*/ | ||
_findTargetCorner(pointer: Point, forTouch = false): 0 | string { | ||
if ( | ||
!this.hasControls || | ||
!this.canvas || | ||
(this.canvas._activeObject as unknown as this) !== this | ||
) { | ||
return 0; | ||
_findTargetCorner(pointer: Point, forTouch = false): string { | ||
if (!this.hasControls || !this.canvas) { | ||
return ''; | ||
} | ||
|
||
this.__corner = undefined; | ||
// had to keep the reverse loop because was breaking tests | ||
const cornerEntries = Object.entries(this.oCoords); | ||
for (let i = cornerEntries.length - 1; i >= 0; i--) { | ||
const [cornerKey, corner] = cornerEntries[i]; | ||
if (!this.isControlVisible(cornerKey)) { | ||
continue; | ||
} | ||
const lines = this._getImageLines( | ||
forTouch ? corner.touchCorner : corner.corner | ||
); | ||
const xPoints = this._findCrossPoints(pointer, lines); | ||
if (xPoints !== 0 && xPoints % 2 === 1) { | ||
this.__corner = cornerKey; | ||
return cornerKey; | ||
const [key, corner] = cornerEntries[i]; | ||
if (this.controls[key].shouldActivate(key, this)) { | ||
const lines = this._getImageLines( | ||
forTouch ? corner.touchCorner : corner.corner | ||
); | ||
const xPoints = this._findCrossPoints(pointer, lines); | ||
if (xPoints !== 0 && xPoints % 2 === 1) { | ||
this.__corner = key; | ||
return key; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like that both getImageLines and findCrossPoints are object method that are more utils than anyhitng else. If you want to have the control class being the owner of the decision if the cursor is in the control, you can do that moving those to utils and exposing a method that uses the utils. |
||
} | ||
|
||
// // debugging | ||
// | ||
// this.canvas.contextTop.fillRect(lines.bottomline.d.x, lines.bottomline.d.y, 2, 2); | ||
|
@@ -223,7 +219,7 @@ export class InteractiveFabricObject< | |
// this.canvas.contextTop.fillRect(lines.rightline.d.x, lines.rightline.d.y, 2, 2); | ||
// this.canvas.contextTop.fillRect(lines.rightline.o.x, lines.rightline.o.y, 2, 2); | ||
} | ||
return 0; | ||
return ''; | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean we could look at actionName and the relevant lockProperties?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or better off, move the lock property to the control
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well lock is by object and controls could be generic.
That is the same issue we have with visibility.