forked from Green-Sky/tomato
Green Sky
293f4fd0a0
00ad3c65bc2 Version 1.90.7 f814ef816fb Commented out CaptureKeyboardFromApp(), CaptureMouseFromApp(). Commented out obsolete IsKeyPressedMap() from imgui_internal.h (can call IsKeyPressed). Comments b9084949bd7 Fixed typo in IsMouseDragging and GetMouseDragDelta's documentation. (#7620) 86931393a36 Shortcuts: Revert "SetShortcutRouting: require explicit routing. (#456) 7832e6a70e6 Shortcuts: Routing: fixed mixed keys<>chars filtering not applying on global routes. (#456, #7618) 85d982011e9 Shortcuts: fixed priority of route calculation (higher first). (#456, #7618) ce4e210dcb6 Shotcuts: renamed ImGuiInputFlags_RouteGlobalOverFocused -> ImGuiInputFlags_RouteOverFocused, ImGuiInputFlags_RouteGlobalOverActive -> ImGuiInputFlags_RouteOverActive in previsiion of using them with a Hovered route. (#456) 5ce3d299555 Shortcuts: rename ImGuiInputFlags_RouteGlobalHighest to ImGuiInputFlags_RouteGlobalOverActive, made ImGuiInputFlags_RouteGlobalOverFocused and ImGuiInputFlags_RouteGlobalOverActive flags. (#456) 650cb51bf10 Shortcuts: renamed ImGuiInputFlags_RouteActiveItem to ImGuiInputFlags_RouteActive. (#456, #7618) ef9d525f02c Shortcuts: added ImGuiInputFlags_RouteActiveItem. (#456, #7618) + rearrange Changelog 16b72f2d210 Comments 29439bdd27c Windows: BeginChild(): fixed auto-fit calculation when using either (not both) ResizeX/ResizeY and double-clicking on a border. (#1710) 374b9a7fb43 Demo: Documents: refactor + add Renaming option. (#7233) c150ad50c46 Shortcuts: claim mods ownership once pressed. (#456, #2637, #2620, #2891, #3370, #3724, #4828, #5108, #5242, #5641) 1002cfa6d2d Demo, Shortcut(): amend Shortcuts demo. (#456) 7c71e66370d Shortcuts, SetShortcutRouting: move ImGuiInputFlags_RouteFromRootWindow evaluation to SetShortcutRouting() for now. (#456) d5a600e9c64 Shortcuts, SetShortcutRouting: added ImGuiInputFlags_RouteFromRootWindow. Made it possible for SetShortcutRouting() to query for another location. 0eb025f4847 Internals: move ItemHandleShortcut() next to Shortcut(), it's calling it anyhow. (#456) a689fa262ae SetShortcutRouting: require explicit routing. (#456) c06e6340cde Shortcuts: added ImGuiInputFlags_Tooltip. (#456) 77e41718940 Shortcuts: added flags to SetNextItemShortcut(). (#456) 197f8904fe8 Shortcuts, Nav: make SetNextItemShortcut() work when another item is active. Made NavCalcPreferredRefPos() take account for remote activation. (#456) dc5caa483cd Demo: added "Shortcuts" section. (#456, #2637) fc512a24741 Inputs: Added Shortcut(), SetNextItemShortcut(). Added ImGuiInputFlags, ImGuiInputFlags_RouteXXXX. (#456, #2637) 85513de2476 Internals, Inputs: *Breaking* Swapped parameter order of owner-aware versions of IsKeyPressed(), IsKeyChordPressed(), IsMouseClicked(). (#456) 900b29055c5 Internals, Inputs: *Breaking* Swapped parameter order of Shortcut(). (#456) 55748cdbe12 Internals, Inputs: *Breaking* Renamed ImGuiKeyOwner_None to ImGuiKeyOwner_NoOwner: avoid confusion with non zero value, makes IsKeyPressed() calls using ImGuiKeyOwner_NoOwner more explicit. ec1d2be96f3 Examples: Win32+DX9,DX10,DX11,DX12: rework main loop to handle minimization and screen locking. (#2496, #3907, #6308, #7615) 6d1a6f1c748 Internals, Inputs: Comments, alignment. 4c3eac2c10e Backends: OpenGL3: Fixed zealous warning by initializing last_pixel_unpack_buffer. (#7614) a1566c5e1ba Tables: fixed 28a283b breaking PageDown on tables with no interactive items. aa725ca79dc Inputs: moving ImGuiInputFlags_RouteAlways into ImGuiInputFlags_RouteTypeMask_ cd48059dc53 Tables: comments about skipping access to table data in coarse clipping path. 28a283b4603 Windows: BeginChild(), Tables:fixed visibility of fully clipped child windows and tables to Test Engine. aa5a6098ee2 Fixed typos in comments (#7599) d39ca33b63a Fixed false positive with PVS-Studio. ae8218a3eaf Inputs, Shortcut: fixes some edge cases for GetKeyChordName(), clarify that it is aimed at display. (#456) 25e279ee73f Inputs: Treat ctrl-left-click as right click when ConfigMacOSXBehaviors is set. (#2343) b4f564c1ed7 Internals: Shortcuts: *Breaking* : rename ImGuiInputFlags_RouteGlobalLow -> ImGuiInputFlags_RouteGlobal, ImGuiInputFlags_RouteGlobal -> ImGuiInputFlags_RouteGlobalOverFocused, ImGuiInputFlags_RouteGlobalHigh -> ImGuiInputFlags_RouteGlobalHighest (#456) 5107e58b0f3 Inputs: amend changelog and clarify how the swap might be a breaking change for a minority of users. (#2343) 8bd5d1d42f0 Inputs: Fixed swapping of keys associated to mods. Fixed warnings. (#2343, #4084, #5923, #456) 77471066471 Inputs: swap Ctrl and Cmd on macOS X, remove ImGuiMod_Shortcut. (#2343, #4084, #5923, #456) 07dbcf1f70d Fixed typos. (#7593) 93daf232233 Examples: SDL3: updates for latest SDL3 API changes. e45efa9951a Backends: SDL3: Rename SDLK_QUOTE and SDLK_BACKQUOTE to SDLK_APOSTROPHE and SDLK_GRAVE. (#7580) 5d973a87d45 Backends: SDL_Renderer2/SDL_Renderer3: and ImGui_ImplSDLRenderer2_RenderDrawData() and ImGui_ImplSDLRenderer3_RenderDrawData() now takes a SDL_Renderer* parameter. af2fbf043df Backends/Internals: Don't use IME and clipboard default win32 functions when WINAPI_FAMILY_GAMES (#7585) e4576914cb9 Internals: amend f806c76 to better match docking + fixed unused static forward declaration warning. d0524df8879 Internals: slight refactor FindHoveredWindow() -> FindHoveredWindowEx() toward reducing far-away code duplication. f806c76e97b Tables, Dpi: added dummy g.DpiScale storage (to be altered in docking), using to scale tables border hit thickness. f0912833ba9 Update FAQ.md (#7581) ac90e1bd5bd Backends: Win32: replace bd != nullptr assert with early out. (#6275) 0a5d40a0161 Update FAQ.md d06b8b58d84 Nav: fixed holding Ctrl or gamepad L1 from not slowing down keyboard/gamepad tweak speed. 5e236804541 Backends: all backends + demo now call IMGUI_CHECKVERSION() to verify ABI compatibility between caller code and compiled version of dear imgui. (#7568) 510eb8f4801 Tables: fixed cell background of fully clipped row overlapping with header. (#7575, #7041) f48aae600a2 Version 1.90.7 WIP git-subtree-dir: external/imgui/imgui git-subtree-split: 00ad3c65bc256a16521288505f26fb335440f8f5
384 lines
14 KiB
C++
384 lines
14 KiB
C++
// dear imgui: standalone example application for Android + OpenGL ES 3
|
|
|
|
// Learn about Dear ImGui:
|
|
// - FAQ https://dearimgui.com/faq
|
|
// - Getting Started https://dearimgui.com/getting-started
|
|
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
|
// - Introduction, links and more at the top of imgui.cpp
|
|
|
|
#include "imgui.h"
|
|
#include "imgui_impl_android.h"
|
|
#include "imgui_impl_opengl3.h"
|
|
#include <android/log.h>
|
|
#include <android_native_app_glue.h>
|
|
#include <android/asset_manager.h>
|
|
#include <EGL/egl.h>
|
|
#include <GLES3/gl3.h>
|
|
#include <string>
|
|
|
|
// Data
|
|
static EGLDisplay g_EglDisplay = EGL_NO_DISPLAY;
|
|
static EGLSurface g_EglSurface = EGL_NO_SURFACE;
|
|
static EGLContext g_EglContext = EGL_NO_CONTEXT;
|
|
static struct android_app* g_App = nullptr;
|
|
static bool g_Initialized = false;
|
|
static char g_LogTag[] = "ImGuiExample";
|
|
static std::string g_IniFilename = "";
|
|
|
|
// Forward declarations of helper functions
|
|
static void Init(struct android_app* app);
|
|
static void Shutdown();
|
|
static void MainLoopStep();
|
|
static int ShowSoftKeyboardInput();
|
|
static int PollUnicodeChars();
|
|
static int GetAssetData(const char* filename, void** out_data);
|
|
|
|
// Main code
|
|
static void handleAppCmd(struct android_app* app, int32_t appCmd)
|
|
{
|
|
switch (appCmd)
|
|
{
|
|
case APP_CMD_SAVE_STATE:
|
|
break;
|
|
case APP_CMD_INIT_WINDOW:
|
|
Init(app);
|
|
break;
|
|
case APP_CMD_TERM_WINDOW:
|
|
Shutdown();
|
|
break;
|
|
case APP_CMD_GAINED_FOCUS:
|
|
case APP_CMD_LOST_FOCUS:
|
|
break;
|
|
}
|
|
}
|
|
|
|
static int32_t handleInputEvent(struct android_app* app, AInputEvent* inputEvent)
|
|
{
|
|
return ImGui_ImplAndroid_HandleInputEvent(inputEvent);
|
|
}
|
|
|
|
void android_main(struct android_app* app)
|
|
{
|
|
app->onAppCmd = handleAppCmd;
|
|
app->onInputEvent = handleInputEvent;
|
|
|
|
while (true)
|
|
{
|
|
int out_events;
|
|
struct android_poll_source* out_data;
|
|
|
|
// Poll all events. If the app is not visible, this loop blocks until g_Initialized == true.
|
|
while (ALooper_pollAll(g_Initialized ? 0 : -1, nullptr, &out_events, (void**)&out_data) >= 0)
|
|
{
|
|
// Process one event
|
|
if (out_data != nullptr)
|
|
out_data->process(app, out_data);
|
|
|
|
// Exit the app by returning from within the infinite loop
|
|
if (app->destroyRequested != 0)
|
|
{
|
|
// shutdown() should have been called already while processing the
|
|
// app command APP_CMD_TERM_WINDOW. But we play save here
|
|
if (!g_Initialized)
|
|
Shutdown();
|
|
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Initiate a new frame
|
|
MainLoopStep();
|
|
}
|
|
}
|
|
|
|
void Init(struct android_app* app)
|
|
{
|
|
if (g_Initialized)
|
|
return;
|
|
|
|
g_App = app;
|
|
ANativeWindow_acquire(g_App->window);
|
|
|
|
// Initialize EGL
|
|
// This is mostly boilerplate code for EGL...
|
|
{
|
|
g_EglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
|
if (g_EglDisplay == EGL_NO_DISPLAY)
|
|
__android_log_print(ANDROID_LOG_ERROR, g_LogTag, "%s", "eglGetDisplay(EGL_DEFAULT_DISPLAY) returned EGL_NO_DISPLAY");
|
|
|
|
if (eglInitialize(g_EglDisplay, 0, 0) != EGL_TRUE)
|
|
__android_log_print(ANDROID_LOG_ERROR, g_LogTag, "%s", "eglInitialize() returned with an error");
|
|
|
|
const EGLint egl_attributes[] = { EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, EGL_DEPTH_SIZE, 24, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE };
|
|
EGLint num_configs = 0;
|
|
if (eglChooseConfig(g_EglDisplay, egl_attributes, nullptr, 0, &num_configs) != EGL_TRUE)
|
|
__android_log_print(ANDROID_LOG_ERROR, g_LogTag, "%s", "eglChooseConfig() returned with an error");
|
|
if (num_configs == 0)
|
|
__android_log_print(ANDROID_LOG_ERROR, g_LogTag, "%s", "eglChooseConfig() returned 0 matching config");
|
|
|
|
// Get the first matching config
|
|
EGLConfig egl_config;
|
|
eglChooseConfig(g_EglDisplay, egl_attributes, &egl_config, 1, &num_configs);
|
|
EGLint egl_format;
|
|
eglGetConfigAttrib(g_EglDisplay, egl_config, EGL_NATIVE_VISUAL_ID, &egl_format);
|
|
ANativeWindow_setBuffersGeometry(g_App->window, 0, 0, egl_format);
|
|
|
|
const EGLint egl_context_attributes[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
|
|
g_EglContext = eglCreateContext(g_EglDisplay, egl_config, EGL_NO_CONTEXT, egl_context_attributes);
|
|
|
|
if (g_EglContext == EGL_NO_CONTEXT)
|
|
__android_log_print(ANDROID_LOG_ERROR, g_LogTag, "%s", "eglCreateContext() returned EGL_NO_CONTEXT");
|
|
|
|
g_EglSurface = eglCreateWindowSurface(g_EglDisplay, egl_config, g_App->window, nullptr);
|
|
eglMakeCurrent(g_EglDisplay, g_EglSurface, g_EglSurface, g_EglContext);
|
|
}
|
|
|
|
// Setup Dear ImGui context
|
|
IMGUI_CHECKVERSION();
|
|
ImGui::CreateContext();
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
// Redirect loading/saving of .ini file to our location.
|
|
// Make sure 'g_IniFilename' persists while we use Dear ImGui.
|
|
g_IniFilename = std::string(app->activity->internalDataPath) + "/imgui.ini";
|
|
io.IniFilename = g_IniFilename.c_str();;
|
|
|
|
// Setup Dear ImGui style
|
|
ImGui::StyleColorsDark();
|
|
//ImGui::StyleColorsLight();
|
|
|
|
// Setup Platform/Renderer backends
|
|
ImGui_ImplAndroid_Init(g_App->window);
|
|
ImGui_ImplOpenGL3_Init("#version 300 es");
|
|
|
|
// Load Fonts
|
|
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
|
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
|
// - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
|
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
|
// - Android: The TTF files have to be placed into the assets/ directory (android/app/src/main/assets), we use our GetAssetData() helper to retrieve them.
|
|
|
|
// We load the default font with increased size to improve readability on many devices with "high" DPI.
|
|
// FIXME: Put some effort into DPI awareness.
|
|
// Important: when calling AddFontFromMemoryTTF(), ownership of font_data is transferred by Dear ImGui by default (deleted is handled by Dear ImGui), unless we set FontDataOwnedByAtlas=false in ImFontConfig
|
|
ImFontConfig font_cfg;
|
|
font_cfg.SizePixels = 22.0f;
|
|
io.Fonts->AddFontDefault(&font_cfg);
|
|
//void* font_data;
|
|
//int font_data_size;
|
|
//ImFont* font;
|
|
//font_data_size = GetAssetData("segoeui.ttf", &font_data);
|
|
//font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size, 16.0f);
|
|
//IM_ASSERT(font != nullptr);
|
|
//font_data_size = GetAssetData("DroidSans.ttf", &font_data);
|
|
//font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size, 16.0f);
|
|
//IM_ASSERT(font != nullptr);
|
|
//font_data_size = GetAssetData("Roboto-Medium.ttf", &font_data);
|
|
//font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size, 16.0f);
|
|
//IM_ASSERT(font != nullptr);
|
|
//font_data_size = GetAssetData("Cousine-Regular.ttf", &font_data);
|
|
//font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size, 15.0f);
|
|
//IM_ASSERT(font != nullptr);
|
|
//font_data_size = GetAssetData("ArialUni.ttf", &font_data);
|
|
//font = io.Fonts->AddFontFromMemoryTTF(font_data, font_data_size, 18.0f, nullptr, io.Fonts->GetGlyphRangesJapanese());
|
|
//IM_ASSERT(font != nullptr);
|
|
|
|
// Arbitrary scale-up
|
|
// FIXME: Put some effort into DPI awareness
|
|
ImGui::GetStyle().ScaleAllSizes(3.0f);
|
|
|
|
g_Initialized = true;
|
|
}
|
|
|
|
void MainLoopStep()
|
|
{
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
if (g_EglDisplay == EGL_NO_DISPLAY)
|
|
return;
|
|
|
|
// Our state
|
|
// (we use static, which essentially makes the variable globals, as a convenience to keep the example code easy to follow)
|
|
static bool show_demo_window = true;
|
|
static bool show_another_window = false;
|
|
static ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
|
|
|
// Poll Unicode characters via JNI
|
|
// FIXME: do not call this every frame because of JNI overhead
|
|
PollUnicodeChars();
|
|
|
|
// Open on-screen (soft) input if requested by Dear ImGui
|
|
static bool WantTextInputLast = false;
|
|
if (io.WantTextInput && !WantTextInputLast)
|
|
ShowSoftKeyboardInput();
|
|
WantTextInputLast = io.WantTextInput;
|
|
|
|
// Start the Dear ImGui frame
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
ImGui_ImplAndroid_NewFrame();
|
|
ImGui::NewFrame();
|
|
|
|
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
|
if (show_demo_window)
|
|
ImGui::ShowDemoWindow(&show_demo_window);
|
|
|
|
// 2. Show a simple window that we create ourselves. We use a Begin/End pair to create a named window.
|
|
{
|
|
static float f = 0.0f;
|
|
static int counter = 0;
|
|
|
|
ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
|
|
|
|
ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
|
|
ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
|
|
ImGui::Checkbox("Another Window", &show_another_window);
|
|
|
|
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
|
|
ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
|
|
|
|
if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
|
|
counter++;
|
|
ImGui::SameLine();
|
|
ImGui::Text("counter = %d", counter);
|
|
|
|
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
|
|
ImGui::End();
|
|
}
|
|
|
|
// 3. Show another simple window.
|
|
if (show_another_window)
|
|
{
|
|
ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
|
|
ImGui::Text("Hello from another window!");
|
|
if (ImGui::Button("Close Me"))
|
|
show_another_window = false;
|
|
ImGui::End();
|
|
}
|
|
|
|
// Rendering
|
|
ImGui::Render();
|
|
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
|
|
glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
eglSwapBuffers(g_EglDisplay, g_EglSurface);
|
|
}
|
|
|
|
void Shutdown()
|
|
{
|
|
if (!g_Initialized)
|
|
return;
|
|
|
|
// Cleanup
|
|
ImGui_ImplOpenGL3_Shutdown();
|
|
ImGui_ImplAndroid_Shutdown();
|
|
ImGui::DestroyContext();
|
|
|
|
if (g_EglDisplay != EGL_NO_DISPLAY)
|
|
{
|
|
eglMakeCurrent(g_EglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
|
|
|
if (g_EglContext != EGL_NO_CONTEXT)
|
|
eglDestroyContext(g_EglDisplay, g_EglContext);
|
|
|
|
if (g_EglSurface != EGL_NO_SURFACE)
|
|
eglDestroySurface(g_EglDisplay, g_EglSurface);
|
|
|
|
eglTerminate(g_EglDisplay);
|
|
}
|
|
|
|
g_EglDisplay = EGL_NO_DISPLAY;
|
|
g_EglContext = EGL_NO_CONTEXT;
|
|
g_EglSurface = EGL_NO_SURFACE;
|
|
ANativeWindow_release(g_App->window);
|
|
|
|
g_Initialized = false;
|
|
}
|
|
|
|
// Helper functions
|
|
|
|
// Unfortunately, there is no way to show the on-screen input from native code.
|
|
// Therefore, we call ShowSoftKeyboardInput() of the main activity implemented in MainActivity.kt via JNI.
|
|
static int ShowSoftKeyboardInput()
|
|
{
|
|
JavaVM* java_vm = g_App->activity->vm;
|
|
JNIEnv* java_env = nullptr;
|
|
|
|
jint jni_return = java_vm->GetEnv((void**)&java_env, JNI_VERSION_1_6);
|
|
if (jni_return == JNI_ERR)
|
|
return -1;
|
|
|
|
jni_return = java_vm->AttachCurrentThread(&java_env, nullptr);
|
|
if (jni_return != JNI_OK)
|
|
return -2;
|
|
|
|
jclass native_activity_clazz = java_env->GetObjectClass(g_App->activity->clazz);
|
|
if (native_activity_clazz == nullptr)
|
|
return -3;
|
|
|
|
jmethodID method_id = java_env->GetMethodID(native_activity_clazz, "showSoftInput", "()V");
|
|
if (method_id == nullptr)
|
|
return -4;
|
|
|
|
java_env->CallVoidMethod(g_App->activity->clazz, method_id);
|
|
|
|
jni_return = java_vm->DetachCurrentThread();
|
|
if (jni_return != JNI_OK)
|
|
return -5;
|
|
|
|
return 0;
|
|
}
|
|
|
|
// Unfortunately, the native KeyEvent implementation has no getUnicodeChar() function.
|
|
// Therefore, we implement the processing of KeyEvents in MainActivity.kt and poll
|
|
// the resulting Unicode characters here via JNI and send them to Dear ImGui.
|
|
static int PollUnicodeChars()
|
|
{
|
|
JavaVM* java_vm = g_App->activity->vm;
|
|
JNIEnv* java_env = nullptr;
|
|
|
|
jint jni_return = java_vm->GetEnv((void**)&java_env, JNI_VERSION_1_6);
|
|
if (jni_return == JNI_ERR)
|
|
return -1;
|
|
|
|
jni_return = java_vm->AttachCurrentThread(&java_env, nullptr);
|
|
if (jni_return != JNI_OK)
|
|
return -2;
|
|
|
|
jclass native_activity_clazz = java_env->GetObjectClass(g_App->activity->clazz);
|
|
if (native_activity_clazz == nullptr)
|
|
return -3;
|
|
|
|
jmethodID method_id = java_env->GetMethodID(native_activity_clazz, "pollUnicodeChar", "()I");
|
|
if (method_id == nullptr)
|
|
return -4;
|
|
|
|
// Send the actual characters to Dear ImGui
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
jint unicode_character;
|
|
while ((unicode_character = java_env->CallIntMethod(g_App->activity->clazz, method_id)) != 0)
|
|
io.AddInputCharacter(unicode_character);
|
|
|
|
jni_return = java_vm->DetachCurrentThread();
|
|
if (jni_return != JNI_OK)
|
|
return -5;
|
|
|
|
return 0;
|
|
}
|
|
|
|
// Helper to retrieve data placed into the assets/ directory (android/app/src/main/assets)
|
|
static int GetAssetData(const char* filename, void** outData)
|
|
{
|
|
int num_bytes = 0;
|
|
AAsset* asset_descriptor = AAssetManager_open(g_App->activity->assetManager, filename, AASSET_MODE_BUFFER);
|
|
if (asset_descriptor)
|
|
{
|
|
num_bytes = AAsset_getLength(asset_descriptor);
|
|
*outData = IM_ALLOC(num_bytes);
|
|
int64_t num_bytes_read = AAsset_read(asset_descriptor, *outData, num_bytes);
|
|
AAsset_close(asset_descriptor);
|
|
IM_ASSERT(num_bytes_read == num_bytes);
|
|
}
|
|
return num_bytes;
|
|
}
|