diff --git a/.gitignore b/.gitignore
index 10ad372..c6b1517 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,4 +14,6 @@ Folder.DotSettings.user
CMakeSettings.json
poggers_decoder
m17_decoder/libcorrect
-SDR++.app
\ No newline at end of file
+SDR++.app
+android/deps
+android/app/assets
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 788ce05..ad8d003 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,6 +7,20 @@ else()
set(CMAKE_INSTALL_PREFIX "/usr")
endif()
+# Configure toolchain for android
+if (ANDROID)
+ set(CMAKE_SHARED_LINKER_FLAGS
+ "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate"
+ )
+ set(CMAKE_C_STANDARD 11)
+ set(CMAKE_CXX_STANDARD 14)
+ set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=c++17")
+endif (ANDROID)
+
+# Backends
+option(OPT_BACKEND_GLFW "Use the GLFW backend" ON)
+option(OPT_BACKEND_ANDROID "Use the Android backend" OFF)
+
# Compatibility Options
option(OPT_OVERRIDE_STD_FILESYSTEM "Use a local version of std::filesystem on systems that don't have it yet" OFF)
@@ -28,6 +42,7 @@ option(OPT_BUILD_SPYSERVER_SOURCE "Build SpyServer Source Module (no dependencie
option(OPT_BUILD_PLUTOSDR_SOURCE "Build PlutoSDR Source Module (Dependencies: libiio, libad9361)" ON)
# Sinks
+option(OPT_BUILD_ANDROID_AUDIO_SINK "Build Android Audio Sink Module (Dependencies: AAudio, only for android)" OFF)
option(OPT_BUILD_AUDIO_SINK "Build Audio Sink Module (Dependencies: rtaudio)" ON)
option(OPT_BUILD_PORTAUDIO_SINK "Build PortAudio Sink Module (Dependencies: portaudio)" OFF)
option(OPT_BUILD_NETWORK_SINK "Build Audio Sink Module (no dependencies required)" ON)
@@ -35,6 +50,7 @@ option(OPT_BUILD_NEW_PORTAUDIO_SINK "Build the new PortAudio Sink Module (Depend
# Decoders
option(OPT_BUILD_FALCON9_DECODER "Build the falcon9 live decoder (Dependencies: ffplay)" OFF)
+option(OPT_BUILD_KG_SSTV_DECODER "Build the M17 decoder module (no dependencies required)" OFF)
option(OPT_BUILD_M17_DECODER "Build the M17 decoder module (no dependencies required)" OFF)
option(OPT_BUILD_METEOR_DEMODULATOR "Build the meteor demodulator module (no dependencies required)" ON)
option(OPT_BUILD_RADIO "Main audio modulation decoder (AM, FM, SSB, etc...)" ON)
@@ -49,7 +65,7 @@ option(OPT_BUILD_SCANNER "Frequency scanner" OFF)
option(OPT_BUILD_SCHEDULER "Build the scheduler" OFF)
# Other options
-option(USE_INTERNAL_LIBCORRECT "Use an external version of libcorrect" ON)
+option(USE_INTERNAL_LIBCORRECT "Use an internal version of libcorrect" ON)
option(USE_BUNDLE_DEFAULTS "Set the default resource and module directories to the right ones for a MacOS .app" OFF)
# Core of SDR++
@@ -118,6 +134,10 @@ endif (OPT_BUILD_PLUTOSDR_SOURCE)
# Sink modules
+if (OPT_BUILD_ANDROID_AUDIO_SINK)
+add_subdirectory("sink_modules/android_audio_sink")
+endif (OPT_BUILD_ANDROID_AUDIO_SINK)
+
if (OPT_BUILD_AUDIO_SINK)
add_subdirectory("sink_modules/audio_sink")
endif (OPT_BUILD_AUDIO_SINK)
@@ -140,6 +160,10 @@ if (OPT_BUILD_FALCON9_DECODER)
add_subdirectory("decoder_modules/falcon9_decoder")
endif (OPT_BUILD_FALCON9_DECODER)
+if (OPT_BUILD_KG_SSTV_DECODER)
+add_subdirectory("decoder_modules/kg_sstv_decoder")
+endif (OPT_BUILD_KG_SSTV_DECODER)
+
if (OPT_BUILD_M17_DECODER)
add_subdirectory("decoder_modules/m17_decoder")
endif (OPT_BUILD_M17_DECODER)
diff --git a/android/.gitignore b/android/.gitignore
new file mode 100644
index 0000000..3c7a619
--- /dev/null
+++ b/android/.gitignore
@@ -0,0 +1,12 @@
+.cxx
+.externalNativeBuild
+build/
+*.iml
+
+.idea
+.gradle
+local.properties
+
+# Android Studio puts a Gradle wrapper here, that we don't want:
+gradle/
+gradlew*
diff --git a/android/app/build.gradle b/android/app/build.gradle
new file mode 100644
index 0000000..ed4054d
--- /dev/null
+++ b/android/app/build.gradle
@@ -0,0 +1,64 @@
+apply plugin: 'com.android.application'
+apply plugin: 'kotlin-android'
+
+android {
+ compileSdkVersion 28
+ buildToolsVersion "30.0.3"
+ ndkVersion "23.0.7599858"
+ defaultConfig {
+ applicationId "org.sdrpp.sdrpp"
+ minSdkVersion 28
+ targetSdkVersion 28
+ versionCode 1
+ versionName "1.1.0"
+
+ externalNativeBuild {
+ cmake {
+ arguments "-DOPT_BACKEND_GLFW=OFF", "-DOPT_BACKEND_ANDROID=ON", "-DOPT_BUILD_SOAPY_SOURCE=OFF", "-DOPT_BUILD_ANDROID_AUDIO_SINK=ON", "-DOPT_BUILD_AUDIO_SINK=OFF", "-DOPT_BUILD_DISCORD_PRESENCE=OFF", "-DUSE_INTERNAL_LIBCORRECT=OFF"
+ }
+ }
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')
+ }
+ }
+
+ externalNativeBuild {
+ cmake {
+ version "3.18.1"
+ path "../../CMakeLists.txt"
+ }
+ }
+
+ sourceSets {
+ main {
+ assets.srcDirs += ['assets']
+ }
+ }
+}
+
+task deleteTempAssets (type: Delete) {
+ delete 'assets'
+}
+
+task copyResources(type: Copy) {
+ description = 'Copy resources...'
+ from '../../root/'
+ into 'assets/'
+ include('**/*')
+}
+
+repositories {
+ mavenCentral()
+}
+
+dependencies {
+ implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
+ implementation 'androidx.appcompat:appcompat:1.0.2'
+}
+
+copyResources.dependsOn deleteTempAssets
+preBuild.dependsOn copyResources
\ No newline at end of file
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..d5163d4
--- /dev/null
+++ b/android/app/src/main/AndroidManifest.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android/app/src/main/java/DeviceManager.kt b/android/app/src/main/java/DeviceManager.kt
new file mode 100644
index 0000000..f53f174
--- /dev/null
+++ b/android/app/src/main/java/DeviceManager.kt
@@ -0,0 +1,32 @@
+package org.sdrpp.sdrpp;
+
+import android.app.NativeActivity;
+import android.app.AlertDialog;
+import android.app.PendingIntent;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.pm.PackageManager;
+import android.hardware.usb.*;
+import android.Manifest;
+import android.os.Bundle;
+import android.view.View;
+import android.view.KeyEvent;
+import android.view.inputmethod.InputMethodManager;
+import android.util.Log;
+import android.content.res.AssetManager;
+
+import androidx.core.app.ActivityCompat;
+
+import androidx.core.content.PermissionChecker;
+
+import java.util.concurrent.LinkedBlockingQueue;
+import java.io.*;
+
+class DeviceManager {
+ public fun init() {
+
+ }
+}
\ No newline at end of file
diff --git a/android/app/src/main/java/MainActivity.kt b/android/app/src/main/java/MainActivity.kt
new file mode 100644
index 0000000..9fbf5ec
--- /dev/null
+++ b/android/app/src/main/java/MainActivity.kt
@@ -0,0 +1,192 @@
+package org.sdrpp.sdrpp;
+
+import android.app.NativeActivity;
+import android.app.AlertDialog;
+import android.app.PendingIntent;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.pm.PackageManager;
+import android.hardware.usb.*;
+import android.Manifest;
+import android.os.Bundle;
+import android.view.View;
+import android.view.KeyEvent;
+import android.view.inputmethod.InputMethodManager;
+import android.util.Log;
+import android.content.res.AssetManager;
+
+import androidx.core.app.ActivityCompat;
+
+import androidx.core.content.PermissionChecker;
+
+import java.util.concurrent.LinkedBlockingQueue;
+import java.io.*;
+
+private const val ACTION_USB_PERMISSION = "org.sdrpp.sdrpp.USB_PERMISSION";
+
+private val usbReceiver = object : BroadcastReceiver() {
+ override fun onReceive(context: Context, intent: Intent) {
+ if (ACTION_USB_PERMISSION == intent.action) {
+ synchronized(this) {
+ var _this = context as MainActivity;
+ _this.SDR_device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE)
+ if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
+ _this.SDR_conn = _this.usbManager!!.openDevice(_this.SDR_device);
+
+ // Save SDR info
+ _this.SDR_VID = _this.SDR_device!!.getVendorId();
+ _this.SDR_PID = _this.SDR_device!!.getProductId()
+ _this.SDR_FD = _this.SDR_conn!!.getFileDescriptor();
+ }
+
+ // Whatever the hell this does
+ context.unregisterReceiver(this);
+
+ // Hide again the system bars
+ _this.hideSystemBars();
+ }
+ }
+ }
+}
+
+class MainActivity : NativeActivity() {
+ private val TAG : String = "SDR++";
+ public var usbManager : UsbManager? = null;
+ public var SDR_device : UsbDevice? = null;
+ public var SDR_conn : UsbDeviceConnection? = null;
+ public var SDR_VID : Int = -1;
+ public var SDR_PID : Int = -1;
+ public var SDR_FD : Int = -1;
+
+ fun checkAndAsk(permission: String) {
+ if (PermissionChecker.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
+ ActivityCompat.requestPermissions(this, arrayOf(permission), 1);
+ }
+ }
+
+ public fun hideSystemBars() {
+ val decorView = getWindow().getDecorView();
+ val uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
+ decorView.setSystemUiVisibility(uiOptions);
+ }
+
+ public override fun onCreate(savedInstanceState: Bundle?) {
+ // Hide bars
+ hideSystemBars();
+
+ // Ask for required permissions, without these the app cannot run.
+ checkAndAsk(Manifest.permission.WRITE_EXTERNAL_STORAGE);
+ checkAndAsk(Manifest.permission.READ_EXTERNAL_STORAGE);
+
+ // TODO: Have the main code wait until these two permissions are available
+
+ // Register events
+ usbManager = getSystemService(Context.USB_SERVICE) as UsbManager;
+ val permissionIntent = PendingIntent.getBroadcast(this, 0, Intent(ACTION_USB_PERMISSION), 0)
+ val filter = IntentFilter(ACTION_USB_PERMISSION)
+ registerReceiver(usbReceiver, filter)
+
+ // Get permission for all USB devices
+ val devList = usbManager!!.getDeviceList();
+ for ((name, dev) in devList) {
+ usbManager!!.requestPermission(dev, permissionIntent);
+ }
+
+ // Ask for internet permission
+ checkAndAsk(Manifest.permission.INTERNET);
+
+ super.onCreate(savedInstanceState)
+ }
+
+ public override fun onResume() {
+ // Hide bars again
+ hideSystemBars();
+ super.onResume();
+ }
+
+ fun showSoftInput() {
+ val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager;
+ inputMethodManager.showSoftInput(window.decorView, 0);
+ }
+
+ fun hideSoftInput() {
+ val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager;
+ inputMethodManager.hideSoftInputFromWindow(window.decorView.windowToken, 0);
+ hideSystemBars();
+ }
+
+ // Queue for the Unicode characters to be polled from native code (via pollUnicodeChar())
+ private var unicodeCharacterQueue: LinkedBlockingQueue = LinkedBlockingQueue()
+
+ // We assume dispatchKeyEvent() of the NativeActivity is actually called for every
+ // KeyEvent and not consumed by any View before it reaches here
+ override fun dispatchKeyEvent(event: KeyEvent): Boolean {
+ if (event.action == KeyEvent.ACTION_DOWN) {
+ unicodeCharacterQueue.offer(event.getUnicodeChar(event.metaState))
+ }
+ return super.dispatchKeyEvent(event)
+ }
+
+ fun pollUnicodeChar(): Int {
+ return unicodeCharacterQueue.poll() ?: 0
+ }
+
+ public fun createIfDoesntExist(path: String) {
+ // This is a directory, create it in the filesystem
+ var folder = File(path);
+ var success = true;
+ if (!folder.exists()) {
+ success = folder.mkdirs();
+ }
+ if (!success) {
+ Log.e(TAG, "Could not create folder with path " + path);
+ }
+ }
+
+ public fun extractDir(aman: AssetManager, local: String, rsrc: String): Int {
+ val flist = aman.list(rsrc);
+ var ecount = 0;
+ for (fp in flist) {
+ val lpath = local + "/" + fp;
+ val rpath = rsrc + "/" + fp;
+
+ Log.w(TAG, "Extracting '" + rpath + "' to '" + lpath + "'");
+
+ // Create local path if non-existent
+ createIfDoesntExist(local);
+
+ // Create if directory
+ val ext = extractDir(aman, lpath, rpath);
+
+ // Extract if file
+ if (ext == 0) {
+ // This is a file, extract it
+ val _os = FileOutputStream(lpath);
+ val _is = aman.open(rpath);
+ val ilen = _is.available();
+ var fbuf = ByteArray(ilen);
+ _is.read(fbuf, 0, ilen);
+ _os.write(fbuf);
+ _os.close();
+ _is.close();
+ }
+
+ ecount++;
+ }
+ return ecount;
+ }
+
+ public fun getAppDir(): String {
+ val fdir = getFilesDir().getAbsolutePath();
+
+ // Extract all resources to the app directory
+ val aman = getAssets();
+ extractDir(aman, fdir + "/res", "res");
+ createIfDoesntExist(fdir + "/modules");
+
+ return fdir;
+ }
+}
diff --git a/android/app/src/main/res/mipmap/ic_launcher.png b/android/app/src/main/res/mipmap/ic_launcher.png
new file mode 100644
index 0000000..03cf618
Binary files /dev/null and b/android/app/src/main/res/mipmap/ic_launcher.png differ
diff --git a/android/build.gradle b/android/build.gradle
new file mode 100644
index 0000000..24f9e99
--- /dev/null
+++ b/android/build.gradle
@@ -0,0 +1,22 @@
+buildscript {
+ ext.kotlin_version = '1.4.31'
+ repositories {
+ google()
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:4.1.0'
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
+ }
+}
+
+allprojects {
+ repositories {
+ google()
+ mavenCentral()
+ }
+}
+
+task clean(type: Delete) {
+ delete rootProject.buildDir
+}
diff --git a/android/gradle.properties b/android/gradle.properties
new file mode 100644
index 0000000..2d8d1e4
--- /dev/null
+++ b/android/gradle.properties
@@ -0,0 +1 @@
+android.useAndroidX=true
\ No newline at end of file
diff --git a/android/settings.gradle b/android/settings.gradle
new file mode 100644
index 0000000..e7b4def
--- /dev/null
+++ b/android/settings.gradle
@@ -0,0 +1 @@
+include ':app'
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index 5a37ca1..675cdee 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -17,8 +17,17 @@ if (MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif ()
+# Configure backend sources
+if (OPT_BACKEND_GLFW)
+ file(GLOB_RECURSE BACKEND_SRC "backends/glfw/*.cpp" "backends/glfw/*.c")
+endif (OPT_BACKEND_GLFW)
+if (OPT_BACKEND_ANDROID)
+ file(GLOB_RECURSE BACKEND_SRC "backends/android/*.cpp" "backends/android/*.c")
+ set(BACKEND_SRC ${BACKEND_SRC} ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
+endif (OPT_BACKEND_ANDROID)
+
# Add code to dyn lib
-add_library(sdrpp_core SHARED ${SRC})
+add_library(sdrpp_core SHARED ${SRC} ${BACKEND_SRC})
# Set compiler options
if (MSVC)
@@ -36,6 +45,29 @@ target_compile_definitions(sdrpp_core PUBLIC INSTALL_PREFIX="${CMAKE_INSTALL_PRE
target_include_directories(sdrpp_core PUBLIC "src/")
target_include_directories(sdrpp_core PUBLIC "src/imgui")
+# Configure backend includes and libraries
+if (OPT_BACKEND_GLFW)
+ target_include_directories(sdrpp_core PUBLIC "backends/glfw")
+ target_include_directories(sdrpp_core PUBLIC "backends/glfw/imgui")
+
+ if (MSVC)
+ # GLFW3
+ find_package(glfw3 CONFIG REQUIRED)
+ target_link_libraries(sdrpp_core PUBLIC glfw)
+ else()
+ find_package(PkgConfig)
+ pkg_check_modules(GLFW3 REQUIRED glfw3)
+
+ target_include_directories(sdrpp_core PUBLIC ${GLFW3_INCLUDE_DIRS})
+ target_link_directories(sdrpp_core PUBLIC ${GLFW3_LIBRARY_DIRS})
+ target_link_libraries(sdrpp_core PUBLIC ${GLFW3_LIBRARIES})
+ endif()
+endif (OPT_BACKEND_GLFW)
+if (OPT_BACKEND_ANDROID)
+ target_include_directories(sdrpp_core PUBLIC "backends/android")
+ target_include_directories(sdrpp_core PUBLIC "backends/android/imgui")
+endif (OPT_BACKEND_ANDROID)
+
# Link to libcorrect
if (USE_INTERNAL_LIBCORRECT)
target_include_directories(sdrpp_core PUBLIC "libcorrect/include")
@@ -74,7 +106,24 @@ if (MSVC)
# ZSTD
find_package(zstd CONFIG REQUIRED)
target_link_libraries(sdrpp_core PUBLIC zstd::libzstd_shared)
+elseif (ANDROID)
+ target_include_directories(sdrpp_core PUBLIC
+ ../android/deps/volk/jni
+ ../android/deps/fftw3/jni
+ /mnt/android_sdr/zstd/lib
+ ${ANDROID_NDK}/sources/android/native_app_glue
+ )
+ target_link_libraries(sdrpp_core PUBLIC
+ ${PROJECT_SOURCE_DIR}/../android/deps/volk/${ANDROID_ABI}/libcpu_features.a
+ ${PROJECT_SOURCE_DIR}/../android/deps/volk/${ANDROID_ABI}/libvolk.so
+ ${PROJECT_SOURCE_DIR}/../android/deps/fftw3/${ANDROID_ABI}/libfftw3f.a
+ /mnt/android_sdr/output/zstd/${ANDROID_ABI}/libzstd.so
+ android
+ EGL
+ GLESv3
+ log
+ )
else()
find_package(PkgConfig)
find_package(OpenGL REQUIRED)
diff --git a/core/backends/android/android_backend.h b/core/backends/android/android_backend.h
new file mode 100644
index 0000000..50fdf51
--- /dev/null
+++ b/core/backends/android/android_backend.h
@@ -0,0 +1,17 @@
+#pragma once
+#include
+#include
+
+namespace backend {
+ struct DevVIDPID {
+ uint16_t vid;
+ uint16_t pid;
+ };
+
+ extern const std::vector AIRSPY_VIDPIDS;
+ extern const std::vector AIRSPYHF_VIDPIDS;
+ extern const std::vector HACKRF_VIDPIDS;
+ extern const std::vector RTL_SDR_VIDPIDS;
+
+ int getDeviceFD(int& vid, int& pid, const std::vector& allowedVidPids);
+}
\ No newline at end of file
diff --git a/core/backends/android/backend.cpp b/core/backends/android/backend.cpp
new file mode 100644
index 0000000..93c5f31
--- /dev/null
+++ b/core/backends/android/backend.cpp
@@ -0,0 +1,490 @@
+#include
+#include "android_backend.h"
+#include
+#include
+#include "imgui.h"
+#include "imgui_impl_android.h"
+#include "imgui_impl_opengl3.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+// Credit to the ImGui android OpenGL3 example for a lot of this code!
+
+namespace backend {
+ struct android_app* app = NULL;
+ EGLDisplay _EglDisplay = EGL_NO_DISPLAY;
+ EGLSurface _EglSurface = EGL_NO_SURFACE;
+ EGLContext _EglContext = EGL_NO_CONTEXT;
+ bool _Initialized = false;
+ char _LogTag[] = "SDR++";
+ bool initialized = false;
+ bool pauseRendering = false;
+ bool exited = false;
+
+ // Forward declaration
+ int ShowSoftKeyboardInput();
+ int PollUnicodeChars();
+
+ void doPartialInit() {
+ std::string root = (std::string)core::args["root"];
+ backend::init();
+ style::loadFonts(root + "/res"); // TODO: Don't hardcode, use config
+ icons::load(root + "/res");
+ thememenu::applyTheme();
+ ImGui::GetStyle().ScaleAllSizes(style::uiScale);
+ gui::mainWindow.setFirstMenuRender();
+ }
+
+ void handleAppCmd(struct android_app* app, int32_t appCmd) {
+ switch (appCmd) {
+ case APP_CMD_SAVE_STATE:
+ spdlog::warn("APP_CMD_SAVE_STATE");
+ break;
+ case APP_CMD_INIT_WINDOW:
+ spdlog::warn("APP_CMD_INIT_WINDOW");
+ if (pauseRendering && !exited) {
+ doPartialInit();
+ pauseRendering = false;
+ }
+ exited = false;
+ break;
+ case APP_CMD_TERM_WINDOW:
+ spdlog::warn("APP_CMD_TERM_WINDOW");
+ pauseRendering = true;
+ backend::end();
+ break;
+ case APP_CMD_GAINED_FOCUS:
+ spdlog::warn("APP_CMD_GAINED_FOCUS");
+ break;
+ case APP_CMD_LOST_FOCUS:
+ spdlog::warn("APP_CMD_LOST_FOCUS");
+ break;
+ }
+ }
+
+ int32_t handleInputEvent(struct android_app* app, AInputEvent* inputEvent) {
+ return ImGui_ImplAndroid_HandleInputEvent(inputEvent);
+ }
+
+ int aquireWindow() {
+ while (!app->window) {
+ spdlog::warn("Waiting on the shitty window thing"); std::this_thread::sleep_for(std::chrono::milliseconds(30));
+ int out_events;
+ struct android_poll_source* out_data;
+
+ while (ALooper_pollAll(0, NULL, &out_events, (void**)&out_data) >= 0) {
+ // Process one event
+ if (out_data != NULL) { out_data->process(app, out_data); }
+
+ // Exit the app by returning from within the infinite loop
+ if (app->destroyRequested != 0) {
+ return -1;
+ }
+ }
+ }
+ ANativeWindow_acquire(app->window);
+ return 0;
+ }
+
+ int init(std::string resDir) {
+ spdlog::warn("Backend init");
+
+ // Get window
+ aquireWindow();
+
+ // EGL Init
+ {
+ _EglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+ if (_EglDisplay == EGL_NO_DISPLAY)
+ __android_log_print(ANDROID_LOG_ERROR, _LogTag, "%s", "eglGetDisplay(EGL_DEFAULT_DISPLAY) returned EGL_NO_DISPLAY");
+
+ if (eglInitialize(_EglDisplay, 0, 0) != EGL_TRUE)
+ __android_log_print(ANDROID_LOG_ERROR, _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(_EglDisplay, egl_attributes, nullptr, 0, &num_configs) != EGL_TRUE)
+ __android_log_print(ANDROID_LOG_ERROR, _LogTag, "%s", "eglChooseConfig() returned with an error");
+ if (num_configs == 0)
+ __android_log_print(ANDROID_LOG_ERROR, _LogTag, "%s", "eglChooseConfig() returned 0 matching config");
+
+ // Get the first matching config
+ EGLConfig egl_config;
+ eglChooseConfig(_EglDisplay, egl_attributes, &egl_config, 1, &num_configs);
+ EGLint egl_format;
+ eglGetConfigAttrib(_EglDisplay, egl_config, EGL_NATIVE_VISUAL_ID, &egl_format);
+ ANativeWindow_setBuffersGeometry(app->window, 0, 0, egl_format);
+
+ const EGLint egl_context_attributes[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
+ _EglContext = eglCreateContext(_EglDisplay, egl_config, EGL_NO_CONTEXT, egl_context_attributes);
+
+ if (_EglContext == EGL_NO_CONTEXT)
+ __android_log_print(ANDROID_LOG_ERROR, _LogTag, "%s", "eglCreateContext() returned EGL_NO_CONTEXT");
+
+ _EglSurface = eglCreateWindowSurface(_EglDisplay, egl_config, app->window, NULL);
+ eglMakeCurrent(_EglDisplay, _EglSurface, _EglSurface, _EglContext);
+ }
+
+ // Setup Dear ImGui context
+ IMGUI_CHECKVERSION();
+ ImGui::CreateContext();
+ ImGuiIO& io = ImGui::GetIO();
+ (void)io;
+
+ // Disable loading/saving of .ini file from disk.
+ // FIXME: Consider using LoadIniSettingsFromMemory() / SaveIniSettingsToMemory() to save in appropriate location for Android.
+ io.IniFilename = NULL;
+
+ // Setup Platform/Renderer backends
+ ImGui_ImplAndroid_Init(app->window);
+ ImGui_ImplOpenGL3_Init("#version 300 es");
+
+ return 0;
+ }
+
+ void beginFrame() {
+ // Start the Dear ImGui frame
+ ImGui_ImplOpenGL3_NewFrame();
+ ImGui_ImplAndroid_NewFrame();
+ ImGui::NewFrame();
+ }
+
+ void render(bool vsync) {
+ // Rendering
+ ImGui::Render();
+ auto dSize = ImGui::GetIO().DisplaySize;
+ glViewport(0, 0, dSize.x, dSize.y);
+ glClearColor(gui::themeManager.clearColor.x, gui::themeManager.clearColor.y, gui::themeManager.clearColor.z, gui::themeManager.clearColor.w);
+ glClear(GL_COLOR_BUFFER_BIT);
+ ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
+ eglSwapBuffers(_EglDisplay, _EglSurface);
+ }
+
+ // No screen pos to detect
+ void getMouseScreenPos(double& x, double& y) { x = 0; y = 0; }
+ void setMouseScreenPos(double x, double y) {}
+
+ int renderLoop() {
+ spdlog::warn("BRUH: {0}", (void*)backend::app->window);
+ while (true) {
+ int out_events;
+ struct android_poll_source* out_data;
+
+ while (ALooper_pollAll(0, NULL, &out_events, (void**)&out_data) >= 0) {
+ // Process one event
+ if (out_data != NULL) { out_data->process(app, out_data); }
+
+ // Exit the app by returning from within the infinite loop
+ if (app->destroyRequested != 0) {
+ spdlog::warn("ASKED TO EXIT");
+ exited = true;
+
+ // Stop SDR
+ gui::mainWindow.setPlayState(false);
+ return 0;
+ }
+ }
+
+ if (_EglDisplay == EGL_NO_DISPLAY) { continue; }
+
+ if (!pauseRendering) {
+ // Initiate a new frame
+ ImGuiIO& io = ImGui::GetIO();
+ auto dsize = io.DisplaySize;
+
+ // 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;
+
+ // Render
+ beginFrame();
+
+ if (dsize.x > 0 && dsize.y > 0) {
+ ImGui::SetNextWindowPos(ImVec2(0, 0));
+ ImGui::SetNextWindowSize(ImVec2(dsize.x, dsize.y));
+ gui::mainWindow.draw();
+ }
+ render();
+ }
+ else {
+ std::this_thread::sleep_for(std::chrono::milliseconds(30));
+ }
+ }
+
+ return 0;
+ }
+
+ int end() {
+ // Cleanup
+ ImGui_ImplOpenGL3_Shutdown();
+ ImGui_ImplAndroid_Shutdown();
+ ImGui::DestroyContext();
+
+ // Destroy all
+ if (_EglDisplay != EGL_NO_DISPLAY) {
+ eglMakeCurrent(_EglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ if (_EglContext != EGL_NO_CONTEXT) { eglDestroyContext(_EglDisplay, _EglContext); }
+ if (_EglSurface != EGL_NO_SURFACE) { eglDestroySurface(_EglDisplay, _EglSurface); }
+ eglTerminate(_EglDisplay);
+ }
+
+ _EglDisplay = EGL_NO_DISPLAY;
+ _EglContext = EGL_NO_CONTEXT;
+ _EglSurface = EGL_NO_SURFACE;
+
+ if (app->window) { ANativeWindow_release(app->window); }
+
+ return 0;
+ }
+
+ int ShowSoftKeyboardInput() {
+ JavaVM* java_vm = app->activity->vm;
+ JNIEnv* java_env = NULL;
+
+ 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, NULL);
+ if (jni_return != JNI_OK)
+ return -2;
+
+ jclass native_activity_clazz = java_env->GetObjectClass(app->activity->clazz);
+ if (native_activity_clazz == NULL)
+ return -3;
+
+ jmethodID method_id = java_env->GetMethodID(native_activity_clazz, "showSoftInput", "()V");
+ if (method_id == NULL)
+ return -4;
+
+ java_env->CallVoidMethod(app->activity->clazz, method_id);
+
+ jni_return = java_vm->DetachCurrentThread();
+ if (jni_return != JNI_OK)
+ return -5;
+
+ return 0;
+ }
+
+ int getDeviceFD(int& vid, int& pid, const std::vector& allowedVidPids) {
+ JavaVM* java_vm = app->activity->vm;
+ JNIEnv* java_env = NULL;
+
+ 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, NULL);
+ if (jni_return != JNI_OK)
+ return -1;
+
+ jclass native_activity_clazz = java_env->GetObjectClass(app->activity->clazz);
+ if (native_activity_clazz == NULL)
+ return -1;
+
+ jfieldID fd_field_id = java_env->GetFieldID(native_activity_clazz, "SDR_FD", "I");
+ jfieldID vid_field_id = java_env->GetFieldID(native_activity_clazz, "SDR_VID", "I");
+ jfieldID pid_field_id = java_env->GetFieldID(native_activity_clazz, "SDR_PID", "I");
+
+ if (!vid_field_id || !vid_field_id || !pid_field_id)
+ return -1;
+
+ int fd = java_env->GetIntField(app->activity->clazz, fd_field_id);
+ vid = java_env->GetIntField(app->activity->clazz, vid_field_id);
+ pid = java_env->GetIntField(app->activity->clazz, pid_field_id);
+
+ jni_return = java_vm->DetachCurrentThread();
+ if (jni_return != JNI_OK)
+ return -1;
+
+ // If no vid/pid was given, just return successfully
+ if (allowedVidPids.empty()) {
+ return fd;
+ }
+
+ // Otherwise, check that the vid/pid combo is allowed
+ for (auto const& vp : allowedVidPids) {
+ if (vp.vid != vid || vp.pid != pid) { continue; }
+ return fd;
+ }
+
+ return -1;
+ }
+
+ // 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.
+ int PollUnicodeChars() {
+ JavaVM* java_vm = app->activity->vm;
+ JNIEnv* java_env = NULL;
+
+ 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, NULL);
+ if (jni_return != JNI_OK)
+ return -2;
+
+ jclass native_activity_clazz = java_env->GetObjectClass(app->activity->clazz);
+ if (native_activity_clazz == NULL)
+ return -3;
+
+ jmethodID method_id = java_env->GetMethodID(native_activity_clazz, "pollUnicodeChar", "()I");
+ if (method_id == NULL)
+ return -4;
+
+ // Send the actual characters to Dear ImGui
+ ImGuiIO& io = ImGui::GetIO();
+ jint unicode_character;
+ while ((unicode_character = java_env->CallIntMethod(app->activity->clazz, method_id)) != 0)
+ io.AddInputCharacter(unicode_character);
+
+ jni_return = java_vm->DetachCurrentThread();
+ if (jni_return != JNI_OK)
+ return -5;
+
+ return 0;
+ }
+
+ std::string getAppFilesDir() {
+ JavaVM* java_vm = app->activity->vm;
+ JNIEnv* java_env = NULL;
+
+ jint jni_return = java_vm->GetEnv((void**)&java_env, JNI_VERSION_1_6);
+ if (jni_return == JNI_ERR)
+ throw std::runtime_error("Could not get JNI environement");
+
+ jni_return = java_vm->AttachCurrentThread(&java_env, NULL);
+ if (jni_return != JNI_OK)
+ throw std::runtime_error("Could not attach to thread");
+
+ jclass native_activity_clazz = java_env->GetObjectClass(app->activity->clazz);
+ if (native_activity_clazz == NULL)
+ throw std::runtime_error("Could not get MainActivity class");
+
+ jmethodID method_id = java_env->GetMethodID(native_activity_clazz, "getAppDir", "()Ljava/lang/String;");
+ if (method_id == NULL)
+ throw std::runtime_error("Could not get methode ID");
+
+ jstring jstr = (jstring)java_env->CallObjectMethod(app->activity->clazz, method_id);
+
+ const char* _str = java_env->GetStringUTFChars(jstr, NULL);
+ std::string str(_str);
+ java_env->ReleaseStringUTFChars(jstr, _str);
+
+ jni_return = java_vm->DetachCurrentThread();
+ if (jni_return != JNI_OK)
+ throw std::runtime_error("Could not detach from thread");
+
+
+ return str;
+ }
+
+ const std::vector AIRSPY_VIDPIDS = {
+ { 0x1d50, 0x60a1 }
+ };
+
+ const std::vector AIRSPYHF_VIDPIDS = {
+ { 0x03EB, 0x800C }
+ };
+
+ const std::vector HACKRF_VIDPIDS = {
+ { 0x1d50, 0x604b },
+ { 0x1d50, 0x6089 },
+ { 0x1d50, 0xcc15 }
+ };
+
+ const std::vector RTL_SDR_VIDPIDS = {
+ { 0x0bda, 0x2832 },
+ { 0x0bda, 0x2838 },
+ { 0x0413, 0x6680 },
+ { 0x0413, 0x6f0f },
+ { 0x0458, 0x707f },
+ { 0x0ccd, 0x00a9 },
+ { 0x0ccd, 0x00b3 },
+ { 0x0ccd, 0x00b4 },
+ { 0x0ccd, 0x00b5 },
+ { 0x0ccd, 0x00b7 },
+ { 0x0ccd, 0x00b8 },
+ { 0x0ccd, 0x00b9 },
+ { 0x0ccd, 0x00c0 },
+ { 0x0ccd, 0x00c6 },
+ { 0x0ccd, 0x00d3 },
+ { 0x0ccd, 0x00d7 },
+ { 0x0ccd, 0x00e0 },
+ { 0x1554, 0x5020 },
+ { 0x15f4, 0x0131 },
+ { 0x15f4, 0x0133 },
+ { 0x185b, 0x0620 },
+ { 0x185b, 0x0650 },
+ { 0x185b, 0x0680 },
+ { 0x1b80, 0xd393 },
+ { 0x1b80, 0xd394 },
+ { 0x1b80, 0xd395 },
+ { 0x1b80, 0xd397 },
+ { 0x1b80, 0xd398 },
+ { 0x1b80, 0xd39d },
+ { 0x1b80, 0xd3a4 },
+ { 0x1b80, 0xd3a8 },
+ { 0x1b80, 0xd3af },
+ { 0x1b80, 0xd3b0 },
+ { 0x1d19, 0x1101 },
+ { 0x1d19, 0x1102 },
+ { 0x1d19, 0x1103 },
+ { 0x1d19, 0x1104 },
+ { 0x1f4d, 0xa803 },
+ { 0x1f4d, 0xb803 },
+ { 0x1f4d, 0xc803 },
+ { 0x1f4d, 0xd286 },
+ { 0x1f4d, 0xd803 }
+ };
+}
+
+extern "C" {
+ void android_main(struct android_app* app) {
+ // Save app instance
+ app->onAppCmd = backend::handleAppCmd;
+ app->onInputEvent = backend::handleInputEvent;
+ backend::app = app;
+
+ // Check if this is the first time we run or not
+ if (backend::initialized) {
+ spdlog::warn("android_main called again");
+ backend::doPartialInit();
+ backend::pauseRendering = false;
+ backend::renderLoop();
+ return;
+ }
+ backend::initialized = true;
+
+ // prepare spdlog
+ auto console_sink = std::make_shared("SDR++");
+ auto logger = std::shared_ptr(new spdlog::logger("", { console_sink }));
+ spdlog::set_default_logger(logger);
+
+ // Grab files dir
+ std::string appdir = backend::getAppFilesDir();
+
+ // Call main
+ char* rootpath = new char[appdir.size() + 1];
+ strcpy(rootpath, appdir.c_str());
+ char* dummy[] = { "", "-r", rootpath };
+ sdrpp_main(3, dummy);
+ }
+}
\ No newline at end of file
diff --git a/core/backends/android/imgui/imgui_impl_android.cpp b/core/backends/android/imgui/imgui_impl_android.cpp
new file mode 100644
index 0000000..ffefc4a
--- /dev/null
+++ b/core/backends/android/imgui/imgui_impl_android.cpp
@@ -0,0 +1,278 @@
+// dear imgui: Platform Binding for Android native app
+// This needs to be used along with the OpenGL 3 Renderer (imgui_impl_opengl3)
+
+// Implemented features:
+// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy AKEYCODE_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
+// Missing features:
+// [ ] Platform: Clipboard support.
+// [ ] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
+// [ ] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. FIXME: Check if this is even possible with Android.
+// Important:
+// - Consider using SDL or GLFW backend on Android, which will be more full-featured than this.
+// - FIXME: On-screen keyboard currently needs to be enabled by the application (see examples/ and issue #3446)
+// - FIXME: Unicode character inputs needs to be passed by Dear ImGui by the application (see examples/ and issue #3446)
+
+// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
+// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
+// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
+// Read online: https://github.com/ocornut/imgui/tree/master/docs
+
+// CHANGELOG
+// (minor and older changes stripped away, please see git history for details)
+// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago)with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion.
+// 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+).
+// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
+// 2021-03-04: Initial version.
+
+#include "imgui.h"
+#include "imgui_impl_android.h"
+#include
+#include
+#include
+#include
+#include
+
+// Android data
+static double g_Time = 0.0;
+static ANativeWindow* g_Window;
+static char g_LogTag[] = "ImGuiExample";
+
+static ImGuiKey ImGui_ImplAndroid_KeyCodeToImGuiKey(int32_t key_code)
+{
+ switch (key_code)
+ {
+ case AKEYCODE_TAB: return ImGuiKey_Tab;
+ case AKEYCODE_DPAD_LEFT: return ImGuiKey_LeftArrow;
+ case AKEYCODE_DPAD_RIGHT: return ImGuiKey_RightArrow;
+ case AKEYCODE_DPAD_UP: return ImGuiKey_UpArrow;
+ case AKEYCODE_DPAD_DOWN: return ImGuiKey_DownArrow;
+ case AKEYCODE_PAGE_UP: return ImGuiKey_PageUp;
+ case AKEYCODE_PAGE_DOWN: return ImGuiKey_PageDown;
+ case AKEYCODE_MOVE_HOME: return ImGuiKey_Home;
+ case AKEYCODE_MOVE_END: return ImGuiKey_End;
+ case AKEYCODE_INSERT: return ImGuiKey_Insert;
+ case AKEYCODE_FORWARD_DEL: return ImGuiKey_Delete;
+ case AKEYCODE_DEL: return ImGuiKey_Backspace;
+ case AKEYCODE_SPACE: return ImGuiKey_Space;
+ case AKEYCODE_ENTER: return ImGuiKey_Enter;
+ case AKEYCODE_ESCAPE: return ImGuiKey_Escape;
+ case AKEYCODE_APOSTROPHE: return ImGuiKey_Apostrophe;
+ case AKEYCODE_COMMA: return ImGuiKey_Comma;
+ case AKEYCODE_MINUS: return ImGuiKey_Minus;
+ case AKEYCODE_PERIOD: return ImGuiKey_Period;
+ case AKEYCODE_SLASH: return ImGuiKey_Slash;
+ case AKEYCODE_SEMICOLON: return ImGuiKey_Semicolon;
+ case AKEYCODE_EQUALS: return ImGuiKey_Equal;
+ case AKEYCODE_LEFT_BRACKET: return ImGuiKey_LeftBracket;
+ case AKEYCODE_BACKSLASH: return ImGuiKey_Backslash;
+ case AKEYCODE_RIGHT_BRACKET: return ImGuiKey_RightBracket;
+ case AKEYCODE_GRAVE: return ImGuiKey_GraveAccent;
+ case AKEYCODE_CAPS_LOCK: return ImGuiKey_CapsLock;
+ case AKEYCODE_SCROLL_LOCK: return ImGuiKey_ScrollLock;
+ case AKEYCODE_NUM_LOCK: return ImGuiKey_NumLock;
+ case AKEYCODE_SYSRQ: return ImGuiKey_PrintScreen;
+ case AKEYCODE_BREAK: return ImGuiKey_Pause;
+ case AKEYCODE_NUMPAD_0: return ImGuiKey_Keypad0;
+ case AKEYCODE_NUMPAD_1: return ImGuiKey_Keypad1;
+ case AKEYCODE_NUMPAD_2: return ImGuiKey_Keypad2;
+ case AKEYCODE_NUMPAD_3: return ImGuiKey_Keypad3;
+ case AKEYCODE_NUMPAD_4: return ImGuiKey_Keypad4;
+ case AKEYCODE_NUMPAD_5: return ImGuiKey_Keypad5;
+ case AKEYCODE_NUMPAD_6: return ImGuiKey_Keypad6;
+ case AKEYCODE_NUMPAD_7: return ImGuiKey_Keypad7;
+ case AKEYCODE_NUMPAD_8: return ImGuiKey_Keypad8;
+ case AKEYCODE_NUMPAD_9: return ImGuiKey_Keypad9;
+ case AKEYCODE_NUMPAD_DOT: return ImGuiKey_KeypadDecimal;
+ case AKEYCODE_NUMPAD_DIVIDE: return ImGuiKey_KeypadDivide;
+ case AKEYCODE_NUMPAD_MULTIPLY: return ImGuiKey_KeypadMultiply;
+ case AKEYCODE_NUMPAD_SUBTRACT: return ImGuiKey_KeypadSubtract;
+ case AKEYCODE_NUMPAD_ADD: return ImGuiKey_KeypadAdd;
+ case AKEYCODE_NUMPAD_ENTER: return ImGuiKey_KeypadEnter;
+ case AKEYCODE_NUMPAD_EQUALS: return ImGuiKey_KeypadEqual;
+ case AKEYCODE_CTRL_LEFT: return ImGuiKey_LeftCtrl;
+ case AKEYCODE_SHIFT_LEFT: return ImGuiKey_LeftShift;
+ case AKEYCODE_ALT_LEFT: return ImGuiKey_LeftAlt;
+ case AKEYCODE_META_LEFT: return ImGuiKey_LeftSuper;
+ case AKEYCODE_CTRL_RIGHT: return ImGuiKey_RightCtrl;
+ case AKEYCODE_SHIFT_RIGHT: return ImGuiKey_RightShift;
+ case AKEYCODE_ALT_RIGHT: return ImGuiKey_RightAlt;
+ case AKEYCODE_META_RIGHT: return ImGuiKey_RightSuper;
+ case AKEYCODE_MENU: return ImGuiKey_Menu;
+ case AKEYCODE_0: return ImGuiKey_0;
+ case AKEYCODE_1: return ImGuiKey_1;
+ case AKEYCODE_2: return ImGuiKey_2;
+ case AKEYCODE_3: return ImGuiKey_3;
+ case AKEYCODE_4: return ImGuiKey_4;
+ case AKEYCODE_5: return ImGuiKey_5;
+ case AKEYCODE_6: return ImGuiKey_6;
+ case AKEYCODE_7: return ImGuiKey_7;
+ case AKEYCODE_8: return ImGuiKey_8;
+ case AKEYCODE_9: return ImGuiKey_9;
+ case AKEYCODE_A: return ImGuiKey_A;
+ case AKEYCODE_B: return ImGuiKey_B;
+ case AKEYCODE_C: return ImGuiKey_C;
+ case AKEYCODE_D: return ImGuiKey_D;
+ case AKEYCODE_E: return ImGuiKey_E;
+ case AKEYCODE_F: return ImGuiKey_F;
+ case AKEYCODE_G: return ImGuiKey_G;
+ case AKEYCODE_H: return ImGuiKey_H;
+ case AKEYCODE_I: return ImGuiKey_I;
+ case AKEYCODE_J: return ImGuiKey_J;
+ case AKEYCODE_K: return ImGuiKey_K;
+ case AKEYCODE_L: return ImGuiKey_L;
+ case AKEYCODE_M: return ImGuiKey_M;
+ case AKEYCODE_N: return ImGuiKey_N;
+ case AKEYCODE_O: return ImGuiKey_O;
+ case AKEYCODE_P: return ImGuiKey_P;
+ case AKEYCODE_Q: return ImGuiKey_Q;
+ case AKEYCODE_R: return ImGuiKey_R;
+ case AKEYCODE_S: return ImGuiKey_S;
+ case AKEYCODE_T: return ImGuiKey_T;
+ case AKEYCODE_U: return ImGuiKey_U;
+ case AKEYCODE_V: return ImGuiKey_V;
+ case AKEYCODE_W: return ImGuiKey_W;
+ case AKEYCODE_X: return ImGuiKey_X;
+ case AKEYCODE_Y: return ImGuiKey_Y;
+ case AKEYCODE_Z: return ImGuiKey_Z;
+ case AKEYCODE_F1: return ImGuiKey_F1;
+ case AKEYCODE_F2: return ImGuiKey_F2;
+ case AKEYCODE_F3: return ImGuiKey_F3;
+ case AKEYCODE_F4: return ImGuiKey_F4;
+ case AKEYCODE_F5: return ImGuiKey_F5;
+ case AKEYCODE_F6: return ImGuiKey_F6;
+ case AKEYCODE_F7: return ImGuiKey_F7;
+ case AKEYCODE_F8: return ImGuiKey_F8;
+ case AKEYCODE_F9: return ImGuiKey_F9;
+ case AKEYCODE_F10: return ImGuiKey_F10;
+ case AKEYCODE_F11: return ImGuiKey_F11;
+ case AKEYCODE_F12: return ImGuiKey_F12;
+ default: return ImGuiKey_None;
+ }
+}
+
+int32_t ImGui_ImplAndroid_HandleInputEvent(AInputEvent* input_event)
+{
+ ImGuiIO& io = ImGui::GetIO();
+ int32_t event_type = AInputEvent_getType(input_event);
+ switch (event_type)
+ {
+ case AINPUT_EVENT_TYPE_KEY:
+ {
+ int32_t event_key_code = AKeyEvent_getKeyCode(input_event);
+ int32_t event_scan_code = AKeyEvent_getScanCode(input_event);
+ int32_t event_action = AKeyEvent_getAction(input_event);
+ int32_t event_meta_state = AKeyEvent_getMetaState(input_event);
+
+ io.AddKeyEvent(ImGuiKey_ModCtrl, (event_meta_state & AMETA_CTRL_ON) != 0);
+ io.AddKeyEvent(ImGuiKey_ModShift, (event_meta_state & AMETA_SHIFT_ON) != 0);
+ io.AddKeyEvent(ImGuiKey_ModAlt, (event_meta_state & AMETA_ALT_ON) != 0);
+ io.AddKeyEvent(ImGuiKey_ModSuper, (event_meta_state & AMETA_META_ON) != 0);
+
+ switch (event_action)
+ {
+ // FIXME: AKEY_EVENT_ACTION_DOWN and AKEY_EVENT_ACTION_UP occur at once as soon as a touch pointer
+ // goes up from a key. We use a simple key event queue/ and process one event per key per frame in
+ // ImGui_ImplAndroid_NewFrame()...or consider using IO queue, if suitable: https://github.com/ocornut/imgui/issues/2787
+ case AKEY_EVENT_ACTION_DOWN:
+ case AKEY_EVENT_ACTION_UP:
+ {
+ ImGuiKey key = ImGui_ImplAndroid_KeyCodeToImGuiKey(event_key_code);
+ if (key != ImGuiKey_None && (event_action == AKEY_EVENT_ACTION_DOWN || event_action == AKEY_EVENT_ACTION_UP))
+ {
+ io.AddKeyEvent(key, event_action == AKEY_EVENT_ACTION_DOWN);
+ io.SetKeyEventNativeData(key, event_key_code, event_scan_code);
+ }
+
+ break;
+ }
+ default:
+ break;
+ }
+ break;
+ }
+ case AINPUT_EVENT_TYPE_MOTION:
+ {
+ int32_t event_action = AMotionEvent_getAction(input_event);
+ int32_t event_pointer_index = (event_action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
+ event_action &= AMOTION_EVENT_ACTION_MASK;
+ switch (event_action)
+ {
+ case AMOTION_EVENT_ACTION_DOWN:
+ case AMOTION_EVENT_ACTION_UP:
+ // Physical mouse buttons (and probably other physical devices) also invoke the actions AMOTION_EVENT_ACTION_DOWN/_UP,
+ // but we have to process them separately to identify the actual button pressed. This is done below via
+ // AMOTION_EVENT_ACTION_BUTTON_PRESS/_RELEASE. Here, we only process "FINGER" input (and "UNKNOWN", as a fallback).
+ if((AMotionEvent_getToolType(input_event, event_pointer_index) == AMOTION_EVENT_TOOL_TYPE_FINGER)
+ || (AMotionEvent_getToolType(input_event, event_pointer_index) == AMOTION_EVENT_TOOL_TYPE_STYLUS)
+ || (AMotionEvent_getToolType(input_event, event_pointer_index) == AMOTION_EVENT_TOOL_TYPE_MOUSE)
+ || (AMotionEvent_getToolType(input_event, event_pointer_index) == AMOTION_EVENT_TOOL_TYPE_UNKNOWN))
+ {
+ io.AddMousePosEvent(AMotionEvent_getX(input_event, event_pointer_index), AMotionEvent_getY(input_event, event_pointer_index));
+ io.AddMouseButtonEvent(0, event_action == AMOTION_EVENT_ACTION_DOWN);
+ }
+ break;
+ case AMOTION_EVENT_ACTION_BUTTON_PRESS:
+ case AMOTION_EVENT_ACTION_BUTTON_RELEASE:
+ {
+ int32_t button_state = AMotionEvent_getButtonState(input_event);
+ io.AddMouseButtonEvent(0, (button_state & AMOTION_EVENT_BUTTON_PRIMARY) != 0);
+ io.AddMouseButtonEvent(1, (button_state & AMOTION_EVENT_BUTTON_SECONDARY) != 0);
+ io.AddMouseButtonEvent(2, (button_state & AMOTION_EVENT_BUTTON_TERTIARY) != 0);
+ }
+ break;
+ case AMOTION_EVENT_ACTION_HOVER_MOVE: // Hovering: Tool moves while NOT pressed (such as a physical mouse)
+ case AMOTION_EVENT_ACTION_MOVE: // Touch pointer moves while DOWN
+ io.AddMousePosEvent(AMotionEvent_getX(input_event, event_pointer_index), AMotionEvent_getY(input_event, event_pointer_index));
+ break;
+ case AMOTION_EVENT_ACTION_SCROLL:
+ io.AddMouseWheelEvent(AMotionEvent_getAxisValue(input_event, AMOTION_EVENT_AXIS_HSCROLL, event_pointer_index), AMotionEvent_getAxisValue(input_event, AMOTION_EVENT_AXIS_VSCROLL, event_pointer_index));
+ break;
+ default:
+ break;
+ }
+ }
+ return 1;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+bool ImGui_ImplAndroid_Init(ANativeWindow* window)
+{
+ g_Window = window;
+ g_Time = 0.0;
+
+ // Setup backend capabilities flags
+ ImGuiIO& io = ImGui::GetIO();
+ io.BackendPlatformName = "imgui_impl_android";
+
+ return true;
+}
+
+void ImGui_ImplAndroid_Shutdown()
+{
+}
+
+void ImGui_ImplAndroid_NewFrame()
+{
+ ImGuiIO& io = ImGui::GetIO();
+
+ // Setup display size (every frame to accommodate for window resizing)
+ int32_t window_width = ANativeWindow_getWidth(g_Window);
+ int32_t window_height = ANativeWindow_getHeight(g_Window);
+ int display_width = window_width;
+ int display_height = window_height;
+
+ io.DisplaySize = ImVec2((float)window_width, (float)window_height);
+ if (window_width > 0 && window_height > 0)
+ io.DisplayFramebufferScale = ImVec2((float)display_width / window_width, (float)display_height / window_height);
+
+ // Setup time step
+ struct timespec current_timespec;
+ clock_gettime(CLOCK_MONOTONIC, ¤t_timespec);
+ double current_time = (double)(current_timespec.tv_sec) + (current_timespec.tv_nsec / 1000000000.0);
+ io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f / 60.0f);
+ g_Time = current_time;
+}
diff --git a/core/backends/android/imgui/imgui_impl_android.h b/core/backends/android/imgui/imgui_impl_android.h
new file mode 100644
index 0000000..8bfa186
--- /dev/null
+++ b/core/backends/android/imgui/imgui_impl_android.h
@@ -0,0 +1,28 @@
+// dear imgui: Platform Binding for Android native app
+// This needs to be used along with the OpenGL 3 Renderer (imgui_impl_opengl3)
+
+// Implemented features:
+// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy AKEYCODE_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
+// Missing features:
+// [ ] Platform: Clipboard support.
+// [ ] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
+// [ ] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. FIXME: Check if this is even possible with Android.
+// Important:
+// - Consider using SDL or GLFW backend on Android, which will be more full-featured than this.
+// - FIXME: On-screen keyboard currently needs to be enabled by the application (see examples/ and issue #3446)
+// - FIXME: Unicode character inputs needs to be passed by Dear ImGui by the application (see examples/ and issue #3446)
+
+// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
+// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
+// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
+// Read online: https://github.com/ocornut/imgui/tree/master/docs
+
+#pragma once
+
+struct ANativeWindow;
+struct AInputEvent;
+
+IMGUI_IMPL_API bool ImGui_ImplAndroid_Init(ANativeWindow* window);
+IMGUI_IMPL_API int32_t ImGui_ImplAndroid_HandleInputEvent(AInputEvent* input_event);
+IMGUI_IMPL_API void ImGui_ImplAndroid_Shutdown();
+IMGUI_IMPL_API void ImGui_ImplAndroid_NewFrame();
diff --git a/core/backends/glfw/backend.cpp b/core/backends/glfw/backend.cpp
new file mode 100644
index 0000000..542e94f
--- /dev/null
+++ b/core/backends/glfw/backend.cpp
@@ -0,0 +1,305 @@
+#include
+#include "imgui.h"
+#include "imgui_impl_glfw.h"
+#include "imgui_impl_opengl3.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+namespace backend {
+ const char* OPENGL_VERSIONS_GLSL[] = {
+ "#version 120",
+ "#version 300 es",
+ "#version 120"
+ };
+
+ const int OPENGL_VERSIONS_MAJOR[] = {
+ 3,
+ 3,
+ 2
+ };
+
+ const int OPENGL_VERSIONS_MINOR[] = {
+ 0,
+ 1,
+ 1
+ };
+
+ const bool OPENGL_VERSIONS_IS_ES[] = {
+ false,
+ true,
+ false
+ };
+
+ #define OPENGL_VERSION_COUNT (sizeof(OPENGL_VERSIONS_GLSL) / sizeof(char*))
+
+ bool maximized = false;
+ bool fullScreen = false;
+ int winHeight;
+ int winWidth;
+ bool _maximized = maximized;
+ int fsWidth, fsHeight, fsPosX, fsPosY;
+ int _winWidth, _winHeight;
+ GLFWwindow* window;
+ GLFWmonitor* monitor;
+
+ static void glfw_error_callback(int error, const char* description) {
+ spdlog::error("Glfw Error {0}: {1}", error, description);
+ }
+
+ static void maximized_callback(GLFWwindow* window, int n) {
+ if (n == GLFW_TRUE) {
+ maximized = true;
+ }
+ else {
+ maximized = false;
+ }
+ }
+
+ int init(std::string resDir) {
+ // Load config
+ core::configManager.acquire();
+ winWidth = core::configManager.conf["windowSize"]["w"];
+ winHeight = core::configManager.conf["windowSize"]["h"];
+ maximized = core::configManager.conf["maximized"];
+ fullScreen = core::configManager.conf["fullscreen"];
+ core::configManager.release();
+
+ // Setup window
+ glfwSetErrorCallback(glfw_error_callback);
+ if (!glfwInit()) {
+ return 1;
+ }
+
+ #ifdef __APPLE__
+ // GL 3.2 + GLSL 150
+ const char* glsl_version = "#version 150";
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
+ glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
+ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac
+
+ // Create window with graphics context
+ monitor = glfwGetPrimaryMonitor();
+ window = glfwCreateWindow(winWidth, winHeight, "SDR++ v" VERSION_STR " (Built at " __TIME__ ", " __DATE__ ")", NULL, NULL);
+ if (window == NULL)
+ return 1;
+ glfwMakeContextCurrent(window);
+ #else
+ const char* glsl_version = "#version 120";
+ monitor = NULL;
+ for (int i = 0; i < OPENGL_VERSION_COUNT; i++) {
+ glsl_version = OPENGL_VERSIONS_GLSL[i];
+ glfwWindowHint(GLFW_CLIENT_API, OPENGL_VERSIONS_IS_ES[i] ? GLFW_OPENGL_ES_API : GLFW_OPENGL_API);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, OPENGL_VERSIONS_MAJOR[i]);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, OPENGL_VERSIONS_MINOR[i]);
+
+ // Create window with graphics context
+ monitor = glfwGetPrimaryMonitor();
+ window = glfwCreateWindow(winWidth, winHeight, "SDR++ v" VERSION_STR " (Built at " __TIME__ ", " __DATE__ ")", NULL, NULL);
+ if (window == NULL) {
+ spdlog::info("OpenGL {0}.{1} {2}was not supported", OPENGL_VERSIONS_MAJOR[i], OPENGL_VERSIONS_MINOR[i], OPENGL_VERSIONS_IS_ES[i] ? "ES " : "");
+ continue;
+ }
+ spdlog::info("Using OpenGL {0}.{1}{2}", OPENGL_VERSIONS_MAJOR[i], OPENGL_VERSIONS_MINOR[i], OPENGL_VERSIONS_IS_ES[i] ? " ES" : "");
+ glfwMakeContextCurrent(window);
+ break;
+ }
+
+ #endif
+
+ // Add callback for max/min if GLFW supports it
+ #if (GLFW_VERSION_MAJOR == 3) && (GLFW_VERSION_MINOR >= 3)
+ if (maximized) {
+ glfwMaximizeWindow(window);
+ }
+
+ glfwSetWindowMaximizeCallback(window, maximized_callback);
+ #endif
+
+ // Load app icon
+ if (!std::filesystem::is_regular_file(resDir + "/icons/sdrpp.png")) {
+ spdlog::error("Icon file '{0}' doesn't exist!", resDir + "/icons/sdrpp.png");
+ return 1;
+ }
+
+ GLFWimage icons[10];
+ icons[0].pixels = stbi_load(((std::string)(resDir + "/icons/sdrpp.png")).c_str(), &icons[0].width, &icons[0].height, 0, 4);
+ icons[1].pixels = (unsigned char*)malloc(16 * 16 * 4);
+ icons[1].width = icons[1].height = 16;
+ icons[2].pixels = (unsigned char*)malloc(24 * 24 * 4);
+ icons[2].width = icons[2].height = 24;
+ icons[3].pixels = (unsigned char*)malloc(32 * 32 * 4);
+ icons[3].width = icons[3].height = 32;
+ icons[4].pixels = (unsigned char*)malloc(48 * 48 * 4);
+ icons[4].width = icons[4].height = 48;
+ icons[5].pixels = (unsigned char*)malloc(64 * 64 * 4);
+ icons[5].width = icons[5].height = 64;
+ icons[6].pixels = (unsigned char*)malloc(96 * 96 * 4);
+ icons[6].width = icons[6].height = 96;
+ icons[7].pixels = (unsigned char*)malloc(128 * 128 * 4);
+ icons[7].width = icons[7].height = 128;
+ icons[8].pixels = (unsigned char*)malloc(196 * 196 * 4);
+ icons[8].width = icons[8].height = 196;
+ icons[9].pixels = (unsigned char*)malloc(256 * 256 * 4);
+ icons[9].width = icons[9].height = 256;
+ stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[1].pixels, 16, 16, 16 * 4, 4);
+ stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[2].pixels, 24, 24, 24 * 4, 4);
+ stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[3].pixels, 32, 32, 32 * 4, 4);
+ stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[4].pixels, 48, 48, 48 * 4, 4);
+ stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[5].pixels, 64, 64, 64 * 4, 4);
+ stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[6].pixels, 96, 96, 96 * 4, 4);
+ stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[7].pixels, 128, 128, 128 * 4, 4);
+ stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[8].pixels, 196, 196, 196 * 4, 4);
+ stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[9].pixels, 256, 256, 256 * 4, 4);
+ glfwSetWindowIcon(window, 10, icons);
+ stbi_image_free(icons[0].pixels);
+ for (int i = 1; i < 10; i++) {
+ free(icons[i].pixels);
+ }
+
+ // Setup Dear ImGui context
+ IMGUI_CHECKVERSION();
+ ImGui::CreateContext();
+ ImGuiIO& io = ImGui::GetIO();
+ (void)io;
+ io.IniFilename = NULL;
+
+ // Setup Platform/Renderer bindings
+ ImGui_ImplGlfw_InitForOpenGL(window, true);
+
+ if (!ImGui_ImplOpenGL3_Init(glsl_version)) {
+ // If init fail, try to fall back on GLSL 1.2
+ spdlog::warn("Could not init using OpenGL with normal GLSL version, falling back to GLSL 1.2");
+ if (!ImGui_ImplOpenGL3_Init("#version 120")) {
+ spdlog::error("Failed to initialize OpenGL with GLSL 1.2");
+ return -1;
+ }
+ }
+
+ // Set window size and fullscreen state
+ glfwGetWindowSize(window, &_winWidth, &_winHeight);
+ if (fullScreen) {
+ spdlog::info("Fullscreen: ON");
+ fsWidth = _winWidth;
+ fsHeight = _winHeight;
+ glfwGetWindowPos(window, &fsPosX, &fsPosY);
+ const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
+ glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, 0);
+ }
+
+ // Everything went according to plan
+ return 0;
+ }
+
+ void beginFrame() {
+ // Start the Dear ImGui frame
+ ImGui_ImplOpenGL3_NewFrame();
+ ImGui_ImplGlfw_NewFrame();
+ ImGui::NewFrame();
+ }
+
+ void render(bool vsync) {
+ // Rendering
+ ImGui::Render();
+ int display_w, display_h;
+ glfwGetFramebufferSize(window, &display_w, &display_h);
+ glViewport(0, 0, display_w, display_h);
+ glClearColor(gui::themeManager.clearColor.x, gui::themeManager.clearColor.y, gui::themeManager.clearColor.z, gui::themeManager.clearColor.w);
+ glClear(GL_COLOR_BUFFER_BIT);
+ ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
+
+ glfwSwapInterval(vsync);
+ glfwSwapBuffers(window);
+ }
+
+ void getMouseScreenPos(double& x, double& y) {
+ glfwGetCursorPos(window, &x, &y);
+ }
+
+ void setMouseScreenPos(double x, double y) {
+ // Tell GLFW to move the cursor and then manually fire the event
+ glfwSetCursorPos(window, x, y);
+ ImGui_ImplGlfw_CursorPosCallback(window, x, y);
+ }
+
+ int renderLoop() {
+ // Main loop
+ while (!glfwWindowShouldClose(window)) {
+ glfwPollEvents();
+
+ beginFrame();
+
+ if (_maximized != maximized) {
+ _maximized = maximized;
+ core::configManager.acquire();
+ core::configManager.conf["maximized"] = _maximized;
+ if (!maximized) {
+ glfwSetWindowSize(window, core::configManager.conf["windowSize"]["w"], core::configManager.conf["windowSize"]["h"]);
+ }
+ core::configManager.release(true);
+ }
+
+ glfwGetWindowSize(window, &_winWidth, &_winHeight);
+
+ if (ImGui::IsKeyPressed(GLFW_KEY_F11)) {
+ fullScreen = !fullScreen;
+ if (fullScreen) {
+ spdlog::info("Fullscreen: ON");
+ fsWidth = _winWidth;
+ fsHeight = _winHeight;
+ glfwGetWindowPos(window, &fsPosX, &fsPosY);
+ const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
+ glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, 0);
+ core::configManager.acquire();
+ core::configManager.conf["fullscreen"] = true;
+ core::configManager.release();
+ }
+ else {
+ spdlog::info("Fullscreen: OFF");
+ glfwSetWindowMonitor(window, nullptr, fsPosX, fsPosY, fsWidth, fsHeight, 0);
+ core::configManager.acquire();
+ core::configManager.conf["fullscreen"] = false;
+ core::configManager.release();
+ }
+ }
+
+ if ((_winWidth != winWidth || _winHeight != winHeight) && !maximized && _winWidth > 0 && _winHeight > 0) {
+ winWidth = _winWidth;
+ winHeight = _winHeight;
+ core::configManager.acquire();
+ core::configManager.conf["windowSize"]["w"] = winWidth;
+ core::configManager.conf["windowSize"]["h"] = winHeight;
+ core::configManager.release(true);
+ }
+
+ if (winWidth > 0 && winHeight > 0) {
+ ImGui::SetNextWindowPos(ImVec2(0, 0));
+ ImGui::SetNextWindowSize(ImVec2(_winWidth, _winHeight));
+ gui::mainWindow.draw();
+ }
+
+ render();
+ }
+
+ return 0;
+ }
+
+ int end() {
+ // Cleanup
+ ImGui_ImplOpenGL3_Shutdown();
+ ImGui_ImplGlfw_Shutdown();
+ ImGui::DestroyContext();
+
+ glfwDestroyWindow(window);
+ glfwTerminate();
+
+ return 0; // TODO: Int really needed?
+ }
+}
diff --git a/core/backends/glfw/imgui/imgui_impl_glfw.cpp b/core/backends/glfw/imgui/imgui_impl_glfw.cpp
new file mode 100644
index 0000000..516aa3c
--- /dev/null
+++ b/core/backends/glfw/imgui/imgui_impl_glfw.cpp
@@ -0,0 +1,643 @@
+// dear imgui: Platform Backend for GLFW
+// This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..)
+// (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
+// (Requires: GLFW 3.1+)
+
+// Implemented features:
+// [X] Platform: Clipboard support.
+// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
+// [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
+// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+).
+
+// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
+// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
+// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
+// Read online: https://github.com/ocornut/imgui/tree/master/docs
+
+// CHANGELOG
+// (minor and older changes stripped away, please see git history for details)
+// 2022-02-07: Added ImGui_ImplGlfw_InstallCallbacks()/ImGui_ImplGlfw_RestoreCallbacks() helpers to facilitate user installing callbacks after iniitializing backend.
+// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago)with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion.
+// 2021-01-20: Inputs: calling new io.AddKeyAnalogEvent() for gamepad support, instead of writing directly to io.NavInputs[].
+// 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+).
+// 2022-01-17: Inputs: always update key mods next and before key event (not in NewFrame) to fix input queue with very low framerates.
+// 2022-01-12: *BREAKING CHANGE*: Now using glfwSetCursorPosCallback(). If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetCursorPosCallback() and forward it to the backend via ImGui_ImplGlfw_CursorPosCallback().
+// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
+// 2022-01-05: Inputs: Converting GLFW untranslated keycodes back to translated keycodes (in the ImGui_ImplGlfw_KeyCallback() function) in order to match the behavior of every other backend, and facilitate the use of GLFW with lettered-shortcuts API.
+// 2021-08-17: *BREAKING CHANGE*: Now using glfwSetWindowFocusCallback() to calling io.AddFocusEvent(). If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetWindowFocusCallback() and forward it to the backend via ImGui_ImplGlfw_WindowFocusCallback().
+// 2021-07-29: *BREAKING CHANGE*: Now using glfwSetCursorEnterCallback(). MousePos is correctly reported when the host platform window is hovered but not focused. If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetWindowFocusCallback() callback and forward it to the backend via ImGui_ImplGlfw_CursorEnterCallback().
+// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
+// 2020-01-17: Inputs: Disable error callback while assigning mouse cursors because some X11 setup don't have them and it generates errors.
+// 2019-12-05: Inputs: Added support for new mouse cursors added in GLFW 3.4+ (resizing cursors, not allowed cursor).
+// 2019-10-18: Misc: Previously installed user callbacks are now restored on shutdown.
+// 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter.
+// 2019-05-11: Inputs: Don't filter value from character callback before calling AddInputCharacter().
+// 2019-03-12: Misc: Preserve DisplayFramebufferScale when main window is minimized.
+// 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window.
+// 2018-11-07: Inputs: When installing our GLFW callbacks, we save user's previously installed ones - if any - and chain call them.
+// 2018-08-01: Inputs: Workaround for Emscripten which doesn't seem to handle focus related calls.
+// 2018-06-29: Inputs: Added support for the ImGuiMouseCursor_Hand cursor.
+// 2018-06-08: Misc: Extracted imgui_impl_glfw.cpp/.h away from the old combined GLFW+OpenGL/Vulkan examples.
+// 2018-03-20: Misc: Setup io.BackendFlags ImGuiBackendFlags_HasMouseCursors flag + honor ImGuiConfigFlags_NoMouseCursorChange flag.
+// 2018-02-20: Inputs: Added support for mouse cursors (ImGui::GetMouseCursor() value, passed to glfwSetCursor()).
+// 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.
+// 2018-02-06: Inputs: Added mapping for ImGuiKey_Space.
+// 2018-01-25: Inputs: Added gamepad support if ImGuiConfigFlags_NavEnableGamepad is set.
+// 2018-01-25: Inputs: Honoring the io.WantSetMousePos by repositioning the mouse (when using navigation and ImGuiConfigFlags_NavMoveMouse is set).
+// 2018-01-20: Inputs: Added Horizontal Mouse Wheel support.
+// 2018-01-18: Inputs: Added mapping for ImGuiKey_Insert.
+// 2017-08-25: Inputs: MousePos set to -FLT_MAX,-FLT_MAX when mouse is unavailable/missing (instead of -1,-1).
+// 2016-10-15: Misc: Added a void* user_data parameter to Clipboard function handlers.
+
+#include "imgui.h"
+#include "imgui_impl_glfw.h"
+
+// Clang warnings with -Weverything
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast
+#pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness
+#if __has_warning("-Wzero-as-null-pointer-constant")
+#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
+#endif
+#endif
+
+// GLFW
+#include
+#ifdef _WIN32
+#undef APIENTRY
+#define GLFW_EXPOSE_NATIVE_WIN32
+#include // for glfwGetWin32Window
+#endif
+#ifdef GLFW_RESIZE_NESW_CURSOR // Let's be nice to people who pulled GLFW between 2019-04-16 (3.4 define) and 2019-11-29 (cursors defines) // FIXME: Remove when GLFW 3.4 is released?
+#define GLFW_HAS_NEW_CURSORS (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3400) // 3.4+ GLFW_RESIZE_ALL_CURSOR, GLFW_RESIZE_NESW_CURSOR, GLFW_RESIZE_NWSE_CURSOR, GLFW_NOT_ALLOWED_CURSOR
+#else
+#define GLFW_HAS_NEW_CURSORS (0)
+#endif
+#define GLFW_HAS_GAMEPAD_API (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwGetGamepadState() new api
+#define GLFW_HAS_GET_KEY_NAME (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3200) // 3.2+ glfwGetKeyName()
+
+// GLFW data
+enum GlfwClientApi
+{
+ GlfwClientApi_Unknown,
+ GlfwClientApi_OpenGL,
+ GlfwClientApi_Vulkan
+};
+
+struct ImGui_ImplGlfw_Data
+{
+ GLFWwindow* Window;
+ GlfwClientApi ClientApi;
+ double Time;
+ GLFWwindow* MouseWindow;
+ GLFWcursor* MouseCursors[ImGuiMouseCursor_COUNT];
+ ImVec2 LastValidMousePos;
+ bool InstalledCallbacks;
+
+ // Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any.
+ GLFWwindowfocusfun PrevUserCallbackWindowFocus;
+ GLFWcursorposfun PrevUserCallbackCursorPos;
+ GLFWcursorenterfun PrevUserCallbackCursorEnter;
+ GLFWmousebuttonfun PrevUserCallbackMousebutton;
+ GLFWscrollfun PrevUserCallbackScroll;
+ GLFWkeyfun PrevUserCallbackKey;
+ GLFWcharfun PrevUserCallbackChar;
+ GLFWmonitorfun PrevUserCallbackMonitor;
+
+ ImGui_ImplGlfw_Data() { memset(this, 0, sizeof(*this)); }
+};
+
+// Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts
+// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
+// FIXME: multi-context support is not well tested and probably dysfunctional in this backend.
+// - Because glfwPollEvents() process all windows and some events may be called outside of it, you will need to register your own callbacks
+// (passing install_callbacks=false in ImGui_ImplGlfw_InitXXX functions), set the current dear imgui context and then call our callbacks.
+// - Otherwise we may need to store a GLFWWindow* -> ImGuiContext* map and handle this in the backend, adding a little bit of extra complexity to it.
+// FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context.
+static ImGui_ImplGlfw_Data* ImGui_ImplGlfw_GetBackendData()
+{
+ return ImGui::GetCurrentContext() ? (ImGui_ImplGlfw_Data*)ImGui::GetIO().BackendPlatformUserData : NULL;
+}
+
+// Functions
+static const char* ImGui_ImplGlfw_GetClipboardText(void* user_data)
+{
+ return glfwGetClipboardString((GLFWwindow*)user_data);
+}
+
+static void ImGui_ImplGlfw_SetClipboardText(void* user_data, const char* text)
+{
+ glfwSetClipboardString((GLFWwindow*)user_data, text);
+}
+
+static ImGuiKey ImGui_ImplGlfw_KeyToImGuiKey(int key)
+{
+ switch (key)
+ {
+ case GLFW_KEY_TAB: return ImGuiKey_Tab;
+ case GLFW_KEY_LEFT: return ImGuiKey_LeftArrow;
+ case GLFW_KEY_RIGHT: return ImGuiKey_RightArrow;
+ case GLFW_KEY_UP: return ImGuiKey_UpArrow;
+ case GLFW_KEY_DOWN: return ImGuiKey_DownArrow;
+ case GLFW_KEY_PAGE_UP: return ImGuiKey_PageUp;
+ case GLFW_KEY_PAGE_DOWN: return ImGuiKey_PageDown;
+ case GLFW_KEY_HOME: return ImGuiKey_Home;
+ case GLFW_KEY_END: return ImGuiKey_End;
+ case GLFW_KEY_INSERT: return ImGuiKey_Insert;
+ case GLFW_KEY_DELETE: return ImGuiKey_Delete;
+ case GLFW_KEY_BACKSPACE: return ImGuiKey_Backspace;
+ case GLFW_KEY_SPACE: return ImGuiKey_Space;
+ case GLFW_KEY_ENTER: return ImGuiKey_Enter;
+ case GLFW_KEY_ESCAPE: return ImGuiKey_Escape;
+ case GLFW_KEY_APOSTROPHE: return ImGuiKey_Apostrophe;
+ case GLFW_KEY_COMMA: return ImGuiKey_Comma;
+ case GLFW_KEY_MINUS: return ImGuiKey_Minus;
+ case GLFW_KEY_PERIOD: return ImGuiKey_Period;
+ case GLFW_KEY_SLASH: return ImGuiKey_Slash;
+ case GLFW_KEY_SEMICOLON: return ImGuiKey_Semicolon;
+ case GLFW_KEY_EQUAL: return ImGuiKey_Equal;
+ case GLFW_KEY_LEFT_BRACKET: return ImGuiKey_LeftBracket;
+ case GLFW_KEY_BACKSLASH: return ImGuiKey_Backslash;
+ case GLFW_KEY_RIGHT_BRACKET: return ImGuiKey_RightBracket;
+ case GLFW_KEY_GRAVE_ACCENT: return ImGuiKey_GraveAccent;
+ case GLFW_KEY_CAPS_LOCK: return ImGuiKey_CapsLock;
+ case GLFW_KEY_SCROLL_LOCK: return ImGuiKey_ScrollLock;
+ case GLFW_KEY_NUM_LOCK: return ImGuiKey_NumLock;
+ case GLFW_KEY_PRINT_SCREEN: return ImGuiKey_PrintScreen;
+ case GLFW_KEY_PAUSE: return ImGuiKey_Pause;
+ case GLFW_KEY_KP_0: return ImGuiKey_Keypad0;
+ case GLFW_KEY_KP_1: return ImGuiKey_Keypad1;
+ case GLFW_KEY_KP_2: return ImGuiKey_Keypad2;
+ case GLFW_KEY_KP_3: return ImGuiKey_Keypad3;
+ case GLFW_KEY_KP_4: return ImGuiKey_Keypad4;
+ case GLFW_KEY_KP_5: return ImGuiKey_Keypad5;
+ case GLFW_KEY_KP_6: return ImGuiKey_Keypad6;
+ case GLFW_KEY_KP_7: return ImGuiKey_Keypad7;
+ case GLFW_KEY_KP_8: return ImGuiKey_Keypad8;
+ case GLFW_KEY_KP_9: return ImGuiKey_Keypad9;
+ case GLFW_KEY_KP_DECIMAL: return ImGuiKey_KeypadDecimal;
+ case GLFW_KEY_KP_DIVIDE: return ImGuiKey_KeypadDivide;
+ case GLFW_KEY_KP_MULTIPLY: return ImGuiKey_KeypadMultiply;
+ case GLFW_KEY_KP_SUBTRACT: return ImGuiKey_KeypadSubtract;
+ case GLFW_KEY_KP_ADD: return ImGuiKey_KeypadAdd;
+ case GLFW_KEY_KP_ENTER: return ImGuiKey_KeypadEnter;
+ case GLFW_KEY_KP_EQUAL: return ImGuiKey_KeypadEqual;
+ case GLFW_KEY_LEFT_SHIFT: return ImGuiKey_LeftShift;
+ case GLFW_KEY_LEFT_CONTROL: return ImGuiKey_LeftCtrl;
+ case GLFW_KEY_LEFT_ALT: return ImGuiKey_LeftAlt;
+ case GLFW_KEY_LEFT_SUPER: return ImGuiKey_LeftSuper;
+ case GLFW_KEY_RIGHT_SHIFT: return ImGuiKey_RightShift;
+ case GLFW_KEY_RIGHT_CONTROL: return ImGuiKey_RightCtrl;
+ case GLFW_KEY_RIGHT_ALT: return ImGuiKey_RightAlt;
+ case GLFW_KEY_RIGHT_SUPER: return ImGuiKey_RightSuper;
+ case GLFW_KEY_MENU: return ImGuiKey_Menu;
+ case GLFW_KEY_0: return ImGuiKey_0;
+ case GLFW_KEY_1: return ImGuiKey_1;
+ case GLFW_KEY_2: return ImGuiKey_2;
+ case GLFW_KEY_3: return ImGuiKey_3;
+ case GLFW_KEY_4: return ImGuiKey_4;
+ case GLFW_KEY_5: return ImGuiKey_5;
+ case GLFW_KEY_6: return ImGuiKey_6;
+ case GLFW_KEY_7: return ImGuiKey_7;
+ case GLFW_KEY_8: return ImGuiKey_8;
+ case GLFW_KEY_9: return ImGuiKey_9;
+ case GLFW_KEY_A: return ImGuiKey_A;
+ case GLFW_KEY_B: return ImGuiKey_B;
+ case GLFW_KEY_C: return ImGuiKey_C;
+ case GLFW_KEY_D: return ImGuiKey_D;
+ case GLFW_KEY_E: return ImGuiKey_E;
+ case GLFW_KEY_F: return ImGuiKey_F;
+ case GLFW_KEY_G: return ImGuiKey_G;
+ case GLFW_KEY_H: return ImGuiKey_H;
+ case GLFW_KEY_I: return ImGuiKey_I;
+ case GLFW_KEY_J: return ImGuiKey_J;
+ case GLFW_KEY_K: return ImGuiKey_K;
+ case GLFW_KEY_L: return ImGuiKey_L;
+ case GLFW_KEY_M: return ImGuiKey_M;
+ case GLFW_KEY_N: return ImGuiKey_N;
+ case GLFW_KEY_O: return ImGuiKey_O;
+ case GLFW_KEY_P: return ImGuiKey_P;
+ case GLFW_KEY_Q: return ImGuiKey_Q;
+ case GLFW_KEY_R: return ImGuiKey_R;
+ case GLFW_KEY_S: return ImGuiKey_S;
+ case GLFW_KEY_T: return ImGuiKey_T;
+ case GLFW_KEY_U: return ImGuiKey_U;
+ case GLFW_KEY_V: return ImGuiKey_V;
+ case GLFW_KEY_W: return ImGuiKey_W;
+ case GLFW_KEY_X: return ImGuiKey_X;
+ case GLFW_KEY_Y: return ImGuiKey_Y;
+ case GLFW_KEY_Z: return ImGuiKey_Z;
+ case GLFW_KEY_F1: return ImGuiKey_F1;
+ case GLFW_KEY_F2: return ImGuiKey_F2;
+ case GLFW_KEY_F3: return ImGuiKey_F3;
+ case GLFW_KEY_F4: return ImGuiKey_F4;
+ case GLFW_KEY_F5: return ImGuiKey_F5;
+ case GLFW_KEY_F6: return ImGuiKey_F6;
+ case GLFW_KEY_F7: return ImGuiKey_F7;
+ case GLFW_KEY_F8: return ImGuiKey_F8;
+ case GLFW_KEY_F9: return ImGuiKey_F9;
+ case GLFW_KEY_F10: return ImGuiKey_F10;
+ case GLFW_KEY_F11: return ImGuiKey_F11;
+ case GLFW_KEY_F12: return ImGuiKey_F12;
+ default: return ImGuiKey_None;
+ }
+}
+
+static void ImGui_ImplGlfw_UpdateKeyModifiers(int mods)
+{
+ ImGuiIO& io = ImGui::GetIO();
+ io.AddKeyEvent(ImGuiKey_ModCtrl, (mods & GLFW_MOD_CONTROL) != 0);
+ io.AddKeyEvent(ImGuiKey_ModShift, (mods & GLFW_MOD_SHIFT) != 0);
+ io.AddKeyEvent(ImGuiKey_ModAlt, (mods & GLFW_MOD_ALT) != 0);
+ io.AddKeyEvent(ImGuiKey_ModSuper, (mods & GLFW_MOD_SUPER) != 0);
+}
+
+void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
+{
+ ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
+ if (bd->PrevUserCallbackMousebutton != NULL && window == bd->Window)
+ bd->PrevUserCallbackMousebutton(window, button, action, mods);
+
+ ImGui_ImplGlfw_UpdateKeyModifiers(mods);
+
+ ImGuiIO& io = ImGui::GetIO();
+ if (button >= 0 && button < ImGuiMouseButton_COUNT)
+ io.AddMouseButtonEvent(button, action == GLFW_PRESS);
+}
+
+void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
+{
+ ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
+ if (bd->PrevUserCallbackScroll != NULL && window == bd->Window)
+ bd->PrevUserCallbackScroll(window, xoffset, yoffset);
+
+ ImGuiIO& io = ImGui::GetIO();
+ io.AddMouseWheelEvent((float)xoffset, (float)yoffset);
+}
+
+static int ImGui_ImplGlfw_TranslateUntranslatedKey(int key, int scancode)
+{
+#if GLFW_HAS_GET_KEY_NAME && !defined(__EMSCRIPTEN__)
+ // GLFW 3.1+ attempts to "untranslate" keys, which goes the opposite of what every other framework does, making using lettered shortcuts difficult.
+ // (It had reasons to do so: namely GLFW is/was more likely to be used for WASD-type game controls rather than lettered shortcuts, but IHMO the 3.1 change could have been done differently)
+ // See https://github.com/glfw/glfw/issues/1502 for details.
+ // Adding a workaround to undo this (so our keys are translated->untranslated->translated, likely a lossy process).
+ // This won't cover edge cases but this is at least going to cover common cases.
+ if (key >= GLFW_KEY_KP_0 && key <= GLFW_KEY_KP_EQUAL)
+ return key;
+ const char* key_name = glfwGetKeyName(key, scancode);
+ if (key_name && key_name[0] != 0 && key_name[1] == 0)
+ {
+ const char char_names[] = "`-=[]\\,;\'./";
+ const int char_keys[] = { GLFW_KEY_GRAVE_ACCENT, GLFW_KEY_MINUS, GLFW_KEY_EQUAL, GLFW_KEY_LEFT_BRACKET, GLFW_KEY_RIGHT_BRACKET, GLFW_KEY_BACKSLASH, GLFW_KEY_COMMA, GLFW_KEY_SEMICOLON, GLFW_KEY_APOSTROPHE, GLFW_KEY_PERIOD, GLFW_KEY_SLASH, 0 };
+ IM_ASSERT(IM_ARRAYSIZE(char_names) == IM_ARRAYSIZE(char_keys));
+ if (key_name[0] >= '0' && key_name[0] <= '9') { key = GLFW_KEY_0 + (key_name[0] - '0'); }
+ else if (key_name[0] >= 'A' && key_name[0] <= 'Z') { key = GLFW_KEY_A + (key_name[0] - 'A'); }
+ else if (const char* p = strchr(char_names, key_name[0])) { key = char_keys[p - char_names]; }
+ }
+ // if (action == GLFW_PRESS) printf("key %d scancode %d name '%s'\n", key, scancode, key_name);
+#else
+ IM_UNUSED(scancode);
+#endif
+ return key;
+}
+
+void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int keycode, int scancode, int action, int mods)
+{
+ ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
+ if (bd->PrevUserCallbackKey != NULL && window == bd->Window)
+ bd->PrevUserCallbackKey(window, keycode, scancode, action, mods);
+
+ if (action != GLFW_PRESS && action != GLFW_RELEASE)
+ return;
+
+ ImGui_ImplGlfw_UpdateKeyModifiers(mods);
+
+ keycode = ImGui_ImplGlfw_TranslateUntranslatedKey(keycode, scancode);
+
+ ImGuiIO& io = ImGui::GetIO();
+ ImGuiKey imgui_key = ImGui_ImplGlfw_KeyToImGuiKey(keycode);
+ io.AddKeyEvent(imgui_key, (action == GLFW_PRESS));
+ io.SetKeyEventNativeData(imgui_key, keycode, scancode); // To support legacy indexing (<1.87 user code)
+}
+
+void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused)
+{
+ ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
+ if (bd->PrevUserCallbackWindowFocus != NULL && window == bd->Window)
+ bd->PrevUserCallbackWindowFocus(window, focused);
+
+ ImGuiIO& io = ImGui::GetIO();
+ io.AddFocusEvent(focused != 0);
+}
+
+void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y)
+{
+ ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
+ if (bd->PrevUserCallbackCursorPos != NULL && window == bd->Window)
+ bd->PrevUserCallbackCursorPos(window, x, y);
+
+ ImGuiIO& io = ImGui::GetIO();
+ io.AddMousePosEvent((float)x, (float)y);
+ bd->LastValidMousePos = ImVec2((float)x, (float)y);
+}
+
+// Workaround: X11 seems to send spurious Leave/Enter events which would make us lose our position,
+// so we back it up and restore on Leave/Enter (see https://github.com/ocornut/imgui/issues/4984)
+void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered)
+{
+ ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
+ if (bd->PrevUserCallbackCursorEnter != NULL && window == bd->Window)
+ bd->PrevUserCallbackCursorEnter(window, entered);
+
+ ImGuiIO& io = ImGui::GetIO();
+ if (entered)
+ {
+ bd->MouseWindow = window;
+ io.AddMousePosEvent(bd->LastValidMousePos.x, bd->LastValidMousePos.y);
+ }
+ else if (!entered && bd->MouseWindow == window)
+ {
+ bd->LastValidMousePos = io.MousePos;
+ bd->MouseWindow = NULL;
+ io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
+ }
+}
+
+void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c)
+{
+ ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
+ if (bd->PrevUserCallbackChar != NULL && window == bd->Window)
+ bd->PrevUserCallbackChar(window, c);
+
+ ImGuiIO& io = ImGui::GetIO();
+ io.AddInputCharacter(c);
+}
+
+void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor*, int)
+{
+ // Unused in 'master' branch but 'docking' branch will use this, so we declare it ahead of it so if you have to install callbacks you can install this one too.
+}
+
+void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window)
+{
+ ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
+ IM_ASSERT(bd->InstalledCallbacks == false && "Callbacks already installed!");
+ IM_ASSERT(bd->Window == window);
+
+ bd->PrevUserCallbackWindowFocus = glfwSetWindowFocusCallback(window, ImGui_ImplGlfw_WindowFocusCallback);
+ bd->PrevUserCallbackCursorEnter = glfwSetCursorEnterCallback(window, ImGui_ImplGlfw_CursorEnterCallback);
+ bd->PrevUserCallbackCursorPos = glfwSetCursorPosCallback(window, ImGui_ImplGlfw_CursorPosCallback);
+ bd->PrevUserCallbackMousebutton = glfwSetMouseButtonCallback(window, ImGui_ImplGlfw_MouseButtonCallback);
+ bd->PrevUserCallbackScroll = glfwSetScrollCallback(window, ImGui_ImplGlfw_ScrollCallback);
+ bd->PrevUserCallbackKey = glfwSetKeyCallback(window, ImGui_ImplGlfw_KeyCallback);
+ bd->PrevUserCallbackChar = glfwSetCharCallback(window, ImGui_ImplGlfw_CharCallback);
+ bd->PrevUserCallbackMonitor = glfwSetMonitorCallback(ImGui_ImplGlfw_MonitorCallback);
+ bd->InstalledCallbacks = true;
+}
+
+void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window)
+{
+ ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
+ IM_ASSERT(bd->InstalledCallbacks == true && "Callbacks not installed!");
+ IM_ASSERT(bd->Window == window);
+
+ glfwSetWindowFocusCallback(window, bd->PrevUserCallbackWindowFocus);
+ glfwSetCursorEnterCallback(window, bd->PrevUserCallbackCursorEnter);
+ glfwSetCursorPosCallback(window, bd->PrevUserCallbackCursorPos);
+ glfwSetMouseButtonCallback(window, bd->PrevUserCallbackMousebutton);
+ glfwSetScrollCallback(window, bd->PrevUserCallbackScroll);
+ glfwSetKeyCallback(window, bd->PrevUserCallbackKey);
+ glfwSetCharCallback(window, bd->PrevUserCallbackChar);
+ glfwSetMonitorCallback(bd->PrevUserCallbackMonitor);
+ bd->InstalledCallbacks = false;
+ bd->PrevUserCallbackWindowFocus = NULL;
+ bd->PrevUserCallbackCursorEnter = NULL;
+ bd->PrevUserCallbackCursorPos = NULL;
+ bd->PrevUserCallbackMousebutton = NULL;
+ bd->PrevUserCallbackScroll = NULL;
+ bd->PrevUserCallbackKey = NULL;
+ bd->PrevUserCallbackChar = NULL;
+ bd->PrevUserCallbackMonitor = NULL;
+}
+
+static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, GlfwClientApi client_api)
+{
+ ImGuiIO& io = ImGui::GetIO();
+ IM_ASSERT(io.BackendPlatformUserData == NULL && "Already initialized a platform backend!");
+
+ // Setup backend capabilities flags
+ ImGui_ImplGlfw_Data* bd = IM_NEW(ImGui_ImplGlfw_Data)();
+ io.BackendPlatformUserData = (void*)bd;
+ io.BackendPlatformName = "imgui_impl_glfw";
+ io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
+ io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
+
+ bd->Window = window;
+ bd->Time = 0.0;
+
+ io.SetClipboardTextFn = ImGui_ImplGlfw_SetClipboardText;
+ io.GetClipboardTextFn = ImGui_ImplGlfw_GetClipboardText;
+ io.ClipboardUserData = bd->Window;
+
+ // Set platform dependent data in viewport
+#if defined(_WIN32)
+ ImGui::GetMainViewport()->PlatformHandleRaw = (void*)glfwGetWin32Window(bd->Window);
+#endif
+
+ // Create mouse cursors
+ // (By design, on X11 cursors are user configurable and some cursors may be missing. When a cursor doesn't exist,
+ // GLFW will emit an error which will often be printed by the app, so we temporarily disable error reporting.
+ // Missing cursors will return NULL and our _UpdateMouseCursor() function will use the Arrow cursor instead.)
+ GLFWerrorfun prev_error_callback = glfwSetErrorCallback(NULL);
+ bd->MouseCursors[ImGuiMouseCursor_Arrow] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
+ bd->MouseCursors[ImGuiMouseCursor_TextInput] = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR);
+ bd->MouseCursors[ImGuiMouseCursor_ResizeNS] = glfwCreateStandardCursor(GLFW_VRESIZE_CURSOR);
+ bd->MouseCursors[ImGuiMouseCursor_ResizeEW] = glfwCreateStandardCursor(GLFW_HRESIZE_CURSOR);
+ bd->MouseCursors[ImGuiMouseCursor_Hand] = glfwCreateStandardCursor(GLFW_HAND_CURSOR);
+#if GLFW_HAS_NEW_CURSORS
+ bd->MouseCursors[ImGuiMouseCursor_ResizeAll] = glfwCreateStandardCursor(GLFW_RESIZE_ALL_CURSOR);
+ bd->MouseCursors[ImGuiMouseCursor_ResizeNESW] = glfwCreateStandardCursor(GLFW_RESIZE_NESW_CURSOR);
+ bd->MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_RESIZE_NWSE_CURSOR);
+ bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = glfwCreateStandardCursor(GLFW_NOT_ALLOWED_CURSOR);
+#else
+ bd->MouseCursors[ImGuiMouseCursor_ResizeAll] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
+ bd->MouseCursors[ImGuiMouseCursor_ResizeNESW] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
+ bd->MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
+ bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
+#endif
+ glfwSetErrorCallback(prev_error_callback);
+
+ // Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any.
+ if (install_callbacks)
+ ImGui_ImplGlfw_InstallCallbacks(window);
+
+ bd->ClientApi = client_api;
+ return true;
+}
+
+bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks)
+{
+ return ImGui_ImplGlfw_Init(window, install_callbacks, GlfwClientApi_OpenGL);
+}
+
+bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks)
+{
+ return ImGui_ImplGlfw_Init(window, install_callbacks, GlfwClientApi_Vulkan);
+}
+
+bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks)
+{
+ return ImGui_ImplGlfw_Init(window, install_callbacks, GlfwClientApi_Unknown);
+}
+
+void ImGui_ImplGlfw_Shutdown()
+{
+ ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
+ IM_ASSERT(bd != NULL && "No platform backend to shutdown, or already shutdown?");
+ ImGuiIO& io = ImGui::GetIO();
+
+ if (bd->InstalledCallbacks)
+ ImGui_ImplGlfw_RestoreCallbacks(bd->Window);
+
+ for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
+ glfwDestroyCursor(bd->MouseCursors[cursor_n]);
+
+ io.BackendPlatformName = NULL;
+ io.BackendPlatformUserData = NULL;
+ IM_DELETE(bd);
+}
+
+static void ImGui_ImplGlfw_UpdateMouseData()
+{
+ ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
+ ImGuiIO& io = ImGui::GetIO();
+
+#ifdef __EMSCRIPTEN__
+ const bool is_app_focused = true;
+#else
+ const bool is_app_focused = glfwGetWindowAttrib(bd->Window, GLFW_FOCUSED) != 0;
+#endif
+ if (is_app_focused)
+ {
+ // (Optional) Set OS mouse position from Dear ImGui if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
+ if (io.WantSetMousePos)
+ glfwSetCursorPos(bd->Window, (double)io.MousePos.x, (double)io.MousePos.y);
+
+ // (Optional) Fallback to provide mouse position when focused (ImGui_ImplGlfw_CursorPosCallback already provides this when hovered or captured)
+ if (is_app_focused && bd->MouseWindow == NULL)
+ {
+ double mouse_x, mouse_y;
+ glfwGetCursorPos(bd->Window, &mouse_x, &mouse_y);
+ io.AddMousePosEvent((float)mouse_x, (float)mouse_y);
+ bd->LastValidMousePos = ImVec2((float)mouse_x, (float)mouse_y);
+ }
+ }
+}
+
+static void ImGui_ImplGlfw_UpdateMouseCursor()
+{
+ ImGuiIO& io = ImGui::GetIO();
+ ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
+ if ((io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) || glfwGetInputMode(bd->Window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED)
+ return;
+
+ ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
+ if (imgui_cursor == ImGuiMouseCursor_None || io.MouseDrawCursor)
+ {
+ // Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
+ glfwSetInputMode(bd->Window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
+ }
+ else
+ {
+ // Show OS mouse cursor
+ // FIXME-PLATFORM: Unfocused windows seems to fail changing the mouse cursor with GLFW 3.2, but 3.3 works here.
+ glfwSetCursor(bd->Window, bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow]);
+ glfwSetInputMode(bd->Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
+ }
+}
+
+// Update gamepad inputs
+static inline float Saturate(float v) { return v < 0.0f ? 0.0f : v > 1.0f ? 1.0f : v; }
+static void ImGui_ImplGlfw_UpdateGamepads()
+{
+ ImGuiIO& io = ImGui::GetIO();
+ if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0)
+ return;
+
+ io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
+#if GLFW_HAS_GAMEPAD_API
+ GLFWgamepadstate gamepad;
+ if (!glfwGetGamepadState(GLFW_JOYSTICK_1, &gamepad))
+ return;
+ #define MAP_BUTTON(KEY_NO, BUTTON_NO, _UNUSED) do { io.AddKeyEvent(KEY_NO, gamepad.buttons[BUTTON_NO] != 0); } while (0)
+ #define MAP_ANALOG(KEY_NO, AXIS_NO, _UNUSED, V0, V1) do { float v = gamepad.axes[AXIS_NO]; v = (v - V0) / (V1 - V0); io.AddKeyAnalogEvent(KEY_NO, v > 0.10f, Saturate(v)); } while (0)
+#else
+ int axes_count = 0, buttons_count = 0;
+ const float* axes = glfwGetJoystickAxes(GLFW_JOYSTICK_1, &axes_count);
+ const unsigned char* buttons = glfwGetJoystickButtons(GLFW_JOYSTICK_1, &buttons_count);
+ if (axes_count == 0 || buttons_count == 0)
+ return;
+ #define MAP_BUTTON(KEY_NO, _UNUSED, BUTTON_NO) do { io.AddKeyEvent(KEY_NO, (buttons_count > BUTTON_NO && buttons[BUTTON_NO] == GLFW_PRESS)); } while (0)
+ #define MAP_ANALOG(KEY_NO, _UNUSED, AXIS_NO, V0, V1) do { float v = (axes_count > AXIS_NO) ? axes[AXIS_NO] : V0; v = (v - V0) / (V1 - V0); io.AddKeyAnalogEvent(KEY_NO, v > 0.10f, Saturate(v)); } while (0)
+#endif
+ io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
+ MAP_BUTTON(ImGuiKey_GamepadStart, GLFW_GAMEPAD_BUTTON_START, 7);
+ MAP_BUTTON(ImGuiKey_GamepadBack, GLFW_GAMEPAD_BUTTON_BACK, 6);
+ MAP_BUTTON(ImGuiKey_GamepadFaceDown, GLFW_GAMEPAD_BUTTON_A, 0); // Xbox A, PS Cross
+ MAP_BUTTON(ImGuiKey_GamepadFaceRight, GLFW_GAMEPAD_BUTTON_B, 1); // Xbox B, PS Circle
+ MAP_BUTTON(ImGuiKey_GamepadFaceLeft, GLFW_GAMEPAD_BUTTON_X, 2); // Xbox X, PS Square
+ MAP_BUTTON(ImGuiKey_GamepadFaceUp, GLFW_GAMEPAD_BUTTON_Y, 3); // Xbox Y, PS Triangle
+ MAP_BUTTON(ImGuiKey_GamepadDpadLeft, GLFW_GAMEPAD_BUTTON_DPAD_LEFT, 13);
+ MAP_BUTTON(ImGuiKey_GamepadDpadRight, GLFW_GAMEPAD_BUTTON_DPAD_RIGHT, 11);
+ MAP_BUTTON(ImGuiKey_GamepadDpadUp, GLFW_GAMEPAD_BUTTON_DPAD_UP, 10);
+ MAP_BUTTON(ImGuiKey_GamepadDpadDown, GLFW_GAMEPAD_BUTTON_DPAD_DOWN, 12);
+ MAP_BUTTON(ImGuiKey_GamepadL1, GLFW_GAMEPAD_BUTTON_LEFT_BUMPER, 4);
+ MAP_BUTTON(ImGuiKey_GamepadR1, GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER, 5);
+ MAP_ANALOG(ImGuiKey_GamepadL2, GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, 4, -0.75f, +1.0f);
+ MAP_ANALOG(ImGuiKey_GamepadR2, GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, 5, -0.75f, +1.0f);
+ MAP_BUTTON(ImGuiKey_GamepadL3, GLFW_GAMEPAD_BUTTON_LEFT_THUMB, 8);
+ MAP_BUTTON(ImGuiKey_GamepadR3, GLFW_GAMEPAD_BUTTON_RIGHT_THUMB, 9);
+ MAP_ANALOG(ImGuiKey_GamepadLStickLeft, GLFW_GAMEPAD_AXIS_LEFT_X, 0, -0.25f, -1.0f);
+ MAP_ANALOG(ImGuiKey_GamepadLStickRight, GLFW_GAMEPAD_AXIS_LEFT_X, 0, +0.25f, +1.0f);
+ MAP_ANALOG(ImGuiKey_GamepadLStickUp, GLFW_GAMEPAD_AXIS_LEFT_Y, 1, -0.25f, -1.0f);
+ MAP_ANALOG(ImGuiKey_GamepadLStickDown, GLFW_GAMEPAD_AXIS_LEFT_Y, 1, +0.25f, +1.0f);
+ MAP_ANALOG(ImGuiKey_GamepadRStickLeft, GLFW_GAMEPAD_AXIS_RIGHT_X, 2, -0.25f, -1.0f);
+ MAP_ANALOG(ImGuiKey_GamepadRStickRight, GLFW_GAMEPAD_AXIS_RIGHT_X, 2, +0.25f, +1.0f);
+ MAP_ANALOG(ImGuiKey_GamepadRStickUp, GLFW_GAMEPAD_AXIS_RIGHT_Y, 3, -0.25f, -1.0f);
+ MAP_ANALOG(ImGuiKey_GamepadRStickDown, GLFW_GAMEPAD_AXIS_RIGHT_Y, 3, +0.25f, +1.0f);
+ #undef MAP_BUTTON
+ #undef MAP_ANALOG
+}
+
+void ImGui_ImplGlfw_NewFrame()
+{
+ ImGuiIO& io = ImGui::GetIO();
+ ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
+ IM_ASSERT(bd != NULL && "Did you call ImGui_ImplGlfw_InitForXXX()?");
+
+ // Setup display size (every frame to accommodate for window resizing)
+ int w, h;
+ int display_w, display_h;
+ glfwGetWindowSize(bd->Window, &w, &h);
+ glfwGetFramebufferSize(bd->Window, &display_w, &display_h);
+ io.DisplaySize = ImVec2((float)w, (float)h);
+ if (w > 0 && h > 0)
+ io.DisplayFramebufferScale = ImVec2((float)display_w / (float)w, (float)display_h / (float)h);
+
+ // Setup time step
+ double current_time = glfwGetTime();
+ io.DeltaTime = bd->Time > 0.0 ? (float)(current_time - bd->Time) : (float)(1.0f / 60.0f);
+ bd->Time = current_time;
+
+ ImGui_ImplGlfw_UpdateMouseData();
+ ImGui_ImplGlfw_UpdateMouseCursor();
+
+ // Update game controllers (if enabled and available)
+ ImGui_ImplGlfw_UpdateGamepads();
+}
+
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
diff --git a/core/src/imgui/imgui_impl_glfw.h b/core/backends/glfw/imgui/imgui_impl_glfw.h
similarity index 64%
rename from core/src/imgui/imgui_impl_glfw.h
rename to core/backends/glfw/imgui/imgui_impl_glfw.h
index 5e1fb06..58712de 100644
--- a/core/src/imgui/imgui_impl_glfw.h
+++ b/core/backends/glfw/imgui/imgui_impl_glfw.h
@@ -4,9 +4,9 @@
// Implemented features:
// [X] Platform: Clipboard support.
+// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
// [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
-// [x] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. FIXME: 3 cursors types are missing from GLFW.
-// [X] Platform: Keyboard arrays indexed using GLFW_KEY_* codes, e.g. ImGui::IsKeyPressed(GLFW_KEY_SPACE).
+// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+).
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
@@ -29,11 +29,16 @@ IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool ins
IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown();
IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame();
-// GLFW callbacks
-// - When calling Init with 'install_callbacks=true': GLFW callbacks will be installed for you. They will call user's previously installed callbacks, if any.
-// - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call those function yourself from your own GLFW callbacks.
-IMGUI_IMPL_API void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused);
-IMGUI_IMPL_API void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered);
+// GLFW callbacks (installer)
+// - When calling Init with 'install_callbacks=true': ImGui_ImplGlfw_InstallCallbacks() is called. GLFW callbacks will be installed for you. They will chain-call user's previously installed callbacks, if any.
+// - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call individual function yourself from your own GLFW callbacks.
+IMGUI_IMPL_API void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window);
+IMGUI_IMPL_API void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window);
+
+// GLFW callbacks (individual callbacks to call if you didn't install callbacks)
+IMGUI_IMPL_API void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused); // Since 1.84
+IMGUI_IMPL_API void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered); // Since 1.84
+IMGUI_IMPL_API void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y); // Since 1.87
IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
diff --git a/core/src/backend.h b/core/src/backend.h
new file mode 100644
index 0000000..03f9e3d
--- /dev/null
+++ b/core/src/backend.h
@@ -0,0 +1,12 @@
+#pragma once
+#include
+
+namespace backend {
+ int init(std::string resDir = "");
+ void beginFrame();
+ void render(bool vsync = true);
+ void getMouseScreenPos(double& x, double& y);
+ void setMouseScreenPos(double x, double y);
+ int renderLoop();
+ int end();
+}
\ No newline at end of file
diff --git a/core/src/command_args.cpp b/core/src/command_args.cpp
new file mode 100644
index 0000000..75418fa
--- /dev/null
+++ b/core/src/command_args.cpp
@@ -0,0 +1,123 @@
+#include "command_args.h"
+#include
+
+void CommandArgsParser::defineAll() {
+#if defined(_WIN32)
+ std::string root = ".";
+ define('c', "con", "Show console on Windows");
+#elif defined(IS_MACOS_BUNDLE)
+ std::string root = (std::string)getenv("HOME") + "/Library/Application Support/sdrpp";
+#elif defined(__ANDROID__)
+ std::string root = "/storage/self/primary/sdrpp";
+#else
+ std::string root = (std::string)getenv("HOME") + "/.config/sdrpp";
+#endif
+
+ define('a', "addr", "Server mode address", "0.0.0.0");
+ define('h', "help", "Show help");
+ define('p', "port", "Server mode port", 5259);
+ define('r', "root", "Root directory, where all config files are stored", std::filesystem::absolute(root).string());
+ define('s', "server", "Run in server mode");
+}
+
+int CommandArgsParser::parse(int argc, char* argv[]) {
+ for (int i = 1; i < argc; i++) {
+ std::string arg = argv[i];
+
+ // Check for long and short name arguments
+ if (!arg.rfind("--", 0)) {
+ arg = arg.substr(2);
+ }
+ else if (!arg.rfind("-", 0)) {
+ if (aliases.find(arg[1]) == aliases.end()) {
+ printf("Unknown argument\n");
+ showHelp();
+ return -1;
+ }
+ arg = aliases[arg[1]];
+ }
+ else {
+ printf("Invalid argument\n");
+ showHelp();
+ return -1;
+ }
+
+ // Make sure the argument exists
+ if (args.find(arg) == args.end()) {
+ printf("Unknown argument\n");
+ showHelp();
+ return -1;
+ }
+
+ // Parse depending on type
+ CLIArg& carg = args[arg];
+
+ // If not void, make sure an argument is available and retrieve it
+ if (carg.type != CLI_ARG_TYPE_VOID && i + 1 >= argc) {
+ printf("Missing argument\n");
+ showHelp();
+ return -1;
+ }
+
+ // Parse void since arg won't be needed
+ if (carg.type == CLI_ARG_TYPE_VOID) {
+ carg.bval = true;
+ continue;
+ }
+
+ // Parse types that require parsing
+ arg = argv[++i];
+ if (carg.type == CLI_ARG_TYPE_BOOL) {
+ // Enforce lower case
+ for (int i = 0; i < arg.size(); i++) { arg[i] = std::tolower(arg[i]); }
+
+ if (arg == "true" || arg == "on" || arg == "1") {
+ carg.bval = true;
+ }
+ else if (arg == "false" || arg == "off" || arg == "0") {
+ carg.bval = true;
+ }
+ else {
+ printf("Invald argument, expected bool (true, false, on, off, 1, 0)\n");
+ showHelp();
+ return -1;
+ }
+ }
+ else if (carg.type == CLI_ARG_TYPE_INT) {
+ try {
+ carg.ival = std::stoi(arg);
+ }
+ catch (std::exception e) {
+ printf("Invald argument, failed to parse integer\n");
+ showHelp();
+ return -1;
+ }
+ }
+ else if (carg.type == CLI_ARG_TYPE_FLOAT) {
+ try {
+ carg.fval = std::stod(arg);
+ }
+ catch (std::exception e) {
+ printf("Invald argument, failed to parse float\n");
+ showHelp();
+ return -1;
+ }
+ }
+ else if (carg.type == CLI_ARG_TYPE_STRING) {
+ carg.sval = arg;
+ }
+ }
+
+ return 0;
+}
+
+void CommandArgsParser::showHelp() {
+ for (auto const& [ln, arg] : args) {
+ if (arg.alias) {
+ printf("-%c --%s\t\t%s\n", arg.alias, ln.c_str(), arg.description.c_str());
+ }
+ else {
+ printf(" --%s\t\t%s\n", ln.c_str(), arg.description.c_str());
+ }
+ }
+}
\ No newline at end of file
diff --git a/core/src/command_args.h b/core/src/command_args.h
new file mode 100644
index 0000000..9854cbe
--- /dev/null
+++ b/core/src/command_args.h
@@ -0,0 +1,153 @@
+#pragma once
+#include
+#include