Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions addons/material_maker/types/curve.gd
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@ func compare(curve) -> bool:
return false
return true

func add_point(x : float, y : float, ls : float = INF, rs : float = INF) -> void:
func add_point(x : float, y : float, ls : float = INF, rs : float = INF) -> int:
for i in points.size():
if x < points[i].p.x:
if ls == INF:
ls = 0
if rs == INF:
rs = 0
points.insert(i, Point.new(x, y, ls, rs))
return
return i
points.append(Point.new(x, y, ls, rs))
return -1

func remove_point(index : int) -> bool:
if index <= 0 or index >= points.size() - 1:
Expand Down
42 changes: 38 additions & 4 deletions material_maker/widgets/curve_edit/control_point.gd
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
extends Control

var moving : bool = false
var hovering : bool = false
var is_selected : bool = false

var min_x : float
var max_x : float
var min_y : float
var max_y : float

const OFFSET : Vector2 = Vector2(3, 3)
const OFFSET : Vector2 = Vector2(4, 4)

signal moved(index)
signal removed(index)
signal selected(index)

func _ready():
pass # Replace with function body.

func _draw():
var current_theme : Theme = mm_globals.main_window.theme
var color : Color = current_theme.get_color("font_color", "Label")
var selected_color : Color = current_theme.get_color("icon_pressed_color", "Button")
for c in get_children():
if c.visible:
draw_line(OFFSET, c.position+OFFSET, color)
draw_rect(Rect2(0, 0, 7, 7), color)
draw_line(OFFSET, c.position+OFFSET, color, 0.5, true)
draw_rect(Rect2(Vector2.ZERO, custom_minimum_size), selected_color if is_selected else color, true)
draw_rect(Rect2(Vector2.ZERO, custom_minimum_size), color.inverted(), false)
if hovering or moving:
draw_rect(Rect2(-custom_minimum_size * 0.5, custom_minimum_size * 2.0), color, false, 1.0)
draw_rect(Rect2(-custom_minimum_size*0.5-Vector2(1.0,1.0),
custom_minimum_size*2.0+Vector2(2.0,2.0)), color.inverted(), false, 1.0)

func initialize(p : MMCurve.Point) -> void:
position = get_parent().transform_point(p.p)-OFFSET
Expand All @@ -41,13 +50,27 @@ func _on_ControlPoint_gui_input(event):
if event.button_index == MOUSE_BUTTON_LEFT:
if event.pressed:
moving = true
is_selected = true
emit_signal("selected", get_index())
queue_redraw()
else:
moving = false
is_selected = false
queue_redraw()
get_parent().update_controls()
elif event.button_index == MOUSE_BUTTON_RIGHT and event.pressed:
emit_signal("removed", get_index())
elif moving and event is InputEventMouseMotion:
position += event.relative
var new_pos : Vector2 = position + event.relative
if event.is_command_or_control_pressed():
if get_parent().axes_density > 1.0:
var snap : float = 1.0 / (get_parent().axes_density - 1.0)
new_pos = position + (event.position - custom_minimum_size / 2.0)
new_pos /= get_parent_control().size
new_pos = snapped(new_pos, Vector2(snap, snap))
new_pos *= get_parent_control().size
new_pos -= custom_minimum_size/2.0
position = new_pos
if position.x < min_x:
position.x = min_x
elif position.x > max_x:
Expand All @@ -61,3 +84,14 @@ func _on_ControlPoint_gui_input(event):
func update_tangents() -> void:
queue_redraw()
emit_signal("moved", get_index())
emit_signal("selected", get_index())


func _on_mouse_entered() -> void:
queue_redraw()
hovering = true


func _on_mouse_exited() -> void:
queue_redraw()
hovering = false
36 changes: 19 additions & 17 deletions material_maker/widgets/curve_edit/control_point.tscn
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
[gd_scene load_steps=3 format=3 uid="uid://bhr7y7noxv5e6"]

[ext_resource type="Script" path="res://material_maker/widgets/curve_edit/slope_point.gd" id="1"]
[ext_resource type="Script" path="res://material_maker/widgets/curve_edit/control_point.gd" id="2"]
[ext_resource type="Script" uid="uid://dl376nblfgqfs" path="res://material_maker/widgets/curve_edit/slope_point.gd" id="1"]
[ext_resource type="Script" uid="uid://lfjxe7jh8oyu" path="res://material_maker/widgets/curve_edit/control_point.gd" id="2"]

[node name="ControlPoint" type="Control"]
custom_minimum_size = Vector2(8, 8)
layout_mode = 3
anchors_preset = 0
offset_left = 56.9864
offset_top = 33.8615
offset_right = 63.9864
offset_bottom = 40.8615
custom_minimum_size = Vector2(7, 7)
script = ExtResource("2")
__meta__ = {
"_edit_use_anchors_": false
}

[node name="LeftSlope" type="Control" parent="."]
offset_left = -18.5235
offset_right = -11.5235
offset_bottom = 7.0
custom_minimum_size = Vector2(7, 7)
anchors_preset = 0
offset_left = -18.524
offset_right = -11.524
offset_bottom = 7.0
script = ExtResource("1")
__meta__ = {
"_edit_use_anchors_": false
}
distance = -30.0

[node name="RightSlope" type="Control" parent="."]
offset_left = 15.6919
offset_right = 22.6919
custom_minimum_size = Vector2(7, 7)
anchors_preset = 0
offset_left = 15.692
offset_right = 22.692
offset_bottom = 7.0
script = ExtResource("1")
__meta__ = {
"_edit_use_anchors_": false
}
distance = 30.0

[connection signal="gui_input" from="." to="." method="_on_ControlPoint_gui_input"]
[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"]
[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"]
[connection signal="gui_input" from="LeftSlope" to="LeftSlope" method="_on_ControlPoint_gui_input"]
[connection signal="mouse_entered" from="LeftSlope" to="LeftSlope" method="_on_mouse_entered"]
[connection signal="mouse_exited" from="LeftSlope" to="LeftSlope" method="_on_mouse_exited"]
[connection signal="gui_input" from="RightSlope" to="RightSlope" method="_on_ControlPoint_gui_input"]
[connection signal="mouse_entered" from="RightSlope" to="RightSlope" method="_on_mouse_entered"]
[connection signal="mouse_exited" from="RightSlope" to="RightSlope" method="_on_mouse_exited"]
1 change: 1 addition & 0 deletions material_maker/widgets/curve_edit/curve_dialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ func _on_Invert_pressed() -> void:
for p in old_curve.points:
new_curve.add_point(p.p.x, 1.0 - p.p.y, -p.ls, -p.rs)
$VBoxContainer/EditorContainer/CurveEditor.set_curve(new_curve)
$VBoxContainer/EditorContainer/CurveEditor.update_control_ui()
109 changes: 106 additions & 3 deletions material_maker/widgets/curve_edit/curve_dialog.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
[gd_scene load_steps=4 format=3 uid="uid://dmfusfaiojjvf"]
[gd_scene load_steps=6 format=3 uid="uid://dmfusfaiojjvf"]

[ext_resource type="PackedScene" uid="uid://c2ns17avhb2nx" path="res://material_maker/widgets/curve_edit/curve_editor.tscn" id="1"]
[ext_resource type="Script" path="res://material_maker/widgets/curve_edit/curve_dialog.gd" id="2"]
[ext_resource type="Script" path="res://material_maker/widgets/curve_edit/presets_selector.gd" id="3"]
[ext_resource type="Script" uid="uid://06osuiqfmilt" path="res://material_maker/widgets/curve_edit/curve_dialog.gd" id="2"]
[ext_resource type="Script" uid="uid://pgn60kk5fcj6" path="res://material_maker/widgets/curve_edit/settings_panel.gd" id="2_fe25e"]
[ext_resource type="Script" uid="uid://df24muo083lfx" path="res://material_maker/widgets/curve_edit/presets_selector.gd" id="3"]
[ext_resource type="PackedScene" uid="uid://rflulhsuy3ax" path="res://material_maker/widgets/float_edit/float_edit.tscn" id="3_fe25e"]

[node name="CurveDialog" type="Window"]
title = "Edit curve"
position = Vector2i(0, 36)
size = Vector2i(300, 300)
exclusive = true
min_size = Vector2i(300, 300)
Expand All @@ -20,16 +23,107 @@ offset_top = 5.0
offset_right = -5.0
offset_bottom = -5.0

[node name="CurveViewSettingsContainer" type="MarginContainer" parent="VBoxContainer"]
layout_mode = 2
theme_override_constants/margin_left = 12
theme_override_constants/margin_top = 4

[node name="CurveViewSettings" type="PanelContainer" parent="VBoxContainer/CurveViewSettingsContainer"]
layout_mode = 2
size_flags_horizontal = 0
theme_type_variation = &"MM_PanelMenuBar"
script = ExtResource("2_fe25e")

[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/CurveViewSettingsContainer/CurveViewSettings"]
layout_mode = 2
size_flags_horizontal = 0

[node name="GridLabel" type="Label" parent="VBoxContainer/CurveViewSettingsContainer/CurveViewSettings/HBoxContainer"]
layout_mode = 2
text = "Grid"

[node name="GridDensity" parent="VBoxContainer/CurveViewSettingsContainer/CurveViewSettings/HBoxContainer" instance=ExtResource("3_fe25e")]
unique_name_in_owner = true
layout_mode = 2
value = 4.0
min_value = 1.0
max_value = 16.0
step = 1.0
float_only = true

[node name="EditorContainer" type="MarginContainer" parent="VBoxContainer"]
clip_contents = true
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_constants/margin_left = 12
theme_override_constants/margin_top = 12
theme_override_constants/margin_right = 12
theme_override_constants/margin_bottom = 12

[node name="CurveEditor" parent="VBoxContainer/EditorContainer" instance=ExtResource("1")]
unique_name_in_owner = true
layout_mode = 2
size_flags_vertical = 3

[node name="ControlUIContainer" type="VBoxContainer" parent="VBoxContainer"]
custom_minimum_size = Vector2(0, 23)
layout_mode = 2

[node name="ControlUI" type="HBoxContainer" parent="VBoxContainer/ControlUIContainer"]
unique_name_in_owner = true
visible = false
layout_mode = 2
size_flags_horizontal = 4

[node name="PositionLabel" type="Label" parent="VBoxContainer/ControlUIContainer/ControlUI"]
layout_mode = 2
text = "Position"

[node name="PositionX" parent="VBoxContainer/ControlUIContainer/ControlUI" instance=ExtResource("3_fe25e")]
unique_name_in_owner = true
custom_minimum_size = Vector2(70, 0)
layout_mode = 2
value = 1.0
step = 0.01
float_only = true

[node name="PositionY" parent="VBoxContainer/ControlUIContainer/ControlUI" instance=ExtResource("3_fe25e")]
unique_name_in_owner = true
custom_minimum_size = Vector2(70, 0)
layout_mode = 2
value = 0.0
step = 0.01
float_only = true

[node name="Spacer" type="Control" parent="VBoxContainer/ControlUIContainer/ControlUI"]
custom_minimum_size = Vector2(12, 0)
layout_mode = 2

[node name="SlopeLabel" type="Label" parent="VBoxContainer/ControlUIContainer/ControlUI"]
layout_mode = 2
text = "Handles"

[node name="LeftSlope" parent="VBoxContainer/ControlUIContainer/ControlUI" instance=ExtResource("3_fe25e")]
unique_name_in_owner = true
custom_minimum_size = Vector2(70, 0)
layout_mode = 2
value = 0.0
min_value = -89.0
max_value = 89.0
step = 0.1
float_only = true

[node name="RightSlope" parent="VBoxContainer/ControlUIContainer/ControlUI" instance=ExtResource("3_fe25e")]
unique_name_in_owner = true
custom_minimum_size = Vector2(70, 0)
layout_mode = 2
value = 45.0
min_value = -89.0
max_value = 89.0
step = 0.1
float_only = true

[node name="HSeparator" type="HSeparator" parent="VBoxContainer"]
layout_mode = 2

Expand Down Expand Up @@ -63,7 +157,16 @@ layout_mode = 2
text = "Cancel"

[connection signal="close_requested" from="." to="." method="_on_Cancel_pressed"]
[connection signal="ready" from="VBoxContainer/CurveViewSettingsContainer/CurveViewSettings" to="VBoxContainer/CurveViewSettingsContainer/CurveViewSettings" method="_on_ready"]
[connection signal="value_changed" from="VBoxContainer/CurveViewSettingsContainer/CurveViewSettings/HBoxContainer/GridDensity" to="VBoxContainer/CurveViewSettingsContainer/CurveViewSettings" method="_on_grid_density_value_changed"]
[connection signal="value_changed" from="VBoxContainer/EditorContainer/CurveEditor" to="." method="_on_CurveEditor_value_changed"]
[connection signal="gui_input" from="VBoxContainer/EditorContainer/CurveEditor/@Control@283287" to="VBoxContainer/EditorContainer/CurveEditor/@Control@283287" method="_on_ControlPoint_gui_input"]
[connection signal="mouse_entered" from="VBoxContainer/EditorContainer/CurveEditor/@Control@283287" to="VBoxContainer/EditorContainer/CurveEditor/@Control@283287" method="_on_mouse_entered"]
[connection signal="mouse_exited" from="VBoxContainer/EditorContainer/CurveEditor/@Control@283287" to="VBoxContainer/EditorContainer/CurveEditor/@Control@283287" method="_on_mouse_exited"]
[connection signal="value_changed" from="VBoxContainer/ControlUIContainer/ControlUI/PositionX" to="VBoxContainer/EditorContainer/CurveEditor" method="_on_position_x_value_changed"]
[connection signal="value_changed" from="VBoxContainer/ControlUIContainer/ControlUI/PositionY" to="VBoxContainer/EditorContainer/CurveEditor" method="_on_position_y_value_changed"]
[connection signal="value_changed" from="VBoxContainer/ControlUIContainer/ControlUI/LeftSlope" to="VBoxContainer/EditorContainer/CurveEditor" method="_on_left_slope_value_changed"]
[connection signal="value_changed" from="VBoxContainer/ControlUIContainer/ControlUI/RightSlope" to="VBoxContainer/EditorContainer/CurveEditor" method="_on_right_slope_value_changed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Invert" to="." method="_on_Invert_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/OK" to="." method="_on_OK_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Cancel" to="." method="_on_Cancel_pressed"]
8 changes: 7 additions & 1 deletion material_maker/widgets/curve_edit/curve_edit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ var value = null: set = set_value

signal updated(curve, old_value)


func _ready():
set_value(MMCurve.new())


func set_value(v) -> void:
value = v.duplicate()
$CurveView.curve = value
$CurveView.queue_redraw()


func _on_CurveEdit_pressed():
var dialog = preload("res://material_maker/widgets/curve_edit/curve_dialog.tscn").instantiate()
var content_scale_factor = mm_globals.main_window.get_window().content_scale_factor
Expand All @@ -25,10 +28,12 @@ func _on_CurveEdit_pressed():
set_value(new_curve.value)
emit_signal("updated", new_curve.value.duplicate(), null if new_curve.value.compare(new_curve.previous_value) else new_curve.previous_value)


func on_value_changed(v) -> void:
set_value(v)
emit_signal("updated", v.duplicate(), null)


func _get_drag_data(_position) -> MMCurve:
var duplicated_value = value.duplicate()
var view = CurveView.new(duplicated_value)
Expand All @@ -39,9 +44,10 @@ func _get_drag_data(_position) -> MMCurve:
set_drag_preview(button)
return duplicated_value


func _can_drop_data(_position, data) -> bool:
return data is MMCurve


func _drop_data(_position, data) -> void:
var old_curve : MMCurve = value
Expand Down
4 changes: 1 addition & 3 deletions material_maker/widgets/curve_edit/curve_edit.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=3 format=3 uid="uid://cvv8rhglg3jlm"]

[ext_resource type="Script" path="res://material_maker/widgets/curve_edit/curve_edit.gd" id="1"]
[ext_resource type="Script" uid="uid://cd0ugv3swm5os" path="res://material_maker/widgets/curve_edit/curve_edit.gd" id="1"]
[ext_resource type="PackedScene" uid="uid://yeaj0tj7b08i" path="res://material_maker/widgets/curve_edit/curve_view.tscn" id="2"]

[node name="CurveEdit" type="Button"]
Expand All @@ -21,7 +21,5 @@ offset_left = 0.0
offset_top = 0.0
offset_right = 0.0
offset_bottom = 0.0
grow_horizontal = 2
grow_vertical = 2

[connection signal="pressed" from="." to="." method="_on_CurveEdit_pressed"]
Loading