Mercurial > dwindows
diff android/DWindows.kt @ 2637:22105f99dd6a
Android: Add support for transparent background color for text drawing.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 11 Aug 2021 23:24:06 +0000 |
parents | dcd71b04cc46 |
children | 3edc64443b71 |
line wrap: on
line diff
--- a/android/DWindows.kt Wed Aug 11 20:32:13 2021 +0000 +++ b/android/DWindows.kt Wed Aug 11 23:24:06 2021 +0000 @@ -767,7 +767,7 @@ var darkMode: Int = -1 var lastClickView: View? = null private var paint = Paint() - private var bgcolor: Int = 0 + private var bgcolor: Int? = null private var menuBar: DWMenu? = null private var defaultItem: View? = null private var fileURI: Uri? = null @@ -3140,21 +3140,23 @@ colorsSet(fgColor, bgColor) // Save the old color for later... val rect = Rect() - val oldcolor = paint.color - // Prepare to draw the background rect - paint.color = bgcolor paint.flags = 0 paint.style = Paint.Style.FILL_AND_STROKE paint.textAlign = Paint.Align.LEFT paint.getTextBounds(text, 0, text.length, rect) val textheight = rect.bottom - rect.top - rect.top += y + textheight - rect.bottom += y + textheight - rect.left += x - rect.right += x - canvas.drawRect(rect, paint) - // Restore the color and prepare to draw text - paint.color = oldcolor + if(bgcolor != null) { + val oldcolor = paint.color + // Prepare to draw the background rect + paint.color = bgcolor as Int + rect.top += y + textheight + rect.bottom += y + textheight + rect.left += x + rect.right += x + canvas.drawRect(rect, paint) + // Restore the color and prepare to draw text + paint.color = oldcolor + } paint.style = Paint.Style.STROKE canvas.drawText(text, x.toFloat(), y.toFloat() + textheight.toFloat(), paint) } @@ -3298,7 +3300,11 @@ { waitOnUiThread { paint.color = colorFromDW(fgColor) - this.bgcolor = colorFromDW(bgColor) + if(bgColor != -1L) { + this.bgcolor = colorFromDW(bgColor) + } else { + this.bgcolor = null + } } } @@ -3476,7 +3482,7 @@ if(Looper.getMainLooper() == Looper.myLooper()) { val starttime = System.currentTimeMillis() - // Waiting for Idle to make sure Toast gets rendered. + // Waiting for Idle to check for sleep expiration Looper.myQueue().addIdleHandler(object : MessageQueue.IdleHandler { var thrown: Boolean = false