comparison android/dw.cpp @ 2547:dbd15c13f5bb

Android: Implement most of the font functions and control/widget color. Add an Android section in dwtest for picking fonts and folders. Minor update to the readme.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 14 May 2021 11:29:00 +0000
parents f803f3b164cf
children c4d75d30430c
comparison
equal deleted inserted replaced
2546:897d94c20365 2547:dbd15c13f5bb
2573 jstring jstr = env->NewStringUTF(text); 2573 jstring jstr = env->NewStringUTF(text);
2574 // First get the class that contains the method you need to call 2574 // First get the class that contains the method you need to call
2575 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 2575 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2576 // Get the method that you want to call 2576 // Get the method that you want to call
2577 jmethodID drawLine = env->GetMethodID(clazz, "drawText", 2577 jmethodID drawLine = env->GetMethodID(clazz, "drawText",
2578 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IILjava/lang/String;)V"); 2578 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IILjava/lang/String;Landroid/graphics/Typeface;ILandroid/view/View;)V");
2579 // Call the method on the object 2579 // Call the method on the object
2580 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : NULL, x, y, jstr); 2580 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : nullptr, x, y, jstr,
2581 pixmap ? pixmap->typeface : nullptr, pixmap ? pixmap->fontsize : 0, pixmap ? pixmap->handle : nullptr);
2581 } 2582 }
2582 } 2583 }
2583 2584
2584 /* Query the width and height of a text string. 2585 /* Query the width and height of a text string.
2585 * Parameters: 2586 * Parameters:
2589 * width: Pointer to a variable to be filled in with the width. 2590 * width: Pointer to a variable to be filled in with the width.
2590 * height: Pointer to a variable to be filled in with the height. 2591 * height: Pointer to a variable to be filled in with the height.
2591 */ 2592 */
2592 void API dw_font_text_extents_get(HWND handle, HPIXMAP pixmap, const char *text, int *width, int *height) 2593 void API dw_font_text_extents_get(HWND handle, HPIXMAP pixmap, const char *text, int *width, int *height)
2593 { 2594 {
2595 JNIEnv *env;
2596
2597 if((handle || pixmap) && text && (width || height) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
2598 {
2599 // Construct the string
2600 jstring jstr = env->NewStringUTF(text);
2601 // First get the class that contains the method you need to call
2602 //jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2603 jclass clazz = env->FindClass(DW_CLASS_NAME);
2604 // Get the method that you want to call
2605 jmethodID fontTextExtentsGet = env->GetMethodID(clazz, "fontTextExtentsGet",
2606 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;Ljava/lang/String;Landroid/graphics/Typeface;ILandroid/view/View;)J");
2607 // Call the method on the object
2608 jlong dimensions = env->CallLongMethod(_dw_obj, fontTextExtentsGet, handle, pixmap ? pixmap->bitmap : nullptr, jstr,
2609 pixmap ? pixmap->typeface : nullptr, pixmap ? pixmap->fontsize : 0, pixmap ? pixmap->handle : nullptr);
2610
2611 if(width)
2612 *width = dimensions & 0xFFFF;
2613 if(height)
2614 *height = (dimensions >> 32) & 0xFFFF;
2615 }
2594 } 2616 }
2595 2617
2596 /* Draw a polygon on a window (preferably a render window). 2618 /* Draw a polygon on a window (preferably a render window).
2597 * Parameters: 2619 * Parameters:
2598 * handle: Handle to the window. 2620 * handle: Handle to the window.
3584 * Returns: 3606 * Returns:
3585 * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure. 3607 * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure.
3586 */ 3608 */
3587 int API dw_pixmap_set_font(HPIXMAP pixmap, const char *fontname) 3609 int API dw_pixmap_set_font(HPIXMAP pixmap, const char *fontname)
3588 { 3610 {
3611 JNIEnv *env;
3612
3613 if(pixmap && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3614 {
3615 // Construct a string
3616 jstring jstr = env->NewStringUTF(fontname);
3617 // First get the class that contains the method you need to call
3618 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3619 // Get the method that you want to call
3620 jmethodID typefaceFromFontName = env->GetMethodID(clazz, "typefaceFromFontName",
3621 "(Ljava/lang/String;)Landroid/graphics/Typeface;");
3622 // Call the method on the object
3623 jobject typeface = env->NewGlobalRef(env->CallObjectMethod(_dw_obj, typefaceFromFontName, jstr));
3624 if(typeface)
3625 {
3626 jobject oldtypeface = pixmap->typeface;
3627 pixmap->typeface = typeface;
3628 if(oldtypeface)
3629 env->DeleteGlobalRef(oldtypeface);
3630 pixmap->fontsize = atoi(fontname);
3631 }
3632 return DW_ERROR_NONE;
3633 }
3589 return DW_ERROR_GENERAL; 3634 return DW_ERROR_GENERAL;
3590 } 3635 }
3591 3636
3592 /* 3637 /*
3593 * Destroys an allocated pixmap. 3638 * Destroys an allocated pixmap.
4393 * Returns: 4438 * Returns:
4394 * DW_ERROR_NONE (0) on success. 4439 * DW_ERROR_NONE (0) on success.
4395 */ 4440 */
4396 int API dw_window_set_color(HWND handle, ULONG fore, ULONG back) 4441 int API dw_window_set_color(HWND handle, ULONG fore, ULONG back)
4397 { 4442 {
4443 JNIEnv *env;
4444
4445 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
4446 {
4447 unsigned long _fore = _dw_get_color(fore);
4448 unsigned long _back = _dw_get_color(back);
4449
4450 // First get the class that contains the method you need to call
4451 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
4452 // Get the method that you want to call
4453 jmethodID windowSetColor = env->GetMethodID(clazz, "windowSetColor",
4454 "(Landroid/view/View;IIIIIIII)V");
4455 // Call the method on the object
4456 env->CallVoidMethod(_dw_obj, windowSetColor, handle,
4457 0, (jint)DW_RED_VALUE(_fore), (jint)DW_GREEN_VALUE(_fore), (jint)DW_BLUE_VALUE(_fore),
4458 0, (jint)DW_RED_VALUE(_back), (jint)DW_GREEN_VALUE(_back), (jint)DW_BLUE_VALUE(_back));
4459 return DW_ERROR_NONE;
4460 }
4398 return DW_ERROR_GENERAL; 4461 return DW_ERROR_GENERAL;
4399 } 4462 }
4400 4463
4401 /* 4464 /*
4402 * Sets the border size of a specified window (widget) handle. 4465 * Sets the border size of a specified window (widget) handle.
4489 * Returns: 4552 * Returns:
4490 * DW_ERROR_NONE (0) on success. 4553 * DW_ERROR_NONE (0) on success.
4491 */ 4554 */
4492 int API dw_window_set_font(HWND handle, const char *fontname) 4555 int API dw_window_set_font(HWND handle, const char *fontname)
4493 { 4556 {
4557 JNIEnv *env;
4558
4559 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
4560 {
4561 // Construct a string
4562 jstring jstr = env->NewStringUTF(fontname);
4563 // First get the class that contains the method you need to call
4564 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
4565 // Get the method that you want to call
4566 jmethodID windowHideShow = env->GetMethodID(clazz, "windowSetFont",
4567 "(Landroid/view/View;Ljava/lang/String;)V");
4568 // Call the method on the object
4569 env->CallVoidMethod(_dw_obj, windowHideShow, handle, jstr);
4570 return DW_ERROR_NONE;
4571 }
4494 return DW_ERROR_GENERAL; 4572 return DW_ERROR_GENERAL;
4495 } 4573 }
4496 4574
4497 /* 4575 /*
4498 * Returns the current font for the specified window. 4576 * Returns the current font for the specified window.