Skip to content

Commit 5da6a0e

Browse files
committed
Showing guidelines when selecting part of the component hierarchy graph
1 parent 16f3bed commit 5da6a0e

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/commands/showComponentHierarchy/showComponentHierarchy_Template.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,35 @@
8181
selectionCanvasContext = selectionCanvas.getContext("2d");
8282
}
8383

84+
function drawGuideLine(ctx, mouseX, mouseY) {
85+
ctx.beginPath();
86+
ctx.setLineDash([3, 7]);
87+
if(mouseX > -1) {
88+
ctx.moveTo(mouseX, 0);
89+
ctx.lineTo(mouseX, selectionCanvas.height);
90+
} else if (mouseY > -1) {
91+
ctx.moveTo(0, mouseY);
92+
ctx.lineTo(selectionCanvas.width, mouseY);
93+
}
94+
ctx.strokeStyle = 'blue';
95+
ctx.lineWidth = 1;
96+
ctx.stroke();
97+
}
98+
99+
function showGuideLines() {
100+
var tmpSelectionCanvasContext = selectionCanvas.getContext("2d");
101+
tmpSelectionCanvasContext.clearRect(0, 0, selectionCanvas.width, selectionCanvas.height);
102+
drawGuideLine(tmpSelectionCanvasContext, mouseX, -1);
103+
drawGuideLine(tmpSelectionCanvasContext, -1, mouseY);
104+
}
105+
84106
function mouseMoveEventListener(event) {
85107
mouseX = parseInt(event.clientX - selectionCanvas.offsetLeft);
86108
mouseY = parseInt(event.clientY - selectionCanvas.offsetTop);
109+
showGuideLines();
87110
if (selectionCanvasContext != undefined) {
88-
selectionCanvasContext.clearRect(0, 0, window.innerWidth, window.innerHeight);
89111
selectionCanvasContext.beginPath();
112+
selectionCanvasContext.setLineDash([]);
90113
const width = mouseX - lastMouseX;
91114
const height = mouseY - lastMouseY;
92115
selectionCanvasContext.rect(lastMouseX, lastMouseY, width, height);

0 commit comments

Comments
 (0)