From 3244dc267df131c21efef1963e440875daf4d82f Mon Sep 17 00:00:00 2001 From: Scott Harrison Date: Tue, 28 Feb 2023 16:44:10 -0600 Subject: [PATCH 1/3] Core: Touch event xDelta and yDelta Fixes --- librtt/Rtt_Event.cpp | 20 +++++++++++++++----- librtt/Rtt_Event.h | 5 +++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/librtt/Rtt_Event.cpp b/librtt/Rtt_Event.cpp index 6066ccab5..f73b404ac 100755 --- a/librtt/Rtt_Event.cpp +++ b/librtt/Rtt_Event.cpp @@ -1852,6 +1852,14 @@ HitEvent::ScreenToContent( const Display& display, Real xScreen, Real yScreen, R outYContent = Rtt_RealMul( yScreen, display.GetSy() ); outYContent -= display.GetYOriginOffset(); } +void +HitEvent::ContentToDelta(const Display& display, Real xContent, Real yContent, Real& outXDelta, Real& outYDelta ) +{ + outXDelta = Rtt_RealMul( outXDelta, display.GetSx() ); + outXDelta -= xContent; + outYDelta = Rtt_RealMul( outYDelta, display.GetSx() ); + outYDelta -= yContent; +} void HitEvent::Dispatch( lua_State *L, Runtime& runtime ) const @@ -2059,8 +2067,8 @@ TouchEvent::TouchEvent( Real x, Real y, Real xStartScreen, Real yStartScreen, Ph fXStartContent( xStartScreen ), fYStartContent( yStartScreen ), fPressure( pressure ), - fDeltaX( x - xStartScreen ), - fDeltaY( y - yStartScreen ) + fDeltaX( x ), + fDeltaY( y ) { } @@ -2090,9 +2098,10 @@ TouchEvent::Push( lua_State *L ) const lua_setfield( L, -2, kXStartKey ); lua_pushnumber( L, Rtt_RealToFloat( fYStartContent ) ); lua_setfield( L, -2, kYStartKey ); - lua_pushinteger( L, Rtt_RealToInt( fDeltaX) ); + + lua_pushnumber( L, Rtt_RealToFloat( fDeltaX ) ); lua_setfield( L, -2, kXDeltaKey ); - lua_pushinteger( L, Rtt_RealToInt( fDeltaY )); + lua_pushnumber( L, Rtt_RealToFloat( fDeltaY )); lua_setfield( L, -2, kYDeltaKey ); if ( fPressure >= kPressureThreshold ) @@ -2115,7 +2124,7 @@ void TouchEvent::Dispatch( lua_State *L, Runtime& runtime ) const { ScreenToContent( runtime.GetDisplay(), fXStartScreen, fYStartScreen, fXStartContent, fYStartContent ); - + ContentToDelta(runtime.GetDisplay(), fXStartContent, fYStartContent, fDeltaX, fDeltaY ); Super::Dispatch( L, runtime ); } @@ -2123,6 +2132,7 @@ bool TouchEvent::DispatchFocused( lua_State *L, Runtime& runtime, StageObject& stage, DisplayObject *focus ) const { ScreenToContent( runtime.GetDisplay(), fXStartScreen, fYStartScreen, fXStartContent, fYStartContent ); + ContentToDelta(runtime.GetDisplay(), fXStartContent, fYStartContent, fDeltaX, fDeltaY ); return Super::DispatchFocused( L, runtime, stage, focus ); } diff --git a/librtt/Rtt_Event.h b/librtt/Rtt_Event.h index 28b6f96de..f3aebc727 100755 --- a/librtt/Rtt_Event.h +++ b/librtt/Rtt_Event.h @@ -863,6 +863,7 @@ class HitEvent : public VirtualEvent protected: static void ScreenToContent( const Display& display, Real xScreen, Real yScreen, Real& outXContent, Real& outYContent ); + static void ContentToDelta( const Display& display, Real xContent, Real yContent, Real& outXDelta, Real& outYDelta ); bool DispatchEvent( lua_State *L, HitTestObject& parent ) const; private: @@ -945,8 +946,8 @@ class TouchEvent : public HitEvent mutable Real fXStartContent; mutable Real fYStartContent; Real fPressure; - Real fDeltaX; - Real fDeltaY; + mutable Real fDeltaX; + mutable Real fDeltaY; }; // ---------------------------------------------------------------------------- From 981c0af26b28e3f34baa0bb05db2e60bbb7da961 Mon Sep 17 00:00:00 2001 From: Scott Harrison Date: Wed, 1 Mar 2023 23:21:34 -0600 Subject: [PATCH 2/3] Simplification --- librtt/Rtt_Event.cpp | 22 +++++++--------------- librtt/Rtt_Event.h | 1 - 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/librtt/Rtt_Event.cpp b/librtt/Rtt_Event.cpp index f73b404ac..ba3229dc0 100755 --- a/librtt/Rtt_Event.cpp +++ b/librtt/Rtt_Event.cpp @@ -1802,7 +1802,6 @@ HitEvent::DispatchFocused( lua_State *L, Runtime& runtime, StageObject& stage, D Rtt_ASSERT( focus ); bool handled = false; - ScreenToContent( runtime.GetDisplay(), fXScreen, fYScreen, fXContent, fYContent ); // If we have focus, then dispatch only to that object or its ancestors @@ -1852,14 +1851,6 @@ HitEvent::ScreenToContent( const Display& display, Real xScreen, Real yScreen, R outYContent = Rtt_RealMul( yScreen, display.GetSy() ); outYContent -= display.GetYOriginOffset(); } -void -HitEvent::ContentToDelta(const Display& display, Real xContent, Real yContent, Real& outXDelta, Real& outYDelta ) -{ - outXDelta = Rtt_RealMul( outXDelta, display.GetSx() ); - outXDelta -= xContent; - outYDelta = Rtt_RealMul( outYDelta, display.GetSx() ); - outYDelta -= yContent; -} void HitEvent::Dispatch( lua_State *L, Runtime& runtime ) const @@ -1873,9 +1864,10 @@ HitEvent::Dispatch( lua_State *L, Runtime& runtime ) const StageObject& stage = * display.GetStage(); DisplayObject* focus = stage.GetFocus(); bool handled = false; + if ( focus ) { - handled = DispatchFocused( L, runtime, stage, focus ); + handled = DispatchFocused( L, runtime, stage, focus); } else { @@ -2093,15 +2085,16 @@ TouchEvent::Push( lua_State *L ) const lua_pushstring( L, StringForPhase( (Phase)fPhase ) ); lua_setfield( L, -2, kPhaseKey ); - + lua_pushnumber( L, Rtt_RealToFloat( fXStartContent ) ); lua_setfield( L, -2, kXStartKey ); lua_pushnumber( L, Rtt_RealToFloat( fYStartContent ) ); lua_setfield( L, -2, kYStartKey ); - lua_pushnumber( L, Rtt_RealToFloat( fDeltaX ) ); + + lua_pushnumber( L, X()-Rtt_RealToFloat( fXStartContent ) ); lua_setfield( L, -2, kXDeltaKey ); - lua_pushnumber( L, Rtt_RealToFloat( fDeltaY )); + lua_pushnumber( L, Y()-Rtt_RealToFloat( fYStartContent )); lua_setfield( L, -2, kYDeltaKey ); if ( fPressure >= kPressureThreshold ) @@ -2124,7 +2117,7 @@ void TouchEvent::Dispatch( lua_State *L, Runtime& runtime ) const { ScreenToContent( runtime.GetDisplay(), fXStartScreen, fYStartScreen, fXStartContent, fYStartContent ); - ContentToDelta(runtime.GetDisplay(), fXStartContent, fYStartContent, fDeltaX, fDeltaY ); + Super::Dispatch( L, runtime ); } @@ -2132,7 +2125,6 @@ bool TouchEvent::DispatchFocused( lua_State *L, Runtime& runtime, StageObject& stage, DisplayObject *focus ) const { ScreenToContent( runtime.GetDisplay(), fXStartScreen, fYStartScreen, fXStartContent, fYStartContent ); - ContentToDelta(runtime.GetDisplay(), fXStartContent, fYStartContent, fDeltaX, fDeltaY ); return Super::DispatchFocused( L, runtime, stage, focus ); } diff --git a/librtt/Rtt_Event.h b/librtt/Rtt_Event.h index f3aebc727..e5f81ac92 100755 --- a/librtt/Rtt_Event.h +++ b/librtt/Rtt_Event.h @@ -863,7 +863,6 @@ class HitEvent : public VirtualEvent protected: static void ScreenToContent( const Display& display, Real xScreen, Real yScreen, Real& outXContent, Real& outYContent ); - static void ContentToDelta( const Display& display, Real xContent, Real yContent, Real& outXDelta, Real& outYDelta ); bool DispatchEvent( lua_State *L, HitTestObject& parent ) const; private: From 7c253c6dc2c27219205d197d625b904c07725d0f Mon Sep 17 00:00:00 2001 From: Scott Harrison Date: Wed, 1 Mar 2023 23:41:29 -0600 Subject: [PATCH 3/3] More Simplification --- librtt/Rtt_Event.cpp | 11 +++-------- librtt/Rtt_Event.h | 5 +---- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/librtt/Rtt_Event.cpp b/librtt/Rtt_Event.cpp index ba3229dc0..5d48cef77 100755 --- a/librtt/Rtt_Event.cpp +++ b/librtt/Rtt_Event.cpp @@ -2044,9 +2044,7 @@ TouchEvent::TouchEvent() fYStartScreen( Rtt_REAL_0 ), fXStartContent( Rtt_REAL_0 ), fYStartContent( Rtt_REAL_0 ), - fPressure( kPressureInvalid ), - fDeltaX( Rtt_REAL_0 ), - fDeltaY( Rtt_REAL_0 ) + fPressure( kPressureInvalid ) { } @@ -2058,9 +2056,7 @@ TouchEvent::TouchEvent( Real x, Real y, Real xStartScreen, Real yStartScreen, Ph fYStartScreen( yStartScreen ), fXStartContent( xStartScreen ), fYStartContent( yStartScreen ), - fPressure( pressure ), - fDeltaX( x ), - fDeltaY( y ) + fPressure( pressure ) { } @@ -2175,8 +2171,7 @@ MultitouchEvent::Dispatch( lua_State *L, Runtime& runtime ) const if ( object ) { // Dispatch focused per-object touch events - e.DispatchFocused( L, runtime, stage, object ); - + e.DispatchFocused( L, runtime, stage, object); // Cleanup: remove per-object focus at the end of the touch (e.g. phase is "ended" or "cancelled") if ( shouldCleanup ) { diff --git a/librtt/Rtt_Event.h b/librtt/Rtt_Event.h index e5f81ac92..370754948 100755 --- a/librtt/Rtt_Event.h +++ b/librtt/Rtt_Event.h @@ -934,8 +934,6 @@ class TouchEvent : public HitEvent public: bool IsProperty( U16 mask ) const { return (fProperties & mask) != 0; } void SetProperty( U16 mask, bool value ); - Rtt_FORCE_INLINE Real DeltaX() const { return fDeltaX; }; - Rtt_FORCE_INLINE Real DeltaY() const { return fDeltaY; }; private: U16 fPhase; @@ -945,8 +943,7 @@ class TouchEvent : public HitEvent mutable Real fXStartContent; mutable Real fYStartContent; Real fPressure; - mutable Real fDeltaX; - mutable Real fDeltaY; + }; // ----------------------------------------------------------------------------