web: Fix touch input

This commit is contained in:
WerWolv
2024-07-03 22:32:33 +02:00
parent cfbc6e085a
commit 1d99f8534d
2 changed files with 96 additions and 2 deletions

View File

@@ -7,6 +7,9 @@
#include <hex/api/event_manager.hpp>
#include <imgui.h>
#include <imgui_internal.h>
// Function used by c++ to get the size of the html canvas
EM_JS(int, canvas_get_width, (), {
return Module.canvas.width;
@@ -37,6 +40,27 @@ extern "C" void handleThemeChange() {
hex::EventOSThemeChanged::post();
}
EM_JS(void, setupInputModeListener, (), {
Module.canvas.addEventListener('mousedown', function() {
Module._enterMouseMode();
});
Module.canvas.addEventListener('touchstart', function() {
Module._enterTouchMode();
});
});
EMSCRIPTEN_KEEPALIVE
extern "C" void enterMouseMode() {
ImGui::GetIO().AddMouseSourceEvent(ImGuiMouseSource_Mouse);
}
EMSCRIPTEN_KEEPALIVE
extern "C" void enterTouchMode() {
ImGui::GetIO().AddMouseSourceEvent(ImGuiMouseSource_TouchScreen);
}
namespace hex {
void nativeErrorMessage(const std::string &message) {
@@ -70,6 +94,7 @@ namespace hex {
void Window::setupNativeWindow() {
resizeCanvas();
setupThemeListener();
setupInputModeListener();
bool themeFollowSystem = ImHexApi::System::usesSystemThemeDetection();
EventOSThemeChanged::subscribe(this, [themeFollowSystem] {