mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 09:09:47 +00:00
Add support for gradient presets
This commit is contained in:
parent
48130809c9
commit
1f6998e723
|
@ -19,9 +19,14 @@ var active_cursor: GradientCursor: ## Showing a color picker popup to change a
|
||||||
i.queue_redraw()
|
i.queue_redraw()
|
||||||
var texture := GradientTexture2D.new()
|
var texture := GradientTexture2D.new()
|
||||||
var gradient := Gradient.new()
|
var gradient := Gradient.new()
|
||||||
|
var presets: Array[Gradient] = []
|
||||||
|
|
||||||
@onready var x_offset: float = size.x - GradientCursor.WIDTH
|
@onready var x_offset: float = size.x - GradientCursor.WIDTH
|
||||||
@onready var offset_value_slider := %OffsetValueSlider as ValueSlider
|
@onready var offset_value_slider := %OffsetValueSlider as ValueSlider
|
||||||
|
@onready var interpolation_option_button: OptionButton = %InterpolationOptionButton
|
||||||
|
@onready var color_space_option_button: OptionButton = %ColorSpaceOptionButton
|
||||||
|
@onready var tools_menu_button: MenuButton = %ToolsMenuButton
|
||||||
|
@onready var presets_menu_button: MenuButton = %PresetsMenuButton
|
||||||
@onready var texture_rect := $TextureRect as TextureRect
|
@onready var texture_rect := $TextureRect as TextureRect
|
||||||
@onready var color_picker := $Popup.get_node("ColorPicker") as ColorPicker
|
@onready var color_picker := $Popup.get_node("ColorPicker") as ColorPicker
|
||||||
@onready var divide_dialog := $DivideConfirmationDialog as ConfirmationDialog
|
@onready var divide_dialog := $DivideConfirmationDialog as ConfirmationDialog
|
||||||
|
@ -131,14 +136,23 @@ class GradientCursor:
|
||||||
|
|
||||||
func _init() -> void:
|
func _init() -> void:
|
||||||
texture.gradient = gradient
|
texture.gradient = gradient
|
||||||
|
presets.append(Gradient.new()) # Left to right
|
||||||
|
presets.append(Gradient.new()) # Left to transparent
|
||||||
|
presets.append(Gradient.new()) # Black to white
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
texture_rect.texture = texture
|
texture_rect.texture = texture
|
||||||
_create_cursors()
|
_create_cursors()
|
||||||
%InterpolationOptionButton.select(gradient.interpolation_mode)
|
interpolation_option_button.select(gradient.interpolation_mode)
|
||||||
%ColorSpaceOptionButton.select(gradient.interpolation_color_space)
|
color_space_option_button.select(gradient.interpolation_color_space)
|
||||||
%ToolsMenuButton.get_popup().index_pressed.connect(_on_tools_menu_button_index_pressed)
|
tools_menu_button.get_popup().index_pressed.connect(_on_tools_menu_button_index_pressed)
|
||||||
|
presets_menu_button.get_popup().index_pressed.connect(_on_presets_menu_button_index_pressed)
|
||||||
|
for preset in presets:
|
||||||
|
var grad_texture := GradientTexture2D.new()
|
||||||
|
grad_texture.height = 32
|
||||||
|
grad_texture.gradient = preset
|
||||||
|
presets_menu_button.get_popup().add_icon_item(grad_texture, "")
|
||||||
|
|
||||||
|
|
||||||
func _create_cursors() -> void:
|
func _create_cursors() -> void:
|
||||||
|
@ -256,6 +270,22 @@ func _on_tools_menu_button_index_pressed(index: int) -> void:
|
||||||
divide_dialog.popup_centered()
|
divide_dialog.popup_centered()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_presets_menu_button_about_to_popup() -> void:
|
||||||
|
# Update left to right and left to transparent gradients
|
||||||
|
presets[0].set_color(0, Tools.get_assigned_color(MOUSE_BUTTON_LEFT))
|
||||||
|
presets[0].set_color(1, Tools.get_assigned_color(MOUSE_BUTTON_RIGHT))
|
||||||
|
presets[1].set_color(0, Tools.get_assigned_color(MOUSE_BUTTON_LEFT))
|
||||||
|
presets[1].set_color(1, Color(0, 0, 0, 0))
|
||||||
|
|
||||||
|
|
||||||
|
func _on_presets_menu_button_index_pressed(index: int) -> void:
|
||||||
|
var item_icon := presets_menu_button.get_popup().get_item_icon(index) as GradientTexture2D
|
||||||
|
gradient = item_icon.gradient.duplicate()
|
||||||
|
texture.gradient = gradient
|
||||||
|
_create_cursors()
|
||||||
|
updated.emit(gradient, continuous_change)
|
||||||
|
|
||||||
|
|
||||||
func _on_DivideConfirmationDialog_confirmed() -> void:
|
func _on_DivideConfirmationDialog_confirmed() -> void:
|
||||||
var add_point_to_end := add_point_end_check_box.button_pressed
|
var add_point_to_end := add_point_end_check_box.button_pressed
|
||||||
var parts := number_of_parts_spin_box.value
|
var parts := number_of_parts_spin_box.value
|
||||||
|
|
|
@ -15,6 +15,7 @@ layout_mode = 2
|
||||||
|
|
||||||
[node name="OffsetValueSlider" type="TextureProgressBar" parent="InterpolationContainer"]
|
[node name="OffsetValueSlider" type="TextureProgressBar" parent="InterpolationContainer"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
|
custom_minimum_size = Vector2(64, 0)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
focus_mode = 2
|
focus_mode = 2
|
||||||
|
@ -38,6 +39,7 @@ size_flags_horizontal = 3
|
||||||
tooltip_text = "Interpolation"
|
tooltip_text = "Interpolation"
|
||||||
mouse_default_cursor_shape = 2
|
mouse_default_cursor_shape = 2
|
||||||
selected = 0
|
selected = 0
|
||||||
|
fit_to_longest_item = false
|
||||||
item_count = 3
|
item_count = 3
|
||||||
popup/item_0/text = "Linear"
|
popup/item_0/text = "Linear"
|
||||||
popup/item_1/text = "Constant"
|
popup/item_1/text = "Constant"
|
||||||
|
@ -52,6 +54,7 @@ size_flags_horizontal = 3
|
||||||
tooltip_text = "Color space"
|
tooltip_text = "Color space"
|
||||||
mouse_default_cursor_shape = 2
|
mouse_default_cursor_shape = 2
|
||||||
selected = 0
|
selected = 0
|
||||||
|
fit_to_longest_item = false
|
||||||
item_count = 3
|
item_count = 3
|
||||||
popup/item_0/text = "sRGB"
|
popup/item_0/text = "sRGB"
|
||||||
popup/item_1/text = "Linear sRGB"
|
popup/item_1/text = "Linear sRGB"
|
||||||
|
@ -74,6 +77,14 @@ popup/item_1/id = 1
|
||||||
popup/item_2/text = "Divide into equal parts"
|
popup/item_2/text = "Divide into equal parts"
|
||||||
popup/item_2/id = 2
|
popup/item_2/id = 2
|
||||||
|
|
||||||
|
[node name="PresetsMenuButton" type="MenuButton" parent="InterpolationContainer"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
mouse_default_cursor_shape = 2
|
||||||
|
text = "Presets"
|
||||||
|
flat = false
|
||||||
|
|
||||||
[node name="TextureRect" type="TextureRect" parent="."]
|
[node name="TextureRect" type="TextureRect" parent="."]
|
||||||
custom_minimum_size = Vector2(0, 30)
|
custom_minimum_size = Vector2(0, 30)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
@ -129,5 +140,6 @@ text = "Add point at the end"
|
||||||
[connection signal="value_changed" from="InterpolationContainer/OffsetValueSlider" to="." method="_on_offset_value_slider_value_changed"]
|
[connection signal="value_changed" from="InterpolationContainer/OffsetValueSlider" to="." method="_on_offset_value_slider_value_changed"]
|
||||||
[connection signal="item_selected" from="InterpolationContainer/InterpolationOptionButton" to="." method="_on_InterpolationOptionButton_item_selected"]
|
[connection signal="item_selected" from="InterpolationContainer/InterpolationOptionButton" to="." method="_on_InterpolationOptionButton_item_selected"]
|
||||||
[connection signal="item_selected" from="InterpolationContainer/ColorSpaceOptionButton" to="." method="_on_color_space_option_button_item_selected"]
|
[connection signal="item_selected" from="InterpolationContainer/ColorSpaceOptionButton" to="." method="_on_color_space_option_button_item_selected"]
|
||||||
|
[connection signal="about_to_popup" from="InterpolationContainer/PresetsMenuButton" to="." method="_on_presets_menu_button_about_to_popup"]
|
||||||
[connection signal="color_changed" from="Popup/ColorPicker" to="." method="_on_ColorPicker_color_changed"]
|
[connection signal="color_changed" from="Popup/ColorPicker" to="." method="_on_ColorPicker_color_changed"]
|
||||||
[connection signal="confirmed" from="DivideConfirmationDialog" to="." method="_on_DivideConfirmationDialog_confirmed"]
|
[connection signal="confirmed" from="DivideConfirmationDialog" to="." method="_on_DivideConfirmationDialog_confirmed"]
|
||||||
|
|
Loading…
Reference in a new issue