1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Add <kbd>Control+Shift+Alt</kbd> as a shortcut that automatically selects a layer directly from the canvas when using tools

This commit is contained in:
Emmanouil Papadeas 2024-08-15 20:16:43 +03:00
parent 077c57c53a
commit 2e3f0a2696
3 changed files with 49 additions and 7 deletions

View file

@ -879,6 +879,11 @@ alpha_lock={
"deadzone": 0.5,
"events": []
}
change_layer_automatically={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"command_or_control_autoremap":true,"alt_pressed":false,"shift_pressed":true,"pressed":false,"keycode":0,"physical_keycode":4194328,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
[input_devices]

View file

@ -765,7 +765,7 @@ func _initialize_keychain() -> void:
&"view_splash_screen": Keychain.InputAction.new("", "Help menu", true),
&"open_docs": Keychain.InputAction.new("", "Help menu", true),
&"issue_tracker": Keychain.InputAction.new("", "Help menu", true),
&"open_logs_folder": Keychain.InputAction.new("", "Help menu", true),
&"open_editor_data_folder": Keychain.InputAction.new("", "Help menu", true),
&"changelog": Keychain.InputAction.new("", "Help menu", true),
&"about_pixelorama": Keychain.InputAction.new("", "Help menu", true),
&"zoom_in": Keychain.InputAction.new("", "Canvas"),
@ -817,6 +817,7 @@ func _initialize_keychain() -> void:
&"draw_create_line": Keychain.InputAction.new("", "Draw tools", false),
&"draw_snap_angle": Keychain.InputAction.new("", "Draw tools", false),
&"draw_color_picker": Keychain.InputAction.new("Quick color picker", "Draw tools", false),
&"change_layer_automatically": Keychain.InputAction.new("", "Tools", false),
&"shape_perfect": Keychain.InputAction.new("", "Shape tools", false),
&"shape_center": Keychain.InputAction.new("", "Shape tools", false),
&"shape_displace": Keychain.InputAction.new("", "Shape tools", false),

View file

@ -524,26 +524,34 @@ func handle_draw(position: Vector2i, event: InputEvent) -> void:
var draw_pos := position
if Global.mirror_view:
draw_pos.x = Global.current_project.size.x - position.x - 1
if event.is_action(&"activate_left_tool") or event.is_action(&"activate_right_tool"):
if Input.is_action_pressed(&"change_layer_automatically", true):
change_layer_automatically(draw_pos)
return
if event.is_action_pressed("activate_left_tool") and _active_button == -1 and not pen_inverted:
if event.is_action_pressed(&"activate_left_tool") and _active_button == -1 and not pen_inverted:
_active_button = MOUSE_BUTTON_LEFT
_slots[_active_button].tool_node.draw_start(draw_pos)
elif event.is_action_released("activate_left_tool") and _active_button == MOUSE_BUTTON_LEFT:
elif event.is_action_released(&"activate_left_tool") and _active_button == MOUSE_BUTTON_LEFT:
_slots[_active_button].tool_node.draw_end(draw_pos)
_active_button = -1
elif (
(
event.is_action_pressed("activate_right_tool")
event.is_action_pressed(&"activate_right_tool")
and _active_button == -1
and not pen_inverted
)
or (event.is_action_pressed("activate_left_tool") and _active_button == -1 and pen_inverted)
or (
event.is_action_pressed(&"activate_left_tool") and _active_button == -1 and pen_inverted
)
):
_active_button = MOUSE_BUTTON_RIGHT
_slots[_active_button].tool_node.draw_start(draw_pos)
elif (
(event.is_action_released("activate_right_tool") and _active_button == MOUSE_BUTTON_RIGHT)
or (event.is_action_released("activate_left_tool") and _active_button == MOUSE_BUTTON_RIGHT)
(event.is_action_released(&"activate_right_tool") and _active_button == MOUSE_BUTTON_RIGHT)
or (
event.is_action_released(&"activate_left_tool") and _active_button == MOUSE_BUTTON_RIGHT
)
):
_slots[_active_button].tool_node.draw_end(draw_pos)
_active_button = -1
@ -632,3 +640,31 @@ func _show_relevant_tools(layer_type: Global.LayerTypes) -> void:
func _is_tool_available(layer_type: int, t: Tool) -> bool:
return t.layer_types.is_empty() or layer_type in t.layer_types
func change_layer_automatically(pos: Vector2i) -> void:
var project := Global.current_project
pos = project.tiles.get_canon_position(pos)
if pos.x < 0 or pos.y < 0:
return
var image := Image.new()
image.copy_from(project.get_current_cel().get_image())
if pos.x > image.get_width() - 1 or pos.y > image.get_height() - 1:
return
var color := Color(0, 0, 0, 0)
var curr_frame := project.frames[project.current_frame]
for layer in project.layers.size():
var layer_index := (project.layers.size() - 1) - layer
if project.layers[layer_index].is_visible_in_hierarchy():
image = curr_frame.cels[layer_index].get_image()
color = image.get_pixelv(pos)
if not is_zero_approx(color.a):
# Change layer.
project.selected_cels.clear()
var frame_layer := [project.current_frame, layer_index]
if !project.selected_cels.has(frame_layer):
project.selected_cels.append(frame_layer)
project.change_cel(-1, layer_index)
break