Mercurial > dwindows
comparison android/DWindows.kt @ 2572:bbe693293be5
Android: New color handling system, save the color in the C API and pass
it into the Java/Kotlin API directly so the threads won't contaminate.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 21 May 2021 00:39:13 +0000 |
parents | b536b7b21682 |
children | ea75e295025b |
comparison
equal
deleted
inserted
replaced
2571:e34b627b2491 | 2572:bbe693293be5 |
---|---|
2828 } | 2828 } |
2829 } | 2829 } |
2830 return retval | 2830 return retval |
2831 } | 2831 } |
2832 | 2832 |
2833 fun drawPoint(render: DWRender?, bitmap: Bitmap?, x: Int, y: Int) | 2833 fun drawPoint(render: DWRender?, bitmap: Bitmap?, x: Int, y: Int, fgColor: Int, bgColor: Int) |
2834 { | 2834 { |
2835 waitOnUiThread { | 2835 waitOnUiThread { |
2836 var canvas: Canvas? = null | 2836 var canvas: Canvas? = null |
2837 | 2837 |
2838 if(render != null) { | 2838 if(render != null) { |
2840 } else if(bitmap != null) { | 2840 } else if(bitmap != null) { |
2841 canvas = Canvas(bitmap) | 2841 canvas = Canvas(bitmap) |
2842 } | 2842 } |
2843 | 2843 |
2844 if(canvas != null) { | 2844 if(canvas != null) { |
2845 colorsSet(fgColor, bgColor) | |
2845 canvas.drawPoint(x.toFloat(), y.toFloat(), Paint()) | 2846 canvas.drawPoint(x.toFloat(), y.toFloat(), Paint()) |
2846 } | 2847 } |
2847 } | 2848 } |
2848 } | 2849 } |
2849 | 2850 |
2850 fun drawLine(render: DWRender?, bitmap: Bitmap?, x1: Int, y1: Int, x2: Int, y2: Int) | 2851 fun drawLine(render: DWRender?, bitmap: Bitmap?, x1: Int, y1: Int, x2: Int, y2: Int, fgColor: Int, bgColor: Int) |
2851 { | 2852 { |
2852 waitOnUiThread { | 2853 waitOnUiThread { |
2853 var canvas: Canvas? = null | 2854 var canvas: Canvas? = null |
2854 | 2855 |
2855 if(render != null) { | 2856 if(render != null) { |
2857 } else if(bitmap != null) { | 2858 } else if(bitmap != null) { |
2858 canvas = Canvas(bitmap) | 2859 canvas = Canvas(bitmap) |
2859 } | 2860 } |
2860 | 2861 |
2861 if(canvas != null) { | 2862 if(canvas != null) { |
2863 colorsSet(fgColor, bgColor) | |
2862 paint.flags = 0 | 2864 paint.flags = 0 |
2863 paint.style = Paint.Style.STROKE | 2865 paint.style = Paint.Style.STROKE |
2864 canvas.drawLine(x1.toFloat(), y1.toFloat(), x2.toFloat(), y2.toFloat(), paint) | 2866 canvas.drawLine(x1.toFloat(), y1.toFloat(), x2.toFloat(), y2.toFloat(), paint) |
2865 } | 2867 } |
2866 } | 2868 } |
2903 dimensions = textwidth.toLong() or (textheight.toLong() shl 32) | 2905 dimensions = textwidth.toLong() or (textheight.toLong() shl 32) |
2904 } | 2906 } |
2905 return dimensions | 2907 return dimensions |
2906 } | 2908 } |
2907 | 2909 |
2908 fun drawText(render: DWRender?, bitmap: Bitmap?, x: Int, y: Int, text:String, typeface: Typeface?, fontsize: Int, window: View?) | 2910 fun drawText(render: DWRender?, bitmap: Bitmap?, x: Int, y: Int, text:String, typeface: Typeface?, |
2911 fontsize: Int, window: View?, fgColor: Int, bgColor: Int) | |
2909 { | 2912 { |
2910 waitOnUiThread { | 2913 waitOnUiThread { |
2911 var canvas: Canvas? = null | 2914 var canvas: Canvas? = null |
2912 | 2915 |
2913 if(render != null && render.cachedCanvas != null) { | 2916 if(render != null && render.cachedCanvas != null) { |
2936 } | 2939 } |
2937 } | 2940 } |
2938 } | 2941 } |
2939 | 2942 |
2940 if(canvas != null) { | 2943 if(canvas != null) { |
2944 colorsSet(fgColor, bgColor) | |
2941 // Save the old color for later... | 2945 // Save the old color for later... |
2942 var rect = Rect() | 2946 var rect = Rect() |
2943 val oldcolor = paint.color | 2947 val oldcolor = paint.color |
2944 // Prepare to draw the background rect | 2948 // Prepare to draw the background rect |
2945 paint.color = bgcolor | 2949 paint.color = bgcolor |
2959 canvas.drawText(text, x.toFloat(), y.toFloat() + textheight.toFloat(), paint) | 2963 canvas.drawText(text, x.toFloat(), y.toFloat() + textheight.toFloat(), paint) |
2960 } | 2964 } |
2961 } | 2965 } |
2962 } | 2966 } |
2963 | 2967 |
2964 fun drawRect(render: DWRender?, bitmap: Bitmap?, x: Int, y: Int, width: Int, height: Int) | 2968 fun drawRect(render: DWRender?, bitmap: Bitmap?, x: Int, y: Int, width: Int, height: Int, fgColor: Int, bgColor: Int) |
2965 { | 2969 { |
2966 waitOnUiThread { | 2970 waitOnUiThread { |
2967 var canvas: Canvas? = null | 2971 var canvas: Canvas? = null |
2968 | 2972 |
2969 if(render != null) { | 2973 if(render != null) { |
2971 } else if(bitmap != null) { | 2975 } else if(bitmap != null) { |
2972 canvas = Canvas(bitmap) | 2976 canvas = Canvas(bitmap) |
2973 } | 2977 } |
2974 | 2978 |
2975 if(canvas != null) { | 2979 if(canvas != null) { |
2980 colorsSet(fgColor, bgColor) | |
2976 paint.flags = 0 | 2981 paint.flags = 0 |
2977 paint.style = Paint.Style.FILL_AND_STROKE | 2982 paint.style = Paint.Style.FILL_AND_STROKE |
2978 canvas.drawRect(x.toFloat(), y.toFloat(), x.toFloat() + width.toFloat(), y.toFloat() + height.toFloat(), paint) | 2983 canvas.drawRect(x.toFloat(), y.toFloat(), x.toFloat() + width.toFloat(), y.toFloat() + height.toFloat(), paint) |
2979 } | 2984 } |
2980 } | 2985 } |
2981 } | 2986 } |
2982 | 2987 |
2983 fun drawPolygon(render: DWRender?, bitmap: Bitmap?, flags: Int, npoints: Int, x: IntArray, y: IntArray) | 2988 fun drawPolygon(render: DWRender?, bitmap: Bitmap?, flags: Int, npoints: Int, |
2989 x: IntArray, y: IntArray, fgColor: Int, bgColor: Int) | |
2984 { | 2990 { |
2985 // Create a path with all our points | 2991 // Create a path with all our points |
2986 val path = Path() | 2992 val path = Path() |
2987 | 2993 |
2988 path.moveTo(x[0].toFloat(), y[0].toFloat()) | 2994 path.moveTo(x[0].toFloat(), y[0].toFloat()) |
2998 } else if(bitmap != null) { | 3004 } else if(bitmap != null) { |
2999 canvas = Canvas(bitmap) | 3005 canvas = Canvas(bitmap) |
3000 } | 3006 } |
3001 | 3007 |
3002 if(canvas != null) { | 3008 if(canvas != null) { |
3009 colorsSet(fgColor, bgColor) | |
3003 // Handle the DW_DRAW_NOAA flag | 3010 // Handle the DW_DRAW_NOAA flag |
3004 if((flags and (1 shl 2)) == 0) { | 3011 if((flags and (1 shl 2)) == 0) { |
3005 paint.flags = Paint.ANTI_ALIAS_FLAG | 3012 paint.flags = Paint.ANTI_ALIAS_FLAG |
3006 } else { | 3013 } else { |
3007 paint.flags = 0 | 3014 paint.flags = 0 |
3016 } | 3023 } |
3017 } | 3024 } |
3018 } | 3025 } |
3019 | 3026 |
3020 fun drawArc(render: DWRender?, bitmap: Bitmap?, flags: Int, xorigin: Int, yorigin: Int, | 3027 fun drawArc(render: DWRender?, bitmap: Bitmap?, flags: Int, xorigin: Int, yorigin: Int, |
3021 x1: Int, y1: Int, x2: Int, y2: Int) | 3028 x1: Int, y1: Int, x2: Int, y2: Int, fgColor: Int, bgColor: Int) |
3022 { | 3029 { |
3023 waitOnUiThread { | 3030 waitOnUiThread { |
3024 var canvas: Canvas? = null | 3031 var canvas: Canvas? = null |
3025 | 3032 |
3026 if(render != null) { | 3033 if(render != null) { |
3037 val r: Double = Math.sqrt(dx * dx + dy * dy) | 3044 val r: Double = Math.sqrt(dx * dx + dy * dy) |
3038 val left = (xorigin-r).toFloat() | 3045 val left = (xorigin-r).toFloat() |
3039 val top = (yorigin-r).toFloat() | 3046 val top = (yorigin-r).toFloat() |
3040 val rect = RectF(left, top, (left + (r*2)).toFloat(), (top + (r*2)).toFloat()) | 3047 val rect = RectF(left, top, (left + (r*2)).toFloat(), (top + (r*2)).toFloat()) |
3041 | 3048 |
3042 /* Convert to degrees */ | 3049 // Convert to degrees |
3043 a1 *= 180.0 / Math.PI | 3050 a1 *= 180.0 / Math.PI |
3044 a2 *= 180.0 / Math.PI | 3051 a2 *= 180.0 / Math.PI |
3045 val sweep = Math.abs(a1 - a2) | 3052 val sweep = Math.abs(a1 - a2) |
3053 | |
3054 colorsSet(fgColor, bgColor) | |
3046 | 3055 |
3047 // Handle the DW_DRAW_NOAA flag | 3056 // Handle the DW_DRAW_NOAA flag |
3048 if((flags and (1 shl 2)) == 0) { | 3057 if((flags and (1 shl 2)) == 0) { |
3049 paint.flags = Paint.ANTI_ALIAS_FLAG | 3058 paint.flags = Paint.ANTI_ALIAS_FLAG |
3050 } else { | 3059 } else { |
3082 if(alpha != 0) { | 3091 if(alpha != 0) { |
3083 this.bgcolor = Color.argb(alpha, red, green, blue) | 3092 this.bgcolor = Color.argb(alpha, red, green, blue) |
3084 } else { | 3093 } else { |
3085 this.bgcolor = Color.rgb(red, green, blue) | 3094 this.bgcolor = Color.rgb(red, green, blue) |
3086 } | 3095 } |
3096 } | |
3097 | |
3098 fun colorsSet(fgColor: Int, bgColor: Int) | |
3099 { | |
3100 val fgRed: Int = (fgColor and 0x000000FF) | |
3101 val fgGreen: Int = (fgColor and 0x0000FF00) shr 8 | |
3102 val fgBlue: Int = (fgColor and 0x00FF0000) shr 16 | |
3103 val bgRed: Int = (bgColor and 0x000000FF) | |
3104 val bgGreen: Int = (bgColor and 0x0000FF00) shr 8 | |
3105 val bgBlue: Int = (bgColor and 0x00FF0000) shr 16 | |
3106 | |
3107 paint.color = Color.rgb(fgRed, fgGreen, fgBlue) | |
3108 this.bgcolor = Color.rgb(bgRed, bgGreen, bgBlue) | |
3087 } | 3109 } |
3088 | 3110 |
3089 fun timerConnect(interval: Long, sigfunc: Long, data: Long): Timer | 3111 fun timerConnect(interval: Long, sigfunc: Long, data: Long): Timer |
3090 { | 3112 { |
3091 // creating timer task, timer | 3113 // creating timer task, timer |