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

chore(TS): migrate brushes #8182

Merged
merged 14 commits into from
Aug 26, 2022
Merged

chore(TS): migrate brushes #8182

merged 14 commits into from
Aug 26, 2022

Conversation

ShaMan123
Copy link
Contributor

@ShaMan123 ShaMan123 commented Aug 25, 2022

I will migrate eraser on a separate PR
It will wait...

@github-actions
Copy link
Contributor

github-actions bot commented Aug 25, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.13 |    74.64 |   84.43 |   80.77 |                                               
 fabric.js |   82.13 |    74.64 |   84.43 |   80.77 | ...-27701,27828-27829,27851-27888,27905-28065 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Aug 25, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.12 |     74.6 |   84.43 |   80.76 |                                               
 fabric.js |   82.12 |     74.6 |   84.43 |   80.76 | ...-27699,27826-27827,27849-27886,27903-28063 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Aug 25, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.17 |    74.62 |   84.36 |    80.8 |                                               
 fabric.js |   82.17 |    74.62 |   84.36 |    80.8 | ...-27689,27805-27806,27827-27868,27883-28042 
-----------|---------|----------|---------|---------|-----------------------------------------------

@ShaMan123 ShaMan123 requested a review from asturur August 25, 2022 12:02
@github-actions
Copy link
Contributor

github-actions bot commented Aug 25, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.14 |    74.62 |   84.36 |   80.76 |                                               
 fabric.js |   82.14 |    74.62 |   84.36 |   80.76 | ...-27689,27805-27806,27827-27868,27883-28042 
-----------|---------|----------|---------|---------|-----------------------------------------------

Copy link
Contributor Author

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments for major changes
I propose we add an options object in the constructor passing initial state. I have been wanting this for a while

READY

@@ -93,5 +88,7 @@ import './src/mixins/itext_key_behavior.mixin'; // optional itext
import './src/mixins/itext.svg_export'; // optional itext
import './src/shapes/textbox.class'; // optional textbox
import './src/mixins/default_controls'; // optional interaction

import './src/brushes'; // optional freedrawing
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to end because brushes depend on shapes

const canvas = this.canvas,
shadow = this.shadow,
ctx = canvas.contextTop,
zoom = canvas.getZoom() * canvas.getRetinaScaling();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed this line

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but it should be 100% equivalent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should

*/
canvas

constructor(canvas) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about accepting options?

*/
export type Shadow = any;
export type Canvas = any;
export type Rect = any;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transient types

* @param {(string|number)[][]} pathData SVG path commands
* @returns {boolean}
*/
_isEmptySVGPath: function (pathData) {
Copy link
Contributor Author

@ShaMan123 ShaMan123 Aug 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extracted to standalone function

* @private
* @param {Object} pointer Actual mouse position related to the canvas.
*/
_captureDrawingPath: function(pointer) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed
this was a redundant wrapper around _addPoint

@github-actions
Copy link
Contributor

github-actions bot commented Aug 25, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.13 |    74.59 |   84.36 |   80.74 |                                               
 fabric.js |   82.13 |    74.59 |   84.36 |   80.74 | ...-27689,27805-27806,27827-27868,27883-28042 
-----------|---------|----------|---------|---------|-----------------------------------------------

@asturur
Copy link
Member

asturur commented Aug 25, 2022

I have no issue with adding initial state to a brush ( even if it can probably be done outisde the constructor ).
The point is that the brush interface as it is now does not make sense, they are way similar to objects and have this issue of starting and ending with mouse down/up.
I want to change that and i m not sure how things will translate, but in general we can assume is safe to think brushes can have options when created.

@ShaMan123
Copy link
Contributor Author

I don't mind waiting and returning to it later.
I want to hear more of your thoughts regarding brushes

@github-actions
Copy link
Contributor

github-actions bot commented Aug 25, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   82.14 |    74.62 |   84.36 |   80.76 |                                               
 fabric.js |   82.14 |    74.62 |   84.36 |   80.76 | ...-27689,27805-27806,27827-27868,27883-28042 
-----------|---------|----------|---------|---------|-----------------------------------------------

@ShaMan123
Copy link
Contributor Author

let's merge this. enough changes for one iteration

@asturur
Copy link
Member

asturur commented Aug 26, 2022

yes this will get merge with no additional changes today.
Regrding brushes, i would like a brush to expose an even handler for every mouse or touch event.
down, click, up, dblclick and so on.
Those events will get executed as today before standard canvas logic, and will by default block the event from running the canvas logic afterward, but is optional to the dev to do so.
The brush will be in control to terminate its own lifecycle on one of those events.

This should let current brushes work as they are working today, but would also allow brushes to work on clicks and collect points like to build a polygon and end when the polygon is closed or end on dblclick.

It doesn't change much but offer so much more flexibility.

@ShaMan123
Copy link
Contributor Author

ShaMan123 commented Aug 26, 2022

sounds great
and even not block events (with a return value) so things can run together creating complex UX.
This can be leveraged to many things like you suggested and a custom pointer for example or a laser.

@ShaMan123 ShaMan123 merged commit f52f1c4 into master Aug 26, 2022
@ShaMan123 ShaMan123 deleted the ts-brushes branch September 11, 2022 23:36
frankrousseau pushed a commit to cgwire/fabric.js that referenced this pull request Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants