74 lines
1.6 KiB
Vue
74 lines
1.6 KiB
Vue
<script setup lang="ts">
|
|
const props = withDefaults(
|
|
defineProps<{
|
|
rect: [x: number, y: number, width: number, height: number];
|
|
opacity?: number;
|
|
}>(),
|
|
{
|
|
opacity: 1,
|
|
},
|
|
);
|
|
|
|
const cornerImage = useTemplateRef("cornerImage");
|
|
|
|
const ANIMATION_SPEED = 0.25;
|
|
|
|
let [currentX, currentY, currentWidth, currentHeight] = props.rect;
|
|
|
|
useRender((ctx) => {
|
|
if (!cornerImage.value) return;
|
|
|
|
const [targetX, targetY, targetWidth, targetHeight] = props.rect;
|
|
const dx = targetX - currentX;
|
|
const dy = targetY - currentY;
|
|
const dw = targetWidth - currentWidth;
|
|
const dh = targetHeight - currentHeight;
|
|
|
|
if (
|
|
Math.abs(dx) < 0.5 &&
|
|
Math.abs(dy) < 0.5 &&
|
|
Math.abs(dw) < 0.5 &&
|
|
Math.abs(dh) < 0.5
|
|
) {
|
|
[currentX, currentY, currentWidth, currentHeight] = props.rect;
|
|
} else {
|
|
currentX += dx * ANIMATION_SPEED;
|
|
currentY += dy * ANIMATION_SPEED;
|
|
currentWidth += dw * ANIMATION_SPEED;
|
|
currentHeight += dh * ANIMATION_SPEED;
|
|
}
|
|
|
|
const x = Math.floor(currentX);
|
|
const y = Math.floor(currentY);
|
|
const w = Math.floor(currentWidth);
|
|
const h = Math.floor(currentHeight);
|
|
|
|
ctx.globalAlpha = props.opacity;
|
|
|
|
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>
|