|
|
|
@ -12,6 +12,14 @@ function init_listeners(state, context) {
@@ -12,6 +12,14 @@ function init_listeners(state, context) {
|
|
|
|
|
context.canvas.addEventListener('touchmove', (e) => touchmove(e, state, context)); |
|
|
|
|
context.canvas.addEventListener('touchend', (e) => touchend(e, state, context)); |
|
|
|
|
context.canvas.addEventListener('touchcancel', (e) => touchend(e, state, context)); |
|
|
|
|
|
|
|
|
|
context.canvas.addEventListener('drop', (e) => on_drop(e, state, context)); |
|
|
|
|
context.canvas.addEventListener('dragover', (e) => mousemove(e, state, context)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function cancel(e) { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function keydown(e, state, context) { |
|
|
|
@ -45,7 +53,6 @@ function mousedown(e, state, context) {
@@ -45,7 +53,6 @@ function mousedown(e, state, context) {
|
|
|
|
|
const screenp = {'x': e.clientX, 'y': e.clientY}; |
|
|
|
|
const canvasp = screen_to_canvas(state, screenp); |
|
|
|
|
|
|
|
|
|
state.cursor = canvasp; |
|
|
|
|
clear_dynamic_stroke(state, context); |
|
|
|
|
update_dynamic_stroke(state, context, canvasp); |
|
|
|
|
state.drawing = true; |
|
|
|
@ -54,6 +61,8 @@ function mousedown(e, state, context) {
@@ -54,6 +61,8 @@ function mousedown(e, state, context) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function mousemove(e, state, context) { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
|
|
|
|
|
let do_draw = false; |
|
|
|
|
|
|
|
|
|
if (state.moving) { |
|
|
|
@ -63,10 +72,11 @@ function mousemove(e, state, context) {
@@ -63,10 +72,11 @@ function mousemove(e, state, context) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const screenp = {'x': e.clientX, 'y': e.clientY}; |
|
|
|
|
const canvasp = screen_to_canvas(state, screenp); |
|
|
|
|
|
|
|
|
|
state.cursor = screenp; |
|
|
|
|
|
|
|
|
|
if (state.drawing) { |
|
|
|
|
const canvasp = screen_to_canvas(state, screenp); |
|
|
|
|
state.cursor = canvasp; |
|
|
|
|
update_dynamic_stroke(state, context, canvasp); |
|
|
|
|
do_draw = true; |
|
|
|
|
} |
|
|
|
@ -74,6 +84,8 @@ function mousemove(e, state, context) {
@@ -74,6 +84,8 @@ function mousemove(e, state, context) {
|
|
|
|
|
if (do_draw) { |
|
|
|
|
window.requestAnimationFrame(() => draw(state, context)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function mouseup(e, state, context) { |
|
|
|
@ -321,4 +333,43 @@ function touchend(e, state, context) {
@@ -321,4 +333,43 @@ function touchend(e, state, context) {
|
|
|
|
|
state.touch.moving = false; |
|
|
|
|
waiting_for_second_finger = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async function on_drop(e, state, context) { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
|
|
|
|
|
if (e.dataTransfer.files.length !== 1) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const file = e.dataTransfer.files[0]; |
|
|
|
|
const bitmap = await createImageBitmap(file); |
|
|
|
|
|
|
|
|
|
const p = { 'x': state.cursor.x, 'y': state.cursor.y }; |
|
|
|
|
const canvasp = screen_to_canvas(state, p); |
|
|
|
|
|
|
|
|
|
canvasp.x -= bitmap.width / 2; |
|
|
|
|
canvasp.y -= bitmap.height / 2; |
|
|
|
|
|
|
|
|
|
add_image(context, bitmap, canvasp); |
|
|
|
|
// storage.ctx0.drawImage(bitmap, x, y);
|
|
|
|
|
|
|
|
|
|
const form_data = new FormData(); |
|
|
|
|
form_data.append('file', file); |
|
|
|
|
|
|
|
|
|
const resp = await fetch(`/api/image?deskId=333`, { |
|
|
|
|
method: 'post', |
|
|
|
|
body: form_data, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
if (resp.ok) { |
|
|
|
|
// const image_id = await resp.text();
|
|
|
|
|
// const event = image_event(image_id, x, y);
|
|
|
|
|
// await queue_event(event);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
window.requestAnimationFrame(() => draw(state, context)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |