Added value label to gradient editor cursors + position rounding when Control is held
This commit is contained in:
parent
a1f1407e3d
commit
dd91551f53
|
@ -5,12 +5,18 @@ class GradientCursor:
|
||||||
|
|
||||||
var color : Color
|
var color : Color
|
||||||
var sliding : bool = false
|
var sliding : bool = false
|
||||||
|
|
||||||
|
var label : Label = Label.new()
|
||||||
|
|
||||||
const WIDTH : int = 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)
|
||||||
|
label.rect_position = Vector2(-20, 20)
|
||||||
|
label.rect_min_size = Vector2(50, 20)
|
||||||
|
label.align = Label.ALIGN_LEFT
|
||||||
|
add_child(label)
|
||||||
|
|
||||||
func _draw() -> void:
|
func _draw() -> void:
|
||||||
# warning-ignore:integer_division
|
# warning-ignore:integer_division
|
||||||
|
@ -27,19 +33,25 @@ class GradientCursor:
|
||||||
get_parent().select_color(self, ev.global_position)
|
get_parent().select_color(self, ev.global_position)
|
||||||
elif ev.pressed:
|
elif ev.pressed:
|
||||||
sliding = true
|
sliding = true
|
||||||
|
label.visible = true
|
||||||
|
label.text = "%.03f" % get_cursor_position()
|
||||||
else:
|
else:
|
||||||
sliding = false
|
sliding = false
|
||||||
|
label.visible = false
|
||||||
elif ev.button_index == BUTTON_RIGHT and get_parent().get_sorted_cursors().size() > 2:
|
elif ev.button_index == BUTTON_RIGHT and get_parent().get_sorted_cursors().size() > 2:
|
||||||
var parent = get_parent()
|
var parent = get_parent()
|
||||||
parent.remove_child(self)
|
parent.remove_child(self)
|
||||||
parent.update_value()
|
parent.update_value()
|
||||||
queue_free()
|
queue_free()
|
||||||
elif ev is InputEventMouseMotion and (ev.button_mask & BUTTON_MASK_LEFT) != 0 and sliding:
|
elif ev is InputEventMouseMotion and (ev.button_mask & BUTTON_MASK_LEFT) != 0 and sliding:
|
||||||
rect_position.x += ev.relative.x
|
rect_position.x += get_local_mouse_position().x
|
||||||
|
if ev.control:
|
||||||
|
rect_position.x = round(get_cursor_position()*20.0)*0.05*(get_parent().rect_size.x - WIDTH)
|
||||||
rect_position.x = min(max(0, rect_position.x), get_parent().rect_size.x-rect_size.x)
|
rect_position.x = min(max(0, rect_position.x), get_parent().rect_size.x-rect_size.x)
|
||||||
get_parent().update_value()
|
get_parent().update_value()
|
||||||
|
label.text = "%.03f" % get_cursor_position()
|
||||||
|
|
||||||
func get_position() -> Vector2:
|
func get_cursor_position() -> float:
|
||||||
return rect_position.x / (get_parent().rect_size.x - WIDTH)
|
return rect_position.x / (get_parent().rect_size.x - WIDTH)
|
||||||
|
|
||||||
func set_color(c) -> void:
|
func set_color(c) -> void:
|
||||||
|
|
Loading…
Reference in New Issue