Filtered unwanted mouse events in float editor and updated shader parameter editor

This commit is contained in:
RodZill4 2019-11-06 08:31:38 +01:00
parent 1c4e904a22
commit e7a70af690
3 changed files with 61 additions and 41 deletions

View File

@ -7,6 +7,7 @@ export var min_value : float = 0.0 setget set_min_value
export var max_value : float = 1.0 setget set_max_value export var max_value : float = 1.0 setget set_max_value
export var step : float = 0.0 setget set_step export var step : float = 0.0 setget set_step
var sliding : bool = false
var start_position : float var start_position : float
var start_value : float var start_value : float
@ -45,9 +46,12 @@ func _on_LineEdit_gui_input(event : InputEvent) -> void:
if event.is_pressed(): if event.is_pressed():
start_position = event.position.x start_position = event.position.x
start_value = value start_value = value
elif event is InputEventMouseMotion and event.button_mask == BUTTON_MASK_LEFT: sliding = true
else:
sliding = false
elif sliding and event is InputEventMouseMotion and event.button_mask == BUTTON_MASK_LEFT:
var delta : float = event.position.x-start_position var delta : float = event.position.x-start_position
var v : float = clamp(start_value+sign(delta)*pow(abs(delta)*0.005, 2)*abs(max_value - min_value), min_value, max_value) var v : float = start_value+sign(delta)*pow(abs(delta)*0.005, 2)*abs(max_value - min_value)
if step != 0: if step != 0:
v = min_value+floor((v - min_value)/step)*step v = min_value+floor((v - min_value)/step)*step
set_value(v) set_value(v)

View File

@ -9,18 +9,27 @@ func get_model_data() -> Dictionary:
default = $Default.value, default = $Default.value,
} }
if $SpinBox.pressed:
data.widget = "spinbox"
return data return data
func set_model_data(data) -> void: func set_model_data(data) -> void:
if data.has("min"): if data.has("min"):
$Min.value = data.min $Min.value = data.min
$Default.min_value = data.min
if data.has("max"): if data.has("max"):
$Max.value = data.max $Max.value = data.max
$Default.max_value = data.max
if data.has("step"): if data.has("step"):
$Step.value = data.step $Step.value = data.step
$Default.step = data.step
if data.has("default"): if data.has("default"):
$Default.value = data.default $Default.value = data.default
$SpinBox.pressed = ( data.has("widget") && data.widget == "spinbox" )
func _on_Min_value_changed(v : float) -> void:
$Default.min_value = v
func _on_Max_value_changed(v : float) -> void:
$Default.max_value = v
func _on_Step_value_changed(v : float) -> void:
$Default.step = v

View File

@ -1,6 +1,7 @@
[gd_scene load_steps=2 format=2] [gd_scene load_steps=3 format=2]
[ext_resource path="res://addons/material_maker/widgets/node_editor/parameter_float.gd" type="Script" id=1] [ext_resource path="res://addons/material_maker/widgets/node_editor/parameter_float.gd" type="Script" id=1]
[ext_resource path="res://addons/material_maker/widgets/float_edit.tscn" type="PackedScene" id=2]
[node name="float" type="HBoxContainer"] [node name="float" type="HBoxContainer"]
margin_right = 547.0 margin_right = 547.0
@ -13,67 +14,73 @@ margin_right = 28.0
margin_bottom = 19.0 margin_bottom = 19.0
text = "Min:" text = "Min:"
[node name="Min" type="SpinBox" parent="."] [node name="Min" parent="." instance=ExtResource( 2 )]
anchor_left = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 32.0 margin_left = 32.0
margin_right = 106.0 margin_right = 90.0
margin_bottom = 24.0 margin_bottom = 24.0
text = "0"
value = 0.0
min_value = -65536.0 min_value = -65536.0
max_value = 65536.0 max_value = 65536.0
step = 0.005 step = 0.005
allow_greater = true
allow_lesser = true
[node name="LabelMax" type="Label" parent="."] [node name="LabelMax" type="Label" parent="."]
margin_left = 110.0 margin_left = 94.0
margin_top = 5.0 margin_top = 5.0
margin_right = 140.0 margin_right = 124.0
margin_bottom = 19.0 margin_bottom = 19.0
text = "Max:" text = "Max:"
[node name="Max" type="SpinBox" parent="."] [node name="Max" parent="." instance=ExtResource( 2 )]
margin_left = 144.0 anchor_left = 0.0
margin_right = 218.0 anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 128.0
margin_right = 186.0
margin_bottom = 24.0 margin_bottom = 24.0
text = "1"
value = 1.0
min_value = -65536.0 min_value = -65536.0
max_value = 65536.0 max_value = 65536.0
step = 0.005 step = 0.005
allow_greater = true
allow_lesser = true
[node name="LabelStep" type="Label" parent="."] [node name="LabelStep" type="Label" parent="."]
margin_left = 222.0 margin_left = 190.0
margin_top = 5.0 margin_top = 5.0
margin_right = 254.0 margin_right = 222.0
margin_bottom = 19.0 margin_bottom = 19.0
text = "Step:" text = "Step:"
[node name="Step" type="SpinBox" parent="."] [node name="Step" parent="." instance=ExtResource( 2 )]
margin_left = 258.0 anchor_left = 0.0
margin_right = 332.0 anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 226.0
margin_right = 284.0
margin_bottom = 24.0 margin_bottom = 24.0
text = "0.1"
value = 0.1
max_value = 10.0
step = 0.005 step = 0.005
allow_greater = true
allow_lesser = true
[node name="LabelDefault" type="Label" parent="."] [node name="LabelDefault" type="Label" parent="."]
margin_left = 336.0 margin_left = 288.0
margin_top = 5.0 margin_top = 5.0
margin_right = 386.0 margin_right = 338.0
margin_bottom = 19.0 margin_bottom = 19.0
text = "Default:" text = "Default:"
[node name="Default" type="SpinBox" parent="."] [node name="Default" parent="." instance=ExtResource( 2 )]
margin_left = 390.0 anchor_left = 0.0
margin_right = 464.0 anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 342.0
margin_right = 400.0
margin_bottom = 24.0 margin_bottom = 24.0
min_value = -65536.0 step = 0.1
max_value = 65536.0 [connection signal="value_changed" from="Min" to="." method="_on_Min_value_changed"]
step = 0.0 [connection signal="value_changed" from="Max" to="." method="_on_Max_value_changed"]
allow_greater = true [connection signal="value_changed" from="Step" to="." method="_on_Step_value_changed"]
allow_lesser = true
[node name="SpinBox" type="CheckBox" parent="."]
margin_left = 468.0
margin_right = 547.0
margin_bottom = 24.0
text = "SpinBox"