comparison android/dw.cpp @ 2531:f45ebd96ebe5

Android: First attempts at implementing drawing functions
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 11 May 2021 00:51:20 +0000
parents b9923432cb1f
children 457c91634881
comparison
equal deleted inserted replaced
2530:b9923432cb1f 2531:f45ebd96ebe5
541 return DWSignalTranslate[z].message; 541 return DWSignalTranslate[z].message;
542 } 542 }
543 return 0L; 543 return 0L;
544 } 544 }
545 545
546 unsigned long _dw_colors[] =
547 {
548 0x00000000, /* 0 black */
549 0x000000bb, /* 1 red */
550 0x0000bb00, /* 2 green */
551 0x0000aaaa, /* 3 yellow */
552 0x00cc0000, /* 4 blue */
553 0x00bb00bb, /* 5 magenta */
554 0x00bbbb00, /* 6 cyan */
555 0x00bbbbbb, /* 7 white */
556 0x00777777, /* 8 grey */
557 0x000000ff, /* 9 bright red */
558 0x0000ff00, /* 10 bright green */
559 0x0000eeee, /* 11 bright yellow */
560 0x00ff0000, /* 12 bright blue */
561 0x00ff00ff, /* 13 bright magenta */
562 0x00eeee00, /* 14 bright cyan */
563 0x00ffffff, /* 15 bright white */
564 0xff000000 /* 16 default color */
565 };
566
567 /* Return the RGB color regardless if a predefined color was passed */
568 unsigned long _dw_get_color(unsigned long thiscolor)
569 {
570 if(thiscolor & DW_RGB_COLOR)
571 {
572 return thiscolor & ~DW_RGB_COLOR;
573 }
574 else if(thiscolor < 17)
575 {
576 return _dw_colors[thiscolor];
577 }
578 return 0;
579 }
580
546 /* 581 /*
547 * Runs a message loop for Dynamic Windows. 582 * Runs a message loop for Dynamic Windows.
548 */ 583 */
549 void API dw_main(void) 584 void API dw_main(void)
550 { 585 {
2395 * green: green value. 2430 * green: green value.
2396 * blue: blue value. 2431 * blue: blue value.
2397 */ 2432 */
2398 void API dw_color_foreground_set(unsigned long value) 2433 void API dw_color_foreground_set(unsigned long value)
2399 { 2434 {
2435 JNIEnv *env;
2436
2437 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
2438 {
2439 unsigned long color = _dw_get_color(value);
2440
2441 // First get the class that contains the method you need to call
2442 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2443 // Get the method that you want to call
2444 jmethodID colorSet = env->GetMethodID(clazz, "colorSet",
2445 "(IIII)V");
2446 // Call the method on the object
2447 env->CallVoidMethod(_dw_obj, colorSet, 0, (jint)DW_RED_VALUE(color), (jint)DW_GREEN_VALUE(color), (jint)DW_BLUE_VALUE(color));
2448 }
2400 } 2449 }
2401 2450
2402 /* Sets the current background drawing color. 2451 /* Sets the current background drawing color.
2403 * Parameters: 2452 * Parameters:
2404 * red: red value. 2453 * red: red value.
2427 * x: X coordinate. 2476 * x: X coordinate.
2428 * y: Y coordinate. 2477 * y: Y coordinate.
2429 */ 2478 */
2430 void API dw_draw_point(HWND handle, HPIXMAP pixmap, int x, int y) 2479 void API dw_draw_point(HWND handle, HPIXMAP pixmap, int x, int y)
2431 { 2480 {
2481 JNIEnv *env;
2482
2483 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
2484 {
2485 // First get the class that contains the method you need to call
2486 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2487 // Get the method that you want to call
2488 jmethodID drawPoint = env->GetMethodID(clazz, "drawPoint",
2489 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;II)V");
2490 // Call the method on the object
2491 env->CallVoidMethod(_dw_obj, drawPoint, handle, pixmap->bitmap, x, y);
2492 }
2432 } 2493 }
2433 2494
2434 /* Draw a line on a window (preferably a render window). 2495 /* Draw a line on a window (preferably a render window).
2435 * Parameters: 2496 * Parameters:
2436 * handle: Handle to the window. 2497 * handle: Handle to the window.
2440 * x2: Second X coordinate. 2501 * x2: Second X coordinate.
2441 * y2: Second Y coordinate. 2502 * y2: Second Y coordinate.
2442 */ 2503 */
2443 void API dw_draw_line(HWND handle, HPIXMAP pixmap, int x1, int y1, int x2, int y2) 2504 void API dw_draw_line(HWND handle, HPIXMAP pixmap, int x1, int y1, int x2, int y2)
2444 { 2505 {
2506 JNIEnv *env;
2507
2508 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
2509 {
2510 // First get the class that contains the method you need to call
2511 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2512 // Get the method that you want to call
2513 jmethodID drawLine = env->GetMethodID(clazz, "drawLine",
2514 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIII)V");
2515 // Call the method on the object
2516 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap->bitmap, x1, y1, x2, y2);
2517 }
2445 } 2518 }
2446 2519
2447 /* Draw text on a window (preferably a render window). 2520 /* Draw text on a window (preferably a render window).
2448 * Parameters: 2521 * Parameters:
2449 * handle: Handle to the window. 2522 * handle: Handle to the window.
2491 * width: Width of rectangle. 2564 * width: Width of rectangle.
2492 * height: Height of rectangle. 2565 * height: Height of rectangle.
2493 */ 2566 */
2494 void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int flags, int x, int y, int width, int height) 2567 void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int flags, int x, int y, int width, int height)
2495 { 2568 {
2569 JNIEnv *env;
2570
2571 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
2572 {
2573 // First get the class that contains the method you need to call
2574 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
2575 // Get the method that you want to call
2576 jmethodID drawLine = env->GetMethodID(clazz, "drawRect",
2577 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIII)V");
2578 // Call the method on the object
2579 env->CallVoidMethod(_dw_obj, drawLine, handle, pixmap->bitmap, x, y, width, height);
2580 }
2496 } 2581 }
2497 2582
2498 /* Draw an arc on a window (preferably a render window). 2583 /* Draw an arc on a window (preferably a render window).
2499 * Parameters: 2584 * Parameters:
2500 * handle: Handle to the window. 2585 * handle: Handle to the window.
3453 * xsrc: X coordinate of source. 3538 * xsrc: X coordinate of source.
3454 * ysrc: Y coordinate of source. 3539 * ysrc: Y coordinate of source.
3455 */ 3540 */
3456 void API dw_pixmap_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc) 3541 void API dw_pixmap_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc)
3457 { 3542 {
3543 dw_pixmap_stretch_bitblt(dest, destp, xdest, ydest, width, height, src, srcp, xsrc, ysrc, -1, -1);
3458 } 3544 }
3459 3545
3460 /* 3546 /*
3461 * Copies from one surface to another allowing for stretching. 3547 * Copies from one surface to another allowing for stretching.
3462 * Parameters: 3548 * Parameters:
3475 * Returns: 3561 * Returns:
3476 * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure. 3562 * DW_ERROR_NONE on success and DW_ERROR_GENERAL on failure.
3477 */ 3563 */
3478 int API dw_pixmap_stretch_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc, int srcwidth, int srcheight) 3564 int API dw_pixmap_stretch_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc, int srcwidth, int srcheight)
3479 { 3565 {
3480 return DW_ERROR_GENERAL; 3566 JNIEnv *env;
3567 int retval = DW_ERROR_GENERAL;
3568
3569 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
3570 {
3571 // First get the class that contains the method you need to call
3572 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
3573 // Get the method that you want to call
3574 jmethodID pixmapBitBlt = env->GetMethodID(clazz, "pixmapBitBlt",
3575 "(Lorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIIILorg/dbsoft/dwindows/DWRender;Landroid/graphics/Bitmap;IIII)I");
3576 // Call the method on the object
3577 retval = env->CallIntMethod(_dw_obj, pixmapBitBlt, dest, destp->bitmap, xdest, ydest, width, height, src, srcp->bitmap, xsrc, ysrc, srcwidth, srcheight);
3578 }
3579 return retval;
3481 } 3580 }
3482 3581
3483 /* 3582 /*
3484 * Create a new calendar window (widget) to be packed. 3583 * Create a new calendar window (widget) to be packed.
3485 * Parameters: 3584 * Parameters:
4587 } 4686 }
4588 4687
4589 /* This should return the current color depth. */ 4688 /* This should return the current color depth. */
4590 unsigned long API dw_color_depth_get(void) 4689 unsigned long API dw_color_depth_get(void)
4591 { 4690 {
4592 return 0; 4691 return 32;
4593 } 4692 }
4594 4693
4595 /* 4694 /*
4596 * Returns some information about the current operating environment. 4695 * Returns some information about the current operating environment.
4597 * Parameters: 4696 * Parameters: