@@ -23,7 +23,8 @@ class ToolPick {
23
23
this . m_objGraphics2d = objGra ;
24
24
this . m_wScreen = 0 ;
25
25
this . m_hScreen = 0 ;
26
- this . m_strMessage = '' ;
26
+ this . m_strMessageOnClick = '' ;
27
+ this . m_strMessageOnMove = '' ;
27
28
this . m_xMessage = 0 ;
28
29
this . m_yMessage = 0 ;
29
30
this . m_timeStart = 0 ;
@@ -89,12 +90,11 @@ class ToolPick {
89
90
return vTex ;
90
91
}
91
92
92
- onMouseDown ( xScr , yScr , store ) {
93
+ getMessageText ( xScr , yScr , store ) {
93
94
if ( this . m_wScreen === 0 || this . m_hScreen === 0 ) {
94
95
console . log ( 'ToolPick. onMouseDown. Bad screen size' ) ;
95
96
return ;
96
97
}
97
-
98
98
const xRatioImage = xScr / this . m_wScreen ;
99
99
const yRatioImage = yScr / this . m_hScreen ;
100
100
const vTex = this . screenToTexture ( xRatioImage , yRatioImage , store ) ;
@@ -105,7 +105,7 @@ class ToolPick {
105
105
const yDim = vol . m_yDim ;
106
106
107
107
if ( vTex . x < 0 || vTex . y < 0 || vTex . z < 0 || vTex . x >= vol . m_xDim || vTex . y >= vol . m_yDim ) {
108
- return ;
108
+ return 'x: 0 y: 0 z: 0 val: 0' ;
109
109
}
110
110
/*
111
111
if (mode2d === Modes2d.SAGGITAL) {
@@ -138,20 +138,37 @@ class ToolPick {
138
138
off = off * FOUR ;
139
139
val = vol . m_dataArray [ off ] ;
140
140
}
141
+ return `x: ${ vTex . x . toString ( ) } y: ${ vTex . y . toString ( ) } z: ${ vTex . z . toString ( ) } val: ${ val . toString ( ) } ` ;
142
+ }
141
143
144
+ onMouseDown ( xScr , yScr , store ) {
145
+ const message = this . getMessageText ( xScr , yScr , store ) ;
146
+ if ( ! message ) return ;
147
+ this . m_strMessageOnClick = message ;
142
148
this . m_xMessage = xScr ;
143
149
this . m_yMessage = yScr ;
144
- this . m_strMessage = 'x,y,z = ' + vTex . x . toString ( ) + ', ' + vTex . y . toString ( ) + ', ' + vTex . z . toString ( ) + '. val = ' + val . toString ( ) ;
145
- // console.log(`ToolPick. onMouseDown. ${this.m_strMessage}`);
146
150
this . m_timeStart = Date . now ( ) ;
147
151
setTimeout ( this . onTimerEnd , 6000 ) ;
148
152
} // end onMouseDown
149
153
154
+ onMouseMove ( xScr , yScr , store ) {
155
+ const message = this . getMessageText ( xScr , yScr , store ) ;
156
+ if ( ! message ) return ;
157
+ this . m_strMessageOnMove = message ;
158
+ }
159
+
150
160
onTimerEnd ( ) {
151
161
this . m_objGraphics2d . forceUpdate ( ) ;
152
162
}
153
163
154
164
render ( ctx ) {
165
+ ctx . fillStyle = 'white' ;
166
+ const FONT_SZ = 16 ;
167
+ ctx . font = FONT_SZ . toString ( ) + 'px Arial' ;
168
+ ctx . textBaseline = 'bottom' ;
169
+ ctx . textAlign = 'left' ;
170
+ ctx . fillText ( this . m_strMessageOnMove , 0 , this . m_hScreen ) ;
171
+
155
172
if ( this . m_timeStart === 0 ) {
156
173
return ;
157
174
}
@@ -162,10 +179,7 @@ class ToolPick {
162
179
if ( timeDelta < TIME_SHOW_MS ) {
163
180
// render message
164
181
// console.log('ToolPick. Render message on ctx');
165
- ctx . fillStyle = 'white' ;
166
- const FONT_SZ = 16 ;
167
- ctx . font = FONT_SZ . toString ( ) + 'px Arial' ;
168
- const sizeTextRect = ctx . measureText ( this . m_strMessage ) ;
182
+ const sizeTextRect = ctx . measureText ( this . m_strMessageOnClick ) ;
169
183
// console.log(`ToolPick. draw text. x = ${this.m_xMessage}, szRect = ${sizeTextRect.width}, wScr = ${this.m_wScreen}`);
170
184
if ( this . m_xMessage + sizeTextRect . width < this . m_wScreen ) {
171
185
ctx . textAlign = 'left' ;
@@ -178,7 +192,7 @@ class ToolPick {
178
192
ctx . textBaseline = 'bottom' ;
179
193
}
180
194
181
- ctx . fillText ( this . m_strMessage , this . m_xMessage , this . m_yMessage ) ;
195
+ ctx . fillText ( this . m_strMessageOnClick , this . m_xMessage , this . m_yMessage ) ;
182
196
}
183
197
}
184
198
}
0 commit comments