-
Notifications
You must be signed in to change notification settings - Fork 0
/
POPLayerExtras.mm
288 lines (238 loc) · 5.45 KB
/
POPLayerExtras.mm
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/**
Copyright (c) 2014-present, Facebook, Inc.
All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree. An additional grant
of patent rights can be found in the PATENTS file in the same directory.
*/
#import "POPLayerExtras.h"
#include "TransformationMatrix.h"
using namespace WebCore;
#define DECOMPOSE_TRANSFORM(L) \
TransformationMatrix _m(L.transform); \
TransformationMatrix::DecomposedType _d; \
_m.decompose(_d);
#define RECOMPOSE_TRANSFORM(L) \
_m.recompose(_d); \
L.transform = _m.transform3d();
#define RECOMPOSE_ROT_TRANSFORM(L) \
_m.recompose(_d, true); \
L.transform = _m.transform3d();
#define DECOMPOSE_SUBLAYER_TRANSFORM(L) \
TransformationMatrix _m(L.sublayerTransform); \
TransformationMatrix::DecomposedType _d; \
_m.decompose(_d);
#define RECOMPOSE_SUBLAYER_TRANSFORM(L) \
_m.recompose(_d); \
L.sublayerTransform = _m.transform3d();
#pragma mark - Scale
NS_INLINE void ensureNonZeroValue(CGFloat &f)
{
if (f == 0) {
f = 1e-6;
}
}
NS_INLINE void ensureNonZeroValue(CGPoint &p)
{
if (p.x == 0 && p.y == 0) {
p.x = 1e-6;
p.y = 1e-6;
}
}
CGFloat POPLayerGetScaleX(CALayer *l)
{
DECOMPOSE_TRANSFORM(l);
return _d.scaleX;
}
void POPLayerSetScaleX(CALayer *l, CGFloat f)
{
ensureNonZeroValue(f);
DECOMPOSE_TRANSFORM(l);
_d.scaleX = f;
RECOMPOSE_TRANSFORM(l);
}
CGFloat POPLayerGetScaleY(CALayer *l)
{
DECOMPOSE_TRANSFORM(l);
return _d.scaleY;
}
void POPLayerSetScaleY(CALayer *l, CGFloat f)
{
ensureNonZeroValue(f);
DECOMPOSE_TRANSFORM(l);
_d.scaleY = f;
RECOMPOSE_TRANSFORM(l);
}
CGFloat POPLayerGetScaleZ(CALayer *l)
{
DECOMPOSE_TRANSFORM(l);
return _d.scaleZ;
}
void POPLayerSetScaleZ(CALayer *l, CGFloat f)
{
ensureNonZeroValue(f);
DECOMPOSE_TRANSFORM(l);
_d.scaleZ = f;
RECOMPOSE_TRANSFORM(l);
}
CGPoint POPLayerGetScaleXY(CALayer *l)
{
DECOMPOSE_TRANSFORM(l);
return CGPointMake(_d.scaleX, _d.scaleY);
}
void POPLayerSetScaleXY(CALayer *l, CGPoint p)
{
ensureNonZeroValue(p);
DECOMPOSE_TRANSFORM(l);
_d.scaleX = p.x;
_d.scaleY = p.y;
RECOMPOSE_TRANSFORM(l);
}
#pragma mark - Translation
CGFloat POPLayerGetTranslationX(CALayer *l)
{
DECOMPOSE_TRANSFORM(l);
return _d.translateX;
}
void POPLayerSetTranslationX(CALayer *l, CGFloat f)
{
DECOMPOSE_TRANSFORM(l);
_d.translateX = f;
RECOMPOSE_TRANSFORM(l);
}
CGFloat POPLayerGetTranslationY(CALayer *l)
{
DECOMPOSE_TRANSFORM(l);
return _d.translateY;
}
void POPLayerSetTranslationY(CALayer *l, CGFloat f)
{
DECOMPOSE_TRANSFORM(l);
_d.translateY = f;
RECOMPOSE_TRANSFORM(l);
}
CGFloat POPLayerGetTranslationZ(CALayer *l)
{
DECOMPOSE_TRANSFORM(l);
return _d.translateZ;
}
void POPLayerSetTranslationZ(CALayer *l, CGFloat f)
{
DECOMPOSE_TRANSFORM(l);
_d.translateZ = f;
RECOMPOSE_TRANSFORM(l);
}
CGPoint POPLayerGetTranslationXY(CALayer *l)
{
DECOMPOSE_TRANSFORM(l);
return CGPointMake(_d.translateX, _d.translateY);
}
void POPLayerSetTranslationXY(CALayer *l, CGPoint p)
{
DECOMPOSE_TRANSFORM(l);
_d.translateX = p.x;
_d.translateY = p.y;
RECOMPOSE_TRANSFORM(l);
}
#pragma mark - Rotation
CGFloat POPLayerGetRotationX(CALayer *l)
{
DECOMPOSE_TRANSFORM(l);
return _d.rotateX;
}
void POPLayerSetRotationX(CALayer *l, CGFloat f)
{
DECOMPOSE_TRANSFORM(l);
_d.rotateX = f;
RECOMPOSE_ROT_TRANSFORM(l);
}
CGFloat POPLayerGetRotationY(CALayer *l)
{
DECOMPOSE_TRANSFORM(l);
return _d.rotateY;
}
void POPLayerSetRotationY(CALayer *l, CGFloat f)
{
DECOMPOSE_TRANSFORM(l);
_d.rotateY = f;
RECOMPOSE_ROT_TRANSFORM(l);
}
CGFloat POPLayerGetRotationZ(CALayer *l)
{
DECOMPOSE_TRANSFORM(l);
return _d.rotateZ;
}
void POPLayerSetRotationZ(CALayer *l, CGFloat f)
{
DECOMPOSE_TRANSFORM(l);
_d.rotateZ = f;
RECOMPOSE_ROT_TRANSFORM(l);
}
CGFloat POPLayerGetRotation(CALayer *l)
{
return POPLayerGetRotationZ(l);
}
void POPLayerSetRotation(CALayer *l, CGFloat f)
{
POPLayerSetRotationZ(l, f);
}
#pragma mark - Sublayer Scale
CGPoint POPLayerGetSubScaleXY(CALayer *l)
{
DECOMPOSE_SUBLAYER_TRANSFORM(l);
return CGPointMake(_d.scaleX, _d.scaleY);
}
void POPLayerSetSubScaleXY(CALayer *l, CGPoint p)
{
ensureNonZeroValue(p);
DECOMPOSE_SUBLAYER_TRANSFORM(l);
_d.scaleX = p.x;
_d.scaleY = p.y;
RECOMPOSE_SUBLAYER_TRANSFORM(l);
}
#pragma mark - Sublayer Translation
extern CGFloat POPLayerGetSubTranslationX(CALayer *l)
{
DECOMPOSE_SUBLAYER_TRANSFORM(l);
return _d.translateX;
}
extern void POPLayerSetSubTranslationX(CALayer *l, CGFloat f)
{
DECOMPOSE_SUBLAYER_TRANSFORM(l);
_d.translateX = f;
RECOMPOSE_SUBLAYER_TRANSFORM(l);
}
extern CGFloat POPLayerGetSubTranslationY(CALayer *l)
{
DECOMPOSE_SUBLAYER_TRANSFORM(l);
return _d.translateY;
}
extern void POPLayerSetSubTranslationY(CALayer *l, CGFloat f)
{
DECOMPOSE_SUBLAYER_TRANSFORM(l);
_d.translateY = f;
RECOMPOSE_SUBLAYER_TRANSFORM(l);
}
extern CGFloat POPLayerGetSubTranslationZ(CALayer *l)
{
DECOMPOSE_SUBLAYER_TRANSFORM(l);
return _d.translateZ;
}
extern void POPLayerSetSubTranslationZ(CALayer *l, CGFloat f)
{
DECOMPOSE_SUBLAYER_TRANSFORM(l);
_d.translateZ = f;
RECOMPOSE_SUBLAYER_TRANSFORM(l);
}
extern CGPoint POPLayerGetSubTranslationXY(CALayer *l)
{
DECOMPOSE_SUBLAYER_TRANSFORM(l);
return CGPointMake(_d.translateX, _d.translateY);
}
extern void POPLayerSetSubTranslationXY(CALayer *l, CGPoint p)
{
DECOMPOSE_SUBLAYER_TRANSFORM(l);
_d.translateX = p.x;
_d.translateY = p.y;
RECOMPOSE_SUBLAYER_TRANSFORM(l);
}