diff --git a/ohos-project/entry/src/main/cpp/CMakeLists.txt b/ohos-project/entry/src/main/cpp/CMakeLists.txt index b3e379e17c..1b8714f992 100644 --- a/ohos-project/entry/src/main/cpp/CMakeLists.txt +++ b/ohos-project/entry/src/main/cpp/CMakeLists.txt @@ -16,6 +16,6 @@ include_directories(${NATIVERENDER_ROOT_PATH} ${NATIVERENDER_ROOT_PATH}/include ${SDL3_SOURCE_DIR}/include) -add_library(entry SHARED napi_init.cpp) +add_library(entry SHARED entrypoint.cpp) add_dependencies(entry SDL3::SDL3-shared) target_link_libraries(entry PUBLIC libace_napi.z.so libSDL3.so libvulkan.so libGLESv2.so libohaudio.so libohsensor.so) diff --git a/ohos-project/entry/src/main/cpp/napi_init.cpp b/ohos-project/entry/src/main/cpp/entrypoint.cpp similarity index 84% rename from ohos-project/entry/src/main/cpp/napi_init.cpp rename to ohos-project/entry/src/main/cpp/entrypoint.cpp index d764002add..08922b3e57 100644 --- a/ohos-project/entry/src/main/cpp/napi_init.cpp +++ b/ohos-project/entry/src/main/cpp/entrypoint.cpp @@ -8,7 +8,6 @@ #include "SDL3/SDL_vulkan.h" #include "SDL3/SDL_locale.h" #include "SDL3/SDL_clipboard.h" -#include "napi/native_api.h" #include "SDL3/SDL_log.h" #include "SDL3/SDL_hints.h" #include "SDL3/SDL_power.h" @@ -23,44 +22,6 @@ #include #include -static napi_value Add(napi_env env, napi_callback_info info) -{ - size_t argc = 2; - napi_value args[2] = {nullptr}; - - napi_get_cb_info(env, info, &argc, args , nullptr, nullptr); - - napi_valuetype valuetype0; - napi_typeof(env, args[0], &valuetype0); - - napi_valuetype valuetype1; - napi_typeof(env, args[1], &valuetype1); - - double value0; - napi_get_value_double(env, args[0], &value0); - - double value1; - napi_get_value_double(env, args[1], &value1); - - napi_value sum; - napi_create_double(env, value0 + value1, &sum); - - SDL_Log("Add invoke!"); - - return sum; - -} - -EXTERN_C_START -static napi_value Init(napi_env env, napi_value exports) -{ - napi_property_descriptor desc[] = { - { "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr } - }; - napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); - return exports; -} - float vtxdata[] = { -0.5f, -0.5f, 0.f, 0.5f, -0.5f, 0.0f, @@ -124,8 +85,6 @@ int main() SDL_Window* win = SDL_CreateWindow("test", 1024, 1024, SDL_WINDOW_OPENGL); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "SDL Application", "test!", win); - SDL_StartTextInput(win); - // SDL_StopTextInput(); auto context = SDL_GL_CreateContext(win); SDL_GL_MakeCurrent(win, context); @@ -167,6 +126,7 @@ int main() ((PFNGLCLEARCOLORPROC)SDL_GL_GetProcAddress("glClearColor"))(0, 0, 0, 0); while (true) { + SDL_StartTextInput(win); int w, h; SDL_GetWindowSize(win, &w, &h); @@ -200,6 +160,10 @@ int main() if (event.type == SDL_EVENT_QUIT) { break; } + + if (event.type == SDL_EVENT_TEXT_INPUT) { + SDL_Log("text %s", event.text.text); + } } } @@ -210,20 +174,4 @@ int main() SDL_DestroyWindow(win); return 0; -} -EXTERN_C_END - -static napi_module demoModule = { - .nm_version = 1, - .nm_flags = 0, - .nm_filename = nullptr, - .nm_register_func = Init, - .nm_modname = "entry", - .nm_priv = ((void*)0), - .reserved = { 0 }, -}; - -extern "C" __attribute__((constructor)) void RegisterEntryModule(void) -{ - napi_module_register(&demoModule); -} +} \ No newline at end of file diff --git a/ohos-project/entry/src/main/ets/pages/Index.ets b/ohos-project/entry/src/main/ets/pages/Index.ets index 8ec3487e9f..72da526504 100644 --- a/ohos-project/entry/src/main/ets/pages/Index.ets +++ b/ohos-project/entry/src/main/ets/pages/Index.ets @@ -186,7 +186,6 @@ struct Index { if (targetText.length > 0) { targetText = targetText.substring(0, targetText.length - i) } - hilog.info(DOMAIN, 'surfaceLayer', targetText) }) controller.on('deleteRight', (i) => { sdl.sdlTextEditing(targetText, 0, i); @@ -194,7 +193,6 @@ struct Index { if (targetText.length > 0) { targetText = targetText.substring(i, targetText.length) } - hilog.info(DOMAIN, 'surfaceLayer', targetText) }) } diff --git a/src/core/ohos/SDL_ohos.c b/src/core/ohos/SDL_ohos.c index 5792f914a6..318dce9e87 100644 --- a/src/core/ohos/SDL_ohos.c +++ b/src/core/ohos/SDL_ohos.c @@ -800,6 +800,8 @@ static napi_value sdlTextAppend(napi_env env, napi_callback_info info) SDL_SendKeyboardText(fname); + SDL_free(fname); + napi_value result; napi_create_int32(env, 0, &result); return result; @@ -822,6 +824,8 @@ static napi_value sdlTextEditing(napi_env env, napi_callback_info info) SDL_SendEditingText(fname, start, len); + SDL_free(fname); + napi_value result; napi_create_int32(env, 0, &result); return result;