Mercurial > dwindows
comparison android/dw.cpp @ 2542:bb75e64e6138
Android: Implement dw_screen_* and dw_environment_query().
Minor code cleanup in dwtest and ios.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 13 May 2021 07:43:31 +0000 |
parents | 822f814a54f4 |
children | f9367eb9a6e7 |
comparison
equal
deleted
inserted
replaced
2541:2ee4df2c50bf | 2542:bb75e64e6138 |
---|---|
36 extern "C" { | 36 extern "C" { |
37 #endif | 37 #endif |
38 | 38 |
39 #define DW_CLASS_NAME "org/dbsoft/dwindows/DWindows" | 39 #define DW_CLASS_NAME "org/dbsoft/dwindows/DWindows" |
40 | 40 |
41 /* Dynamic Windows internal variables */ | |
41 static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0}; | 42 static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0}; |
42 static char _dw_app_name[_DW_APP_ID_SIZE+1]= {0}; | 43 static char _dw_app_name[_DW_APP_ID_SIZE+1]= {0}; |
43 static char _dw_exec_dir[MAX_PATH+1] = {0}; | 44 static char _dw_exec_dir[MAX_PATH+1] = {0}; |
45 static int _dw_android_api = 0; | |
44 | 46 |
45 static pthread_key_t _dw_env_key; | 47 static pthread_key_t _dw_env_key; |
46 static HEV _dw_main_event; | 48 static HEV _dw_main_event; |
47 static JavaVM *_dw_jvm; | 49 static JavaVM *_dw_jvm; |
48 static jobject _dw_obj; | 50 static jobject _dw_obj; |
3411 "(Landroid/graphics/Bitmap;)J"); | 3413 "(Landroid/graphics/Bitmap;)J"); |
3412 // Call the method on the object | 3414 // Call the method on the object |
3413 jlong dimensions = env->CallLongMethod(_dw_obj, pixmapGetDimensions, pixmap->bitmap); | 3415 jlong dimensions = env->CallLongMethod(_dw_obj, pixmapGetDimensions, pixmap->bitmap); |
3414 | 3416 |
3415 pixmap->width = dimensions & 0xFFFF; | 3417 pixmap->width = dimensions & 0xFFFF; |
3416 pixmap->height = dimensions >> 32; | 3418 pixmap->height = (dimensions >> 32) & 0xFFFF; |
3417 } | 3419 } |
3418 } | 3420 } |
3419 | 3421 |
3420 /* | 3422 /* |
3421 * Creates a pixmap with given parameters. | 3423 * Creates a pixmap with given parameters. |
4728 */ | 4730 */ |
4729 void API dw_window_get_pos_size(HWND handle, LONG *x, LONG *y, ULONG *width, ULONG *height) | 4731 void API dw_window_get_pos_size(HWND handle, LONG *x, LONG *y, ULONG *width, ULONG *height) |
4730 { | 4732 { |
4731 } | 4733 } |
4732 | 4734 |
4735 static jlong _dw_screen_dimensions = 0; | |
4736 | |
4733 /* | 4737 /* |
4734 * Returns the width of the screen. | 4738 * Returns the width of the screen. |
4735 */ | 4739 */ |
4736 int API dw_screen_width(void) | 4740 int API dw_screen_width(void) |
4737 { | 4741 { |
4738 return 0; | 4742 if(!_dw_screen_dimensions) |
4743 { | |
4744 JNIEnv *env; | |
4745 | |
4746 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
4747 { | |
4748 // First get the class that contains the method you need to call | |
4749 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
4750 // Get the method that you want to call | |
4751 jmethodID screenGetDimensions = env->GetMethodID(clazz, "screenGetDimensions", | |
4752 "()J"); | |
4753 // Call the method on the object | |
4754 _dw_screen_dimensions = env->CallLongMethod(_dw_obj, screenGetDimensions); | |
4755 } | |
4756 } | |
4757 return _dw_screen_dimensions & 0xFFFF; | |
4739 } | 4758 } |
4740 | 4759 |
4741 /* | 4760 /* |
4742 * Returns the height of the screen. | 4761 * Returns the height of the screen. |
4743 */ | 4762 */ |
4744 int API dw_screen_height(void) | 4763 int API dw_screen_height(void) |
4745 { | 4764 { |
4746 return 0; | 4765 if(!_dw_screen_dimensions) |
4766 { | |
4767 JNIEnv *env; | |
4768 | |
4769 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
4770 { | |
4771 // First get the class that contains the method you need to call | |
4772 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
4773 // Get the method that you want to call | |
4774 jmethodID screenGetDimensions = env->GetMethodID(clazz, "screenGetDimensions", | |
4775 "()J"); | |
4776 // Call the method on the object | |
4777 _dw_screen_dimensions = env->CallLongMethod(_dw_obj, screenGetDimensions); | |
4778 } | |
4779 } | |
4780 return (_dw_screen_dimensions >> 32) & 0xFFFF; | |
4747 } | 4781 } |
4748 | 4782 |
4749 /* This should return the current color depth. */ | 4783 /* This should return the current color depth. */ |
4750 unsigned long API dw_color_depth_get(void) | 4784 unsigned long API dw_color_depth_get(void) |
4751 { | 4785 { |
4757 * Parameters: | 4791 * Parameters: |
4758 * env: Pointer to a DWEnv struct. | 4792 * env: Pointer to a DWEnv struct. |
4759 */ | 4793 */ |
4760 void API dw_environment_query(DWEnv *env) | 4794 void API dw_environment_query(DWEnv *env) |
4761 { | 4795 { |
4762 strcpy(env->osName, "Android"); | 4796 static char osName[_DW_ENV_STRING_SIZE+1] = { 0 }; |
4763 | 4797 |
4764 strcpy(env->buildDate, __DATE__); | 4798 if(!osName[0]) |
4765 strcpy(env->buildTime, __TIME__); | 4799 { |
4800 JNIEnv *env; | |
4801 const char *release = nullptr; | |
4802 | |
4803 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
4804 { | |
4805 // First get the class that contains the method you need to call | |
4806 //jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
4807 jclass clazz = env->FindClass(DW_CLASS_NAME); | |
4808 // Get the method that you want to call | |
4809 jmethodID androidGetRelease = env->GetMethodID(clazz, "androidGetRelease", | |
4810 "()Ljava/lang/String;"); | |
4811 // Call the method on the object | |
4812 jstring jstr = (jstring)env->CallObjectMethod(_dw_obj, androidGetRelease); | |
4813 | |
4814 if(jstr) | |
4815 release = env->GetStringUTFChars(jstr, 0); | |
4816 } | |
4817 snprintf(osName, _DW_ENV_STRING_SIZE-1, "Android%s%s", | |
4818 release ? " " : "", release ? release : ""); | |
4819 } | |
4820 memset(env, '\0', sizeof(DWEnv)); | |
4821 | |
4822 strncpy(env->osName, osName, sizeof(env->osName)-1); | |
4823 strncpy(env->buildDate, __DATE__, sizeof(env->buildDate)-1); | |
4824 strncpy(env->buildTime, __TIME__, sizeof(env->buildTime)-1); | |
4825 strncpy(env->htmlEngine, "CHROME", sizeof(env->htmlEngine)-1); | |
4766 env->DWMajorVersion = DW_MAJOR_VERSION; | 4826 env->DWMajorVersion = DW_MAJOR_VERSION; |
4767 env->DWMinorVersion = DW_MINOR_VERSION; | 4827 env->DWMinorVersion = DW_MINOR_VERSION; |
4768 env->DWSubVersion = DW_SUB_VERSION; | 4828 env->DWSubVersion = DW_SUB_VERSION; |
4769 | 4829 |
4770 env->MajorVersion = 0; /* Operating system major */ | 4830 /* Operating system major */ |
4771 env->MinorVersion = 0; /* Operating system minor */ | 4831 env->MajorVersion = _dw_android_api; |
4772 env->MajorBuild = 0; /* Build versions... if available */ | 4832 /* Operating system minor */ |
4773 env->MinorBuild = 0; | 4833 env->MinorVersion = 0; |
4774 } | 4834 } |
4775 | 4835 |
4776 /* | 4836 /* |
4777 * Emits a beep. | 4837 * Emits a beep. |
4778 * Parameters: | 4838 * Parameters: |
5946 jstring appname = env->NewStringUTF(_dw_app_name); | 6006 jstring appname = env->NewStringUTF(_dw_app_name); |
5947 // First get the class that contains the method you need to call | 6007 // First get the class that contains the method you need to call |
5948 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | 6008 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); |
5949 // Get the method that you want to call | 6009 // Get the method that you want to call |
5950 jmethodID dwInit = env->GetMethodID(clazz, "dwInit", | 6010 jmethodID dwInit = env->GetMethodID(clazz, "dwInit", |
5951 "(Ljava/lang/String;Ljava/lang/String;)V"); | 6011 "(Ljava/lang/String;Ljava/lang/String;)I"); |
5952 // Call the method on the object | 6012 // Call the method on the object |
5953 env->CallVoidMethod(_dw_obj, dwInit, appid, appname); | 6013 _dw_android_api = env->CallIntMethod(_dw_obj, dwInit, appid, appname); |
5954 } | 6014 } |
5955 return DW_ERROR_NONE; | 6015 return DW_ERROR_NONE; |
5956 } | 6016 } |
5957 | 6017 |
5958 /* | 6018 /* |