1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

ColorReplace Shading Mode (#1107)

* ColorReplace Sdading Mode

* Fixed changing colors array by mistake

* the tool now takes more things into account

* Make it work with transparent colors (more consistent with aseprite), and improve ui a bit. This should be the last commit to this pr
This commit is contained in:
Variable 2024-10-09 13:29:46 +05:00 committed by GitHub
parent 434f87e463
commit 0551b23a19
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 127 additions and 7 deletions

View file

@ -1,6 +1,6 @@
extends "res://src/Tools/BaseDraw.gd" extends "res://src/Tools/BaseDraw.gd"
enum ShadingMode { SIMPLE, HUE_SHIFTING } enum ShadingMode { SIMPLE, HUE_SHIFTING, COLOR_REPLACE }
enum LightenDarken { LIGHTEN, DARKEN } enum LightenDarken { LIGHTEN, DARKEN }
var _prev_mode := 0 var _prev_mode := 0
@ -12,6 +12,8 @@ var _amount := 10
var _hue_amount := 10 var _hue_amount := 10
var _sat_amount := 10 var _sat_amount := 10
var _value_amount := 10 var _value_amount := 10
var _colors_right := 10
var _old_palette: Palette
class LightenDarkenOp: class LightenDarkenOp:
@ -28,17 +30,18 @@ class LightenDarkenOp:
var sat_lighten_limit := 10.0 / 100.0 var sat_lighten_limit := 10.0 / 100.0
var value_darken_limit := 10.0 / 100.0 var value_darken_limit := 10.0 / 100.0
var color_array := PackedStringArray()
func process(_src: Color, dst: Color) -> Color: func process(_src: Color, dst: Color) -> Color:
changed = true changed = true
if dst.a == 0: if dst.a == 0 and shading_mode != ShadingMode.COLOR_REPLACE:
return dst return dst
if shading_mode == ShadingMode.SIMPLE: if shading_mode == ShadingMode.SIMPLE:
if lighten_or_darken == LightenDarken.LIGHTEN: if lighten_or_darken == LightenDarken.LIGHTEN:
dst = dst.lightened(strength) dst = dst.lightened(strength)
else: else:
dst = dst.darkened(strength) dst = dst.darkened(strength)
else: elif shading_mode == ShadingMode.HUE_SHIFTING:
var hue_shift := hue_amount / 360.0 var hue_shift := hue_amount / 360.0
var sat_shift := sat_amount / 100.0 var sat_shift := sat_amount / 100.0
var value_shift := value_amount / 100.0 var value_shift := value_amount / 100.0
@ -61,6 +64,18 @@ class LightenDarkenOp:
dst.s += sat_shift dst.s += sat_shift
if dst.v > value_darken_limit: if dst.v > value_darken_limit:
dst.v = maxf(dst.v - minf(value_shift, dst.v), value_darken_limit) dst.v = maxf(dst.v - minf(value_shift, dst.v), value_darken_limit)
else:
if not color_array.is_empty():
var index = color_array.find(dst.to_html())
if index != -1:
if lighten_or_darken == LightenDarken.LIGHTEN:
## Moving to Right
if index < color_array.size() - 1:
dst = Color(color_array[index + 1])
else:
## Moving to Left
if index > 0:
dst = Color(color_array[index - 1])
return dst return dst
@ -106,6 +121,8 @@ class LightenDarkenOp:
func _init() -> void: func _init() -> void:
_drawer.color_op = LightenDarkenOp.new() _drawer.color_op = LightenDarkenOp.new()
Tools.color_changed.connect(_refresh_colors_array)
Palettes.palette_selected.connect(palette_changed)
func _input(event: InputEvent) -> void: func _input(event: InputEvent) -> void:
@ -161,6 +178,12 @@ func _on_LightenDarken_value_value_changed(value: float) -> void:
save_config() save_config()
func _on_LightenDarken_colors_right_changed(value: float) -> void:
_colors_right = int(value)
update_config()
save_config()
func get_config() -> Dictionary: func get_config() -> Dictionary:
var config := super.get_config() var config := super.get_config()
config["shading_mode"] = _shading_mode config["shading_mode"] = _shading_mode
@ -169,6 +192,7 @@ func get_config() -> Dictionary:
config["hue_amount"] = _hue_amount config["hue_amount"] = _hue_amount
config["sat_amount"] = _sat_amount config["sat_amount"] = _sat_amount
config["value_amount"] = _value_amount config["value_amount"] = _value_amount
config["colors_right"] = _colors_right
return config return config
@ -182,6 +206,7 @@ func set_config(config: Dictionary) -> void:
_hue_amount = config.get("hue_amount", _hue_amount) _hue_amount = config.get("hue_amount", _hue_amount)
_sat_amount = config.get("sat_amount", _sat_amount) _sat_amount = config.get("sat_amount", _sat_amount)
_value_amount = config.get("value_amount", _value_amount) _value_amount = config.get("value_amount", _value_amount)
_colors_right = config.get("colors_right", _colors_right)
func update_config() -> void: func update_config() -> void:
@ -192,8 +217,11 @@ func update_config() -> void:
$HueShiftingOptions/HueSlider.value = _hue_amount $HueShiftingOptions/HueSlider.value = _hue_amount
$HueShiftingOptions/SatSlider.value = _sat_amount $HueShiftingOptions/SatSlider.value = _sat_amount
$HueShiftingOptions/ValueSlider.value = _value_amount $HueShiftingOptions/ValueSlider.value = _value_amount
$ColorReplaceOptions/Settings/ColorsRight.value = _colors_right
$AmountSlider.visible = _shading_mode == ShadingMode.SIMPLE $AmountSlider.visible = _shading_mode == ShadingMode.SIMPLE
$HueShiftingOptions.visible = _shading_mode == ShadingMode.HUE_SHIFTING $HueShiftingOptions.visible = _shading_mode == ShadingMode.HUE_SHIFTING
$ColorReplaceOptions.visible = _shading_mode == ShadingMode.COLOR_REPLACE
_refresh_colors_array()
update_strength() update_strength()
@ -293,3 +321,54 @@ func _draw_brush_image(image: Image, src_rect: Rect2i, dst: Vector2i) -> void:
func update_brush() -> void: func update_brush() -> void:
super.update_brush() super.update_brush()
$ColorInterpolation.visible = false $ColorInterpolation.visible = false
## this function is also used by a signal, this is why there is _color = Color.TRANSPARENT in here.
func _refresh_colors_array(_color = Color.TRANSPARENT, mouse_button := tool_slot.button) -> void:
if mouse_button != tool_slot.button:
return
if _shading_mode == ShadingMode.COLOR_REPLACE:
await get_tree().process_frame
var index = Palettes.current_palette_get_selected_color_index(mouse_button)
if index > -1:
$ColorReplaceOptions/Settings.visible = true
$ColorReplaceOptions/Label.visible = false
var color_array := PackedStringArray()
for i in _colors_right + 1:
var next_color = Palettes.current_palette.get_color(index + i)
if next_color != null:
color_array.append(next_color.to_html())
_drawer.color_op.color_array = color_array
construct_preview()
else:
$ColorReplaceOptions/Settings.visible = false
$ColorReplaceOptions/Label.visible = true
_drawer.color_op.color_array.clear()
func construct_preview() -> void:
var colors_container: HFlowContainer = $ColorReplaceOptions/Settings/Colors
for i in colors_container.get_child_count():
if i >= _drawer.color_op.color_array.size():
colors_container.get_child(i).queue_free()
for i in _drawer.color_op.color_array.size():
var color = _drawer.color_op.color_array[i]
if i < colors_container.get_child_count():
colors_container.get_child(i).color = color
else:
var color_rect := ColorRect.new()
color_rect.color = color
color_rect.custom_minimum_size = Vector2(20, 20)
var checker = preload("res://src/UI/Nodes/TransparentChecker.tscn").instantiate()
checker.show_behind_parent = true
checker.set_anchors_preset(Control.PRESET_FULL_RECT)
color_rect.add_child(checker)
colors_container.add_child(color_rect)
func palette_changed(_palette_name):
if _old_palette:
_old_palette.data_changed.disconnect(_refresh_colors_array)
Palettes.current_palette.data_changed.connect(_refresh_colors_array)
_old_palette = Palettes.current_palette
_refresh_colors_array()

View file

@ -24,22 +24,22 @@ button_group = SubResource("ButtonGroup_se02m")
custom_minimum_size = Vector2(92, 0) custom_minimum_size = Vector2(92, 0)
layout_mode = 2 layout_mode = 2
mouse_default_cursor_shape = 2 mouse_default_cursor_shape = 2
item_count = 2
selected = 0 selected = 0
item_count = 2
popup/item_0/text = "Lighten" popup/item_0/text = "Lighten"
popup/item_0/id = 0
popup/item_1/text = "Darken" popup/item_1/text = "Darken"
popup/item_1/id = 1 popup/item_1/id = 1
[node name="ShadingMode" type="OptionButton" parent="." index="6"] [node name="ShadingMode" type="OptionButton" parent="." index="6"]
layout_mode = 2 layout_mode = 2
mouse_default_cursor_shape = 2 mouse_default_cursor_shape = 2
item_count = 2
selected = 0 selected = 0
item_count = 3
popup/item_0/text = "Simple Shading" popup/item_0/text = "Simple Shading"
popup/item_0/id = 0
popup/item_1/text = "Hue Shifting" popup/item_1/text = "Hue Shifting"
popup/item_1/id = 1 popup/item_1/id = 1
popup/item_2/text = "Color Replace"
popup/item_2/id = 2
[node name="AmountSlider" parent="." index="7" instance=ExtResource("3")] [node name="AmountSlider" parent="." index="7" instance=ExtResource("3")]
layout_mode = 2 layout_mode = 2
@ -71,9 +71,50 @@ min_value = -100.0
value = 10.0 value = 10.0
prefix = "Value:" prefix = "Value:"
[node name="ColorReplaceOptions" type="VBoxContainer" parent="." index="9"]
visible = false
layout_mode = 2
[node name="Settings" type="VBoxContainer" parent="ColorReplaceOptions" index="0"]
visible = false
layout_mode = 2
[node name="ColorsRight" parent="ColorReplaceOptions/Settings" index="0" instance=ExtResource("3")]
layout_mode = 2
max_value = 10.0
allow_greater = true
prefix = "Colors Right"
[node name="HBoxContainer" type="HBoxContainer" parent="ColorReplaceOptions/Settings" index="1"]
layout_mode = 2
[node name="DarkenLabel" type="Label" parent="ColorReplaceOptions/Settings/HBoxContainer" index="0"]
layout_mode = 2
text = "Darken"
[node name="HSeparator" type="HSeparator" parent="ColorReplaceOptions/Settings/HBoxContainer" index="1"]
layout_mode = 2
size_flags_horizontal = 3
[node name="LightenLabel" type="Label" parent="ColorReplaceOptions/Settings/HBoxContainer" index="2"]
layout_mode = 2
text = "Lighten"
horizontal_alignment = 2
[node name="Colors" type="HFlowContainer" parent="ColorReplaceOptions/Settings" index="2"]
layout_mode = 2
[node name="Label" type="Label" parent="ColorReplaceOptions" index="1"]
custom_minimum_size = Vector2(0, 75)
layout_mode = 2
text = "Please Select a color from the palette."
horizontal_alignment = 1
autowrap_mode = 3
[connection signal="item_selected" from="LightenDarken" to="." method="_on_LightenDarken_item_selected"] [connection signal="item_selected" from="LightenDarken" to="." method="_on_LightenDarken_item_selected"]
[connection signal="item_selected" from="ShadingMode" to="." method="_on_ShadingMode_item_selected"] [connection signal="item_selected" from="ShadingMode" to="." method="_on_ShadingMode_item_selected"]
[connection signal="value_changed" from="AmountSlider" to="." method="_on_LightenDarken_value_changed"] [connection signal="value_changed" from="AmountSlider" to="." method="_on_LightenDarken_value_changed"]
[connection signal="value_changed" from="HueShiftingOptions/HueSlider" to="." method="_on_LightenDarken_hue_value_changed"] [connection signal="value_changed" from="HueShiftingOptions/HueSlider" to="." method="_on_LightenDarken_hue_value_changed"]
[connection signal="value_changed" from="HueShiftingOptions/SatSlider" to="." method="_on_LightenDarken_sat_value_changed"] [connection signal="value_changed" from="HueShiftingOptions/SatSlider" to="." method="_on_LightenDarken_sat_value_changed"]
[connection signal="value_changed" from="HueShiftingOptions/ValueSlider" to="." method="_on_LightenDarken_value_value_changed"] [connection signal="value_changed" from="HueShiftingOptions/ValueSlider" to="." method="_on_LightenDarken_value_value_changed"]
[connection signal="value_changed" from="ColorReplaceOptions/Settings/ColorsRight" to="." method="_on_LightenDarken_colors_right_changed"]