|
|
|
@ -1,48 +1,73 @@
@@ -1,48 +1,73 @@
|
|
|
|
|
function on_down(e) { |
|
|
|
|
const x = Math.round((e.clientX + storage.canvas.offset_x) / storage.canvas.zoom); |
|
|
|
|
const y = Math.round((e.clientY + storage.canvas.offset_y) / storage.canvas.zoom); |
|
|
|
|
|
|
|
|
|
if (e.button === 1) { |
|
|
|
|
elements.canvas0.classList.add('moving'); |
|
|
|
|
storage.state.moving = true; |
|
|
|
|
storage.state.mousedown = true; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (e.button != 0) { |
|
|
|
|
if (e.button === 2) { |
|
|
|
|
const image_hit = image_at(x, y); |
|
|
|
|
activate_image(image_hit); |
|
|
|
|
e.preventDefault(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (storage.state.moving) { |
|
|
|
|
storage.state.mousedown = true; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (e.button === 0) { |
|
|
|
|
const image_hit = image_at(x, y); |
|
|
|
|
|
|
|
|
|
const x = Math.round((e.clientX + storage.canvas.offset_x) / storage.canvas.zoom); |
|
|
|
|
const y = Math.round((e.clientY + storage.canvas.offset_y) / storage.canvas.zoom); |
|
|
|
|
if (elements.active_image !== null && image_hit !== null) { |
|
|
|
|
storage.state.moving_image = true; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
storage.state.drawing = true; |
|
|
|
|
if (storage.state.moving) { |
|
|
|
|
storage.state.mousedown = true; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (storage.ctx1.lineWidth !== storage.cursor.width) { |
|
|
|
|
storage.ctx1.lineWidth = storage.cursor.width; |
|
|
|
|
} |
|
|
|
|
storage.state.drawing = true; |
|
|
|
|
|
|
|
|
|
storage.cursor.x = x; |
|
|
|
|
storage.cursor.y = y; |
|
|
|
|
if (storage.ctx1.lineWidth !== storage.cursor.width) { |
|
|
|
|
storage.ctx1.lineWidth = storage.cursor.width; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const predraw = predraw_event(x, y); |
|
|
|
|
storage.current_stroke.push(predraw); |
|
|
|
|
storage.cursor.x = x; |
|
|
|
|
storage.cursor.y = y; |
|
|
|
|
|
|
|
|
|
fire_event(predraw); |
|
|
|
|
const predraw = predraw_event(x, y); |
|
|
|
|
storage.current_stroke.push(predraw); |
|
|
|
|
|
|
|
|
|
fire_event(predraw); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function on_move(e) { |
|
|
|
|
const last_x = storage.cursor.x; |
|
|
|
|
const last_y = storage.cursor.y; |
|
|
|
|
|
|
|
|
|
const x = storage.cursor.x = Math.round((e.clientX + storage.canvas.offset_x) / storage.canvas.zoom); |
|
|
|
|
const y = storage.cursor.y = Math.round((e.clientY + storage.canvas.offset_y) / storage.canvas.zoom); |
|
|
|
|
const x = storage.cursor.x = Math.max(Math.round((e.clientX + storage.canvas.offset_x) / storage.canvas.zoom), 0); |
|
|
|
|
const y = storage.cursor.y = Math.max(Math.round((e.clientY + storage.canvas.offset_y) / storage.canvas.zoom), 0); |
|
|
|
|
|
|
|
|
|
const old_offset_x = storage.canvas.offset_x; |
|
|
|
|
const old_offset_y = storage.canvas.offset_y; |
|
|
|
|
|
|
|
|
|
if (elements.active_image && storage.state.moving_image) { |
|
|
|
|
const dx = Math.round(e.movementX / storage.canvas.zoom); |
|
|
|
|
const dy = Math.round(e.movementY / storage.canvas.zoom); |
|
|
|
|
|
|
|
|
|
const image_id = elements.active_image.getAttribute('data-image-id'); |
|
|
|
|
|
|
|
|
|
const ix = storage.images[image_id].x += dx; |
|
|
|
|
const iy = storage.images[image_id].y += dy; |
|
|
|
|
|
|
|
|
|
elements.active_image.style.transform = `translate(${ix}px, ${iy}px)`; |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (storage.state.drawing) { |
|
|
|
|
const width = storage.cursor.width; |
|
|
|
|
|
|
|
|
@ -75,10 +100,18 @@ function on_move(e) {
@@ -75,10 +100,18 @@ function on_move(e) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async function on_up(e) { |
|
|
|
|
if (storage.state.moving_image && e.button === 0) { |
|
|
|
|
storage.state.moving_image = false; |
|
|
|
|
const image_id = elements.active_image.getAttribute('data-image-id'); |
|
|
|
|
const position = storage.images[image_id]; |
|
|
|
|
const event = image_move_event(image_id, position.x, position.y); |
|
|
|
|
await queue_event(event); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (storage.state.moving && (e.button === 1 || e.button === 0)) { |
|
|
|
|
storage.state.mousedown = false; |
|
|
|
|
if (!storage.state.spacedown) { |
|
|
|
|
elements.canvas0.classList.remove('moving'); |
|
|
|
|
storage.state.moving = false; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -95,7 +128,6 @@ async function on_up(e) {
@@ -95,7 +128,6 @@ async function on_up(e) {
|
|
|
|
|
|
|
|
|
|
function on_keydown(e) { |
|
|
|
|
if (e.code === 'Space' && !storage.state.drawing) { |
|
|
|
|
elements.canvas0.classList.add('moving'); |
|
|
|
|
storage.state.moving = true; |
|
|
|
|
storage.state.spacedown = true; |
|
|
|
|
return; |
|
|
|
@ -110,7 +142,6 @@ function on_keydown(e) {
@@ -110,7 +142,6 @@ function on_keydown(e) {
|
|
|
|
|
|
|
|
|
|
function on_keyup(e) { |
|
|
|
|
if (e.code === 'Space' && storage.state.moving) { |
|
|
|
|
elements.canvas0.classList.remove('moving'); |
|
|
|
|
storage.state.moving = false; |
|
|
|
|
storage.state.spacedown = false; |
|
|
|
|
} |
|
|
|
@ -118,7 +149,6 @@ function on_keyup(e) {
@@ -118,7 +149,6 @@ function on_keyup(e) {
|
|
|
|
|
|
|
|
|
|
function on_leave(e) { |
|
|
|
|
if (storage.state.moving) { |
|
|
|
|
elements.canvas0.classList.remove('moving'); |
|
|
|
|
storage.state.moving = false; |
|
|
|
|
storage.state.holding = false; |
|
|
|
|
return; |
|
|
|
|