From d083df7245f219d758dbb48354e55d9d4715c339 Mon Sep 17 00:00:00 2001 From: Kyle Geib Date: Mon, 14 Mar 2022 18:23:18 -0500 Subject: [PATCH 1/7] ISSUE-053 - Have worked out the scaled video feed element. Didn't have to do anything to position the element, which made me pretty happy. I assumed I'd have to do some annoying amount of finagling to get it to position correctly in the frame. It just worked. Lucky me. --- .../Broadcast/VideoFeed/VideoFeed.tsx | 41 +++++++++++++++++-- src/components/Broadcast/VideoFeed/styles.ts | 24 +++++++++++ src/shared/theme.ts | 4 ++ src/utils/styling.ts | 34 +++++++++++++++ 4 files changed, 99 insertions(+), 4 deletions(-) diff --git a/src/components/Broadcast/VideoFeed/VideoFeed.tsx b/src/components/Broadcast/VideoFeed/VideoFeed.tsx index 7de18c9..e9d5908 100644 --- a/src/components/Broadcast/VideoFeed/VideoFeed.tsx +++ b/src/components/Broadcast/VideoFeed/VideoFeed.tsx @@ -1,9 +1,42 @@ -import { VideoFeedFrame, BackgroundImageDiv } from "./styles"; +import useMeasure from "react-use-measure"; + +import { calculateFitSize, calculateScale } from "../../../utils/styling"; +import { theme } from "../../../shared/theme"; + +import { VideoFeedFrame, BackgroundImageDiv, DimensionsSpan, BroadcastLayout } from "./styles"; +import { MockupBlock } from "../../Common/MockupBlock.styled"; import bg from "../../../public/images/misc/bg-standin.jpg"; export default function VideoFeed() { - return - - ; + const [frameRef, { + height: frameHeight, + width: frameWidth, + }] = useMeasure(); + + const { + dimensionsWidthPx: broadcastWidth, + dimensionsHeightPx: broadcastHeight, + } = theme.broadcast; + + const [layoutWidth, layoutHeight] = calculateFitSize(frameWidth, frameHeight, + [broadcastWidth, broadcastHeight]); + const layoutScale = calculateScale(layoutWidth, layoutHeight, + [broadcastWidth, broadcastHeight]); + + return ( + + + {Math.floor(frameWidth)} x {Math.floor(frameHeight)}px + + + + + + + ); } diff --git a/src/components/Broadcast/VideoFeed/styles.ts b/src/components/Broadcast/VideoFeed/styles.ts index ef4e844..835d68e 100644 --- a/src/components/Broadcast/VideoFeed/styles.ts +++ b/src/components/Broadcast/VideoFeed/styles.ts @@ -1,9 +1,12 @@ import styled, { css } from "styled-components/macro"; +import { Fraction, Px } from "../../../types/style"; + type VideoFeedFrameProps = { centered?: boolean, }; export const VideoFeedFrame = styled.div` + position: relative; height: 100%; width: 100%; background-color: ${p => p.theme.colors.videoFrameBG}; @@ -20,6 +23,19 @@ export const VideoFeedFrame = styled.div` `} `; +type BroadcastLayoutProps = { + height: Px, + width: Px, + scale: Fraction, +}; +export const BroadcastLayout = styled.div.attrs(({ + height, + width, + scale, +}) => ({ style: { height, width, transform: `scale(${scale})` } }))` + position: absolute; +`; + export const BackgroundImage = styled.img` height: 100%; max-width: 100%; @@ -37,3 +53,11 @@ export const BackgroundImageDiv = styled.div` background-repeat: no-repeat; background-position: 0% 50%; `; + +export const DimensionsSpan = styled.span` + position: absolute; + top: 5px; + right: 10px; + color: ${p => p.theme.colors.textWhite}; + font-family: ${p => p.theme.fonts.f1Regular}; +`; diff --git a/src/shared/theme.ts b/src/shared/theme.ts index 5e6536e..fa5c275 100644 --- a/src/shared/theme.ts +++ b/src/shared/theme.ts @@ -102,6 +102,10 @@ export const theme = { medRadius: "11px", smRadius: "7px", }, + broadcast: { + dimensionsWidthPx: 1920, + dimensionsHeightPx: 1080, + }, }; export type MainThemeProps = ThemeProps; diff --git a/src/utils/styling.ts b/src/utils/styling.ts index 82f833c..e919523 100644 --- a/src/utils/styling.ts +++ b/src/utils/styling.ts @@ -182,3 +182,37 @@ export function formatTime(time: Seconds, limit: Seconds) { const seconds = time % 60; return `${minutes}:${seconds.toFixed(3).padStart(6, "0")}`; } + +/** + * Given a frame to work within, this will return the dimensions of an element + * that will best fit into this given frame with a specific ratio. + * @param frameWidth Width of the working frame in pixels + * @param frameHeight Width of the working frame in pixels + * @param ratioWH Ratio in the form of [width, height] + * @returns Dimensions [width, height] of a fitted element in pixels + */ +export function calculateFitSize(frameWidth: Px, frameHeight: Px, ratioWH: [number, number]): [Px, Px] { + const [w, h] = ratioWH; + let scaledWidth = frameWidth; + let scaledHeight = frameHeight; + + if ((frameWidth / frameHeight) > (w / h)) { // Wider frame. + scaledWidth = frameHeight / h * w; + } else if ((frameWidth / frameHeight) < (w / h)) { // Narrower frame. + scaledHeight = frameWidth / w * h; + } + return [scaledWidth, scaledHeight]; +} + +/** + * Given a fit element's dimensions in pixels this take the provided reference + * width and height defined in pixels and return the scale the fitted element + * is currently at. + * @param fitWidth Width of the fitted element in pixels + * @param fitHeight Height of the fitted element in pixels + * @param referenceWH Dimensions that we need to be scaled to [width, height] in pixels + * @returns Scale of the fitted element as a fraction + */ +export function calculateScale(fitWidth: Px, fitHeight: Px, referenceWH: [Px, Px]): Fraction { + return (fitWidth / referenceWH[0] + fitHeight / referenceWH[1]) / 2; +} From b48579ac54956ee8f8f09cd5d1080f3921743c57 Mon Sep 17 00:00:00 2001 From: Kyle Geib Date: Tue, 15 Mar 2022 13:14:20 -0500 Subject: [PATCH 2/7] ISSUE-053 - Placed TimingBoard into the video feed element. But the scaling is messing with the clip path because the clip path values do not follow the scale correctly. The issue is, say our scale is 50%. A PositionFlag on the TimingBoard is normally 32x32px in size. That means that the size of the actual PositionFlag while scaled is 16x16. The WipeTransition component takes the effective size of its child element using the useMeasure() hook. So it sees the size is 16x16, thus, when the wipe is set to visible its clip dimensions on the opposite and adjacent points of the triangle are 16px away from origin. But because we're scaled at 50% that clip path effectively becomes 8px. The clip path is doubly scaled. As a result I'm seeing white squares in the corner of the PositionFlag component. I think I might be able to solve this by using simple division to express the values of the clip path in percentages. Or I'll find a way to avoid the double scaling issue. --- .../Chyrons/ChyronsDirectorControls.tsx | 2 +- src/components/Broadcast/Layout/Layout.tsx | 5 ++--- src/components/Broadcast/VideoFeed/VideoFeed.tsx | 8 ++------ .../BroadcastGraphics/TimingBoard/TimingBoard.tsx | 5 ++++- .../BroadcastGraphics/TimingBoard/styles.ts | 9 ++++++++- src/domain/data/broadcastGraphics.ts | 12 +++++++----- .../broadcast/graphics/broadcastGraphicsSlice.ts | 4 ++-- src/types/state.ts | 10 ++-------- 8 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/components/Broadcast/BroadcastDirectorUI/Chyrons/ChyronsDirectorControls.tsx b/src/components/Broadcast/BroadcastDirectorUI/Chyrons/ChyronsDirectorControls.tsx index 5c5235e..2bb577b 100644 --- a/src/components/Broadcast/BroadcastDirectorUI/Chyrons/ChyronsDirectorControls.tsx +++ b/src/components/Broadcast/BroadcastDirectorUI/Chyrons/ChyronsDirectorControls.tsx @@ -71,7 +71,7 @@ export function ChyronsDirectorControls() { } const newChyrons: BGChyrons = { openState: 0, - relativePos: { top: "0", right: "0", bottom: "0", left: "0" }, + placement: { top: "0", right: "0", bottom: "0", left: "0" }, mode: chyronMode, subMode: chyronSubMode, driver: { diff --git a/src/components/Broadcast/Layout/Layout.tsx b/src/components/Broadcast/Layout/Layout.tsx index 1e1f818..13c0a07 100644 --- a/src/components/Broadcast/Layout/Layout.tsx +++ b/src/components/Broadcast/Layout/Layout.tsx @@ -1,6 +1,7 @@ import { MockupBlock } from "../../Common/MockupBlock.styled"; import VideoFeed from "../VideoFeed/VideoFeed"; import { LayoutGrid, LayoutGridItem } from "../../Common/LayoutGrid.styled"; +import { TimingTowerPrototypeControls } from "../../Workspaces/PrototypingControls/TimingTowerPrototype"; type LayoutProps = { headerHeight?: number, @@ -33,9 +34,7 @@ export function Layout({ headerHeight }: LayoutProps) { - Broadcast Director UI + ); diff --git a/src/components/Broadcast/VideoFeed/VideoFeed.tsx b/src/components/Broadcast/VideoFeed/VideoFeed.tsx index e9d5908..ee79789 100644 --- a/src/components/Broadcast/VideoFeed/VideoFeed.tsx +++ b/src/components/Broadcast/VideoFeed/VideoFeed.tsx @@ -4,7 +4,7 @@ import { calculateFitSize, calculateScale } from "../../../utils/styling"; import { theme } from "../../../shared/theme"; import { VideoFeedFrame, BackgroundImageDiv, DimensionsSpan, BroadcastLayout } from "./styles"; -import { MockupBlock } from "../../Common/MockupBlock.styled"; +import { TimingBoard } from "../../BroadcastGraphics/TimingBoard"; import bg from "../../../public/images/misc/bg-standin.jpg"; @@ -31,11 +31,7 @@ export default function VideoFeed() { - + ); diff --git a/src/components/BroadcastGraphics/TimingBoard/TimingBoard.tsx b/src/components/BroadcastGraphics/TimingBoard/TimingBoard.tsx index 0164ed7..1cd86ac 100644 --- a/src/components/BroadcastGraphics/TimingBoard/TimingBoard.tsx +++ b/src/components/BroadcastGraphics/TimingBoard/TimingBoard.tsx @@ -5,14 +5,17 @@ import { workspaceSelector } from "../../../features/workspace/workspaceSelector import { TimingBoardLayout } from "./styles"; import { TimingTower } from "./TimingTower"; import { StatusIndicator } from "./StatusIndicator"; +import { broadcastGraphicsSelector } from "../../../features/broadcast/graphics/broadcastGraphicsSelector"; type TimingBoardProps = { debug?: boolean, }; export function TimingBoard({ debug = false }: TimingBoardProps) { const { debugDurationMultiplier } = useSelector(workspaceSelector); + const { timingBoard } = useSelector(broadcastGraphicsSelector); + return ( - + diff --git a/src/components/BroadcastGraphics/TimingBoard/styles.ts b/src/components/BroadcastGraphics/TimingBoard/styles.ts index 347222d..a5802ed 100644 --- a/src/components/BroadcastGraphics/TimingBoard/styles.ts +++ b/src/components/BroadcastGraphics/TimingBoard/styles.ts @@ -1,7 +1,14 @@ import styled from "styled-components/macro"; -export const TimingBoardLayout = styled.div` +import { Placement } from "../../../types/style"; +import { placementStyleRules } from "../../../utils/styling"; + +type TimingBoardLayoutProps = { + placement: Placement, +}; +export const TimingBoardLayout = styled.div` position: relative; + ${({ placement }) => placementStyleRules(placement)} display: flex; flex-direction: column; diff --git a/src/domain/data/broadcastGraphics.ts b/src/domain/data/broadcastGraphics.ts index 05940ce..ed56aa0 100644 --- a/src/domain/data/broadcastGraphics.ts +++ b/src/domain/data/broadcastGraphics.ts @@ -1,17 +1,19 @@ import { keys } from "lodash"; -import { BGChyronSubMode, BGChyronMode, BGRelativePos, FlagMode } from "../../types/state"; + +import { BGChyronSubMode, BGChyronMode, FlagMode } from "../../types/state"; +import { Placement } from "../../types/style"; // Chyrons Section const chyronsData: { [mode: BGChyronMode]: { - relativePos: BGRelativePos, + placement: Placement, subModes: { [subMode: BGChyronSubMode]: Record, }, }, } = { driver: { - relativePos: { top: "0", right: "0", bottom: "0", left: "0" }, + placement: { top: "0", right: "0", bottom: "0", left: "0" }, subModes: { medium: { width: 582, height: 72 }, large: { width: 638, height: 98 }, @@ -25,8 +27,8 @@ export function getChyronModesList(): Array { return keys(chyronsData); } -export function getChyronRelativePos(mode: BGChyronMode): BGRelativePos { - return chyronsData[mode]?.relativePos +export function getChyronRelativePos(mode: BGChyronMode): Placement { + return chyronsData[mode]?.placement ?? { top: "0", right: "0", bottom: "0", left: "0" }; } diff --git a/src/features/broadcast/graphics/broadcastGraphicsSlice.ts b/src/features/broadcast/graphics/broadcastGraphicsSlice.ts index ffcbc5f..5e41089 100644 --- a/src/features/broadcast/graphics/broadcastGraphicsSlice.ts +++ b/src/features/broadcast/graphics/broadcastGraphicsSlice.ts @@ -13,8 +13,8 @@ import { const initialState: RootState["broadcastGraphics"] = { chyrons: null, timingBoard: { - relativePos: {}, - openState: 0, + placement: { top: "54px", left: "96px" }, + openState: 1, statusIndicator: { mode: BGStatusIndicatorModes.LapNarrow, }, diff --git a/src/types/state.ts b/src/types/state.ts index ad83a28..a91b509 100644 --- a/src/types/state.ts +++ b/src/types/state.ts @@ -1,5 +1,5 @@ import { Meters, Milliseconds, Optional } from "./util"; -import { Corner, Fraction } from "./style"; +import { Corner, Fraction, Placement } from "./style"; export interface RootState { pageDimensions: PageDimensions; @@ -253,14 +253,8 @@ export interface BroadcastDirector { } // Broadcast Graphics -export interface BGRelativePos { - top?: string; - right?: string; - bottom?: string; - left?: string; -} export interface BGBaseState { - relativePos: BGRelativePos; + placement: Placement; openState: OpenState; } /** From a11f5b8eb6807f23e3903547371c78c891565597 Mon Sep 17 00:00:00 2001 From: Kyle Geib Date: Tue, 15 Mar 2022 14:13:29 -0500 Subject: [PATCH 3/7] ISSUE-053 - To avoid messing with code that already works I dropped in a function-function that will convert pixel values to percent values. This fix adds a little bit of overhead, I guess, but it works without munging up any clean looking code. --- src/components/Broadcast/Layout/Layout.tsx | 4 +- .../Chyrons/Driver/ChyronDriver.tsx | 2 +- .../Common/WipeTransition/WipeTransition.tsx | 2 +- .../TimingTower/TimingTowerRow.tsx | 2 +- src/utils/styling.ts | 94 ++++++++++++------- 5 files changed, 64 insertions(+), 40 deletions(-) diff --git a/src/components/Broadcast/Layout/Layout.tsx b/src/components/Broadcast/Layout/Layout.tsx index 13c0a07..e9d5489 100644 --- a/src/components/Broadcast/Layout/Layout.tsx +++ b/src/components/Broadcast/Layout/Layout.tsx @@ -17,7 +17,7 @@ export function Layout({ headerHeight }: LayoutProps) { >Timing Board UI - + @@ -33,7 +33,7 @@ export function Layout({ headerHeight }: LayoutProps) { >Race Director UI - + diff --git a/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx b/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx index 888442e..b660457 100644 --- a/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx +++ b/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx @@ -98,7 +98,7 @@ export function ChyronDriver({ progress, 5, ); - return `polygon(${coordinates.map(([x, y]) => `${x}px ${y}px`).join(", ")})`; + return `polygon(${coordinates.map(([x, y]) => `${x}% ${y}%`).join(", ")})`; }), }} /> diff --git a/src/components/BroadcastGraphics/Common/WipeTransition/WipeTransition.tsx b/src/components/BroadcastGraphics/Common/WipeTransition/WipeTransition.tsx index 7f18d94..ac81376 100644 --- a/src/components/BroadcastGraphics/Common/WipeTransition/WipeTransition.tsx +++ b/src/components/BroadcastGraphics/Common/WipeTransition/WipeTransition.tsx @@ -64,7 +64,7 @@ export function WipeTransition({ startingCorner, angle, ); - return `polygon(${coordinates.map(([x, y]) => `${x}px ${y}px`).join(", ")})`; + return `polygon(${coordinates.map(([x, y]) => `${x}% ${y}%`).join(", ")})`; }), }} ref={childRef} diff --git a/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTowerRow.tsx b/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTowerRow.tsx index d8c7772..71ff63a 100644 --- a/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTowerRow.tsx +++ b/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTowerRow.tsx @@ -305,7 +305,7 @@ export function TimingTowerRow({ 3, 3, ); - return `polygon(${coordinates.map(([x, y]) => `${x}px ${y}px`).join(", ")})`; + return `polygon(${coordinates.map(([x, y]) => `${x}% ${y}%`).join(", ")})`; }), }} /> diff --git a/src/utils/styling.ts b/src/utils/styling.ts index e919523..bbcbcd8 100644 --- a/src/utils/styling.ts +++ b/src/utils/styling.ts @@ -1,7 +1,7 @@ import { css }from "styled-components/macro"; import { clamp } from "lodash"; -import { Corner, Fraction, Placement, Px, TransitionArgs } from "../types/style"; +import { Corner, Fraction, Percent, Placement, Px, TransitionArgs } from "../types/style"; import { Seconds } from "../types/util"; export function placementStyleRules(pos: Placement) { @@ -14,6 +14,21 @@ export function placementStyleRules(pos: Placement) { } +/** + * Call to create a function that can be re-used to generate a pair of percent + * values to use on a clip-path. + * This was necessary to deal with double-applied scaling issues when using + * element measurement hooks. + * @param width the width of the element to be clipped in pixels + * @param height the height of the element to be clipped in pixels + * @returns A function that can be used to convert pixel values into percent values + */ +const clipConvertToPercent = (width: Px, height: Px) => + (coords: [Px, Px]): [Percent, Percent] => [ + coords[0] / width * 100, + coords[1] / height * 100, + ]; + /** * 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 @@ -23,7 +38,7 @@ export function placementStyleRules(pos: Placement) { * @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 + * @returns Array of three pairs of percentages to the coordinates of the clip-path */ export function wipeCustomDegClip( width: Px, @@ -31,33 +46,34 @@ export function wipeCustomDegClip( progress: Fraction, startingCorner: Corner, degrees: number, -): [[Px, Px], [Px, Px], [Px, Px]] { +): [[Percent, Percent], [Percent, Percent], [Percent, Percent]] { const tangent = Math.tan(clamp(degrees, 0.01, 90) * Math.PI / 180); + const convert = clipConvertToPercent(width, height); switch (startingCorner) { case "topLeft": return [ - [0, 0], - [(width + height / tangent) * progress, 0], - [0, (height + width * tangent) * progress ], + convert([0, 0]), + convert([(width + height / tangent) * progress, 0]), + convert([0, (height + width * tangent) * progress ]), ]; case "topRight": return [ - [width, 0], - [width, (height + width * tangent) * progress], - [width - (width + height / tangent) * progress, 0], + convert([width, 0]), + convert([width, (height + width * tangent) * progress]), + convert([width - (width + height / tangent) * progress, 0]), ]; case "bottomRight": return [ - [width, height], - [width, height - (height + width * tangent) * progress], - [width - (width + height / tangent) * progress, height], + convert([width, height]), + convert([width, height - (height + width * tangent) * progress]), + convert([width - (width + height / tangent) * progress, height]), ]; case "bottomLeft": return [ - [0, height], - [0, height - (height + width * tangent) * progress], - [(width + height / tangent) * progress, height], + convert([0, height]), + convert([0, height - (height + width * tangent) * progress]), + convert([(width + height / tangent) * progress, height]), ]; } } @@ -114,7 +130,7 @@ export function commonDirectionalTransition( * @param progress fraction from 0 to 1 * @param outlineThickness the expected max width of the outline * @param interiorThickness the expected max width of the outline internally - * @returns + * @returns Array of six pairs of percentages to the coordinates of the clip-path */ export function outlineClipPath( width: Px, @@ -122,45 +138,53 @@ export function outlineClipPath( progress: Fraction, outlineThickness: Px, interiorThickness: Px = 0, -): [[Px, Px], [Px, Px], [Px, Px], [Px, Px], [Px, Px], [Px, Px]] { +): [ + [Percent, Percent], + [Percent, Percent], + [Percent, Percent], + [Percent, Percent], + [Percent, Percent], + [Percent, Percent], +] { const travelDistance = width * 2 + height; const pt1End = width / travelDistance; const pt2End = (width + height) / travelDistance; + const convert = clipConvertToPercent(width, height); // Part 1: Reveal the bottom line. if (progress <= pt1End) { const x = width * progress / pt1End; return [ - [0, height - interiorThickness], - [0, height - interiorThickness], - [0, height - interiorThickness], - [x, height - interiorThickness], - [x, height + outlineThickness], - [0, height + outlineThickness], + convert([0, height - interiorThickness]), + convert([0, height - interiorThickness]), + convert([0, height - interiorThickness]), + convert([x, height - interiorThickness]), + convert([x, height + outlineThickness]), + convert([0, height + outlineThickness]), ]; // Part 2: Reveal the right line. } else if (progress > pt1End && progress <= pt2End) { const y = height - (height + outlineThickness) * ((progress - pt1End) / (pt2End - pt1End)); return [ - [0, height - interiorThickness], - [width - Math.max(10, interiorThickness), height - interiorThickness], - [width - interiorThickness, y], - [width + outlineThickness, y], - [width + outlineThickness, height + outlineThickness], - [0, height + outlineThickness], + convert([0, height - interiorThickness]), + convert([width - Math.max(10, interiorThickness), height - interiorThickness]), + convert([width - interiorThickness, y]), + convert([width + outlineThickness, y]), + convert([width + outlineThickness, height + outlineThickness]), + convert([0, height + outlineThickness]), ]; // Part 3: Reveal the top line. } else { const x = width - width * ((progress - pt2End) / (1 - pt2End)); return [ - [0, height - interiorThickness], - [x - Math.max(10, interiorThickness), height - interiorThickness], - [x - interiorThickness, -outlineThickness], - [width + outlineThickness, -outlineThickness], - [width + outlineThickness, height + outlineThickness], - [0, height + outlineThickness], + convert([0, height - interiorThickness]), + convert([x - Math.max(10, interiorThickness), height - interiorThickness]), + convert([x - interiorThickness, -outlineThickness]), + convert([width + outlineThickness, -outlineThickness]), + convert([width + outlineThickness, height + outlineThickness]), + convert([0, height + outlineThickness]), ]; } } From 47ae67a5a8b4c4c9fee6622ecba32579e790addd Mon Sep 17 00:00:00 2001 From: Kyle Geib Date: Tue, 15 Mar 2022 14:16:18 -0500 Subject: [PATCH 4/7] ISSUE-053 - Minor improvement to clipConvertToPercent(). --- src/utils/styling.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/utils/styling.ts b/src/utils/styling.ts index bbcbcd8..d0a616b 100644 --- a/src/utils/styling.ts +++ b/src/utils/styling.ts @@ -24,10 +24,7 @@ export function placementStyleRules(pos: Placement) { * @returns A function that can be used to convert pixel values into percent values */ const clipConvertToPercent = (width: Px, height: Px) => - (coords: [Px, Px]): [Percent, Percent] => [ - coords[0] / width * 100, - coords[1] / height * 100, - ]; + ([x, y]: [Px, Px]): [Percent, Percent] => [x / width * 100, y / height * 100]; /** * Provides the x, y coordinates of a three point polygon for use in a clip-path From b7d1b23dffe0679964ab99787bc5f06ecf74e3fe Mon Sep 17 00:00:00 2001 From: Kyle Geib Date: Wed, 16 Mar 2022 17:25:12 -0400 Subject: [PATCH 5/7] ISSUE-053 - Added white F1 logo svg. Minimized red F1 logo svg. --- src/public/images/logos/f1-logo-red.svg | 13 +------------ src/public/images/logos/f1-logo-white.svg | 1 + 2 files changed, 2 insertions(+), 12 deletions(-) create mode 100755 src/public/images/logos/f1-logo-white.svg diff --git a/src/public/images/logos/f1-logo-red.svg b/src/public/images/logos/f1-logo-red.svg index e29d0ad..04ea67e 100644 --- a/src/public/images/logos/f1-logo-red.svg +++ b/src/public/images/logos/f1-logo-red.svg @@ -1,12 +1 @@ - - - - - - - - + \ No newline at end of file diff --git a/src/public/images/logos/f1-logo-white.svg b/src/public/images/logos/f1-logo-white.svg new file mode 100755 index 0000000..5635e08 --- /dev/null +++ b/src/public/images/logos/f1-logo-white.svg @@ -0,0 +1 @@ + \ No newline at end of file From 58da0e4895fffc1bed3868fa7c121be695207a3a Mon Sep 17 00:00:00 2001 From: Kyle Geib Date: Thu, 17 Mar 2022 08:56:55 -0400 Subject: [PATCH 6/7] ISSUE-053 - Placed Chyrons on video feed. Adjusted the method that placement is determined. It didn't make much sense to define Placement in state, so I've moved it to the central theme object instead. I also took the time to support +10 laps and minutes with a special xScale setting for the TimingTowerRows. --- .../Chyrons/ChyronsDirectorControls.tsx | 1 - src/components/Broadcast/Layout/Layout.tsx | 14 +++++-- .../Broadcast/VideoFeed/VideoFeed.tsx | 14 +++++-- src/components/Broadcast/VideoFeed/styles.ts | 13 ++++++- .../Chyrons/Container/ChyronContainer.tsx | 37 ++++++++++--------- .../Chyrons/Container/styles.ts | 12 ++++++ .../TimingBoard/TimingBoard.tsx | 8 ++-- .../TimingTower/TimingTowerRow.tsx | 7 ++++ .../TimingBoard/TimingTower/styles.ts | 1 + .../BroadcastGraphics/TimingBoard/styles.ts | 2 +- .../graphics/broadcastGraphicsSlice.ts | 3 +- src/shared/theme.ts | 6 +++ src/types/state.ts | 3 +- 13 files changed, 86 insertions(+), 35 deletions(-) diff --git a/src/components/Broadcast/BroadcastDirectorUI/Chyrons/ChyronsDirectorControls.tsx b/src/components/Broadcast/BroadcastDirectorUI/Chyrons/ChyronsDirectorControls.tsx index 2bb577b..6e4e87f 100644 --- a/src/components/Broadcast/BroadcastDirectorUI/Chyrons/ChyronsDirectorControls.tsx +++ b/src/components/Broadcast/BroadcastDirectorUI/Chyrons/ChyronsDirectorControls.tsx @@ -71,7 +71,6 @@ export function ChyronsDirectorControls() { } const newChyrons: BGChyrons = { openState: 0, - placement: { top: "0", right: "0", bottom: "0", left: "0" }, mode: chyronMode, subMode: chyronSubMode, driver: { diff --git a/src/components/Broadcast/Layout/Layout.tsx b/src/components/Broadcast/Layout/Layout.tsx index e9d5489..fb7fe3f 100644 --- a/src/components/Broadcast/Layout/Layout.tsx +++ b/src/components/Broadcast/Layout/Layout.tsx @@ -1,7 +1,10 @@ -import { MockupBlock } from "../../Common/MockupBlock.styled"; +import { PadBox } from "@bedrock-layout/padbox"; + import VideoFeed from "../VideoFeed/VideoFeed"; +import { MockupBlock } from "../../Common/MockupBlock.styled"; import { LayoutGrid, LayoutGridItem } from "../../Common/LayoutGrid.styled"; import { TimingTowerPrototypeControls } from "../../Workspaces/PrototypingControls/TimingTowerPrototype"; +import { ChyronsDirectorControls } from "../BroadcastDirectorUI/Chyrons"; type LayoutProps = { headerHeight?: number, @@ -17,7 +20,7 @@ export function Layout({ headerHeight }: LayoutProps) { >Timing Board UI - + @@ -33,8 +36,11 @@ export function Layout({ headerHeight }: LayoutProps) { >Race Director UI - - + + + + + ); diff --git a/src/components/Broadcast/VideoFeed/VideoFeed.tsx b/src/components/Broadcast/VideoFeed/VideoFeed.tsx index ee79789..c8fd11c 100644 --- a/src/components/Broadcast/VideoFeed/VideoFeed.tsx +++ b/src/components/Broadcast/VideoFeed/VideoFeed.tsx @@ -3,10 +3,12 @@ import useMeasure from "react-use-measure"; import { calculateFitSize, calculateScale } from "../../../utils/styling"; import { theme } from "../../../shared/theme"; -import { VideoFeedFrame, BackgroundImageDiv, DimensionsSpan, BroadcastLayout } from "./styles"; +import { VideoFeedFrame, BackgroundImageDiv, DimensionsSpan, BroadcastLayout, Logo } from "./styles"; import { TimingBoard } from "../../BroadcastGraphics/TimingBoard"; +import { ChyronContainer } from "../../BroadcastGraphics/Chyrons/Container"; import bg from "../../../public/images/misc/bg-standin.jpg"; +import f1Logo from "../../../public/images/logos/f1-logo-white.svg"; export default function VideoFeed() { const [frameRef, { @@ -17,6 +19,8 @@ export default function VideoFeed() { const { dimensionsWidthPx: broadcastWidth, dimensionsHeightPx: broadcastHeight, + logoHeightPx, + placement, } = theme.broadcast; const [layoutWidth, layoutHeight] = calculateFitSize(frameWidth, frameHeight, @@ -27,11 +31,15 @@ export default function VideoFeed() { return ( - {Math.floor(frameWidth)} x {Math.floor(frameHeight)}px + Frame: {Math.floor(frameWidth)} x {Math.floor(frameHeight)}px +
+ Scaled: {Math.floor(layoutWidth)} x {Math.floor(layoutHeight)}px ({(layoutScale * 100).toFixed(1)}%)
- + + +
); diff --git a/src/components/Broadcast/VideoFeed/styles.ts b/src/components/Broadcast/VideoFeed/styles.ts index 835d68e..734f2b1 100644 --- a/src/components/Broadcast/VideoFeed/styles.ts +++ b/src/components/Broadcast/VideoFeed/styles.ts @@ -1,6 +1,7 @@ import styled, { css } from "styled-components/macro"; -import { Fraction, Px } from "../../../types/style"; +import { Fraction, Placement, Px } from "../../../types/style"; +import { placementStyleRules } from "../../../utils/styling"; type VideoFeedFrameProps = { centered?: boolean, @@ -61,3 +62,13 @@ export const DimensionsSpan = styled.span` color: ${p => p.theme.colors.textWhite}; font-family: ${p => p.theme.fonts.f1Regular}; `; + +type LogoProps = { + placement: Placement, + height: Px, +}; +export const Logo = styled.img` + position: absolute; + ${({ placement }) => placementStyleRules(placement)} + height: ${({ height }) => height}px; +`; diff --git a/src/components/BroadcastGraphics/Chyrons/Container/ChyronContainer.tsx b/src/components/BroadcastGraphics/Chyrons/Container/ChyronContainer.tsx index 6766c0f..be3f11e 100644 --- a/src/components/BroadcastGraphics/Chyrons/Container/ChyronContainer.tsx +++ b/src/components/BroadcastGraphics/Chyrons/Container/ChyronContainer.tsx @@ -2,14 +2,16 @@ import { useSelector } from "react-redux"; import { broadcastGraphicsSelector } from "../../../../features/broadcast/graphics/broadcastGraphicsSelector"; import { workspaceSelector } from "../../../../features/workspace/workspaceSelector"; +import { Placement } from "../../../../types/style"; import { ChyronDriver } from "../Driver"; -import { DoubleChyronContainer } from "./styles"; +import { ChyronPlacement, DoubleChyronContainer } from "./styles"; type ChyronContainerProps = { debug?: boolean, + placement?: Placement, }; -export function ChyronContainer({ debug = false }: ChyronContainerProps) { +export function ChyronContainer({ debug = false, placement = {} }: ChyronContainerProps) { const { chyrons } = useSelector(broadcastGraphicsSelector); const { debugDurationMultiplier } = useSelector(workspaceSelector); @@ -23,19 +25,20 @@ export function ChyronContainer({ debug = false }: ChyronContainerProps) { debugDurationMultiplier={debug ? debugDurationMultiplier : 1} /> ); - if (chyrons.subMode === "medium" && chyrons.driver.secondary) { - return ( - - {primary} - - - ); - } else { - return primary; - } + + return ( + + {chyrons.subMode === "medium" && chyrons.driver.secondary ? ( + + {primary} + + + ) : primary} + + ); } diff --git a/src/components/BroadcastGraphics/Chyrons/Container/styles.ts b/src/components/BroadcastGraphics/Chyrons/Container/styles.ts index 7ce6563..7766d88 100644 --- a/src/components/BroadcastGraphics/Chyrons/Container/styles.ts +++ b/src/components/BroadcastGraphics/Chyrons/Container/styles.ts @@ -1,7 +1,19 @@ import styled from "styled-components/macro"; +import { Placement } from "../../../../types/style"; +import { placementStyleRules } from "../../../../utils/styling"; + export const DoubleChyronContainer = styled.div` display: flex; justify-content: space-between; width: 1196px; `; + + +type ChyronPlacementProps = { + placement: Placement, +}; +export const ChyronPlacement = styled.div` + position: absolute; + ${({ placement }) => placementStyleRules(placement)} +`; diff --git a/src/components/BroadcastGraphics/TimingBoard/TimingBoard.tsx b/src/components/BroadcastGraphics/TimingBoard/TimingBoard.tsx index 1cd86ac..b1e8202 100644 --- a/src/components/BroadcastGraphics/TimingBoard/TimingBoard.tsx +++ b/src/components/BroadcastGraphics/TimingBoard/TimingBoard.tsx @@ -1,21 +1,21 @@ import { useSelector } from "react-redux"; import { workspaceSelector } from "../../../features/workspace/workspaceSelector"; +import { Placement } from "../../../types/style"; import { TimingBoardLayout } from "./styles"; import { TimingTower } from "./TimingTower"; import { StatusIndicator } from "./StatusIndicator"; -import { broadcastGraphicsSelector } from "../../../features/broadcast/graphics/broadcastGraphicsSelector"; type TimingBoardProps = { debug?: boolean, + placement?: Placement, }; -export function TimingBoard({ debug = false }: TimingBoardProps) { +export function TimingBoard({ debug = false, placement = {} }: TimingBoardProps) { const { debugDurationMultiplier } = useSelector(workspaceSelector); - const { timingBoard } = useSelector(broadcastGraphicsSelector); return ( - + diff --git a/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTowerRow.tsx b/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTowerRow.tsx index 71ff63a..e867d16 100644 --- a/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTowerRow.tsx +++ b/src/components/BroadcastGraphics/TimingBoard/TimingTower/TimingTowerRow.tsx @@ -153,6 +153,13 @@ export function TimingTowerRow({ xScale = rightHalfContent.includes(":") ? 0.75 : 0.9; yScale = rightHalfContent.includes("+") ? 1.1 : 1.0; + + if (rightHalfContent.includes("LAPS") && rightHalfContent.length > 7) { + xScale = 0.85; // Extreme edge case where +10 laps or more behind. + } + if (rightHalfContent.length > 9) { + xScale = 0.7; // Extreme edge case where +10 minutes or more behind. + } } return ( diff --git a/src/components/BroadcastGraphics/TimingBoard/TimingTower/styles.ts b/src/components/BroadcastGraphics/TimingBoard/TimingTower/styles.ts index d09dcca..1f2977f 100644 --- a/src/components/BroadcastGraphics/TimingBoard/TimingTower/styles.ts +++ b/src/components/BroadcastGraphics/TimingBoard/TimingTower/styles.ts @@ -221,6 +221,7 @@ export const TimeDiff = styled.span` color: ${p => p.theme.colors.textWhite}; font-family: ${p => p.theme.fonts.f1Regular}; font-size: 20px; + white-space: nowrap; text-align: end; diff --git a/src/components/BroadcastGraphics/TimingBoard/styles.ts b/src/components/BroadcastGraphics/TimingBoard/styles.ts index a5802ed..1072346 100644 --- a/src/components/BroadcastGraphics/TimingBoard/styles.ts +++ b/src/components/BroadcastGraphics/TimingBoard/styles.ts @@ -7,7 +7,7 @@ type TimingBoardLayoutProps = { placement: Placement, }; export const TimingBoardLayout = styled.div` - position: relative; + position: absolute; ${({ placement }) => placementStyleRules(placement)} display: flex; diff --git a/src/features/broadcast/graphics/broadcastGraphicsSlice.ts b/src/features/broadcast/graphics/broadcastGraphicsSlice.ts index 5e41089..3e2fcd9 100644 --- a/src/features/broadcast/graphics/broadcastGraphicsSlice.ts +++ b/src/features/broadcast/graphics/broadcastGraphicsSlice.ts @@ -13,13 +13,12 @@ import { const initialState: RootState["broadcastGraphics"] = { chyrons: null, timingBoard: { - placement: { top: "54px", left: "96px" }, openState: 1, statusIndicator: { mode: BGStatusIndicatorModes.LapNarrow, }, timingTower: { - open: 1, + openState: 1, displayMode: BGTimingTowerDisplayMode.LeftAndRight, splitsMode: BGTimingTowerSplitsMode.Leader, focusedCars: [], diff --git a/src/shared/theme.ts b/src/shared/theme.ts index fa5c275..de7f0f5 100644 --- a/src/shared/theme.ts +++ b/src/shared/theme.ts @@ -105,6 +105,12 @@ export const theme = { broadcast: { dimensionsWidthPx: 1920, dimensionsHeightPx: 1080, + logoHeightPx: 40, + placement: { + chyrons: { bottom: "52px", left: "378px" }, + timingBoard: { top: "54px", left: "96px" }, + logo: { left: "86px", bottom: "52px" }, + }, }, }; diff --git a/src/types/state.ts b/src/types/state.ts index a91b509..19bffdc 100644 --- a/src/types/state.ts +++ b/src/types/state.ts @@ -254,7 +254,6 @@ export interface BroadcastDirector { // Broadcast Graphics export interface BGBaseState { - placement: Placement; openState: OpenState; } /** @@ -287,7 +286,7 @@ export enum BGStatusIndicatorModes { // Timing Tower export interface BGTimingTower { - open: OpenState; + openState: OpenState; displayMode: BGTimingTowerDisplayMode; splitsMode: BGTimingTowerSplitsMode, focusedCars: Car[], From c631f0e4eed44c1b9b84a9084923acb5cb7fedfd Mon Sep 17 00:00:00 2001 From: Kyle Geib Date: Thu, 17 Mar 2022 09:14:29 -0400 Subject: [PATCH 7/7] ISSUE-053 - Small change. Retired cars no longer show position in ChyronDriver. Stopped having Norris and Perez retired at the start. --- .../BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx | 4 ++-- src/features/event/eventSlice.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx b/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx index b660457..39d12e0 100644 --- a/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx +++ b/src/components/BroadcastGraphics/Chyrons/Driver/ChyronDriver.tsx @@ -1,7 +1,7 @@ import { useSpring } from "@react-spring/web"; import { useDispatch } from "react-redux"; -import { BGChyronDriver, BGChyronSubMode, OpenState } from "../../../../types/state"; +import { BGChyronDriver, BGChyronSubMode, CarStatus, OpenState } from "../../../../types/state"; import { DebugDurationProps } from "../../../../types/style"; import { clearChyrons } from "../../../../features/broadcast/graphics/broadcastGraphicsSlice"; import { theme } from "../../../../shared/theme"; @@ -133,7 +133,7 @@ export function ChyronDriver({ teamColor={teamColor} /> - {showPosFlag && ( + {showPosFlag && car.status !== CarStatus.Retired && (