Mercurial > dwindows
comparison android/dw.cpp @ 2580:473eb9ff3f04
Android: Implement dw_container_set_stripe() and center the images in the rows.
Also switch to using jlong (Long) types for passing the colors internally.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 23 May 2021 02:27:12 +0000 |
parents | a36448beb7f7 |
children | 01fca1937806 |
comparison
equal
deleted
inserted
replaced
2579:68ee9a89e0f0 | 2580:473eb9ff3f04 |
---|---|
716 0x00ffffff, /* 15 bright white */ | 716 0x00ffffff, /* 15 bright white */ |
717 0xff000000 /* 16 default color */ | 717 0xff000000 /* 16 default color */ |
718 }; | 718 }; |
719 | 719 |
720 /* Return the RGB color regardless if a predefined color was passed */ | 720 /* Return the RGB color regardless if a predefined color was passed */ |
721 unsigned long _dw_get_color(unsigned long thiscolor) | 721 jlong _dw_get_color(unsigned long thiscolor) |
722 { | 722 { |
723 if(thiscolor & DW_RGB_COLOR) | 723 if(thiscolor & DW_RGB_COLOR) |
724 { | 724 { |
725 return thiscolor & ~DW_RGB_COLOR; | 725 return ((jlong)thiscolor) & ~DW_RGB_COLOR; |
726 } | 726 } |
727 else if(thiscolor < 17) | 727 else if(thiscolor < 17) |
728 { | 728 { |
729 return _dw_colors[thiscolor]; | 729 return _dw_colors[thiscolor]; |
730 } | 730 } |
2698 { | 2698 { |
2699 JNIEnv *env; | 2699 JNIEnv *env; |
2700 | 2700 |
2701 if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | 2701 if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) |
2702 { | 2702 { |
2703 unsigned long fgcolor = (unsigned long)pthread_getspecific(_dw_fgcolor_key); | 2703 jlong fgcolor = (jlong)pthread_getspecific(_dw_fgcolor_key); |
2704 unsigned long bgcolor = (unsigned long)pthread_getspecific(_dw_bgcolor_key); | 2704 jlong bgcolor = (jlong)pthread_getspecific(_dw_bgcolor_key); |
2705 | 2705 |
2706 // First get the class that contains the method you need to call | 2706 // First get the class that contains the method you need to call |
2707 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | 2707 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); |
2708 // Get the method that you want to call | 2708 // Get the method that you want to call |
2709 jmethodID drawPoint = env->GetMethodID(clazz, "drawPoint", | 2709 jmethodID drawPoint = env->GetMethodID(clazz, "drawPoint", |
2710 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIII)V"); | 2710 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIJJ)V"); |
2711 // Call the method on the object | 2711 // Call the method on the object |
2712 env->CallVoidMethod(_dw_obj, drawPoint, handle, pixmap ? pixmap->bitmap : nullptr, x, y, (jint)fgcolor, (jint)bgcolor); | 2712 env->CallVoidMethod(_dw_obj, drawPoint, handle, pixmap ? pixmap->bitmap : nullptr, x, y, fgcolor, bgcolor); |
2713 _dw_jni_check_exception(env); | 2713 _dw_jni_check_exception(env); |
2714 } | 2714 } |
2715 } | 2715 } |
2716 | 2716 |
2717 /* Draw a line on a window (preferably a render window). | 2717 /* Draw a line on a window (preferably a render window). |
2727 { | 2727 { |
2728 JNIEnv *env; | 2728 JNIEnv *env; |
2729 | 2729 |
2730 if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | 2730 if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) |
2731 { | 2731 { |
2732 unsigned long fgcolor = (unsigned long)pthread_getspecific(_dw_fgcolor_key); | 2732 jlong fgcolor = (jlong)pthread_getspecific(_dw_fgcolor_key); |
2733 unsigned long bgcolor = (unsigned long)pthread_getspecific(_dw_bgcolor_key); | 2733 jlong bgcolor = (jlong)pthread_getspecific(_dw_bgcolor_key); |
2734 | 2734 |
2735 // First get the class that contains the method you need to call | 2735 // First get the class that contains the method you need to call |
2736 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | 2736 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); |
2737 // Get the method that you want to call | 2737 // Get the method that you want to call |
2738 jmethodID drawLine = env->GetMethodID(clazz, "drawLine", | 2738 jmethodID drawLine = env->GetMethodID(clazz, "drawLine", |
2739 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIIIII)V"); | 2739 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIIIJJ)V"); |
2740 // Call the method on the object | 2740 // Call the method on the object |
2741 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : nullptr, x1, y1, x2, y2, (jint)fgcolor, (jint)bgcolor); | 2741 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : nullptr, x1, y1, x2, y2, fgcolor, bgcolor); |
2742 _dw_jni_check_exception(env); | 2742 _dw_jni_check_exception(env); |
2743 } | 2743 } |
2744 } | 2744 } |
2745 | 2745 |
2746 /* Draw text on a window (preferably a render window). | 2746 /* Draw text on a window (preferably a render window). |
2755 { | 2755 { |
2756 JNIEnv *env; | 2756 JNIEnv *env; |
2757 | 2757 |
2758 if((handle || pixmap) && text && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | 2758 if((handle || pixmap) && text && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) |
2759 { | 2759 { |
2760 unsigned long fgcolor = (unsigned long)pthread_getspecific(_dw_fgcolor_key); | 2760 jlong fgcolor = (jlong)pthread_getspecific(_dw_fgcolor_key); |
2761 unsigned long bgcolor = (unsigned long)pthread_getspecific(_dw_bgcolor_key); | 2761 jlong bgcolor = (jlong)pthread_getspecific(_dw_bgcolor_key); |
2762 | 2762 |
2763 // Construct the string | 2763 // Construct the string |
2764 jstring jstr = env->NewStringUTF(text); | 2764 jstring jstr = env->NewStringUTF(text); |
2765 // First get the class that contains the method you need to call | 2765 // First get the class that contains the method you need to call |
2766 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | 2766 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); |
2767 // Get the method that you want to call | 2767 // Get the method that you want to call |
2768 jmethodID drawLine = env->GetMethodID(clazz, "drawText", | 2768 jmethodID drawLine = env->GetMethodID(clazz, "drawText", |
2769 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IILjava/lang/String;Landroid/graphics/Typeface;ILandroid/view/View;II)V"); | 2769 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IILjava/lang/String;Landroid/graphics/Typeface;ILandroid/view/View;JJ)V"); |
2770 // Call the method on the object | 2770 // Call the method on the object |
2771 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : nullptr, x, y, jstr, | 2771 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : nullptr, x, y, jstr, |
2772 pixmap ? pixmap->typeface : nullptr, pixmap ? pixmap->fontsize : 0, | 2772 pixmap ? pixmap->typeface : nullptr, pixmap ? pixmap->fontsize : 0, |
2773 pixmap ? pixmap->handle : nullptr, (jint)fgcolor, (jint)bgcolor); | 2773 pixmap ? pixmap->handle : nullptr, fgcolor, bgcolor); |
2774 _dw_jni_check_exception(env); | 2774 _dw_jni_check_exception(env); |
2775 } | 2775 } |
2776 } | 2776 } |
2777 | 2777 |
2778 /* Query the width and height of a text string. | 2778 /* Query the width and height of a text string. |
2827 jintArray jx = env->NewIntArray(npoints); | 2827 jintArray jx = env->NewIntArray(npoints); |
2828 jintArray jy = env->NewIntArray(npoints); | 2828 jintArray jy = env->NewIntArray(npoints); |
2829 | 2829 |
2830 if(jx && jy) | 2830 if(jx && jy) |
2831 { | 2831 { |
2832 unsigned long fgcolor = (unsigned long)pthread_getspecific(_dw_fgcolor_key); | 2832 jlong fgcolor = (jlong)pthread_getspecific(_dw_fgcolor_key); |
2833 unsigned long bgcolor = (unsigned long)pthread_getspecific(_dw_bgcolor_key); | 2833 jlong bgcolor = (jlong)pthread_getspecific(_dw_bgcolor_key); |
2834 | 2834 |
2835 // Construct the integer arrays | 2835 // Construct the integer arrays |
2836 env->SetIntArrayRegion(jx, 0, npoints, x); | 2836 env->SetIntArrayRegion(jx, 0, npoints, x); |
2837 env->SetIntArrayRegion(jy, 0, npoints, y); | 2837 env->SetIntArrayRegion(jy, 0, npoints, y); |
2838 // First get the class that contains the method you need to call | 2838 // First get the class that contains the method you need to call |
2839 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | 2839 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); |
2840 // Get the method that you want to call | 2840 // Get the method that you want to call |
2841 jmethodID drawPolygon = env->GetMethodID(clazz, "drawPolygon", | 2841 jmethodID drawPolygon = env->GetMethodID(clazz, "drawPolygon", |
2842 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;II[I[III)V"); | 2842 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;II[I[IJJ)V"); |
2843 // Call the method on the object | 2843 // Call the method on the object |
2844 env->CallVoidMethod(_dw_obj, drawPolygon, handle, pixmap ? pixmap->bitmap : nullptr, flags, npoints, jx, jy, (jint)fgcolor, (jint)bgcolor); | 2844 env->CallVoidMethod(_dw_obj, drawPolygon, handle, pixmap ? pixmap->bitmap : nullptr, flags, npoints, jx, jy, fgcolor, bgcolor); |
2845 _dw_jni_check_exception(env); | 2845 _dw_jni_check_exception(env); |
2846 } | 2846 } |
2847 } | 2847 } |
2848 } | 2848 } |
2849 | 2849 |
2861 { | 2861 { |
2862 JNIEnv *env; | 2862 JNIEnv *env; |
2863 | 2863 |
2864 if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | 2864 if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) |
2865 { | 2865 { |
2866 unsigned long fgcolor = (unsigned long)pthread_getspecific(_dw_fgcolor_key); | 2866 jlong fgcolor = (jlong)pthread_getspecific(_dw_fgcolor_key); |
2867 unsigned long bgcolor = (unsigned long)pthread_getspecific(_dw_bgcolor_key); | 2867 jlong bgcolor = (jlong)pthread_getspecific(_dw_bgcolor_key); |
2868 | 2868 |
2869 // First get the class that contains the method you need to call | 2869 // First get the class that contains the method you need to call |
2870 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | 2870 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); |
2871 // Get the method that you want to call | 2871 // Get the method that you want to call |
2872 jmethodID drawLine = env->GetMethodID(clazz, "drawRect", | 2872 jmethodID drawLine = env->GetMethodID(clazz, "drawRect", |
2873 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIIIII)V"); | 2873 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIIIJJ)V"); |
2874 // Call the method on the object | 2874 // Call the method on the object |
2875 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : nullptr, x, y, width, height, (jint)fgcolor, (jint)bgcolor); | 2875 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : nullptr, x, y, width, height, fgcolor, bgcolor); |
2876 _dw_jni_check_exception(env); | 2876 _dw_jni_check_exception(env); |
2877 } | 2877 } |
2878 } | 2878 } |
2879 | 2879 |
2880 /* Draw an arc on a window (preferably a render window). | 2880 /* Draw an arc on a window (preferably a render window). |
2894 { | 2894 { |
2895 JNIEnv *env; | 2895 JNIEnv *env; |
2896 | 2896 |
2897 if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | 2897 if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) |
2898 { | 2898 { |
2899 unsigned long fgcolor = (unsigned long)pthread_getspecific(_dw_fgcolor_key); | 2899 jlong fgcolor = (jlong)pthread_getspecific(_dw_fgcolor_key); |
2900 unsigned long bgcolor = (unsigned long)pthread_getspecific(_dw_bgcolor_key); | 2900 jlong bgcolor = (jlong)pthread_getspecific(_dw_bgcolor_key); |
2901 | 2901 |
2902 // First get the class that contains the method you need to call | 2902 // First get the class that contains the method you need to call |
2903 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | 2903 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); |
2904 // Get the method that you want to call | 2904 // Get the method that you want to call |
2905 jmethodID drawLine = env->GetMethodID(clazz, "drawArc", | 2905 jmethodID drawLine = env->GetMethodID(clazz, "drawArc", |
2906 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIIIIIIII)V"); | 2906 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIIIIIIJJ)V"); |
2907 // Call the method on the object | 2907 // Call the method on the object |
2908 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : nullptr, flags, xorigin, yorigin, x1, y1, x2, y2, (jint)fgcolor, (jint)bgcolor); | 2908 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : nullptr, flags, xorigin, yorigin, x1, y1, x2, y2, fgcolor, bgcolor); |
2909 _dw_jni_check_exception(env); | 2909 _dw_jni_check_exception(env); |
2910 } | 2910 } |
2911 } | 2911 } |
2912 | 2912 |
2913 /* | 2913 /* |
3452 * DW_RGB_TRANSPARENT will disable coloring rows. | 3452 * DW_RGB_TRANSPARENT will disable coloring rows. |
3453 * DW_CLR_DEFAULT will use the system default alternating row colors. | 3453 * DW_CLR_DEFAULT will use the system default alternating row colors. |
3454 */ | 3454 */ |
3455 void API dw_container_set_stripe(HWND handle, unsigned long oddcolor, unsigned long evencolor) | 3455 void API dw_container_set_stripe(HWND handle, unsigned long oddcolor, unsigned long evencolor) |
3456 { | 3456 { |
3457 JNIEnv *env; | |
3458 | |
3459 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
3460 { | |
3461 jlong odd = _dw_get_color(oddcolor); | |
3462 jlong even = _dw_get_color(evencolor); | |
3463 | |
3464 // First get the class that contains the method you need to call | |
3465 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
3466 // Get the method that you want to call | |
3467 jmethodID containerSetStripe = env->GetMethodID(clazz, "containerSetStripe", | |
3468 "(Landroid/widget/ListView;JJ)V"); | |
3469 if(oddcolor == DW_RGB_TRANSPARENT) | |
3470 odd = -1; | |
3471 else if(oddcolor == DW_CLR_DEFAULT) | |
3472 odd = -2; | |
3473 if(evencolor == DW_RGB_TRANSPARENT) | |
3474 even = -1; | |
3475 else if(evencolor == DW_CLR_DEFAULT) | |
3476 even = -2; | |
3477 | |
3478 // Call the method on the object | |
3479 env->CallVoidMethod(_dw_obj, containerSetStripe, handle, odd, even); | |
3480 _dw_jni_check_exception(env); | |
3481 } | |
3457 } | 3482 } |
3458 | 3483 |
3459 /* | 3484 /* |
3460 * Sets the width of a column in the container. | 3485 * Sets the width of a column in the container. |
3461 * Parameters: | 3486 * Parameters: |