다각형 수정 , font global

This commit is contained in:
hyojun.choi 2024-07-02 16:38:11 +09:00
parent 56b1683859
commit 9ff6152a9f
3 changed files with 23 additions and 16 deletions

View File

@ -5,6 +5,8 @@ import QRect from '@/components/fabric/QRect'
import QLine from '@/components/fabric/QLine' 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 { fontSizeState } from '@/store/canvasAtom'
export default function Roof2() { export default function Roof2() {
const { canvas, handleRedo, handleUndo, setCanvasBackgroundWithDots } = const { canvas, handleRedo, handleUndo, setCanvasBackgroundWithDots } =
@ -15,7 +17,7 @@ export default function Roof2() {
//canvas //canvas
const [horizontalSize, setHorizontalSize] = useState(1000) const [horizontalSize, setHorizontalSize] = useState(1000)
// //
const [fontSize, setFontSize] = useState(0) const [fontSize, setFontSize] = useRecoilState(fontSizeState)
const { const {
mode, mode,
@ -82,10 +84,10 @@ export default function Roof2() {
} }
const canvasSizeMode = () => { const canvasSizeMode = () => {
if(canvas) { if (canvas) {
canvas.setWidth(parseInt(verticalSize)); canvas.setWidth(parseInt(verticalSize))
canvas.setHeight(parseInt(horizontalSize)); canvas.setHeight(parseInt(horizontalSize))
canvas.renderAll(); canvas.renderAll()
} }
} }
@ -93,6 +95,10 @@ export default function Roof2() {
canvasSizeMode() canvasSizeMode()
}, [verticalSize, horizontalSize]) }, [verticalSize, horizontalSize])
useEffect(() => {
console.log(`fontSize 바꼈다 ${fontSize}`)
}, [fontSize])
return ( return (
<> <>
{canvas && ( {canvas && (
@ -233,7 +239,7 @@ export default function Roof2() {
</div> </div>
<div className="m-2 p-2 w-80"> <div className="m-2 p-2 w-80">
<RangeSlider <RangeSlider
title="글자 크기" title={`글자 크기${fontSize}`}
initValue={fontSize} initValue={fontSize}
onchange={setFontSize} onchange={setFontSize}
/> />
@ -242,7 +248,7 @@ export default function Roof2() {
</> </>
)} )}
<div className="flex justify-center my-8"> <div className="flex justify-center my-8">
<canvas id="canvas" style={{border:'1px solid black'}}/> <canvas id="canvas" style={{ border: '1px solid black' }} />
</div> </div>
</> </>
) )

View File

@ -60,22 +60,18 @@ export default class QPolygon extends fabric.Polygon {
const scaleX = this.scaleX const scaleX = this.scaleX
const scaleY = this.scaleY const scaleY = this.scaleY
const points = this.getCurrentPoints() const points = this.points
for (let i = 0; i < points.length; i++) { for (let i = 0; i < points.length; i++) {
const start = this.getCurrentPoints()[i] const start = points[i]
const currentStart = this.getCurrentPoints()[i] const end = points[(i + 1) % points.length]
const end =
this.getCurrentPoints()[(i + 1) % this.getCurrentPoints().length]
const currentEnd =
this.getCurrentPoints()[(i + 1) % this.getCurrentPoints().length]
const dx = end.x - start.x const dx = end.x - start.x
const dy = end.y - start.y const dy = end.y - start.y
const length = Math.sqrt(dx * dx + dy * dy) const length = Math.sqrt(dx * dx + dy * dy)
const midPoint = new fabric.Point( const midPoint = new fabric.Point(
(currentStart.x + currentEnd.x) / 2, (start.x + end.x) / 2,
(currentStart.y + currentEnd.y) / 2, (start.y + end.y) / 2,
) )
const text = new fabric.Text(length.toFixed(0), { const text = new fabric.Text(length.toFixed(0), {

View File

@ -4,3 +4,8 @@ export const textState = atom({
key: 'textState', key: 'textState',
default: 'test text', default: 'test text',
}) })
export const fontSizeState = atom({
key: 'fontSizeState',
default: 10,
})