리코일 적용 및 캔버스 사이즈 기본 값 변경
This commit is contained in:
parent
9ff6152a9f
commit
478f626970
@ -6,16 +6,19 @@ import QLine from '@/components/fabric/QLine'
|
|||||||
import QPolygon from '@/components/fabric/QPolygon'
|
import QPolygon from '@/components/fabric/QPolygon'
|
||||||
import RangeSlider from './ui/RangeSlider'
|
import RangeSlider from './ui/RangeSlider'
|
||||||
import { useRecoilState } from 'recoil'
|
import { useRecoilState } from 'recoil'
|
||||||
import { fontSizeState } from '@/store/canvasAtom'
|
import { fontSizeState, canvasSizeState } from '@/store/canvasAtom'
|
||||||
|
|
||||||
export default function Roof2() {
|
export default function Roof2() {
|
||||||
const { canvas, handleRedo, handleUndo, setCanvasBackgroundWithDots } =
|
const { canvas, handleRedo, handleUndo, setCanvasBackgroundWithDots } =
|
||||||
useCanvas('canvas')
|
useCanvas('canvas')
|
||||||
|
|
||||||
|
//canvas 기본 사이즈
|
||||||
|
const [canvasSize, setCanvasSize] = useRecoilState(canvasSizeState)
|
||||||
|
|
||||||
//canvas 가로 사이즈
|
//canvas 가로 사이즈
|
||||||
const [verticalSize, setVerticalSize] = useState(1000)
|
const [verticalSize, setVerticalSize] = useState(canvasSize.vertical)
|
||||||
//canvas 세로 사이즈
|
//canvas 세로 사이즈
|
||||||
const [horizontalSize, setHorizontalSize] = useState(1000)
|
const [horizontalSize, setHorizontalSize] = useState(canvasSize.horizontal)
|
||||||
// 글자크기
|
// 글자크기
|
||||||
const [fontSize, setFontSize] = useRecoilState(fontSizeState)
|
const [fontSize, setFontSize] = useRecoilState(fontSizeState)
|
||||||
|
|
||||||
@ -83,14 +86,25 @@ export default function Roof2() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* canvas 사이즈 변경 함수
|
||||||
|
*/
|
||||||
const canvasSizeMode = () => {
|
const canvasSizeMode = () => {
|
||||||
if (canvas) {
|
if (canvas) {
|
||||||
canvas.setWidth(parseInt(verticalSize))
|
canvas.setWidth(horizontalSize)
|
||||||
canvas.setHeight(parseInt(horizontalSize))
|
canvas.setHeight(verticalSize)
|
||||||
canvas.renderAll()
|
canvas.renderAll()
|
||||||
|
|
||||||
|
setCanvasSize(() => ({
|
||||||
|
vertical: verticalSize,
|
||||||
|
horizontal: horizontalSize
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 값 변경시
|
||||||
|
*/
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
canvasSizeMode()
|
canvasSizeMode()
|
||||||
}, [verticalSize, horizontalSize])
|
}, [verticalSize, horizontalSize])
|
||||||
@ -222,19 +236,21 @@ export default function Roof2() {
|
|||||||
<div className="m-2 p-2 w-80">
|
<div className="m-2 p-2 w-80">
|
||||||
<RangeSlider
|
<RangeSlider
|
||||||
title="canvas 가로 사이즈"
|
title="canvas 가로 사이즈"
|
||||||
initValue={verticalSize}
|
initValue={horizontalSize}
|
||||||
|
min="500"
|
||||||
step="100"
|
step="100"
|
||||||
max="2000"
|
max="2000"
|
||||||
onchange={setVerticalSize}
|
onchange={setHorizontalSize}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="m-2 p-2 w-80">
|
<div className="m-2 p-2 w-80">
|
||||||
<RangeSlider
|
<RangeSlider
|
||||||
title="canvas 세로 사이즈"
|
title="canvas 세로 사이즈"
|
||||||
initValue={horizontalSize}
|
initValue={verticalSize}
|
||||||
|
min="500"
|
||||||
step="100"
|
step="100"
|
||||||
max="2000"
|
max="2000"
|
||||||
onchange={setHorizontalSize}
|
onchange={setVerticalSize}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="m-2 p-2 w-80">
|
<div className="m-2 p-2 w-80">
|
||||||
|
|||||||
@ -6,16 +6,15 @@ import {
|
|||||||
polygonPositionHandler,
|
polygonPositionHandler,
|
||||||
} from '@/app/util/canvas-util'
|
} from '@/app/util/canvas-util'
|
||||||
|
|
||||||
const CANVAS = {
|
import { useRecoilState } from 'recoil'
|
||||||
WIDTH: 1000,
|
import { canvasSizeState } from '@/store/canvasAtom'
|
||||||
HEIGHT: 1000,
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useCanvas(id) {
|
export function useCanvas(id) {
|
||||||
const [canvas, setCanvas] = useState()
|
const [canvas, setCanvas] = useState()
|
||||||
const [isLocked, setIsLocked] = useState(false)
|
const [isLocked, setIsLocked] = useState(false)
|
||||||
const [history, setHistory] = useState([])
|
const [history, setHistory] = useState([])
|
||||||
|
const [canvasSize] = useRecoilState(canvasSizeState)
|
||||||
const points = useRef([])
|
const points = useRef([])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,8 +22,8 @@ export function useCanvas(id) {
|
|||||||
*/
|
*/
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const c = new fabric.Canvas(id, {
|
const c = new fabric.Canvas(id, {
|
||||||
height: CANVAS.HEIGHT,
|
height: canvasSize.vertical,
|
||||||
width: CANVAS.WIDTH,
|
width: canvasSize.horizontal,
|
||||||
backgroundColor: 'white',
|
backgroundColor: 'white',
|
||||||
selection: false,
|
selection: false,
|
||||||
})
|
})
|
||||||
|
|||||||
@ -9,3 +9,11 @@ export const fontSizeState = atom({
|
|||||||
key: 'fontSizeState',
|
key: 'fontSizeState',
|
||||||
default: 10,
|
default: 10,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const canvasSizeState = atom({
|
||||||
|
key: 'canvasSize',
|
||||||
|
default: {
|
||||||
|
vertical: 500,
|
||||||
|
horizontal : 500
|
||||||
|
}
|
||||||
|
})
|
||||||
Loading…
x
Reference in New Issue
Block a user