diff --git a/fableous-fe/src/components/canvas/Canvas.tsx b/fableous-fe/src/components/canvas/Canvas.tsx index 85f177f1..553395f0 100644 --- a/fableous-fe/src/components/canvas/Canvas.tsx +++ b/fableous-fe/src/components/canvas/Canvas.tsx @@ -22,7 +22,7 @@ import { scaleUpXY, translateXY, } from "./helpers"; -import { ASPECT_RATIO, SCALE, SELECT_PADDING } from "./constants"; +import { SCALE, SELECT_PADDING } from "./constants"; import { Cursor } from "./CursorScreen"; import { ImperativeCanvasRef, TextShape, TextShapeMap } from "./data"; import { ControllerRole, ToolMode, WSMessageType } from "../../constant"; @@ -41,8 +41,9 @@ interface CanvasProps { pageNum: number; isGallery?: boolean; isShown?: boolean; + offsetWidth: number; + offsetHeight: number; onDraw?: () => void; - offsetWidth?: number; setCursor?: React.Dispatch; textShapes: TextShapeMap; setTextShapes: React.Dispatch>; @@ -60,7 +61,6 @@ const defaultProps = { isGallery: false, isShown: true, onDraw: () => {}, - offsetWidth: 0, setCursor: undefined, toolColor: "#000000ff", toolMode: ToolMode.None, @@ -86,8 +86,9 @@ const Canvas = forwardRef( pageNum, isGallery, isShown, + offsetWidth, + offsetHeight, onDraw = defaultProps.onDraw, - offsetWidth = defaultProps.offsetWidth, setCursor, setTextShapes, textShapes, @@ -796,9 +797,8 @@ const Canvas = forwardRef( const adjustCanvasSize = useCallback(() => { const canvas = canvasRef.current; - const canvasOffsetWidth = canvas.offsetWidth; - canvas.width = canvasOffsetWidth * SCALE; - canvas.height = canvas.width * ASPECT_RATIO; + canvas.width = canvas.offsetWidth * SCALE; + canvas.height = canvas.offsetHeight * SCALE; }, [canvasRef]); // exposes callbacks to parent, to be used by toolbar @@ -911,10 +911,12 @@ const Canvas = forwardRef( return (
( }} style={{ position: "absolute", - width: offsetWidth, + width: "100%", + height: "100%", borderRadius: "24px", // allows onPointerMove to be fired continuously on touch, // else will be treated as pan gesture leading to short strokes diff --git a/fableous-fe/src/components/canvas/CursorScreen.tsx b/fableous-fe/src/components/canvas/CursorScreen.tsx index 3a8bf562..d5c3dc9d 100644 --- a/fableous-fe/src/components/canvas/CursorScreen.tsx +++ b/fableous-fe/src/components/canvas/CursorScreen.tsx @@ -4,7 +4,7 @@ /* eslint-disable no-case-declarations */ import { useEffect, useRef } from "react"; import { scaleUpXY } from "./helpers"; -import { ASPECT_RATIO, SCALE } from "./constants"; +import { SCALE } from "./constants"; import { ToolMode } from "../../constant"; export interface Cursor { @@ -18,11 +18,12 @@ interface CursorScreenProps { cursor: Cursor | undefined; name?: string; isShown?: boolean; - offsetWidth?: number; + offsetWidth: number; + offsetHeight: number; } const CursorScreen = (props: CursorScreenProps) => { - const { cursor, name, isShown, offsetWidth = 0 } = props; + const { cursor, name, isShown, offsetWidth, offsetHeight } = props; const canvasRef = useRef(document.createElement("canvas")); const cursorRef = useRef(cursor as Cursor); cursorRef.current = cursor as Cursor; @@ -93,9 +94,8 @@ const CursorScreen = (props: CursorScreenProps) => { // set canvas size onmount and when canvas appears or becomes hidden useEffect(() => { const canvas = canvasRef.current; - const canvasOffsetWidth = canvas.offsetWidth; - canvas.width = canvasOffsetWidth * SCALE; - canvas.height = canvas.width * ASPECT_RATIO; + canvas.width = canvas.offsetWidth * SCALE; + canvas.height = canvas.offsetHeight * SCALE; const ctx = canvas.getContext("2d"); if (ctx) { ctx.textBaseline = "middle"; @@ -110,10 +110,12 @@ const CursorScreen = (props: CursorScreenProps) => { return (
{ style={{ position: "absolute", borderRadius: "24px", - width: offsetWidth, + width: "100%", + height: "100%", touchAction: "none", msTouchAction: "none", msTouchSelect: "none", @@ -139,7 +142,6 @@ const CursorScreen = (props: CursorScreenProps) => { CursorScreen.defaultProps = { name: "", isShown: true, - offsetWidth: 0, }; export default CursorScreen; diff --git a/fableous-fe/src/components/canvas/LayerToolbar.tsx b/fableous-fe/src/components/canvas/LayerToolbar.tsx index aa4437a3..fda8d111 100644 --- a/fableous-fe/src/components/canvas/LayerToolbar.tsx +++ b/fableous-fe/src/components/canvas/LayerToolbar.tsx @@ -47,11 +47,9 @@ export default function LayerToolbar(props: { const classes = useStyles(); return ( -
+
+): number => { + return canvasRef.current.width / canvasRef.current.offsetWidth; +}; + export const translateXY = ( canvasRef: MutableRefObject, x: number, y: number ) => { const bound = canvasRef.current.getBoundingClientRect(); - return [(x - bound.x) * SCALE, (y - bound.y) * SCALE]; + const currentScale = getCurrentScaling(canvasRef); + return [(x - bound.x) * currentScale, (y - bound.y) * currentScale]; }; // wrap with useCallback() because dependency chain leads to being used at useEffect() diff --git a/fableous-fe/src/containers/ControllerCanvasPage.tsx b/fableous-fe/src/containers/ControllerCanvasPage.tsx index a4212440..f52fd14e 100644 --- a/fableous-fe/src/containers/ControllerCanvasPage.tsx +++ b/fableous-fe/src/containers/ControllerCanvasPage.tsx @@ -290,199 +290,216 @@ export default function ControllerCanvasPage() { return ( - - - { +
+ + { - [ControllerState.JoinForm]: "Join Room", - [ControllerState.WaitingRoom]: "Lobby", - [ControllerState.DrawingSession]: "", - [ControllerState.StoryFinished]: "Finished!", - }[controllerState] - } - - - {controllerState === ControllerState.JoinForm && ( - - - (val || "").length <= 24 - ), - token: yup - .string() - .required("Token required") - .length(4, "Invalid token") - .uppercase("Invalid token"), - })} - onSubmit={handleJoinSession} - > - {(formik) => ( -
- - - - - - - - - - ) => { - const evUpperCase = { ...ev }; - if (ev.target.value.length > 4) { - return; - } - evUpperCase.target.value = - ev.target.value?.toUpperCase(); - formik.handleChange(evUpperCase); - }, - }} - /> + { + [ControllerState.JoinForm]: "Join Room", + [ControllerState.WaitingRoom]: "Lobby", + [ControllerState.DrawingSession]: "", + [ControllerState.StoryFinished]: "Finished!", + }[controllerState] + } + + + {controllerState === ControllerState.JoinForm && ( + + + (val || "").length <= 24 + ), + token: yup + .string() + .required("Token required") + .length(4, "Invalid token") + .uppercase("Invalid token"), + })} + onSubmit={handleJoinSession} + > + {(formik) => ( + + + + + + + + + + + ) => { + const evUpperCase = { ...ev }; + if (ev.target.value.length > 4) { + return; + } + evUpperCase.target.value = + ev.target.value?.toUpperCase(); + formik.handleChange(evUpperCase); + }, + }} + /> + + + + Role + + + - + + - - - - - - - )} - - - - )} - {controllerState === ControllerState.WaitingRoom && ( -
- - - - Waiting for session to begin - - - - -
- )} - {controllerState === ControllerState.StoryFinished && ( - <> - - +
+ + )} +
+
- - - - - )} + )} + {controllerState === ControllerState.WaitingRoom && ( +
+ + + + Waiting for session to begin + + + + +
+ )} + {controllerState === ControllerState.StoryFinished && ( + <> + + + + + + + + )} +
@@ -512,7 +529,7 @@ export default function ControllerCanvasPage() { /> - +
diff --git a/fableous-fe/src/containers/HubCanvasPage.tsx b/fableous-fe/src/containers/HubCanvasPage.tsx index bcd5a938..7efa3da6 100644 --- a/fableous-fe/src/containers/HubCanvasPage.tsx +++ b/fableous-fe/src/containers/HubCanvasPage.tsx @@ -431,267 +431,281 @@ export default function HubCanvasPage() { }, [achievements, broadcastAchievement]); return ( - - {hubState !== HubState.DrawingSession && ( - - - - { + +
+ {hubState !== HubState.DrawingSession && ( + + + { - [HubState.SessionForm]: "New Story", - [HubState.WaitingRoom]: "Lobby", - [HubState.DrawingSession]: "", - }[hubState] - } - - - )} - {hubState === HubState.SessionForm && ( - - - (val || "").length <= 32 - ), - description: yup - .string() - .required("Description required") - .test( - "len", - "Description too long", - (val) => (val || "").length <= 32 - ), - pages: yup - .number() - .required("Number of pages required") - .integer("Invalid numbergit") - .positive("Must have at least one page") - .lessThan(21, "Maximum is 20 pages"), - })} - onSubmit={handleCreateSession} - > - {(formik) => ( -
- - - - - - - + + + )} + {hubState === HubState.SessionForm && ( + + + (val || "").length <= 32 + ), + description: yup + .string() + .required("Description required") + .test( + "len", + "Description too long", + (val) => (val || "").length <= 32 + ), + pages: yup + .number() + .required("Number of pages required") + .integer("Invalid numbergit") + .positive("Must have at least one page") + .lessThan(21, "Maximum is 20 pages"), + })} + onSubmit={handleCreateSession} + > + {(formik) => ( + + + + + + + + + + + + + + + - - + + + )} + + + + )} + {hubState === HubState.WaitingRoom && ( + + + + + + + Joined Students ({Object.keys(joinedControllers).length} + /3) + + + + + + + text_fields + + Story - - + +
+ {joinedControllers[ControllerRole.Story] ? ( + <>{joinedControllers[ControllerRole.Story]} + ) : ( + <> + waiting to join{" "} + + + )} +
-
- - )} -
-
-
- )} - {hubState === HubState.WaitingRoom && ( - - - - - - - Joined Students ({Object.keys(joinedControllers).length}/3) - - - - - - - text_fields - - Story - - -
- {joinedControllers[ControllerRole.Story] ? ( - <>{joinedControllers[ControllerRole.Story]} - ) : ( - <> - waiting to join{" "} - - - )} -
-
-
- - - - - directions_run - - Character - - -
- {joinedControllers[ControllerRole.Character] ? ( - <>{joinedControllers[ControllerRole.Character]} - ) : ( - <> - waiting to join{" "} - - - )} -
+ + + + + directions_run + + Character + + +
+ {joinedControllers[ControllerRole.Character] ? ( + <>{joinedControllers[ControllerRole.Character]} + ) : ( + <> + waiting to join{" "} + + + )} +
+
-
- - - - - image - - Background - - -
- {joinedControllers[ControllerRole.Background] ? ( - <>{joinedControllers[ControllerRole.Background]} - ) : ( - <> - waiting to join{" "} - - - )} -
+ + + + + image + + Background + + +
+ {joinedControllers[ControllerRole.Background] ? ( + <>{joinedControllers[ControllerRole.Background]} + ) : ( + <> + waiting to join{" "} + + + )} +
+
+ + +
+ + - - -
- - - - - - - )} + + + + )} +
@@ -746,6 +760,7 @@ export default function HubCanvasPage() { name={ROLE_ICON[ControllerRole.Story].text} isShown={hubState === HubState.DrawingSession} offsetWidth={canvasOffsetWidth} + offsetHeight={canvasOffsetHeight} />
diff --git a/fableous-fe/src/containers/StoryDetailPage.tsx b/fableous-fe/src/containers/StoryDetailPage.tsx index 2618e14c..4c9e9eaa 100644 --- a/fableous-fe/src/containers/StoryDetailPage.tsx +++ b/fableous-fe/src/containers/StoryDetailPage.tsx @@ -98,6 +98,8 @@ export default function StoryDetailPage() { textShapes={textShapes} audioPaths={audioPaths} setAudioPaths={setAudioPaths} + offsetWidth={0} + offsetHeight={0} />
(config: { const isPotrait = (width || 0) / (height || 1) > ratio; const containedWidth = isPotrait ? (height || 0) * ratio : width || 0; + const containedHeight = containedWidth / ratio; - return [containedWidth, containedWidth / ratio]; + return [containedWidth, containedHeight]; }