mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): do not floor cursor position
This commit is contained in:
parent
7ed24cf847
commit
c951e733d3
@ -1,5 +1,5 @@
|
||||
import type { KonvaNodeManager } from 'features/controlLayers/konva/nodeManager';
|
||||
import { getScaledFlooredCursorPosition } from 'features/controlLayers/konva/util';
|
||||
import { getScaledCursorPosition } from 'features/controlLayers/konva/util';
|
||||
import type { CanvasEntity } from 'features/controlLayers/store/types';
|
||||
import type Konva from 'konva';
|
||||
import type { Vector2d } from 'konva/lib/types';
|
||||
@ -25,7 +25,7 @@ const updateLastCursorPos = (
|
||||
stage: Konva.Stage,
|
||||
setLastCursorPos: KonvaNodeManager['stateApi']['setLastCursorPos']
|
||||
) => {
|
||||
const pos = getScaledFlooredCursorPosition(stage);
|
||||
const pos = getScaledCursorPosition(stage);
|
||||
if (!pos) {
|
||||
return null;
|
||||
}
|
||||
|
@ -34,6 +34,19 @@ export const getScaledFlooredCursorPosition = (stage: Konva.Stage): Vector2d | n
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the scaled cursor position on the stage. If the cursor is not currently over the stage, returns null.
|
||||
* @param stage The konva stage
|
||||
*/
|
||||
export const getScaledCursorPosition = (stage: Konva.Stage): Vector2d | null => {
|
||||
const pointerPosition = stage.getPointerPosition();
|
||||
const stageTransform = stage.getAbsoluteTransform().copy();
|
||||
if (!pointerPosition) {
|
||||
return null;
|
||||
}
|
||||
return stageTransform.invert().point(pointerPosition);
|
||||
};
|
||||
|
||||
/**
|
||||
* Snaps a position to the edge of the stage if within a threshold of the edge
|
||||
* @param pos The position to snap
|
||||
|
Loading…
Reference in New Issue
Block a user