diff android/DWindows.kt @ 2537:cd9d2ba251d5

Android: Reimplement drawPolygon() using drawPath() instead of drawLines/Points(). Add some extra safety checks before calling into drawPolygon().
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 11 May 2021 22:44:45 +0000
parents d172ab2eddb6
children 1b3b40c89cd0
line wrap: on
line diff
--- a/android/DWindows.kt	Tue May 11 22:19:28 2021 +0000
+++ b/android/DWindows.kt	Tue May 11 22:44:45 2021 +0000
@@ -1971,12 +1971,12 @@
 
     fun drawPolygon(render: DWRender?, bitmap: Bitmap?, flags: Int, npoints: Int, x: IntArray, y: IntArray)
     {
-        var points = FloatArray(npoints*2)
+        // Create a path with all our points
+        val path = Path()
 
-        // Convert to a single IntArray
-        for (i in 0 until npoints) {
-            points[(i*2)] = x[i].toFloat()
-            points[(i*2)+1] = y[i].toFloat()
+        path.moveTo(x[0].toFloat(), y[0].toFloat())
+        for (i in 1 until npoints) {
+            path.lineTo(x[i].toFloat(), y[i].toFloat())
         }
 
         waitOnUiThread {
@@ -2001,7 +2001,7 @@
                 } else {
                     paint.style = Paint.Style.STROKE
                 }
-                canvas.drawPoints(points, paint)
+                canvas.drawPath(path, paint)
             }
         }
     }