mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Internal changes in SelectionTool regarding snap to grid transformation
These changes allow users to set the left (or right) mouse buttons as mapped shortcuts to the transform snap grid action, in order to automatically snap to grid while moving a selection.
This commit is contained in:
parent
9135caabbe
commit
081ce90a08
|
@ -8,7 +8,6 @@ var _displace_origin = false # Mouse Click + Alt
|
||||||
|
|
||||||
|
|
||||||
func _input(event: InputEvent) -> void:
|
func _input(event: InputEvent) -> void:
|
||||||
._input(event)
|
|
||||||
if !_move and !_rect.has_no_area():
|
if !_move and !_rect.has_no_area():
|
||||||
if event.is_action_pressed("shape_perfect"):
|
if event.is_action_pressed("shape_perfect"):
|
||||||
_square = true
|
_square = true
|
||||||
|
|
|
@ -6,7 +6,6 @@ var _ready_to_apply := false
|
||||||
|
|
||||||
|
|
||||||
func _input(event: InputEvent) -> void:
|
func _input(event: InputEvent) -> void:
|
||||||
._input(event)
|
|
||||||
if _move:
|
if _move:
|
||||||
return
|
return
|
||||||
if event is InputEventMouseMotion:
|
if event is InputEventMouseMotion:
|
||||||
|
|
|
@ -8,7 +8,6 @@ var _displace_origin = false # Mouse Click + Alt
|
||||||
|
|
||||||
|
|
||||||
func _input(event: InputEvent) -> void:
|
func _input(event: InputEvent) -> void:
|
||||||
._input(event)
|
|
||||||
if !_move and !_rect.has_no_area():
|
if !_move and !_rect.has_no_area():
|
||||||
if event.is_action_pressed("shape_perfect"):
|
if event.is_action_pressed("shape_perfect"):
|
||||||
_square = true
|
_square = true
|
||||||
|
|
|
@ -13,7 +13,6 @@ var _ongoing_selection := false
|
||||||
var _add := false # Shift + Mouse Click
|
var _add := false # Shift + Mouse Click
|
||||||
var _subtract := false # Ctrl + Mouse Click
|
var _subtract := false # Ctrl + Mouse Click
|
||||||
var _intersect := false # Shift + Ctrl + Mouse Click
|
var _intersect := false # Shift + Ctrl + Mouse Click
|
||||||
var _snap_to_grid := false # Mouse Click + Ctrl
|
|
||||||
|
|
||||||
# Used to check if the state of content transformation has been changed
|
# Used to check if the state of content transformation has been changed
|
||||||
# while draw_move() is being called. For example, pressing Enter while still moving content
|
# while draw_move() is being called. For example, pressing Enter while still moving content
|
||||||
|
@ -31,28 +30,12 @@ func _ready() -> void:
|
||||||
set_spinbox_values()
|
set_spinbox_values()
|
||||||
|
|
||||||
|
|
||||||
func _input(event: InputEvent) -> void:
|
|
||||||
if _move:
|
|
||||||
if event.is_action_pressed("transform_snap_grid"):
|
|
||||||
_snap_to_grid = true
|
|
||||||
var grid_size := Vector2(Global.grid_width, Global.grid_height)
|
|
||||||
_offset = _offset.snapped(grid_size)
|
|
||||||
var prev_pos = selection_node.big_bounding_rectangle.position
|
|
||||||
selection_node.big_bounding_rectangle.position = prev_pos.snapped(grid_size)
|
|
||||||
selection_node.marching_ants_outline.offset += (
|
|
||||||
selection_node.big_bounding_rectangle.position
|
|
||||||
- prev_pos
|
|
||||||
)
|
|
||||||
elif event.is_action_released("transform_snap_grid"):
|
|
||||||
_snap_to_grid = false
|
|
||||||
|
|
||||||
|
|
||||||
func set_spinbox_values() -> void:
|
func set_spinbox_values() -> void:
|
||||||
var select_rect: Rect2 = selection_node.big_bounding_rectangle
|
var select_rect: Rect2 = selection_node.big_bounding_rectangle
|
||||||
xspinbox.editable = !select_rect.has_no_area()
|
xspinbox.editable = !select_rect.has_no_area()
|
||||||
yspinbox.editable = !select_rect.has_no_area()
|
yspinbox.editable = xspinbox.editable
|
||||||
wspinbox.editable = !select_rect.has_no_area()
|
wspinbox.editable = xspinbox.editable
|
||||||
hspinbox.editable = !select_rect.has_no_area()
|
hspinbox.editable = xspinbox.editable
|
||||||
|
|
||||||
xspinbox.value = select_rect.position.x
|
xspinbox.value = select_rect.position.x
|
||||||
yspinbox.value = select_rect.position.y
|
yspinbox.value = select_rect.position.y
|
||||||
|
@ -149,7 +132,15 @@ func draw_move(position: Vector2) -> void:
|
||||||
position.y = _start_pos.y
|
position.y = _start_pos.y
|
||||||
else:
|
else:
|
||||||
position.x = _start_pos.x
|
position.x = _start_pos.x
|
||||||
if _snap_to_grid:
|
if Input.is_action_pressed("transform_snap_grid"):
|
||||||
|
var grid_size := Vector2(Global.grid_width, Global.grid_height)
|
||||||
|
_offset = _offset.snapped(grid_size)
|
||||||
|
var prev_pos = selection_node.big_bounding_rectangle.position
|
||||||
|
selection_node.big_bounding_rectangle.position = prev_pos.snapped(grid_size)
|
||||||
|
selection_node.marching_ants_outline.offset += (
|
||||||
|
selection_node.big_bounding_rectangle.position
|
||||||
|
- prev_pos
|
||||||
|
)
|
||||||
position = position.snapped(Vector2(Global.grid_width, Global.grid_height))
|
position = position.snapped(Vector2(Global.grid_width, Global.grid_height))
|
||||||
position += Vector2(Global.grid_offset_x, Global.grid_offset_y)
|
position += Vector2(Global.grid_offset_x, Global.grid_offset_y)
|
||||||
|
|
||||||
|
@ -173,7 +164,6 @@ func draw_end(position: Vector2) -> void:
|
||||||
apply_selection(position)
|
apply_selection(position)
|
||||||
|
|
||||||
_move = false
|
_move = false
|
||||||
_snap_to_grid = false
|
|
||||||
cursor_text = ""
|
cursor_text = ""
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue