Skip to content

Commit

Permalink
Constant Pressure (#279)
Browse files Browse the repository at this point in the history
* feat: added constant pressure

* fix: saved setting not being applied to checkbox on start up
  • Loading branch information
Braayy authored Aug 15, 2024
1 parent 721cc51 commit 2281b5b
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 40 deletions.
1 change: 1 addition & 0 deletions lorien/Assets/I18n/en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ SETTINGS_APPEARANCE Appearance
SETTINGS_RENDERING Rendering
SETTINGS_KEYBINDINGS Keybindings
SETTINGS_PRESSURE_SENSITIVITY Pressure Sensitivity
SETTINGS_CONSTANT_PRESSURE Constant Pressure?
SETTINGS_BRUSH_SIZE Default Brush Size
SETTINGS_PROJECT_FOLDER Default Project Folder
SETTINGS_GRID_SIZE Grid Size
Expand Down
1 change: 1 addition & 0 deletions lorien/Assets/I18n/pt-BR.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ SETTINGS_APPEARANCE Aparência
SETTINGS_RENDERING Renderização
SETTINGS_KEYBINDINGS Teclas de Atalho
SETTINGS_PRESSURE_SENSITIVITY Sensibilidade à Pressão
SETTINGS_CONSTANT_PRESSURE Pressão Constante?
SETTINGS_BRUSH_SIZE Tamanho Padrão do Pincel
SETTINGS_CANVAS_COLOR Cor da Área de Desenho
SETTINGS_PROJECT_FOLDER Pasta Padrão do Projeto
Expand Down
1 change: 1 addition & 0 deletions lorien/Config.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const DEFAULT_CANVAS_COLOR := Color("202124")
const DEFAULT_BRUSH_COLOR := Color.white
const DEFAULT_BRUSH_SIZE := 12
const DEFAULT_PRESSURE_SENSITIVITY := 1.5
const DEFAULT_CONSTANT_PRESSURE := false
const DEFAULT_AA_MODE := Types.AAMode.TEXTURE_FILL
const DEFAULT_SELECTION_COLOR := Color("#2a967c")
const DEFAULT_FOREGROUND_FPS := 144
Expand Down
16 changes: 16 additions & 0 deletions lorien/InfiniteCanvas/InfiniteCanvas.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ onready var _camera: Camera2D = $Viewport/Camera2D
onready var _viewport: Viewport = $Viewport
onready var _grid: InfiniteCanvasGrid = $Viewport/Grid

onready var _constant_pressure_curve := load("res://InfiniteCanvas/constant_pressure_curve.tres")
onready var _default_pressure_curve := load("res://InfiniteCanvas/default_pressure_curve.tres")

var info := Types.CanvasInfo.new()
var _is_enabled := false
var _background_color: Color
Expand All @@ -41,6 +44,12 @@ func _ready():
_active_tool._on_brush_size_changed(_brush_size)
_active_tool.enabled = false

var constant_pressure = Settings.get_value(Settings.GENERAL_CONSTANT_PRESSURE, Config.DEFAULT_CONSTANT_PRESSURE)
if constant_pressure:
_brush_tool.pressure_curve = _constant_pressure_curve
else:
_brush_tool.pressure_curve = _default_pressure_curve

get_tree().get_root().connect("size_changed", self, "_on_window_resized")

for child in $Viewport.get_children():
Expand Down Expand Up @@ -381,3 +390,10 @@ func set_canvas_scale(scale: float) -> void:
# -------------------------------------------------------------------------------------------------
func get_canvas_scale() -> float:
return _scale


func _on_SettingsDialog_constant_pressure_changed(state: bool):
if state:
_brush_tool.pressure_curve = _constant_pressure_curve
else:
_brush_tool.pressure_curve = _default_pressure_curve
2 changes: 1 addition & 1 deletion lorien/InfiniteCanvas/InfiniteCanvas.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[ext_resource path="res://InfiniteCanvas/InfiniteCanvas.gd" type="Script" id=1]
[ext_resource path="res://InfiniteCanvas/PanZoomCamera.gd" type="Script" id=2]
[ext_resource path="res://InfiniteCanvas/pressure_curve.tres" type="Curve" id=3]
[ext_resource path="res://InfiniteCanvas/default_pressure_curve.tres" type="Curve" id=3]
[ext_resource path="res://InfiniteCanvas/Cursor/BrushCursor/BrushCursor.tscn" type="PackedScene" id=4]
[ext_resource path="res://InfiniteCanvas/Tools/BrushTool.gd" type="Script" id=5]
[ext_resource path="res://InfiniteCanvas/Tools/LineTool.gd" type="Script" id=6]
Expand Down
4 changes: 4 additions & 0 deletions lorien/InfiniteCanvas/constant_pressure_curve.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[gd_resource type="Curve" format=2]

[resource]
_data = [ Vector2( 0, 1 ), 0.0, 0.210526, 0, 0 ]
File renamed without changes.
11 changes: 7 additions & 4 deletions lorien/Main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ margin_bottom = 202.0
custom_styles/panel = SubResource( 1 )

[node name="ColorPicker" type="ColorPicker" parent="BackgroundColorPickerPopup/PanelContainer"]
margin_left = 84.0
margin_top = 84.0
margin_right = 393.0
margin_bottom = 488.0
margin_left = 100.0
margin_top = 100.0
margin_right = 409.0
margin_bottom = 504.0
edit_alpha = false
presets_enabled = false
presets_visible = false
Expand Down Expand Up @@ -131,6 +131,7 @@ margin_right = 385.0
margin_bottom = 216.5
theme = ExtResource( 8 )
popup_exclusive = true
window_title = "Salvar um Arquivo"
access = 2
filters = PoolStringArray( "*.lorien" )
__meta__ = {
Expand Down Expand Up @@ -237,6 +238,7 @@ margin_right = 68.5
margin_bottom = 35.0
theme = ExtResource( 8 )
popup_exclusive = true
window_title = "Alerta!"
dialog_text = "Generic message. "
__meta__ = {
"_edit_lock_": true
Expand All @@ -249,3 +251,4 @@ __meta__ = {
[connection signal="new_palette_created" from="NewPaletteDialog" to="." method="_on_NewPaletteDialog_new_palette_created"]
[connection signal="palette_deleted" from="DeletePaletteDialog" to="." method="_on_DeletePaletteDialog_palette_deleted"]
[connection signal="palette_changed" from="EditPaletteDialog" to="." method="_on_EditPaletteDialog_palette_changed"]
[connection signal="constant_pressure_changed" from="SettingsDialog" to="InfiniteCanvas" method="_on_SettingsDialog_constant_pressure_changed"]
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 DEFAULT_SECTION := "settings"
const SHORTCUTS_SECTION := "shortcuts"
const GENERAL_PRESSURE_SENSITIVITY := "general_pressure_sensitvity"
const GENERAL_CONSTANT_PRESSURE := "general_constant_pressure"
const GENERAL_DEFAULT_BRUSH_SIZE := "general_default_brush_size"
const GENERAL_DEFAULT_PROJECT_DIR := "general_default_project_dir"
const GENERAL_LANGUAGE := "general_language"
Expand Down
11 changes: 11 additions & 0 deletions lorien/UI/Dialogs/SettingsDialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ signal ui_scale_changed
signal canvas_color_changed(color)
signal grid_size_changed(size)
signal grid_pattern_changed(pattern)
signal constant_pressure_changed(state)

# -------------------------------------------------------------------------------------------------
onready var _tab_container: TabContainer = $MarginContainer/TabContainer
onready var _tab_general: Control = $MarginContainer/TabContainer/General
onready var _tab_appearance: Control = $MarginContainer/TabContainer/Appearance
onready var _tab_rendering: Control = $MarginContainer/TabContainer/Rendering
onready var _pressure_sensitivity: SpinBox = $MarginContainer/TabContainer/General/VBoxContainer/PressureSensitivity/PressureSensitivity
onready var _constant_pressure: CheckBox = $MarginContainer/TabContainer/General/VBoxContainer/ConstantPressure/ConstantPressure
onready var _brush_size: SpinBox = $MarginContainer/TabContainer/General/VBoxContainer/DefaultBrushSize/DefaultBrushSize
onready var _canvas_color: ColorPickerButton = $MarginContainer/TabContainer/Appearance/VBoxContainer/CanvasColor/CanvasColor
onready var _project_dir: LineEdit = $MarginContainer/TabContainer/General/VBoxContainer/DefaultSaveDir/DefaultSaveDir
Expand Down Expand Up @@ -75,6 +77,9 @@ func _set_values() -> void:
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)

var constant_pressure = Settings.get_value(Settings.GENERAL_CONSTANT_PRESSURE, Config.DEFAULT_CONSTANT_PRESSURE)
_constant_pressure.pressed = constant_pressure

match theme:
Types.UITheme.DARK: _theme.selected = THEME_DARK_INDEX
Types.UITheme.LIGHT: _theme.selected = THEME_LIGHT_INDEX
Expand Down Expand Up @@ -257,3 +262,9 @@ func _on_UIScale_value_changed(value: float):
# -------------------------------------------------------------------------------------------------
func _on_DefaultToolPressure_value_changed(value):
Settings.set_value(Settings.GENERAL_TOOL_PRESSURE, value)


func _on_ConstantPressure_toggled(button_pressed: bool):
Settings.set_value(Settings.GENERAL_CONSTANT_PRESSURE, button_pressed)
emit_signal("constant_pressure_changed", button_pressed)
pass # Replace with function body.
47 changes: 33 additions & 14 deletions lorien/UI/Dialogs/SettingsDialog.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
[sub_resource type="StyleBoxEmpty" id=2]

[node name="SettingsDialog" type="WindowDialog"]
visible = true
margin_right = 520.0
margin_bottom = 250.0
rect_min_size = Vector2( 520, 270 )
Expand Down Expand Up @@ -43,7 +42,6 @@ __meta__ = {
}

[node name="General" type="Control" parent="MarginContainer/TabContainer"]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
margin_top = 27.0
Expand Down Expand Up @@ -86,10 +84,30 @@ max_value = 2.0
step = 0.01
value = 1.0

[node name="DefaultBrushSize" type="HBoxContainer" parent="MarginContainer/TabContainer/General/VBoxContainer"]
[node name="ConstantPressure" type="HBoxContainer" parent="MarginContainer/TabContainer/General/VBoxContainer"]
margin_top = 41.0
margin_right = 496.0
margin_bottom = 62.0
margin_bottom = 66.0
size_flags_horizontal = 3

[node name="Label" type="Label" parent="MarginContainer/TabContainer/General/VBoxContainer/ConstantPressure"]
margin_top = 4.0
margin_right = 246.0
margin_bottom = 21.0
size_flags_horizontal = 3
size_flags_vertical = 6
text = "SETTINGS_CONSTANT_PRESSURE"

[node name="ConstantPressure" type="CheckBox" parent="MarginContainer/TabContainer/General/VBoxContainer/ConstantPressure"]
margin_left = 250.0
margin_right = 278.0
margin_bottom = 25.0
size_flags_horizontal = 3

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

[node name="Label" type="Label" parent="MarginContainer/TabContainer/General/VBoxContainer/DefaultBrushSize"]
Expand All @@ -111,9 +129,9 @@ value = 12.0
allow_greater = true

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

[node name="Label" type="Label" parent="MarginContainer/TabContainer/General/VBoxContainer/DefaultToolPressure"]
Expand All @@ -135,9 +153,9 @@ step = 0.05
value = 1.0

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

[node name="Label" type="Label" parent="MarginContainer/TabContainer/General/VBoxContainer/DefaultSaveDir"]
Expand All @@ -158,15 +176,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 = 116.0
margin_top = 145.0
margin_right = 496.0
margin_bottom = 140.0
margin_bottom = 169.0
custom_constants/separation = 24

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

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

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

Expand Down Expand Up @@ -531,6 +549,7 @@ window_title = "KEYBINDING_DIALOG_REBIND_WINDOW_NAME"
dialog_autowrap = true

[connection signal="value_changed" from="MarginContainer/TabContainer/General/VBoxContainer/PressureSensitivity/PressureSensitivity" to="." method="_on_PressureSensitivity_value_changed"]
[connection signal="toggled" from="MarginContainer/TabContainer/General/VBoxContainer/ConstantPressure/ConstantPressure" to="." method="_on_ConstantPressure_toggled"]
[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"]
Expand Down
32 changes: 11 additions & 21 deletions lorien/UI/Themes/theme_dark.tres
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
[gd_resource type="Theme" load_steps=38 format=2]
[gd_resource type="Theme" load_steps=31 format=2]

[ext_resource path="res://Assets/Fonts/font_big_bold.tres" type="DynamicFont" id=1]
[ext_resource path="res://Assets/Fonts/font_normal.tres" type="DynamicFont" id=2]
[ext_resource path="res://Assets/Textures/slider_knob_white.png" type="Texture" id=3]
[ext_resource path="res://Assets/Icons/close.png" type="Texture" id=4]
[ext_resource path="res://Assets/Textures/switch_off.png" type="Texture" id=5]
[ext_resource path="res://Assets/Textures/switch_on.png" type="Texture" id=6]
[ext_resource path="res://Assets/Textures/scrollbar_hl.png" type="Texture" id=7]
[ext_resource path="res://Assets/Textures/scrollbar.png" type="Texture" id=8]
[ext_resource path="res://Assets/Textures/scrollbar_bg.png" type="Texture" id=9]

[sub_resource type="StyleBoxFlat" id=1]
content_margin_left = 6.0
Expand Down Expand Up @@ -50,23 +43,20 @@ corner_radius_bottom_right = 1
corner_radius_bottom_left = 1

[sub_resource type="StyleBoxTexture" id=26]
texture = ExtResource( 8 )
region_rect = Rect2( 0, 0, 12, 12 )
margin_left = 6.0
margin_right = 6.0
expand_margin_left = 2.0
expand_margin_right = 2.0

[sub_resource type="StyleBoxTexture" id=28]
texture = ExtResource( 7 )
region_rect = Rect2( 0, 0, 12, 12 )
margin_left = 6.0
margin_right = 6.0
expand_margin_left = 2.0
expand_margin_right = 2.0

[sub_resource type="StyleBoxTexture" id=29]
texture = ExtResource( 9 )
region_rect = Rect2( 0, 0, 12, 12 )
margin_left = 4.0
margin_right = 4.0
Expand Down Expand Up @@ -240,10 +230,10 @@ CheckButton/colors/font_color_pressed = Color( 1, 1, 1, 1 )
CheckButton/constants/check_vadjust = 0
CheckButton/constants/hseparation = 4
CheckButton/fonts/font = ExtResource( 2 )
CheckButton/icons/off = ExtResource( 5 )
CheckButton/icons/off_disabled = ExtResource( 5 )
CheckButton/icons/on = ExtResource( 6 )
CheckButton/icons/on_disabled = ExtResource( 6 )
CheckButton/icons/off = null
CheckButton/icons/off_disabled = null
CheckButton/icons/on = null
CheckButton/icons/on_disabled = null
CheckButton/styles/disabled = null
CheckButton/styles/focus = null
CheckButton/styles/hover = null
Expand Down Expand Up @@ -279,10 +269,10 @@ HScrollBar/styles/grabber_pressed = SubResource( 28 )
HScrollBar/styles/scroll = SubResource( 29 )
HSeparator/constants/separation = 4
HSeparator/styles/separator = SubResource( 5 )
HSlider/icons/grabber = ExtResource( 3 )
HSlider/icons/grabber_disabled = ExtResource( 3 )
HSlider/icons/grabber_highlight = ExtResource( 3 )
HSlider/icons/tick = ExtResource( 3 )
HSlider/icons/grabber = null
HSlider/icons/grabber_disabled = null
HSlider/icons/grabber_highlight = null
HSlider/icons/tick = null
HSlider/styles/grabber_area = SubResource( 6 )
HSlider/styles/grabber_area_highlight = SubResource( 6 )
HSlider/styles/slider = SubResource( 7 )
Expand Down Expand Up @@ -406,6 +396,6 @@ WindowDialog/constants/close_v_ofs = 18
WindowDialog/constants/scaleborder_size = 4
WindowDialog/constants/title_height = 20
WindowDialog/fonts/title_font = ExtResource( 1 )
WindowDialog/icons/close = ExtResource( 4 )
WindowDialog/icons/close_highlight = ExtResource( 4 )
WindowDialog/icons/close = null
WindowDialog/icons/close_highlight = null
WindowDialog/styles/panel = SubResource( 23 )

0 comments on commit 2281b5b

Please sign in to comment.