|
81 | 81 | selectionCanvasContext = selectionCanvas.getContext("2d");
|
82 | 82 | }
|
83 | 83 |
|
| 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 | + |
84 | 106 | function mouseMoveEventListener(event) {
|
85 | 107 | mouseX = parseInt(event.clientX - selectionCanvas.offsetLeft);
|
86 | 108 | mouseY = parseInt(event.clientY - selectionCanvas.offsetTop);
|
| 109 | + showGuideLines(); |
87 | 110 | if (selectionCanvasContext != undefined) {
|
88 |
| - selectionCanvasContext.clearRect(0, 0, window.innerWidth, window.innerHeight); |
89 | 111 | selectionCanvasContext.beginPath();
|
| 112 | + selectionCanvasContext.setLineDash([]); |
90 | 113 | const width = mouseX - lastMouseX;
|
91 | 114 | const height = mouseY - lastMouseY;
|
92 | 115 | selectionCanvasContext.rect(lastMouseX, lastMouseY, width, height);
|
|
0 commit comments