@@ -13,14 +13,21 @@ import { LeftMouseModeEnum, Stage } from "../../../../stage/Stage";
1313 * 涂鸦功能
1414 */
1515class ControllerDrawingClass extends ControllerClass {
16- // 一开始是禁用状态
1716 private _isUsing : boolean = false ;
1817
18+ /** 在移动的过程中,记录这一笔画的笔迹 */
1919 public currentStroke : PenStrokeSegment [ ] = [ ] ;
2020
2121 private autoFillPenStrokeColorEnable = false ;
2222 private autoFillPenStrokeColor : Color = Color . Transparent ;
2323
24+ /**
25+ * 初始按下的起始点的位置
26+ */
27+ public pressStartWordLocation = Vector . getZero ( ) ;
28+ /** 当前是否是在绘制直线 */
29+ public isDrawingLine = false ;
30+
2431 /**
2532 * 当前画笔的粗度
2633 */
@@ -52,7 +59,12 @@ class ControllerDrawingClass extends ControllerClass {
5259 return ;
5360 }
5461 this . _isUsing = true ;
62+
5563 const pressWorldLocation = Renderer . transformView2World ( new Vector ( event . clientX , event . clientY ) ) ;
64+ if ( Controller . pressingKeySet . has ( "shift" ) ) {
65+ this . isDrawingLine = true ;
66+ }
67+ this . pressStartWordLocation = pressWorldLocation . clone ( ) ;
5668 this . recordLocation . push ( pressWorldLocation . clone ( ) ) ;
5769
5870 this . lastMoveLocation = pressWorldLocation . clone ( ) ;
@@ -86,27 +98,52 @@ class ControllerDrawingClass extends ControllerClass {
8698 this . recordLocation . push ( releaseWorldLocation . clone ( ) ) ;
8799
88100 // 生成笔触
89- const strokeStringList : string [ ] = [ ] ;
90- for ( const location of this . recordLocation ) {
91- strokeStringList . push ( `${ Math . round ( location . x ) } ,${ Math . round ( location . y ) } ,${ this . currentStrokeWidth } ` ) ;
101+ if ( Controller . pressingKeySet . has ( "shift" ) ) {
102+ // 直线
103+ const startLocation = this . pressStartWordLocation ;
104+ const endLocation = releaseWorldLocation ;
105+ const strokeStringList : string [ ] = [
106+ `${ Math . round ( startLocation . x ) } ,${ Math . round ( startLocation . y ) } ,${ this . currentStrokeWidth } ` ,
107+ `${ Math . round ( endLocation . x ) } ,${ Math . round ( endLocation . y ) } ,${ this . currentStrokeWidth } ` ,
108+ ] ;
109+ const contentString = strokeStringList . join ( "~" ) ;
110+ const stroke = new PenStroke ( {
111+ type : "core:pen_stroke" ,
112+ content : contentString ,
113+ color : this . getCurrentStrokeColor ( ) . toArray ( ) ,
114+ uuid : v4 ( ) ,
115+ location : [ 0 , 0 ] ,
116+ details : "" ,
117+ } ) ;
118+ stroke . setColor ( this . getCurrentStrokeColor ( ) ) ;
119+ StageManager . addPenStroke ( stroke ) ;
120+ } else {
121+ // 普通笔迹
122+ const strokeStringList : string [ ] = [ ] ;
123+ for ( const location of this . recordLocation ) {
124+ strokeStringList . push ( `${ Math . round ( location . x ) } ,${ Math . round ( location . y ) } ,${ this . currentStrokeWidth } ` ) ;
125+ }
126+ const contentString = strokeStringList . join ( "~" ) ;
127+
128+ const stroke = new PenStroke ( {
129+ type : "core:pen_stroke" ,
130+ content : contentString ,
131+ color : this . getCurrentStrokeColor ( ) . toArray ( ) ,
132+ uuid : v4 ( ) ,
133+ location : [ 0 , 0 ] ,
134+ details : "" ,
135+ } ) ;
136+ stroke . setColor ( this . getCurrentStrokeColor ( ) ) ;
137+ StageManager . addPenStroke ( stroke ) ;
92138 }
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 ) ;
139+
140+ // 清理
105141 this . recordLocation = [ ] ;
106142 this . currentStroke = [ ] ;
107143
108144 Controller . setCursorNameHook ( CursorNameEnum . Crosshair ) ;
109145 this . _isUsing = false ;
146+ this . isDrawingLine = false ;
110147 } ;
111148
112149 public getCurrentStrokeColor ( ) {
0 commit comments