|
5 | 5 |
|
6 | 6 |
|
7 | 7 | from videocode.input.input import * |
8 | | -from videocode.input.offset.Offset import Offset |
9 | | -from videocode.shader.vertexShader.position import position |
10 | 8 |
|
11 | 9 |
|
12 | 10 | class Group(Input): |
| 11 | + # fmt: off |
13 | 12 | """ |
14 | 13 | A `Group` contains many inputs and will apply each transformations it gets to all of its inputs. |
| 14 | +
|
| 15 | + Also used to create bigger things that link many Inputs. |
| 16 | + You create a class that inherits from `Group`, setup your things and then super().__init__(). |
15 | 17 | """ |
| 18 | + # fmt: on |
16 | 19 |
|
17 | 20 | def __new__(cls, *args, **kwargs) -> Self: |
18 | 21 | instance = object.__new__(cls) |
19 | 22 | instance.meta = Metadata(interface=True) |
20 | 23 | return instance |
21 | 24 |
|
22 | 25 | def __init__(self, *inputs: Input): |
23 | | - self.inputs = [i for i in inputs] |
| 26 | + self._inputs = [i for i in inputs] |
24 | 27 |
|
25 | 28 | def addInput(self, *inputs: Input) -> Self: |
26 | 29 | for i in inputs: |
27 | | - self.inputs.append(i) |
| 30 | + self._inputs.append(i) |
28 | 31 | return self |
29 | 32 |
|
30 | 33 | def flush(self) -> Self: |
31 | 34 | """ |
32 | 35 | Appends the `frames` of `self` to the `timeline`. |
33 | 36 | """ |
34 | | - for i in self.inputs: |
| 37 | + for i in self._inputs: |
35 | 38 | i.flush() |
36 | 39 |
|
37 | 40 | return self |
38 | 41 |
|
39 | | - def apply(self, *shaders: IShader, start: defaultable[sec] = default(0), duration: defaultable[sec] = default(1)) -> Self: |
| 42 | + def apply(self, *shaders: IShader, start: sec = 0, duration: sec = 1) -> Self: |
40 | 43 | """ |
41 | 44 | Applies the `Transformations` `ts` to all the `Inputs` of the `Group`. |
42 | 45 | """ |
43 | 46 | for s in shaders: |
44 | | - for i in self.inputs: |
| 47 | + for i in self._inputs: |
45 | 48 | i.apply(copy.deepcopy(s), start=start, duration=duration) |
46 | 49 |
|
47 | 50 | return self |
48 | 51 |
|
49 | 52 | def waitForOthers(self, n: sec = 0, updateContext=False) -> Self: |
50 | | - lastAffectedFramePlusN = max(i.meta.lastAffectedFrame for i in self.inputs) + int(n * FRAMERATE) |
| 53 | + lastAffectedFramePlusN = max(i.meta.lastAffectedFrame for i in self._inputs) + int(n * FRAMERATE) |
51 | 54 |
|
52 | | - for i in self.inputs: |
| 55 | + for i in self._inputs: |
53 | 56 | i.waitTo(lastAffectedFramePlusN) |
54 | 57 |
|
55 | 58 | if updateContext and lastAffectedFramePlusN >= Context.lastEverAffectedFrame: |
56 | 59 | Context.waitOffset = Context.lastEverAffectedFrame = lastAffectedFramePlusN |
57 | 60 |
|
58 | 61 | return self |
59 | 62 |
|
| 63 | + def _broadcast(self, name: str, *args, **kwargs) -> Self: |
| 64 | + for child in self._inputs: |
| 65 | + getattr(child, name)(*args, **kwargs) |
| 66 | + return self |
| 67 | + |
| 68 | + # fmt: off |
| 69 | + def moveTo(self, *args, **kwargs) -> Self: return self._broadcast('moveTo', *args, **kwargs) |
| 70 | + def moveBy(self, *args, **kwargs) -> Self: return self._broadcast('moveBy', *args, **kwargs) |
| 71 | + def scaleTo(self, *args, **kwargs) -> Self: return self._broadcast('scaleTo', *args, **kwargs) |
| 72 | + def scaleBy(self, *args, **kwargs) -> Self: return self._broadcast('scaleBy', *args, **kwargs) |
| 73 | + def rotateTo(self, *args, **kwargs) -> Self: return self._broadcast('rotateTo', *args, **kwargs) |
| 74 | + def rotateBy(self, *args, **kwargs) -> Self: return self._broadcast('rotateBy', *args, **kwargs) |
| 75 | + def alignTo(self, *args, **kwargs) -> Self: return self._broadcast('alignTo', *args, **kwargs) |
| 76 | + def fadeIn(self, *args, **kwargs) -> Self: return self._broadcast('fadeIn', *args, **kwargs) |
| 77 | + def fadeOut(self, *args, **kwargs) -> Self: return self._broadcast('fadeOut', *args, **kwargs) |
| 78 | + # fmt: on |
| 79 | + |
60 | 80 | def __str__(self) -> str: |
61 | | - return "".join(f"idx=[{idx}], i=[{type(i).__name__}]]\n" for idx, i in enumerate(self.inputs)) |
| 81 | + return "".join(f"idx=[{idx}], i=[{type(i).__name__}]]\n" for idx, i in enumerate(self._inputs)) |
62 | 82 |
|
63 | 83 | def __repr__(self) -> str: |
64 | 84 | return self.__str__() |
0 commit comments