浏览代码

Implement ClipOval.

/main
Yuncong Zhang 5 年前
当前提交
14e9fa4f
共有 2 个文件被更改,包括 116 次插入16 次删除
  1. 95
      Runtime/rendering/proxy_box.cs
  2. 37
      Runtime/widgets/basic.cs

95
Runtime/rendering/proxy_box.cs


}
}
public class RenderClipOval : _RenderCustomClip<Rect> {
public RenderClipOval(
RenderBox child = null,
CustomClipper<Rect> clipper = null,
Clip clipBehavior = Clip.antiAlias
) : base(child: child, clipper: clipper, clipBehavior: clipBehavior) {
D.assert(clipBehavior != Clip.none);
}
Rect _cachedRect;
Path _cachedPath;
Path _getClipPath(Rect rect) {
if (rect != this._cachedRect) {
this._cachedRect = rect;
this._cachedPath = new Path();
this._cachedPath.addOval(this._cachedRect);
}
return this._cachedPath;
}
protected override Rect _defaultClip {
get { return Offset.zero & this.size; }
}
public override bool hitTest(HitTestResult result,
Offset position = null
) {
this._updateClip();
D.assert(this._clip != null);
Offset center = this._clip.center;
Offset offset = new Offset((position.dx - center.dx) / this._clip.width,
(position.dy - center.dy) / this._clip.height);
if (offset.distanceSquared > 0.25f) // x^2 + y^2 > r^2
{
return false;
}
return base.hitTest(result, position: position);
}
public override void paint(PaintingContext context, Offset offset) {
if (this.child != null) {
this._updateClip();
context.pushClipPath(this.needsCompositing, offset, this._clip, this._getClipPath(this._clip),
base.paint, clipBehavior: this.clipBehavior);
}
}
protected override void debugPaintSize(PaintingContext context, Offset offset) {
D.assert(() => {
if (this.child != null) {
base.debugPaintSize(context, offset);
context.canvas.drawPath(this._getClipPath(this._clip).shift(offset), this._debugPaint);
this._debugText.paint(context.canvas,
offset + new Offset((this._clip.width - this._debugText.width) / 2.0f,
-this._debugText.text.style.fontSize * 1.1f ?? 0.0f));
}
return true;
});
}
}
public class RenderClipPath : _RenderCustomClip<Path> {
public RenderClipPath(

return base.hitTest(result, position: position);
}
public override void paint(PaintingContext context, Offset offset) {
if (this.child != null) {
this._updateClip();

return base.hitTest(result, position: position);
}
public override void paint(PaintingContext context, Offset offset) {
if (this.child != null) {
this._updateClip();

}
else {
Canvas canvas = context.canvas;
if (this.elevation != 0.0) {
canvas.drawRect(
offsetBounds.inflate(20.0f),
_transparentPaint
);
canvas.drawShadow(
offsetPath,
this.shadowColor,
this.elevation,
this.color.alpha != 0xFF
);
}
if (this.elevation != 0.0) {
canvas.drawRect(
offsetBounds.inflate(20.0f),
_transparentPaint
);
canvas.drawShadow(
offsetPath,
this.shadowColor,
this.elevation,
this.color.alpha != 0xFF
);
}
Paint paint = new Paint {color = this.color, style = PaintingStyle.fill};
canvas.drawPath(offsetPath, paint);
context.clipPathAndPaint(offsetPath, this.clipBehavior,

37
Runtime/widgets/basic.cs


}
}
public class ClipOval : SingleChildRenderObjectWidget {
public ClipOval(
Key key = null,
CustomClipper<Rect> clipper = null,
Clip clipBehavior = Clip.antiAlias,
Widget child = null) : base(key: key, child: child
) {
this.clipper = clipper;
this.clipBehavior = clipBehavior;
}
public readonly CustomClipper<Rect> clipper;
public readonly Clip clipBehavior;
public override RenderObject createRenderObject(BuildContext context) {
return new RenderClipOval(clipper: this.clipper, clipBehavior: this.clipBehavior);
}
public override void updateRenderObject(BuildContext context, RenderObject _renderObject) {
RenderClipOval renderObject = _renderObject as RenderClipOval;
renderObject.clipper = this.clipper;
}
public override void didUnmountRenderObject(RenderObject _renderObject) {
RenderClipOval renderObject = _renderObject as RenderClipOval;
renderObject.clipper = null;
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new DiagnosticsProperty<CustomClipper<Rect>>("clipper", this.clipper, defaultValue: null));
}
}
public class ClipPath : SingleChildRenderObjectWidget {
public ClipPath(
Key key = null,

return this.builder(context);
}
}
}
}
正在加载...
取消
保存