mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-31 07:29:49 +00:00
Snap movement to axis by holding Shift after mouse clicking
Works with the Move tool and with the Selection tools.
This commit is contained in:
parent
0a35615c24
commit
20275fc465
|
@ -1,29 +1,41 @@
|
||||||
extends BaseTool
|
extends BaseTool
|
||||||
|
|
||||||
|
|
||||||
var _starting_pos : Vector2
|
var _start_pos : Vector2
|
||||||
var _offset : Vector2
|
var _offset : Vector2
|
||||||
|
|
||||||
|
|
||||||
func draw_start(position : Vector2) -> void:
|
func draw_start(position : Vector2) -> void:
|
||||||
_starting_pos = position
|
_start_pos = position
|
||||||
_offset = position
|
_offset = position
|
||||||
if Global.current_project.has_selection:
|
if Global.current_project.has_selection:
|
||||||
Global.canvas.selection.transform_content_start()
|
Global.canvas.selection.transform_content_start()
|
||||||
|
|
||||||
|
|
||||||
func draw_move(position : Vector2) -> void:
|
func draw_move(position : Vector2) -> void:
|
||||||
|
if Tools.shift: # Snap to axis
|
||||||
|
var angle := position.angle_to_point(_start_pos)
|
||||||
|
if abs(angle) <= PI / 4 or abs(angle) >= 3*PI / 4:
|
||||||
|
position.y = _start_pos.y
|
||||||
|
else:
|
||||||
|
position.x = _start_pos.x
|
||||||
if Global.current_project.has_selection:
|
if Global.current_project.has_selection:
|
||||||
Global.canvas.selection.move_content(position - _offset)
|
Global.canvas.selection.move_content(position - _offset)
|
||||||
_offset = position
|
_offset = position
|
||||||
else:
|
else:
|
||||||
Global.canvas.move_preview_location = position - _starting_pos
|
Global.canvas.move_preview_location = position - _start_pos
|
||||||
_offset = position
|
_offset = position
|
||||||
|
|
||||||
|
|
||||||
func draw_end(position : Vector2) -> void:
|
func draw_end(position : Vector2) -> void:
|
||||||
if _starting_pos != Vector2.INF:
|
if _start_pos != Vector2.INF:
|
||||||
var pixel_diff : Vector2 = position - _starting_pos
|
if Tools.shift: # Snap to axis
|
||||||
|
var angle := position.angle_to_point(_start_pos)
|
||||||
|
if abs(angle) <= PI / 4 or abs(angle) >= 3*PI / 4:
|
||||||
|
position.y = _start_pos.y
|
||||||
|
else:
|
||||||
|
position.x = _start_pos.x
|
||||||
|
var pixel_diff : Vector2 = position - _start_pos
|
||||||
var project : Project = Global.current_project
|
var project : Project = Global.current_project
|
||||||
var image : Image = _get_draw_image()
|
var image : Image = _get_draw_image()
|
||||||
|
|
||||||
|
@ -37,4 +49,4 @@ func draw_end(position : Vector2) -> void:
|
||||||
|
|
||||||
Global.canvas.handle_redo("Draw")
|
Global.canvas.handle_redo("Draw")
|
||||||
|
|
||||||
_starting_pos = Vector2.INF
|
_start_pos = Vector2.INF
|
||||||
|
|
|
@ -2,7 +2,6 @@ extends SelectionTool
|
||||||
|
|
||||||
|
|
||||||
var _rect := Rect2(0, 0, 0, 0)
|
var _rect := Rect2(0, 0, 0, 0)
|
||||||
var _start_pos := Vector2.ZERO
|
|
||||||
|
|
||||||
var _square := false # Mouse Click + Shift
|
var _square := false # Mouse Click + Shift
|
||||||
var _expand_from_center := false # Mouse Click + Ctrl
|
var _expand_from_center := false # Mouse Click + Ctrl
|
||||||
|
@ -25,12 +24,6 @@ func _input(event : InputEvent) -> void:
|
||||||
_displace_origin = false
|
_displace_origin = false
|
||||||
|
|
||||||
|
|
||||||
func draw_start(position : Vector2) -> void:
|
|
||||||
.draw_start(position)
|
|
||||||
if !_move:
|
|
||||||
_start_pos = position
|
|
||||||
|
|
||||||
|
|
||||||
func draw_move(position : Vector2) -> void:
|
func draw_move(position : Vector2) -> void:
|
||||||
.draw_move(position)
|
.draw_move(position)
|
||||||
if !_move:
|
if !_move:
|
||||||
|
|
|
@ -3,7 +3,9 @@ class_name SelectionTool extends BaseTool
|
||||||
|
|
||||||
var _move := false
|
var _move := false
|
||||||
var _move_content := true
|
var _move_content := true
|
||||||
|
var _start_pos := Vector2.ZERO
|
||||||
var _offset := Vector2.ZERO
|
var _offset := Vector2.ZERO
|
||||||
|
|
||||||
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
|
||||||
|
@ -29,6 +31,7 @@ func draw_start(position : Vector2) -> void:
|
||||||
_intersect = Tools.shift && Tools.control
|
_intersect = Tools.shift && Tools.control
|
||||||
_add = Tools.shift && !_intersect
|
_add = Tools.shift && !_intersect
|
||||||
_subtract = Tools.control && !_intersect
|
_subtract = Tools.control && !_intersect
|
||||||
|
_start_pos = position
|
||||||
_offset = position
|
_offset = position
|
||||||
|
|
||||||
var selection_position : Vector2 = Global.canvas.selection.big_bounding_rectangle.position
|
var selection_position : Vector2 = Global.canvas.selection.big_bounding_rectangle.position
|
||||||
|
@ -53,10 +56,18 @@ func draw_start(position : Vector2) -> void:
|
||||||
|
|
||||||
func draw_move(position : Vector2) -> void:
|
func draw_move(position : Vector2) -> void:
|
||||||
if _move:
|
if _move:
|
||||||
|
if Tools.shift: # Snap to axis
|
||||||
|
var angle := position.angle_to_point(_start_pos)
|
||||||
|
if abs(angle) <= PI / 4 or abs(angle) >= 3*PI / 4:
|
||||||
|
position.y = _start_pos.y
|
||||||
|
else:
|
||||||
|
position.x = _start_pos.x
|
||||||
|
|
||||||
if _move_content:
|
if _move_content:
|
||||||
Global.canvas.selection.move_content(position - _offset)
|
Global.canvas.selection.move_content(position - _offset)
|
||||||
else:
|
else:
|
||||||
Global.canvas.selection.move_borders(position - _offset)
|
Global.canvas.selection.move_borders(position - _offset)
|
||||||
|
|
||||||
_offset = position
|
_offset = position
|
||||||
_set_cursor_text(Global.canvas.selection.big_bounding_rectangle)
|
_set_cursor_text(Global.canvas.selection.big_bounding_rectangle)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue