diff --git a/client/cursor.js b/client/cursor.js index 22b29f6..ede264d 100644 --- a/client/cursor.js +++ b/client/cursor.js @@ -44,10 +44,13 @@ function on_down(e) { storage.cursor.x = x; storage.cursor.y = y; - if (storage.tool === 'brush') { + if (storage.tools.active === 'pencil') { const predraw = predraw_event(x, y); storage.current_stroke.push(predraw); fire_event(predraw); + } else if (storage.tools.active === 'ruler') { + storage.ruler_origin.x = x; + storage.ruler_origin.y = y; } } } @@ -77,7 +80,7 @@ function on_move(e) { } if (storage.state.drawing) { - if (storage.tool === 'brush') { + if (storage.tools.active === 'pencil') { const width = storage.cursor.width; storage.ctx1.beginPath(); @@ -91,7 +94,7 @@ function on_move(e) { storage.current_stroke.push(predraw); fire_event(predraw); - } else if (storage.tool === 'eraser') { + } else if (storage.tools.active === 'eraser') { const erased = strokes_intersect_line(last_x, last_y, x, y); storage.erased.push(...erased); @@ -108,6 +111,23 @@ function on_move(e) { } } } + } else if (storage.tools.active === 'ruler') { + const old_ruler = [ + {'x': storage.ruler_origin.x, 'y': storage.ruler_origin.y}, + {'x': last_x, 'y': last_y} + ]; + + const stats = stroke_stats(old_ruler, storage.cursor.width); + const bbox = stats.bbox; + + storage.ctx1.clearRect(bbox.xmin, bbox.ymin, bbox.xmax - bbox.xmin, bbox.ymax - bbox.ymin); + + storage.ctx1.beginPath(); + + storage.ctx1.moveTo(storage.ruler_origin.x, storage.ruler_origin.y); + storage.ctx1.lineTo(x, y); + + storage.ctx1.stroke(); } else { console.error('fuck'); } @@ -150,11 +170,11 @@ async function on_up(e) { } if (storage.state.drawing && e.button === 0) { - if (storage.tool === 'brush') { + if (storage.tools.active === 'pencil') { const event = stroke_event(); storage.current_stroke = []; await queue_event(event); - } else if (storage.tool === 'eraser') { + } else if (storage.tools.active === 'eraser') { const events = eraser_events(); storage.erased = []; if (events.length > 0) { @@ -162,6 +182,9 @@ async function on_up(e) { await queue_event(event); } } + } else if (storage.tools.active === 'ruler') { + const event = ruler_event(storage.cursor.x, storage.cursor.y); + await queue_event(event); } else { console.error('fuck'); } @@ -173,16 +196,6 @@ async function on_up(e) { } function on_keydown(e) { - if (e.code === 'KeyE') { - storage.tool = 'eraser'; - return; - } - - if (e.code === 'KeyB') { - storage.tool = 'brush'; - return; - } - if (e.code === 'Space' && !storage.state.drawing) { storage.state.moving = true; storage.state.spacedown = true; @@ -190,8 +203,7 @@ function on_keydown(e) { } if (e.code === 'KeyZ' && e.ctrlKey) { - const event = undo_event(); - queue_event(event); + undo(); return; } } @@ -204,6 +216,7 @@ function on_keyup(e) { } function on_leave(e) { + // TODO: broken when "moving" if (storage.state.moving) { storage.state.moving = false; storage.state.holding = false; diff --git a/client/default.css b/client/default.css index 418b3f9..9ec6b8c 100644 --- a/client/default.css +++ b/client/default.css @@ -2,6 +2,7 @@ html, body { margin: 0; padding: 0; overflow: hidden; + touch-action: none; } .dhide { @@ -18,6 +19,16 @@ html, body { pointer-events: none; } +#toucher { + position: fixed; + width: 100%; + height: 100%; + top: 0; + left: 0; + z-index: 5; /* above all canvases, but below tools */ + cursor: crosshair; +} + .canvas.white { opacity: 0; } @@ -28,8 +39,10 @@ html, body { #canvas0 { z-index: 1; - box-sizing: border-box; - border: 1px solid black; + background: #eee; + background-position: 0px 0px; + background-size: 32px 32px; + background-image: radial-gradient(rgba(0, 0, 0, 0.1) 1px, transparent 10%); } #canvas1 { @@ -37,50 +50,61 @@ html, body { opacity: 0.3; } -.toolbar { +.tools-wrapper { position: fixed; - left: 20px; - top: 20px; - background: #eee; - border: 1px solid #ddd; - padding: 10px; - border-radius: 5px; - box-shadow: 0px 2px 2px 0px rgba(0, 0, 0, 0.1); + bottom: 0; + width: 100%; + height: 32px; display: flex; - gap: 10px; + justify-content: center; + align-items: end; z-index: 10; - align-items: center; } -.toolbar #brush-width { - width: 7ch; - height: 30px; - padding: 5px; - box-sizing: border-box; - border: none; - cursor: crosshair; +.tools { + display: flex; + align-items: center; + justify-content: center; + background: #333; + border-radius: 5px; + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; + height: 42px; + padding-left: 10px; + padding-right: 10px; } -.toolbar #brush-color { - padding: 0; - height: 30px; - width: 30px; - border: none; +.tool { cursor: pointer; + padding-left: 10px; + padding-right: 10px; + height: 100%; + display: flex; + align-items: center; + background: #333; + transition: transform .1s ease-in-out; + user-select: none; } -#brush-preview { - border-radius: 50%; - width: 5px; - height: 5px; - background: black; - position: absolute; - pointer-events: none; - z-index: 11; +.tool:hover { + background: #888; +} + +.tool.active { + transform: translateY(-10px); + border-top-right-radius: 5px; + border-top-left-radius: 5px; + background: #333; } -.toolbar #brush-color::-moz-color-swatch { - border: none; +.tool img { + height: 24px; + width: 24px; + filter: invert(100%); +} + +.toolbar { + visibility: hidden; } .floating-image { diff --git a/client/favicon.png b/client/favicon_old.png similarity index 100% rename from client/favicon.png rename to client/favicon_old.png diff --git a/client/icons/draw.svg b/client/icons/draw.svg new file mode 100644 index 0000000..5278f0e --- /dev/null +++ b/client/icons/draw.svg @@ -0,0 +1,54 @@ + + + + diff --git a/client/icons/erase.svg b/client/icons/erase.svg new file mode 100644 index 0000000..38d6749 --- /dev/null +++ b/client/icons/erase.svg @@ -0,0 +1,74 @@ + + + + diff --git a/client/icons/favicon.svg b/client/icons/favicon.svg new file mode 100644 index 0000000..cefb877 --- /dev/null +++ b/client/icons/favicon.svg @@ -0,0 +1,49 @@ + + + + diff --git a/client/icons/redo.svg b/client/icons/redo.svg new file mode 100644 index 0000000..c777746 --- /dev/null +++ b/client/icons/redo.svg @@ -0,0 +1,54 @@ + + + + diff --git a/client/icons/ruler.svg b/client/icons/ruler.svg new file mode 100644 index 0000000..2012999 --- /dev/null +++ b/client/icons/ruler.svg @@ -0,0 +1,49 @@ + + + + diff --git a/client/icons/undo.svg b/client/icons/undo.svg new file mode 100644 index 0000000..49d5e88 --- /dev/null +++ b/client/icons/undo.svg @@ -0,0 +1,54 @@ + + + + diff --git a/client/index.html b/client/index.html index 69191db..3605235 100644 --- a/client/index.html +++ b/client/index.html @@ -3,25 +3,42 @@