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

Add support for InputEventMouseMotion.pen_inverted (#966)

* Add support for InputEventMouseMotion.pen_inverted

This commit adds support for stylus erasers, both for drawing and
choosing tools.  This may be supported on some styli by inverting them
as the property name suggests, or by holding a button while drawing with
the nib.

* Formatting fixes
This commit is contained in:
Clara Hobbs 2023-12-24 19:50:10 -05:00 committed by GitHub
parent dffaf1d504
commit 3d2d9e47a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 6 deletions

View file

@ -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
@ -483,16 +484,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
@ -510,6 +521,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

View file

@ -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):
@ -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)