comparison android/dw.cpp @ 2535:d862d9e4069b

Android: Implement most of the rest of drawing except for fonts... With varying degrees of functionality... more work needed.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 11 May 2021 09:03:30 +0000
parents c4255630cade
children cd9d2ba251d5
comparison
equal deleted inserted replaced
2534:c4255630cade 2535:d862d9e4069b
2454 * green: green value. 2454 * green: green value.
2455 * blue: blue value. 2455 * blue: blue value.
2456 */ 2456 */
2457 void API dw_color_background_set(unsigned long value) 2457 void API dw_color_background_set(unsigned long value)
2458 { 2458 {
2459 JNIEnv *env;
2460
2461 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
2462 {
2463 unsigned long color = _dw_get_color(value);
2464
2465 // First get the class that contains the method you need to call
2466 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2467 // Get the method that you want to call
2468 jmethodID bgColorSet = env->GetMethodID(clazz, "bgColorSet",
2469 "(IIII)V");
2470 // Call the method on the object
2471 env->CallVoidMethod(_dw_obj, bgColorSet, 0, (jint)DW_RED_VALUE(color), (jint)DW_GREEN_VALUE(color), (jint)DW_BLUE_VALUE(color));
2472 }
2459 } 2473 }
2460 2474
2461 /* Allows the user to choose a color using the system's color chooser dialog. 2475 /* Allows the user to choose a color using the system's color chooser dialog.
2462 * Parameters: 2476 * Parameters:
2463 * value: current color 2477 * value: current color
2486 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 2500 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2487 // Get the method that you want to call 2501 // Get the method that you want to call
2488 jmethodID drawPoint = env->GetMethodID(clazz, "drawPoint", 2502 jmethodID drawPoint = env->GetMethodID(clazz, "drawPoint",
2489 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;II)V"); 2503 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;II)V");
2490 // Call the method on the object 2504 // Call the method on the object
2491 env->CallVoidMethod(_dw_obj, drawPoint, handle, pixmap->bitmap, x, y); 2505 env->CallVoidMethod(_dw_obj, drawPoint, handle, pixmap ? pixmap->bitmap : NULL, x, y);
2492 } 2506 }
2493 } 2507 }
2494 2508
2495 /* Draw a line on a window (preferably a render window). 2509 /* Draw a line on a window (preferably a render window).
2496 * Parameters: 2510 * Parameters:
2511 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 2525 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2512 // Get the method that you want to call 2526 // Get the method that you want to call
2513 jmethodID drawLine = env->GetMethodID(clazz, "drawLine", 2527 jmethodID drawLine = env->GetMethodID(clazz, "drawLine",
2514 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIII)V"); 2528 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIII)V");
2515 // Call the method on the object 2529 // Call the method on the object
2516 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap->bitmap, x1, y1, x2, y2); 2530 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : NULL, x1, y1, x2, y2);
2517 } 2531 }
2518 } 2532 }
2519 2533
2520 /* Draw text on a window (preferably a render window). 2534 /* Draw text on a window (preferably a render window).
2521 * Parameters: 2535 * Parameters:
2525 * y: Y coordinate. 2539 * y: Y coordinate.
2526 * text: Text to be displayed. 2540 * text: Text to be displayed.
2527 */ 2541 */
2528 void API dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, const char *text) 2542 void API dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, const char *text)
2529 { 2543 {
2544 JNIEnv *env;
2545
2546 if((handle || pixmap) && text && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
2547 {
2548 // Construct the string
2549 jstring jstr = env->NewStringUTF(text);
2550 // First get the class that contains the method you need to call
2551 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2552 // Get the method that you want to call
2553 jmethodID drawLine = env->GetMethodID(clazz, "drawText",
2554 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IILjava/lang/String;)V");
2555 // Call the method on the object
2556 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : NULL, x, y, jstr);
2557 }
2530 } 2558 }
2531 2559
2532 /* Query the width and height of a text string. 2560 /* Query the width and height of a text string.
2533 * Parameters: 2561 * Parameters:
2534 * handle: Handle to the window. 2562 * handle: Handle to the window.
2548 * flags: DW_DRAW_FILL (1) to fill the polygon or DW_DRAW_DEFAULT (0). 2576 * flags: DW_DRAW_FILL (1) to fill the polygon or DW_DRAW_DEFAULT (0).
2549 * npoints: Number of points passed in. 2577 * npoints: Number of points passed in.
2550 * x: Pointer to array of X coordinates. 2578 * x: Pointer to array of X coordinates.
2551 * y: Pointer to array of Y coordinates. 2579 * y: Pointer to array of Y coordinates.
2552 */ 2580 */
2553 void API dw_draw_polygon( HWND handle, HPIXMAP pixmap, int flags, int npoints, int *x, int *y ) 2581 void API dw_draw_polygon(HWND handle, HPIXMAP pixmap, int flags, int npoints, int *x, int *y)
2554 { 2582 {
2583 JNIEnv *env;
2584
2585 if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
2586 {
2587 jintArray jx = env->NewIntArray(npoints);
2588 jintArray jy = env->NewIntArray(npoints);
2589
2590 if(jx && jy)
2591 {
2592 // Construct the integer arrays
2593 env->SetIntArrayRegion(jx, 0, npoints, x);
2594 env->SetIntArrayRegion(jy, 0, npoints, y);
2595 // First get the class that contains the method you need to call
2596 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2597 // Get the method that you want to call
2598 jmethodID drawPolygon = env->GetMethodID(clazz, "drawPolygon",
2599 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;II[I[I)V");
2600 // Call the method on the object
2601 env->CallVoidMethod(_dw_obj, drawPolygon, handle, pixmap ? pixmap->bitmap : NULL, flags, npoints, jx, jy);
2602 }
2603 }
2555 } 2604 }
2556 2605
2557 /* Draw a rectangle on a window (preferably a render window). 2606 /* Draw a rectangle on a window (preferably a render window).
2558 * Parameters: 2607 * Parameters:
2559 * handle: Handle to the window. 2608 * handle: Handle to the window.
2574 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 2623 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2575 // Get the method that you want to call 2624 // Get the method that you want to call
2576 jmethodID drawLine = env->GetMethodID(clazz, "drawRect", 2625 jmethodID drawLine = env->GetMethodID(clazz, "drawRect",
2577 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIII)V"); 2626 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIII)V");
2578 // Call the method on the object 2627 // Call the method on the object
2579 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap->bitmap, x, y, width, height); 2628 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : NULL, x, y, width, height);
2580 } 2629 }
2581 } 2630 }
2582 2631
2583 /* Draw an arc on a window (preferably a render window). 2632 /* Draw an arc on a window (preferably a render window).
2584 * Parameters: 2633 * Parameters:
2593 * x2: X coordinate of second segment of arc. 2642 * x2: X coordinate of second segment of arc.
2594 * y2: Y coordinate of second segment of arc. 2643 * y2: Y coordinate of second segment of arc.
2595 */ 2644 */
2596 void API dw_draw_arc(HWND handle, HPIXMAP pixmap, int flags, int xorigin, int yorigin, int x1, int y1, int x2, int y2) 2645 void API dw_draw_arc(HWND handle, HPIXMAP pixmap, int flags, int xorigin, int yorigin, int x1, int y1, int x2, int y2)
2597 { 2646 {
2647 JNIEnv *env;
2648
2649 if((handle || pixmap) && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
2650 {
2651 // First get the class that contains the method you need to call
2652 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2653 // Get the method that you want to call
2654 jmethodID drawLine = env->GetMethodID(clazz, "drawArc",
2655 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIIIIII)V");
2656 // Call the method on the object
2657 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap ? pixmap->bitmap : NULL, flags, xorigin, yorigin, x1, y1, x2, y2);
2658 }
2598 } 2659 }
2599 2660
2600 /* 2661 /*
2601 * Create a tree object to be packed. 2662 * Create a tree object to be packed.
2602 * Parameters: 2663 * Parameters: