mirror of
https://github.com/Insality/druid
synced 2025-09-27 18:12:21 +02:00
Scroll refactoring progress
This commit is contained in:
@@ -22,11 +22,11 @@ local function start_touch(self, touch)
|
||||
self.is_touch = true
|
||||
self.is_drag = false
|
||||
|
||||
self.touch_start_pos.x = touch.screen_x
|
||||
self.touch_start_pos.y = touch.screen_y
|
||||
self.touch_start_pos.x = touch.x
|
||||
self.touch_start_pos.y = touch.y
|
||||
|
||||
self.screen_x = touch.screen_x
|
||||
self.screen_y = touch.screen_y
|
||||
self.x = touch.x
|
||||
self.y = touch.y
|
||||
|
||||
self.on_touch_start:trigger(self:get_context())
|
||||
end
|
||||
@@ -40,22 +40,24 @@ local function end_touch(self)
|
||||
self.is_drag = false
|
||||
self.is_touch = false
|
||||
self.on_touch_end:trigger(self:get_context())
|
||||
self:reset_input_priority()
|
||||
self.touch_id = 0
|
||||
end
|
||||
|
||||
|
||||
local function process_touch(self, touch)
|
||||
if not self.can_x then
|
||||
self.touch_start_pos.x = touch.screen_x
|
||||
self.touch_start_pos.x = touch.x
|
||||
end
|
||||
if not self.can_y then
|
||||
self.touch_start_pos.y = touch.screen_y
|
||||
self.touch_start_pos.y = touch.y
|
||||
end
|
||||
|
||||
local distance = helper.distance(touch.screen_x, touch.screen_y, self.touch_start_pos.x, self.touch_start_pos.y)
|
||||
local distance = helper.distance(touch.x, touch.y, self.touch_start_pos.x, self.touch_start_pos.y)
|
||||
if not self.is_drag and distance >= self.drag_deadzone then
|
||||
self.is_drag = true
|
||||
self.on_drag_start:trigger(self:get_context())
|
||||
self:increase_input_priority()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -93,8 +95,8 @@ local function on_touch_release(self, action_id, action)
|
||||
end
|
||||
|
||||
if next_touch then
|
||||
self.screen_x = next_touch.screen_x
|
||||
self.screen_y = next_touch.screen_y
|
||||
self.x = next_touch.x
|
||||
self.y = next_touch.y
|
||||
self.touch_id = next_touch.id
|
||||
else
|
||||
end_touch(self)
|
||||
@@ -116,8 +118,8 @@ function M.init(self, node, on_drag_callback)
|
||||
self.dx = 0
|
||||
self.dy = 0
|
||||
self.touch_id = 0
|
||||
self.screen_x = 0
|
||||
self.screen_y = 0
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
self.is_touch = false
|
||||
self.is_drag = false
|
||||
self.touch_start_pos = vmath.vector3(0)
|
||||
@@ -185,13 +187,13 @@ function M.on_input(self, action_id, action)
|
||||
|
||||
local touch_modified = find_touch(action_id, action, self.touch_id)
|
||||
if touch_modified and self.is_drag then
|
||||
self.dx = touch_modified.screen_x - self.screen_x
|
||||
self.dy = touch_modified.screen_y - self.screen_y
|
||||
self.dx = touch_modified.x - self.x
|
||||
self.dy = touch_modified.y - self.y
|
||||
end
|
||||
|
||||
if touch_modified then
|
||||
self.screen_x = touch_modified.screen_x
|
||||
self.screen_y = touch_modified.screen_y
|
||||
self.x = touch_modified.x
|
||||
self.y = touch_modified.y
|
||||
end
|
||||
|
||||
if self.is_drag then
|
||||
|
@@ -22,7 +22,7 @@ local function on_scroll_drag(self, dx, dy)
|
||||
dy = -dy
|
||||
local t = self.target_pos
|
||||
local b = self.available_soft_pos
|
||||
local soft = 100
|
||||
local extra_size = self.style.EXTRA_STRECH_SIZE
|
||||
|
||||
-- Handle soft zones
|
||||
-- Percent - multiplier for delta. Less if outside of scroll zone
|
||||
@@ -30,10 +30,10 @@ local function on_scroll_drag(self, dx, dy)
|
||||
local y_perc = 1
|
||||
|
||||
if t.x < b.x and dx < 0 then
|
||||
x_perc = (soft - (b.x - t.x)) / soft
|
||||
x_perc = (-extra_size.x - (b.x - t.x)) / -extra_size.x
|
||||
end
|
||||
if t.x > b.z and dx > 0 then
|
||||
x_perc = (soft - (t.x - b.z)) / soft
|
||||
x_perc = (extra_size.z - (t.x - b.z)) / extra_size.z
|
||||
end
|
||||
-- If disabled scroll by x
|
||||
if not self.can_x then
|
||||
@@ -41,24 +41,16 @@ local function on_scroll_drag(self, dx, dy)
|
||||
end
|
||||
|
||||
if t.y > b.y and dy < 0 then
|
||||
y_perc = (soft - (t.y - b.y)) / soft
|
||||
y_perc = (extra_size.y - (t.y - b.y)) / extra_size.y
|
||||
end
|
||||
if t.y < b.w and dy > 0 then
|
||||
y_perc = (soft - (b.w - t.y)) / soft
|
||||
y_perc = (-extra_size.w - (b.w - t.y)) / -extra_size.w
|
||||
end
|
||||
-- If disabled scroll by y
|
||||
if not self.can_y then
|
||||
y_perc = 0
|
||||
end
|
||||
|
||||
-- Reset inert if outside of scroll zone
|
||||
if x_perc ~= 1 then
|
||||
self.inertion.x = 0
|
||||
end
|
||||
if y_perc ~= 1 then
|
||||
self.inertion.y = 0
|
||||
end
|
||||
|
||||
t.x = t.x + dx * x_perc
|
||||
t.y = t.y - dy * y_perc
|
||||
end
|
||||
@@ -79,21 +71,8 @@ local function update_hand_scroll(self, dt)
|
||||
local dx = self.target_pos.x - self.current_pos.x
|
||||
local dy = self.target_pos.y - self.current_pos.y
|
||||
|
||||
if helper.sign(dx) ~= helper.sign(self.inertion.x) then
|
||||
self.inertion.x = 0
|
||||
end
|
||||
if helper.sign(dy) ~= helper.sign(self.inertion.y) then
|
||||
self.inertion.y = 0
|
||||
end
|
||||
|
||||
self.inertion.x = self.inertion.x + dx
|
||||
self.inertion.y = self.inertion.y + dy
|
||||
|
||||
self.inertion.x = math.abs(self.inertion.x) * helper.sign(dx)
|
||||
self.inertion.y = math.abs(self.inertion.y) * helper.sign(dy)
|
||||
|
||||
self.inertion.x = self.inertion.x * self.style.FRICT_HOLD
|
||||
self.inertion.y = self.inertion.y * self.style.FRICT_HOLD
|
||||
self.inertion.x = (self.inertion.x + dx) * self.style.FRICT_HOLD
|
||||
self.inertion.y = (self.inertion.y + dy) * self.style.FRICT_HOLD
|
||||
|
||||
set_pos(self, self.target_pos)
|
||||
end
|
||||
@@ -119,8 +98,10 @@ end
|
||||
|
||||
|
||||
local function check_threshold(self)
|
||||
if vmath.length(self.inertion) < self.style.INERT_THRESHOLD then
|
||||
if math.abs(self.inertion.x) < self.style.INERT_THRESHOLD then
|
||||
self.inertion.x = 0
|
||||
end
|
||||
if math.abs(self.inertion.y) < self.style.INERT_THRESHOLD then
|
||||
self.inertion.y = 0
|
||||
end
|
||||
end
|
||||
@@ -221,7 +202,7 @@ function M.init(self, view_zone, content_zone)
|
||||
|
||||
self.current_pos = gui.get_position(self.content_node)
|
||||
self.target_pos = vmath.vector3(self.current_pos)
|
||||
self.inertion = vmath.vector3()
|
||||
self.inertion = vmath.vector3(0)
|
||||
|
||||
self.drag = self.druid:new_drag(view_zone, on_scroll_drag)
|
||||
self.drag.on_touch_start:subscribe(on_touch_start)
|
||||
|
Reference in New Issue
Block a user