[1059] : [HANASYS DESIGN】文字作成について]
[작업내용] : 텍스트 입력 모드 토글로 종료 모드 기능 추가
This commit is contained in:
parent
50aa5ca556
commit
ed68a93b20
@ -210,6 +210,7 @@ export const SAVE_KEY = [
|
|||||||
'toFixed',
|
'toFixed',
|
||||||
'startPoint',
|
'startPoint',
|
||||||
'endPoint',
|
'endPoint',
|
||||||
|
'editable',
|
||||||
'isSortedPoints',
|
'isSortedPoints',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@ -22,12 +22,12 @@ export function useCommonUtils() {
|
|||||||
const lengthTextFont = useRecoilValue(fontSelector('lengthText'))
|
const lengthTextFont = useRecoilValue(fontSelector('lengthText'))
|
||||||
const commonTextFont = useRecoilValue(fontSelector('commonText'))
|
const commonTextFont = useRecoilValue(fontSelector('commonText'))
|
||||||
const [commonUtils, setCommonUtilsState] = useRecoilState(commonUtilsState)
|
const [commonUtils, setCommonUtilsState] = useRecoilState(commonUtilsState)
|
||||||
const { addPopup } = usePopup()
|
const { addPopup, closeAll } = usePopup()
|
||||||
const { drawDirectionArrow, addLengthText } = usePolygon()
|
const { drawDirectionArrow, addLengthText } = usePolygon()
|
||||||
const { applyDormers } = useObjectBatch({})
|
const { applyDormers } = useObjectBatch({})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (commonUtils.text) {
|
if (commonUtils.text || !commonUtils.text) {
|
||||||
commonTextMode()
|
commonTextMode()
|
||||||
} else if (commonUtils.dimension) {
|
} else if (commonUtils.dimension) {
|
||||||
commonDimensionMode()
|
commonDimensionMode()
|
||||||
@ -38,35 +38,57 @@ export function useCommonUtils() {
|
|||||||
|
|
||||||
const commonTextMode = () => {
|
const commonTextMode = () => {
|
||||||
let textbox
|
let textbox
|
||||||
|
closeAll()
|
||||||
if (commonUtils.text) {
|
if (commonUtils.text) {
|
||||||
commonTextKeyEvent()
|
setTimeout(() => {
|
||||||
addCanvasMouseEventListener('mouse:down', (event) => {
|
commonTextKeyEvent()
|
||||||
const pointer = canvas?.getPointer(event.e)
|
addCanvasMouseEventListener('mouse:down', (event) => {
|
||||||
|
const pointer = canvas?.getPointer(event.e)
|
||||||
|
|
||||||
textbox = new fabric.Textbox('', {
|
textbox = new fabric.Textbox('', {
|
||||||
left: pointer.x,
|
left: pointer.x,
|
||||||
top: pointer.y,
|
top: pointer.y,
|
||||||
width: 200,
|
width: 200,
|
||||||
editable: true,
|
editable: true,
|
||||||
name: 'commonText',
|
name: 'commonText',
|
||||||
visible: wordDisplay,
|
visible: wordDisplay,
|
||||||
fill: commonTextFont.fontColor.value,
|
fill: commonTextFont.fontColor.value,
|
||||||
fontFamily: commonTextFont.fontFamily.value,
|
fontFamily: commonTextFont.fontFamily.value,
|
||||||
fontSize: commonTextFont.fontSize.value,
|
fontSize: commonTextFont.fontSize.value,
|
||||||
fontStyle: commonTextFont.fontWeight.value.toLowerCase().includes('italic') ? 'italic' : 'normal',
|
fontStyle: commonTextFont.fontWeight.value.toLowerCase().includes('italic') ? 'italic' : 'normal',
|
||||||
fontWeight: commonTextFont.fontWeight.value.toLowerCase().includes('bold') ? 'bold' : 'normal',
|
fontWeight: commonTextFont.fontWeight.value.toLowerCase().includes('bold') ? 'bold' : 'normal',
|
||||||
selectable: true,
|
selectable: true,
|
||||||
lockMovementX: true,
|
lockMovementX: true,
|
||||||
lockMovementY: true,
|
lockMovementY: true,
|
||||||
originX: 'center',
|
originX: 'center',
|
||||||
originY: 'center',
|
originY: 'center',
|
||||||
|
})
|
||||||
|
|
||||||
|
canvas?.add(textbox)
|
||||||
|
canvas.setActiveObject(textbox)
|
||||||
|
textbox.enterEditing()
|
||||||
|
textbox.selectAll()
|
||||||
})
|
})
|
||||||
|
}, 100)
|
||||||
|
} else {
|
||||||
|
const activeObject = canvas?.getActiveObject()
|
||||||
|
if (activeObject && activeObject.name === 'commonText') {
|
||||||
|
if (activeObject && activeObject.isEditing) {
|
||||||
|
if (activeObject.text === '') {
|
||||||
|
canvas?.remove(activeObject)
|
||||||
|
} else {
|
||||||
|
activeObject.exitEditing()
|
||||||
|
}
|
||||||
|
//정책 협의
|
||||||
|
const texts = canvas.getObjects().filter((obj) => obj.name === 'commonText')
|
||||||
|
texts.forEach((text) => {
|
||||||
|
text.set({ editable: false })
|
||||||
|
})
|
||||||
|
canvas.renderAll()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
canvas?.add(textbox)
|
initEvent()
|
||||||
canvas.setActiveObject(textbox)
|
|
||||||
textbox.enterEditing()
|
|
||||||
textbox.selectAll()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user