mirror of
https://github.com/Relintai/material-maker.git
synced 2024-11-13 06:27:18 +01:00
Updated the gradient editor
This commit is contained in:
parent
aaa2adc046
commit
4246673c85
@ -3,13 +3,21 @@ extends Control
|
|||||||
class_name MMGradientEditor
|
class_name MMGradientEditor
|
||||||
|
|
||||||
class GradientCursor:
|
class GradientCursor:
|
||||||
extends ColorRect
|
extends Control
|
||||||
|
|
||||||
|
var color : Color
|
||||||
|
|
||||||
const WIDTH = 10
|
const WIDTH : int = 10
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
rect_position = Vector2(0, 15)
|
rect_position = Vector2(0, 15)
|
||||||
rect_size = Vector2(WIDTH, 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:
|
func _gui_input(ev) -> void:
|
||||||
if ev is InputEventMouseButton:
|
if ev is InputEventMouseButton:
|
||||||
@ -35,11 +43,6 @@ class GradientCursor:
|
|||||||
static func sort(a, b) -> bool:
|
static func sort(a, b) -> bool:
|
||||||
return a.get_position() < b.get_position()
|
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
|
var value = null setget set_value
|
||||||
export var embedded : bool = true
|
export var embedded : bool = true
|
||||||
|
|
||||||
@ -62,7 +65,7 @@ func set_value(v) -> void:
|
|||||||
func update_value() -> void:
|
func update_value() -> void:
|
||||||
value.clear()
|
value.clear()
|
||||||
for p in get_children():
|
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)
|
value.add_point(p.rect_position.x/(rect_size.x-GradientCursor.WIDTH), p.color)
|
||||||
update_shader()
|
update_shader()
|
||||||
|
|
||||||
@ -75,7 +78,7 @@ func add_cursor(x, color) -> void:
|
|||||||
func _gui_input(ev) -> void:
|
func _gui_input(ev) -> void:
|
||||||
if ev is InputEventMouseButton && ev.button_index == 1 && ev.doubleclick:
|
if ev is InputEventMouseButton && ev.button_index == 1 && ev.doubleclick:
|
||||||
if ev.position.y > 15:
|
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))
|
add_cursor(p, get_gradient_color(p))
|
||||||
update_value()
|
update_value()
|
||||||
elif embedded:
|
elif embedded:
|
||||||
|
@ -12,20 +12,18 @@ void fragment() {
|
|||||||
[sub_resource type="ShaderMaterial" id=2]
|
[sub_resource type="ShaderMaterial" id=2]
|
||||||
shader = SubResource( 1 )
|
shader = SubResource( 1 )
|
||||||
|
|
||||||
[sub_resource type="Shader" id=3]
|
[sub_resource type="Shader" id=6]
|
||||||
code = "shader_type canvas_item;
|
code = "shader_type canvas_item;
|
||||||
vec4 gradient(float x) {
|
vec4 gradient(float x) {
|
||||||
if (x < 0.000000000) {
|
if (x < 0.000000000) {
|
||||||
return vec4(0.000000000,0.000000000,0.000000000,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); }"
|
void fragment() { COLOR = gradient(UV.x); }"
|
||||||
|
|
||||||
[sub_resource type="ShaderMaterial" id=4]
|
[sub_resource type="ShaderMaterial" id=7]
|
||||||
shader = SubResource( 3 )
|
shader = SubResource( 6 )
|
||||||
|
|
||||||
[sub_resource type="Theme" id=5]
|
[sub_resource type="Theme" id=5]
|
||||||
|
|
||||||
@ -38,13 +36,19 @@ script = ExtResource( 1 )
|
|||||||
[node name="Background" type="ColorRect" parent="."]
|
[node name="Background" type="ColorRect" parent="."]
|
||||||
material = SubResource( 2 )
|
material = SubResource( 2 )
|
||||||
anchor_right = 1.0
|
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
|
mouse_filter = 2
|
||||||
|
|
||||||
[node name="Gradient" type="ColorRect" parent="."]
|
[node name="Gradient" type="ColorRect" parent="."]
|
||||||
material = SubResource( 4 )
|
material = SubResource( 7 )
|
||||||
anchor_right = 1.0
|
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
|
mouse_filter = 2
|
||||||
theme = SubResource( 5 )
|
theme = SubResource( 5 )
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user