@geastack/engine 0.1.15 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/canvas.cpp +270 -139
- package/css/engine.h +23 -3
- package/image_store.cpp +35 -2
- package/package.json +2 -2
- package/rasterized_font.cpp +42 -2
- package/touch_runtime.cpp +231 -178
- package/ui/canvas_element.cpp +432 -125
- package/ui/canvas_element.h +84 -16
- package/ui/core.cpp +1 -0
- package/ui/debugger_listeners.h +80 -0
- package/ui/debugger_overlay.h +79 -0
- package/ui/debugger_picker.h +105 -0
- package/ui/document.cpp +1 -1
- package/ui/image_node.cpp +33 -1
- package/ui/input.cpp +27 -6
- package/ui/input_render.cpp +6 -8
- package/ui/internal.h +20 -0
- package/ui/layout.cpp +130 -17
- package/ui/layout_snapshot.cpp +1 -0
- package/ui/node.h +4 -0
- package/ui/node_lifecycle.cpp +7 -0
- package/ui/node_model.h +38 -16
- package/ui/render.cpp +259 -26
- package/ui/style.cpp +571 -66
- package/ui/style.h +16 -1
- package/ui/text.cpp +113 -65
- package/ui/tree_events.cpp +55 -13
- package/ui/tree_internal.h +5 -0
- package/ui/tree_nodes.cpp +16 -1
- package/ui/tree_render.cpp +153 -13
- package/ui/tree_style.cpp +25 -3
- package/ui/view.cpp +8 -8
package/touch_runtime.cpp
CHANGED
|
@@ -8,9 +8,16 @@
|
|
|
8
8
|
#include "touch.h"
|
|
9
9
|
#include "ui/tree_internal.h"
|
|
10
10
|
#include "ui/virtual_keyboard.h"
|
|
11
|
+
#include "ui/debugger_picker.h"
|
|
11
12
|
|
|
12
13
|
#include <cstring>
|
|
13
14
|
|
|
15
|
+
#if defined(GEA_EMBEDDED_COMPARISON_BENCHMARK) && GEA_EMBEDDED_COMPARISON_BENCHMARK
|
|
16
|
+
// Optional target diagnostic: actual consumption, after move-cache coalescing.
|
|
17
|
+
extern "C" void gea_touch_trace_consumed(int phase, bool touching, int x, int y, int pointerId, int handlerX,
|
|
18
|
+
int handlerY) __attribute__((weak));
|
|
19
|
+
#endif
|
|
20
|
+
|
|
14
21
|
// Weak default for the optional multi-finger observer. Single-touch controllers
|
|
15
22
|
// (every target except the GT911 ones) don't override it, so registering a
|
|
16
23
|
// pointer observer is a harmless no-op there and they keep using the single
|
|
@@ -99,18 +106,31 @@ public:
|
|
|
99
106
|
// at the same coordinates) returns false so a static hold can't busy-render.
|
|
100
107
|
bool dispatch(const Event &event)
|
|
101
108
|
{
|
|
109
|
+
#if defined(GEA_NATIVE_DEBUGGER) && GEA_NATIVE_DEBUGGER
|
|
110
|
+
auto &picker = gea::embedded::ui::debuggerPicker;
|
|
111
|
+
if (picker.capturesInput()) {
|
|
112
|
+
int x = event.x, y = event.y;
|
|
113
|
+
if (event.touchPhase == TouchPhase::Move && event.pointerId == 0) {
|
|
114
|
+
gea::platform::touch::Touchscreen::consumeLatestMove(&x, &y);
|
|
115
|
+
TouchRuntime::transformTouchToLogical(&x, &y);
|
|
116
|
+
}
|
|
117
|
+
if (picker.consume(event.touchPhase, x, y, event.pointerId)) return true;
|
|
118
|
+
}
|
|
119
|
+
#endif
|
|
102
120
|
// Immediate-mode apps (Display.ctx games) mount no UI tree: hitTestNode
|
|
103
121
|
// returns -1 and there is no root to bind document listeners onto, so the
|
|
104
122
|
// tree dispatch below can never reach the app. Deliver pointer events
|
|
105
123
|
// straight to document-level listeners, exactly like the DOM document, so
|
|
106
124
|
// every finger (pointerId 0..N) reaches document.addEventListener().
|
|
107
125
|
if (gea::embedded::ui::Tree::instance().mountedRoot() < 0) {
|
|
126
|
+
recordConsumed(event, event.touching, event.x, event.y, event.x, event.y);
|
|
108
127
|
return dispatchToDocument(event);
|
|
109
128
|
}
|
|
110
129
|
// Additional simultaneous fingers are routed to independent per-pointer
|
|
111
130
|
// slots so they can hold/tap their own buttons (e.g. move + jump) without
|
|
112
131
|
// disturbing the primary pointer's scroll / focus / keyboard gesture.
|
|
113
132
|
if (event.pointerId >= 1) {
|
|
133
|
+
recordConsumed(event, event.touching, event.x, event.y, event.x, event.y);
|
|
114
134
|
return dispatchSecondary(event);
|
|
115
135
|
}
|
|
116
136
|
|
|
@@ -124,6 +144,10 @@ public:
|
|
|
124
144
|
TouchRuntime::transformTouchToLogical(&tx, &ty);
|
|
125
145
|
touching = true;
|
|
126
146
|
}
|
|
147
|
+
// Up callbacks inherit the last consumed move, while tx/ty retain the
|
|
148
|
+
// consumed edge coordinates. Expose both without changing routing.
|
|
149
|
+
recordConsumed(event, touching, tx, ty, !touching && wasActive_ ? lastX_ : tx,
|
|
150
|
+
!touching && wasActive_ ? lastY_ : ty);
|
|
127
151
|
|
|
128
152
|
if (touching && !wasActive_) {
|
|
129
153
|
changed = true;
|
|
@@ -238,184 +262,213 @@ public:
|
|
|
238
262
|
}
|
|
239
263
|
|
|
240
264
|
private:
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
265
|
+
static void recordConsumed(const Event &event, bool touching, int x, int y, int handlerX, int handlerY)
|
|
266
|
+
{
|
|
267
|
+
#if defined(GEA_EMBEDDED_COMPARISON_BENCHMARK) && GEA_EMBEDDED_COMPARISON_BENCHMARK
|
|
268
|
+
if (gea_touch_trace_consumed) {
|
|
269
|
+
gea_touch_trace_consumed(static_cast<int>(event.touchPhase), touching, x, y, event.pointerId, handlerX,
|
|
270
|
+
handlerY);
|
|
271
|
+
}
|
|
272
|
+
#else
|
|
273
|
+
(void)event;
|
|
274
|
+
(void)touching;
|
|
275
|
+
(void)x;
|
|
276
|
+
(void)y;
|
|
277
|
+
(void)handlerX;
|
|
278
|
+
(void)handlerY;
|
|
279
|
+
#endif
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Lightweight per-pointer handler for non-primary fingers. Independently
|
|
283
|
+
// hit-tests and fires touch*/click on its own target, but does NOT touch
|
|
284
|
+
// scroll / focus / keyboard / the hardware Touchscreen state — those stay
|
|
285
|
+
// owned by the primary pointer (pointerId 0).
|
|
286
|
+
bool dispatchSecondary(const Event &event)
|
|
287
|
+
{
|
|
288
|
+
const int slot = event.pointerId - 1;
|
|
289
|
+
if (slot < 0 || slot >= kMaxSecondaryPointers)
|
|
290
|
+
return false;
|
|
291
|
+
Secondary &s = secondary_[slot];
|
|
292
|
+
const int tx = event.x;
|
|
293
|
+
const int ty = event.y;
|
|
294
|
+
const bool touching = event.touching || event.touchPhase == TouchPhase::Move;
|
|
295
|
+
// Web convention: pointerId 1 is the primary pointer, so extra fingers
|
|
296
|
+
// are numbered from 2 upward.
|
|
297
|
+
const int webPointerId = event.pointerId + 1;
|
|
298
|
+
|
|
299
|
+
if (touching && !s.active) {
|
|
300
|
+
s.active = true;
|
|
301
|
+
s.startX = tx;
|
|
302
|
+
s.startY = ty;
|
|
303
|
+
s.lastX = tx;
|
|
304
|
+
s.lastY = ty;
|
|
305
|
+
s.dragged = false;
|
|
306
|
+
s.defaultPrevented = false;
|
|
307
|
+
s.targetId = gea::embedded::ui::Tree::instance().hitTestNode(tx, ty);
|
|
308
|
+
if (s.targetId >= 0) {
|
|
309
|
+
s.defaultPrevented =
|
|
310
|
+
dispatchPointer(PointerEventType::TouchStart, s.targetId, tx, ty, true, webPointerId, false);
|
|
311
|
+
}
|
|
312
|
+
return true;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (touching && s.active) {
|
|
316
|
+
const bool moved = tx != s.lastX || ty != s.lastY;
|
|
317
|
+
if (moved) {
|
|
318
|
+
if (!s.dragged) {
|
|
319
|
+
const int dx = tx - s.startX;
|
|
320
|
+
const int dy = ty - s.startY;
|
|
321
|
+
if (dx > 16 || dx < -16 || dy > 16 || dy < -16)
|
|
322
|
+
s.dragged = true;
|
|
323
|
+
}
|
|
324
|
+
if (s.targetId >= 0) {
|
|
325
|
+
dispatchPointer(PointerEventType::TouchMove, s.targetId, tx, ty, true, webPointerId, false);
|
|
326
|
+
}
|
|
327
|
+
s.lastX = tx;
|
|
328
|
+
s.lastY = ty;
|
|
329
|
+
}
|
|
330
|
+
return moved;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (!touching && s.active) {
|
|
334
|
+
if (s.targetId >= 0) {
|
|
335
|
+
dispatchPointer(PointerEventType::TouchEnd, s.targetId, s.lastX, s.lastY, false, webPointerId, false);
|
|
336
|
+
if (!s.dragged && !s.defaultPrevented) {
|
|
337
|
+
dispatchPointer(PointerEventType::Click, s.targetId, s.lastX, s.lastY, false, webPointerId, false);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
s.active = false;
|
|
341
|
+
s.targetId = -1;
|
|
342
|
+
s.dragged = false;
|
|
343
|
+
s.defaultPrevented = false;
|
|
344
|
+
return true;
|
|
345
|
+
}
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// Immediate-mode (no UI tree) path: synthesize the pointer event from the raw
|
|
350
|
+
// touch and hand it straight to document-level listeners. No node target, no
|
|
351
|
+
// tree walk — `document` sees every pointer event, exactly like the DOM.
|
|
352
|
+
static bool dispatchToDocument(const Event &event)
|
|
353
|
+
{
|
|
354
|
+
PointerEventType type;
|
|
355
|
+
switch (event.touchPhase) {
|
|
356
|
+
case TouchPhase::Down:
|
|
357
|
+
type = PointerEventType::TouchStart;
|
|
358
|
+
break;
|
|
359
|
+
case TouchPhase::Move:
|
|
360
|
+
type = PointerEventType::TouchMove;
|
|
361
|
+
break;
|
|
362
|
+
case TouchPhase::Up:
|
|
363
|
+
type = PointerEventType::TouchEnd;
|
|
364
|
+
break;
|
|
365
|
+
default:
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
PointerEvent pe{};
|
|
369
|
+
pe.type = type;
|
|
370
|
+
pe.targetId = -1;
|
|
371
|
+
// Match the mounted-tree path and the public TypeScript surface:
|
|
372
|
+
// web-facing pointer ids start at 1, while internal touch slots start at 0.
|
|
373
|
+
const int webPointerId = event.pointerId + 1;
|
|
374
|
+
pe.pointerId = webPointerId;
|
|
375
|
+
pe.x = event.x;
|
|
376
|
+
pe.y = event.y;
|
|
377
|
+
pe.clientX = event.x;
|
|
378
|
+
pe.clientY = event.y;
|
|
379
|
+
pe.pageX = event.x;
|
|
380
|
+
pe.pageY = event.y;
|
|
381
|
+
pe.screenX = event.x;
|
|
382
|
+
pe.screenY = event.y;
|
|
383
|
+
pe.primary = event.pointerId == 0;
|
|
384
|
+
pe.touchesLength = event.touching ? 1 : 0;
|
|
385
|
+
pe.targetTouchesLength = event.touching ? 1 : 0;
|
|
386
|
+
pe.changedTouchesLength = 1;
|
|
387
|
+
pe.touches[0] = makeTouchPoint(-1, event.x, event.y, webPointerId);
|
|
388
|
+
pe.targetTouches[0] = pe.touches[0];
|
|
389
|
+
pe.changedTouches[0] = pe.touches[0];
|
|
390
|
+
return gea::embedded::ui::dispatchDocumentPointer(pe);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
static bool dispatchPointer(PointerEventType type, int targetId, int x, int y, bool activeTouch, int pointerId = 1,
|
|
394
|
+
bool primary = true)
|
|
395
|
+
{
|
|
396
|
+
PointerEvent event{};
|
|
397
|
+
event.type = type;
|
|
398
|
+
// Skip entirely when no node listens for this type — don't build the
|
|
399
|
+
// event payload or walk the tree. Apps that bind only touch* never pay
|
|
400
|
+
// for the paired pointer* dispatch (and vice versa).
|
|
401
|
+
if (!gea::embedded::ui::Tree::instance().hasListenersForType(event.typeName()))
|
|
402
|
+
return false;
|
|
403
|
+
event.targetId = targetId;
|
|
404
|
+
event.pointerId = pointerId;
|
|
405
|
+
event.x = x;
|
|
406
|
+
event.y = y;
|
|
407
|
+
event.clientX = x;
|
|
408
|
+
event.clientY = y;
|
|
409
|
+
event.pageX = x;
|
|
410
|
+
event.pageY = y;
|
|
411
|
+
event.screenX = x;
|
|
412
|
+
event.screenY = y;
|
|
413
|
+
event.primary = primary;
|
|
414
|
+
event.touchesLength = activeTouch ? 1 : 0;
|
|
415
|
+
event.targetTouchesLength = activeTouch ? 1 : 0;
|
|
416
|
+
event.changedTouchesLength = 1;
|
|
417
|
+
event.touches[0] = makeTouchPoint(targetId, x, y, pointerId);
|
|
418
|
+
event.targetTouches[0] = event.touches[0];
|
|
419
|
+
event.changedTouches[0] = event.touches[0];
|
|
420
|
+
gea::embedded::ui::Tree::instance().dispatchEvent(event);
|
|
421
|
+
return event.defaultPrevented;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
static TouchPoint makeTouchPoint(int targetId, int x, int y, int identifier = 1)
|
|
425
|
+
{
|
|
426
|
+
TouchPoint point{};
|
|
427
|
+
point.identifier = identifier;
|
|
428
|
+
point.target = EventTarget(targetId);
|
|
429
|
+
point.screenX = x;
|
|
430
|
+
point.screenY = y;
|
|
431
|
+
point.clientX = x;
|
|
432
|
+
point.clientY = y;
|
|
433
|
+
point.pageX = x;
|
|
434
|
+
point.pageY = y;
|
|
435
|
+
return point;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
static int inputAncestor(int nodeId)
|
|
439
|
+
{
|
|
440
|
+
auto &tree = gea::embedded::ui::Tree::instance();
|
|
441
|
+
for (int n = nodeId; n >= 0 && n < tree.nodeCount(); n = tree.node(n).parent) {
|
|
442
|
+
if (std::strcmp(tree.tagName(n), "input") == 0)
|
|
443
|
+
return n;
|
|
444
|
+
}
|
|
445
|
+
return -1;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
bool dispatchEnabled_ = true;
|
|
449
|
+
bool wasActive_ = false;
|
|
450
|
+
int lastActivityMs_ = 0;
|
|
451
|
+
bool activeDefaultPrevented_ = false;
|
|
452
|
+
int lastX_ = 0;
|
|
453
|
+
int lastY_ = 0;
|
|
454
|
+
int startX_ = 0;
|
|
455
|
+
int startY_ = 0;
|
|
456
|
+
bool dragged_ = false;
|
|
457
|
+
int activeTargetId_ = -1;
|
|
458
|
+
|
|
459
|
+
// Per-pointer state for non-primary (pointerId >= 1) simultaneous fingers.
|
|
460
|
+
struct Secondary {
|
|
461
|
+
bool active = false;
|
|
462
|
+
bool dragged = false;
|
|
463
|
+
bool defaultPrevented = false;
|
|
464
|
+
int targetId = -1;
|
|
465
|
+
int startX = 0;
|
|
466
|
+
int startY = 0;
|
|
467
|
+
int lastX = 0;
|
|
468
|
+
int lastY = 0;
|
|
469
|
+
};
|
|
470
|
+
static constexpr int kMaxSecondaryPointers = 9;
|
|
471
|
+
Secondary secondary_[kMaxSecondaryPointers]{};
|
|
419
472
|
};
|
|
420
473
|
|
|
421
474
|
} // namespace
|