1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-20 12:33:14 +00:00

Implement moving selections with arrow keys

Moves selection with contents by default.
Control + arrow keys = Moves & snaps selection to grid.
Alt + arrow keys = Moves the selection itself without the contents.
This commit is contained in:
Manolis Papadeas 2021-05-07 04:33:28 +03:00
parent 0c1f839d34
commit 356ddc0038
4 changed files with 77 additions and 0 deletions

View file

@ -26,6 +26,8 @@ func _input(event : InputEvent) -> void:
func draw_move(position : Vector2) -> void:
if selection_node.arrow_key_move:
return
.draw_move(position)
if !_move:
if _displace_origin:
@ -36,6 +38,8 @@ func draw_move(position : Vector2) -> void:
func draw_end(position : Vector2) -> void:
if selection_node.arrow_key_move:
return
.draw_end(position)
_rect = Rect2(0, 0, 0, 0)
_square = false

View file

@ -42,6 +42,8 @@ func _input(event : InputEvent) -> void:
func draw_start(position : Vector2) -> void:
if selection_node.arrow_key_move:
return
var project : Project = Global.current_project
undo_data = selection_node._get_undo_data(false)
_intersect = Tools.shift && Tools.control
@ -77,6 +79,8 @@ func draw_start(position : Vector2) -> void:
func draw_move(position : Vector2) -> void:
if selection_node.arrow_key_move:
return
if _move:
if Tools.shift: # Snap to axis
var angle := position.angle_to_point(_start_pos)
@ -97,6 +101,8 @@ func draw_move(position : Vector2) -> void:
func draw_end(_position : Vector2) -> void:
if selection_node.arrow_key_move:
return
if _move:
selection_node.move_borders_end(!_move_content)
else:

View file

@ -50,6 +50,9 @@ const key_move_action_names := ["ui_up", "ui_down", "ui_left", "ui_right"]
# Check if an event is a ui_up/down/left/right event-press :)
func is_action_direction_pressed(event : InputEvent, allow_echo: bool = true) -> bool:
for slot in Tools._slots.values():
if slot.tool_node is SelectionTool:
return false
for action in key_move_action_names:
if event.is_action_pressed(action, allow_echo):
return true
@ -58,6 +61,9 @@ func is_action_direction_pressed(event : InputEvent, allow_echo: bool = true) ->
# Check if an event is a ui_up/down/left/right event release nya
func is_action_direction_released(event: InputEvent) -> bool:
for slot in Tools._slots.values():
if slot.tool_node is SelectionTool:
return false
for action in key_move_action_names:
if event.is_action_released(action):
return true

View file

@ -37,9 +37,11 @@ class Gizmo:
enum SelectionOperation {ADD, SUBTRACT, INTERSECT}
const KEY_MOVE_ACTION_NAMES := ["ui_up", "ui_down", "ui_left", "ui_right"]
var clipboard := Clipboard.new()
var is_moving_content := false
var arrow_key_move := false
var is_pasting := false
var big_bounding_rectangle := Rect2() setget _big_bounding_rectangle_changed
@ -82,6 +84,9 @@ func _input(event : InputEvent) -> void:
transform_content_confirm()
elif Input.is_action_just_pressed("escape"):
transform_content_cancel()
move_with_arrow_keys(event)
elif event is InputEventMouse:
var gizmo : Gizmo
if big_bounding_rectangle.size != Vector2.ZERO:
@ -135,6 +140,60 @@ func _input(event : InputEvent) -> void:
gizmo_rotate()
func move_with_arrow_keys(event : InputEvent) -> void:
var selection_tool_selected := false
for slot in Tools._slots.values():
if slot.tool_node is SelectionTool:
selection_tool_selected = true
break
if !selection_tool_selected:
return
if Global.current_project.has_selection:
if is_action_direction_pressed(event) and !arrow_key_move:
arrow_key_move = true
if Input.is_key_pressed(KEY_ALT):
transform_content_confirm()
move_borders_start()
is_moving_content = false
else:
transform_content_start()
is_moving_content = true
if is_action_direction_released(event) and arrow_key_move:
arrow_key_move = false
move_borders_end(!is_moving_content)
if is_action_direction(event) and arrow_key_move:
var step := Vector2.ONE
if Input.is_key_pressed(KEY_CONTROL):
step = Vector2(Global.grid_width, Global.grid_height)
move_content(Vector2(int(event.is_action("ui_right")) - int(event.is_action("ui_left")), int(event.is_action("ui_down")) - int(event.is_action("ui_up"))) * step)
# Check if an event is a ui_up/down/left/right event-press
func is_action_direction_pressed(event : InputEvent) -> bool:
for action in KEY_MOVE_ACTION_NAMES:
if event.is_action_pressed(action):
return true
return false
# Check if an event is a ui_up/down/left/right event release
func is_action_direction(event: InputEvent) -> bool:
for action in KEY_MOVE_ACTION_NAMES:
if event.is_action(action):
return true
return false
# Check if an event is a ui_up/down/left/right event release
func is_action_direction_released(event: InputEvent) -> bool:
for action in KEY_MOVE_ACTION_NAMES:
if event.is_action_released(action):
return true
return false
func _draw() -> void:
var _position := position
var _scale := scale
@ -302,6 +361,8 @@ func move_borders_start() -> void:
func move_borders(move : Vector2) -> void:
if move == Vector2.ZERO:
return
marching_ants_outline.offset += move
self.big_bounding_rectangle.position += move
update()