Skip to content

Commit

Permalink
Added Default Tools Pressure setting. (mbrlabs#263)
Browse files Browse the repository at this point in the history
* Added Default Tools Pressure setting.
- Added configuration to Settings Dialog
- Circle, Line and Rectangle Tool pressure use the configured pressure instead of the constant 0.5

* Code rework, removed multiple calls of Settings.getValue for GENERAL_TOOL_PRESSURE
  • Loading branch information
tafode authored Mar 18, 2024
1 parent 0954698 commit a4c11c9
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 22 deletions.
1 change: 1 addition & 0 deletions lorien/Assets/I18n/en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ SETTINGS_BRUSH_CAPS Brush Rounding Mode
SETTINGS_BRUSH_CAPS_FLAT Flat
SETTINGS_BRUSH_CAPS_ROUND Round
SETTINGS_RESTART_NOTICE Restart required to apply the new settings
SETTINGS_TOOL_PRESSURE Default Tools Pressure

# -----------------------------------------------------------------------------
# About dialog strings
Expand Down
1 change: 1 addition & 0 deletions lorien/Config.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ const DEFAULT_UI_SCALE_MODE := Types.UIScale.AUTO
const DEFAULT_UI_SCALE := 1.0
const DEFAULT_GRID_PATTERN := Types.GridPattern.DOTS
const DEFAULT_GRID_SIZE := 25.0
const DEFAULT_TOOL_PRESSURE := 0.5

9 changes: 5 additions & 4 deletions lorien/InfiniteCanvas/Tools/CircleTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class_name CircleTool
extends CanvasTool

# -------------------------------------------------------------------------------------------------
const PRESSURE := 0.5
const STEP_IN_MOTION := 15
const STEP_STATIC := 4

Expand All @@ -27,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(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 @@ -40,10 +41,10 @@ func tool_event(event: InputEvent) -> void:
start_stroke()
_start_position_top_left = _cursor.global_position
remove_all_stroke_points()
_make_ellipse(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(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(0.5)
_tail = _add_point_at_snap_pos(tool_pressure)
else:
_tail = _add_point_at_mouse_pos(0.5)
_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(0.5)
_tail = _add_point_at_mouse_pos(0.5)
_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(0.5))
add_subdivided_line(_head, _tail, pressure_curve.interpolate(tool_pressure))
end_stroke()

# -------------------------------------------------------------------------------------------------
Expand Down
11 changes: 5 additions & 6 deletions lorien/InfiniteCanvas/Tools/RectangleTool.gd
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
class_name RectangleTool
extends CanvasTool

# -------------------------------------------------------------------------------------------------
const PRESSURE := 0.5

# -------------------------------------------------------------------------------------------------
export var pressure_curve: Curve
var _start_position_top_left: Vector2
Expand All @@ -12,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(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(PRESSURE)
_make_rectangle(tool_pressure)
elif !event.pressed && performing_stroke:
remove_all_stroke_points()
_make_rectangle(PRESSURE)
_make_rectangle(tool_pressure)
end_stroke()

# -------------------------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions lorien/Misc/Settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const RENDERING_FOREGROUND_FPS := "rendering_foreground_fps"
const RENDERING_BACKGROUND_FPS := "rendering_background_fps"
const RENDERING_BRUSH_ROUNDING := "rendering_brush_rounding"
const COLOR_PALETTE_UUID_LAST_USED := "color_palette_uuid_last_used"
const GENERAL_TOOL_PRESSURE := "general_tool_pressure"

# -------------------------------------------------------------------------------------------------
var _config_file := ConfigFile.new()
Expand Down
7 changes: 7 additions & 0 deletions lorien/UI/Dialogs/SettingsDialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ onready var _ui_scale_options: OptionButton = $MarginContainer/TabContainer/Appe
onready var _ui_scale: SpinBox = $MarginContainer/TabContainer/Appearance/VBoxContainer/UIScale/HBoxContainer/UIScale
onready var _grid_size: SpinBox = $MarginContainer/TabContainer/Appearance/VBoxContainer/GridSize/GridSize
onready var _grid_pattern: OptionButton = $MarginContainer/TabContainer/Appearance/VBoxContainer/GridPattern/GridPattern
onready var _tool_pressure: SpinBox = $MarginContainer/TabContainer/General/VBoxContainer/DefaultToolPressure/DefaultToolPressure

# -------------------------------------------------------------------------------------------------
func _ready():
Expand Down Expand Up @@ -72,6 +73,7 @@ func _set_values() -> void:
var ui_scale = Settings.get_value(Settings.APPEARANCE_UI_SCALE, Config.DEFAULT_UI_SCALE)
var grid_pattern = Settings.get_value(Settings.APPEARANCE_GRID_PATTERN, Config.DEFAULT_GRID_PATTERN)
var grid_size = Settings.get_value(Settings.APPEARANCE_GRID_SIZE, Config.DEFAULT_GRID_SIZE)
var tool_pressure = Settings.get_value(Settings.GENERAL_TOOL_PRESSURE, Config.DEFAULT_TOOL_PRESSURE)

match theme:
Types.UITheme.DARK: _theme.selected = THEME_DARK_INDEX
Expand All @@ -92,6 +94,7 @@ func _set_values() -> void:

_pressure_sensitivity.value = pressure_sensitivity
_brush_size.value = brush_size
_tool_pressure.value = tool_pressure
_canvas_color.color = canvas_color
_grid_size.value = grid_size
match grid_pattern:
Expand Down Expand Up @@ -250,3 +253,7 @@ func _on_UIScale_value_changed(value: float):
Settings.set_value(Settings.APPEARANCE_UI_SCALE, value)
emit_signal("ui_scale_changed")
popup_centered()

# -------------------------------------------------------------------------------------------------
func _on_DefaultToolPressure_value_changed(value):
Settings.set_value(Settings.GENERAL_TOOL_PRESSURE, value)
40 changes: 33 additions & 7 deletions lorien/UI/Dialogs/SettingsDialog.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,36 @@ min_value = 1.0
value = 12.0
allow_greater = true

[node name="DefaultSaveDir" type="HBoxContainer" parent="MarginContainer/TabContainer/General/VBoxContainer"]
[node name="DefaultToolPressure" type="HBoxContainer" parent="MarginContainer/TabContainer/General/VBoxContainer"]
margin_top = 66.0
margin_right = 496.0
margin_bottom = 87.0
size_flags_horizontal = 3

[node name="Label" type="Label" parent="MarginContainer/TabContainer/General/VBoxContainer/DefaultToolPressure"]
margin_top = 2.0
margin_right = 246.0
margin_bottom = 19.0
size_flags_horizontal = 3
size_flags_vertical = 6
text = "SETTINGS_TOOL_PRESSURE"

[node name="DefaultToolPressure" type="SpinBox" parent="MarginContainer/TabContainer/General/VBoxContainer/DefaultToolPressure"]
margin_left = 250.0
margin_right = 496.0
margin_bottom = 21.0
size_flags_horizontal = 3
size_flags_vertical = 3
max_value = 1.0
step = 0.05
value = 1.0

[node name="DefaultSaveDir" type="HBoxContainer" parent="MarginContainer/TabContainer/General/VBoxContainer"]
margin_top = 91.0
margin_right = 496.0
margin_bottom = 112.0
size_flags_horizontal = 3

[node name="Label" type="Label" parent="MarginContainer/TabContainer/General/VBoxContainer/DefaultSaveDir"]
margin_top = 2.0
margin_right = 246.0
Expand All @@ -134,15 +158,15 @@ placeholder_text = "e.g. C:/Users/me/Lorien"
placeholder_alpha = 0.5

[node name="HSeparator4" type="HSeparator" parent="MarginContainer/TabContainer/General/VBoxContainer"]
margin_top = 91.0
margin_top = 116.0
margin_right = 496.0
margin_bottom = 115.0
margin_bottom = 140.0
custom_constants/separation = 24

[node name="Language" type="HBoxContainer" parent="MarginContainer/TabContainer/General/VBoxContainer"]
margin_top = 119.0
margin_top = 144.0
margin_right = 496.0
margin_bottom = 144.0
margin_bottom = 169.0
size_flags_horizontal = 3

[node name="Label" type="Label" parent="MarginContainer/TabContainer/General/VBoxContainer/Language"]
Expand All @@ -161,9 +185,9 @@ size_flags_horizontal = 3
text = "English"

[node name="HSeparator" type="HSeparator" parent="MarginContainer/TabContainer/General/VBoxContainer"]
margin_top = 148.0
margin_top = 173.0
margin_right = 496.0
margin_bottom = 160.0
margin_bottom = 185.0
custom_constants/separation = 12
custom_styles/separator = SubResource( 3 )

Expand All @@ -177,6 +201,7 @@ text = "SETTINGS_RESTART_NOTICE"
align = 1

[node name="Appearance" type="Control" parent="MarginContainer/TabContainer"]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
margin_top = 27.0
Expand Down Expand Up @@ -507,6 +532,7 @@ dialog_autowrap = true

[connection signal="value_changed" from="MarginContainer/TabContainer/General/VBoxContainer/PressureSensitivity/PressureSensitivity" to="." method="_on_PressureSensitivity_value_changed"]
[connection signal="value_changed" from="MarginContainer/TabContainer/General/VBoxContainer/DefaultBrushSize/DefaultBrushSize" to="." method="_on_DefaultBrushSize_value_changed"]
[connection signal="value_changed" from="MarginContainer/TabContainer/General/VBoxContainer/DefaultToolPressure/DefaultToolPressure" to="." method="_on_DefaultToolPressure_value_changed"]
[connection signal="text_changed" from="MarginContainer/TabContainer/General/VBoxContainer/DefaultSaveDir/DefaultSaveDir" to="." method="_on_DefaultSaveDir_text_changed"]
[connection signal="item_selected" from="MarginContainer/TabContainer/General/VBoxContainer/Language/OptionButton" to="." method="_on_OptionButton_item_selected"]
[connection signal="item_selected" from="MarginContainer/TabContainer/Appearance/VBoxContainer/Theme/Theme" to="." method="_on_Theme_item_selected"]
Expand Down

0 comments on commit a4c11c9

Please sign in to comment.