Skip to content

Commit c19e5d4

Browse files
committed
Enable AA for CurveView curve
1 parent 23463a3 commit c19e5d4

File tree

13 files changed

+258
-36
lines changed

13 files changed

+258
-36
lines changed

addons/material_maker/types/curve.gd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,17 @@ func compare(curve) -> bool:
3838
return false
3939
return true
4040

41-
func add_point(x : float, y : float, ls : float = INF, rs : float = INF) -> void:
41+
func add_point(x : float, y : float, ls : float = INF, rs : float = INF) -> int:
4242
for i in points.size():
4343
if x < points[i].p.x:
4444
if ls == INF:
4545
ls = 0
4646
if rs == INF:
4747
rs = 0
4848
points.insert(i, Point.new(x, y, ls, rs))
49-
return
49+
return i
5050
points.append(Point.new(x, y, ls, rs))
51+
return -1
5152

5253
func remove_point(index : int) -> bool:
5354
if index <= 0 or index >= points.size() - 1:

material_maker/widgets/curve_edit/control_point.gd

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
extends Control
22

33
var moving : bool = false
4+
var hovering : bool = false
5+
var is_selected : bool = false
46

57
var min_x : float
68
var max_x : float
@@ -11,17 +13,22 @@ const OFFSET : Vector2 = Vector2(3, 3)
1113

1214
signal moved(index)
1315
signal removed(index)
16+
signal selected(index)
1417

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

1821
func _draw():
1922
var current_theme : Theme = mm_globals.main_window.theme
2023
var color : Color = current_theme.get_color("font_color", "Label")
24+
var selected_color : Color = current_theme.get_color("icon_pressed_color", "Button")
2125
for c in get_children():
2226
if c.visible:
23-
draw_line(OFFSET, c.position+OFFSET, color)
24-
draw_rect(Rect2(0, 0, 7, 7), color)
27+
draw_line(OFFSET, c.position+OFFSET, color, 0.5, true)
28+
draw_rect(Rect2(Vector2.ZERO, custom_minimum_size), selected_color if is_selected else color, true)
29+
if hovering or moving:
30+
draw_rect(Rect2(-custom_minimum_size / 2.0,
31+
custom_minimum_size * 2.0), color, false, 0.5)
2532

2633
func initialize(p : MMCurve.Point) -> void:
2734
position = get_parent().transform_point(p.p)-OFFSET
@@ -41,8 +48,13 @@ func _on_ControlPoint_gui_input(event):
4148
if event.button_index == MOUSE_BUTTON_LEFT:
4249
if event.pressed:
4350
moving = true
51+
is_selected = true
52+
emit_signal("selected", get_index())
53+
queue_redraw()
4454
else:
4555
moving = false
56+
is_selected = false
57+
queue_redraw()
4658
get_parent().update_controls()
4759
elif event.button_index == MOUSE_BUTTON_RIGHT and event.pressed:
4860
emit_signal("removed", get_index())
@@ -61,3 +73,14 @@ func _on_ControlPoint_gui_input(event):
6173
func update_tangents() -> void:
6274
queue_redraw()
6375
emit_signal("moved", get_index())
76+
emit_signal("selected", get_index())
77+
78+
79+
func _on_mouse_entered() -> void:
80+
queue_redraw()
81+
hovering = true
82+
83+
84+
func _on_mouse_exited() -> void:
85+
queue_redraw()
86+
hovering = false
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
11
[gd_scene load_steps=3 format=3 uid="uid://bhr7y7noxv5e6"]
22

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

66
[node name="ControlPoint" type="Control"]
7+
custom_minimum_size = Vector2(9, 9)
8+
layout_mode = 3
9+
anchors_preset = 0
710
offset_left = 56.9864
811
offset_top = 33.8615
912
offset_right = 63.9864
1013
offset_bottom = 40.8615
11-
custom_minimum_size = Vector2(7, 7)
1214
script = ExtResource("2")
13-
__meta__ = {
14-
"_edit_use_anchors_": false
15-
}
1615

1716
[node name="LeftSlope" type="Control" parent="."]
17+
custom_minimum_size = Vector2(7, 7)
18+
anchors_preset = 0
1819
offset_left = -18.5235
1920
offset_right = -11.5235
2021
offset_bottom = 7.0
21-
custom_minimum_size = Vector2(7, 7)
2222
script = ExtResource("1")
23-
__meta__ = {
24-
"_edit_use_anchors_": false
25-
}
2623
distance = -30.0
2724

2825
[node name="RightSlope" type="Control" parent="."]
26+
anchors_preset = 0
2927
offset_left = 15.6919
3028
offset_right = 22.6919
3129
offset_bottom = 7.0
3230
script = ExtResource("1")
33-
__meta__ = {
34-
"_edit_use_anchors_": false
35-
}
3631
distance = 30.0
3732

3833
[connection signal="gui_input" from="." to="." method="_on_ControlPoint_gui_input"]
34+
[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"]
35+
[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"]
3936
[connection signal="gui_input" from="LeftSlope" to="LeftSlope" method="_on_ControlPoint_gui_input"]
37+
[connection signal="mouse_entered" from="LeftSlope" to="LeftSlope" method="_on_mouse_entered"]
38+
[connection signal="mouse_exited" from="LeftSlope" to="LeftSlope" method="_on_mouse_exited"]
4039
[connection signal="gui_input" from="RightSlope" to="RightSlope" method="_on_ControlPoint_gui_input"]
40+
[connection signal="mouse_entered" from="RightSlope" to="RightSlope" method="_on_mouse_entered"]
41+
[connection signal="mouse_exited" from="RightSlope" to="RightSlope" method="_on_mouse_exited"]

material_maker/widgets/curve_edit/curve_dialog.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ func _on_Invert_pressed() -> void:
3636
for p in old_curve.points:
3737
new_curve.add_point(p.p.x, 1.0 - p.p.y, -p.ls, -p.rs)
3838
$VBoxContainer/EditorContainer/CurveEditor.set_curve(new_curve)
39+
$VBoxContainer/EditorContainer/CurveEditor.update_control_ui()

material_maker/widgets/curve_edit/curve_dialog.tscn

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
[gd_scene load_steps=4 format=3 uid="uid://dmfusfaiojjvf"]
1+
[gd_scene load_steps=5 format=3 uid="uid://dmfusfaiojjvf"]
22

33
[ext_resource type="PackedScene" uid="uid://c2ns17avhb2nx" path="res://material_maker/widgets/curve_edit/curve_editor.tscn" id="1"]
4-
[ext_resource type="Script" path="res://material_maker/widgets/curve_edit/curve_dialog.gd" id="2"]
5-
[ext_resource type="Script" path="res://material_maker/widgets/curve_edit/presets_selector.gd" id="3"]
4+
[ext_resource type="Script" uid="uid://06osuiqfmilt" path="res://material_maker/widgets/curve_edit/curve_dialog.gd" id="2"]
5+
[ext_resource type="Script" uid="uid://df24muo083lfx" path="res://material_maker/widgets/curve_edit/presets_selector.gd" id="3"]
6+
[ext_resource type="PackedScene" uid="uid://rflulhsuy3ax" path="res://material_maker/widgets/float_edit/float_edit.tscn" id="3_fe25e"]
67

78
[node name="CurveDialog" type="Window"]
89
title = "Edit curve"
10+
position = Vector2i(0, 36)
911
size = Vector2i(300, 300)
1012
exclusive = true
1113
min_size = Vector2i(300, 300)
@@ -25,11 +27,73 @@ clip_contents = true
2527
layout_mode = 2
2628
size_flags_horizontal = 3
2729
size_flags_vertical = 3
30+
theme_override_constants/margin_left = 12
31+
theme_override_constants/margin_top = 12
32+
theme_override_constants/margin_right = 12
33+
theme_override_constants/margin_bottom = 12
2834

2935
[node name="CurveEditor" parent="VBoxContainer/EditorContainer" instance=ExtResource("1")]
3036
layout_mode = 2
3137
size_flags_vertical = 3
3238

39+
[node name="ControlUIContainer" type="VBoxContainer" parent="VBoxContainer"]
40+
custom_minimum_size = Vector2(0, 23)
41+
layout_mode = 2
42+
43+
[node name="ControlUI" type="HBoxContainer" parent="VBoxContainer/ControlUIContainer"]
44+
unique_name_in_owner = true
45+
visible = false
46+
layout_mode = 2
47+
size_flags_horizontal = 4
48+
49+
[node name="PositionLabel" type="Label" parent="VBoxContainer/ControlUIContainer/ControlUI"]
50+
layout_mode = 2
51+
text = "Position"
52+
53+
[node name="PositionX" parent="VBoxContainer/ControlUIContainer/ControlUI" instance=ExtResource("3_fe25e")]
54+
unique_name_in_owner = true
55+
custom_minimum_size = Vector2(70, 0)
56+
layout_mode = 2
57+
value = 1.0
58+
step = 0.01
59+
float_only = true
60+
61+
[node name="PositionY" parent="VBoxContainer/ControlUIContainer/ControlUI" instance=ExtResource("3_fe25e")]
62+
unique_name_in_owner = true
63+
custom_minimum_size = Vector2(70, 0)
64+
layout_mode = 2
65+
value = 0.0
66+
step = 0.01
67+
float_only = true
68+
69+
[node name="Spacer" type="Control" parent="VBoxContainer/ControlUIContainer/ControlUI"]
70+
custom_minimum_size = Vector2(12, 0)
71+
layout_mode = 2
72+
73+
[node name="SlopeLabel" type="Label" parent="VBoxContainer/ControlUIContainer/ControlUI"]
74+
layout_mode = 2
75+
text = "Handles"
76+
77+
[node name="LeftSlope" parent="VBoxContainer/ControlUIContainer/ControlUI" instance=ExtResource("3_fe25e")]
78+
unique_name_in_owner = true
79+
custom_minimum_size = Vector2(70, 0)
80+
layout_mode = 2
81+
value = 0.0
82+
min_value = -89.0
83+
max_value = 89.0
84+
step = 0.1
85+
float_only = true
86+
87+
[node name="RightSlope" parent="VBoxContainer/ControlUIContainer/ControlUI" instance=ExtResource("3_fe25e")]
88+
unique_name_in_owner = true
89+
custom_minimum_size = Vector2(70, 0)
90+
layout_mode = 2
91+
value = 45.0
92+
min_value = -89.0
93+
max_value = 89.0
94+
step = 0.1
95+
float_only = true
96+
3397
[node name="HSeparator" type="HSeparator" parent="VBoxContainer"]
3498
layout_mode = 2
3599

@@ -64,6 +128,11 @@ text = "Cancel"
64128

65129
[connection signal="close_requested" from="." to="." method="_on_Cancel_pressed"]
66130
[connection signal="value_changed" from="VBoxContainer/EditorContainer/CurveEditor" to="." method="_on_CurveEditor_value_changed"]
131+
[connection signal="gui_input" from="VBoxContainer/EditorContainer/CurveEditor/@Control@71539" to="VBoxContainer/EditorContainer/CurveEditor/@Control@71539" method="_on_ControlPoint_gui_input"]
132+
[connection signal="value_changed" from="VBoxContainer/ControlUIContainer/ControlUI/PositionX" to="VBoxContainer/EditorContainer/CurveEditor" method="_on_position_x_value_changed"]
133+
[connection signal="value_changed" from="VBoxContainer/ControlUIContainer/ControlUI/PositionY" to="VBoxContainer/EditorContainer/CurveEditor" method="_on_position_y_value_changed"]
134+
[connection signal="value_changed" from="VBoxContainer/ControlUIContainer/ControlUI/LeftSlope" to="VBoxContainer/EditorContainer/CurveEditor" method="_on_left_slope_value_changed"]
135+
[connection signal="value_changed" from="VBoxContainer/ControlUIContainer/ControlUI/RightSlope" to="VBoxContainer/EditorContainer/CurveEditor" method="_on_right_slope_value_changed"]
67136
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Invert" to="." method="_on_Invert_pressed"]
68137
[connection signal="pressed" from="VBoxContainer/HBoxContainer/OK" to="." method="_on_OK_pressed"]
69138
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Cancel" to="." method="_on_Cancel_pressed"]

material_maker/widgets/curve_edit/curve_edit.gd

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ var value = null: set = set_value
55

66
signal updated(curve, old_value)
77

8+
89
func _ready():
910
set_value(MMCurve.new())
1011

12+
1113
func set_value(v) -> void:
1214
value = v.duplicate()
1315
$CurveView.curve = value
1416
$CurveView.queue_redraw()
1517

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

31+
2832
func on_value_changed(v) -> void:
2933
set_value(v)
3034
emit_signal("updated", v.duplicate(), null)
3135

36+
3237
func _get_drag_data(_position) -> MMCurve:
3338
var duplicated_value = value.duplicate()
3439
var view = CurveView.new(duplicated_value)
@@ -39,9 +44,10 @@ func _get_drag_data(_position) -> MMCurve:
3944
set_drag_preview(button)
4045
return duplicated_value
4146

47+
4248
func _can_drop_data(_position, data) -> bool:
4349
return data is MMCurve
44-
50+
4551

4652
func _drop_data(_position, data) -> void:
4753
var old_curve : MMCurve = value

material_maker/widgets/curve_edit/curve_edit.tscn

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[gd_scene load_steps=3 format=3 uid="uid://cvv8rhglg3jlm"]
22

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

66
[node name="CurveEdit" type="Button"]
@@ -21,7 +21,5 @@ offset_left = 0.0
2121
offset_top = 0.0
2222
offset_right = 0.0
2323
offset_bottom = 0.0
24-
grow_horizontal = 2
25-
grow_vertical = 2
2624

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

0 commit comments

Comments
 (0)