-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
502 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/kotlin/com/muedsa/snapshot/rendering/box/RenderClipOval.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.muedsa.snapshot.rendering.box | ||
|
||
import com.muedsa.geometry.Offset | ||
import com.muedsa.geometry.Size | ||
import com.muedsa.snapshot.rendering.ClipBehavior | ||
import com.muedsa.snapshot.rendering.PaintingContext | ||
import org.jetbrains.skia.Path | ||
import org.jetbrains.skia.Rect | ||
|
||
class RenderClipOval( | ||
clipper: ((Size) -> Rect)? = null, | ||
clipBehavior: ClipBehavior = ClipBehavior.ANTI_ALIAS, | ||
child: RenderBox? = null, | ||
) : RenderCustomClip<Rect>( | ||
clipper = clipper, | ||
clipBehavior = clipBehavior, | ||
child = child | ||
) { | ||
override val defaultClip: Rect | ||
get() = Offset.ZERO combine definiteSize | ||
|
||
private var cachedRect: Rect? = null | ||
private lateinit var cachedPath: Path | ||
|
||
private fun getClipPath(rect: Rect): Path { | ||
if (rect != cachedRect) { | ||
cachedRect = rect | ||
cachedPath = Path().addOval(cachedRect!!) | ||
} | ||
return cachedPath | ||
} | ||
|
||
override fun paint(context: PaintingContext, offset: Offset) { | ||
if (child != null) { | ||
if (clipBehavior != ClipBehavior.NONE) { | ||
context.doClipPath( | ||
offset = offset, | ||
bounds = Offset.ZERO combine definiteSize, | ||
clipPath = getClipPath(rect = getClip()), | ||
clipBehavior = clipBehavior | ||
) { c, o -> | ||
super.paint(c, o) | ||
} | ||
} else { | ||
context.paintChild(child, offset) | ||
} | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalStdlibApi::class) | ||
override fun debugPaint(context: PaintingContext, offset: Offset) { | ||
if (child != null) { | ||
super.debugPaint(context, offset) | ||
if (clipBehavior != ClipBehavior.NONE) { | ||
context.canvas.drawPath( | ||
Path().also { getClipPath(getClip()).offset(offset.x, offset.y, it) }, | ||
debugPaint!! | ||
) | ||
debugText!!.paint( | ||
context.canvas, | ||
offset + Offset((getClip().width - debugText!!.width) / 2f, -debugText!!.fontSize * 1.1f) | ||
) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/kotlin/com/muedsa/snapshot/rendering/box/RenderClipRRect.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.muedsa.snapshot.rendering.box | ||
|
||
import com.muedsa.geometry.Offset | ||
import com.muedsa.geometry.Size | ||
import com.muedsa.geometry.shift | ||
import com.muedsa.geometry.tlRadiusX | ||
import com.muedsa.snapshot.paint.decoration.BorderRadius | ||
import com.muedsa.snapshot.paint.decoration.BorderRadiusGeometry | ||
import com.muedsa.snapshot.rendering.ClipBehavior | ||
import com.muedsa.snapshot.rendering.PaintingContext | ||
import org.jetbrains.skia.RRect | ||
import org.jetbrains.skia.paragraph.Direction | ||
|
||
class RenderClipRRect( | ||
val borderRadius: BorderRadiusGeometry = BorderRadius.ZERO, | ||
clipper: ((Size) -> RRect)? = null, | ||
clipBehavior: ClipBehavior = ClipBehavior.ANTI_ALIAS, | ||
val textDirection: Direction? = null, | ||
child: RenderBox? = null, | ||
) : RenderCustomClip<RRect>( | ||
clipper = clipper, | ||
clipBehavior = clipBehavior, | ||
child = child | ||
) { | ||
|
||
override val defaultClip: RRect | ||
get() = borderRadius.resolve(textDirection).toRRect(rect = Offset.ZERO combine definiteSize) | ||
|
||
override fun paint(context: PaintingContext, offset: Offset) { | ||
if (child != null) { | ||
if (clipBehavior != ClipBehavior.NONE) { | ||
context.doClipRRect( | ||
offset = offset, | ||
bounds = getClip(), | ||
clipRRect = getClip(), | ||
clipBehavior = clipBehavior | ||
) { c, o -> | ||
super.paint(c, o) | ||
} | ||
} else { | ||
context.paintChild(child, offset) | ||
} | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalStdlibApi::class) | ||
override fun debugPaint(context: PaintingContext, offset: Offset) { | ||
if (child != null) { | ||
super.debugPaint(context, offset) | ||
if (clipBehavior != ClipBehavior.NONE) { | ||
context.canvas.drawRRect(getClip().shift(offset), debugPaint!!) | ||
debugText!!.paint(context.canvas, offset + Offset(getClip().tlRadiusX, -debugText!!.fontSize * 1.1f)) | ||
} | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/kotlin/com/muedsa/snapshot/rendering/box/RenderClipRect.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.muedsa.snapshot.rendering.box | ||
|
||
import com.muedsa.geometry.Offset | ||
import com.muedsa.geometry.Size | ||
import com.muedsa.geometry.shift | ||
import com.muedsa.snapshot.rendering.ClipBehavior | ||
import com.muedsa.snapshot.rendering.PaintingContext | ||
import org.jetbrains.skia.Rect | ||
|
||
class RenderClipRect( | ||
clipper: ((Size) -> Rect)? = null, | ||
clipBehavior: ClipBehavior = ClipBehavior.ANTI_ALIAS, | ||
child: RenderBox? = null, | ||
) : RenderCustomClip<Rect>( | ||
clipper = clipper, | ||
clipBehavior = clipBehavior, | ||
child = child | ||
) { | ||
|
||
override val defaultClip: Rect | ||
get() = Offset.ZERO combine definiteSize | ||
|
||
|
||
override fun paint(context: PaintingContext, offset: Offset) { | ||
if (child != null) { | ||
if (clipBehavior != ClipBehavior.NONE) { | ||
context.doClipRect( | ||
offset = offset, | ||
clipRect = getClip(), | ||
clipBehavior = clipBehavior | ||
) { c, o -> | ||
super.paint(c, o) | ||
} | ||
} else { | ||
context.paintChild(child, offset) | ||
} | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalStdlibApi::class) | ||
override fun debugPaint(context: PaintingContext, offset: Offset) { | ||
if (child != null) { | ||
super.debugPaint(context, offset) | ||
if (clipBehavior != ClipBehavior.NONE) { | ||
context.canvas.drawRect(getClip().shift(offset), debugPaint!!) | ||
debugText!!.paint(context.canvas, offset + Offset(getClip().width / 8f, -debugText!!.fontSize * 1.1f)) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/main/kotlin/com/muedsa/snapshot/rendering/flex/FlexFunction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../com/muedsa/snapshot/VerticalDirection.kt → ...pshot/rendering/flex/VerticalDirection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.muedsa.snapshot.widget | ||
|
||
import com.muedsa.geometry.Size | ||
import com.muedsa.snapshot.rendering.ClipBehavior | ||
import com.muedsa.snapshot.rendering.box.RenderBox | ||
import com.muedsa.snapshot.rendering.box.RenderClipOval | ||
import org.jetbrains.skia.Rect | ||
|
||
class ClipOval( | ||
val clipper: ((Size) -> Rect)? = null, | ||
val clipBehavior: ClipBehavior = ClipBehavior.ANTI_ALIAS, | ||
childBuilder: SingleWidgetBuilder? = null, | ||
) : SingleChildWidget(childBuilder = childBuilder) { | ||
|
||
override fun createRenderTree(): RenderBox = RenderClipOval( | ||
clipper = clipper, | ||
clipBehavior = clipBehavior, | ||
child = child?.createRenderTree() | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.