comparison 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
comparison
equal deleted inserted replaced
2636:038f83009cdb 2637:22105f99dd6a
765 var threadCond = threadLock.newCondition() 765 var threadCond = threadLock.newCondition()
766 var notificationID: Int = 0 766 var notificationID: Int = 0
767 var darkMode: Int = -1 767 var darkMode: Int = -1
768 var lastClickView: View? = null 768 var lastClickView: View? = null
769 private var paint = Paint() 769 private var paint = Paint()
770 private var bgcolor: Int = 0 770 private var bgcolor: Int? = null
771 private var menuBar: DWMenu? = null 771 private var menuBar: DWMenu? = null
772 private var defaultItem: View? = null 772 private var defaultItem: View? = null
773 private var fileURI: Uri? = null 773 private var fileURI: Uri? = null
774 private var fileLock = ReentrantLock() 774 private var fileLock = ReentrantLock()
775 private var fileCond = threadLock.newCondition() 775 private var fileCond = threadLock.newCondition()
3138 3138
3139 if(canvas != null) { 3139 if(canvas != null) {
3140 colorsSet(fgColor, bgColor) 3140 colorsSet(fgColor, bgColor)
3141 // Save the old color for later... 3141 // Save the old color for later...
3142 val rect = Rect() 3142 val rect = Rect()
3143 val oldcolor = paint.color
3144 // Prepare to draw the background rect
3145 paint.color = bgcolor
3146 paint.flags = 0 3143 paint.flags = 0
3147 paint.style = Paint.Style.FILL_AND_STROKE 3144 paint.style = Paint.Style.FILL_AND_STROKE
3148 paint.textAlign = Paint.Align.LEFT 3145 paint.textAlign = Paint.Align.LEFT
3149 paint.getTextBounds(text, 0, text.length, rect) 3146 paint.getTextBounds(text, 0, text.length, rect)
3150 val textheight = rect.bottom - rect.top 3147 val textheight = rect.bottom - rect.top
3151 rect.top += y + textheight 3148 if(bgcolor != null) {
3152 rect.bottom += y + textheight 3149 val oldcolor = paint.color
3153 rect.left += x 3150 // Prepare to draw the background rect
3154 rect.right += x 3151 paint.color = bgcolor as Int
3155 canvas.drawRect(rect, paint) 3152 rect.top += y + textheight
3156 // Restore the color and prepare to draw text 3153 rect.bottom += y + textheight
3157 paint.color = oldcolor 3154 rect.left += x
3155 rect.right += x
3156 canvas.drawRect(rect, paint)
3157 // Restore the color and prepare to draw text
3158 paint.color = oldcolor
3159 }
3158 paint.style = Paint.Style.STROKE 3160 paint.style = Paint.Style.STROKE
3159 canvas.drawText(text, x.toFloat(), y.toFloat() + textheight.toFloat(), paint) 3161 canvas.drawText(text, x.toFloat(), y.toFloat() + textheight.toFloat(), paint)
3160 } 3162 }
3161 } 3163 }
3162 } 3164 }
3296 3298
3297 fun colorsSet(fgColor: Long, bgColor: Long) 3299 fun colorsSet(fgColor: Long, bgColor: Long)
3298 { 3300 {
3299 waitOnUiThread { 3301 waitOnUiThread {
3300 paint.color = colorFromDW(fgColor) 3302 paint.color = colorFromDW(fgColor)
3301 this.bgcolor = colorFromDW(bgColor) 3303 if(bgColor != -1L) {
3304 this.bgcolor = colorFromDW(bgColor)
3305 } else {
3306 this.bgcolor = null
3307 }
3302 } 3308 }
3303 } 3309 }
3304 3310
3305 fun timerConnect(interval: Long, sigfunc: Long, data: Long): Timer 3311 fun timerConnect(interval: Long, sigfunc: Long, data: Long): Timer
3306 { 3312 {
3474 // Then loop until we throw an exception when the time expires 3480 // Then loop until we throw an exception when the time expires
3475 // in the idle handler, if we are already thrown... remove the handler 3481 // in the idle handler, if we are already thrown... remove the handler
3476 if(Looper.getMainLooper() == Looper.myLooper()) { 3482 if(Looper.getMainLooper() == Looper.myLooper()) {
3477 val starttime = System.currentTimeMillis() 3483 val starttime = System.currentTimeMillis()
3478 3484
3479 // Waiting for Idle to make sure Toast gets rendered. 3485 // Waiting for Idle to check for sleep expiration
3480 Looper.myQueue().addIdleHandler(object : MessageQueue.IdleHandler { 3486 Looper.myQueue().addIdleHandler(object : MessageQueue.IdleHandler {
3481 var thrown: Boolean = false 3487 var thrown: Boolean = false
3482 3488
3483 override fun queueIdle(): Boolean { 3489 override fun queueIdle(): Boolean {
3484 if(System.currentTimeMillis() - starttime >= milliseconds) { 3490 if(System.currentTimeMillis() - starttime >= milliseconds) {