chore: pass pointer type and timestamp to scripted drawable handlers (#14472) e3c4939942 In a Node script's pointer handlers (pointerDown / pointerMove / pointerUp / pointerExit), event.type always read "pointerEnter", in the editor and at runtime. event.timeStamp was always 0. The scripted drawable path built its ScriptedPointerEvent from only the pointer id and local position. ScriptBackend::callPointerEvent had no parameter for the listener type, so it was left at its default of 0, which is ListenerType::enter. Listener actions were unaffected because asPointerEvent() already passes the full invocation through. This PR fixes event.type everywhere, and passes event.timeStamp wherever the host already has one. See "Timestamps" below for exactly which events get a real timestamp. Co-authored-by: Philip Chung <philterdesign@gmail.com>
diff --git a/.rive_head b/.rive_head index 134b702..1ad80e7 100644 --- a/.rive_head +++ b/.rive_head
@@ -1 +1 @@ -89a770ce653b7ae8f7a3a3a0da73a229377f5d1f +e3c4939942893dab8d7b4f76bf9d2b736367e11c
diff --git a/include/rive/lua/scripting_vm.hpp b/include/rive/lua/scripting_vm.hpp index 85cf4cf..be6dae3 100644 --- a/include/rive/lua/scripting_vm.hpp +++ b/include/rive/lua/scripting_vm.hpp
@@ -85,6 +85,8 @@ const char* method, int pointerId, Vec2D localPosition, + ListenerType hitType, + float timeStamp, HitResult* outResult) override; bool callKeyboardEvent(ScriptedObject* object, int selfRef,
diff --git a/include/rive/scripted/script_backend.hpp b/include/rive/scripted/script_backend.hpp index 32c4503..9bbb9f8 100644 --- a/include/rive/scripted/script_backend.hpp +++ b/include/rive/scripted/script_backend.hpp
@@ -5,6 +5,7 @@ #include "rive/hit_result.hpp" #include "rive/input/focusable.hpp" +#include "rive/listener_type.hpp" #include "rive/math/mat2d.hpp" #include "rive/math/vec2d.hpp" @@ -162,6 +163,8 @@ const char* method, int pointerId, Vec2D localPosition, + ListenerType hitType, + float timeStamp, HitResult* outResult) = 0; /// Drawable protocol: self.keyboardEvent(self, invocation) -> stop /// propagation.
diff --git a/include/rive/wasm/wasm_scripting_vm.hpp b/include/rive/wasm/wasm_scripting_vm.hpp index 9fb232e..8557a26 100644 --- a/include/rive/wasm/wasm_scripting_vm.hpp +++ b/include/rive/wasm/wasm_scripting_vm.hpp
@@ -275,6 +275,8 @@ const char* method, int pointerId, Vec2D localPosition, + ListenerType hitType, + float timeStamp, HitResult* outResult) override; bool callKeyboardEvent(ScriptedObject* object, int selfRef,
diff --git a/src/lua/lua_script_backend.cpp b/src/lua/lua_script_backend.cpp index 29a00f4..58c6b5e 100644 --- a/src/lua/lua_script_backend.cpp +++ b/src/lua/lua_script_backend.cpp
@@ -524,6 +524,8 @@ const char* method, int pointerId, Vec2D localPosition, + ListenerType hitType, + float timeStamp, HitResult* outResult) { lua_State* L = m_state; @@ -537,8 +539,12 @@ return false; } lua_pushvalue(L, -2); - auto pointerEvent = - lua_newrive<ScriptedPointerEvent>(L, pointerId, localPosition); + auto pointerEvent = lua_newrive<ScriptedPointerEvent>(L, + pointerId, + localPosition, + Vec2D(), + (int)hitType, + timeStamp); if (static_cast<lua_Status>(rive_lua_pcall_with_context(L, object, 2, 0)) != LUA_OK) {
diff --git a/src/scripted/scripted_drawable.cpp b/src/scripted/scripted_drawable.cpp index 89c348e..a491259 100644 --- a/src/scripted/scripted_drawable.cpp +++ b/src/scripted/scripted_drawable.cpp
@@ -118,6 +118,8 @@ mName.c_str(), pointerId, localPos, + canHit ? hitType : ListenerType::exit, + timeStamp, &hitResult)) { m_drawable->wakeAdvance();
diff --git a/src/wasm/wasm_scripting_vm.cpp b/src/wasm/wasm_scripting_vm.cpp index 2d171d1..573c081 100644 --- a/src/wasm/wasm_scripting_vm.cpp +++ b/src/wasm/wasm_scripting_vm.cpp
@@ -9306,8 +9306,13 @@ const char* method, int pointerId, Vec2D localPosition, + ListenerType hitType, + float timeStamp, HitResult* outResult) { + // Not forwarded yet: host_obj_pointer_event's guest ABI has no slots. + (void)hitType; + (void)timeStamp; if (!valid()) { return false;
diff --git a/tests/unit_tests/runtime/scripting/scripting_drawable_pointer_type_test.cpp b/tests/unit_tests/runtime/scripting/scripting_drawable_pointer_type_test.cpp new file mode 100644 index 0000000..c8d3d69 --- /dev/null +++ b/tests/unit_tests/runtime/scripting/scripting_drawable_pointer_type_test.cpp
@@ -0,0 +1,139 @@ +/* + * Copyright 2026 Rive + */ + +// Pointer events dispatched to a scripted drawable carry the listener type and +// timestamp of the event, not the ScriptedPointerEvent defaults (which read as +// "pointerEnter" and 0). + +#include "catch.hpp" +#include "scripting_test_utilities.hpp" +#include "rive/lua/rive_lua_libs.hpp" +#include "rive/scripted/scripted_drawable.hpp" + +#include <string> + +using namespace rive; + +namespace +{ +// Stubs addScriptedDirt so the test doesn't need a full artboard graph. +class PointerTypeScriptedDrawable : public ScriptedDrawable +{ +public: + bool addScriptedDirt(ComponentDirt value, bool recurse = false) override + { + return true; + } +}; + +constexpr const char* pointerTypeScript = + R"(type MyDrawing = {} +local lastHandler = '' +local lastType = '' +local lastTimeStamp = -1 + +local function record(handler: string, event: PointerEvent) + lastHandler = handler + lastType = event.type + lastTimeStamp = event.timeStamp +end + +function init(self: MyDrawing, context: Context): boolean + return true +end + +function pointerDown(self: MyDrawing, event: PointerEvent) + record('pointerDown', event) +end + +function pointerMove(self: MyDrawing, event: PointerEvent) + record('pointerMove', event) +end + +function pointerUp(self: MyDrawing, event: PointerEvent) + record('pointerUp', event) +end + +function pointerExit(self: MyDrawing, event: PointerEvent) + record('pointerExit', event) +end + +function getLastHandler(): string + return lastHandler +end + +function getLastType(): string + return lastType +end + +function getLastTimeStamp(): number + return lastTimeStamp +end + +return function(): Node<MyDrawing> + return { + init = init, + pointerDown = pointerDown, + pointerMove = pointerMove, + pointerUp = pointerUp, + pointerExit = pointerExit, + } +end +)"; + +std::string readString(lua_State* L, const char* getter) +{ + lua_getglobal(L, getter); + REQUIRE(lua_pcall(L, 0, 1, 0) == LUA_OK); + std::string value = lua_tostring(L, -1); + lua_pop(L, 1); + return value; +} + +float readNumber(lua_State* L, const char* getter) +{ + lua_getglobal(L, getter); + REQUIRE(lua_pcall(L, 0, 1, 0) == LUA_OK); + float value = (float)lua_tonumber(L, -1); + lua_pop(L, 1); + return value; +} +} // namespace + +TEST_CASE("scripted drawable pointer events report their type and timestamp", + "[scripting]") +{ + ScriptingTest vm(pointerTypeScript); + lua_State* L = vm.state(); + + PointerTypeScriptedDrawable drawable; + // wantsPointerDown | wantsPointerMove | wantsPointerUp | wantsPointerExit + drawable.implementedMethods((1 << 3) | (1 << 4) | (1 << 5) | (1 << 6)); + drawable.setAsset(make_rcp<ScriptAsset>()); + REQUIRE(drawable.ensureScriptInitialized(vm.vm(), refTopFunction(L))); + + HitScriptedDrawable hit(&drawable, nullptr); + + hit.processEvent(Vec2D(1.0f, 1.0f), ListenerType::down, true, 1.5f, 0); + CHECK(readString(L, "getLastHandler") == "pointerDown"); + CHECK(readString(L, "getLastType") == "pointerDown"); + CHECK(readNumber(L, "getLastTimeStamp") == 1.5f); + + hit.processEvent(Vec2D(2.0f, 1.0f), ListenerType::move, true, 2.25f, 0); + CHECK(readString(L, "getLastHandler") == "pointerMove"); + CHECK(readString(L, "getLastType") == "pointerMove"); + CHECK(readNumber(L, "getLastTimeStamp") == 2.25f); + + hit.processEvent(Vec2D(2.0f, 1.0f), ListenerType::up, true, 3.0f, 0); + CHECK(readString(L, "getLastHandler") == "pointerUp"); + CHECK(readString(L, "getLastType") == "pointerUp"); + CHECK(readNumber(L, "getLastTimeStamp") == 3.0f); + + // An occluded target is dispatched to pointerExit whatever the incoming + // event was, and the type follows the handler. + hit.processEvent(Vec2D(2.0f, 1.0f), ListenerType::move, false, 4.0f, 0); + CHECK(readString(L, "getLastHandler") == "pointerExit"); + CHECK(readString(L, "getLastType") == "pointerExit"); + CHECK(readNumber(L, "getLastTimeStamp") == 4.0f); +}