tidy(ui): $cursorPosition -> $lastCursorPos

This commit is contained in:
psychedelicious 2024-05-04 19:01:18 +10:00 committed by Kent Keirsey
parent 7ca613d41c
commit ac0b9ba290
3 changed files with 9 additions and 9 deletions

View File

@ -6,7 +6,7 @@ import { createMemoizedSelector } from 'app/store/createMemoizedSelector';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import { useMouseEvents } from 'features/controlLayers/hooks/mouseEventHooks'; import { useMouseEvents } from 'features/controlLayers/hooks/mouseEventHooks';
import { import {
$cursorPosition, $lastCursorPos,
$lastMouseDownPos, $lastMouseDownPos,
$tool, $tool,
isRegionalGuidanceLayer, isRegionalGuidanceLayer,
@ -48,7 +48,7 @@ const useStageRenderer = (
const state = useAppSelector((s) => s.controlLayers.present); const state = useAppSelector((s) => s.controlLayers.present);
const tool = useStore($tool); const tool = useStore($tool);
const mouseEventHandlers = useMouseEvents(); const mouseEventHandlers = useMouseEvents();
const cursorPosition = useStore($cursorPosition); const lastCursorPos = useStore($lastCursorPos);
const lastMouseDownPos = useStore($lastMouseDownPos); const lastMouseDownPos = useStore($lastMouseDownPos);
const selectedLayerIdColor = useAppSelector(selectSelectedLayerColor); const selectedLayerIdColor = useAppSelector(selectSelectedLayerColor);
const selectedLayerType = useAppSelector(selectSelectedLayerType); const selectedLayerType = useAppSelector(selectSelectedLayerType);
@ -141,7 +141,7 @@ const useStageRenderer = (
selectedLayerIdColor, selectedLayerIdColor,
selectedLayerType, selectedLayerType,
state.globalMaskLayerOpacity, state.globalMaskLayerOpacity,
cursorPosition, lastCursorPos,
lastMouseDownPos, lastMouseDownPos,
state.brushSize state.brushSize
); );
@ -152,7 +152,7 @@ const useStageRenderer = (
selectedLayerIdColor, selectedLayerIdColor,
selectedLayerType, selectedLayerType,
state.globalMaskLayerOpacity, state.globalMaskLayerOpacity,
cursorPosition, lastCursorPos,
lastMouseDownPos, lastMouseDownPos,
state.brushSize, state.brushSize,
renderers, renderers,

View File

@ -3,8 +3,8 @@ import { useStore } from '@nanostores/react';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import { calculateNewBrushSize } from 'features/canvas/hooks/useCanvasZoom'; import { calculateNewBrushSize } from 'features/canvas/hooks/useCanvasZoom';
import { import {
$cursorPosition,
$isDrawing, $isDrawing,
$lastCursorPos,
$lastMouseDownPos, $lastMouseDownPos,
$tool, $tool,
brushSizeChanged, brushSizeChanged,
@ -63,7 +63,7 @@ const syncCursorPos = (stage: Konva.Stage): Vector2d | null => {
if (!pos) { if (!pos) {
return null; return null;
} }
$cursorPosition.set(pos); $lastCursorPos.set(pos);
return pos; return pos;
}; };
@ -117,7 +117,7 @@ export const useMouseEvents = () => {
if (!stage) { if (!stage) {
return; return;
} }
const pos = $cursorPosition.get(); const pos = $lastCursorPos.get();
if (!pos || !selectedLayerId || selectedLayerType !== 'regional_guidance_layer') { if (!pos || !selectedLayerId || selectedLayerType !== 'regional_guidance_layer') {
return; return;
} }
@ -188,7 +188,7 @@ export const useMouseEvents = () => {
dispatch(rgLayerPointsAdded({ layerId: selectedLayerId, point: [pos.x, pos.y] })); dispatch(rgLayerPointsAdded({ layerId: selectedLayerId, point: [pos.x, pos.y] }));
} }
$isDrawing.set(false); $isDrawing.set(false);
$cursorPosition.set(null); $lastCursorPos.set(null);
$lastMouseDownPos.set(null); $lastMouseDownPos.set(null);
}, },
[selectedLayerId, selectedLayerType, tool, dispatch] [selectedLayerId, selectedLayerType, tool, dispatch]

View File

@ -866,7 +866,7 @@ const migrateControlLayersState = (state: any): any => {
export const $isDrawing = atom(false); export const $isDrawing = atom(false);
export const $lastMouseDownPos = atom<Vector2d | null>(null); export const $lastMouseDownPos = atom<Vector2d | null>(null);
export const $tool = atom<Tool>('brush'); export const $tool = atom<Tool>('brush');
export const $cursorPosition = atom<Vector2d | null>(null); export const $lastCursorPos = atom<Vector2d | null>(null);
// IDs for singleton Konva layers and objects // IDs for singleton Konva layers and objects
export const TOOL_PREVIEW_LAYER_ID = 'tool_preview_layer'; export const TOOL_PREVIEW_LAYER_ID = 'tool_preview_layer';