|
|
|
@ -37,10 +37,11 @@ function on_down(e) {
@@ -37,10 +37,11 @@ function on_down(e) {
|
|
|
|
|
storage.cursor.x = x; |
|
|
|
|
storage.cursor.y = y; |
|
|
|
|
|
|
|
|
|
const predraw = predraw_event(x, y); |
|
|
|
|
storage.current_stroke.push(predraw); |
|
|
|
|
|
|
|
|
|
fire_event(predraw); |
|
|
|
|
if (storage.tool === 'brush') { |
|
|
|
|
const predraw = predraw_event(x, y); |
|
|
|
|
storage.current_stroke.push(predraw); |
|
|
|
|
fire_event(predraw); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -69,19 +70,40 @@ function on_move(e) {
@@ -69,19 +70,40 @@ function on_move(e) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (storage.state.drawing) { |
|
|
|
|
const width = storage.cursor.width; |
|
|
|
|
|
|
|
|
|
storage.ctx1.beginPath(); |
|
|
|
|
|
|
|
|
|
storage.ctx1.moveTo(last_x, last_y); |
|
|
|
|
storage.ctx1.lineTo(x, y); |
|
|
|
|
|
|
|
|
|
storage.ctx1.stroke(); |
|
|
|
|
|
|
|
|
|
const predraw = predraw_event(x, y); |
|
|
|
|
storage.current_stroke.push(predraw); |
|
|
|
|
|
|
|
|
|
fire_event(predraw); |
|
|
|
|
if (storage.tool === 'brush') { |
|
|
|
|
const width = storage.cursor.width; |
|
|
|
|
|
|
|
|
|
storage.ctx1.beginPath(); |
|
|
|
|
|
|
|
|
|
storage.ctx1.moveTo(last_x, last_y); |
|
|
|
|
storage.ctx1.lineTo(x, y); |
|
|
|
|
|
|
|
|
|
storage.ctx1.stroke(); |
|
|
|
|
|
|
|
|
|
const predraw = predraw_event(x, y); |
|
|
|
|
storage.current_stroke.push(predraw); |
|
|
|
|
|
|
|
|
|
fire_event(predraw); |
|
|
|
|
} else if (storage.tool === 'eraser') { |
|
|
|
|
const erased = strokes_intersect_line(last_x, last_y, x, y); |
|
|
|
|
storage.erased.push(...erased); |
|
|
|
|
|
|
|
|
|
if (erased.length > 0) { |
|
|
|
|
for (const other_event of storage.events) { |
|
|
|
|
for (const stroke_id of erased) { |
|
|
|
|
if (stroke_id === other_event.stroke_id) { |
|
|
|
|
if (!other_event.deleted) { |
|
|
|
|
other_event.deleted = true; |
|
|
|
|
const stats = stroke_stats(other_event.points, storage.cursor.width); |
|
|
|
|
redraw_region(stats.bbox); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
console.error('fuck'); |
|
|
|
|
} |
|
|
|
|
} else if (storage.state.moving && storage.state.mousedown) { |
|
|
|
|
storage.canvas.offset_x -= e.movementX; |
|
|
|
|
storage.canvas.offset_y -= e.movementY; |
|
|
|
@ -118,15 +140,39 @@ async function on_up(e) {
@@ -118,15 +140,39 @@ async function on_up(e) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (storage.state.drawing && e.button === 0) { |
|
|
|
|
if (storage.tool === 'brush') { |
|
|
|
|
const event = stroke_event(); |
|
|
|
|
storage.current_stroke = []; |
|
|
|
|
await queue_event(event); |
|
|
|
|
} else if (storage.tool === 'eraser') { |
|
|
|
|
const events = eraser_events(); |
|
|
|
|
storage.erased = []; |
|
|
|
|
if (events.length > 0) { |
|
|
|
|
for (const event of events) { |
|
|
|
|
await queue_event(event); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
console.error('fuck'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
storage.state.drawing = false; |
|
|
|
|
const event = stroke_event(); |
|
|
|
|
storage.current_stroke = []; |
|
|
|
|
await queue_event(event); |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function on_keydown(e) { |
|
|
|
|
if (e.code === 'KeyE') { |
|
|
|
|
storage.tool = 'eraser'; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (e.code === 'KeyB') { |
|
|
|
|
storage.tool = 'brush'; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (e.code === 'Space' && !storage.state.drawing) { |
|
|
|
|
storage.state.moving = true; |
|
|
|
|
storage.state.spacedown = true; |
|
|
|
|