Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for InputEventMouseMotion.pen_inverted #966

Merged
merged 2 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/Autoload/Tools.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var pen_pressure := 1.0
var pen_pressure_min := 0.2
var pen_pressure_max := 0.8
var pressure_buf := [0, 0] # past pressure value buffer
var pen_inverted := false
var mouse_velocity := 1.0
var mouse_velocity_min_thres := 0.2
var mouse_velocity_max_thres := 0.8
Expand Down Expand Up @@ -485,16 +486,26 @@ func handle_draw(position: Vector2i, event: InputEvent) -> void:
if Global.mirror_view:
draw_pos.x = Global.current_project.size.x - position.x - 1

if event.is_action_pressed("activate_left_tool") and _active_button == -1:
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:
_slots[_active_button].tool_node.draw_end(draw_pos)
_active_button = -1
elif event.is_action_pressed("activate_right_tool") and _active_button == -1:
elif (
(
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)
):
_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:
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)
):
_slots[_active_button].tool_node.draw_end(draw_pos)
_active_button = -1

Expand All @@ -512,6 +523,8 @@ func handle_draw(position: Vector2i, event: InputEvent) -> void:
pen_pressure = remap(pen_pressure, pen_pressure_min, pen_pressure_max, 0.0, 1.0)
pen_pressure = clampf(pen_pressure, 0.0, 1.0)

pen_inverted = event.pen_inverted

mouse_velocity = event.velocity.length() / mouse_velocity_max
mouse_velocity = remap(
mouse_velocity, mouse_velocity_min_thres, mouse_velocity_max_thres, 0.0, 1.0
Expand Down
16 changes: 13 additions & 3 deletions src/UI/ToolsPanel/ToolButtons.gd
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
extends FlowContainer

var pen_inverted := false


func _input(event: InputEvent) -> void:
if not Global.has_focus or not Global.can_draw:
return
if event is InputEventMouseMotion:
pen_inverted = event.pen_inverted
return
if not Global.has_focus or not Global.can_draw:
return
for action in ["undo", "redo"]:
if event.is_action_pressed(action):
Expand All @@ -29,6 +32,13 @@ func _input(event: InputEvent) -> void:
func _on_Tool_pressed(tool_pressed: BaseButton) -> void:
var button := -1
button = MOUSE_BUTTON_LEFT if Input.is_action_just_released("left_mouse") else button
button = MOUSE_BUTTON_RIGHT if Input.is_action_just_released("right_mouse") else button
button = (
MOUSE_BUTTON_RIGHT
if (
Input.is_action_just_released("right_mouse")
or (pen_inverted and Input.is_action_just_released("left_mouse"))
)
else button
)
if button != -1:
Tools.assign_tool(tool_pressed.name, button)