Skip to content

Commit 35340de

Browse files
authored
Merge pull request #4932 from laytan/js-pointer-event-and-charcode
core/sys/wasm/js: add pointer event info and add charCode to keyboard
2 parents 5a12190 + 00ac48c commit 35340de

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

core/sys/wasm/js/events.odin

+23
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ Gamepad_State :: struct {
239239
_mapping_buf: [GAMEPAD_MAX_MAPPING_SIZE]byte `fmt:"-"`,
240240
}
241241

242+
Pointer_Type :: enum u8 {
243+
Mouse,
244+
Pen,
245+
Touch,
246+
}
247+
242248
Event :: struct {
243249
kind: Event_Kind,
244250
target_kind: Event_Target_Kind,
@@ -275,6 +281,8 @@ Event :: struct {
275281

276282
repeat: bool,
277283

284+
char: rune,
285+
278286
_key_len: int `fmt:"-"`,
279287
_code_len: int `fmt:"-"`,
280288
_key_buf: [KEYBOARD_MAX_KEY_SIZE]byte `fmt:"-"`,
@@ -295,6 +303,21 @@ Event :: struct {
295303

296304
button: i16,
297305
buttons: bit_set[0..<16; u16],
306+
307+
pointer: struct {
308+
altitude_angle: f64,
309+
azimuth_angle: f64,
310+
persistent_device_id: int,
311+
pointer_id: int,
312+
width: int,
313+
height: int,
314+
pressure: f64,
315+
tangential_pressure: f64,
316+
tilt: [2]f64,
317+
twist: f64,
318+
pointer_type: Pointer_Type,
319+
is_primary: bool,
320+
},
298321
},
299322

300323
gamepad: Gamepad_State,

core/sys/wasm/js/odin.js

+25
Original file line numberDiff line numberDiff line change
@@ -1543,6 +1543,29 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement, memory) {
15431543

15441544
wmi.storeI16(off(2), e.button);
15451545
wmi.storeU16(off(2), e.buttons);
1546+
1547+
if (e instanceof PointerEvent) {
1548+
wmi.storeF64(off(8), e.altitudeAngle);
1549+
wmi.storeF64(off(8), e.azimuthAngle);
1550+
wmi.storeInt(off(W), e.persistentDeviceId);
1551+
wmi.storeInt(off(W), e.pointerId);
1552+
wmi.storeInt(off(W), e.width);
1553+
wmi.storeInt(off(W), e.height);
1554+
wmi.storeF64(off(8), e.pressure);
1555+
wmi.storeF64(off(8), e.tangentialPressure);
1556+
wmi.storeF64(off(8), e.tiltX);
1557+
wmi.storeF64(off(8), e.tiltY);
1558+
wmi.storeF64(off(8), e.twist);
1559+
if (e.pointerType == "pen") {
1560+
wmi.storeU8(off(1), 1);
1561+
} else if (e.pointerType == "touch") {
1562+
wmi.storeU8(off(1), 2);
1563+
} else {
1564+
wmi.storeU8(off(1), 0);
1565+
}
1566+
wmi.storeU8(off(1), !!e.isPrimary);
1567+
}
1568+
15461569
} else if (e instanceof KeyboardEvent) {
15471570
// Note: those strings are constructed
15481571
// on the native side from buffers that
@@ -1559,6 +1582,8 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement, memory) {
15591582

15601583
wmi.storeU8(off(1), !!e.repeat);
15611584

1585+
wmi.storeI32(off(4), e.charCode);
1586+
15621587
wmi.storeInt(off(W, W), e.key.length)
15631588
wmi.storeInt(off(W, W), e.code.length)
15641589
wmi.storeString(off(32, 1), e.key);

0 commit comments

Comments
 (0)