|
|
|
@ -86,23 +86,18 @@ function des_event(d) {
@@ -86,23 +86,18 @@ function des_event(d) {
|
|
|
|
|
return event; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function redraw_region(bbox) { |
|
|
|
|
storage.ctx0.save(); |
|
|
|
|
storage.ctx0.clearRect(bbox.xmin, bbox.ymin, bbox.xmax - bbox.xmin, bbox.ymax - bbox.ymin); |
|
|
|
|
|
|
|
|
|
storage.ctx0.beginPath(); |
|
|
|
|
storage.ctx0.rect(bbox.xmin, bbox.ymin, bbox.xmax - bbox.xmin, bbox.ymax - bbox.ymin); |
|
|
|
|
storage.ctx0.clip(); |
|
|
|
|
|
|
|
|
|
for (const event of storage.events) { |
|
|
|
|
if (event.type === EVENT.STROKE && !event.deleted) { |
|
|
|
|
if (stroke_intersects_region(event.points, bbox)) { |
|
|
|
|
draw_stroke(event); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
function bitmap_bbox(event) { |
|
|
|
|
const x = (event.x <= storage.canvas.width ? event.x : event.x - 65536); |
|
|
|
|
const y = (event.y <= storage.canvas.height ? event.y : event.y - 65536); |
|
|
|
|
|
|
|
|
|
const bbox = { |
|
|
|
|
'xmin': x, |
|
|
|
|
'xmax': x + event.bitmap.width, |
|
|
|
|
'ymin': y, |
|
|
|
|
'ymax': y + event.bitmap.height |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
storage.ctx0.restore(); |
|
|
|
|
return bbox; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async function handle_event(event) { |
|
|
|
@ -123,11 +118,17 @@ async function handle_event(event) {
@@ -123,11 +118,17 @@ async function handle_event(event) {
|
|
|
|
|
case EVENT.UNDO: { |
|
|
|
|
for (let i = storage.events.length - 1; i >=0; --i) { |
|
|
|
|
const other_event = storage.events[i]; |
|
|
|
|
|
|
|
|
|
if (other_event.type === EVENT.STROKE && other_event.user_id === event.user_id && !other_event.deleted) { |
|
|
|
|
other_event.deleted = true; |
|
|
|
|
const stats = stroke_stats(other_event.points, storage.cursor.width); |
|
|
|
|
redraw_region(stats.bbox); |
|
|
|
|
break; |
|
|
|
|
} else if (other_event.type === EVENT.IMAGE && other_event.user_id === event.user_id && !other_event.deleted) { |
|
|
|
|
other_event.deleted = true; |
|
|
|
|
const bbox = bitmap_bbox(other_event); |
|
|
|
|
redraw_region(bbox); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -139,11 +140,11 @@ async function handle_event(event) {
@@ -139,11 +140,11 @@ async function handle_event(event) {
|
|
|
|
|
const blob = await r.blob(); |
|
|
|
|
const bitmap = await createImageBitmap(blob); |
|
|
|
|
|
|
|
|
|
event.bitmap = bitmap; |
|
|
|
|
|
|
|
|
|
const x = (event.x <= storage.canvas.width ? event.x : event.x - 65536); |
|
|
|
|
const y = (event.y <= storage.canvas.height ? event.y : event.y - 65536); |
|
|
|
|
const bbox = bitmap_bbox(event); |
|
|
|
|
storage.ctx0.drawImage(bitmap, bbox.xmin, bbox.ymin); |
|
|
|
|
|
|
|
|
|
storage.ctx0.drawImage(bitmap, x, y); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -176,7 +177,6 @@ async function handle_message(d) {
@@ -176,7 +177,6 @@ async function handle_message(d) {
|
|
|
|
|
console.debug('init in'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const event_count = des_u32(d); |
|
|
|
|
|
|
|
|
|
console.debug(`${event_count} events in init`); |
|
|
|
@ -184,10 +184,12 @@ async function handle_message(d) {
@@ -184,10 +184,12 @@ async function handle_message(d) {
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < event_count; ++i) { |
|
|
|
|
const event = des_event(d); |
|
|
|
|
handle_event(event); |
|
|
|
|
await handle_event(event); |
|
|
|
|
storage.events.push(event); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
elements.canvas0.classList.remove('white'); |
|
|
|
|
|
|
|
|
|
send_ack(event_count); |
|
|
|
|
|
|
|
|
|
sync_queue(); |
|
|
|
|