2022-01-03 23:53:28 +01:00
tool
2021-11-21 11:46:04 +01:00
extends SummerDayTool
class_name SummerDayFreeTransformCanvasTool
2021-11-21 13:44:46 +01:00
var touch_dict = { }
var initial_touches
var current_touches
var initial_transform : Transform2D
2021-11-21 11:46:04 +01:00
func _init ( ) :
priority = 1
2021-12-21 21:40:04 +01:00
func _handle_global_input ( event : InputEvent ) :
pass
2022-01-02 16:42:55 +01:00
func _check_for_use ( event : InputEvent ) :
2021-11-21 13:44:46 +01:00
if event is InputEventScreenTouch :
if event . pressed :
touch_dict [ event . index ] = event . position
else :
touch_dict . erase ( event . index )
if touch_dict . size ( ) == 2 :
2022-01-02 16:42:55 +01:00
initial_transform = SummerDay . canvas_state . canvas_transform
2021-11-21 13:44:46 +01:00
var keys = touch_dict . keys ( )
initial_touches = [ touch_dict [ keys [ 0 ] ] , touch_dict [ keys [ 1 ] ] ]
2021-11-21 11:46:04 +01:00
if event is InputEventScreenDrag :
2021-11-21 13:44:46 +01:00
touch_dict [ event . index ] = event . position
if touch_dict . size ( ) == 2 :
var keys = touch_dict . keys ( )
current_touches = [ touch_dict [ keys [ 0 ] ] , touch_dict [ keys [ 1 ] ] ]
return true
return false
2021-11-21 11:46:04 +01:00
2022-01-02 16:42:55 +01:00
func _run ( event : InputEvent ) :
2021-11-25 18:26:56 +01:00
var init_set = [
initial_touches [ 0 ] ,
initial_touches [ 1 ] ,
( initial_touches [ 1 ] - initial_touches [ 0 ] ) . tangent ( ) + initial_touches [ 1 ] ,
( initial_touches [ 1 ] - initial_touches [ 0 ] ) . tangent ( ) + initial_touches [ 0 ] ,
]
var curr_set = [
current_touches [ 0 ] ,
current_touches [ 1 ] ,
( current_touches [ 1 ] - current_touches [ 0 ] ) . tangent ( ) + current_touches [ 1 ] ,
( current_touches [ 1 ] - current_touches [ 0 ] ) . tangent ( ) + current_touches [ 0 ] ,
]
var basis = SummerDayMathHelper . basis_from_to_points (
init_set [ 0 ] , init_set [ 1 ] , init_set [ 2 ] , init_set [ 3 ] ,
curr_set [ 0 ] , curr_set [ 1 ] , curr_set [ 2 ] , curr_set [ 3 ]
)
var transform = Transform2D (
Vector2 ( basis . x . x , basis . x . y ) ,
Vector2 ( basis . y . x , basis . y . y ) ,
Vector2 ( basis . z . x , basis . z . y )
) * initial_transform
2022-01-02 16:42:55 +01:00
SummerDay . canvas_state . canvas_transform = transform