From 32de4827428caab531b9cac8508666b91d746dcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Mon, 11 Jan 2021 22:17:29 +0100 Subject: [PATCH] support rotation, refactor VideoScroll.vue --- app/src/components/SVGContent.vue | 25 ++++++++++++++--- app/src/components/VideoScroll.vue | 45 +++++++++++++++++------------- app/src/utils.ts | 8 ++++++ 3 files changed, 54 insertions(+), 24 deletions(-) create mode 100644 app/src/utils.ts diff --git a/app/src/components/SVGContent.vue b/app/src/components/SVGContent.vue index 9c98d91..3abdb39 100644 --- a/app/src/components/SVGContent.vue +++ b/app/src/components/SVGContent.vue @@ -27,6 +27,7 @@ import createPanZoom, {PanZoom} from "panzoom"; import VideoScroll, {VideoScrollDef, VideoScrollDirection} from "@/components/VideoScroll.vue"; import AudioArea, {AudioAreaDef} from "@/components/AudioArea.vue"; import Stats from "stats.js"; +import {rotate} from "@/utils"; export default defineComponent({ name: "SVGContent", @@ -264,11 +265,27 @@ async function processScrolls(svg: XMLDocument): Promise { const preURL = fileFetch.url.replace(/\/files.lst$/, ""); const files = (await fileFetch.text()).split("\n").filter(Boolean).map((str) => `${preURL}/${str}`); + let x = el.x.baseVal.value; + let y = el.y.baseVal.value; + let w = el.width.baseVal.value; + let h = el.height.baseVal.value; + let angle = 0; + + const transform = el.attributes.getNamedItem("transform"); + const rotateResult = /rotate\((-?[0-9.]+)\)/.exec(transform?.value || ""); + if (rotateResult) { + angle = parseFloat(rotateResult[1]); + const [ncx, ncy] = rotate(x + w / 2, y + h / 2, 0, 0, angle); + x = ncx - w / 2; + y = ncy - h / 2; + } + return { - top: el.y.baseVal.value * ratio, - left: el.x.baseVal.value * ratio, - width: el.width.baseVal.value * ratio, - height: el.height.baseVal.value * ratio, + top: y * ratio, + left: x * ratio, + angle, + width: w * ratio, + height: h * ratio, direction: directionString as VideoScrollDirection, files }; diff --git a/app/src/components/VideoScroll.vue b/app/src/components/VideoScroll.vue index 308be49..0d9e204 100644 --- a/app/src/components/VideoScroll.vue +++ b/app/src/components/VideoScroll.vue @@ -5,22 +5,22 @@ :style="{ top: `${Math.round(definition.top)}px`, left: `${Math.round(definition.left)}px`, - width: isHorizontal(definition) ? `${Math.round(definition.width)}px` : 'auto', - height: isHorizontal(definition) ? 'auto' : `${Math.round(definition.height)}px`, + width: isHorizontal ? `${Math.round(definition.width)}px` : 'auto', + height: isHorizontal ? 'auto' : `${Math.round(definition.height)}px`, + rotate: `${definition.angle}deg` }" /> - @@ -28,6 +28,7 @@