-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added set-off-set-zoom-to-coords.hook and AddCollection refactor
Added set-off-set-zoom-to-coords.hook
- Loading branch information
Showing
2 changed files
with
44 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/pods/toolbar/components/add-collection/set-off-set-zoom-to-coords.hook.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useCanvasViewSettingsContext } from '@/core/providers/canvas-view-settings'; | ||
import { CANVAS_MAX_HEIGHT, CANVAS_MAX_WIDTH } from '@/core/providers'; | ||
import { Coords } from '@/core/model'; | ||
|
||
export const useOffsetZoomToCoords = ({ x, y }: Coords): Coords => { | ||
const { canvasViewSettings, viewBoxSize } = useCanvasViewSettingsContext(); | ||
|
||
const MULTIPLIER_TO_SET_OFFSET_TO_CANVAS_DIMENSION_WIDTH = | ||
CANVAS_MAX_WIDTH / canvasViewSettings.canvasSize.width; | ||
const MULTIPLIER_TO_SET_OFFSET_TO_CANVAS_DIMENSION_HEIGHT = | ||
CANVAS_MAX_WIDTH / canvasViewSettings.canvasSize.height; | ||
const adjustedWidth = CANVAS_MAX_WIDTH / viewBoxSize.width; | ||
const adjustedHeight = CANVAS_MAX_HEIGHT / viewBoxSize.height; | ||
|
||
const newX = | ||
(x / (canvasViewSettings.zoomFactor * adjustedWidth) / adjustedWidth) * | ||
MULTIPLIER_TO_SET_OFFSET_TO_CANVAS_DIMENSION_WIDTH; | ||
const newY = | ||
(y / (canvasViewSettings.zoomFactor * adjustedHeight) / adjustedHeight) * | ||
MULTIPLIER_TO_SET_OFFSET_TO_CANVAS_DIMENSION_HEIGHT; | ||
|
||
return { x: newX, y: newY }; | ||
}; |