edge dragging for crop
All checks were successful
Build Images and Deploy / Update-PROD-Stack (push) Successful in 1m9s
All checks were successful
Build Images and Deploy / Update-PROD-Stack (push) Successful in 1m9s
This commit is contained in:
@@ -668,8 +668,10 @@
|
|||||||
let muteAudio = false;
|
let muteAudio = false;
|
||||||
let compressionQuality = 23;
|
let compressionQuality = 23;
|
||||||
let isDraggingHandle = false;
|
let isDraggingHandle = false;
|
||||||
|
let isDraggingEdge = false;
|
||||||
let isDraggingBox = false;
|
let isDraggingBox = false;
|
||||||
let activeHandle = null;
|
let activeHandle = null;
|
||||||
|
let activeEdge = null;
|
||||||
let dragOffsetX = 0;
|
let dragOffsetX = 0;
|
||||||
let dragOffsetY = 0;
|
let dragOffsetY = 0;
|
||||||
const handleSize = 12;
|
const handleSize = 12;
|
||||||
@@ -841,6 +843,14 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if clicking on an edge
|
||||||
|
const edge = getEdgeAtPosition(mouseX, mouseY);
|
||||||
|
if (edge) {
|
||||||
|
isDraggingEdge = true;
|
||||||
|
activeEdge = edge;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if clicking inside the box to move it
|
// Check if clicking inside the box to move it
|
||||||
if (isInsideRect(mouseX, mouseY)) {
|
if (isInsideRect(mouseX, mouseY)) {
|
||||||
isDraggingBox = true;
|
isDraggingBox = true;
|
||||||
@@ -865,14 +875,19 @@
|
|||||||
const mouseY = e.clientY - rect.top;
|
const mouseY = e.clientY - rect.top;
|
||||||
|
|
||||||
// Update cursor based on position
|
// Update cursor based on position
|
||||||
if (!isDrawing && !isDraggingHandle && !isDraggingBox && cropRect) {
|
if (!isDrawing && !isDraggingHandle && !isDraggingEdge && !isDraggingBox && cropRect) {
|
||||||
const handle = getHandleAtPosition(mouseX, mouseY);
|
const handle = getHandleAtPosition(mouseX, mouseY);
|
||||||
if (handle) {
|
if (handle) {
|
||||||
cropCanvas.style.cursor = getHandleCursor(handle);
|
cropCanvas.style.cursor = getHandleCursor(handle);
|
||||||
} else if (isInsideRect(mouseX, mouseY)) {
|
|
||||||
cropCanvas.style.cursor = 'move';
|
|
||||||
} else {
|
} else {
|
||||||
cropCanvas.style.cursor = 'crosshair';
|
const edge = getEdgeAtPosition(mouseX, mouseY);
|
||||||
|
if (edge) {
|
||||||
|
cropCanvas.style.cursor = getEdgeCursor(edge);
|
||||||
|
} else if (isInsideRect(mouseX, mouseY)) {
|
||||||
|
cropCanvas.style.cursor = 'move';
|
||||||
|
} else {
|
||||||
|
cropCanvas.style.cursor = 'crosshair';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -883,6 +898,13 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle edge resizing
|
||||||
|
if (isDraggingEdge && cropRect) {
|
||||||
|
resizeEdge(mouseX, mouseY);
|
||||||
|
updateFormFields();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Handle moving
|
// Handle moving
|
||||||
if (isDraggingBox && cropRect) {
|
if (isDraggingBox && cropRect) {
|
||||||
moveCropRect(mouseX, mouseY);
|
moveCropRect(mouseX, mouseY);
|
||||||
@@ -907,14 +929,16 @@
|
|||||||
cropCanvas.addEventListener('mouseup', (e) => {
|
cropCanvas.addEventListener('mouseup', (e) => {
|
||||||
if (!cropMode) return;
|
if (!cropMode) return;
|
||||||
|
|
||||||
if (isDrawing || isDraggingHandle || isDraggingBox) {
|
if (isDrawing || isDraggingHandle || isDraggingEdge || isDraggingBox) {
|
||||||
updateFormFields();
|
updateFormFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
isDrawing = false;
|
isDrawing = false;
|
||||||
isDraggingHandle = false;
|
isDraggingHandle = false;
|
||||||
|
isDraggingEdge = false;
|
||||||
isDraggingBox = false;
|
isDraggingBox = false;
|
||||||
activeHandle = null;
|
activeHandle = null;
|
||||||
|
activeEdge = null;
|
||||||
cropCanvas.style.cursor = 'crosshair';
|
cropCanvas.style.cursor = 'crosshair';
|
||||||
|
|
||||||
// Keep crop mode active and canvas visible
|
// Keep crop mode active and canvas visible
|
||||||
@@ -923,13 +947,15 @@
|
|||||||
|
|
||||||
// Handle mouse leaving canvas while dragging
|
// Handle mouse leaving canvas while dragging
|
||||||
cropCanvas.addEventListener('mouseleave', (e) => {
|
cropCanvas.addEventListener('mouseleave', (e) => {
|
||||||
if (isDrawing || isDraggingHandle || isDraggingBox) {
|
if (isDrawing || isDraggingHandle || isDraggingEdge || isDraggingBox) {
|
||||||
// Finish the drag operation
|
// Finish the drag operation
|
||||||
updateFormFields();
|
updateFormFields();
|
||||||
isDrawing = false;
|
isDrawing = false;
|
||||||
isDraggingHandle = false;
|
isDraggingHandle = false;
|
||||||
|
isDraggingEdge = false;
|
||||||
isDraggingBox = false;
|
isDraggingBox = false;
|
||||||
activeHandle = null;
|
activeHandle = null;
|
||||||
|
activeEdge = null;
|
||||||
drawCropRect();
|
drawCropRect();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1070,6 +1096,16 @@
|
|||||||
return cursors[handle] || 'default';
|
return cursors[handle] || 'default';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getEdgeCursor(edge) {
|
||||||
|
const cursors = {
|
||||||
|
'top': 'ns-resize',
|
||||||
|
'bottom': 'ns-resize',
|
||||||
|
'left': 'ew-resize',
|
||||||
|
'right': 'ew-resize'
|
||||||
|
};
|
||||||
|
return cursors[edge] || 'default';
|
||||||
|
}
|
||||||
|
|
||||||
function isInsideRect(x, y) {
|
function isInsideRect(x, y) {
|
||||||
if (!cropRect) return false;
|
if (!cropRect) return false;
|
||||||
return x >= cropRect.x && x <= cropRect.x + cropRect.width &&
|
return x >= cropRect.x && x <= cropRect.x + cropRect.width &&
|
||||||
@@ -1127,6 +1163,47 @@
|
|||||||
drawCropRect();
|
drawCropRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resizeEdge(mouseX, mouseY) {
|
||||||
|
const minSize = 20;
|
||||||
|
|
||||||
|
switch (activeEdge) {
|
||||||
|
case 'top':
|
||||||
|
const newHeight = cropRect.y + cropRect.height - mouseY;
|
||||||
|
if (newHeight > minSize && mouseY >= 0) {
|
||||||
|
cropRect.height = newHeight;
|
||||||
|
cropRect.y = mouseY;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'bottom':
|
||||||
|
const heightBottom = mouseY - cropRect.y;
|
||||||
|
if (heightBottom > minSize && mouseY <= cropCanvas.height) {
|
||||||
|
cropRect.height = heightBottom;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'left':
|
||||||
|
const newWidth = cropRect.x + cropRect.width - mouseX;
|
||||||
|
if (newWidth > minSize && mouseX >= 0) {
|
||||||
|
cropRect.width = newWidth;
|
||||||
|
cropRect.x = mouseX;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'right':
|
||||||
|
const widthRight = mouseX - cropRect.x;
|
||||||
|
if (widthRight > minSize && mouseX <= cropCanvas.width) {
|
||||||
|
cropRect.width = widthRight;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constrain to canvas bounds
|
||||||
|
cropRect.x = Math.max(0, cropRect.x);
|
||||||
|
cropRect.y = Math.max(0, cropRect.y);
|
||||||
|
cropRect.width = Math.min(cropRect.width, cropCanvas.width - cropRect.x);
|
||||||
|
cropRect.height = Math.min(cropRect.height, cropCanvas.height - cropRect.y);
|
||||||
|
|
||||||
|
drawCropRect();
|
||||||
|
}
|
||||||
|
|
||||||
function moveCropRect(mouseX, mouseY) {
|
function moveCropRect(mouseX, mouseY) {
|
||||||
const newX = mouseX - dragOffsetX;
|
const newX = mouseX - dragOffsetX;
|
||||||
const newY = mouseY - dragOffsetY;
|
const newY = mouseY - dragOffsetY;
|
||||||
|
|||||||
Reference in New Issue
Block a user