4 Commits

Author SHA1 Message Date
7f7a4a1ae6 resizing works 2025-11-21 10:43:38 +01:00
e078914ed2 resizing works 2025-11-21 10:42:52 +01:00
9234986b6f FIX: css shape fix 2025-11-20 22:40:04 +01:00
4bbd92920e resize works, but not ideal 2025-11-19 23:26:01 +01:00
3 changed files with 399 additions and 308 deletions

View File

@@ -13,7 +13,7 @@ Funkcjonalności aplikacji koncentrują się na tworzeniu i modyfikacji kształt
- [x] 3. Tworzenie elipsy - [x] 3. Tworzenie elipsy
### Akcje na kształtach ### Akcje na kształtach
- [ ] 4. Zmiana rozmiaru kształtów. - [x] 4. Zmiana rozmiaru kształtów.
- [x] 5. Przeciągnięcie kzstałtu po planszy - [x] 5. Przeciągnięcie kzstałtu po planszy
- [x] 6. Usunięcie kształtu - [x] 6. Usunięcie kształtu
- [x] 7. Zaznaczenie kształtu - [x] 7. Zaznaczenie kształtu

View File

@@ -30,6 +30,8 @@
<button id="zoom-out">-</button> <button id="zoom-out">-</button>
</div> </div>
</div> </div>
<div id="resize-handle" style="position: absolute; display: none; border: 2px dashed #4A90E2; z-index: 10;"></div>
<div class="canvas-container"> <div class="canvas-container">
<div id="paper"></div> <div id="paper"></div>
</div> </div>
@@ -41,7 +43,6 @@
let selectedElement = null; let selectedElement = null;
let activeElementView = null; let activeElementView = null;
let clipboard = null; let clipboard = null;
let zoomLevel = 1.0;
$(document).ready(function () { $(document).ready(function () {
//init paper - Start //init paper - Start
@@ -55,48 +56,33 @@
}); });
//init paper - END //init paper - END
const $resizeHandle = $('#resize-handle');
// obwódka i znaczek usuwanie // obwódka i znaczek usuwanie
function createToolsView() { function createToolsView() {
return new joint.dia.ToolsView({ return new joint.dia.ToolsView({
tools: [ tools: [
new joint.elementTools.Boundary({ new joint.elementTools.Boundary({
padding: 10, padding: 20,
}), }),
new joint.elementTools.Remove({ new joint.elementTools.Remove({
offset: { x: -10, y: -10 },
focusOpacity: 0.5, focusOpacity: 0.5,
action: function() {
deleteShape();
}
}) })
] ]
}); });
} }
//create shape - START
function createRectangle(paperX, paperY) {
const rect = new joint.shapes.standard.Rectangle({
position: { x: paperX - 40, y: paperY - 24 },
size: { width: 80, height: 48 },
attrs: {
body: {
fill: 'transparent',
stroke: '#000000',
strokeWidth: 1
},
label: {
text: ''
}
}
});
graph.addCell(rect);
const elementView = rect.findView(paper);
elementView.addTools(createToolsView());
}
function createDiamond(paperX, paperY) { function createDiamond(paperX, paperY) {
const rect = new joint.shapes.standard.Rectangle({ const diamond = new joint.shapes.standard.Polygon({
position: { x: paperX - 24, y: paperY - 24 }, position: { x: paperX - 24, y: paperY - 24 },
size: { width: 48, height: 48 }, size: { width: 48, height: 48 },
angle: 45,
attrs: { attrs: {
body: { body: {
refPoints: '0.5,0 1,0.5 0.5,1 0,0.5', // Diamond shape points
fill: 'transparent', fill: 'transparent',
stroke: '#000000', stroke: '#000000',
strokeWidth: 1 strokeWidth: 1
@@ -106,8 +92,9 @@
} }
} }
}); });
graph.addCell(rect);
const elementView = rect.findView(paper); graph.addCell(diamond);
const elementView = diamond.findView(paper);
elementView.addTools(createToolsView()); elementView.addTools(createToolsView());
} }
@@ -188,6 +175,7 @@
activeElementView = null; activeElementView = null;
selectedElement = null; selectedElement = null;
hideResizeHandle();
if (shapeType === 'rectangle') { if (shapeType === 'rectangle') {
createRectangle(paperX, paperY); createRectangle(paperX, paperY);
@@ -210,10 +198,6 @@
}); });
//init draggable - END //init draggable - END
function updateStatus(message) {
$('#status').text(message + ' | Zoom: ' + Math.round(zoomLevel * 100) + '%');
}
function getViewportCenter() { function getViewportCenter() {
const container = $('.canvas-container'); const container = $('.canvas-container');
const scale = paper.scale(); const scale = paper.scale();
@@ -228,9 +212,6 @@
function copyShape() { function copyShape() {
if (selectedElement) { if (selectedElement) {
clipboard = selectedElement.clone(); clipboard = selectedElement.clone();
updateStatus('Skopiowano element');
} else {
updateStatus('Brak zaznaczonego elementu');
} }
} }
@@ -253,16 +234,17 @@
} }
selectedElement = pasted; selectedElement = pasted;
updateStatus('Wklejono element'); showResizeHandle(pastedView);
} else {
updateStatus('Brak elementu w schowku');
} }
} }
function deleteShape() { function deleteShape() {
if (selectedElement) {
selectedElement.remove(); selectedElement.remove();
selectedElement = null; selectedElement = null;
updateStatus('Usunięto element'); activeElementView = null;
hideResizeHandle();
}
} }
$('#btn-delete').click(function() { $('#btn-delete').click(function() {
@@ -284,8 +266,8 @@
} }
elementView.showTools(); elementView.showTools();
activeElementView = elementView; activeElementView = elementView;
selectedElement = elementView.model; selectedElement = elementView.model;
showResizeHandle(elementView);
}); });
let panStart = null; let panStart = null;
@@ -300,6 +282,7 @@
activeElementView = null; activeElementView = null;
} }
selectedElement = null; selectedElement = null;
hideResizeHandle();
//ruszanie caloscia //ruszanie caloscia
panStart = { panStart = {
x: evt.clientX, x: evt.clientX,
@@ -315,6 +298,7 @@
const dx = evt.clientX - panStart.x; const dx = evt.clientX - panStart.x;
const dy = evt.clientY - panStart.y; const dy = evt.clientY - panStart.y;
paper.translate(panStart.tx + dx, panStart.ty + dy); paper.translate(panStart.tx + dx, panStart.ty + dy);
showResizeHandle(activeElementView);
} }
}); });
@@ -355,21 +339,118 @@
}); });
//add text to text block - END //add text to text block - END
// resize
function showResizeHandle(elementView) {
if (!elementView) return;
const bbox = elementView.model.getBBox();
const clientRect = paper.localToClientRect(bbox);
const angle = elementView.model.get('angle') || 0;
$resizeHandle.css({
left: clientRect.x,
top: clientRect.y,
width: clientRect.width,
height: clientRect.height,
transform: `rotate(${angle}deg)`,
transformOrigin: 'center center'
}).show();
if ($resizeHandle.data('ui-resizable')) {
$resizeHandle.resizable('destroy');
}
let originalBBox;
$resizeHandle.resizable({
handles: 'n, e, s, w, ne, se, sw, nw',
start: function() {
if (activeElementView) {
activeElementView.hideTools();
}
originalBBox = selectedElement.getBBox();
},
resize: function(event, ui) {
if (selectedElement && originalBBox) {
const scale = paper.scale();
const newWidth = ui.size.width / scale.sx;
const newHeight = ui.size.height / scale.sy;
const newX = originalBBox.x + (ui.position.left - ui.originalPosition.left) / scale.sx;
const newY = originalBBox.y + (ui.position.top - ui.originalPosition.top) / scale.sy;
if (selectedElement.get('angle')) {
selectedElement.resize(newWidth, newHeight, { direction: 'center' });
} else {
selectedElement.position(newX, newY);
selectedElement.resize(newWidth, newHeight);
}
}
},
stop: function() {
if (activeElementView) {
activeElementView.showTools();
showResizeHandle(activeElementView);
}
originalBBox = null;
}
});
}
function hideResizeHandle() {
if ($resizeHandle.data('ui-resizable')) {
$resizeHandle.resizable('destroy');
}
$resizeHandle.hide();
}
//create shape - START
function createRectangle(paperX, paperY) {
const rect = new joint.shapes.standard.Rectangle({
position: { x: paperX - 40, y: paperY - 24 },
size: { width: 80, height: 48 },
attrs: {
body: {
fill: 'transparent',
stroke: '#000000',
strokeWidth: 1
},
label: {
text: ''
}
}
});
graph.addCell(rect);
const elementView = rect.findView(paper);
elementView.addTools(createToolsView());
}
// Zoom // Zoom
const zoomStep = 0.2; const zoomStep = 0.2;
const minScale = 0.2; const minScale = 0.2;
const maxScale = 3.0; const maxScale = 3.0;
function applyZoom(newScale, ox, oy) {
paper.scale(newScale, newScale, ox, oy);
showResizeHandle(activeElementView);
}
$('#zoom-in').click(function () { $('#zoom-in').click(function () {
const currentScale = paper.scale().sx; const currentScale = paper.scale().sx;
const newScale = Math.min(maxScale, currentScale + zoomStep); const newScale = Math.min(maxScale, currentScale + zoomStep);
paper.scale(newScale, newScale); applyZoom(newScale);
}); });
$('#zoom-out').click(function () { $('#zoom-out').click(function () {
const currentScale = paper.scale().sx; const currentScale = paper.scale().sx;
const newScale = Math.max(minScale, currentScale - zoomStep); const newScale = Math.max(minScale, currentScale - zoomStep);
paper.scale(newScale, newScale); applyZoom(newScale);
}); });
// Zoom za pomoca kolka myszy // Zoom za pomoca kolka myszy
@@ -379,9 +460,10 @@
const zoomFactor = 0.2; const zoomFactor = 0.2;
let newScale = oldScale * (1 + delta * zoomFactor); let newScale = oldScale * (1 + delta * zoomFactor);
newScale = Math.max(minScale, Math.min(maxScale, newScale)); newScale = Math.max(minScale, Math.min(maxScale, newScale));
paper.scale(newScale, newScale, x, y); applyZoom(newScale, x, y);
}); });
}); });
</script> </script>
</body> </body>

View File

@@ -51,7 +51,9 @@ body {
flex-wrap: wrap; flex-wrap: wrap;
gap: 10px; gap: 10px;
padding: 12px; padding: 12px;
min-height: 152px;
justify-content: space-between; justify-content: space-between;
align-content: space-between;
} }
.shape { .shape {
@@ -87,7 +89,7 @@ body {
#shape-diamond { #shape-diamond {
height: 48px; height: 48px;
width: 48px; width: 48px;
transform: rotate(45deg) translateX(15px); transform: rotate(45deg) translate(3px, -16px);
border-radius: 4px; border-radius: 4px;
} }
@@ -171,7 +173,7 @@ body {
display: flex; display: flex;
justify-content: center; justify-content: center;
gap: 12px; gap: 12px;
padding: 0; padding: 6px;
} }
.zoom-wrapper button { .zoom-wrapper button {
@@ -240,6 +242,13 @@ body {
background: #999; background: #999;
} }
#resize-handle {
position: absolute;
box-sizing: border-box;
pointer-events: auto;
}
/* Responsive */ /* Responsive */
@media (max-width: 768px) { @media (max-width: 768px) {
.toolbar { .toolbar {