mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-19 14:01:10 +01:00
[gpu] Skip first touchmove after finger count change
Prevents jumps during 3→2→1 finger transitions by dropping one frame and reinitializing pinch state for the new finger count. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
dac2716b2a
commit
d8f1c44fd3
2 files changed
+32
No files matched your search
@@ -516,10 +516,12 @@ static double pinch_dist;
|
||||
static double pinch_angle;
|
||||
static double pinch_cx, pinch_cy;
|
||||
static bool three_finger_active;
|
||||
static bool touch_count_changed;
|
||||
|
||||
static EM_BOOL
|
||||
on_touchstart (int type, const EmscriptenTouchEvent *e, void *ud)
|
||||
{
|
||||
touch_count_changed = true;
|
||||
if (e->numTouches == 1)
|
||||
{
|
||||
demo_view_motion_func (vu, e->touches[0].targetX, e->touches[0].targetY);
|
||||
@@ -550,6 +552,20 @@ on_touchstart (int type, const EmscriptenTouchEvent *e, void *ud)
|
||||
static EM_BOOL
|
||||
on_touchmove (int type, const EmscriptenTouchEvent *e, void *ud)
|
||||
{
|
||||
if (touch_count_changed)
|
||||
{
|
||||
touch_count_changed = false;
|
||||
if (e->numTouches == 2)
|
||||
{
|
||||
double dx = e->touches[1].targetX - e->touches[0].targetX;
|
||||
double dy = e->touches[1].targetY - e->touches[0].targetY;
|
||||
pinch_dist = sqrt (dx * dx + dy * dy);
|
||||
pinch_angle = atan2 (dy, dx);
|
||||
pinch_cx = (e->touches[0].targetX + e->touches[1].targetX) / 2.0;
|
||||
pinch_cy = (e->touches[0].targetY + e->touches[1].targetY) / 2.0;
|
||||
}
|
||||
return EM_TRUE;
|
||||
}
|
||||
if (e->numTouches >= 3 && three_finger_active)
|
||||
{
|
||||
double cx = (e->touches[0].targetX + e->touches[1].targetX + e->touches[2].targetX) / 3.0;
|
||||
@@ -585,6 +601,7 @@ on_touchmove (int type, const EmscriptenTouchEvent *e, void *ud)
|
||||
static EM_BOOL
|
||||
on_touchend (int type, const EmscriptenTouchEvent *e, void *ud)
|
||||
{
|
||||
touch_count_changed = true;
|
||||
if (three_finger_active && e->numTouches < 3)
|
||||
{
|
||||
three_finger_active = false;
|
||||
|
||||
@@ -207,12 +207,14 @@ tap: animate · dbl-tap+drag: zoom · long-press: reset</span>
|
||||
var pinchAngle = 0;
|
||||
var pinchCX = 0, pinchCY = 0;
|
||||
var threeFingerActive = false;
|
||||
var touchCountChanged = false;
|
||||
var longPressTimer = null;
|
||||
var longPressFired = false;
|
||||
var lastTapTime = 0;
|
||||
var doubleTapZoom = false;
|
||||
var doubleTapY = 0;
|
||||
canvas.addEventListener('touchstart', function (e) {
|
||||
touchCountChanged = true;
|
||||
if (e.touches.length === 1) {
|
||||
var now = performance.now();
|
||||
if (now - lastTapTime < 300) {
|
||||
@@ -262,6 +264,18 @@ tap: animate · dbl-tap+drag: zoom · long-press: reset</span>
|
||||
}, {passive: false});
|
||||
var longPressX = 0, longPressY = 0;
|
||||
canvas.addEventListener('touchmove', function (e) {
|
||||
if (touchCountChanged) {
|
||||
touchCountChanged = false;
|
||||
/* Reinitialize state for current finger count to avoid jumps */
|
||||
if (e.touches.length === 2) {
|
||||
var t = e.touches;
|
||||
pinchDist = Math.hypot(t[1].clientX - t[0].clientX, t[1].clientY - t[0].clientY);
|
||||
pinchAngle = Math.atan2(t[1].clientY - t[0].clientY, t[1].clientX - t[0].clientX);
|
||||
pinchCX = (t[0].clientX + t[1].clientX) / 2;
|
||||
pinchCY = (t[0].clientY + t[1].clientY) / 2;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (longPressTimer && e.touches.length === 1) {
|
||||
var dx = e.touches[0].clientX - longPressX;
|
||||
var dy = e.touches[0].clientY - longPressY;
|
||||
@@ -316,6 +330,7 @@ tap: animate · dbl-tap+drag: zoom · long-press: reset</span>
|
||||
}
|
||||
}, {passive: false});
|
||||
canvas.addEventListener('touchend', function (e) {
|
||||
touchCountChanged = true;
|
||||
if (longPressTimer) { clearTimeout(longPressTimer); longPressTimer = null; }
|
||||
if (longPressFired) {
|
||||
longPressFired = false;
|
||||
|
||||
Reference in new issue
Block a user