diff --git a/client/client_recv.js b/client/client_recv.js index 8a19afc..4789658 100644 --- a/client/client_recv.js +++ b/client/client_recv.js @@ -116,13 +116,16 @@ function bitmap_bbox(event) { return bbox; } -async function handle_event(state, context, event, relax = false) { +function handle_event(state, context, event, relax = false) { if (config.debug_print) console.debug(`event type ${event.type} from user ${event.user_id}`); + let need_draw = false; + switch (event.type) { case EVENT.STROKE: { if (event.user_id != state.me) { clear_dynamic_stroke(state, context, event.user_id); + need_draw = true; } add_static_stroke(state, context, event, relax); @@ -131,6 +134,7 @@ async function handle_event(state, context, event, relax = false) { } case EVENT.UNDO: { + need_draw = true; console.error('todo'); // for (let i = state.events.length - 1; i >=0; --i) { // const other_event = state.events[i]; @@ -173,6 +177,7 @@ async function handle_event(state, context, event, relax = false) { } case EVENT.IMAGE: { + need_draw = true; console.error('todo'); // const url = config.image_url + event.image_id; // const item = document.createElement('img'); @@ -198,6 +203,7 @@ async function handle_event(state, context, event, relax = false) { } case EVENT.IMAGE_MOVE: { + need_draw = true; console.error('todo'); // // Already moved due to local prediction // if (event.user_id !== state.me.id) { @@ -216,6 +222,7 @@ async function handle_event(state, context, event, relax = false) { } case EVENT.ERASER: { + need_draw = true; console.error('todo'); // if (event.deleted) { // break; @@ -239,6 +246,8 @@ async function handle_event(state, context, event, relax = false) { console.error('fuck'); } } + + return need_draw; } async function handle_message(state, context, d) { @@ -273,14 +282,14 @@ async function handle_message(state, context, d) { for (let i = 0; i < event_count; ++i) { const event = des_event(d); - await handle_event(state, context, event, true); + handle_event(state, context, event, true); state.events.push(event); } - recompute_static_data(context); - do_draw = true; + recompute_static_data(context); + send_ack(event_count); sync_queue(state); @@ -324,13 +333,12 @@ async function handle_message(state, context, d) { for (let i = 0; i < count; ++i) { const event = des_event(d); if (i >= first) { - handle_event(state, context, event); + const need_draw = handle_event(state, context, event); + do_draw = do_draw || need_draw; state.events.push(event); } } - do_draw = true; - state.sn = sn; send_ack(sn); // await? diff --git a/client/client_send.js b/client/client_send.js index 3d793bb..91a4ea5 100644 --- a/client/client_send.js +++ b/client/client_send.js @@ -220,7 +220,7 @@ function predraw_event(x, y) { function stroke_event(state) { return { 'type': EVENT.STROKE, - 'points': state.current_strokes[state.me].points, + 'points': process_stroke(state.current_strokes[state.me].points), 'width': state.current_strokes[state.me].width, 'color': state.current_strokes[state.me].color, }; diff --git a/client/default.css b/client/default.css index 896568a..d4ffad9 100644 --- a/client/default.css +++ b/client/default.css @@ -1,60 +1,38 @@ +:root { + --dark-blue: #2f343d; + --dark-hover: #888; + --radius: 5px; + --hgap: 5px; + --gap: 10px; +} + html, body { margin: 0; padding: 0; + width: 100%; + height: 100%; overflow: hidden; - touch-action: none; -} - -.dhide { - display: none !important; -} - -.canvas { - position: absolute; - top: 0; - left: 0; - opacity: 1; - transition: opacity .2s; - transform-origin: top left; - pointer-events: none; } -#toucher { - position: fixed; +canvas { width: 100%; height: 100%; - top: 0; - left: 0; - z-index: 5; /* above all canvases, but below tools */ + display: block; cursor: crosshair; } -.canvas.white { - opacity: 0; -} - -#canvas-images { - z-index: 0; -} - -#canvas0 { - z-index: 1; - background: #eee; - background-position: 0px 0px; - background-size: 32px 32px; - background-image: radial-gradient(rgba(0, 0, 0, 0.1) 1px, transparent 10%); +canvas.movemode { + cursor: grab; } -#canvas1 { - z-index: 2; - opacity: 0.3; +canvas.movemode.moving { + cursor: grabbing; } .tools-wrapper { position: fixed; bottom: 0; width: 100%; - height: 32px; display: flex; justify-content: center; align-items: end; @@ -62,61 +40,97 @@ html, body { pointer-events: none; } +.pallete-wrapper { + position: fixed; + top: 0; + left: 0; + height: 100%; + pointer-events: none; + display: flex; + flex-direction: column; + justify-content: center; +} + +.pallete { + pointer-events: all; + display: grid; + flex-direction: column; + align-items: center; + background: var(--dark-blue); + border-top-right-radius: var(--radius); + border-bottom-right-radius: var(--radius); +/* border-bottom-left-radius: var(--radius);*/ + padding-top: var(--gap); + padding-bottom: var(--gap); +} + +.pallete .color { + padding: var(--gap); + cursor: pointer; + background: var(--dark-blue); + transition: transform .1s ease-in-out; +} + +.pallete .color:hover { + background: var(--dark-hover); +} + +.pallete .color.active { + transform: translateX(10px); + border-top-right-radius: var(--radius); + border-bottom-right-radius: var(--radius); +} + +.pallete .color.active:hover { + background: var(--dark-blue); +} + +.pallete .color-pane { + width: 24px; + height: 24px; + box-sizing: border-box; + border-radius: var(--radius); +} + .tools { pointer-events: all; display: flex; align-items: center; justify-content: center; - background: #333; - border-radius: 5px; + background: var(--dark-blue); + border-radius: var(--radius); border-bottom-right-radius: 0; border-bottom-left-radius: 0; height: 42px; - padding-left: 10px; - padding-right: 10px; + padding-left: var(--gap); + padding-right: var(--gap); } .tool { cursor: pointer; - padding-left: 10px; - padding-right: 10px; + padding-left: var(--gap); + padding-right: var(--gap); height: 100%; display: flex; align-items: center; - background: #333; + background: var(--dark-blue); transition: transform .1s ease-in-out; user-select: none; } .tool:hover { - background: #888; + background: var(--dark-hover); } .tool.active { transform: translateY(-10px); - border-top-right-radius: 5px; - border-top-left-radius: 5px; - background: #333; + border-top-right-radius: var(--radius); + border-top-left-radius: var(--radius); + background: var(--dark-blue); } .tool img { height: 24px; width: 24px; filter: invert(100%); -} - -.toolbar { - visibility: hidden; -} - -.floating-image { - position: absolute; - user-drag: none; - user-select: none; -} - -.floating-image.activated { - outline: 5px solid #5286ff; - z-index: 999999 !important; - cursor: grab; } \ No newline at end of file diff --git a/client/index.html b/client/index.html index 283ee99..9dcaac6 100644 --- a/client/index.html +++ b/client/index.html @@ -4,106 +4,41 @@