Skip to content

Commit

Permalink
Added stabilizer strength setting
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrlabs committed Aug 30, 2024
1 parent baebe8b commit 47e74be
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 6 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added
- Setting to disable pressure sensitivity and always draw with a constant brush width
- Quit shortcut (CTRL+Q by default)
- Alternative way to pan the canvas by holding `SPACE` and moving the mouse
- Brush stroke stabilizer/smoothing
- Translations: Ukrainian, Arabic

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion lorien/Assets/I18n/en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ SETTINGS_APPEARANCE Appearance
SETTINGS_RENDERING Rendering
SETTINGS_KEYBINDINGS Keybindings
SETTINGS_PRESSURE_SENSITIVITY Pressure Sensitivity
SETTINGS_CONSTANT_PRESSURE Constant Pressure?
SETTINGS_CONSTANT_PRESSURE Constant Pressure
SETTINGS_STABILIZER_STRENGTH Stabilizer Strength
SETTINGS_BRUSH_SIZE Default Brush Size
SETTINGS_PROJECT_FOLDER Default save/load folder
SETTINGS_GRID_SIZE Grid Size
Expand Down
1 change: 1 addition & 0 deletions lorien/Config.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ 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
const DEFAULT_STABILIZER_STRENGTH := 0.5
14 changes: 10 additions & 4 deletions lorien/InfiniteCanvas/Tools/BrushTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,30 @@ func _process(delta: float) -> void:
if performing_stroke:
var pos := _cursor.global_position

# Smoothing
var diff := pos.distance_squared_to(_last_accepted_position)
if diff <= MOVEMENT_THRESHOLD || _current_pressure <= MIN_PRESSURE:
return

# Stabilizer smoothing
var stabilizer_strength: float = Settings.get_general_value(
Settings.GENERAL_STABILIZER_STRENGTH, Config.DEFAULT_STABILIZER_STRENGTH
)

var points := get_current_brush_stroke().points
if points.size() > 3:
var p3 := points[-3]
var p2 := points[-2]
var p1 := points[-1]
# TODO: expose the smoothing factor in the settings
pos = Utils.cubic_bezier(p3, p2, p1, pos, 0.75)
# t is in [0.5, 1.0] interval depending on stabilizer settings
var t := 0.5 + (1.0 - stabilizer_strength) * 0.5
pos = Utils.cubic_bezier(p3, p2, p1, pos, t)


# Pressure
var sensitivity: float = Settings.get_general_value(
Settings.GENERAL_PRESSURE_SENSITIVITY, Config.DEFAULT_PRESSURE_SENSITIVITY
)

# Pressure
var point_pressure := pressure_curve.sample(_current_pressure) * sensitivity
if _first_point:
point_pressure *= 1.4
Expand Down
1 change: 1 addition & 0 deletions lorien/Misc/Settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extends Node
const GENERAL_SECTION := "general"
const GENERAL_PRESSURE_SENSITIVITY := "pressure_sensitvity"
const GENERAL_CONSTANT_PRESSURE := "constant_pressure"
const GENERAL_STABILIZER_STRENGTH := "stabilizer_strength"
const GENERAL_DEFAULT_BRUSH_SIZE := "default_brush_size"
const GENERAL_DEFAULT_PROJECT_DIR := "default_project_dir"
const GENERAL_LANGUAGE := "language"
Expand Down
8 changes: 8 additions & 0 deletions lorien/UI/Dialogs/SettingsDialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ signal constant_pressure_changed(state: bool)
@onready var _constant_pressure: CheckBox = %ConstantPressure
@onready var _brush_size: SpinBox = %DefaultBrushSize
@onready var _tool_pressure: SpinBox = %DefaultToolPressure
@onready var _stabilizer_strength: SpinBox = %StabilizerStrength
@onready var _project_dir: LineEdit = %DefaultProjectDir
@onready var _language: OptionButton = %Language
@onready var _theme: OptionButton = %Theme
Expand All @@ -61,6 +62,7 @@ func _ready() -> void:

_pressure_sensitivity.value_changed.connect(_on_pressure_sensitivity_changed)
_constant_pressure.toggled.connect(_on_constant_pressure_toggled)
_stabilizer_strength.value_changed.connect(_on_stabilizer_strength_changed)
_brush_size.value_changed.connect(_on_default_brush_size_changed)
_tool_pressure.value_changed.connect(_on_default_tool_pressure_changed)
_project_dir.text_changed.connect(_on_default_project_dir_changed)
Expand Down Expand Up @@ -88,6 +90,7 @@ func _set_values() -> void:
var tool_pressure: float = Settings.get_general_value(Settings.GENERAL_TOOL_PRESSURE, Config.DEFAULT_TOOL_PRESSURE)
var pressure_sensitivity: float = Settings.get_general_value(Settings.GENERAL_PRESSURE_SENSITIVITY, Config.DEFAULT_PRESSURE_SENSITIVITY)
var constant_pressure: bool = Settings.get_general_value(Settings.GENERAL_CONSTANT_PRESSURE, Config.DEFAULT_CONSTANT_PRESSURE)
var stabilizer_strength: float = Settings.get_general_value(Settings.GENERAL_STABILIZER_STRENGTH, Config.DEFAULT_STABILIZER_STRENGTH)

var canvas_color: Color = Settings.get_appearance_value(Settings.APPEARANCE_CANVAS_COLOR, Config.DEFAULT_CANVAS_COLOR)
var ui_theme: Types.UITheme = Settings.get_appearance_value(Settings.APPEARANCE_THEME, Types.UITheme.DARK)
Expand Down Expand Up @@ -117,6 +120,7 @@ func _set_values() -> void:

_constant_pressure.button_pressed = constant_pressure
_pressure_sensitivity.value = pressure_sensitivity
_stabilizer_strength.value = stabilizer_strength
_brush_size.value = brush_size
_tool_pressure.value = tool_pressure
_canvas_color.color = canvas_color
Expand Down Expand Up @@ -295,6 +299,10 @@ func _on_ui_scale_changed(value: float) -> void:
func _on_default_tool_pressure_changed(value: float) -> void:
Settings.set_general_value(Settings.GENERAL_TOOL_PRESSURE, value)

# -------------------------------------------------------------------------------------------------
func _on_stabilizer_strength_changed(value: float) -> void:
Settings.set_general_value(Settings.GENERAL_STABILIZER_STRENGTH, value)

# -------------------------------------------------------------------------------------------------
func _on_constant_pressure_toggled(button_pressed: bool) -> void:
Settings.set_general_value(Settings.GENERAL_CONSTANT_PRESSURE, button_pressed)
Expand Down
21 changes: 20 additions & 1 deletion lorien/UI/Dialogs/SettingsDialog.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ layout_mode = 2

[node name="GeneralContainer" type="ScrollContainer" parent="VBoxContainer/MarginContainer/VBoxContainer"]
unique_name_in_owner = true
visible = false
layout_mode = 2
size_flags_vertical = 3

Expand Down Expand Up @@ -141,6 +140,25 @@ max_value = 1.0
step = 0.05
value = 1.0

[node name="StabilizerStrength" type="HBoxContainer" parent="VBoxContainer/MarginContainer/VBoxContainer/GeneralContainer/VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3

[node name="Label" type="Label" parent="VBoxContainer/MarginContainer/VBoxContainer/GeneralContainer/VBoxContainer/StabilizerStrength"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 6
text = "SETTINGS_STABILIZER_STRENGTH"

[node name="StabilizerStrength" type="SpinBox" parent="VBoxContainer/MarginContainer/VBoxContainer/GeneralContainer/VBoxContainer/StabilizerStrength"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
max_value = 1.0
step = 0.05
value = 1.0

[node name="DefaultProjectDir" type="HBoxContainer" parent="VBoxContainer/MarginContainer/VBoxContainer/GeneralContainer/VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
Expand Down Expand Up @@ -390,6 +408,7 @@ allow_greater = true

[node name="KeybindingsContainer" type="ScrollContainer" parent="VBoxContainer/MarginContainer/VBoxContainer"]
unique_name_in_owner = true
visible = false
layout_mode = 2
size_flags_vertical = 3

Expand Down

0 comments on commit 47e74be

Please sign in to comment.