From 14e4c0569dfa8a7764e567b8a771a8de51b80acf Mon Sep 17 00:00:00 2001 From: Kyle Geib Date: Mon, 7 Feb 2022 16:02:15 -0500 Subject: [PATCH] =?UTF-8?q?ISSUE-045=20-=20Venetian=20Blinds=20-=20Figured?= =?UTF-8?q?=20out=20some=20trig=20to=20get=20this=20to=20work.=20The=20ang?= =?UTF-8?q?le=20of=20the=20wipe=20is=20now=20customizable=20and=20no=20lon?= =?UTF-8?q?ger=20limited=20to=2045=C2=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VenetianBlindsTransition.tsx | 35 +++++++++++-------- .../VenetianBlindsWorkspace.tsx | 16 +++++++-- src/types/style.d.ts | 5 +++ src/utils/styling.ts | 32 +++++++++-------- 4 files changed, 56 insertions(+), 32 deletions(-) diff --git a/src/components/BroadcastGraphics/Common/VenetianBlindsTransition/VenetianBlindsTransition.tsx b/src/components/BroadcastGraphics/Common/VenetianBlindsTransition/VenetianBlindsTransition.tsx index 7565987..b8cb17b 100644 --- a/src/components/BroadcastGraphics/Common/VenetianBlindsTransition/VenetianBlindsTransition.tsx +++ b/src/components/BroadcastGraphics/Common/VenetianBlindsTransition/VenetianBlindsTransition.tsx @@ -1,53 +1,60 @@ import { useState } from "react"; -import { useSpring, animated } from "@react-spring/web"; +import { useSpring, animated, config } from "@react-spring/web"; import useMeasure from "react-use-measure"; import { VenetianBlindsFilter } from "./styles"; -import { wipe45DegClip } from "../../../../utils/styling"; +import { wipeCustomDegClip } from "../../../../utils/styling"; +import { Corner } from "../../../../types/style"; type VenetianBlindsTransitionProps = { - color: string, + blindsColor: string, + degrees: number, + duration: number, + wipeStartingCorner: Corner, }; export const VenetianBlindsTransition = ( - { color, children }: React.PropsWithChildren, + { + blindsColor, + degrees, + duration, + wipeStartingCorner, + children, + }: React.PropsWithChildren, ) => { const [childRef, { height: childHeight, width: childWidth, }] = useMeasure(); - const deg = -45; const [state, toggle] = useState(true); const { x } = useSpring({ from: { x: 0 }, x: state ? 1 : 0, - config: { duration: 300 }, + config: { duration }, }); return ( -
{ - console.log(!state); - toggle(!state); - }}> +
toggle(!state)}> { - const [a1, a2, b1, b2, c1, c2] = wipe45DegClip( + const [a1, a2, b1, b2, c1, c2] = wipeCustomDegClip( childWidth, childHeight, x, - "bottomRight", + wipeStartingCorner, + degrees, ); return `polygon(${a1}px ${a2}px, ${b1}px ${b2}px, ${c1}px ${c2}px)`; }), }} > {children} diff --git a/src/components/Workspaces/CustomWorkSpaces/VenetianBlindsWorkspace/VenetianBlindsWorkspace.tsx b/src/components/Workspaces/CustomWorkSpaces/VenetianBlindsWorkspace/VenetianBlindsWorkspace.tsx index 87729bf..15e3c67 100644 --- a/src/components/Workspaces/CustomWorkSpaces/VenetianBlindsWorkspace/VenetianBlindsWorkspace.tsx +++ b/src/components/Workspaces/CustomWorkSpaces/VenetianBlindsWorkspace/VenetianBlindsWorkspace.tsx @@ -9,20 +9,30 @@ import { BasicBlock } from "../styles"; export function VenetianBlindsWorkspace() { const { prototypeState } = useSelector(workspaceSelector); - const bgColor = prototypeState?.venetianTransition?.showBG + const bgColor = prototypeState?.venetianTransition?.showBG ?? true ? "black" : "transparent"; return ( {prototypeState?.venetianTransition?.mode === "driverPortrait" ? ( - + ) : ( - + )} diff --git a/src/types/style.d.ts b/src/types/style.d.ts index 42a10b8..7fa6fcc 100644 --- a/src/types/style.d.ts +++ b/src/types/style.d.ts @@ -22,3 +22,8 @@ export interface Placement { bottom?: string; left?: string; } + +/** + * Useful to initialize movements from. + */ +export type Corner = "topLeft" | "topRight" | "bottomRight" | "bottomLeft"; diff --git a/src/utils/styling.ts b/src/utils/styling.ts index a843421..d94b93e 100644 --- a/src/utils/styling.ts +++ b/src/utils/styling.ts @@ -1,6 +1,7 @@ import { css }from "styled-components"; +import { clamp } from "lodash"; -import { Fraction, Placement, Px } from "../types/style"; +import { Corner, Fraction, Placement, Px } from "../types/style"; export function placementStyleRules(pos: Placement) { return css` @@ -15,46 +16,47 @@ export function placementStyleRules(pos: Placement) { /** * Provides the x, y coordinates of a three point polygon for use in a clip-path * mask. By taking a fraction to indicate the progress through the animation it - * will return the six coordinates that will generate a 45 degree wipe effect. + * will return the six coordinates that will generate a wipe effect. * @param width element width in pixels * @param height element height in pixels * @param progress fraction from 0 to 1 * @param startingCorner Which corner the wipe originates from + * @param degrees The angle in degrees of the wipe * @returns Array of six numbers representing pixel values of the clip-path */ -export function wipe45DegClip( +export function wipeCustomDegClip( width: Px, height: Px, progress: Fraction, - startingCorner: "topLeft" | "topRight" | "bottomRight" | "bottomLeft", + startingCorner: Corner, + degrees: number, ): [Px, Px, Px, Px, Px, Px] { - // Long edge multiplied by 2. - const l = Math.max(width, height) * 2; + const tangent = Math.tan(clamp(degrees, 0.01, 90) * Math.PI / 180); - switch(startingCorner) { + switch (startingCorner) { case "topLeft": return [ 0, 0, - l * progress, 0, - 0, l * progress, + (width + height / tangent) * progress, 0, + 0, (height + width * tangent) * progress , ]; case "topRight": return [ width, 0, - width, l * progress, - width - l * progress, 0, + width, (height + width * tangent) * progress, + width - (width + height / tangent) * progress, 0, ]; case "bottomRight": return [ width, height, - width, height - l * progress, - width - l * progress, height, + width, height - (height + width * tangent) * progress, + width - (width + height / tangent) * progress, height, ]; case "bottomLeft": return [ 0, height, - 0, height - l * progress, - l * progress, height, + 0, height - (height + width * tangent) * progress, + (width + height / tangent) * progress, height, ]; } }