diff --git a/cotmw/src/components/HUD.vue b/cotmw/src/components/HUD.vue index f6107b4..fca55f4 100644 --- a/cotmw/src/components/HUD.vue +++ b/cotmw/src/components/HUD.vue @@ -4,11 +4,15 @@ const collapsed = ref(false); + const hud = ref(null); const pos = reactive({ x: 20, y: 20 }); const dragging = ref(false); const dragOffset = { x: 0, y: 0 }; + const logging = false; + function onMouseDown(e){ + log("Dragging started!"); dragging.value = true; dragOffset.x = e.clientX - pos.x; dragOffset.y = e.clientY - pos.y; @@ -17,11 +21,30 @@ function onMouseMove(e){ if(!dragging.value) return; - pos.x = e.clientX - dragOffset.x; - pos.y = e.clientY - dragOffset.y; + + const x = e.clientX - dragOffset.x; + const y = e.clientY - dragOffset.y; + + const hudRect = hud.value.getBoundingClientRect(); + const hudW = hudRect.width; + const hudH = hudRect.height; + + const docW = document.documentElement.scrollWidth; + const docH = document.documentElement.scrollHeight; + + const minX = 20; + const minY = 20; + const maxX = docW - hudW - 20; + const maxY = docH - hudH - 20; + + pos.x = Math.min(Math.max(x, minX), maxX); + pos.y = Math.min(Math.max(y, minY), maxY); + + log(`Location ${pos.x}, ${pos.y}`); } function onMouseUp(){ + log("Dragging done!"); dragging.value = false; } @@ -37,10 +60,9 @@ function toggleHUD() { collapsed.value = !collapsed.value; + log("HUD toggled!"); } - var logging = true; - function log(message){ if(logging) console.log(message); @@ -87,7 +109,7 @@