Skip to content

Commit 0fdaea9

Browse files
committed
add quickReject()
1 parent a536932 commit 0fdaea9

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

23-clipping-magic/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
An app to learn how to clip objects on a canvas.
44

5-
<!-- <p align="center">
5+
<p align="center">
66
<img src="screenshot.png" style="width:528px;max-width: 100%;">
7-
</p> -->
7+
</p>
88

99
## Features
1010

23-clipping-magic/app/src/main/java/com/hfad/clippingmagic/ClippedView.kt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ClippedView @JvmOverloads constructor(
2626
private val textSize = resources.getDimension(R.dimen.textSize)
2727
private val columnOne = rectInset
2828
private val columnTwo = columnOne + rectInset + clipRectRight
29+
private val columnThree = columnTwo + rectInset + clipRectRight
2930
private val rowOne = rectInset
3031
private val rowTwo = rowOne + rectInset + clipRectBottom
3132
private val rowThree = rowTwo + rectInset + clipRectBottom
@@ -49,7 +50,7 @@ class ClippedView @JvmOverloads constructor(
4950
drawOutsideClippingExample(canvas)
5051
drawSkewedTextExample(canvas)
5152
drawTranslatedTextExample(canvas)
52-
// drawQuickRejectExample(canvas)
53+
drawQuickRejectExample(canvas)
5354
}
5455

5556
private fun drawClippedRectangle(canvas: Canvas){
@@ -230,5 +231,34 @@ class ClippedView @JvmOverloads constructor(
230231
}
231232

232233
private fun drawQuickRejectExample(canvas: Canvas){
234+
val inClipRectangle = RectF(clipRectRight / 2,
235+
clipRectBottom / 2,
236+
clipRectRight * 2,
237+
clipRectBottom * 2
238+
)
239+
val notInClipRectangle = RectF(RectF(clipRectRight+1,
240+
clipRectBottom+1,
241+
clipRectRight * 2,
242+
clipRectBottom * 2))
243+
canvas.save()
244+
canvas.translate(columnThree, rowOne)
245+
canvas.clipRect(
246+
clipRectLeft,clipRectTop,
247+
clipRectRight,clipRectBottom
248+
)
249+
if (
250+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
251+
canvas.quickReject(inClipRectangle)
252+
} else {
253+
@Suppress("DEPRECATION")
254+
canvas.quickReject(inClipRectangle, Canvas.EdgeType.AA)
255+
}
256+
) {
257+
canvas.drawColor(Color.WHITE)
258+
} else {
259+
canvas.drawColor(Color.BLACK)
260+
canvas.drawRect(inClipRectangle, paint)
261+
}
262+
canvas.restore()
233263
}
234264
}

23-clipping-magic/screenshot.png

136 KB
Loading

0 commit comments

Comments
 (0)