www.spaceplanner.app

Web client to the spaceplanner API
git clone git://jacobedwards.org/www.spaceplanner.app
Log | Files | Refs

commit c2c9661bc4f1197ab8d1bf937b12ffba9a93ab0e
parent dd13774c6e390d90c45e07894f642689a25db2ec
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Fri, 18 Oct 2024 23:38:49 -0700

Add long press on canvas to add furniture

Not sure if I'll stick with this, but I need to either reduce the
number of items in the toolbar or add dropdown menus to it.  I don't
think I'll remove the furniture adding button though, because that's
the best way to document other ways of doing the same thing.

Diffstat:
Mfiles/floorplans/floorplan/main.js | 41++++++++++++++++++++++++++++++++++++++---
1 file changed, 38 insertions(+), 3 deletions(-)

diff --git a/files/floorplans/floorplan/main.js b/files/floorplans/floorplan/main.js @@ -18,6 +18,7 @@ const buttons = { } const params = { + longpress: 250, threshold: 650 } @@ -35,9 +36,9 @@ const modes = { points: true, handlers: { contextmenu: preventDefaultHandler, - pointerdown: [singlePointerHandler, selectionHandler, selectionBoxHandler, precisePointHandler, precisePointMapHandler, furnitureHandler], - pointermove: [singlePointerHandler, selectionBoxHandler, precisePointHandler, precisePointMapHandler, furnitureHandler], - pointerup: [singlePointerHandler, selectionBoxHandler, precisePointHandler, precisePointMapHandler, furnitureHandler], + pointerdown: [singlePointerHandler, selectionHandler, selectionBoxHandler, precisePointHandler, precisePointMapHandler, furnitureHandler, addFurnitureHandler], + pointermove: [singlePointerHandler, selectionBoxHandler, precisePointHandler, precisePointMapHandler, furnitureHandler, addFurnitureHandler], + pointerup: [singlePointerHandler, selectionBoxHandler, precisePointHandler, precisePointMapHandler, furnitureHandler, addFurnitureHandler], pointercancel: [singlePointerHandler, selectionBoxHandler, precisePointHandler, precisePointMapHandler, furnitureHandler], keydown: [keyHandler], select: selectHandler, @@ -1115,6 +1116,40 @@ function precisePointMapHandler(event, editor, state) { } } +// pointerdown, pointerup +function addFurnitureHandler(ev, editor, state) { + const cleanup = function() { + if (state.timeout) { + clearTimeout(state.timeout) + } + for (let k in state) { + delete state[k] + } + } + + let p = new Vector2(ev.clientX, ev.clientY) + + if (!state.down) { + if (ev.type === "pointerdown") { + state.down = p + state.time = ev.timeStamp + state.timeout = setTimeout(function() { + furnitureMenu(editor, editor.draw.point(state.down.x, state.down.y).vec()) + cleanup() + }, params.longpress) + } + return + } + + if (ev.type === "pointermove") { + if (state.down.distanceTo(p) < 50) { + return + } + } + + cleanup() +} + // pointerdown, pointerup, pointermove function furnitureHandler(ev, editor, state) { const doMove = function() {