Skip to content

Commit

Permalink
Basic outline of poll rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
kepstin committed Sep 30, 2024
1 parent 1bd7269 commit c54024e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
4 changes: 4 additions & 0 deletions bbb_presentation_video/renderer/tldraw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
HighlighterShape,
LineShape,
OvalGeoShape,
PollShape,
RectangleGeoShape,
RectangleShape,
RhombusGeoShape,
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 7 additions & 2 deletions bbb_presentation_video/renderer/tldraw/shape/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand All @@ -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)

Expand All @@ -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[
Expand Down
21 changes: 21 additions & 0 deletions bbb_presentation_video/renderer/tldraw/shape/poll.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit c54024e

Please sign in to comment.