satdump/android/backend.cpp

129 lines
3.6 KiB
C++
Raw Normal View History

2023-12-31 11:11:36 -05:00
#include "backend.h"
2024-03-14 12:39:41 -04:00
#include "core/exception.h"
2026-01-13 21:40:02 +01:00
#include "logger.h"
2023-12-31 11:11:36 -05:00
2024-01-21 21:52:54 -05:00
extern struct android_app *g_App;
2023-12-31 11:11:36 -05:00
extern EGLDisplay g_EglDisplay;
extern EGLSurface g_EglSurface;
float funcDeviceScale()
{
2026-01-13 21:40:02 +01:00
JavaVM *java_vm = g_App->activity->vm;
JNIEnv *java_env = NULL;
2026-01-13 21:40:02 +01:00
jint jni_return = java_vm->GetEnv((void **)&java_env, JNI_VERSION_1_6);
if (jni_return == JNI_ERR)
2024-03-14 12:12:34 +01:00
throw satdump_exception("Could not get JNI environement");
jni_return = java_vm->AttachCurrentThread(&java_env, NULL);
if (jni_return != JNI_OK)
2024-03-14 12:12:34 +01:00
throw satdump_exception("Could not attach to thread");
jclass native_activity_clazz = java_env->GetObjectClass(g_App->activity->clazz);
if (native_activity_clazz == NULL)
2024-03-14 12:12:34 +01:00
throw satdump_exception("Could not get MainActivity class");
jmethodID method_id = java_env->GetMethodID(native_activity_clazz, "get_dpi", "()F");
if (method_id == NULL)
2024-03-14 12:12:34 +01:00
throw satdump_exception("Could not get methode ID");
jfloat jflt = java_env->CallFloatMethod(g_App->activity->clazz, method_id);
jni_return = java_vm->DetachCurrentThread();
if (jni_return != JNI_OK)
2024-03-14 12:12:34 +01:00
throw satdump_exception("Could not detach from thread");
return jflt;
}
void funcRebuildFonts()
{
ImGui_ImplOpenGL3_DestroyFontsTexture();
ImGui_ImplOpenGL3_CreateFontsTexture();
}
2023-12-31 11:11:36 -05:00
void funcSetMousePos(int, int)
{
// Not implemented on Android
}
void procLongPress();
2023-12-31 11:11:36 -05:00
std::pair<int, int> funcBeginFrame()
{
2023-12-31 15:38:36 -05:00
// Get display dimensions
EGLint width, height;
eglQuerySurface(g_EglDisplay, g_EglSurface, EGL_WIDTH, &width);
eglQuerySurface(g_EglDisplay, g_EglSurface, EGL_HEIGHT, &height);
2023-12-31 11:11:36 -05:00
// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplAndroid_NewFrame();
ImGui::NewFrame();
procLongPress();
2026-01-13 21:40:02 +01:00
return {(int)width, (int)height};
2023-12-31 11:11:36 -05:00
}
void funcEndFrame()
{
ImGui::Render();
2026-01-13 21:40:02 +01:00
ImGuiIO &io = ImGui::GetIO();
2023-12-31 11:11:36 -05:00
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
2024-01-21 14:57:41 -05:00
glClearColor(style::theme.frame_bg.Value.x, style::theme.frame_bg.Value.y, style::theme.frame_bg.Value.z, 1.0f);
2023-12-31 11:11:36 -05:00
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
eglSwapBuffers(g_EglDisplay, g_EglSurface);
}
2026-01-13 21:40:02 +01:00
void funcSetIcon(uint8_t *, int, int)
2023-12-31 11:11:36 -05:00
{
// Not implemented on Android
}
2026-01-13 21:40:02 +01:00
#include "android_dialogs.h"
std::string selectFolderDialog(std::string default_path)
{
show_select_directory_dialog();
std::string out = "";
while (out == "")
out = get_select_directory_dialog_result();
return out == "NO_PATH_SELECTED" ? "" : out;
}
std::string selectFileDialog(std::vector<std::pair<std::string, std::string>> filters, std::string default_path)
{
show_select_file_dialog();
std::string out = "";
while (out == "")
out = get_select_file_dialog_result();
return out == "NO_PATH_SELECTED" ? "" : out;
}
std::string saveFileDialog(std::vector<std::pair<std::string, std::string>> filters, std::string default_path, std::string default_name)
{
2026-01-14 08:13:26 +01:00
show_select_filesave_dialog(default_name);
std::string out = "";
while (out == "")
out = get_select_filesave_dialog_result();
return out == "NO_PATH_SELECTED" ? "" : out;
2026-01-13 21:40:02 +01:00
}
2023-12-31 11:11:36 -05:00
void bindBackendFunctions()
{
backend::device_scale = funcDeviceScale();
backend::rebuildFonts = funcRebuildFonts;
2023-12-31 11:11:36 -05:00
backend::setMousePos = funcSetMousePos;
backend::beginFrame = funcBeginFrame;
backend::endFrame = funcEndFrame;
backend::setIcon = funcSetIcon;
2026-01-13 21:40:02 +01:00
backend::selectFolderDialog = selectFolderDialog;
backend::selectFileDialog = selectFileDialog;
backend::saveFileDialog = saveFileDialog;
2023-12-31 11:46:40 -05:00
}