Color picker sorta working again.

This commit is contained in:
2019-10-27 13:25:41 -07:00
parent c2aef6df5b
commit 43fba05875
3 changed files with 21 additions and 11 deletions

View File

@@ -15,7 +15,7 @@ const MAX_ZOOM_FACTOR = 32;
const Sidebar = (props) => {
let {
renderTimeSeconds, binary, binaryMax, scene, imageMetadata, zoomFactor, x, y,
renderTimeSeconds, binary, binaryMax, scene, imageMetadata, zoomFactor, mouseX, mouseY,
onZoom,
} = props;
let samples = imageMetadata.map((md) => {
@@ -23,9 +23,10 @@ const Sidebar = (props) => {
if (pix === undefined) { return <p key={md.name}>Loading...</p>; }
let max = binaryMax[md.name];
let [w, h] = md.size;
let xOff = Math.min(w, Math.max(0, Math.round(x*w)));
let yOff = Math.min(h, Math.max(0, Math.round(y*h)));
let xOff = mouseX; // Math.min(w, Math.max(0, Math.round(x*w)));
let yOff = mouseY; // Math.min(h, Math.max(0, Math.round(y*h)));
let v = pix[xOff+yOff*w];
//console.log(`xOff ${xOff} yOff ${yOff} v ${v}`);
let color = "#fff";
let rgb = "";
let value = "";
@@ -121,7 +122,7 @@ class App extends React.Component {
isFrozen: false,
isMouseDown: false,
isZoomed: true,
zoomFactor: 4,
zoomFactor: 2,
mouseX: 0,
mouseY: 0,
offsetX: 0,
@@ -220,7 +221,7 @@ class App extends React.Component {
});
images = imageMetadata.map((metadata) => {
let {name, ratio, image} = metadata;
let {name, ratio, image, size} = metadata;
let width = 384;
let height = (ratio * width).toFixed();
let url = ROOT + image + '?t=' + timestamp;
@@ -248,9 +249,13 @@ class App extends React.Component {
} else {
let rect = e.currentTarget.getBoundingClientRect();
let x = e.clientX - rect.left;
let y = e.clientY - rect.top;
this.setState({mouseX: x/width, mouseY: y/height});
let screenX = e.clientX - rect.left;
let screenY = e.clientY - rect.top;
let viewW = size[0] / zoomFactor;
let viewH = size[1] / zoomFactor;
let xOff = (-offsetX*size[0])/(zoomFactor * width) + (screenX / width) * viewW;
let yOff = (-offsetY*size[1])/(zoomFactor * height) + (screenY / height) * viewH;
this.setState({mouseX: Math.round(xOff), mouseY: Math.round(yOff)});
}
e.preventDefault();
};
@@ -281,7 +286,6 @@ class App extends React.Component {
//onClick={mouseClick}
onMouseDown={mouseDown}
onMouseUp={mouseUp}
//onMouseMove={mouseMove}
onMouseMove={mouseMove}
//onMouseEnter={mouseEnter}
//onMouseLeave={mouseLeave}
@@ -307,7 +311,8 @@ class App extends React.Component {
renderTimeSeconds={renderTimeSeconds}
imageMetadata={imageMetadata}
zoomFactor={zoomFactor}
x={mouseX} y={mouseY}
mouseX={mouseX}
mouseY={mouseY}
binary={binary}
binaryMax={binaryMax}
onZoom={onZoom} />;