comparison android/dw.cpp @ 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 3d20fcfd8583
children 7101b5692601
comparison
equal deleted inserted replaced
2636:038f83009cdb 2637:22105f99dd6a
176 pthread_key_create(&_dw_env_key, nullptr); 176 pthread_key_create(&_dw_env_key, nullptr);
177 pthread_setspecific(_dw_env_key, env); 177 pthread_setspecific(_dw_env_key, env);
178 pthread_key_create(&_dw_fgcolor_key, nullptr); 178 pthread_key_create(&_dw_fgcolor_key, nullptr);
179 pthread_setspecific(_dw_fgcolor_key, nullptr); 179 pthread_setspecific(_dw_fgcolor_key, nullptr);
180 pthread_key_create(&_dw_bgcolor_key, nullptr); 180 pthread_key_create(&_dw_bgcolor_key, nullptr);
181 pthread_setspecific(_dw_bgcolor_key, nullptr); 181 pthread_setspecific(_dw_bgcolor_key, (void *)DW_RGB_TRANSPARENT);
182 182
183 /* Create the dwmain event */ 183 /* Create the dwmain event */
184 _dw_main_event = dw_event_new(); 184 _dw_main_event = dw_event_new();
185 } 185 }
186 186
840 } 840 }
841 else if(thiscolor < 17) 841 else if(thiscolor < 17)
842 { 842 {
843 return _dw_colors[thiscolor]; 843 return _dw_colors[thiscolor];
844 } 844 }
845 else if(thiscolor == DW_RGB_TRANSPARENT)
846 {
847 return -1;
848 }
845 return 0; 849 return 0;
846 } 850 }
847 851
848 int _dw_dark_mode_detected() 852 int _dw_dark_mode_detected()
849 { 853 {
2847 * green: green value. 2851 * green: green value.
2848 * blue: blue value. 2852 * blue: blue value.
2849 */ 2853 */
2850 void API dw_color_foreground_set(unsigned long value) 2854 void API dw_color_foreground_set(unsigned long value)
2851 { 2855 {
2852 pthread_setspecific(_dw_fgcolor_key, (void *)_dw_get_color(value)); 2856 pthread_setspecific(_dw_fgcolor_key, (void *)value);
2853 } 2857 }
2854 2858
2855 /* Sets the current background drawing color. 2859 /* Sets the current background drawing color.
2856 * Parameters: 2860 * Parameters:
2857 * red: red value. 2861 * red: red value.
2858 * green: green value. 2862 * green: green value.
2859 * blue: blue value. 2863 * blue: blue value.
2860 */ 2864 */
2861 void API dw_color_background_set(unsigned long value) 2865 void API dw_color_background_set(unsigned long value)
2862 { 2866 {
2863 pthread_setspecific(_dw_bgcolor_key, (void *)_dw_get_color(value)); 2867 pthread_setspecific(_dw_bgcolor_key, (void *)value);
2864 } 2868 }
2865 2869
2866 /* Allows the user to choose a color using the system's color chooser dialog. 2870 /* Allows the user to choose a color using the system's color chooser dialog.
2867 * Parameters: 2871 * Parameters:
2868 * value: current color 2872 * value: current color
2885 { 2889 {
2886 JNIEnv *env; 2890 JNIEnv *env;
2887 2891
2888 if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) 2892 if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
2889 { 2893 {
2890 jlong fgcolor = (jlong)pthread_getspecific(_dw_fgcolor_key); 2894 jlong fgcolor = _dw_get_color((unsigned long)pthread_getspecific(_dw_fgcolor_key));
2891 jlong bgcolor = (jlong)pthread_getspecific(_dw_bgcolor_key); 2895 jlong bgcolor = _dw_get_color((unsigned long)pthread_getspecific(_dw_bgcolor_key));
2892 2896
2893 // First get the class that contains the method you need to call 2897 // First get the class that contains the method you need to call
2894 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 2898 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2895 // Get the method that you want to call 2899 // Get the method that you want to call
2896 jmethodID drawPoint = env->GetMethodID(clazz, "drawPoint", 2900 jmethodID drawPoint = env->GetMethodID(clazz, "drawPoint",
2914 { 2918 {
2915 JNIEnv *env; 2919 JNIEnv *env;
2916 2920
2917 if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) 2921 if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
2918 { 2922 {
2919 jlong fgcolor = (jlong)pthread_getspecific(_dw_fgcolor_key); 2923 jlong fgcolor = _dw_get_color((unsigned long)pthread_getspecific(_dw_fgcolor_key));
2920 jlong bgcolor = (jlong)pthread_getspecific(_dw_bgcolor_key); 2924 jlong bgcolor = _dw_get_color((unsigned long)pthread_getspecific(_dw_bgcolor_key));
2921 2925
2922 // First get the class that contains the method you need to call 2926 // First get the class that contains the method you need to call
2923 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 2927 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2924 // Get the method that you want to call 2928 // Get the method that you want to call
2925 jmethodID drawLine = env->GetMethodID(clazz, "drawLine", 2929 jmethodID drawLine = env->GetMethodID(clazz, "drawLine",
2942 { 2946 {
2943 JNIEnv *env; 2947 JNIEnv *env;
2944 2948
2945 if((handle || pixmap) && text && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) 2949 if((handle || pixmap) && text && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
2946 { 2950 {
2947 jlong fgcolor = (jlong)pthread_getspecific(_dw_fgcolor_key); 2951 jlong fgcolor = _dw_get_color((unsigned long)pthread_getspecific(_dw_fgcolor_key));
2948 jlong bgcolor = (jlong)pthread_getspecific(_dw_bgcolor_key); 2952 jlong bgcolor = _dw_get_color((unsigned long)pthread_getspecific(_dw_bgcolor_key));
2949 2953
2950 // Construct the string 2954 // Construct the string
2951 jstring jstr = env->NewStringUTF(text); 2955 jstring jstr = env->NewStringUTF(text);
2952 // First get the class that contains the method you need to call 2956 // First get the class that contains the method you need to call
2953 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 2957 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3014 jintArray jx = env->NewIntArray(npoints); 3018 jintArray jx = env->NewIntArray(npoints);
3015 jintArray jy = env->NewIntArray(npoints); 3019 jintArray jy = env->NewIntArray(npoints);
3016 3020
3017 if(jx && jy) 3021 if(jx && jy)
3018 { 3022 {
3019 jlong fgcolor = (jlong)pthread_getspecific(_dw_fgcolor_key); 3023 jlong fgcolor = _dw_get_color((unsigned long)pthread_getspecific(_dw_fgcolor_key));
3020 jlong bgcolor = (jlong)pthread_getspecific(_dw_bgcolor_key); 3024 jlong bgcolor = _dw_get_color((unsigned long)pthread_getspecific(_dw_bgcolor_key));
3021 3025
3022 // Construct the integer arrays 3026 // Construct the integer arrays
3023 env->SetIntArrayRegion(jx, 0, npoints, x); 3027 env->SetIntArrayRegion(jx, 0, npoints, x);
3024 env->SetIntArrayRegion(jy, 0, npoints, y); 3028 env->SetIntArrayRegion(jy, 0, npoints, y);
3025 // First get the class that contains the method you need to call 3029 // First get the class that contains the method you need to call
3048 { 3052 {
3049 JNIEnv *env; 3053 JNIEnv *env;
3050 3054
3051 if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) 3055 if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3052 { 3056 {
3053 jlong fgcolor = (jlong)pthread_getspecific(_dw_fgcolor_key); 3057 jlong fgcolor = _dw_get_color((unsigned long)pthread_getspecific(_dw_fgcolor_key));
3054 jlong bgcolor = (jlong)pthread_getspecific(_dw_bgcolor_key); 3058 jlong bgcolor = _dw_get_color((unsigned long)pthread_getspecific(_dw_bgcolor_key));
3055 3059
3056 // First get the class that contains the method you need to call 3060 // First get the class that contains the method you need to call
3057 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 3061 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3058 // Get the method that you want to call 3062 // Get the method that you want to call
3059 jmethodID drawLine = env->GetMethodID(clazz, "drawRect", 3063 jmethodID drawLine = env->GetMethodID(clazz, "drawRect",
3081 { 3085 {
3082 JNIEnv *env; 3086 JNIEnv *env;
3083 3087
3084 if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) 3088 if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3085 { 3089 {
3086 jlong fgcolor = (jlong)pthread_getspecific(_dw_fgcolor_key); 3090 jlong fgcolor = _dw_get_color((unsigned long)pthread_getspecific(_dw_fgcolor_key));
3087 jlong bgcolor = (jlong)pthread_getspecific(_dw_bgcolor_key); 3091 jlong bgcolor = _dw_get_color((unsigned long)pthread_getspecific(_dw_bgcolor_key));
3088 3092
3089 // First get the class that contains the method you need to call 3093 // First get the class that contains the method you need to call
3090 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 3094 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3091 // Get the method that you want to call 3095 // Get the method that you want to call
3092 jmethodID drawLine = env->GetMethodID(clazz, "drawArc", 3096 jmethodID drawLine = env->GetMethodID(clazz, "drawArc",
6855 JNIEnv *env; 6859 JNIEnv *env;
6856 6860
6857 _dw_jvm->AttachCurrentThread(&env, nullptr); 6861 _dw_jvm->AttachCurrentThread(&env, nullptr);
6858 pthread_setspecific(_dw_env_key, env); 6862 pthread_setspecific(_dw_env_key, env);
6859 pthread_setspecific(_dw_fgcolor_key, nullptr); 6863 pthread_setspecific(_dw_fgcolor_key, nullptr);
6860 pthread_setspecific(_dw_bgcolor_key, nullptr); 6864 pthread_setspecific(_dw_bgcolor_key, (void *)DW_RGB_TRANSPARENT);
6861 } 6865 }
6862 6866
6863 /* 6867 /*
6864 * Generally an internal function called from a terminating 6868 * Generally an internal function called from a terminating
6865 * thread to cleanup the Dynamic Windows environment for the thread. 6869 * thread to cleanup the Dynamic Windows environment for the thread.