From c54024e932b915954b891b58cdfd3439a763629a Mon Sep 17 00:00:00 2001 From: Calvin Walton Date: Mon, 30 Sep 2024 14:36:11 -0400 Subject: [PATCH] Basic outline of poll rendering --- .../renderer/tldraw/__init__.py | 4 ++++ .../renderer/tldraw/shape/__init__.py | 9 ++++++-- .../renderer/tldraw/shape/poll.py | 21 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 bbb_presentation_video/renderer/tldraw/shape/poll.py diff --git a/bbb_presentation_video/renderer/tldraw/__init__.py b/bbb_presentation_video/renderer/tldraw/__init__.py index 3227599..cc01381 100644 --- a/bbb_presentation_video/renderer/tldraw/__init__.py +++ b/bbb_presentation_video/renderer/tldraw/__init__.py @@ -64,6 +64,7 @@ HighlighterShape, LineShape, OvalGeoShape, + PollShape, RectangleGeoShape, RectangleShape, RhombusGeoShape, @@ -87,6 +88,7 @@ from bbb_presentation_video.renderer.tldraw.shape.frame import finalize_frame from bbb_presentation_video.renderer.tldraw.shape.highlighter import finalize_highlight from bbb_presentation_video.renderer.tldraw.shape.line import finalize_line +from bbb_presentation_video.renderer.tldraw.shape.poll import finalize_poll from bbb_presentation_video.renderer.tldraw.shape.rectangle import finalize_rectangle from bbb_presentation_video.renderer.tldraw.shape.sticky import finalize_sticky from bbb_presentation_video.renderer.tldraw.shape.sticky_v2 import finalize_sticky_v2 @@ -310,6 +312,8 @@ def finalize_shapes( finalize_line(ctx, id, shape) elif isinstance(shape, OvalGeoShape): finalize_oval(ctx, id, shape) + elif isinstance(shape, PollShape): + finalize_poll(ctx, id, shape) elif isinstance(shape, RectangleShape): finalize_rectangle(ctx, id, shape) elif isinstance(shape, RectangleGeoShape): diff --git a/bbb_presentation_video/renderer/tldraw/shape/__init__.py b/bbb_presentation_video/renderer/tldraw/shape/__init__.py index 5d40d25..e8f75d6 100644 --- a/bbb_presentation_video/renderer/tldraw/shape/__init__.py +++ b/bbb_presentation_video/renderer/tldraw/shape/__init__.py @@ -579,11 +579,13 @@ def update_from_data(self, data: ShapeData) -> None: else: self.spline = SplineType.NONE + @attr.s(order=False, slots=True, auto_attribs=True) class PollShapeAnswer: key: str numVotes: int + @attr.s(order=False, slots=True, auto_attribs=True) class PollShape(RotatableShapeProto): question: str = "" @@ -596,7 +598,7 @@ class PollShape(RotatableShapeProto): def update_from_data(self, data: ShapeData) -> None: # Poll shapes contain a prop "fill" which isn't a valid FillStyle if "props" in data and "fill" in data["props"]: - del(data["props"]["fill"]) + del data["props"]["fill"] super().update_from_data(data) @@ -613,7 +615,10 @@ def update_from_data(self, data: ShapeData) -> None: if "questionText" in props: self.questionText = props["questionText"] if "answers" in props: - self.answers = [PollShapeAnswer(key=answer["key"], numVotes=answer["numVotes"]) for answer in props["answers"]] + self.answers = [ + PollShapeAnswer(key=answer["key"], numVotes=answer["numVotes"]) + for answer in props["answers"] + ] Shape = Union[ diff --git a/bbb_presentation_video/renderer/tldraw/shape/poll.py b/bbb_presentation_video/renderer/tldraw/shape/poll.py new file mode 100644 index 0000000..5910725 --- /dev/null +++ b/bbb_presentation_video/renderer/tldraw/shape/poll.py @@ -0,0 +1,21 @@ +# SPDX-FileCopyrightText: 2024 BigBlueButton Inc. and by respective authors +# +# SPDX-License-Identifier: GPL-3.0-or-later + +from __future__ import annotations + +from typing import TypeVar + +import cairo + +from bbb_presentation_video.renderer.tldraw.shape import PollShape, apply_shape_rotation + +CairoSomeSurface = TypeVar("CairoSomeSurface", bound=cairo.Surface) + + +def finalize_poll( + ctx: cairo.Context[CairoSomeSurface], id: str, shape: PollShape +) -> None: + print(f"\tTldraw: Finalizing Poll: {id}") + + apply_shape_rotation(ctx, shape)