Skip to content

Commit

Permalink
Code rework, removed multiple calls of Settings.getValue for GENERAL_…
Browse files Browse the repository at this point in the history
…TOOL_PRESSURE
  • Loading branch information
tafode committed Mar 17, 2024
1 parent e9c7d38 commit 1c49d69
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
8 changes: 5 additions & 3 deletions lorien/InfiniteCanvas/Tools/CircleTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ func tool_event(event: InputEvent) -> void:

var should_draw_circle := Input.is_key_pressed(KEY_SHIFT)

var tool_pressure : float = Settings.get_value(Settings.GENERAL_TOOL_PRESSURE)

if event is InputEventMouseMotion:
if performing_stroke:
_cursor.set_pressure(event.pressure)
remove_all_stroke_points()
_make_ellipse(Settings.get_value(Settings.GENERAL_TOOL_PRESSURE), STEP_IN_MOTION, should_draw_circle)
_make_ellipse(tool_pressure, STEP_IN_MOTION, should_draw_circle)

# Start + End
elif event is InputEventMouseButton:
Expand All @@ -39,10 +41,10 @@ func tool_event(event: InputEvent) -> void:
start_stroke()
_start_position_top_left = _cursor.global_position
remove_all_stroke_points()
_make_ellipse(Settings.get_value(Settings.GENERAL_TOOL_PRESSURE), STEP_IN_MOTION, should_draw_circle)
_make_ellipse(tool_pressure, STEP_IN_MOTION, should_draw_circle)
elif !event.pressed && performing_stroke:
remove_all_stroke_points()
_make_ellipse(Settings.get_value(Settings.GENERAL_TOOL_PRESSURE), STEP_STATIC, should_draw_circle)
_make_ellipse(tool_pressure, STEP_STATIC, should_draw_circle)
end_stroke()

# -------------------------------------------------------------------------------------------------
Expand Down
12 changes: 7 additions & 5 deletions lorien/InfiniteCanvas/Tools/LineTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ var _tail: Vector2
func tool_event(event: InputEvent) -> void:
_cursor.set_pressure(1.0)

var tool_pressure = Settings.get_value(Settings.GENERAL_TOOL_PRESSURE)

# Snap modifier
if event is InputEventKey:
if event.scancode == KEY_SHIFT:
Expand All @@ -25,20 +27,20 @@ func tool_event(event: InputEvent) -> void:
_cursor.set_pressure(event.pressure)
remove_last_stroke_point()
if _snapping_enabled:
_tail = _add_point_at_snap_pos(Settings.get_value(Settings.GENERAL_TOOL_PRESSURE))
_tail = _add_point_at_snap_pos(tool_pressure)
else:
_tail = _add_point_at_mouse_pos(Settings.get_value(Settings.GENERAL_TOOL_PRESSURE))
_tail = _add_point_at_mouse_pos(tool_pressure)

# Start + End
elif event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT:
if event.pressed:
start_stroke()
_head = _add_point_at_mouse_pos(Settings.get_value(Settings.GENERAL_TOOL_PRESSURE))
_tail = _add_point_at_mouse_pos(Settings.get_value(Settings.GENERAL_TOOL_PRESSURE))
_head = _add_point_at_mouse_pos(tool_pressure)
_tail = _add_point_at_mouse_pos(tool_pressure)
elif !event.pressed && performing_stroke:
remove_last_stroke_point()
add_subdivided_line(_head, _tail, pressure_curve.interpolate(Settings.get_value(Settings.GENERAL_TOOL_PRESSURE)))
add_subdivided_line(_head, _tail, pressure_curve.interpolate(tool_pressure))
end_stroke()

# -------------------------------------------------------------------------------------------------
Expand Down
8 changes: 5 additions & 3 deletions lorien/InfiniteCanvas/Tools/RectangleTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@ var _start_position_top_left: Vector2
func tool_event(event: InputEvent) -> void:
_cursor.set_pressure(1.0)

var tool_pressure = Settings.get_value(Settings.GENERAL_TOOL_PRESSURE)

if event is InputEventMouseMotion:
if performing_stroke:
_cursor.set_pressure(event.pressure)
remove_all_stroke_points()
_make_rectangle(Settings.get_value(Settings.GENERAL_TOOL_PRESSURE))
_make_rectangle(tool_pressure)

# Start + End
elif event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT:
if event.pressed:
start_stroke()
_start_position_top_left = _cursor.global_position
_make_rectangle(Settings.get_value(Settings.GENERAL_TOOL_PRESSURE))
_make_rectangle(tool_pressure)
elif !event.pressed && performing_stroke:
remove_all_stroke_points()
_make_rectangle(Settings.get_value(Settings.GENERAL_TOOL_PRESSURE))
_make_rectangle(tool_pressure)
end_stroke()

# -------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 1c49d69

Please sign in to comment.