@@ -73,6 +73,10 @@ export class nrrd_tools {
7373 Max_sensitive : 100 ,
7474 readyToUpdate : true ,
7575 showContrast : false ,
76+ enableCursorChoose : false ,
77+ isCursorSelect : false ,
78+ cursorPageX : 0 ,
79+ cursorPageY : 0 ,
7680 Mouse_Over_x : 0 ,
7781 Mouse_Over_y : 0 ,
7882 Mouse_Over : false ,
@@ -160,12 +164,12 @@ export class nrrd_tools {
160164 this . container . addEventListener ( "keydown" , ( ev : KeyboardEvent ) => {
161165 if ( ev . key === "Shift" ) {
162166 this . Is_Shift_Pressed = true ;
167+ this . nrrd_states . enableCursorChoose = false ;
163168 }
164- if ( ev . key === "ArrowUp" ) {
165- this . setSliceMoving ( - 1 ) ;
166- }
167- if ( ev . key === "ArrowDown" ) {
168- this . setSliceMoving ( 1 ) ;
169+ if ( ev . key === "s" ) {
170+ this . Is_Draw = false ;
171+ this . nrrd_states . enableCursorChoose =
172+ ! this . nrrd_states . enableCursorChoose ;
169173 }
170174 } ) ;
171175 this . container . addEventListener ( "keyup" , ( ev : KeyboardEvent ) => {
@@ -860,30 +864,33 @@ export class nrrd_tools {
860864 this . drawingCanvas . removeEventListener ( "wheel" , this . handleWheelMove ) ;
861865
862866 if ( e . button === 0 ) {
863- if ( ! this . Is_Shift_Pressed ) {
864- return ;
865- }
866-
867- leftclicked = true ;
868- lines = [ ] ;
869- Is_Painting = true ;
870- this . Is_Draw = true ;
867+ if ( this . Is_Shift_Pressed ) {
868+ leftclicked = true ;
869+ lines = [ ] ;
870+ Is_Painting = true ;
871+ this . Is_Draw = true ;
872+
873+ if ( this . gui_states . Eraser ) {
874+ this . drawingCanvas . style . cursor =
875+ "url(https://raw.githubusercontent.com/LinkunGao/copper3d_icons/main/icons/circular-cursor.png) 52 52, crosshair" ;
876+ } else {
877+ this . drawingCanvas . style . cursor =
878+ this . nrrd_states . defaultPaintCursor ;
879+ }
871880
872- if ( this . gui_states . Eraser ) {
873- this . drawingCanvas . style . cursor =
874- "url(https://raw.githubusercontent.com/LinkunGao/copper3d_icons/main/icons/circular-cursor.png) 52 52, crosshair" ;
875- } else {
876- this . drawingCanvas . style . cursor =
877- this . nrrd_states . defaultPaintCursor ;
881+ this . nrrd_states . drawStartPos . set ( e . offsetX , e . offsetY ) ;
882+ this . drawingLayerOneCtx . beginPath ( ) ;
883+ this . drawingCanvas . addEventListener ( "pointerup" , handlePointerUp ) ;
884+ this . drawingCanvas . addEventListener (
885+ "pointermove" ,
886+ handleOnPainterMove
887+ ) ;
888+ } else if ( this . nrrd_states . enableCursorChoose ) {
889+ this . nrrd_states . cursorPageX =
890+ e . offsetX / this . nrrd_states . sizeFoctor ;
891+ this . nrrd_states . cursorPageY =
892+ e . offsetY / this . nrrd_states . sizeFoctor ;
878893 }
879-
880- this . nrrd_states . drawStartPos . set ( e . offsetX , e . offsetY ) ;
881- this . drawingLayerOneCtx . beginPath ( ) ;
882- this . drawingCanvas . addEventListener ( "pointerup" , handlePointerUp ) ;
883- this . drawingCanvas . addEventListener (
884- "pointermove" ,
885- handleOnPainterMove
886- ) ;
887894 } else if ( e . button === 2 ) {
888895 rightclicked = true ;
889896 let offsetX = parseInt ( this . drawingCanvas . style . left ) ;
@@ -1075,6 +1082,22 @@ export class nrrd_tools {
10751082 this . drawingCtx . stroke ( ) ;
10761083 }
10771084 }
1085+ if ( this . nrrd_states . enableCursorChoose ) {
1086+ this . drawingCtx . clearRect (
1087+ 0 ,
1088+ 0 ,
1089+ this . nrrd_states . changedWidth ,
1090+ this . nrrd_states . changedHeight
1091+ ) ;
1092+
1093+ const ex =
1094+ this . nrrd_states . cursorPageX * this . nrrd_states . sizeFoctor ;
1095+ const ey =
1096+ this . nrrd_states . cursorPageY * this . nrrd_states . sizeFoctor ;
1097+
1098+ this . drawLine ( ex , 0 , ex , this . drawingCanvas . height ) ;
1099+ this . drawLine ( 0 , ey , this . drawingCanvas . width , ey ) ;
1100+ }
10781101 }
10791102 this . drawingCtx . drawImage ( this . drawingCanvasLayerOne , 0 , 0 ) ;
10801103 } else {
@@ -1089,6 +1112,14 @@ export class nrrd_tools {
10891112 } ) ;
10901113 }
10911114
1115+ private drawLine = ( x1 : number , y1 : number , x2 : number , y2 : number ) => {
1116+ this . drawingCtx . beginPath ( ) ;
1117+ this . drawingCtx . moveTo ( x1 , y1 ) ;
1118+ this . drawingCtx . lineTo ( x2 , y2 ) ;
1119+ this . drawingCtx . strokeStyle = this . gui_states . color ;
1120+ this . drawingCtx . stroke ( ) ;
1121+ } ;
1122+
10921123 private undoLastPainting ( ) {
10931124 this . Is_Draw = true ;
10941125 this . drawingCanvasLayerOne . width = this . drawingCanvasLayerOne . width ;
0 commit comments