@@ -18,21 +18,6 @@ class ControllerDrawingClass extends ControllerClass {
1818
1919 public currentStroke : PenStrokeSegment [ ] = [ ] ;
2020
21- public get isUsing ( ) {
22- return this . _isUsing ;
23- }
24- public shutDown ( ) {
25- this . _isUsing = false ;
26- this . currentStroke = [ ] ;
27- // 鼠标提示
28- Controller . setCursorNameHook ( CursorNameEnum . Default ) ;
29- }
30- public open ( ) {
31- this . _isUsing = true ;
32- // 鼠标提示
33- Controller . setCursorNameHook ( CursorNameEnum . Crosshair ) ;
34- }
35-
3621 private autoFillPenStrokeColorEnable = false ;
3722 private autoFillPenStrokeColor : Color = Color . Transparent ;
3823
@@ -60,70 +45,68 @@ class ControllerDrawingClass extends ControllerClass {
6045 private recordLocation : Vector [ ] = [ ] ;
6146
6247 public mousedown : ( event : MouseEvent ) => void = ( event : MouseEvent ) => {
63- if ( ! this . _isUsing ) return ;
64- if ( ! ( event . button === 0 ) ) {
48+ if ( Stage . leftMouseMode !== LeftMouseModeEnum . draw ) {
49+ return ;
50+ }
51+ if ( ! ( event . button === 0 && Stage . leftMouseMode === LeftMouseModeEnum . draw ) ) {
6552 return ;
6653 }
54+ this . _isUsing = true ;
6755 const pressWorldLocation = Renderer . transformView2World ( new Vector ( event . clientX , event . clientY ) ) ;
68- if ( event . button === 0 && Stage . leftMouseMode === LeftMouseModeEnum . draw ) {
69- this . recordLocation . push ( pressWorldLocation . clone ( ) ) ;
56+ this . recordLocation . push ( pressWorldLocation . clone ( ) ) ;
7057
71- this . lastMoveLocation = pressWorldLocation . clone ( ) ;
58+ this . lastMoveLocation = pressWorldLocation . clone ( ) ;
7259
73- Controller . setCursorNameHook ( CursorNameEnum . Crosshair ) ;
74- }
60+ Controller . setCursorNameHook ( CursorNameEnum . Crosshair ) ;
7561 } ;
7662
7763 public mousemove = ( event : MouseEvent ) => {
7864 if ( ! this . _isUsing ) return ;
79- if ( ! Controller . isMouseDown [ 0 ] ) {
65+ if ( ! Controller . isMouseDown [ 0 ] && Stage . leftMouseMode === LeftMouseModeEnum . draw ) {
8066 return ;
8167 }
8268 const worldLocation = Renderer . transformView2World ( new Vector ( event . clientX , event . clientY ) ) ;
83- if ( Controller . isMouseDown [ 0 ] && Stage . leftMouseMode === LeftMouseModeEnum . draw ) {
84- // 检测:如果移动距离不超过10,则不记录
85- if ( worldLocation . distance ( this . lastMoveLocation ) < 5 ) {
86- return ;
87- }
88- this . recordLocation . push ( worldLocation . clone ( ) ) ;
89-
90- // 记录笔刷
91- this . currentStroke . push ( new PenStrokeSegment ( this . lastMoveLocation , worldLocation , this . currentStrokeWidth ) ) ;
92- this . lastMoveLocation = worldLocation . clone ( ) ;
69+ // 检测:如果移动距离不超过10,则不记录
70+ if ( worldLocation . distance ( this . lastMoveLocation ) < 5 ) {
71+ return ;
9372 }
73+ this . recordLocation . push ( worldLocation . clone ( ) ) ;
74+
75+ // 记录笔刷
76+ this . currentStroke . push ( new PenStrokeSegment ( this . lastMoveLocation , worldLocation , this . currentStrokeWidth ) ) ;
77+ this . lastMoveLocation = worldLocation . clone ( ) ;
9478 } ;
9579
9680 public mouseup = ( event : MouseEvent ) => {
9781 if ( ! this . _isUsing ) return ;
98- if ( ! ( event . button === 0 ) ) {
82+ if ( ! ( event . button === 0 && Stage . leftMouseMode === LeftMouseModeEnum . draw ) ) {
9983 return ;
10084 }
101- if ( event . button === 0 && Stage . leftMouseMode === LeftMouseModeEnum . draw ) {
102- const releaseWorldLocation = Renderer . transformView2World ( new Vector ( event . clientX , event . clientY ) ) ;
103- this . recordLocation . push ( releaseWorldLocation . clone ( ) ) ;
104-
105- // 生成笔触
106- const strokeStringList : string [ ] = [ ] ;
107- for ( const location of this . recordLocation ) {
108- strokeStringList . push ( `${ Math . round ( location . x ) } ,${ Math . round ( location . y ) } ,${ this . currentStrokeWidth } ` ) ;
109- }
110- const contentString = strokeStringList . join ( "~" ) ;
111-
112- const stroke = new PenStroke ( {
113- type : "core:pen_stroke" ,
114- content : contentString ,
115- color : this . getCurrentStrokeColor ( ) . toArray ( ) ,
116- uuid : v4 ( ) ,
117- location : [ 0 , 0 ] ,
118- details : "" ,
119- } ) ;
120- stroke . setColor ( this . getCurrentStrokeColor ( ) ) ;
121- StageManager . addPenStroke ( stroke ) ;
122- this . recordLocation = [ ] ;
123- this . currentStroke = [ ] ;
124-
125- Controller . setCursorNameHook ( CursorNameEnum . Crosshair ) ;
85+ const releaseWorldLocation = Renderer . transformView2World ( new Vector ( event . clientX , event . clientY ) ) ;
86+ this . recordLocation . push ( releaseWorldLocation . clone ( ) ) ;
87+
88+ // 生成笔触
89+ const strokeStringList : string [ ] = [ ] ;
90+ for ( const location of this . recordLocation ) {
91+ strokeStringList . push ( `${ Math . round ( location . x ) } ,${ Math . round ( location . y ) } ,${ this . currentStrokeWidth } ` ) ;
12692 }
93+ const contentString = strokeStringList . join ( "~" ) ;
94+
95+ const stroke = new PenStroke ( {
96+ type : "core:pen_stroke" ,
97+ content : contentString ,
98+ color : this . getCurrentStrokeColor ( ) . toArray ( ) ,
99+ uuid : v4 ( ) ,
100+ location : [ 0 , 0 ] ,
101+ details : "" ,
102+ } ) ;
103+ stroke . setColor ( this . getCurrentStrokeColor ( ) ) ;
104+ StageManager . addPenStroke ( stroke ) ;
105+ this . recordLocation = [ ] ;
106+ this . currentStroke = [ ] ;
107+
108+ Controller . setCursorNameHook ( CursorNameEnum . Crosshair ) ;
109+ this . _isUsing = false ;
127110 } ;
128111
129112 public getCurrentStrokeColor ( ) {
0 commit comments