|
48 | 48 | rectDom.addEventListener ("mousemove", onMouseMove, false);
|
49 | 49 | }
|
50 | 50 | function onMouseMove (e) {
|
51 |
| - draw(); |
| 51 | + draw(true); |
52 | 52 | _rectangle.endY = e.layerY - _rectangle.startY;
|
53 | 53 | _rectangle.endX = e.layerX - _rectangle.startX;
|
54 | 54 | context.lineWidth = 3;
|
55 | 55 | context.strokeStyle = "rgb(255, 0, 0)";
|
56 | 56 | context.strokeRect (_rectangle.startX, _rectangle.startY, _rectangle.endX, _rectangle.endY);
|
57 | 57 | }
|
58 | 58 | function onMouseUp (e) {
|
59 |
| - draw(); |
60 |
| - _rectangle = createRect(); |
| 59 | + draw(true); |
| 60 | + // _rectangle = createRect(); |
61 | 61 | rectDom.removeEventListener ("mousemove", onMouseMove, false);
|
62 | 62 | }
|
63 | 63 |
|
|
70 | 70 | };
|
71 | 71 | }
|
72 | 72 |
|
73 |
| -function draw() { |
| 73 | +function draw(update) { |
74 | 74 | context.clearRect(0, 0, rectDom.width, rectDom.height);
|
75 | 75 | context.lineWidth = 3;
|
76 | 76 | context.strokeStyle = "rgb(255, 0, 0)";
|
77 | 77 | var r = _rectangle;
|
78 | 78 | context.strokeRect(r.startX, r.startY, r.endX, r.endY);
|
79 | 79 |
|
| 80 | + if (!update) { return; } |
| 81 | + |
80 | 82 | var n = normalize(_rectangle);
|
81 | 83 | if (n.endX * n.endY === 0) {
|
82 | 84 | document.getElementById('selected_area').innerText = '';
|
|
105 | 107 |
|
106 | 108 | rectDom.addEventListener("mousedown", onMouseDown, false);
|
107 | 109 | rectDom.addEventListener("mouseup" , onMouseUp , false);
|
108 |
| -imageDom.addEventListener('load', resize, false); |
| 110 | +imageDom.addEventListener('load', function() { resize(); draw(false); }, false); |
109 | 111 |
|
110 | 112 | renderPage();
|
111 | 113 | </script>
|
|
0 commit comments