다각형 수정 , font global
This commit is contained in:
parent
56b1683859
commit
9ff6152a9f
@ -5,6 +5,8 @@ import QRect from '@/components/fabric/QRect'
|
||||
import QLine from '@/components/fabric/QLine'
|
||||
import QPolygon from '@/components/fabric/QPolygon'
|
||||
import RangeSlider from './ui/RangeSlider'
|
||||
import { useRecoilState } from 'recoil'
|
||||
import { fontSizeState } from '@/store/canvasAtom'
|
||||
|
||||
export default function Roof2() {
|
||||
const { canvas, handleRedo, handleUndo, setCanvasBackgroundWithDots } =
|
||||
@ -15,7 +17,7 @@ export default function Roof2() {
|
||||
//canvas 세로 사이즈
|
||||
const [horizontalSize, setHorizontalSize] = useState(1000)
|
||||
// 글자크기
|
||||
const [fontSize, setFontSize] = useState(0)
|
||||
const [fontSize, setFontSize] = useRecoilState(fontSizeState)
|
||||
|
||||
const {
|
||||
mode,
|
||||
@ -82,10 +84,10 @@ export default function Roof2() {
|
||||
}
|
||||
|
||||
const canvasSizeMode = () => {
|
||||
if(canvas) {
|
||||
canvas.setWidth(parseInt(verticalSize));
|
||||
canvas.setHeight(parseInt(horizontalSize));
|
||||
canvas.renderAll();
|
||||
if (canvas) {
|
||||
canvas.setWidth(parseInt(verticalSize))
|
||||
canvas.setHeight(parseInt(horizontalSize))
|
||||
canvas.renderAll()
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,6 +95,10 @@ export default function Roof2() {
|
||||
canvasSizeMode()
|
||||
}, [verticalSize, horizontalSize])
|
||||
|
||||
useEffect(() => {
|
||||
console.log(`fontSize 바꼈다 ${fontSize}`)
|
||||
}, [fontSize])
|
||||
|
||||
return (
|
||||
<>
|
||||
{canvas && (
|
||||
@ -233,7 +239,7 @@ export default function Roof2() {
|
||||
</div>
|
||||
<div className="m-2 p-2 w-80">
|
||||
<RangeSlider
|
||||
title="글자 크기"
|
||||
title={`글자 크기${fontSize}`}
|
||||
initValue={fontSize}
|
||||
onchange={setFontSize}
|
||||
/>
|
||||
@ -242,7 +248,7 @@ export default function Roof2() {
|
||||
</>
|
||||
)}
|
||||
<div className="flex justify-center my-8">
|
||||
<canvas id="canvas" style={{border:'1px solid black'}}/>
|
||||
<canvas id="canvas" style={{ border: '1px solid black' }} />
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
|
||||
@ -60,22 +60,18 @@ export default class QPolygon extends fabric.Polygon {
|
||||
const scaleX = this.scaleX
|
||||
const scaleY = this.scaleY
|
||||
|
||||
const points = this.getCurrentPoints()
|
||||
const points = this.points
|
||||
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
const start = this.getCurrentPoints()[i]
|
||||
const currentStart = this.getCurrentPoints()[i]
|
||||
const end =
|
||||
this.getCurrentPoints()[(i + 1) % this.getCurrentPoints().length]
|
||||
const currentEnd =
|
||||
this.getCurrentPoints()[(i + 1) % this.getCurrentPoints().length]
|
||||
const start = points[i]
|
||||
const end = points[(i + 1) % points.length]
|
||||
const dx = end.x - start.x
|
||||
const dy = end.y - start.y
|
||||
const length = Math.sqrt(dx * dx + dy * dy)
|
||||
|
||||
const midPoint = new fabric.Point(
|
||||
(currentStart.x + currentEnd.x) / 2,
|
||||
(currentStart.y + currentEnd.y) / 2,
|
||||
(start.x + end.x) / 2,
|
||||
(start.y + end.y) / 2,
|
||||
)
|
||||
|
||||
const text = new fabric.Text(length.toFixed(0), {
|
||||
|
||||
@ -4,3 +4,8 @@ export const textState = atom({
|
||||
key: 'textState',
|
||||
default: 'test text',
|
||||
})
|
||||
|
||||
export const fontSizeState = atom({
|
||||
key: 'fontSizeState',
|
||||
default: 10,
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user