浏览代码

border

/siyaoH-1.17-PlatformMessage
siyao 4 年前
当前提交
9f81e5c5
共有 2 个文件被更改,包括 628 次插入31 次删除
  1. 649
      com.unity.uiwidgets/Runtime/painting/border_radius.cs
  2. 10
      com.unity.uiwidgets/Runtime/painting/gradient.cs

649
com.unity.uiwidgets/Runtime/painting/border_radius.cs


using System;
using System.Text;
using Unity.UIWidgets.foundation;
public class BorderRadius : IEquatable<BorderRadius> {
public abstract class BorderRadiusGeometry : IEquatable<BorderRadiusGeometry> {
public BorderRadiusGeometry() {
}
protected virtual Radius _topLeft { get; }
protected virtual Radius _topRight { get; }
protected virtual Radius _bottomLeft { get; }
protected virtual Radius _bottomRight { get; }
protected virtual Radius _topStart { get; }
protected virtual Radius _topEnd { get; }
protected virtual Radius _bottomStart { get; }
protected virtual Radius _bottomEnd { get; }
public virtual BorderRadiusGeometry subtract(BorderRadiusGeometry other) {
return new _MixedBorderRadius(
_topLeft - other._topLeft,
_topRight - other._topRight,
_bottomLeft - other._bottomLeft,
_bottomRight - other._bottomRight,
_topStart - other._topStart,
_topEnd - other._topEnd,
_bottomStart - other._bottomStart,
_bottomEnd - other._bottomEnd
);
}
public virtual BorderRadiusGeometry add(BorderRadiusGeometry other) {
return new _MixedBorderRadius(
_topLeft + other._topLeft,
_topRight + other._topRight,
_bottomLeft + other._bottomLeft,
_bottomRight + other._bottomRight,
_topStart + other._topStart,
_topEnd + other._topEnd,
_bottomStart + other._bottomStart,
_bottomEnd + other._bottomEnd
);
}
public abstract BorderRadiusGeometry SelfMinus();
public static BorderRadiusGeometry operator -(BorderRadiusGeometry other) {
return other.SelfMinus();
}
public abstract BorderRadiusGeometry Multiply(float other);
public static BorderRadiusGeometry operator *(BorderRadiusGeometry self, float other) {
return self.Multiply(other);
}
public abstract BorderRadiusGeometry Divide(float other);
public static BorderRadiusGeometry operator /(BorderRadiusGeometry self, float other) {
return self.Divide(other);
}
public abstract BorderRadiusGeometry Remainder(float other);
public static BorderRadiusGeometry operator %(BorderRadiusGeometry self, float other) {
return self.Remainder(other);
}
public static BorderRadiusGeometry lerp(BorderRadiusGeometry a, BorderRadiusGeometry b, float t) {
if (a == null && b == null)
return null;
a = a ?? BorderRadius.zero;
b = b ?? BorderRadius.zero;
return a.add((b.subtract(a)) * t);
}
public abstract BorderRadius resolve(TextDirection direction);
//
// @override
// String toString() {
// String visual, logical;
// if (_topLeft == _topRight &&
// _topRight == _bottomLeft &&
// _bottomLeft == _bottomRight) {
// if (_topLeft != Radius.zero) {
// if (_topLeft.x == _topLeft.y) {
// visual = 'BorderRadius.circular(${_topLeft.x.toStringAsFixed(1)})';
// }
// else {
// visual = 'BorderRadius.all($_topLeft)';
// }
// }
// }
// else {
// // visuals aren't the same and at least one isn't zero
// final StringBuffer result = StringBuffer();
// result.write('BorderRadius.only(');
// bool comma = false;
// if (_topLeft != Radius.zero) {
// result.write('topLeft: $_topLeft');
// comma = true;
// }
//
// if (_topRight != Radius.zero) {
// if (comma)
// result.write(', ');
// result.write('topRight: $_topRight');
// comma = true;
// }
//
// if (_bottomLeft != Radius.zero) {
// if (comma)
// result.write(', ');
// result.write('bottomLeft: $_bottomLeft');
// comma = true;
// }
//
// if (_bottomRight != Radius.zero) {
// if (comma)
// result.write(', ');
// result.write('bottomRight: $_bottomRight');
// }
//
// result.write(')');
// visual = result.toString();
// }
//
// if (_topStart == _topEnd &&
// _topEnd == _bottomEnd &&
// _bottomEnd == _bottomStart) {
// if (_topStart != Radius.zero) {
// if (_topStart.x == _topStart.y) {
// logical = 'BorderRadiusDirectional.circular(${_topStart.x.toStringAsFixed(1)})';
// }
// else {
// logical = 'BorderRadiusDirectional.all($_topStart)';
// }
// }
// }
// else {
// // logicals aren't the same and at least one isn't zero
// final StringBuffer result = StringBuffer();
// result.write('BorderRadiusDirectional.only(');
// bool comma = false;
// if (_topStart != Radius.zero) {
// result.write('topStart: $_topStart');
// comma = true;
// }
//
// if (_topEnd != Radius.zero) {
// if (comma)
// result.write(', ');
// result.write('topEnd: $_topEnd');
// comma = true;
// }
//
// if (_bottomStart != Radius.zero) {
// if (comma)
// result.write(', ');
// result.write('bottomStart: $_bottomStart');
// comma = true;
// }
//
// if (_bottomEnd != Radius.zero) {
// if (comma)
// result.write(', ');
// result.write('bottomEnd: $_bottomEnd');
// }
//
// result.write(')');
// logical = result.toString();
// }
//
// if (visual != null && logical != null)
// return '$visual + $logical';
// if (visual != null)
// return visual;
// if (logical != null)
// return logical;
// return 'BorderRadius.zero';
// }
public static bool operator ==(BorderRadiusGeometry left, BorderRadiusGeometry right) {
return Equals(left, right);
}
public static bool operator !=(BorderRadiusGeometry left, BorderRadiusGeometry right) {
return Equals(left, right);
}
public bool Equals(BorderRadiusGeometry other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
return Equals(_topLeft, other._topLeft) && Equals(_topRight, other._topRight) &&
Equals(_bottomLeft, other._bottomLeft) && Equals(_bottomRight, other._bottomRight) &&
Equals(_topStart, other._topStart) && Equals(_topEnd, other._topEnd) &&
Equals(_bottomStart, other._bottomStart) && Equals(_bottomEnd, other._bottomEnd);
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) {
return false;
}
if (ReferenceEquals(this, obj)) {
return true;
}
if (obj.GetType() != GetType()) {
return false;
}
return Equals((BorderRadiusGeometry) obj);
}
public override int GetHashCode() {
unchecked {
var hashCode = (_topLeft != null ? _topLeft.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (_topRight != null ? _topRight.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (_bottomLeft != null ? _bottomLeft.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (_bottomRight != null ? _bottomRight.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (_topStart != null ? _topStart.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (_topEnd != null ? _topEnd.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (_bottomStart != null ? _bottomStart.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (_bottomEnd != null ? _bottomEnd.GetHashCode() : 0);
return hashCode;
}
}
}
public class BorderRadius : BorderRadiusGeometry, IEquatable<BorderRadius> {
BorderRadius(
Radius topLeft,
Radius topRight,

public static readonly BorderRadius zero = all(Radius.zero);
public readonly Radius topLeft;
protected override Radius _topLeft {
get => topLeft;
}
public readonly Radius bottomRight;
protected override Radius _topRight {
get => topRight;
}
protected override Radius _bottomLeft {
get => bottomLeft;
}
public readonly Radius bottomRight;
protected override Radius _bottomRight {
get => bottomRight;
}
protected override Radius _topStart {
get => Radius.zero;
}
protected override Radius _topEnd {
get => Radius.zero;
}
protected override Radius _bottomStart {
get => Radius.zero;
}
protected override Radius _bottomEnd {
get => Radius.zero;
}
public RRect toRRect(Rect rect) {
return RRect.fromRectAndCorners(
rect,

);
}
public static BorderRadius operator -(BorderRadius it) {
public override BorderRadiusGeometry SelfMinus() {
topLeft: -it.topLeft,
topRight: -it.topRight,
bottomLeft: -it.bottomLeft,
bottomRight: -it.bottomRight
topLeft: -topLeft,
topRight: -topRight,
bottomLeft: -bottomLeft,
bottomRight: -bottomRight
public static BorderRadius operator *(BorderRadius it, float other) {
public override BorderRadiusGeometry Multiply(float other) {
topLeft: it.topLeft * other,
topRight: it.topRight * other,
bottomLeft: it.bottomLeft * other,
bottomRight: it.bottomRight * other
topLeft: topLeft * other,
topRight: topRight * other,
bottomLeft: bottomLeft * other,
bottomRight: bottomRight * other
public static BorderRadius operator /(BorderRadius it, float other) {
public override BorderRadiusGeometry Divide(float other) {
topLeft: it.topLeft / other,
topRight: it.topRight / other,
bottomLeft: it.bottomLeft / other,
bottomRight: it.bottomRight / other
topLeft: topLeft / other,
topRight: topRight / other,
bottomLeft: bottomLeft / other,
bottomRight: bottomRight / other
public static BorderRadius operator %(BorderRadius it, float other) {
public override BorderRadiusGeometry Remainder(float other) {
topLeft: it.topLeft % other,
topRight: it.topRight % other,
bottomLeft: it.bottomLeft % other,
bottomRight: it.bottomRight % other
topLeft: topLeft % other,
topRight: topRight % other,
bottomLeft: bottomLeft % other,
bottomRight: bottomRight % other
);
}

}
if (a == null) {
return b * t;
return (BorderRadius) (b * t);
return a * (1.0f - t);
return (BorderRadius) (a * (1.0f - t));
}
return only(

public static bool operator !=(BorderRadius a, BorderRadius b) {
return !Equals(a, b);
}
public BorderRadius resolve(TextDirection? direction) => this;
public override BorderRadius resolve(TextDirection textDirection) => this;
public override string ToString() {
string visual = null;

}
return "BorderRadius.zero";
}
}
public class BorderRadiusDirectional : BorderRadiusGeometry {
BorderRadiusDirectional(
Radius topStart,
Radius topEnd,
Radius bottomStart,
Radius bottomEnd) {
this.topStart = topStart ?? Radius.zero;
this.topEnd = topEnd ?? Radius.zero;
this.bottomStart = bottomStart ?? Radius.zero;
this.bottomEnd = bottomEnd ?? Radius.zero;
}
public static BorderRadiusDirectional all(Radius radius) {
return only(
topStart: radius,
topEnd: radius,
bottomStart: radius,
bottomEnd: radius
);
}
public static BorderRadiusDirectional circular(float radius) {
return all(
Radius.circular(radius)
);
}
public static BorderRadiusDirectional vertical(
Radius top = null,
Radius bottom = null
) {
top = top ?? Radius.zero;
bottom = bottom ?? Radius.zero;
return only(
topStart: top,
topEnd: top,
bottomStart: bottom,
bottomEnd: bottom
);
}
public static BorderRadiusDirectional horizontal(
Radius start = null,
Radius end = null
) {
start = start ?? Radius.zero;
end = end ?? Radius.zero;
return only(
topStart: start,
topEnd: end,
bottomStart: start,
bottomEnd: end
);
}
public static BorderRadiusDirectional only(
Radius topStart,
Radius topEnd,
Radius bottomStart,
Radius bottomEnd) {
return new BorderRadiusDirectional(topStart, topEnd, bottomStart, bottomEnd);
}
public static readonly BorderRadiusDirectional zero = BorderRadiusDirectional.all(Radius.zero);
public readonly Radius topStart;
protected override Radius _topStart {
get => topStart;
}
public readonly Radius topEnd;
protected override Radius _topEnd {
get => topEnd;
}
public readonly Radius bottomStart;
protected override Radius _bottomStart {
get => bottomStart;
}
public readonly Radius bottomEnd;
protected override Radius _bottomEnd {
get => bottomEnd;
}
protected override Radius _topLeft {
get => Radius.zero;
}
protected override Radius _topRight {
get => Radius.zero;
}
protected override Radius _bottomLeft {
get => Radius.zero;
}
protected override Radius _bottomRight {
get => Radius.zero;
}
public override BorderRadiusGeometry subtract(BorderRadiusGeometry other) {
if (other is BorderRadiusDirectional borderRadiusDirectional)
return this - borderRadiusDirectional;
return base.subtract(other);
}
public override BorderRadiusGeometry add(BorderRadiusGeometry other) {
if (other is BorderRadiusDirectional)
return this + (BorderRadiusDirectional) other;
return base.add(other);
}
public static BorderRadiusDirectional operator -(BorderRadiusDirectional self, BorderRadiusDirectional other) {
return BorderRadiusDirectional.only(
topStart: self.topStart - other.topStart,
topEnd: self.topEnd - other.topEnd,
bottomStart: self.bottomStart - other.bottomStart,
bottomEnd: self.bottomEnd - other.bottomEnd
);
}
public static BorderRadiusDirectional operator +(BorderRadiusDirectional other, BorderRadiusDirectional right) {
return BorderRadiusDirectional.only(
topStart: other.topStart + right.topStart,
topEnd: other.topEnd + right.topEnd,
bottomStart: other.bottomStart + right.bottomStart,
bottomEnd: other.bottomEnd + right.bottomEnd
);
}
public override BorderRadiusGeometry SelfMinus() {
return BorderRadiusDirectional.only(
topStart: -topStart,
topEnd: -topEnd,
bottomStart: -bottomStart,
bottomEnd: -bottomEnd
);
}
public override BorderRadiusGeometry Multiply(float other) {
return BorderRadiusDirectional.only(
topStart: topStart * other,
topEnd: topEnd * other,
bottomStart: bottomStart * other,
bottomEnd: bottomEnd * other
);
}
public override BorderRadiusGeometry Divide(float other) {
return BorderRadiusDirectional.only(
topStart: topStart / other,
topEnd: topEnd / other,
bottomStart: bottomStart / other,
bottomEnd: bottomEnd / other
);
}
public override BorderRadiusGeometry Remainder(float other) {
return BorderRadiusDirectional.only(
topStart: topStart % other,
topEnd: topEnd % other,
bottomStart: bottomStart % other,
bottomEnd: bottomEnd % other
);
}
public static BorderRadiusDirectional lerp(BorderRadiusDirectional a, BorderRadiusDirectional b, float t) {
if (a == null && b == null)
return null;
if (a == null)
return (BorderRadiusDirectional) (b * t);
if (b == null)
return (BorderRadiusDirectional) (a * (1.0f - t));
return BorderRadiusDirectional.only(
topStart: Radius.lerp(a.topStart, b.topStart, t),
topEnd: Radius.lerp(a.topEnd, b.topEnd, t),
bottomStart: Radius.lerp(a.bottomStart, b.bottomStart, t),
bottomEnd: Radius.lerp(a.bottomEnd, b.bottomEnd, t)
);
}
public override BorderRadius resolve(TextDirection direction) {
switch (direction) {
case TextDirection.rtl:
return BorderRadius.only(
topLeft: topEnd,
topRight: topStart,
bottomLeft: bottomEnd,
bottomRight: bottomStart
);
case TextDirection.ltr:
return BorderRadius.only(
topLeft: topStart,
topRight: topEnd,
bottomLeft: bottomStart,
bottomRight: bottomEnd
);
}
return null;
}
}
class _MixedBorderRadius : BorderRadiusGeometry {
internal _MixedBorderRadius(
Radius _topLeft,
Radius _topRight,
Radius _bottomLeft,
Radius _bottomRight,
Radius _topStart,
Radius _topEnd,
Radius _bottomStart,
Radius _bottomEnd) {
this._topLeft = _topLeft;
this._topRight = _topRight;
this._bottomLeft = _bottomLeft;
this._bottomRight = _bottomRight;
this._topStart = _topStart;
this._topEnd = _topEnd;
this._bottomStart = _bottomStart;
this._bottomEnd = _bottomEnd;
}
protected override Radius _topLeft { get; }
protected override Radius _topRight { get; }
protected override Radius _bottomLeft { get; }
protected override Radius _bottomRight { get; }
protected override Radius _topStart { get; }
protected override Radius _topEnd { get; }
protected override Radius _bottomStart { get; }
protected override Radius _bottomEnd { get; }
public override BorderRadiusGeometry SelfMinus() {
return new _MixedBorderRadius(
-_topLeft,
-_topRight,
-_bottomLeft,
-_bottomRight,
-_topStart,
-_topEnd,
-_bottomStart,
-_bottomEnd
);
}
public override BorderRadiusGeometry Multiply(float other) {
return new _MixedBorderRadius(
_topLeft * other,
_topRight * other,
_bottomLeft * other,
_bottomRight * other,
_topStart * other,
_topEnd * other,
_bottomStart * other,
_bottomEnd * other
);
}
public override BorderRadiusGeometry Divide(float other) {
return new _MixedBorderRadius(
_topLeft / other,
_topRight / other,
_bottomLeft / other,
_bottomRight / other,
_topStart / other,
_topEnd / other,
_bottomStart / other,
_bottomEnd / other
);
}
public override BorderRadiusGeometry Remainder(float other) {
return new _MixedBorderRadius(
_topLeft % other,
_topRight % other,
_bottomLeft % other,
_bottomRight % other,
_topStart % other,
_topEnd % other,
_bottomStart % other,
_bottomEnd % other
);
}
public override BorderRadius resolve(TextDirection direction) {
switch (direction) {
case TextDirection.rtl:
return BorderRadius.only(
topLeft: _topLeft + _topEnd,
topRight: _topRight + _topStart,
bottomLeft: _bottomLeft + _bottomEnd,
bottomRight: _bottomRight + _bottomStart
);
case TextDirection.ltr:
return BorderRadius.only(
topLeft: _topLeft + _topStart,
topRight: _topRight + _topEnd,
bottomLeft: _bottomLeft + _bottomStart,
bottomRight: _bottomRight + _bottomEnd
);
}
return null;
}
}
}

10
com.unity.uiwidgets/Runtime/painting/gradient.cs


}
public readonly List<Color> colors;
public readonly List<float> stops;
public readonly GradientTransform transform;

}
public override string ToString() {
return $"{GetType()}({begin}, {end}," +
return $"{foundation_.objectRuntimeType(this, "LinearGradient")}({begin}, {end}," +
$"{colors.toStringList()}, {stops.toStringList()}, {tileMode})";
}
}

}
public override string ToString() {
return $"{GetType()}({center}, {radius}," +
return $"{foundation_.objectRuntimeType(this, "RadialGradient")}({center}, {radius}," +
$"{colors.toStringList()}, {stops.toStringList()}, {tileMode})";
}
}

}
public override string ToString() {
return $"{GetType()}({center}, {startAngle}, {endAngle}, " +
$"{colors.toStringList()}, {stops.toStringList()}, {tileMode})";
return $"{foundation_.objectRuntimeType(this, "SweepGradient")}({center}, {startAngle}," +
$" {endAngle}, {colors.toStringList()}, {stops.toStringList()}, {tileMode})";
}
}
}
正在加载...
取消
保存