Skip to content

Commit b735eff

Browse files
committed
fix idling on emscripten during animation and pinch zoom
1 parent 27e3d3a commit b735eff

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ if(portable-file-dialogs_ADDED)
178178
endif()
179179

180180
set(HELLOIMGUI_WITH_GLFW ON)
181-
CPMAddPackage("gh:pthom/hello_imgui#b1a74a7d76a84c08c1fa3a97b8dc3e2c5b5b97b3")
181+
CPMAddPackage("gh:wkjarosz/hello_imgui#745ced9d52be601097e4b7d0837ad67a0b93db32")
182182
if(hello_imgui_ADDED)
183183
message(STATUS "hello_imgui library added")
184184
endif()

src/app.cpp

+20-9
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,7 @@ void SampleViewer::draw_editor()
993993
bool SampleViewer::process_event(void *e)
994994
{
995995
#ifdef HELLOIMGUI_USE_SDL_OPENGL3
996+
auto &io = ImGui::GetIO();
996997
static bool sPinch = false;
997998
SDL_Event *event = static_cast<SDL_Event *>(e);
998999
switch (event->type)
@@ -1012,19 +1013,29 @@ bool SampleViewer::process_event(void *e)
10121013
// case SDL_FINGERDOWN: HelloImGui::Log(HelloImGui::LogLevel::Debug, "Got an SDL_FINGERDOWN event"); break;
10131014
case SDL_MULTIGESTURE:
10141015
{
1015-
const float cPinchZoomThreshold(0.0001f);
1016-
const float cPinchScale(80.0f);
1017-
SDL_MultiGestureEvent *m = static_cast<SDL_MultiGestureEvent *>(e);
1018-
// HelloImGui::Log(
1019-
// HelloImGui::LogLevel::Debug,
1020-
// fmt::format("Got an SDL_MULTIGESTURE event; numFingers: {}; dDist: {}", m->numFingers,
1021-
// m->dDist).c_str());
1022-
if (m->numFingers == 2 && fabs(m->dDist) >= cPinchZoomThreshold)
1016+
constexpr float cPinchZoomThreshold(0.0001f);
1017+
constexpr float cPinchScale(80.0f);
1018+
if (event->mgesture.numFingers == 2 && fabs(event->mgesture.dDist) >= cPinchZoomThreshold)
10231019
{
1020+
// HelloImGui::Log(HelloImGui::LogLevel::Debug,
1021+
// fmt::format("Got an SDL_MULTIGESTURE event; numFingers: {}; dDist: {}; x: {}, y: {}",
1022+
// event->mgesture.numFingers, event->mgesture.dDist, event->mgesture.x,
1023+
// event->mgesture.y)
1024+
// .c_str());
10241025
sPinch = true;
10251026
// Zoom in/out by positive/negative mPinch distance
1026-
float zoomDelta = m->dDist * cPinchScale;
1027+
float zoomDelta = event->mgesture.dDist * cPinchScale;
10271028
m_camera[CAMERA_NEXT].zoom = std::max(0.001, m_camera[CAMERA_NEXT].zoom * pow(1.1, zoomDelta));
1029+
1030+
// add a dummy event so that idling doesn't happen
1031+
auto g = ImGui::GetCurrentContext();
1032+
ImGuiInputEvent e;
1033+
e.Type = ImGuiInputEventType_None;
1034+
e.Source = ImGuiInputSource_Mouse;
1035+
e.EventId = g->InputEventsNextEventId++;
1036+
e.MouseWheel.MouseSource = ImGuiMouseSource_TouchScreen;
1037+
g->InputEventsQueue.push_back(e);
1038+
10281039
return true;
10291040
}
10301041
}

0 commit comments

Comments
 (0)