fix resize
This commit is contained in:
@@ -339,13 +339,61 @@ const ObjectRenderer = ({
|
||||
// محاسبه موقعیت جدید object
|
||||
const newX = node.x();
|
||||
const newY = node.y();
|
||||
const newWidth = Math.max(5, (obj.width || 100) * scaleX);
|
||||
const newHeight = Math.max(5, (obj.height || 100) * scaleY);
|
||||
|
||||
// Handle special shapes that use radius (Circle, Triangle, Abstract)
|
||||
let newWidth: number;
|
||||
let newHeight: number;
|
||||
let finalX = newX;
|
||||
let finalY = newY;
|
||||
|
||||
if (obj.type === "rectangle") {
|
||||
if (obj.shapeType === "circle") {
|
||||
// Circle: maintain aspect ratio and use average scale
|
||||
const avgScale = (scaleX + scaleY) / 2;
|
||||
const newRadius = Math.max(5, ((obj.width || 50) / 2) * avgScale);
|
||||
const newSize = newRadius * 2;
|
||||
newWidth = newSize;
|
||||
newHeight = newSize;
|
||||
} else if (obj.shapeType === "triangle" || obj.shapeType === "abstract") {
|
||||
// Triangle and Abstract: maintain aspect ratio and use average scale
|
||||
const avgScale = (scaleX + scaleY) / 2;
|
||||
const baseRadius = Math.min((obj.width || 100) / 2, (obj.height || 100) / 2);
|
||||
const newRadius = Math.max(5, baseRadius * avgScale);
|
||||
const newSize = newRadius * 2;
|
||||
newWidth = newSize;
|
||||
newHeight = newSize;
|
||||
// Adjust position for centered shapes
|
||||
finalX = newX - newSize / 2;
|
||||
finalY = newY - newSize / 2;
|
||||
} else {
|
||||
// Regular rectangle
|
||||
newWidth = Math.max(5, (obj.width || 100) * scaleX);
|
||||
newHeight = Math.max(5, (obj.height || 100) * scaleY);
|
||||
}
|
||||
} else if (obj.type === "line" || obj.type === "arrow") {
|
||||
// Line and Arrow: scale the end point
|
||||
const startX = obj.x || 0;
|
||||
const startY = obj.y || 0;
|
||||
const endX = obj.width || 0;
|
||||
const endY = obj.height || 0;
|
||||
const dx = (endX - startX) * scaleX;
|
||||
const dy = (endY - startY) * scaleY;
|
||||
newWidth = newX + dx;
|
||||
newHeight = newY + dy;
|
||||
} else if (obj.type === "text" || obj.type === "link") {
|
||||
// Text and Link: use scale directly
|
||||
newWidth = Math.max(5, (obj.width || 100) * scaleX);
|
||||
newHeight = Math.max(5, (obj.height || 100) * scaleY);
|
||||
} else {
|
||||
// Default for other objects (image, etc.)
|
||||
newWidth = Math.max(5, (obj.width || 100) * scaleX);
|
||||
newHeight = Math.max(5, (obj.height || 100) * scaleY);
|
||||
}
|
||||
|
||||
// بهروزرسانی object
|
||||
onUpdate(obj.id, {
|
||||
x: newX,
|
||||
y: newY,
|
||||
x: finalX,
|
||||
y: finalY,
|
||||
rotation: node.rotation(),
|
||||
width: newWidth,
|
||||
height: newHeight,
|
||||
@@ -356,8 +404,8 @@ const ObjectRenderer = ({
|
||||
// محاسبه موقعیت جدید mask
|
||||
// موقعیت نسبی را scale میکنم و به موقعیت جدید object اضافه میکنم
|
||||
// این باعث میشود که موقعیت نسبی mask نسبت به object حفظ شود
|
||||
const newMaskX = newX + (relativeX * scaleX);
|
||||
const newMaskY = newY + (relativeY * scaleY);
|
||||
const newMaskX = finalX + (relativeX * scaleX);
|
||||
const newMaskY = finalY + (relativeY * scaleY);
|
||||
const newMaskWidth = (maskShape.width || 100) * scaleX;
|
||||
const newMaskHeight = (maskShape.height || 100) * scaleY;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user