comparison 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
comparison
equal deleted inserted replaced
2536:d172ab2eddb6 2537:cd9d2ba251d5
1969 } 1969 }
1970 } 1970 }
1971 1971
1972 fun drawPolygon(render: DWRender?, bitmap: Bitmap?, flags: Int, npoints: Int, x: IntArray, y: IntArray) 1972 fun drawPolygon(render: DWRender?, bitmap: Bitmap?, flags: Int, npoints: Int, x: IntArray, y: IntArray)
1973 { 1973 {
1974 var points = FloatArray(npoints*2) 1974 // Create a path with all our points
1975 1975 val path = Path()
1976 // Convert to a single IntArray 1976
1977 for (i in 0 until npoints) { 1977 path.moveTo(x[0].toFloat(), y[0].toFloat())
1978 points[(i*2)] = x[i].toFloat() 1978 for (i in 1 until npoints) {
1979 points[(i*2)+1] = y[i].toFloat() 1979 path.lineTo(x[i].toFloat(), y[i].toFloat())
1980 } 1980 }
1981 1981
1982 waitOnUiThread { 1982 waitOnUiThread {
1983 var canvas: Canvas? = null 1983 var canvas: Canvas? = null
1984 1984
1999 if((flags and 1) == 1) { 1999 if((flags and 1) == 1) {
2000 paint.style = Paint.Style.FILL_AND_STROKE 2000 paint.style = Paint.Style.FILL_AND_STROKE
2001 } else { 2001 } else {
2002 paint.style = Paint.Style.STROKE 2002 paint.style = Paint.Style.STROKE
2003 } 2003 }
2004 canvas.drawPoints(points, paint) 2004 canvas.drawPath(path, paint)
2005 } 2005 }
2006 } 2006 }
2007 } 2007 }
2008 2008
2009 fun drawArc(render: DWRender?, bitmap: Bitmap?, flags: Int, xorigin: Int, yorigin: Int, 2009 fun drawArc(render: DWRender?, bitmap: Bitmap?, flags: Int, xorigin: Int, yorigin: Int,