diff --git a/raylib.js b/raylib.js index 0f8da8f..3d7d385 100644 --- a/raylib.js +++ b/raylib.js @@ -32,6 +32,7 @@ class RaylibJs { this.currentPressedKeyState = new Set(); this.currentMouseWheelMoveState = 0; this.currentMousePosition = {x: 0, y: 0}; + this.currentGestureState = 0; this.quit = false; } @@ -58,7 +59,7 @@ class RaylibJs { this.wasm = await WebAssembly.instantiateStreaming(fetch(wasmPath), { env: make_environment(this) }); - + const keyDown = (e) => { this.currentPressedKeyState.add(glfwKeyMapping[e.code]); }; @@ -66,16 +67,24 @@ class RaylibJs { this.currentPressedKeyState.delete(glfwKeyMapping[e.code]); }; const wheelMove = (e) => { - this.currentMouseWheelMoveState = Math.sign(-e.deltaY); + this.currentMouseWheelMoveState = Math.sign(-e.deltaY); }; const mouseMove = (e) => { this.currentMousePosition = {x: e.clientX, y: e.clientY}; }; + const gestureTap = (e) => { + this.currentGestureState = gestureMapping.GESTURE_TAP; + }; window.addEventListener("keydown", keyDown); window.addEventListener("keyup", keyUp); window.addEventListener("wheel", wheelMove); window.addEventListener("mousemove", mouseMove); + canvas.addEventListener("mousedown", gestureTap); + canvas.oncontextmenu = function(e) { + e.preventDefault(); + }; + this.wasm.instance.exports.main(); const next = (timestamp) => { if (this.quit) { @@ -131,6 +140,7 @@ class RaylibJs { this.prevPressedKeyState.clear(); this.prevPressedKeyState = new Set(this.currentPressedKeyState); this.currentMouseWheelMoveState = 0.0; + this.currentGestureState = 0; } DrawCircleV(center_ptr, radius, color_ptr) { @@ -178,8 +188,8 @@ class RaylibJs { GetMouseWheelMove() { return this.currentMouseWheelMoveState; } - IsGestureDetected() { - return false; + IsGestureDetected(gesture) { + return this.currentGestureState === gesture; } TextFormat(... args){ @@ -364,6 +374,20 @@ const glfwKeyMapping = { // GLFW_KEY_LAST GLFW_KEY_MENU } +const gestureMapping = { + GESTURE_NONE: 0, + GESTURE_TAP: 1, + GESTURE_DOUBLETAP: 2, + GESTURE_HOLD: 4, + GESTURE_DRAG: 8, + GESTURE_SWIPE_RIGHT: 16, + GESTURE_SWIPE_LEFT: 32, + GESTURE_SWIPE_UP: 64, + GESTURE_SWIPE_DOWN: 128, + GESTURE_PINCH_IN: 256, + GESTURE_PINCH_OUT: 512 +} + function cstrlen(mem, ptr) { let len = 0; while (mem[ptr] != 0) {