diff --git a/util/gpu/web/build.sh b/util/gpu/web/build.sh index c51d2a13f..54dca6cf4 100755 --- a/util/gpu/web/build.sh +++ b/util/gpu/web/build.sh @@ -31,7 +31,7 @@ em++ \ -sUSE_WEBGL2=1 \ -sFULL_ES3=1 \ -sALLOW_MEMORY_GROWTH=1 \ - -sEXPORTED_FUNCTIONS='["_main","_web_load_font","_web_set_text","_web_get_text","_web_reset","_web_pinch","_malloc","_free"]' \ + -sEXPORTED_FUNCTIONS='["_main","_web_load_font","_web_set_text","_web_get_text","_web_toggle_animation","_web_reset","_web_pinch","_malloc","_free"]' \ -sEXPORTED_RUNTIME_METHODS='["UTF8ToString","lengthBytesUTF8","stringToUTF8"]' \ --shell-file "$SRCDIR/util/gpu/web/shell.html" \ -o "$OUTDIR/index.html" diff --git a/util/gpu/web/hb-gpu-web-webgpu.cc b/util/gpu/web/hb-gpu-web-webgpu.cc index 7d46910a0..6a34a67e5 100644 --- a/util/gpu/web/hb-gpu-web-webgpu.cc +++ b/util/gpu/web/hb-gpu-web-webgpu.cc @@ -374,6 +374,12 @@ rebuild_buffer (const char *text) extern "C" { +EMSCRIPTEN_KEEPALIVE void +web_reset () +{ + demo_view_reset (vu); +} + EMSCRIPTEN_KEEPALIVE void web_load_font (const char *data, int len) { diff --git a/util/gpu/web/hb-gpu-web.cc b/util/gpu/web/hb-gpu-web.cc index 0c4273940..f3817bf53 100644 --- a/util/gpu/web/hb-gpu-web.cc +++ b/util/gpu/web/hb-gpu-web.cc @@ -120,6 +120,12 @@ web_get_text () return current_text; } +EMSCRIPTEN_KEEPALIVE void +web_toggle_animation () +{ + demo_view_key_func (vu, 32 /* GLFW_KEY_SPACE */, 0, 1, 0); +} + EMSCRIPTEN_KEEPALIVE void web_reset () { diff --git a/util/gpu/web/shell.html b/util/gpu/web/shell.html index 7e70a20bf..17795f130 100644 --- a/util/gpu/web/shell.html +++ b/util/gpu/web/shell.html @@ -196,13 +196,19 @@ tap: animate · dbl-tap+drag: zoom · long-press: reset if (e.touches.length === 1) { var now = performance.now(); if (now - lastTapTime < 300) { - /* Double-tap: start zoom drag */ + /* Double-tap: start zoom drag. + * Undo animation toggle from first tap. */ + e.preventDefault(); + if (typeof _web_toggle_animation === 'function') + _web_toggle_animation(); doubleTapZoom = true; doubleTapY = e.touches[0].clientY; lastTapTime = 0; if (longPressTimer) { clearTimeout(longPressTimer); longPressTimer = null; } } else { lastTapTime = now; + longPressX = e.touches[0].clientX; + longPressY = e.touches[0].clientY; longPressTimer = setTimeout(function () { longPressTimer = null; if (typeof _web_reset === 'function') _web_reset(); @@ -233,8 +239,13 @@ tap: animate · dbl-tap+drag: zoom · long-press: reset })); } }, {passive: false}); + var longPressX = 0, longPressY = 0; canvas.addEventListener('touchmove', function (e) { - if (longPressTimer) { clearTimeout(longPressTimer); longPressTimer = null; } + if (longPressTimer && e.touches.length === 1) { + var dx = e.touches[0].clientX - longPressX; + var dy = e.touches[0].clientY - longPressY; + if (dx*dx + dy*dy > 100) { clearTimeout(longPressTimer); longPressTimer = null; } + } if (doubleTapZoom && e.touches.length === 1) { e.preventDefault(); var dy = e.touches[0].clientY - doubleTapY;