Skip to content

Commit a414ba5

Browse files
author
Oleksandr Iefymchuk
committed
Always show voxel intensity
1 parent d9c6276 commit a414ba5

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

src/engine/Graphics2d.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,8 @@ class Graphics2d extends React.Component {
674674
const xScr = xContainer;
675675
const yScr = yContainer;
676676

677+
this.m_toolPick.onMouseMove(xScr, yScr, store);
678+
677679
if (indexTools2d === Tools2dType.PAINT) {
678680
this.m_toolPaint.onMouseMove(xScr, yScr, store);
679681
}

src/engine/tools2d/ToolPick.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class ToolPick {
2323
this.m_objGraphics2d = objGra;
2424
this.m_wScreen = 0;
2525
this.m_hScreen = 0;
26-
this.m_strMessage = '';
26+
this.m_strMessageOnClick = '';
27+
this.m_strMessageOnMove = '';
2728
this.m_xMessage = 0;
2829
this.m_yMessage = 0;
2930
this.m_timeStart = 0;
@@ -89,12 +90,11 @@ class ToolPick {
8990
return vTex;
9091
}
9192

92-
onMouseDown(xScr, yScr, store) {
93+
getMessageText(xScr, yScr, store) {
9394
if (this.m_wScreen === 0 || this.m_hScreen === 0) {
9495
console.log('ToolPick. onMouseDown. Bad screen size');
9596
return;
9697
}
97-
9898
const xRatioImage = xScr / this.m_wScreen;
9999
const yRatioImage = yScr / this.m_hScreen;
100100
const vTex = this.screenToTexture(xRatioImage, yRatioImage, store);
@@ -105,7 +105,7 @@ class ToolPick {
105105
const yDim = vol.m_yDim;
106106

107107
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';
109109
}
110110
/*
111111
if (mode2d === Modes2d.SAGGITAL) {
@@ -138,20 +138,37 @@ class ToolPick {
138138
off = off * FOUR;
139139
val = vol.m_dataArray[off];
140140
}
141+
return `x: ${vTex.x.toString()} y: ${vTex.y.toString()} z: ${vTex.z.toString()} val: ${val.toString()}`;
142+
}
141143

144+
onMouseDown(xScr, yScr, store) {
145+
const message = this.getMessageText(xScr, yScr, store);
146+
if (!message) return;
147+
this.m_strMessageOnClick = message;
142148
this.m_xMessage = xScr;
143149
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}`);
146150
this.m_timeStart = Date.now();
147151
setTimeout(this.onTimerEnd, 6000);
148152
} // end onMouseDown
149153

154+
onMouseMove(xScr, yScr, store) {
155+
const message = this.getMessageText(xScr, yScr, store);
156+
if (!message) return;
157+
this.m_strMessageOnMove = message;
158+
}
159+
150160
onTimerEnd() {
151161
this.m_objGraphics2d.forceUpdate();
152162
}
153163

154164
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+
155172
if (this.m_timeStart === 0) {
156173
return;
157174
}
@@ -162,10 +179,7 @@ class ToolPick {
162179
if (timeDelta < TIME_SHOW_MS) {
163180
// render message
164181
// 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);
169183
// console.log(`ToolPick. draw text. x = ${this.m_xMessage}, szRect = ${sizeTextRect.width}, wScr = ${this.m_wScreen}`);
170184
if (this.m_xMessage + sizeTextRect.width < this.m_wScreen) {
171185
ctx.textAlign = 'left';
@@ -178,7 +192,7 @@ class ToolPick {
178192
ctx.textBaseline = 'bottom';
179193
}
180194

181-
ctx.fillText(this.m_strMessage, this.m_xMessage, this.m_yMessage);
195+
ctx.fillText(this.m_strMessageOnClick, this.m_xMessage, this.m_yMessage);
182196
}
183197
}
184198
}

src/ui/DragAndDrop/DragAndDropContainer.jsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ import React, { useState } from 'react';
22
import css from '../Main.module.css';
33

44
export const DragAndDropContainer = ({ children }) => {
5-
const [position, setPosition] = useState({ top: 100, left: 900 });
5+
const [position, setPosition] = useState({ top: 15, right: 1 });
66
const [isDragging, setIsDragging] = useState(false);
77
const [offset, setOffset] = useState({ x: 0, y: 0 });
88

99
const startDrag = (e) => {
1010
if (e.target.tagName.toLowerCase() !== 'span') {
11+
const rect = e.currentTarget.getBoundingClientRect();
1112
setIsDragging(true);
1213
setOffset({
13-
x: e.clientX - position.left,
14-
y: e.clientY - position.top,
14+
x: e.clientX - rect.right,
15+
y: e.clientY - rect.top,
1516
});
1617
}
1718
};
@@ -24,7 +25,7 @@ export const DragAndDropContainer = ({ children }) => {
2425
if (isDragging) {
2526
const x = e.clientX - offset.x;
2627
const y = e.clientY - offset.y;
27-
setPosition({ left: x, top: y });
28+
setPosition({ top: (y / window.innerHeight) * 100, right: ((window.innerWidth - x) / window.innerWidth) * 100 });
2829
}
2930
};
3031

@@ -36,8 +37,8 @@ export const DragAndDropContainer = ({ children }) => {
3637
style={{
3738
opacity: isDragging ? 0.5 : 1,
3839
cursor: isDragging ? 'grabbing' : 'grab',
39-
top: position.top,
40-
left: position.left,
40+
top: `${position.top}%`,
41+
right: `${position.right}%`,
4142
}}
4243
className={css.settings}
4344
>

src/ui/Header/Header.module.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
display: flex;
33
gap: 5px;
44
width: 95%;
5-
min-width: 432px;
65
justify-content: space-between;
76
z-index: 12;
87
}

0 commit comments

Comments
 (0)