feat: generic button navigation

This commit is contained in:
2025-11-14 23:21:52 +01:00
parent 4abc233cb1
commit d54d52bff0
2 changed files with 198 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
<script setup lang="ts">
const props = withDefaults(
defineProps<{
x: number;
y: number;
width: number;
height: number;
animationSpeed?: number;
}>(),
{
animationSpeed: 0.25,
},
);
const cornerImage = useTemplateRef("cornerImage");
let currentX = props.x;
let currentY = props.y;
let currentWidth = props.width;
let currentHeight = props.height;
useRender((ctx) => {
if (!cornerImage.value) return;
const dx = props.x - currentX;
const dy = props.y - currentY;
const dw = props.width - currentWidth;
const dh = props.height - currentHeight;
if (
Math.abs(dx) < 0.5 &&
Math.abs(dy) < 0.5 &&
Math.abs(dw) < 0.5 &&
Math.abs(dh) < 0.5
) {
currentX = props.x;
currentY = props.y;
currentWidth = props.width;
currentHeight = props.height;
} else {
currentX += dx * props.animationSpeed;
currentY += dy * props.animationSpeed;
currentWidth += dw * props.animationSpeed;
currentHeight += dh * props.animationSpeed;
}
const x = Math.floor(currentX);
const y = Math.floor(currentY);
const w = Math.floor(currentWidth);
const h = Math.floor(currentHeight);
ctx.drawImage(cornerImage.value, x, y);
ctx.save();
ctx.scale(-1, 1);
ctx.drawImage(cornerImage.value, -(x + w), y);
ctx.restore();
ctx.save();
ctx.scale(1, -1);
ctx.drawImage(cornerImage.value, x, -(y + h));
ctx.restore();
ctx.save();
ctx.scale(-1, -1);
ctx.drawImage(cornerImage.value, -(x + w), -(y + h));
ctx.restore();
});
</script>
<template>
<img
ref="cornerImage"
src="/assets/images/home/bottom-screen/buttons/corner.png"
hidden
/>
</template>