diff --git a/addons/material_maker/widgets/gradient_editor.gd b/addons/material_maker/widgets/gradient_editor.gd index 11cacb2..fa223de 100644 --- a/addons/material_maker/widgets/gradient_editor.gd +++ b/addons/material_maker/widgets/gradient_editor.gd @@ -3,13 +3,21 @@ extends Control class_name MMGradientEditor class GradientCursor: - extends ColorRect + extends Control + + var color : Color - const WIDTH = 10 + const WIDTH : int = 10 func _ready() -> void: rect_position = Vector2(0, 15) rect_size = Vector2(WIDTH, 15) + + func _draw(): + var polygon : PoolVector2Array = PoolVector2Array([Vector2(0, 5), Vector2(WIDTH/2, 0), Vector2(WIDTH, 5), Vector2(WIDTH, 15), Vector2(0, 15)]) + var c = color + c.a = 1.0 + draw_colored_polygon(polygon, c) func _gui_input(ev) -> void: if ev is InputEventMouseButton: @@ -35,11 +43,6 @@ class GradientCursor: static func sort(a, b) -> bool: return a.get_position() < b.get_position() - func _draw() -> void: - var c = color - c.a = 1.0 - draw_rect(Rect2(0, 0, rect_size.x, rect_size.y), c, false) - var value = null setget set_value export var embedded : bool = true @@ -62,7 +65,7 @@ func set_value(v) -> void: func update_value() -> void: value.clear() for p in get_children(): - if p != $Gradient && p != $Background: + if p != $Gradient and p != $Background: value.add_point(p.rect_position.x/(rect_size.x-GradientCursor.WIDTH), p.color) update_shader() @@ -75,7 +78,7 @@ func add_cursor(x, color) -> void: func _gui_input(ev) -> void: if ev is InputEventMouseButton && ev.button_index == 1 && ev.doubleclick: if ev.position.y > 15: - var p = max(0, min(ev.position.x, rect_size.x-GradientCursor.WIDTH)) + var p = clamp(ev.position.x, 0, rect_size.x-GradientCursor.WIDTH) add_cursor(p, get_gradient_color(p)) update_value() elif embedded: diff --git a/addons/material_maker/widgets/gradient_editor.tscn b/addons/material_maker/widgets/gradient_editor.tscn index 6797ae3..841c50a 100644 --- a/addons/material_maker/widgets/gradient_editor.tscn +++ b/addons/material_maker/widgets/gradient_editor.tscn @@ -12,20 +12,18 @@ void fragment() { [sub_resource type="ShaderMaterial" id=2] shader = SubResource( 1 ) -[sub_resource type="Shader" id=3] +[sub_resource type="Shader" id=6] code = "shader_type canvas_item; vec4 gradient(float x) { if (x < 0.000000000) { return vec4(0.000000000,0.000000000,0.000000000,0.000000000); - } else if (x < 1.000000000) { - return vec4(0.000000000,0.000000000,0.000000000,0.000000000)+x*vec4(1.000000000,1.000000000,1.000000000,1.000000000); } - return vec4(1.000000000,1.000000000,1.000000000,1.000000000); + return vec4(0.000000000,0.000000000,0.000000000,0.000000000); } void fragment() { COLOR = gradient(UV.x); }" -[sub_resource type="ShaderMaterial" id=4] -shader = SubResource( 3 ) +[sub_resource type="ShaderMaterial" id=7] +shader = SubResource( 6 ) [sub_resource type="Theme" id=5] @@ -38,13 +36,19 @@ script = ExtResource( 1 ) [node name="Background" type="ColorRect" parent="."] material = SubResource( 2 ) anchor_right = 1.0 -rect_min_size = Vector2( 120, 20 ) +margin_left = 4.0 +margin_right = -4.0 +margin_bottom = 15.0 +rect_min_size = Vector2( 112, 17 ) mouse_filter = 2 [node name="Gradient" type="ColorRect" parent="."] -material = SubResource( 4 ) +material = SubResource( 7 ) anchor_right = 1.0 -rect_min_size = Vector2( 120, 20 ) +margin_left = 4.0 +margin_right = -4.0 +margin_bottom = 15.0 +rect_min_size = Vector2( 112, 17 ) mouse_filter = 2 theme = SubResource( 5 )