From aa7e62e3f1ba6e3f84ef48ce4cae7e479d80e79b Mon Sep 17 00:00:00 2001 From: Roman Silin Date: Tue, 12 Dec 2023 18:28:25 +0200 Subject: [PATCH] Added screen_x and screen_y to the Drag component --- druid/annotations.lua | 2 ++ druid/base/drag.lua | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/druid/annotations.lua b/druid/annotations.lua index 864ad7a..fc967b2 100644 --- a/druid/annotations.lua +++ b/druid/annotations.lua @@ -394,6 +394,8 @@ function druid__data_list.set_data(self, data) end ---@field touch_start_pos vector3 Touch start position ---@field x number Current touch x position ---@field y number Current touch y position +---@field screen_x number Current touch x screen position +---@field screen_y number Current touch y screen position local druid__drag = {} --- The @{Drag} constructor diff --git a/druid/base/drag.lua b/druid/base/drag.lua index db811e4..c2a5072 100644 --- a/druid/base/drag.lua +++ b/druid/base/drag.lua @@ -46,6 +46,12 @@ --- Current touch y position -- @tfield number y +--- Current touch x screen position +-- @tfield number screen_x + +--- Current touch y screen position +-- @tfield number screen_y + --- Touch start position -- @tfield vector3 touch_start_pos @@ -68,6 +74,10 @@ local function start_touch(self, touch) self.x = touch.x self.y = touch.y + + self.screen_x = touch.screen_x + self.screen_y = touch.screen_y + self._scene_scale = helper.get_scene_scale(self.node) self.on_touch_start:trigger(self:get_context(), touch) @@ -186,6 +196,8 @@ function Drag.init(self, node, on_drag_callback) self.touch_id = 0 self.x = 0 self.y = 0 + self.screen_x = 0 + self.screen_y = 0 self.is_touch = false self.is_drag = false self.touch_start_pos = vmath.vector3(0) @@ -287,6 +299,9 @@ function Drag.on_input(self, action_id, action) if touch_modified then self.x = touch_modified.x self.y = touch_modified.y + + self.screen_x = touch_modified.screen_x + self.screen_y = touch_modified.screen_y end if self.is_drag and (self.dx ~= 0 or self.dy ~= 0) then