-
Notifications
You must be signed in to change notification settings - Fork 0
/
MiroShape.php
162 lines (126 loc) · 3.6 KB
/
MiroShape.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
namespace MiroClipboard\Objects;
use MiroClipboard\Enums\ShapeType;
use MiroClipboard\Enums\WidgetType;
use MiroClipboard\MiroWidget;
use MiroClipboard\Styles\MiroShapeStyle;
use MiroClipboard\Utility\HasGroup;
use MiroClipboard\Utility\SetPropertiesFromArray;
class MiroShape extends MiroWidget
{
use HasGroup;
use SetPropertiesFromArray;
private MiroShapeStyle $shapeStyle;
private ShapeType $shapeType;
private string $text = '';
private array $size = [
'width' => 100,
'height' => 100,
];
private array $position = [
'x' => 0.0,
'y' => 0.0,
];
private array $offsetPosition = [
'x' => 0.0,
'y' => 0.0,
];
private float $scale = 1;
private float $relativeScale = 1;
private float $rotation = 0;
private float $relativeRotation = 0;
public function __construct(ShapeType $shapeType = ShapeType::Square)
{
parent::__construct();
$this->widgetType = WidgetType::Shape;
$this->shapeType = $shapeType;
$this->shapeStyle = new MiroShapeStyle();
}
/**
* @param callable(MiroShapeStyle): static $style
*
* @return $this
*/
public function style(callable $style): static
{
$style($this->shapeStyle);
return $this;
}
public function text(string $text): static
{
$this->text = $text;
return $this;
}
public function size(int $width, int $height): static
{
$this->size = [
'width' => $width,
'height' => $height,
];
return $this;
}
public function scale(float $scale): static
{
$this->scale = $scale;
return $this;
}
public function relativeScale(float $relativeScale): static
{
$this->relativeScale = $relativeScale;
return $this;
}
public function rotation(float $rotation): static
{
$this->rotation = $rotation;
return $this;
}
public function relativeRotation(float $relativeRotation): static
{
$this->relativeRotation = $relativeRotation;
return $this;
}
public function position(float $x, float $y): static
{
$this->position = [
'x' => $x,
'y' => $y,
];
return $this;
}
public function offsetPosition(float $x, float $y): static
{
$this->offsetPosition = [
'x' => $x,
'y' => $y,
];
return $this;
}
public function toArray(): array
{
return [
...parent::toArray(),
'widgetData' => [
'type' => $this->widgetType->value,
'json' => [
'size' => $this->size,
'_position' => [
'offsetPx' => $this->offsetPosition,
],
'scale' => [
'scale' => $this->scale,
],
'relativeScale' => $this->relativeScale,
'rotation' => [
'rotation' => $this->rotation,
],
'relativeRotation' => $this->relativeRotation,
'position' => $this->position,
'_parent' => null,
'text' => $this->text,
'style' => json_encode($this->shapeStyle->toArray()),
'shape' => $this->shapeType->value,
],
],
];
}
}