dormeroffset 기능 추가
This commit is contained in:
parent
67ba9be6b6
commit
2a108eb1af
@ -1,9 +1,11 @@
|
|||||||
|
import { useState, useEffect, useRef } from 'react'
|
||||||
import { useMessage } from '@/hooks/useMessage'
|
import { useMessage } from '@/hooks/useMessage'
|
||||||
import WithDraggable from '@/components/common/draggable/WithDraggable'
|
import WithDraggable from '@/components/common/draggable/WithDraggable'
|
||||||
import { useRecoilValue } from 'recoil'
|
import { useRecoilValue } from 'recoil'
|
||||||
import { contextPopupPositionState } from '@/store/popupAtom'
|
import { contextPopupPositionState } from '@/store/popupAtom'
|
||||||
import { usePopup } from '@/hooks/usePopup'
|
import { usePopup } from '@/hooks/usePopup'
|
||||||
import { useState } from 'react'
|
import { useObjectBatch } from '@/hooks/object/useObjectBatch'
|
||||||
|
import { canvasState } from '@/store/canvasAtom'
|
||||||
|
|
||||||
export default function DormerOffset(props) {
|
export default function DormerOffset(props) {
|
||||||
const contextPopupPosition = useRecoilValue(contextPopupPositionState)
|
const contextPopupPosition = useRecoilValue(contextPopupPositionState)
|
||||||
@ -12,6 +14,31 @@ export default function DormerOffset(props) {
|
|||||||
const { closePopup } = usePopup()
|
const { closePopup } = usePopup()
|
||||||
const [arrow1, setArrow1] = useState(null)
|
const [arrow1, setArrow1] = useState(null)
|
||||||
const [arrow2, setArrow2] = useState(null)
|
const [arrow2, setArrow2] = useState(null)
|
||||||
|
const arrow1LengthRef = useRef()
|
||||||
|
const arrow2LengthRef = useRef()
|
||||||
|
|
||||||
|
const canvas = useRecoilValue(canvasState)
|
||||||
|
const { dormerOffsetKeyEvent, dormerOffset } = useObjectBatch({})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (canvas) {
|
||||||
|
dormerOffsetKeyEvent(setArrow1, setArrow2)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const handleOffsetDormer = () => {
|
||||||
|
const length1 = arrow1LengthRef.current.value
|
||||||
|
const length2 = arrow2LengthRef.current.value
|
||||||
|
|
||||||
|
dormerOffset(arrow1, arrow2, length1, length2)
|
||||||
|
|
||||||
|
setArrow1(null)
|
||||||
|
setArrow2(null)
|
||||||
|
arrow1LengthRef.current.value = ''
|
||||||
|
arrow2LengthRef.current.value = ''
|
||||||
|
|
||||||
|
// closePopup(id)
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<WithDraggable isShow={true} pos={pos}>
|
<WithDraggable isShow={true} pos={pos}>
|
||||||
<div className={`modal-pop-wrap xm mount`}>
|
<div className={`modal-pop-wrap xm mount`}>
|
||||||
@ -29,44 +56,40 @@ export default function DormerOffset(props) {
|
|||||||
<p className="mb5">{getMessage('length')}</p>
|
<p className="mb5">{getMessage('length')}</p>
|
||||||
<div className="input-move-wrap mb5">
|
<div className="input-move-wrap mb5">
|
||||||
<div className="input-move">
|
<div className="input-move">
|
||||||
<input type="text" className="input-origin" defaultValue={0} />
|
<input type="text" className="input-origin" ref={arrow1LengthRef} placeholder="0" />
|
||||||
</div>
|
</div>
|
||||||
<span>mm</span>
|
<span>mm</span>
|
||||||
<div className="direction-move-wrap">
|
<div className="direction-move-wrap">
|
||||||
<button
|
<button
|
||||||
className={`direction up ${arrow1 === '↑' ? 'act' : ''}`}
|
className={`direction up ${arrow1 === 'up' ? 'act' : ''}`}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setArrow1('↑')
|
setArrow1('up')
|
||||||
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowUp' }))
|
|
||||||
}}
|
}}
|
||||||
></button>
|
></button>
|
||||||
<button
|
<button
|
||||||
className={`direction down ${arrow1 === '↓' ? 'act' : ''}`}
|
className={`direction down ${arrow1 === 'down' ? 'act' : ''}`}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setArrow1('↓')
|
setArrow1('down')
|
||||||
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown' }))
|
|
||||||
}}
|
}}
|
||||||
></button>
|
></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="input-move-wrap">
|
<div className="input-move-wrap">
|
||||||
<div className="input-move">
|
<div className="input-move">
|
||||||
<input type="text" className="input-origin" defaultValue={0} />
|
<input type="text" className="input-origin" ref={arrow2LengthRef} placeholder="0" />
|
||||||
</div>
|
</div>
|
||||||
<span>mm</span>
|
<span>mm</span>
|
||||||
<div className="direction-move-wrap">
|
<div className="direction-move-wrap">
|
||||||
<button
|
<button
|
||||||
className={`direction left ${arrow2 === '←' ? 'act' : ''}`}
|
className={`direction left ${arrow2 === 'left' ? 'act' : ''}`}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setArrow2('←')
|
setArrow2('left')
|
||||||
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowLeft' }))
|
|
||||||
}}
|
}}
|
||||||
></button>
|
></button>
|
||||||
<button
|
<button
|
||||||
className={`direction right ${arrow2 === '→' ? 'act' : ''}`}
|
className={`direction right ${arrow2 === 'right' ? 'act' : ''}`}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setArrow2('→')
|
setArrow2('right')
|
||||||
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowRight' }))
|
|
||||||
}}
|
}}
|
||||||
></button>
|
></button>
|
||||||
</div>
|
</div>
|
||||||
@ -75,7 +98,9 @@ export default function DormerOffset(props) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="grid-btn-wrap">
|
<div className="grid-btn-wrap">
|
||||||
<button className="btn-frame modal act">{getMessage('modal.common.save')}</button>
|
<button className="btn-frame modal act" onClick={handleOffsetDormer}>
|
||||||
|
{getMessage('modal.common.save')}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -16,7 +16,7 @@ import { fontSelector } from '@/store/fontAtom'
|
|||||||
export function useObjectBatch({ isHidden, setIsHidden }) {
|
export function useObjectBatch({ isHidden, setIsHidden }) {
|
||||||
const { getMessage } = useMessage()
|
const { getMessage } = useMessage()
|
||||||
const canvas = useRecoilValue(canvasState)
|
const canvas = useRecoilValue(canvasState)
|
||||||
const { addCanvasMouseEventListener, initEvent } = useEvent()
|
const { addCanvasMouseEventListener, initEvent, addDocumentEventListener } = useEvent()
|
||||||
const { swalFire } = useSwal()
|
const { swalFire } = useSwal()
|
||||||
const { drawDirectionArrow } = usePolygon()
|
const { drawDirectionArrow } = usePolygon()
|
||||||
const lengthTextFont = useRecoilValue(fontSelector('lengthText'))
|
const lengthTextFont = useRecoilValue(fontSelector('lengthText'))
|
||||||
@ -963,6 +963,8 @@ export function useObjectBatch({ isHidden, setIsHidden }) {
|
|||||||
})
|
})
|
||||||
canvas?.add(reGroup)
|
canvas?.add(reGroup)
|
||||||
canvas?.remove(groupObj)
|
canvas?.remove(groupObj)
|
||||||
|
|
||||||
|
return reGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
const moveObjectBatch = () => {
|
const moveObjectBatch = () => {
|
||||||
@ -986,6 +988,30 @@ export function useObjectBatch({ isHidden, setIsHidden }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dormerOffsetKeyEvent = (setArrow1, setArrow2) => {
|
||||||
|
addDocumentEventListener('keydown', document, (e) => {
|
||||||
|
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
|
||||||
|
const keyEvent = e.key === 'ArrowDown' ? 'down' : 'up'
|
||||||
|
setArrow1(keyEvent)
|
||||||
|
} else if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
|
||||||
|
const keyEvent = e.key === 'ArrowLeft' ? 'left' : 'right'
|
||||||
|
setArrow2(keyEvent)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const dormerOffset = (arrow1, arrow2, length1, length2) => {
|
||||||
|
length1 = parseInt(length1) / 10
|
||||||
|
length2 = parseInt(length2) / 10
|
||||||
|
|
||||||
|
const dormer = canvas.getActiveObject()
|
||||||
|
if (length1) dormer.top = arrow1 === 'down' ? dormer.top + length1 : dormer.top - length1
|
||||||
|
if (length2) dormer.left = arrow2 === 'left' ? dormer.left - length2 : dormer.left + length2
|
||||||
|
|
||||||
|
const newDormer = reGroupObject(dormer)
|
||||||
|
canvas?.setActiveObject(newDormer)
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
applyOpeningAndShadow,
|
applyOpeningAndShadow,
|
||||||
applyDormers,
|
applyDormers,
|
||||||
@ -993,5 +1019,7 @@ export function useObjectBatch({ isHidden, setIsHidden }) {
|
|||||||
splitDormerPentagon,
|
splitDormerPentagon,
|
||||||
resizeObjectBatch,
|
resizeObjectBatch,
|
||||||
moveObjectBatch,
|
moveObjectBatch,
|
||||||
|
dormerOffsetKeyEvent,
|
||||||
|
dormerOffset,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user