|
|
|
@ -127,7 +127,15 @@ function des_event(d, state = null) {
@@ -127,7 +127,15 @@ function des_event(d, state = null) {
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case EVENT.IMAGE: |
|
|
|
|
case EVENT.IMAGE: { |
|
|
|
|
event.image_id = des_u32(d); |
|
|
|
|
event.x = des_f32(d); |
|
|
|
|
event.y = des_f32(d); |
|
|
|
|
event.width = des_u32(d); |
|
|
|
|
event.height = des_u32(d); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case EVENT.IMAGE_MOVE: { |
|
|
|
|
event.image_id = des_u32(d); |
|
|
|
|
event.x = des_f32(d); |
|
|
|
@ -135,6 +143,14 @@ function des_event(d, state = null) {
@@ -135,6 +143,14 @@ function des_event(d, state = null) {
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case EVENT.IMAGE_SCALE: { |
|
|
|
|
event.image_id = des_u32(d); |
|
|
|
|
event.corner = des_u32(d); |
|
|
|
|
event.x = des_f32(d); |
|
|
|
|
event.y = des_f32(d); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case EVENT.UNDO: |
|
|
|
|
case EVENT.REDO: { |
|
|
|
|
break; |
|
|
|
@ -350,6 +366,14 @@ function handle_event(state, context, event, options = {}) {
@@ -350,6 +366,14 @@ function handle_event(state, context, event, options = {}) {
|
|
|
|
|
break; |
|
|
|
|
} else if (other_event.type === EVENT.UNDO) { |
|
|
|
|
// do not undo an undo, we are not Notepad
|
|
|
|
|
} else if (other_event.type === EVENT.IMAGE_MOVE) { |
|
|
|
|
// TODO
|
|
|
|
|
console.log('TODO: undo image scale'); |
|
|
|
|
break; |
|
|
|
|
} else if (other_event.type === EVENT.IMAGE_SCALE) { |
|
|
|
|
// TODO
|
|
|
|
|
console.log('TODO: undo image scale'); |
|
|
|
|
break; |
|
|
|
|
} else { |
|
|
|
|
console.error('cant undo event type', other_event.type); |
|
|
|
|
break; |
|
|
|
@ -361,21 +385,24 @@ function handle_event(state, context, event, options = {}) {
@@ -361,21 +385,24 @@ function handle_event(state, context, event, options = {}) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case EVENT.IMAGE: { |
|
|
|
|
const p = {'x': event.x, 'y': event.y}; |
|
|
|
|
|
|
|
|
|
geometry_add_dummy_stroke(context); |
|
|
|
|
add_image(context, event.image_id, null, p, event.width, event.height); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
(async () => { |
|
|
|
|
const url = config.image_url + event.image_id; |
|
|
|
|
const r = await fetch(config.image_url + event.image_id); |
|
|
|
|
const blob = await r.blob(); |
|
|
|
|
|
|
|
|
|
// NOTE: this will resolve when bitmap is ready, which will be much later
|
|
|
|
|
const bitmap = await createImageBitmap(blob); |
|
|
|
|
const p = {'x': event.x, 'y': event.y}; |
|
|
|
|
|
|
|
|
|
event.width = bitmap.width; |
|
|
|
|
event.height = bitmap.height; |
|
|
|
|
|
|
|
|
|
// TODO: preserve image order
|
|
|
|
|
add_image(context, event.image_id, bitmap, p); |
|
|
|
|
add_image(context, event.image_id, bitmap, p, bitmap.width, bitmap.height); |
|
|
|
|
|
|
|
|
|
// God knows when this will actually complete (it loads the image from the server)
|
|
|
|
|
// so do not set need_draw. Instead just schedule the draw ourselves when done
|
|
|
|
@ -389,17 +416,28 @@ function handle_event(state, context, event, options = {}) {
@@ -389,17 +416,28 @@ function handle_event(state, context, event, options = {}) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case EVENT.IMAGE_MOVE: { |
|
|
|
|
// Already moved due to local prediction
|
|
|
|
|
if (event.user_id !== state.me) { |
|
|
|
|
const image_id = event.image_id; |
|
|
|
|
const image = get_image(context, image_id); |
|
|
|
|
|
|
|
|
|
if (image) { |
|
|
|
|
// if (config.debug_print) console.debug('move image', image_id, 'to', image_event.x, image_event.y);
|
|
|
|
|
image.at.x = event.x; |
|
|
|
|
image.at.y = event.y; |
|
|
|
|
need_draw = true; |
|
|
|
|
} |
|
|
|
|
geometry_add_dummy_stroke(context); |
|
|
|
|
const image_id = event.image_id; |
|
|
|
|
const image = get_image(context, image_id); |
|
|
|
|
|
|
|
|
|
if (image) { |
|
|
|
|
// if (config.debug_print) console.debug('move image', image_id, 'to', image_event.x, image_event.y);
|
|
|
|
|
image.at.x = event.x; |
|
|
|
|
image.at.y = event.y; |
|
|
|
|
need_draw = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case EVENT.IMAGE_SCALE: { |
|
|
|
|
geometry_add_dummy_stroke(context); |
|
|
|
|
const image_id = event.image_id; |
|
|
|
|
const image = get_image(context, image_id); |
|
|
|
|
|
|
|
|
|
if (image !== null) { |
|
|
|
|
scale_image(context, image, event.corner, {'x': event.x, 'y': event.y}); |
|
|
|
|
need_draw = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|