Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: LEAP-148: Fix MagicWand in MIG scenario with image preloading #5385

Merged
merged 13 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/dist/libs/editor/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/dist/libs/editor/main.js.map

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions web/libs/editor/src/components/ImageView/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const Image = observer(forwardRef(({
updateImageSize,
usedValue,
size,
overlay,
}, ref) => {
const imageSize = useMemo(() => {
return {
Expand All @@ -45,6 +46,7 @@ export const Image = observer(forwardRef(({

return (
<Block name="image" style={imageSize}>
{overlay}
<ImageProgress
downloading={imageEntity.downloading}
progress={imageEntity.progress}
Expand Down Expand Up @@ -76,7 +78,7 @@ const ImageProgress = observer(({
return downloading ? (
<Block name="image-progress">
<Elem name="message">Downloading image</Elem>
<Elem tag="progress" name="bar" value={progress} min="0" max={1} step={0.0001}/>
<Elem tag="progress" name="bar" value={progress} min="0" max={1} step={0.0001} />
</Block>
) : error ? (
<ImageLoadingError src={src} value={usedValue} />
Expand Down Expand Up @@ -121,6 +123,6 @@ const ImageLoadingError = ({ src, value }) => {
}, [src]);

return (
<ErrorMessage error={error}/>
<ErrorMessage error={error} />
);
};
68 changes: 29 additions & 39 deletions web/libs/editor/src/components/ImageView/ImageView.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,22 @@ const Crosshair = memo(forwardRef(({ width, height }, ref) => {
);
}));

/**
* Component that creates an overlay on top
* of the image to support Magic Wand tool
*/
const CanvasOverlay = observer(({ item }) => {
return isFF(FF_DEV_4081) ? (
<canvas
className={styles.overlay}
ref={ref => {
item.setOverlayRef(ref);
}}
style={item.imageTransform}
/>
) : null;
});

export default observer(
class ImageView extends Component {
// stored position of canvas before creating region
Expand All @@ -506,9 +522,7 @@ export default observer(
crosshairRef = createRef();
handleDeferredMouseDown = null;
deferredClickTimeout = [];
skipNextMouseDown = false;
skipNextClick = false;
skipNextMouseUp = false;
skipMouseUp = false;
mouseDownPoint = null;

constructor(props) {
Expand All @@ -522,10 +536,10 @@ export default observer(
const { item } = this.props;

if (isFF(FF_DEV_1442)) {
this.handleDeferredMouseDown?.(true);
this.handleDeferredMouseDown?.();
}
if (this.skipNextClick) {
this.skipNextClick = false;
if (this.skipMouseUp) {
this.skipMouseUp = false;
return;
}

Expand Down Expand Up @@ -558,8 +572,8 @@ export default observer(
};

handleDeferredClick = (handleDeferredMouseDownCallback, handleDeselection, eligibleToDeselect = false) => {
this.handleDeferredMouseDown = (wasClicked) => {
if (wasClicked && eligibleToDeselect) {
this.handleDeferredMouseDown = () => {
if (eligibleToDeselect) {
handleDeselection();
}
handleDeferredMouseDownCallback();
Expand All @@ -568,7 +582,7 @@ export default observer(
};
this.resetDeferredClickTimeout();
this.deferredClickTimeout.push(setTimeout(() => {
this.handleDeferredMouseDown?.(false);
this.handleDeferredMouseDown?.();
}, this.props.item.annotation.isDrawing ? 0 : 100));
};

Expand All @@ -577,7 +591,6 @@ export default observer(
const isPanTool = item.getToolsManager().findSelectedTool()?.fullName === 'ZoomPanTool';
const isMoveTool = item.getToolsManager().findSelectedTool()?.fullName === 'MoveTool';

this.skipNextMouseDown = this.skipNextMouseUp = this.skipNextClick = false;
if (isFF(FF_LSDV_4930)) {
this.mouseDownPoint = { x: e.evt.offsetX, y: e.evt.offsetY };
}
Expand Down Expand Up @@ -629,10 +642,6 @@ export default observer(

this.canvasX = left;
this.canvasY = top;
if (this.skipNextMouseDown) {
this.skipNextMouseDown = false;
return true;
}
item.event('mousedown', e, x, y);

return true;
Expand All @@ -659,9 +668,7 @@ export default observer(

const handleDeselection = () => {
item.annotation.unselectAll();
this.skipNextMouseDown = true;
this.skipNextMouseUp = true;
this.skipNextClick = true;
this.skipMouseUp = true;
};

this.handleDeferredClick(handleMouseDown, handleDeselection, eligibleToDeselect);
Expand Down Expand Up @@ -689,7 +696,7 @@ export default observer(

item.freezeHistory();

return this.triggerMouseUp(e, x - this.canvasX, y - this.canvasY);
return item.event('mouseup', e, x - this.canvasX, y - this.canvasY);
};

handleGlobalMouseMove = e => {
Expand All @@ -714,17 +721,7 @@ export default observer(
item.freezeHistory();
item.setSkipInteractions(false);

return this.triggerMouseUp(e, e.evt.offsetX, e.evt.offsetY);
};

triggerMouseUp = (e, x, y) => {
if (this.skipNextMouseUp) {
this.skipNextMouseUp = false;
return;
}
const { item } = this.props;

return item.event('mouseup', e, x, y);
return item.event('mouseup', e, e.evt.offsetX, e.evt.offsetY);
};

handleMouseMove = e => {
Expand All @@ -740,7 +737,7 @@ export default observer(

if (isFF(FF_DEV_1442) && isDragging) {
this.resetDeferredClickTimeout();
this.handleDeferredMouseDown?.(false);
this.handleDeferredMouseDown?.();
}

if ((isMouseWheelClick || isShiftDrag) && item.zoomScale > 1) {
Expand Down Expand Up @@ -1020,6 +1017,7 @@ export default observer(
imageTransform={item.imageTransform}
updateImageSize={item.updateImageSize}
size={item.canvasSize}
overlay={<CanvasOverlay item={item} />}
/>
) : (
<div
Expand All @@ -1045,15 +1043,7 @@ export default observer(
crossOrigin={item.imageCrossOrigin}
alt="LS"
/>
{isFF(FF_DEV_4081) ? (
<canvas
className={styles.overlay}
ref={ref => {
item.setOverlayRef(ref);
}}
style={item.imageTransform}
/>
) : null}
<CanvasOverlay item={item} />
</div>
)}
{/* @todo this is dirty hack; rewrite to proper async waiting for data to load */}
Expand Down
2 changes: 1 addition & 1 deletion web/libs/editor/src/tools/MagicWand.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ const _Tool = types
msg = 'The Magic Wand is not supported on rotated images';
} else {
msg = 'The Magic Wand is not supported if the crosshair is turned on';
}
}

alert(msg);
throw msg;
Expand Down
Loading