Added screen_x and screen_y to the Drag component

This commit is contained in:
Roman Silin 2023-12-12 18:28:25 +02:00
parent bdd9efb892
commit aa7e62e3f1
2 changed files with 17 additions and 0 deletions

View File

@ -394,6 +394,8 @@ function druid__data_list.set_data(self, data) end
---@field touch_start_pos vector3 Touch start position ---@field touch_start_pos vector3 Touch start position
---@field x number Current touch x position ---@field x number Current touch x position
---@field y number Current touch y 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 = {} local druid__drag = {}
--- The @{Drag} constructor --- The @{Drag} constructor

View File

@ -46,6 +46,12 @@
--- Current touch y position --- Current touch y position
-- @tfield number y -- @tfield number y
--- Current touch x screen position
-- @tfield number screen_x
--- Current touch y screen position
-- @tfield number screen_y
--- Touch start position --- Touch start position
-- @tfield vector3 touch_start_pos -- @tfield vector3 touch_start_pos
@ -68,6 +74,10 @@ local function start_touch(self, touch)
self.x = touch.x self.x = touch.x
self.y = touch.y 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._scene_scale = helper.get_scene_scale(self.node)
self.on_touch_start:trigger(self:get_context(), touch) 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.touch_id = 0
self.x = 0 self.x = 0
self.y = 0 self.y = 0
self.screen_x = 0
self.screen_y = 0
self.is_touch = false self.is_touch = false
self.is_drag = false self.is_drag = false
self.touch_start_pos = vmath.vector3(0) self.touch_start_pos = vmath.vector3(0)
@ -287,6 +299,9 @@ function Drag.on_input(self, action_id, action)
if touch_modified then if touch_modified then
self.x = touch_modified.x self.x = touch_modified.x
self.y = touch_modified.y self.y = touch_modified.y
self.screen_x = touch_modified.screen_x
self.screen_y = touch_modified.screen_y
end end
if self.is_drag and (self.dx ~= 0 or self.dy ~= 0) then if self.is_drag and (self.dx ~= 0 or self.dy ~= 0) then