fix drawing

This commit is contained in:
hamid zarghami
2026-01-04 09:02:16 +03:30
parent 84f93463a3
commit 5297d684c5
2 changed files with 91 additions and 5 deletions
@@ -51,15 +51,23 @@ export const useDrawingHandlers = () => {
const pointerPos = stage.getPointerPosition();
if (!pointerPos) return;
// تبدیل موقعیت به مختصات واقعی لایه (با در نظر گرفتن scale)
const scaleX = stage.scaleX();
const scaleY = stage.scaleY();
const realPos = {
x: pointerPos.x / scaleX,
y: pointerPos.y / scaleY,
};
setIsDrawing(true);
setStartPos(pointerPos);
setStartPos(realPos);
if (tool === "text") {
const newText: EditorObject = {
id: `text-${Date.now()}`,
type: "text",
x: pointerPos.x,
y: pointerPos.y,
x: realPos.x,
y: realPos.y,
text: "متن جدید",
fontSize: defaults.fontSize,
fontFamily: defaults.fontFamily,
@@ -75,7 +83,7 @@ export const useDrawingHandlers = () => {
}
if (tool === "grid") {
addTable(pointerPos.x, pointerPos.y, 4, 5);
addTable(realPos.x, realPos.y, 4, 5);
setSelectedTableId(null);
setTool("select");
}
@@ -90,7 +98,15 @@ export const useDrawingHandlers = () => {
const pointerPos = stage.getPointerPosition();
if (!pointerPos) return;
const newObject = createDrawingObject({ tool, startPos, pointerPos, tempObject });
// تبدیل موقعیت به مختصات واقعی لایه (با در نظر گرفتن scale)
const scaleX = stage.scaleX();
const scaleY = stage.scaleY();
const realPos = {
x: pointerPos.x / scaleX,
y: pointerPos.y / scaleY,
};
const newObject = createDrawingObject({ tool, startPos, pointerPos: realPos, tempObject });
if (!newObject) return;
if (!tempObject) {