1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 09:09:47 +00:00

Some improvements to the dynamics (#826)

* fix  dynamics

* removed empty line

* Added icon

* added check/uncheck icons

* make thresholds ui simpler

* Rename dynamics.png to lowercase and add MaxMinEdit class to project.godot

---------

Co-authored-by: Emmanouil Papadeas <manoschool@yahoo.gr>
This commit is contained in:
Variable 2023-02-21 00:51:26 +05:00 committed by GitHub
parent 0da30c015c
commit f2f2f11661
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 444 additions and 141 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 B

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/check.png-0fc65a6dd56b2296f9f8446beb7b136a.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/misc/check.png"
dest_files=[ "res://.import/check.png-0fc65a6dd56b2296f9f8446beb7b136a.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 B

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/dynamics.png-ea904a4a1658c230cb654ce11b3cb7b2.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/misc/dynamics.png"
dest_files=[ "res://.import/dynamics.png-ea904a4a1658c230cb654ce11b3cb7b2.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/uncheck.png-e9003e3a9b5f329de0c2aec37621a462.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/misc/uncheck.png"
dest_files=[ "res://.import/uncheck.png-e9003e3a9b5f329de0c2aec37621a462.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

View file

@ -124,6 +124,11 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://src/UI/Timeline/LayerButton.gd"
}, {
"base": "Control",
"class": "MaxMinEdit",
"language": "GDScript",
"path": "res://src/UI/Nodes/MaxMinEdit.gd"
}, {
"base": "Label",
"class": "NotificationLabel",
"language": "GDScript",
@ -248,6 +253,7 @@ _global_script_class_icons={
"Guide": "",
"ImageEffect": "",
"LayerButton": "",
"MaxMinEdit": "",
"NotificationLabel": "",
"Palette": "",
"PaletteColor": "",

View file

@ -63,6 +63,7 @@ func _on_Brush_selected(brush: Brushes.Brush) -> void:
func _on_BrushSize_value_changed(value: float) -> void:
if _brush_size != int(value):
_brush_size = int(value)
_brush_size_dynamics = _brush_size
_cache_limit = (_brush_size * _brush_size) * 3 # This equation seems the best match
update_config()
save_config()
@ -99,6 +100,7 @@ func set_config(config: Dictionary) -> void:
var index: int = config.get("brush_index", _brush.index)
_brush = Global.brushes_popup.get_brush(type, index)
_brush_size = config.get("brush_size", _brush_size)
_brush_size_dynamics = _brush_size
_brush_interpolate = config.get("brush_interpolate", _brush_interpolate)
@ -209,6 +211,16 @@ func draw_tool(position: Vector2) -> void:
_set_pixel_no_cache(coord)
func draw_end(position: Vector2) -> void:
.draw_end(position)
if Tools.dynamics_size == Tools.Dynamics.PRESSURE:
_brush_size_dynamics = Tools.brush_size_min
else:
_brush_size_dynamics = _brush_size
_indicator = _create_brush_indicator()
_polylines = _create_polylines(_indicator)
func _prepare_tool() -> void:
if !Global.current_project.layers[Global.current_project.current_layer].can_layer_get_drawn():
return
@ -231,6 +243,8 @@ func _prepare_tool() -> void:
# 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:
@ -489,11 +503,11 @@ func _blend_image(image: Image, color: Color, factor: float) -> Image:
func _create_brush_indicator() -> BitMap:
match _brush.type:
Brushes.PIXEL:
return _create_pixel_indicator(_brush_size)
return _create_pixel_indicator(_brush_size_dynamics)
Brushes.CIRCLE:
return _create_circle_indicator(_brush_size, false)
return _create_circle_indicator(_brush_size_dynamics, false)
Brushes.FILLED_CIRCLE:
return _create_circle_indicator(_brush_size, true)
return _create_circle_indicator(_brush_size_dynamics, true)
_:
return _create_image_indicator(_brush_image)

View file

@ -12,10 +12,10 @@ onready var pixel_perfect: BaseButton = grid_container.get_node("PixelPerfect")
onready var dynamics: Button = $"%Dynamics"
onready var dynamics_panel: PopupPanel = $DynamicsPanel
onready var alpha_pressure_button: CheckButton = $"%AlphaPressureButton"
onready var alpha_velocity_button: CheckButton = $"%AlphaVelocityButton"
onready var size_pressure_button: CheckButton = $"%SizePressureButton"
onready var size_velocity_button: CheckButton = $"%SizeVelocityButton"
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 alpha_group: ButtonGroup = alpha_pressure_button.group
onready var size_group: ButtonGroup = size_pressure_button.group
@ -141,6 +141,12 @@ func _on_Dynamics_toggled(
SIZE:
Tools.dynamics_size = final_dynamic
var texture_button: TextureRect = button.get_node("TextureRect")
var file_name := "check.png"
if !button.pressed:
file_name = "uncheck.png"
Global.change_button_texturerect(texture_button, file_name)
func _set_last_pressed_button(prop: int, value: BaseButton) -> void:
match prop:
@ -150,20 +156,14 @@ func _set_last_pressed_button(prop: int, value: BaseButton) -> void:
size_last_pressed = value
func _on_ThresholdPressureMin_value_changed(value: float) -> void:
Tools.pen_pressure_min = value
func _on_ThresholdPressure_updated(value_1, value_2) -> void:
Tools.pen_pressure_min = min(value_1, value_2)
Tools.pen_pressure_max = max(value_1, value_2)
func _on_ThresholdPressureMax_value_changed(value: float) -> void:
Tools.pen_pressure_max = value
func _on_ThresholdVelocityMin_value_changed(value: float) -> void:
Tools.mouse_velocity_min_thres = value
func _on_ThresholdVelocityMax_value_changed(value: float) -> void:
Tools.mouse_velocity_max_thres = value
func _on_ThresholdVelocity_updated(value_1, value_2) -> void:
Tools.mouse_velocity_min_thres = min(value_1, value_2)
Tools.mouse_velocity_max_thres = max(value_1, value_2)
func _on_AlphaMin_value_changed(value: float) -> void:

View file

@ -1,15 +1,29 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=14 format=2]
[ext_resource path="res://assets/graphics/misc/horizontal_mirror_off.png" type="Texture" id=1]
[ext_resource path="res://assets/graphics/misc/vertical_mirror_off.png" type="Texture" id=2]
[ext_resource path="res://src/UI/GlobalToolOptions/GlobalToolOptions.gd" type="Script" id=3]
[ext_resource path="res://assets/graphics/misc/pixel_perfect_off.png" type="Texture" id=4]
[ext_resource path="res://src/UI/Nodes/ValueSlider.gd" type="Script" id=5]
[ext_resource path="res://assets/graphics/misc/dynamics.png" type="Texture" id=6]
[ext_resource path="res://assets/graphics/misc/uncheck.png" type="Texture" id=7]
[ext_resource path="res://src/UI/Nodes/MaxMinEdit.tscn" type="PackedScene" id=8]
[sub_resource type="ButtonGroup" id=1]
[sub_resource type="ButtonGroup" id=2]
[sub_resource type="Gradient" id=3]
interpolation_mode = 1
offsets = PoolRealArray( 0, 0, 1 )
colors = PoolColorArray( 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1 )
[sub_resource type="GradientTexture" id=4]
gradient = SubResource( 3 )
[sub_resource type="GradientTexture" id=5]
gradient = SubResource( 3 )
[node name="Global Tool Options" type="PanelContainer"]
margin_left = 1.0
margin_right = 195.0
@ -25,14 +39,16 @@ margin_bottom = 43.0
rect_min_size = Vector2( 36, 36 )
[node name="CenterContainer" type="CenterContainer" parent="ScrollContainer"]
margin_right = 183.0
margin_bottom = 32.0
margin_right = 180.0
margin_bottom = 36.0
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="GridContainer" type="GridContainer" parent="ScrollContainer/CenterContainer"]
margin_right = 183.0
margin_bottom = 32.0
margin_left = 20.0
margin_top = 2.0
margin_right = 160.0
margin_bottom = 34.0
size_flags_vertical = 0
columns = 4
@ -54,9 +70,6 @@ margin_top = -10.5
margin_right = 10.0
margin_bottom = 10.5
texture = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Vertical" type="Button" parent="ScrollContainer/CenterContainer/GridContainer" groups=["UIButtons"]]
margin_left = 36.0
@ -77,9 +90,6 @@ margin_top = -10.0
margin_right = 10.0
margin_bottom = 10.0
texture = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="PixelPerfect" type="Button" parent="ScrollContainer/CenterContainer/GridContainer" groups=["UIButtons"]]
margin_left = 72.0
@ -102,13 +112,29 @@ margin_right = 11.0
margin_bottom = 10.0
texture = ExtResource( 4 )
[node name="Dynamics" type="Button" parent="ScrollContainer/CenterContainer/GridContainer"]
[node name="Dynamics" type="Button" parent="ScrollContainer/CenterContainer/GridContainer" groups=["UIButtons"]]
unique_name_in_owner = true
margin_left = 108.0
margin_right = 183.0
margin_right = 140.0
margin_bottom = 32.0
rect_min_size = Vector2( 32, 32 )
hint_tooltip = "Pixel Perfect
Makes lines smooth by removing the extra pixels on the edges"
mouse_default_cursor_shape = 2
text = "Dynamics"
__meta__ = {
"_editor_description_": ""
}
[node name="TextureRect" type="TextureRect" parent="ScrollContainer/CenterContainer/GridContainer/Dynamics"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -11.0
margin_top = -10.0
margin_right = 11.0
margin_bottom = 10.0
texture = ExtResource( 6 )
[node name="DynamicsPanel" type="PopupPanel" parent="."]
margin_left = 7.0
@ -125,7 +151,7 @@ margin_bottom = 256.0
[node name="DynamicsOptions" type="GridContainer" parent="DynamicsPanel/VBoxContainer"]
margin_right = 252.0
margin_bottom = 108.0
margin_bottom = 68.0
columns = 3
[node name="Control" type="Control" parent="DynamicsPanel/VBoxContainer/DynamicsOptions"]
@ -153,57 +179,87 @@ text = "Velocity"
align = 1
[node name="AlphaLabel" type="Label" parent="DynamicsPanel/VBoxContainer/DynamicsOptions"]
margin_top = 37.0
margin_top = 27.0
margin_right = 82.0
margin_bottom = 51.0
margin_bottom = 41.0
text = "Alpha"
[node name="AlphaPressureButton" type="CheckButton" parent="DynamicsPanel/VBoxContainer/DynamicsOptions"]
[node name="AlphaPressureButton" type="Button" parent="DynamicsPanel/VBoxContainer/DynamicsOptions" groups=["UIButtons"]]
unique_name_in_owner = true
margin_left = 86.0
margin_top = 24.0
margin_right = 167.0
margin_bottom = 64.0
margin_bottom = 44.0
mouse_default_cursor_shape = 2
toggle_mode = true
group = SubResource( 1 )
icon_align = 1
expand_icon = true
[node name="AlphaVelocityButton" type="CheckButton" parent="DynamicsPanel/VBoxContainer/DynamicsOptions"]
[node name="TextureRect" type="TextureRect" parent="DynamicsPanel/VBoxContainer/DynamicsOptions/AlphaPressureButton"]
anchor_right = 1.0
anchor_bottom = 1.0
texture = ExtResource( 7 )
expand = true
[node name="AlphaVelocityButton" type="Button" parent="DynamicsPanel/VBoxContainer/DynamicsOptions" groups=["UIButtons"]]
unique_name_in_owner = true
margin_left = 171.0
margin_top = 24.0
margin_right = 252.0
margin_bottom = 64.0
margin_bottom = 44.0
mouse_default_cursor_shape = 2
toggle_mode = true
group = SubResource( 1 )
[node name="TextureRect" type="TextureRect" parent="DynamicsPanel/VBoxContainer/DynamicsOptions/AlphaVelocityButton"]
anchor_right = 1.0
anchor_bottom = 1.0
texture = ExtResource( 7 )
expand = true
[node name="SizeLabel" type="Label" parent="DynamicsPanel/VBoxContainer/DynamicsOptions"]
margin_top = 81.0
margin_top = 51.0
margin_right = 82.0
margin_bottom = 95.0
margin_bottom = 65.0
text = "Size"
[node name="SizePressureButton" type="CheckButton" parent="DynamicsPanel/VBoxContainer/DynamicsOptions"]
[node name="SizePressureButton" type="Button" parent="DynamicsPanel/VBoxContainer/DynamicsOptions" groups=["UIButtons"]]
unique_name_in_owner = true
margin_left = 86.0
margin_top = 68.0
margin_top = 48.0
margin_right = 167.0
margin_bottom = 108.0
margin_bottom = 68.0
mouse_default_cursor_shape = 2
toggle_mode = true
group = SubResource( 2 )
[node name="SizeVelocityButton" type="CheckButton" parent="DynamicsPanel/VBoxContainer/DynamicsOptions"]
[node name="TextureRect" type="TextureRect" parent="DynamicsPanel/VBoxContainer/DynamicsOptions/SizePressureButton"]
anchor_right = 1.0
anchor_bottom = 1.0
texture = ExtResource( 7 )
expand = true
[node name="SizeVelocityButton" type="Button" parent="DynamicsPanel/VBoxContainer/DynamicsOptions" groups=["UIButtons"]]
unique_name_in_owner = true
margin_left = 171.0
margin_top = 68.0
margin_top = 48.0
margin_right = 252.0
margin_bottom = 108.0
margin_bottom = 68.0
mouse_default_cursor_shape = 2
toggle_mode = true
group = SubResource( 2 )
[node name="TextureRect" type="TextureRect" parent="DynamicsPanel/VBoxContainer/DynamicsOptions/SizeVelocityButton"]
anchor_right = 1.0
anchor_bottom = 1.0
texture = ExtResource( 7 )
expand = true
[node name="LimitsHeader" type="HBoxContainer" parent="DynamicsPanel/VBoxContainer"]
margin_top = 112.0
margin_top = 72.0
margin_right = 252.0
margin_bottom = 126.0
margin_bottom = 86.0
[node name="Label" type="Label" parent="DynamicsPanel/VBoxContainer/LimitsHeader"]
margin_right = 76.0
@ -218,9 +274,9 @@ margin_bottom = 14.0
size_flags_horizontal = 3
[node name="LimitContainer" type="GridContainer" parent="DynamicsPanel/VBoxContainer"]
margin_top = 130.0
margin_top = 90.0
margin_right = 252.0
margin_bottom = 162.0
margin_bottom = 122.0
columns = 3
[node name="AlphaLabel" type="Label" parent="DynamicsPanel/VBoxContainer/LimitContainer"]
@ -313,9 +369,9 @@ script = ExtResource( 5 )
prefix = "Max"
[node name="ThresholdsHeader" type="HBoxContainer" parent="DynamicsPanel/VBoxContainer"]
margin_top = 166.0
margin_top = 126.0
margin_right = 252.0
margin_bottom = 180.0
margin_bottom = 140.0
[node name="Label" type="Label" parent="DynamicsPanel/VBoxContainer/ThresholdsHeader"]
margin_right = 70.0
@ -330,101 +386,52 @@ margin_bottom = 14.0
size_flags_horizontal = 3
[node name="ThresholdContainer" type="GridContainer" parent="DynamicsPanel/VBoxContainer"]
margin_top = 184.0
margin_top = 144.0
margin_right = 252.0
margin_bottom = 216.0
columns = 3
margin_bottom = 208.0
columns = 2
[node name="ThresholdPressureLabel" type="Label" parent="DynamicsPanel/VBoxContainer/ThresholdContainer"]
margin_right = 82.0
margin_bottom = 14.0
size_flags_horizontal = 3
margin_top = 8.0
margin_right = 56.0
margin_bottom = 22.0
text = "Pressure"
[node name="ThresholdPressureMin" type="TextureProgress" parent="DynamicsPanel/VBoxContainer/ThresholdContainer"]
margin_left = 86.0
margin_right = 167.0
margin_bottom = 14.0
mouse_default_cursor_shape = 2
size_flags_horizontal = 3
theme_type_variation = "ValueSlider"
max_value = 1.0
step = 0.01
value = 0.2
nine_patch_stretch = true
stretch_margin_left = 3
stretch_margin_top = 3
stretch_margin_right = 3
stretch_margin_bottom = 3
script = ExtResource( 5 )
prefix = "Min"
snap_step = 0.1
[node name="ThresholdPressureMax" type="TextureProgress" parent="DynamicsPanel/VBoxContainer/ThresholdContainer"]
margin_left = 171.0
[node name="ThresholdPressure" parent="DynamicsPanel/VBoxContainer/ThresholdContainer" instance=ExtResource( 8 )]
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 60.0
margin_right = 252.0
margin_bottom = 14.0
mouse_default_cursor_shape = 2
margin_bottom = 30.0
size_flags_horizontal = 3
theme_type_variation = "ValueSlider"
max_value = 1.0
step = 0.01
value = 0.8
nine_patch_stretch = true
stretch_margin_left = 3
stretch_margin_top = 3
stretch_margin_right = 3
stretch_margin_bottom = 3
script = ExtResource( 5 )
prefix = "Max"
snap_step = 0.1
start = 0.2
end = 0.8
[node name="TextureRect" parent="DynamicsPanel/VBoxContainer/ThresholdContainer/ThresholdPressure" index="0"]
margin_right = 192.0
margin_bottom = 30.0
texture = SubResource( 4 )
[node name="ThresholdVelocityLabel" type="Label" parent="DynamicsPanel/VBoxContainer/ThresholdContainer"]
margin_top = 18.0
margin_right = 82.0
margin_bottom = 32.0
size_flags_horizontal = 3
margin_top = 42.0
margin_right = 56.0
margin_bottom = 56.0
text = "Velocity"
[node name="ThresholdVelocityMin" type="TextureProgress" parent="DynamicsPanel/VBoxContainer/ThresholdContainer"]
margin_left = 86.0
margin_top = 18.0
margin_right = 167.0
margin_bottom = 32.0
mouse_default_cursor_shape = 2
size_flags_horizontal = 3
theme_type_variation = "ValueSlider"
max_value = 1.0
step = 0.01
value = 0.2
nine_patch_stretch = true
stretch_margin_left = 3
stretch_margin_top = 3
stretch_margin_right = 3
stretch_margin_bottom = 3
script = ExtResource( 5 )
prefix = "Min"
snap_step = 0.1
[node name="ThresholdVelocityMax" type="TextureProgress" parent="DynamicsPanel/VBoxContainer/ThresholdContainer"]
margin_left = 171.0
margin_top = 18.0
[node name="ThresholdVelocity" parent="DynamicsPanel/VBoxContainer/ThresholdContainer" instance=ExtResource( 8 )]
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 60.0
margin_top = 34.0
margin_right = 252.0
margin_bottom = 32.0
mouse_default_cursor_shape = 2
size_flags_horizontal = 3
theme_type_variation = "ValueSlider"
max_value = 1.0
step = 0.01
value = 0.8
nine_patch_stretch = true
stretch_margin_left = 3
stretch_margin_top = 3
stretch_margin_right = 3
stretch_margin_bottom = 3
script = ExtResource( 5 )
prefix = "Max"
snap_step = 0.1
margin_bottom = 64.0
start = 0.2
end = 0.8
[node name="TextureRect" parent="DynamicsPanel/VBoxContainer/ThresholdContainer/ThresholdVelocity" index="0"]
margin_right = 192.0
margin_bottom = 30.0
texture = SubResource( 5 )
[connection signal="resized" from="." to="." method="_on_resized"]
[connection signal="toggled" from="ScrollContainer/CenterContainer/GridContainer/Horizontal" to="." method="_on_Horizontal_toggled"]
@ -435,7 +442,8 @@ snap_step = 0.1
[connection signal="value_changed" from="DynamicsPanel/VBoxContainer/LimitContainer/AlphaMax" to="." method="_on_AlphaMax_value_changed"]
[connection signal="value_changed" from="DynamicsPanel/VBoxContainer/LimitContainer/SizeMin" to="." method="_on_SizeMin_value_changed"]
[connection signal="value_changed" from="DynamicsPanel/VBoxContainer/LimitContainer/SizeMax" to="." method="_on_SizeMax_value_changed"]
[connection signal="value_changed" from="DynamicsPanel/VBoxContainer/ThresholdContainer/ThresholdPressureMin" to="." method="_on_ThresholdPressureMin_value_changed"]
[connection signal="value_changed" from="DynamicsPanel/VBoxContainer/ThresholdContainer/ThresholdPressureMax" to="." method="_on_ThresholdPressureMax_value_changed"]
[connection signal="value_changed" from="DynamicsPanel/VBoxContainer/ThresholdContainer/ThresholdVelocityMin" to="." method="_on_ThresholdVelocityMin_value_changed"]
[connection signal="value_changed" from="DynamicsPanel/VBoxContainer/ThresholdContainer/ThresholdVelocityMax" to="." method="_on_ThresholdVelocityMax_value_changed"]
[connection signal="updated" from="DynamicsPanel/VBoxContainer/ThresholdContainer/ThresholdPressure" to="." method="_on_ThresholdPressure_updated"]
[connection signal="updated" from="DynamicsPanel/VBoxContainer/ThresholdContainer/ThresholdVelocity" to="." method="_on_ThresholdVelocity_updated"]
[editable path="DynamicsPanel/VBoxContainer/ThresholdContainer/ThresholdPressure"]
[editable path="DynamicsPanel/VBoxContainer/ThresholdContainer/ThresholdVelocity"]

133
src/UI/Nodes/MaxMinEdit.gd Normal file
View file

@ -0,0 +1,133 @@
# Code taken and modified from Material Maker, licensed under MIT
# gdlint: ignore=max-line-length
# https://github.com/RodZill4/material-maker/blob/master/material_maker/widgets/gradient_editor/gradient_editor.gd
class_name MaxMinEdit
extends Control
signal updated(zone)
export(float) var start = 0.0
export(float) var end = 1.0
export(Color) var zone_col = Color.black
export(Color) var background_col = Color.gray
var active_cursor: GradientCursor # Showing a color picker popup to change a cursor's color
onready var x_offset: float = rect_size.x - GradientCursor.WIDTH
onready var texture_rect: TextureRect = $TextureRect
onready var texture: Texture = $TextureRect.texture
onready var gradient: Gradient = texture.gradient
class GradientCursor:
extends Control
const WIDTH := 10
var color: Color
var sliding := false
onready var parent: TextureRect = get_parent()
onready var grand_parent: Container = parent.get_parent()
onready var label: Label = parent.get_node("Value")
func _ready() -> void:
rect_position = Vector2(0, 15)
rect_size = Vector2(WIDTH, 15)
func _draw() -> void:
# warning-ignore:integer_division
var polygon := PoolVector2Array(
[
Vector2(0, 5),
Vector2(WIDTH / 2, 0),
Vector2(WIDTH, 5),
Vector2(WIDTH, 15),
Vector2(0, 15),
Vector2(0, 5)
]
)
var c := color
c.a = 1.0
draw_colored_polygon(polygon, c)
draw_polyline(polygon, Color(0.0, 0.0, 0.0) if color.v > 0.5 else Color(1.0, 1.0, 1.0))
func _gui_input(ev: InputEvent) -> void:
if ev is InputEventMouseButton:
if ev.button_index == BUTTON_LEFT:
if ev.pressed:
sliding = true
label.visible = true
label.text = "%.03f" % get_cursor_position()
else:
sliding = false
label.visible = false
elif ev is InputEventMouseMotion and (ev.button_mask & BUTTON_MASK_LEFT) != 0 and sliding:
rect_position.x += get_local_mouse_position().x
if ev.control:
rect_position.x = (
round(get_cursor_position() * 20.0)
* 0.05
* (parent.rect_size.x - WIDTH)
)
rect_position.x = min(max(0, rect_position.x), parent.rect_size.x - rect_size.x)
grand_parent.update_from_value()
label.text = "%.03f" % get_cursor_position()
func get_cursor_position() -> float:
return rect_position.x / (parent.rect_size.x - WIDTH)
func _ready() -> void:
gradient = gradient.duplicate(true)
texture.gradient = gradient
gradient.offsets[1] = start
gradient.offsets[2] = end
gradient.interpolation_mode = Gradient.GRADIENT_INTERPOLATE_CONSTANT
gradient.colors[0] = background_col
gradient.colors[2] = background_col
gradient.colors[1] = zone_col
_create_cursors()
func _create_cursors() -> void:
for c in texture_rect.get_children():
if c is GradientCursor:
texture_rect.remove_child(c)
c.queue_free()
for i in gradient.get_point_count():
if i == 0:
gradient.set_offset(0, 0)
else:
var p: float = gradient.get_offset(i)
add_cursor(p * x_offset)
func update_from_value() -> void:
gradient.offsets = [0.0]
var cursors = []
for c in texture_rect.get_children():
if c is GradientCursor:
cursors.append(c)
var point_1: float = cursors[0].rect_position.x / x_offset
var point_2: float = cursors[1].rect_position.x / x_offset
if cursors[1].get_cursor_position() > cursors[0].get_cursor_position():
gradient.add_point(point_1, zone_col)
gradient.add_point(point_2, background_col)
else:
gradient.add_point(point_1, background_col)
gradient.add_point(point_2, zone_col)
emit_signal("updated", gradient.offsets[1], gradient.offsets[2])
func add_cursor(x: float) -> void:
var cursor := GradientCursor.new()
texture_rect.add_child(cursor)
cursor.rect_position.x = x
cursor.color = zone_col
func _on_GradientEdit_resized() -> void:
if not gradient:
return
x_offset = rect_size.x - GradientCursor.WIDTH
_create_cursors()

View file

@ -0,0 +1,37 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://src/UI/Nodes/MaxMinEdit.gd" type="Script" id=1]
[ext_resource path="res://src/Shaders/AutoInvertColors.shader" type="Shader" id=2]
[sub_resource type="Gradient" id=3]
interpolation_mode = 1
offsets = PoolRealArray( 0, 0, 1 )
colors = PoolColorArray( 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1 )
[sub_resource type="GradientTexture" id=6]
gradient = SubResource( 3 )
[sub_resource type="ShaderMaterial" id=5]
shader = ExtResource( 2 )
[node name="MaxMinEdit" type="VBoxContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
[node name="TextureRect" type="TextureRect" parent="."]
margin_right = 1280.0
margin_bottom = 720.0
rect_min_size = Vector2( 0, 30 )
size_flags_vertical = 3
texture = SubResource( 6 )
expand = true
[node name="Value" type="Label" parent="TextureRect"]
material = SubResource( 5 )
anchor_right = 1.0
anchor_bottom = 1.0
align = 1
valign = 1
[connection signal="resized" from="." to="." method="_on_GradientEdit_resized"]