From e88ba2cb7348fd57753148d3fcd148f59142af61 Mon Sep 17 00:00:00 2001 From: Variable <77773850+Variable-ind@users.noreply.github.com> Date: Tue, 28 Feb 2023 20:07:48 +0500 Subject: [PATCH] Further improvements to Dynamics (#828) * Image bruch now obeys dynamics as well * Added a signal that resets dynamics * formatting * change uncheck.png * added preview for pressure * Added the requested changes --- assets/graphics/misc/uncheck.png | Bin 128 -> 131 bytes src/Autoload/Global.gd | 1 + src/Tools/Draw.gd | 41 +++++++++++++++--- src/UI/GlobalToolOptions/GlobalToolOptions.gd | 17 ++++++++ .../GlobalToolOptions/GlobalToolOptions.tscn | 27 ++++++++++-- 5 files changed, 75 insertions(+), 11 deletions(-) diff --git a/assets/graphics/misc/uncheck.png b/assets/graphics/misc/uncheck.png index 43f82b46df1f5ae95f368666cab13db22be6fc56..b9fe3ebec5e8e2c689b76b2b3ded20df0a4d5c9c 100644 GIT binary patch delta 89 zcmZo*Y-XHb7-Z||;uvDlo17qVq(Si5kN^Mc|2kN)NE#R!nH{ohKAFhF!|~mKcZ>6f t#=zqfx!q*l^(0DVb|!ofKh!MB!0?ETpHpp#v?l`)c)I$ztaD0e0sz~cA2|R3 delta 86 zcmV-c0IC0j0e}IJF;6;4L_t(IjqTJS0stTkLQ(MkcgCbM87L#{C*n&0!SM`9>V&+J sysju1P@dHd`87DV!MP32E&qg5+dyv+37(rk diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index a7db794e8..fc1e655b4 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -165,6 +165,7 @@ onready var tabs: Tabs = control.find_node("Tabs") onready var main_viewport: ViewportContainer = control.find_node("ViewportContainer") onready var second_viewport: ViewportContainer = control.find_node("Second Canvas") onready var canvas_preview_container: Container = control.find_node("Canvas Preview") +onready var global_tool_options: PanelContainer = control.find_node("Global Tool Options") onready var small_preview_viewport: ViewportContainer = canvas_preview_container.find_node( "PreviewViewportContainer" ) diff --git a/src/Tools/Draw.gd b/src/Tools/Draw.gd index eae705c32..8b86cf1a0 100644 --- a/src/Tools/Draw.gd +++ b/src/Tools/Draw.gd @@ -6,6 +6,7 @@ var _brush_size_dynamics := 1 var _cache_limit := 3 var _brush_interpolate := 0 var _brush_image := Image.new() +var _orignal_brush_image := Image.new() # contains the orignal _brush_image (whithout resizing) var _brush_texture := ImageTexture.new() var _strength := 1.0 var _picking_color := false @@ -31,6 +32,7 @@ var _circle_tool_shortcut: PoolVector2Array func _ready() -> void: + Global.global_tool_options.connect("dynamics_changed", self, "_reset_dynamics") Tools.connect("color_changed", self, "_on_Color_changed") Global.brushes_popup.connect("brush_removed", self, "_on_Brush_removed") @@ -64,11 +66,22 @@ func _on_BrushSize_value_changed(value: float) -> void: if _brush_size != int(value): _brush_size = int(value) _brush_size_dynamics = _brush_size + if Tools.dynamics_size != Tools.Dynamics.NONE: + _brush_size_dynamics = Tools.brush_size_min _cache_limit = (_brush_size * _brush_size) * 3 # This equation seems the best match update_config() save_config() +func _reset_dynamics() -> void: + _brush_size_dynamics = _brush_size + if Tools.dynamics_size != Tools.Dynamics.NONE: + _brush_size_dynamics = Tools.brush_size_min + _cache_limit = (_brush_size * _brush_size) * 3 # This equation seems the best match + update_config() + save_config() + + func _on_InterpolateFactor_value_changed(value: float) -> void: _brush_interpolate = int(value) update_config() @@ -101,6 +114,8 @@ func set_config(config: Dictionary) -> void: _brush = Global.brushes_popup.get_brush(type, index) _brush_size = config.get("brush_size", _brush_size) _brush_size_dynamics = _brush_size + if Tools.dynamics_size != Tools.Dynamics.NONE: + _brush_size_dynamics = Tools.brush_size_min _brush_interpolate = config.get("brush_interpolate", _brush_interpolate) @@ -125,10 +140,11 @@ func update_brush() -> void: Brushes.FILE, Brushes.RANDOM_FILE, Brushes.CUSTOM: $Brush/BrushSize.suffix = "00 %" # Use a different size convention on images if _brush.random.size() <= 1: - _brush_image = _create_blended_brush_image(_brush.image) + _orignal_brush_image = _brush.image else: var random := randi() % _brush.random.size() - _brush_image = _create_blended_brush_image(_brush.random[random]) + _orignal_brush_image = _brush.random[random] + _brush_image = _create_blended_brush_image(_orignal_brush_image) _brush_texture.create_from_image(_brush_image, 0) update_mirror_brush() _stroke_dimensions = _brush_image.get_size() @@ -213,10 +229,15 @@ func draw_tool(position: Vector2) -> void: func draw_end(position: Vector2) -> void: .draw_end(position) - if Tools.dynamics_size == Tools.Dynamics.PRESSURE: + _brush_size_dynamics = _brush_size + if Tools.dynamics_size != Tools.Dynamics.NONE: _brush_size_dynamics = Tools.brush_size_min - else: - _brush_size_dynamics = _brush_size + match _brush.type: + Brushes.FILE, Brushes.RANDOM_FILE, Brushes.CUSTOM: + _brush_image = _create_blended_brush_image(_orignal_brush_image) + _brush_texture.create_from_image(_brush_image, 0) + update_mirror_brush() + _stroke_dimensions = _brush_image.get_size() _indicator = _create_brush_indicator() _polylines = _create_polylines(_indicator) @@ -238,19 +259,25 @@ func _prepare_tool() -> void: _drawer.horizontal_mirror = Tools.horizontal_mirror _drawer.vertical_mirror = Tools.vertical_mirror _drawer.color_op.strength = strength + _indicator = _create_brush_indicator() + _polylines = _create_polylines(_indicator) # Memorize current project _stroke_project = Global.current_project # Memorize the frame/layer we are drawing on rather than fetching it on every pixel _stroke_images = _get_selected_draw_images() # This may prevent a few tests when setting pixels - _indicator = _create_brush_indicator() - _polylines = _create_polylines(_indicator) _is_mask_size_zero = _mask.size() == 0 match _brush.type: Brushes.CIRCLE: _prepare_circle_tool(false) Brushes.FILLED_CIRCLE: _prepare_circle_tool(true) + Brushes.FILE, Brushes.RANDOM_FILE, Brushes.CUSTOM: + # save _brush_image for safe keeping + _brush_image = _create_blended_brush_image(_orignal_brush_image) + _brush_texture.create_from_image(_brush_image, 0) + update_mirror_brush() + _stroke_dimensions = _brush_image.get_size() func _prepare_circle_tool(fill: bool) -> void: diff --git a/src/UI/GlobalToolOptions/GlobalToolOptions.gd b/src/UI/GlobalToolOptions/GlobalToolOptions.gd index 89cce3381..88ba8b7db 100644 --- a/src/UI/GlobalToolOptions/GlobalToolOptions.gd +++ b/src/UI/GlobalToolOptions/GlobalToolOptions.gd @@ -1,5 +1,7 @@ extends PanelContainer +signal dynamics_changed + enum { ALPHA, SIZE } var alpha_last_pressed: BaseButton = null @@ -16,6 +18,8 @@ onready var alpha_pressure_button: Button = $"%AlphaPressureButton" onready var alpha_velocity_button: Button = $"%AlphaVelocityButton" onready var size_pressure_button: Button = $"%SizePressureButton" onready var size_velocity_button: Button = $"%SizeVelocityButton" +onready var pressure_preview: ProgressBar = $"%PressurePreview" +onready var velocity_preview: ProgressBar = $"%VelocityPreview" onready var alpha_group: ButtonGroup = alpha_pressure_button.group onready var size_group: ButtonGroup = size_pressure_button.group @@ -53,6 +57,14 @@ func _ready() -> void: ) +func _input(event: InputEvent) -> void: + pressure_preview.value = 0 + velocity_preview.value = 0 + if event is InputEventMouseMotion: + pressure_preview.value = event.pressure + velocity_preview.value = event.speed.length() / Tools.mouse_velocity_max + + func _on_resized() -> void: var tool_panel_size := rect_size var column_n := tool_panel_size.x / 36.5 @@ -146,6 +158,7 @@ func _on_Dynamics_toggled( if !button.pressed: file_name = "uncheck.png" Global.change_button_texturerect(texture_button, file_name) + emit_signal("dynamics_changed") func _set_last_pressed_button(prop: int, value: BaseButton) -> void: @@ -168,15 +181,19 @@ func _on_ThresholdVelocity_updated(value_1, value_2) -> void: func _on_AlphaMin_value_changed(value: float) -> void: Tools.alpha_min = value + emit_signal("dynamics_changed") func _on_AlphaMax_value_changed(value: float) -> void: Tools.alpha_max = value + emit_signal("dynamics_changed") func _on_SizeMin_value_changed(value: float) -> void: Tools.brush_size_min = int(value) + emit_signal("dynamics_changed") func _on_SizeMax_value_changed(value: float) -> void: Tools.brush_size_max = int(value) + emit_signal("dynamics_changed") diff --git a/src/UI/GlobalToolOptions/GlobalToolOptions.tscn b/src/UI/GlobalToolOptions/GlobalToolOptions.tscn index c9ce13402..6147605b9 100644 --- a/src/UI/GlobalToolOptions/GlobalToolOptions.tscn +++ b/src/UI/GlobalToolOptions/GlobalToolOptions.tscn @@ -301,7 +301,7 @@ stretch_margin_top = 3 stretch_margin_right = 3 stretch_margin_bottom = 3 script = ExtResource( 5 ) -prefix = "Min" +prefix = "Start" snap_step = 0.1 [node name="AlphaMax" type="TextureProgress" parent="DynamicsPanel/VBoxContainer/LimitContainer"] @@ -320,7 +320,7 @@ stretch_margin_top = 3 stretch_margin_right = 3 stretch_margin_bottom = 3 script = ExtResource( 5 ) -prefix = "Max" +prefix = "End" snap_step = 0.1 [node name="SizeLabel" type="Label" parent="DynamicsPanel/VBoxContainer/LimitContainer"] @@ -347,7 +347,7 @@ stretch_margin_top = 3 stretch_margin_right = 3 stretch_margin_bottom = 3 script = ExtResource( 5 ) -prefix = "Min" +prefix = "Start" [node name="SizeMax" type="TextureProgress" parent="DynamicsPanel/VBoxContainer/LimitContainer"] margin_left = 171.0 @@ -366,7 +366,7 @@ stretch_margin_top = 3 stretch_margin_right = 3 stretch_margin_bottom = 3 script = ExtResource( 5 ) -prefix = "Max" +prefix = "End" [node name="ThresholdsHeader" type="HBoxContainer" parent="DynamicsPanel/VBoxContainer"] margin_top = 126.0 @@ -412,6 +412,16 @@ margin_right = 192.0 margin_bottom = 30.0 texture = SubResource( 4 ) +[node name="PressurePreview" type="ProgressBar" parent="DynamicsPanel/VBoxContainer/ThresholdContainer/ThresholdPressure/TextureRect" index="0"] +unique_name_in_owner = true +modulate = Color( 1, 1, 1, 0.294118 ) +anchor_right = 1.0 +anchor_bottom = 1.0 +max_value = 1.0 +step = 0.001 +value = 0.497 +percent_visible = false + [node name="ThresholdVelocityLabel" type="Label" parent="DynamicsPanel/VBoxContainer/ThresholdContainer"] margin_top = 42.0 margin_right = 56.0 @@ -433,6 +443,15 @@ margin_right = 192.0 margin_bottom = 30.0 texture = SubResource( 5 ) +[node name="VelocityPreview" type="ProgressBar" parent="DynamicsPanel/VBoxContainer/ThresholdContainer/ThresholdVelocity/TextureRect" index="0"] +unique_name_in_owner = true +modulate = Color( 1, 1, 1, 0.294118 ) +anchor_right = 1.0 +anchor_bottom = 1.0 +max_value = 1.0 +step = 0.001 +percent_visible = false + [connection signal="resized" from="." to="." method="_on_resized"] [connection signal="toggled" from="ScrollContainer/CenterContainer/GridContainer/Horizontal" to="." method="_on_Horizontal_toggled"] [connection signal="toggled" from="ScrollContainer/CenterContainer/GridContainer/Vertical" to="." method="_on_Vertical_toggled"]