1
+ using Unity . UIWidgets . foundation ;
2
+ using Unity . UIWidgets . gestures ;
3
+ using Unity . UIWidgets . rendering ;
4
+ using Unity . UIWidgets . ui ;
5
+ using UnityEngine ;
6
+
7
+ namespace UIWidgets . Runtime . rendering {
8
+ class RotatedBoxUtils {
9
+ public const float _kQuarterTurnsInRadians = Mathf . PI / 2.0f ;
10
+ }
11
+
12
+ public class RenderRotatedBox : RenderObjectWithChildMixinRenderBox < RenderBox > {
13
+ public RenderRotatedBox (
14
+ int quarterTurns ,
15
+ RenderBox child = null
16
+ ) {
17
+ this . child = child ;
18
+ this . _quarterTurns = quarterTurns ;
19
+ }
20
+
21
+ public int quarterTurns {
22
+ get { return this . _quarterTurns ; }
23
+ set {
24
+ if ( this . _quarterTurns == value ) {
25
+ return ;
26
+ }
27
+
28
+ this . _quarterTurns = value ;
29
+ this . markNeedsLayout ( ) ;
30
+ }
31
+ }
32
+
33
+ int _quarterTurns ;
34
+
35
+ public bool _isVertical {
36
+ get { return this . quarterTurns % 2 == 1 ; }
37
+ }
38
+
39
+ protected override float computeMinIntrinsicWidth ( float height ) {
40
+ if ( this . child == null ) {
41
+ return 0.0f ;
42
+ }
43
+
44
+ return this . _isVertical
45
+ ? this . child . getMinIntrinsicHeight ( height )
46
+ : this . child . getMinIntrinsicWidth ( height ) ;
47
+ }
48
+
49
+ protected override float computeMaxIntrinsicWidth ( float height ) {
50
+ if ( this . child == null ) {
51
+ return 0.0f ;
52
+ }
53
+
54
+ return this . _isVertical
55
+ ? this . child . getMaxIntrinsicHeight ( height )
56
+ : this . child . getMaxIntrinsicWidth ( height ) ;
57
+ }
58
+
59
+ protected override float computeMinIntrinsicHeight ( float width ) {
60
+ if ( this . child == null ) {
61
+ return 0.0f ;
62
+ }
63
+
64
+ return this . _isVertical ? this . child . getMinIntrinsicWidth ( width ) : this . child . getMinIntrinsicHeight ( width ) ;
65
+ }
66
+
67
+ protected override float computeMaxIntrinsicHeight ( float width ) {
68
+ if ( this . child == null ) {
69
+ return 0.0f ;
70
+ }
71
+
72
+ return this . _isVertical ? this . child . getMaxIntrinsicWidth ( width ) : this . child . getMaxIntrinsicHeight ( width ) ;
73
+ }
74
+
75
+ Matrix3 _paintTransform ;
76
+
77
+ protected override void performLayout ( ) {
78
+ this . _paintTransform = null ;
79
+ if ( this . child != null ) {
80
+ this . child . layout ( this . _isVertical ? this . constraints . flipped : this . constraints , parentUsesSize : true ) ;
81
+ this . size = this . _isVertical
82
+ ? new Size ( this . child . size . height , this . child . size . width )
83
+ : this . child . size ;
84
+ this . _paintTransform = Matrix3 . I ( ) ;
85
+ this . _paintTransform . preTranslate ( this . size . width / 2.0f , this . size . height / 2.0f ) ;
86
+ this . _paintTransform . preRotate ( RotatedBoxUtils . _kQuarterTurnsInRadians * ( this . quarterTurns % 4 ) ) ;
87
+ this . _paintTransform . preTranslate ( - this . child . size . width / 2.0f , - this . child . size . height / 2.0f ) ;
88
+ }
89
+ else {
90
+ this . performResize ( ) ;
91
+ }
92
+ }
93
+
94
+ protected override bool hitTestChildren (
95
+ HitTestResult result ,
96
+ Offset position = null
97
+ ) {
98
+ D . assert ( this . _paintTransform != null || this . debugNeedsLayout || this . child == null ) ;
99
+ if ( this . child == null || this . _paintTransform == null ) {
100
+ return false ;
101
+ }
102
+
103
+
104
+ Matrix3 inverse = Matrix3 . I ( ) ;
105
+ this . _paintTransform . invert ( inverse ) ;
106
+ return this . child . hitTest ( result , position : inverse . mapPoint ( position ) ) ;
107
+ }
108
+
109
+ void _paintChild ( PaintingContext context , Offset offset ) {
110
+ context . paintChild ( this . child , offset ) ;
111
+ }
112
+
113
+ public override void paint ( PaintingContext context , Offset offset ) {
114
+ if ( this . child != null ) {
115
+ context . pushTransform ( this . needsCompositing , offset , this . _paintTransform , this . _paintChild ) ;
116
+ }
117
+ }
118
+
119
+ public override void applyPaintTransform ( RenderObject child , Matrix3 transform ) {
120
+ if ( this . _paintTransform != null ) {
121
+ transform . preConcat ( this . _paintTransform ) ;
122
+ }
123
+
124
+ base . applyPaintTransform ( child , transform ) ;
125
+ }
126
+ }
127
+ }
0 commit comments