@@ -983,6 +983,70 @@ protected override void debugPaintSize(PaintingContext context, Offset offset) {
983
983
}
984
984
}
985
985
986
+ public class RenderClipOval : _RenderCustomClip < Rect > {
987
+ public RenderClipOval (
988
+ RenderBox child = null ,
989
+ CustomClipper < Rect > clipper = null ,
990
+ Clip clipBehavior = Clip . antiAlias
991
+ ) : base ( child : child , clipper : clipper , clipBehavior : clipBehavior ) {
992
+ D . assert ( clipBehavior != Clip . none ) ;
993
+ }
994
+
995
+ Rect _cachedRect ;
996
+ Path _cachedPath ;
997
+
998
+ Path _getClipPath ( Rect rect ) {
999
+ if ( rect != this . _cachedRect ) {
1000
+ this . _cachedRect = rect ;
1001
+ this . _cachedPath = new Path ( ) ;
1002
+ this . _cachedPath . addOval ( this . _cachedRect ) ;
1003
+ }
1004
+
1005
+ return this . _cachedPath ;
1006
+ }
1007
+
1008
+ protected override Rect _defaultClip {
1009
+ get { return Offset . zero & this . size ; }
1010
+ }
1011
+
1012
+ public override bool hitTest ( HitTestResult result ,
1013
+ Offset position = null
1014
+ ) {
1015
+ this . _updateClip ( ) ;
1016
+ D . assert ( this . _clip != null ) ;
1017
+ Offset center = this . _clip . center ;
1018
+ Offset offset = new Offset ( ( position . dx - center . dx ) / this . _clip . width ,
1019
+ ( position . dy - center . dy ) / this . _clip . height ) ;
1020
+ if ( offset . distanceSquared > 0.25f ) // x^2 + y^2 > r^2
1021
+ {
1022
+ return false ;
1023
+ }
1024
+
1025
+ return base . hitTest ( result , position : position ) ;
1026
+ }
1027
+
1028
+ public override void paint ( PaintingContext context , Offset offset ) {
1029
+ if ( this . child != null ) {
1030
+ this . _updateClip ( ) ;
1031
+ context . pushClipPath ( this . needsCompositing , offset , this . _clip , this . _getClipPath ( this . _clip ) ,
1032
+ base . paint , clipBehavior : this . clipBehavior ) ;
1033
+ }
1034
+ }
1035
+
1036
+ protected override void debugPaintSize ( PaintingContext context , Offset offset ) {
1037
+ D . assert ( ( ) => {
1038
+ if ( this . child != null ) {
1039
+ base . debugPaintSize ( context , offset ) ;
1040
+ context . canvas . drawPath ( this . _getClipPath ( this . _clip ) . shift ( offset ) , this . _debugPaint ) ;
1041
+ this . _debugText . paint ( context . canvas ,
1042
+ offset + new Offset ( ( this . _clip . width - this . _debugText . width ) / 2.0f ,
1043
+ - this . _debugText . text . style . fontSize * 1.1f ?? 0.0f ) ) ;
1044
+ }
1045
+
1046
+ return true ;
1047
+ } ) ;
1048
+ }
1049
+ }
986
1050
987
1051
public class RenderClipPath : _RenderCustomClip < Path > {
988
1052
public RenderClipPath (
@@ -1194,7 +1258,7 @@ public override bool hitTest(HitTestResult result, Offset position = null) {
1194
1258
return base . hitTest ( result , position : position ) ;
1195
1259
}
1196
1260
1197
-
1261
+
1198
1262
public override void paint ( PaintingContext context , Offset offset ) {
1199
1263
if ( this . child != null ) {
1200
1264
this . _updateClip ( ) ;
@@ -1282,7 +1346,7 @@ public override bool hitTest(HitTestResult result, Offset position = null) {
1282
1346
return base . hitTest ( result , position : position ) ;
1283
1347
}
1284
1348
1285
-
1349
+
1286
1350
public override void paint ( PaintingContext context , Offset offset ) {
1287
1351
if ( this . child != null ) {
1288
1352
this . _updateClip ( ) ;
@@ -1301,19 +1365,20 @@ public override void paint(PaintingContext context, Offset offset) {
1301
1365
}
1302
1366
else {
1303
1367
Canvas canvas = context . canvas ;
1304
- if ( this . elevation != 0.0 ) {
1305
- canvas . drawRect (
1306
- offsetBounds . inflate ( 20.0f ) ,
1307
- _transparentPaint
1308
- ) ;
1309
-
1310
- canvas . drawShadow (
1311
- offsetPath ,
1312
- this . shadowColor ,
1313
- this . elevation ,
1314
- this . color . alpha != 0xFF
1315
- ) ;
1316
- }
1368
+ if ( this . elevation != 0.0 ) {
1369
+ canvas . drawRect (
1370
+ offsetBounds . inflate ( 20.0f ) ,
1371
+ _transparentPaint
1372
+ ) ;
1373
+
1374
+ canvas . drawShadow (
1375
+ offsetPath ,
1376
+ this . shadowColor ,
1377
+ this . elevation ,
1378
+ this . color . alpha != 0xFF
1379
+ ) ;
1380
+ }
1381
+
1317
1382
Paint paint = new Paint { color = this . color , style = PaintingStyle . fill } ;
1318
1383
canvas . drawPath ( offsetPath , paint ) ;
1319
1384
context . clipPathAndPaint ( offsetPath , this . clipBehavior ,
0 commit comments