ISSUE-017 - Implemented image overlay solution that I'm happy with.
Shout-out to Blair Wadman for revealing a method to display an image at 1:1 pixel scale and having the div that houses it automatically match that size without any fuss. (Here: https://befused.com/css/flexbox-prevent-image-shrinking/).
This commit is contained in:
1 parent
8780d2a9db
commit
f51df58d17
12 files changed
+69
-93
No files matched your search
@@ -29,6 +29,7 @@
|
|||||||
"@types/react-dom": "^17.0.9",
|
"@types/react-dom": "^17.0.9",
|
||||||
"@types/react-redux": "^7.1.21",
|
"@types/react-redux": "^7.1.21",
|
||||||
"@types/styled-components": "^5.1.18",
|
"@types/styled-components": "^5.1.18",
|
||||||
|
"@types/webpack-env": "^1.16.3",
|
||||||
"@use-gesture/react": "^10.2.4",
|
"@use-gesture/react": "^10.2.4",
|
||||||
"d3": "^7.2.1",
|
"d3": "^7.2.1",
|
||||||
"history": "5",
|
"history": "5",
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSe
|
|||||||
import {
|
import {
|
||||||
initNewOverlayItem,
|
initNewOverlayItem,
|
||||||
setCurrentOverlayId,
|
setCurrentOverlayId,
|
||||||
setPosition,
|
|
||||||
setVisibility,
|
setVisibility,
|
||||||
} from "../../../features/overlayTool/overlayToolSlice";
|
} from "../../../features/overlayTool/overlayToolSlice";
|
||||||
|
|
||||||
@@ -36,7 +35,7 @@ export function OverlayControl() {
|
|||||||
if (currentOverlayItem == null) {
|
if (currentOverlayItem == null) {
|
||||||
dispatch(initNewOverlayItem({
|
dispatch(initNewOverlayItem({
|
||||||
overlayId: overlayIds[idNum],
|
overlayId: overlayIds[idNum],
|
||||||
initialPosition: { x: 400, y: 300 },
|
initialPosition: { x: 0, y: 0 },
|
||||||
setVisible: true,
|
setVisible: true,
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ import { useDrag } from "@use-gesture/react";
|
|||||||
import { useDimensions } from "../../../utils/hooks";
|
import { useDimensions } from "../../../utils/hooks";
|
||||||
import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector";
|
import { overlayToolSelector } from "../../../features/overlayTool/overlayToolSelector";
|
||||||
import { setPosition } from "../../../features/overlayTool/overlayToolSlice";
|
import { setPosition } from "../../../features/overlayTool/overlayToolSlice";
|
||||||
|
import { OverlayImage, OverlayImageContainer, OverlayImageSubContainer } from "./styles";
|
||||||
|
|
||||||
import { OverlayItemContainer } from "./styles";
|
const overlayImages = require.context("../../../public/images/overlays", true);
|
||||||
|
|
||||||
type OverlayDisplayProps = {
|
type OverlayDisplayProps = {
|
||||||
containerDimensions: {
|
containerDimensions: {
|
||||||
@@ -27,10 +28,11 @@ export function OverlayDisplay({
|
|||||||
} = useSelector(overlayToolSelector);
|
} = useSelector(overlayToolSelector);
|
||||||
|
|
||||||
// Monitor element dimensions to calculate min/max drag coordinates.
|
// Monitor element dimensions to calculate min/max drag coordinates.
|
||||||
const [overlayItemRef, {
|
const [overlayItemImageRef, {
|
||||||
width: overlayItemWidth,
|
width: overlayItemWidth,
|
||||||
height: overlayItemHeight,
|
height: overlayItemHeight,
|
||||||
}] = useDimensions<HTMLDivElement>();
|
}] = useDimensions<HTMLImageElement>();
|
||||||
|
console.log(overlayItemWidth, overlayItemHeight);
|
||||||
const
|
const
|
||||||
minX = -bleedover,
|
minX = -bleedover,
|
||||||
minY = -bleedover,
|
minY = -bleedover,
|
||||||
@@ -62,7 +64,6 @@ export function OverlayDisplay({
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { position } = currentOverlayItem;
|
|
||||||
|
|
||||||
return transition((style, visible) =>
|
return transition((style, visible) =>
|
||||||
visible ? (
|
visible ? (
|
||||||
@@ -77,15 +78,14 @@ export function OverlayDisplay({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<animated.div style={{ ...style, position: "absolute" }}>
|
<animated.div style={{ ...style, position: "absolute" }}>
|
||||||
<OverlayItemContainer
|
<OverlayImageContainer>
|
||||||
ref={overlayItemRef}
|
<OverlayImageSubContainer>
|
||||||
visible={visible}
|
<OverlayImage
|
||||||
tempColor={currentOverlayId}
|
ref={overlayItemImageRef}
|
||||||
>
|
src={overlayImages(`./${currentOverlayId}`)}
|
||||||
{currentOverlayId}
|
/>
|
||||||
<br />
|
</OverlayImageSubContainer>
|
||||||
(x:{Math.floor(position.x)}px, y:{Math.floor(position.y)}px)
|
</OverlayImageContainer>
|
||||||
</OverlayItemContainer>
|
|
||||||
</animated.div>
|
</animated.div>
|
||||||
</animated.div>
|
</animated.div>
|
||||||
) : null,
|
) : null,
|
||||||
|
|||||||
@@ -1,22 +1,28 @@
|
|||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
|
|
||||||
export type OverlayItemContainerProps = {
|
/**
|
||||||
visible: boolean,
|
* scale is a percentage (0-100%)
|
||||||
tempColor: string,
|
* */
|
||||||
|
type OverlayImageProps = {
|
||||||
|
src: string,
|
||||||
|
scale?: number,
|
||||||
};
|
};
|
||||||
export const OverlayItemContainer = styled.div.attrs<OverlayItemContainerProps>(({
|
export const OverlayImage = styled.img.attrs<OverlayImageProps>(({
|
||||||
visible,
|
src,
|
||||||
}) => ({
|
}) => ({
|
||||||
style: {
|
draggable: false,
|
||||||
display: visible ? undefined : "none",
|
src,
|
||||||
},
|
}))<OverlayImageProps>`
|
||||||
}))<OverlayItemContainerProps>`
|
width: ${({ scale = 100 }) => `${scale}%`};
|
||||||
/* Temporary. Overlay will be transparent and based on an image. */
|
|
||||||
/* width: ${({ tempColor }) => tempColor == "red" ? "150px" : "100px"}; */
|
|
||||||
width: 150px;
|
|
||||||
height: 150px;
|
|
||||||
background-color: ${({ tempColor }) => tempColor};
|
|
||||||
box-shadow: 0px 7px 11px 1px black;
|
|
||||||
`;
|
`;
|
||||||
OverlayItemContainer.displayName = "OverlayItemContainer";
|
OverlayImage.displayName = "OverlayImage";
|
||||||
|
|
||||||
|
export const OverlayImageContainer = styled.div`
|
||||||
|
display: flex;
|
||||||
|
`;
|
||||||
|
OverlayImageContainer.displayName = "OverlayImageContainer";
|
||||||
|
|
||||||
|
export const OverlayImageSubContainer = styled.div`
|
||||||
|
flex-shrink: 0;
|
||||||
|
`;
|
||||||
|
OverlayImageSubContainer.displayName = "OverlayImageSubContainer";
|
||||||
@@ -16,9 +16,6 @@ import { OverlayDisplay } from "../../OverlayTool";
|
|||||||
|
|
||||||
import { workspaceObject } from "../workspaces";
|
import { workspaceObject } from "../workspaces";
|
||||||
|
|
||||||
const PREVIEW_WINDOW_HEIGHT = 600;
|
|
||||||
const PREVIEW_WINDOW_WIDTH = 800;
|
|
||||||
|
|
||||||
export const Workspace = () => {
|
export const Workspace = () => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { workspaceId } = useParams();
|
const { workspaceId } = useParams();
|
||||||
@@ -40,6 +37,9 @@ export const Workspace = () => {
|
|||||||
}
|
}
|
||||||
}, [workspaceId]);
|
}, [workspaceId]);
|
||||||
|
|
||||||
|
if (workspaceId == null) return null;
|
||||||
|
const workspace = workspaceObject[workspaceId];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
gutter="lg"
|
gutter="lg"
|
||||||
@@ -47,23 +47,18 @@ export const Workspace = () => {
|
|||||||
maxWidth="80%"
|
maxWidth="80%"
|
||||||
centerChildren
|
centerChildren
|
||||||
>
|
>
|
||||||
<H2>{workspaceId ? workspaceObject[workspaceId].name : "Unknown"}</H2>
|
<H2>{workspaceId ? workspace.name : "Unknown"}</H2>
|
||||||
<PreviewWindow
|
<PreviewWindow
|
||||||
height={PREVIEW_WINDOW_HEIGHT}
|
dimensions={workspace.previewWindowDimensions}
|
||||||
width={PREVIEW_WINDOW_WIDTH}
|
|
||||||
animatedBG={animatedBG}
|
animatedBG={animatedBG}
|
||||||
>
|
>
|
||||||
<MockupBlock
|
<MockupBlock
|
||||||
color="#415bad"
|
color="#415bad"
|
||||||
height="300px"
|
height="100px"
|
||||||
width="400px"
|
width="100px"
|
||||||
>Preview Item</MockupBlock>
|
>Preview Item</MockupBlock>
|
||||||
<OverlayDisplay
|
<OverlayDisplay
|
||||||
containerDimensions={{
|
containerDimensions={workspace.previewWindowDimensions}
|
||||||
height: PREVIEW_WINDOW_HEIGHT,
|
|
||||||
width: PREVIEW_WINDOW_WIDTH,
|
|
||||||
}}
|
|
||||||
bleedover={50}
|
|
||||||
/>
|
/>
|
||||||
</PreviewWindow>
|
</PreviewWindow>
|
||||||
<ControlsContainer>
|
<ControlsContainer>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import styled, { css, keyframes } from "styled-components";
|
|||||||
import { PadBox } from "@bedrock-layout/padbox";
|
import { PadBox } from "@bedrock-layout/padbox";
|
||||||
|
|
||||||
import bg from "../../../public/images/misc/checker-40x40.png";
|
import bg from "../../../public/images/misc/checker-40x40.png";
|
||||||
|
import { Dimensions } from "../../../types/state";
|
||||||
|
|
||||||
const scrollAnimation = keyframes`
|
const scrollAnimation = keyframes`
|
||||||
from { background-position: 0 0; }
|
from { background-position: 0 0; }
|
||||||
@@ -9,8 +10,7 @@ const scrollAnimation = keyframes`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export type PreviewWindowProps = {
|
export type PreviewWindowProps = {
|
||||||
height: number,
|
dimensions: Dimensions,
|
||||||
width: number,
|
|
||||||
animatedBG?: boolean,
|
animatedBG?: boolean,
|
||||||
};
|
};
|
||||||
export const PreviewWindow = styled(PadBox).attrs(() => ({
|
export const PreviewWindow = styled(PadBox).attrs(() => ({
|
||||||
@@ -21,8 +21,8 @@ export const PreviewWindow = styled(PadBox).attrs(() => ({
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
height: ${({ height }) => height}px;
|
height: ${({ dimensions }) => dimensions.height}px;
|
||||||
width: ${({ width }) => width}px;
|
width: ${({ dimensions }) => dimensions.width}px;
|
||||||
|
|
||||||
border-radius: 1em;
|
border-radius: 1em;
|
||||||
|
|
||||||
|
|||||||
@@ -1,57 +1,24 @@
|
|||||||
import { OverlayIds } from "../../types/state";
|
import { Dimensions, OverlayIds } from "../../types/state";
|
||||||
|
|
||||||
export type WorkspaceObject = {
|
export type WorkspaceObject = {
|
||||||
[id: string]: {
|
[id: string]: {
|
||||||
name: string,
|
name: string,
|
||||||
overlayIds: OverlayIds,
|
overlayIds: OverlayIds,
|
||||||
|
previewWindowDimensions: Dimensions,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
export const workspaceObject: WorkspaceObject = {
|
export const workspaceObject: WorkspaceObject = {
|
||||||
workspace1: {
|
chyronSimple: {
|
||||||
name: "Workspace 1",
|
name: "Chyron Simple",
|
||||||
overlayIds: ["red", "blue", "white"],
|
overlayIds: [
|
||||||
|
"chyron-simple-full.png",
|
||||||
|
"chyron-simple-opening-1.png",
|
||||||
|
"chyron-simple-opening-2.png",
|
||||||
|
],
|
||||||
|
previewWindowDimensions: {
|
||||||
|
width: 650,
|
||||||
|
height: 200,
|
||||||
},
|
},
|
||||||
workspace2: {
|
|
||||||
name: "Workspace 2",
|
|
||||||
overlayIds: ["green"],
|
|
||||||
},
|
},
|
||||||
workspace3: {
|
|
||||||
name: "Workspace 3",
|
|
||||||
overlayIds: ["green"],
|
|
||||||
},
|
|
||||||
workspace4: {
|
|
||||||
name: "Workspace 4 has a longer name than the rest",
|
|
||||||
overlayIds: ["green"],
|
|
||||||
},
|
|
||||||
blah0: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah1: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah2: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah3: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah4: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah5: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah6: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah7: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah8: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah9: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah10: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah11: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah12: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah13: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah14: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah15: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah16: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah17: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah18: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah19: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah20: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah21: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah22: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah23: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah24: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah25: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah26: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah27: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah28: { name: "blah", overlayIds: ["green"] },
|
|
||||||
blah29: { name: "blah", overlayIds: ["green"] },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 34 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 34 KiB |
@@ -22,6 +22,9 @@
|
|||||||
"jsx": "react-jsx",
|
"jsx": "react-jsx",
|
||||||
"noUnusedLocals": false,
|
"noUnusedLocals": false,
|
||||||
"noUnusedParameters": false,
|
"noUnusedParameters": false,
|
||||||
|
"types": [
|
||||||
|
"webpack-env"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"src",
|
"src",
|
||||||
|
|||||||
@@ -2238,6 +2238,11 @@
|
|||||||
resolved "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.2.tgz"
|
resolved "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.2.tgz"
|
||||||
integrity sha512-F5DIZ36YVLE+PN+Zwws4kJogq47hNgX3Nx6WyDJ3kcplxyke3XIzB8uK5n/Lpm1HBsbGzd6nmGehL8cPekP+Tg==
|
integrity sha512-F5DIZ36YVLE+PN+Zwws4kJogq47hNgX3Nx6WyDJ3kcplxyke3XIzB8uK5n/Lpm1HBsbGzd6nmGehL8cPekP+Tg==
|
||||||
|
|
||||||
|
"@types/webpack-env@^1.16.3":
|
||||||
|
version "1.16.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.16.3.tgz#b776327a73e561b71e7881d0cd6d34a1424db86a"
|
||||||
|
integrity sha512-9gtOPPkfyNoEqCQgx4qJKkuNm/x0R2hKR7fdl7zvTJyHnIisuE/LfvXOsYWL0o3qq6uiBnKZNNNzi3l0y/X+xw==
|
||||||
|
|
||||||
"@types/yargs-parser@*":
|
"@types/yargs-parser@*":
|
||||||
version "20.2.1"
|
version "20.2.1"
|
||||||
resolved "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-20.2.1.tgz"
|
resolved "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-20.2.1.tgz"
|
||||||
|
|||||||
Reference in new issue
Block a user