Merge pull request #252 from astrochili/drag_screen_x_y

Added the screen position to the Drag component
This commit is contained in:
Maksim Tuprikov 2023-12-12 19:40:17 +02:00 committed by GitHub
commit 9b69b65add
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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