Yuncong Zhang
6 年前
当前提交
d89467db
共有 3 个文件被更改,包括 164 次插入 和 1 次删除
-
46Runtime/widgets/basic.cs
-
108Runtime/painting/fractional_offset.cs
-
11Runtime/painting/fractional_offset.cs.meta
|
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.ui; |
|||
|
|||
namespace Unity.UIWidgets.painting { |
|||
public class FractionalOffset : Alignment { |
|||
public FractionalOffset(float dx, float dy) |
|||
: base(dx * 2.0f - 1.0f, dy * 2.0f - 1.0f) { |
|||
} |
|||
|
|||
public static FractionalOffset fromOffsetAndSize(Offset offset, Size size) { |
|||
D.assert(size != null); |
|||
D.assert(offset != null); |
|||
return new FractionalOffset( |
|||
offset.dx / size.width, |
|||
offset.dy / size.height |
|||
); |
|||
} |
|||
|
|||
public static FractionalOffset fromOffsetAndRect(Offset offset, Rect rect) { |
|||
return fromOffsetAndSize( |
|||
offset - rect.topLeft, |
|||
rect.size |
|||
); |
|||
} |
|||
|
|||
public float dx { |
|||
get { return (this.x + 1.0f) / 2.0f; } |
|||
} |
|||
|
|||
public float dy { |
|||
get { return (this.y + 1.0f) / 2.0f; } |
|||
} |
|||
|
|||
public readonly FractionalOffset topLeft = new FractionalOffset(0.0f, 0.0f); |
|||
|
|||
public readonly FractionalOffset topCenter = new FractionalOffset(0.5f, 0.0f); |
|||
|
|||
public readonly FractionalOffset topRight = new FractionalOffset(1.0f, 0.0f); |
|||
|
|||
public readonly FractionalOffset centerLeft = new FractionalOffset(0.0f, 0.5f); |
|||
|
|||
public readonly FractionalOffset center = new FractionalOffset(0.5f, 0.5f); |
|||
|
|||
public readonly FractionalOffset centerRight = new FractionalOffset(1.0f, 0.5f); |
|||
|
|||
public readonly FractionalOffset bottomLeft = new FractionalOffset(0.0f, 1.0f); |
|||
|
|||
public readonly FractionalOffset bottomCenter = new FractionalOffset(0.5f, 1.0f); |
|||
|
|||
public readonly FractionalOffset bottomRight = new FractionalOffset(1.0f, 1.0f); |
|||
|
|||
public static Alignment operator -(FractionalOffset a, Alignment b) { |
|||
if (!(b is FractionalOffset)) { |
|||
return (a as Alignment) - b; |
|||
} |
|||
|
|||
FractionalOffset typedOther = (FractionalOffset) b; |
|||
return new FractionalOffset(a.dx - typedOther.dx, a.dy - typedOther.dy); |
|||
} |
|||
|
|||
public static Alignment operator +(FractionalOffset a, Alignment b) { |
|||
if (!(b is FractionalOffset)) { |
|||
return (a as Alignment) + b; |
|||
} |
|||
|
|||
FractionalOffset typedOther = (FractionalOffset) b; |
|||
return new FractionalOffset(a.dx + typedOther.dx, a.dy + typedOther.dy); |
|||
} |
|||
|
|||
public static FractionalOffset operator -(FractionalOffset a) { |
|||
return new FractionalOffset(-a.dx, -a.dy); |
|||
} |
|||
|
|||
public static FractionalOffset operator *(FractionalOffset a, float b) { |
|||
return new FractionalOffset(a.dx * b, a.dy * b); |
|||
} |
|||
|
|||
public static FractionalOffset operator /(FractionalOffset a, float b) { |
|||
return new FractionalOffset(a.dx / b, a.dy / b); |
|||
} |
|||
|
|||
public static FractionalOffset operator %(FractionalOffset a, float b) { |
|||
return new FractionalOffset(a.dx % b, a.dy % b); |
|||
} |
|||
|
|||
static FractionalOffset lerp(FractionalOffset a, FractionalOffset b, float t) { |
|||
D.assert(t != null); |
|||
if (a == null && b == null) { |
|||
return null; |
|||
} |
|||
|
|||
if (a == null) { |
|||
return new FractionalOffset(MathUtils.lerpFloat(0.5f, b.dx, t), MathUtils.lerpFloat(0.5f, b.dy, t)); |
|||
} |
|||
|
|||
if (b == null) { |
|||
return new FractionalOffset(MathUtils.lerpFloat(a.dx, 0.5f, t), MathUtils.lerpFloat(a.dy, 0.5f, t)); |
|||
} |
|||
|
|||
return new FractionalOffset(MathUtils.lerpFloat(a.dx, b.dx, t), MathUtils.lerpFloat(a.dy, b.dy, t)); |
|||
} |
|||
|
|||
public override string ToString() { |
|||
return $"FractionalOffset({this.dx:0.0}, " + |
|||
$"{this.dy:0.0})"; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c3fea20fd545541eeaff7acf1bd32751 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue