Skip to content

Commit 367a867

Browse files
committed
add brush size range
1 parent 191ce1e commit 367a867

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

index.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,12 @@ const tools = {
101101
const x = window.camera.convertScreenToMapX(canvas, cx);
102102
const y = window.camera.convertScreenToMapY(canvas, cy);
103103
const mx = (x % 1 + 1) % 1;
104-
const radius = 0.05;
104+
const radius = toolVar.radius;
105105
const area = toolVar.area;
106106

107+
toolVar.cx = cx;
108+
toolVar.cy = cy;
109+
107110
toolVar.areas = area._parentLayer.areas;
108111

109112
toolVar.structure.figure.drawCircle(mx - 1, y, radius, area.id, 0.5);
@@ -118,14 +121,17 @@ const tools = {
118121
toolVar.brushing = false;
119122
},
120123
mousemove: e => {
121-
if (!toolVar.brushing) return;
122-
123124
const cx = (e.clientX - canvas.offsetLeft) * window.devicePixelRatio;
124125
const cy = (e.clientY - canvas.offsetTop) * window.devicePixelRatio;
126+
toolVar.cx = cx;
127+
toolVar.cy = cy;
128+
129+
if (!toolVar.brushing) return;
130+
125131
const x = window.camera.convertScreenToMapX(canvas, cx);
126132
const y = window.camera.convertScreenToMapY(canvas, cy);
127133
const mx = (x % 1 + 1) % 1;
128-
const radius = 0.05;
134+
const radius = toolVar.radius;
129135
const area = toolVar.area;
130136

131137
toolVar.areas = area._parentLayer.areas;
@@ -139,15 +145,26 @@ const tools = {
139145
init: () => {
140146
toolVar.structure = new Structure(0, new Quadtree(0));
141147

148+
const sizeRange = document.createElement("input");
149+
sizeRange.type = "range";
150+
sizeRange.min = 0;
151+
sizeRange.max = 0.2;
152+
sizeRange.step = 0.001;
153+
sizeRange.onchange = e => {
154+
toolVar.radius = e.target.value;
155+
toolVar.cx = canvas.width / 2;
156+
toolVar.cy = canvas.height / 2;
157+
processFrame();
158+
};
159+
toolPropertiesDiv.appendChild(sizeRange);
160+
142161
const applyButton = document.createElement("button");
143162
applyButton.innerText = "Apply";
144163
applyButton.onclick = () => {
145164
const year = parseFloat(presentInput.value);
146165
const change = toolVar.structure;
147166
const layer = toolVar.area._parentLayer;
148167

149-
console.log("shit");
150-
151168
layer.createStructureByYear(year);
152169
layer.forEachStructureAfter(year, s => s.figure.overlap(change.figure));
153170
toolVar.structure = new Structure(0, new Quadtree(0));
@@ -156,6 +173,11 @@ const tools = {
156173
toolPropertiesDiv.appendChild(applyButton);
157174
},
158175
render: force => {
176+
const radius = toolVar.radius * window.camera.yZoom;
177+
ctx.beginPath();
178+
ctx.arc(toolVar.cx, toolVar.cy, radius, 0, 2 * Math.PI);
179+
ctx.stroke();
180+
159181
ctx.globalAlpha = 0.4;
160182
toolVar.structure.render(toolVar.areas, canvas, ctx, window.camera, force);
161183
}
@@ -190,6 +212,8 @@ function setTool(toolId) {
190212
});
191213

192214
nowTool = tool.id;
215+
216+
processFrame();
193217
}
194218

195219
/**

0 commit comments

Comments
 (0)