mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-26 01:11:25 +01:00
[gpu] Pinch-zoom around pinch center
Adds demo_view_zoom_around() which scales while compensating translation so the midpoint between fingers stays fixed. Same maps-like behavior as the pinch rotation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
c1550337db
commit
7659baca01
6 files changed
+39
-8
No files matched your search
@@ -505,6 +505,18 @@ demo_view_scroll_func (demo_view_t *vu, double xoffset, double yoffset)
|
||||
vu->needs_redraw = true;
|
||||
}
|
||||
|
||||
void
|
||||
demo_view_zoom_around (demo_view_t *vu, double factor,
|
||||
double cx, double cy,
|
||||
int width, int height)
|
||||
{
|
||||
demo_view_scale (vu, factor, factor);
|
||||
demo_view_translate (vu,
|
||||
+(2. * cx / width - 1) * (1 - factor),
|
||||
-(2. * cy / height - 1) * (1 - factor));
|
||||
vu->needs_redraw = true;
|
||||
}
|
||||
|
||||
void
|
||||
demo_view_rotate_z (demo_view_t *vu, double angle)
|
||||
{
|
||||
|
||||
@@ -45,6 +45,11 @@ demo_view_mouse_func (demo_view_t *vu, int button, int action, int mods);
|
||||
void
|
||||
demo_view_scroll_func (demo_view_t *vu, double xoffset, double yoffset);
|
||||
|
||||
void
|
||||
demo_view_zoom_around (demo_view_t *vu, double factor,
|
||||
double cx, double cy,
|
||||
int width, int height);
|
||||
|
||||
void
|
||||
demo_view_rotate_z (demo_view_t *vu, double angle);
|
||||
|
||||
|
||||
@@ -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_rotate_z","_malloc","_free"]' \
|
||||
-sEXPORTED_FUNCTIONS='["_main","_web_load_font","_web_set_text","_web_get_text","_web_zoom_around","_web_rotate_z","_malloc","_free"]' \
|
||||
-sEXPORTED_RUNTIME_METHODS='["UTF8ToString","lengthBytesUTF8","stringToUTF8"]' \
|
||||
--shell-file "$SRCDIR/util/gpu/web/shell.html" \
|
||||
-o "$OUTDIR/index.html"
|
||||
|
||||
@@ -552,7 +552,11 @@ on_touchmove (int type, const EmscriptenTouchEvent *e, void *ud)
|
||||
double dist = sqrt (dx * dx + dy * dy);
|
||||
double angle = atan2 (dy, dx);
|
||||
if (pinch_dist > 0)
|
||||
demo_view_scroll_func (vu, 0, (dist - pinch_dist) * 0.05);
|
||||
{
|
||||
double mx = (e->touches[0].targetX + e->touches[1].targetX) / 2.0;
|
||||
double my = (e->touches[0].targetY + e->touches[1].targetY) / 2.0;
|
||||
demo_view_zoom_around (vu, dist / pinch_dist, mx, my, css_w, css_h);
|
||||
}
|
||||
double dAngle = angle - pinch_angle;
|
||||
if (dAngle > M_PI) dAngle -= 2 * M_PI;
|
||||
if (dAngle < -M_PI) dAngle += 2 * M_PI;
|
||||
|
||||
@@ -120,6 +120,12 @@ web_get_text ()
|
||||
return current_text;
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void
|
||||
web_zoom_around (float factor, float cx, float cy, int w, int h)
|
||||
{
|
||||
demo_view_zoom_around (vu, factor, cx, cy, w, h);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void
|
||||
web_rotate_z (float angle, float cx, float cy, int w, int h)
|
||||
{
|
||||
|
||||
+10
-6
@@ -227,13 +227,17 @@ space: animate · b: dark mode · g: gamma · s: stem · d: debug · r: reset ·
|
||||
/* Zoom from distance change */
|
||||
var change = dist - pinchDist;
|
||||
if (Math.abs(change) >= 2) {
|
||||
var factor = dist / pinchDist;
|
||||
pinchDist = dist;
|
||||
var delta = change / dist * 5;
|
||||
canvas.dispatchEvent(new WheelEvent('wheel', {
|
||||
deltaY: -delta * 120,
|
||||
clientX: (t[0].clientX + t[1].clientX) / 2,
|
||||
clientY: (t[0].clientY + t[1].clientY) / 2
|
||||
}));
|
||||
var mx = (t[0].clientX + t[1].clientX) / 2;
|
||||
var my = (t[0].clientY + t[1].clientY) / 2;
|
||||
if (typeof _web_zoom_around === 'function')
|
||||
_web_zoom_around(factor, mx, my, canvas.clientWidth, canvas.clientHeight);
|
||||
else {
|
||||
/* Fallback to wheel event */
|
||||
var delta = (factor - 1) * 5;
|
||||
canvas.dispatchEvent(new WheelEvent('wheel', { deltaY: -delta * 120 }));
|
||||
}
|
||||
}
|
||||
/* Rotate from angle change */
|
||||
var dAngle = angle - pinchAngle;
|
||||
|
||||
Reference in new issue
Block a user