mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2026-11-03 16:03:52 +00:00
Initial support for touch callbacks, GuiState now emulates a mouse left click on tap
This commit is contained in:
@@ -53,6 +53,18 @@ module CyberarmEngine
|
|||||||
def gamepad_disconnected(index)
|
def gamepad_disconnected(index)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def touch_began(touch)
|
||||||
|
end
|
||||||
|
|
||||||
|
def touch_moved(touch)
|
||||||
|
end
|
||||||
|
|
||||||
|
def touch_ended(touch)
|
||||||
|
end
|
||||||
|
|
||||||
|
def touch_cancelled(touch)
|
||||||
|
end
|
||||||
|
|
||||||
def gain_focus
|
def gain_focus
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ module CyberarmEngine
|
|||||||
@pending_element_recalculate_requests = []
|
@pending_element_recalculate_requests = []
|
||||||
@hit_elements = []
|
@hit_elements = []
|
||||||
|
|
||||||
|
@touch_down_position = {}
|
||||||
|
@min_touch_drag_distance = 50
|
||||||
|
|
||||||
@needs_repaint = false
|
@needs_repaint = false
|
||||||
|
|
||||||
@menu = nil
|
@menu = nil
|
||||||
@@ -227,6 +230,31 @@ module CyberarmEngine
|
|||||||
@page&.update
|
@page&.update
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def touch_began(touch)
|
||||||
|
@touch_down_position[touch.id] = touch
|
||||||
|
end
|
||||||
|
|
||||||
|
def touch_moved(touch)
|
||||||
|
# TODO: Support scrolling containers and dragging elements
|
||||||
|
end
|
||||||
|
|
||||||
|
def touch_ended(touch)
|
||||||
|
touch_down_pos = @touch_down_position[touch.id]
|
||||||
|
distance = Vector.new(touch_down_pos.x, touch_down_pos.y).distance(Vector.new(touch.x, touch.y))
|
||||||
|
|
||||||
|
# emulate mouse click
|
||||||
|
if distance < @min_touch_drag_distance
|
||||||
|
button_down(Gosu::MS_LEFT)
|
||||||
|
button_up(Gosu::MS_LEFT)
|
||||||
|
end
|
||||||
|
|
||||||
|
@touch_down_position.delete(touch.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def touch_cancelled(touch)
|
||||||
|
@touch_down_position.delete(touch.id)
|
||||||
|
end
|
||||||
|
|
||||||
def button_down(id)
|
def button_down(id)
|
||||||
super
|
super
|
||||||
|
|
||||||
|
|||||||
@@ -143,6 +143,22 @@ module CyberarmEngine
|
|||||||
current_state&.gamepad_disconnected(index)
|
current_state&.gamepad_disconnected(index)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def touch_began(touch)
|
||||||
|
current_state&.touch_began(touch)
|
||||||
|
end
|
||||||
|
|
||||||
|
def touch_moved(touch)
|
||||||
|
current_state&.touch_moved(touch)
|
||||||
|
end
|
||||||
|
|
||||||
|
def touch_ended(touch)
|
||||||
|
current_state&.touch_ended(touch)
|
||||||
|
end
|
||||||
|
|
||||||
|
def touch_cancelled(touch)
|
||||||
|
current_state&.touch_cancelled(touch)
|
||||||
|
end
|
||||||
|
|
||||||
def gain_focus
|
def gain_focus
|
||||||
@has_focus = true
|
@has_focus = true
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user