1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-31 07:29:49 +00:00

Added pattern offset - Closes #130

This commit is contained in:
OverloadedOrama 2020-04-25 02:09:34 +03:00
parent 768a1e7b8f
commit 7bac0ff8f4
7 changed files with 168 additions and 38 deletions

118
Main.tscn
View file

@ -678,21 +678,21 @@ ticks_on_borders = true
[node name="LeftFillArea" type="VBoxContainer" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions"]
visible = false
margin_top = 71.0
margin_right = 160.0
margin_bottom = 155.0
margin_right = 154.0
margin_bottom = 252.0
[node name="FillAreaLabel" type="Label" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftFillArea"]
margin_left = 57.0
margin_right = 103.0
margin_left = 54.0
margin_right = 100.0
margin_bottom = 15.0
mouse_default_cursor_shape = 2
size_flags_horizontal = 4
text = "Fill area:"
[node name="LeftFillAreaOptions" type="OptionButton" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftFillArea"]
margin_left = 24.0
margin_left = 21.0
margin_top = 19.0
margin_right = 136.0
margin_right = 133.0
margin_bottom = 40.0
focus_mode = 0
mouse_default_cursor_shape = 2
@ -702,17 +702,17 @@ items = [ "Same color area", null, false, 0, null, "Same color pixels", null, fa
selected = 0
[node name="FillWithLabel" type="Label" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftFillArea"]
margin_left = 57.0
margin_left = 54.0
margin_top = 44.0
margin_right = 102.0
margin_right = 99.0
margin_bottom = 59.0
size_flags_horizontal = 4
text = "Fill with:"
[node name="LeftFillWithOptions" type="OptionButton" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftFillArea"]
margin_left = 42.0
margin_left = 26.0
margin_top = 63.0
margin_right = 118.0
margin_right = 127.0
margin_bottom = 84.0
mouse_default_cursor_shape = 2
size_flags_horizontal = 4
@ -722,18 +722,19 @@ selected = 0
[node name="LeftFillPattern" type="VBoxContainer" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftFillArea"]
visible = false
margin_left = 59.0
margin_left = 44.0
margin_top = 88.0
margin_right = 95.0
margin_bottom = 120.0
margin_right = 109.0
margin_bottom = 181.0
size_flags_horizontal = 4
[node name="LeftPatternTypeButton" type="TextureButton" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftFillArea/LeftFillPattern"]
margin_right = 36.0
margin_left = 16.0
margin_right = 48.0
margin_bottom = 32.0
rect_min_size = Vector2( 36, 32 )
hint_tooltip = "Select a brush"
mouse_default_cursor_shape = 2
size_flags_horizontal = 4
texture_normal = ExtResource( 12 )
[node name="PatternTexture" type="TextureRect" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftFillArea/LeftFillPattern/LeftPatternTypeButton"]
@ -745,6 +746,46 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="Offset" type="Label" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftFillArea/LeftFillPattern"]
margin_top = 36.0
margin_right = 65.0
margin_bottom = 51.0
text = "Offset"
[node name="XOffset" type="HBoxContainer" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftFillArea/LeftFillPattern"]
margin_top = 55.0
margin_right = 65.0
margin_bottom = 72.0
[node name="Label" type="Label" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftFillArea/LeftFillPattern/XOffset"]
margin_top = 1.0
margin_right = 8.0
margin_bottom = 16.0
text = "X"
[node name="LeftPatternOffsetX" type="SpinBox" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftFillArea/LeftFillPattern/XOffset"]
margin_left = 11.0
margin_right = 65.0
margin_bottom = 17.0
mouse_default_cursor_shape = 2
[node name="YOffset" type="HBoxContainer" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftFillArea/LeftFillPattern"]
margin_top = 76.0
margin_right = 65.0
margin_bottom = 93.0
[node name="Label" type="Label" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftFillArea/LeftFillPattern/YOffset"]
margin_top = 1.0
margin_right = 7.0
margin_bottom = 16.0
text = "Y"
[node name="LeftPatternOffsetY" type="SpinBox" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftFillArea/LeftFillPattern/YOffset"]
margin_left = 10.0
margin_right = 64.0
margin_bottom = 17.0
mouse_default_cursor_shape = 2
[node name="LeftLDOptions" type="VBoxContainer" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions"]
visible = false
margin_top = 75.0
@ -1098,6 +1139,49 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="Offset" type="Label" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/RightToolOptions/RightFillArea/RightFillPattern"]
margin_left = -185.0
margin_top = 36.0
margin_right = -120.0
margin_bottom = 51.0
text = "Offset"
[node name="XOffset" type="HBoxContainer" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/RightToolOptions/RightFillArea/RightFillPattern"]
margin_left = -185.0
margin_top = 55.0
margin_right = -120.0
margin_bottom = 72.0
[node name="Label" type="Label" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/RightToolOptions/RightFillArea/RightFillPattern/XOffset"]
margin_top = 1.0
margin_right = 8.0
margin_bottom = 16.0
text = "X"
[node name="RightPatternOffsetX" type="SpinBox" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/RightToolOptions/RightFillArea/RightFillPattern/XOffset"]
margin_left = 11.0
margin_right = 65.0
margin_bottom = 17.0
mouse_default_cursor_shape = 2
[node name="YOffset" type="HBoxContainer" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/RightToolOptions/RightFillArea/RightFillPattern"]
margin_left = -185.0
margin_top = 76.0
margin_right = -120.0
margin_bottom = 93.0
[node name="Label" type="Label" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/RightToolOptions/RightFillArea/RightFillPattern/YOffset"]
margin_top = 1.0
margin_right = 7.0
margin_bottom = 16.0
text = "Y"
[node name="RightPatternOffsetY" type="SpinBox" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/RightToolOptions/RightFillArea/RightFillPattern/YOffset"]
margin_left = 10.0
margin_right = 64.0
margin_bottom = 17.0
mouse_default_cursor_shape = 2
[node name="RightLDOptions" type="VBoxContainer" parent="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/RightToolOptions"]
visible = false
margin_top = 75.0
@ -1577,6 +1661,8 @@ visible = false
[connection signal="item_selected" from="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftFillArea/LeftFillAreaOptions" to="." method="_on_LeftFillAreaOptions_item_selected"]
[connection signal="item_selected" from="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftFillArea/LeftFillWithOptions" to="." method="_on_LeftFillWithOptions_item_selected"]
[connection signal="pressed" from="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftFillArea/LeftFillPattern/LeftPatternTypeButton" to="." method="_on_LeftPatternTypeButton_pressed"]
[connection signal="value_changed" from="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftFillArea/LeftFillPattern/XOffset/LeftPatternOffsetX" to="." method="_on_LeftPatternOffsetX_value_changed"]
[connection signal="value_changed" from="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftFillArea/LeftFillPattern/YOffset/LeftPatternOffsetY" to="." method="_on_LeftPatternOffsetY_value_changed"]
[connection signal="item_selected" from="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftLDOptions/LeftLightenDarken" to="." method="_on_LeftLightenDarken_item_selected"]
[connection signal="value_changed" from="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftLDOptions/LeftLDAmountSpinbox" to="." method="_on_LeftLDAmountSpinbox_value_changed"]
[connection signal="value_changed" from="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/LeftToolOptions/LeftLDOptions/LeftLDAmountSlider" to="." method="_on_LeftLDAmountSpinbox_value_changed"]
@ -1594,6 +1680,8 @@ visible = false
[connection signal="item_selected" from="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/RightToolOptions/RightFillArea/RightFillAreaOptions" to="." method="_on_RightFillAreaOptions_item_selected"]
[connection signal="item_selected" from="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/RightToolOptions/RightFillArea/RightFillWithOptions" to="." method="_on_RightFillWithOptions_item_selected"]
[connection signal="pressed" from="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/RightToolOptions/RightFillArea/RightFillPattern/RightPatternTypeButton" to="." method="_on_RightPatternTypeButton_pressed"]
[connection signal="value_changed" from="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/RightToolOptions/RightFillArea/RightFillPattern/XOffset/RightPatternOffsetX" to="." method="_on_RightPatternOffsetX_value_changed"]
[connection signal="value_changed" from="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/RightToolOptions/RightFillArea/RightFillPattern/YOffset/RightPatternOffsetY" to="." method="_on_RightPatternOffsetY_value_changed"]
[connection signal="item_selected" from="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/RightToolOptions/RightLDOptions/RightLightenDarken" to="." method="_on_RightLightenDarken_item_selected"]
[connection signal="value_changed" from="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/RightToolOptions/RightLDOptions/RightLDAmountSpinbox" to="." method="_on_RightLDAmountSpinbox_value_changed"]
[connection signal="value_changed" from="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/ColorAndToolOptions/ScrollContainer/ToolOptions/RightToolOptions/RightLDOptions/RightLDAmountSlider" to="." method="_on_RightLDAmountSpinbox_value_changed"]

View file

@ -2,11 +2,13 @@ extends TextureButton
var image : Image
var image_size : Vector2
var texture : ImageTexture
func _ready():
if image:
image_size = image.get_size()
texture = ImageTexture.new()
texture.create_from_image(image, 0)
@ -15,8 +17,13 @@ func _on_PatternButton_pressed() -> void:
if Global.pattern_window_position == "left":
Global.pattern_left_image = image
Global.left_fill_pattern_container.get_child(0).get_child(0).texture = texture
Global.left_fill_pattern_container.get_child(2).get_child(1).max_value = image_size.x - 1
Global.left_fill_pattern_container.get_child(3).get_child(1).max_value = image_size.y - 1
elif Global.pattern_window_position == "right":
Global.pattern_right_image = image
Global.right_fill_pattern_container.get_child(0).get_child(0).texture = texture
Global.right_fill_pattern_container.get_child(2).get_child(1).max_value = image_size.x - 1
Global.right_fill_pattern_container.get_child(3).get_child(1).max_value = image_size.y - 1
Global.patterns_popup.hide()

View file

@ -340,12 +340,15 @@ func _input(event : InputEvent) -> void:
if can_handle:
var fill_with := 0
var pattern_image : Image
var pattern_offset : Vector2
if current_mouse_button == "left_mouse":
fill_with = Global.left_fill_with
pattern_image = Global.pattern_left_image
pattern_offset = Global.left_fill_pattern_offset
elif current_mouse_button == "right_mouse":
fill_with = Global.right_fill_with
pattern_image = Global.pattern_right_image
pattern_offset = Global.right_fill_pattern_offset
if fill_area == 0: # Paint the specific area of the same color
var horizontal_mirror := false
@ -360,16 +363,16 @@ func _input(event : InputEvent) -> void:
vertical_mirror = Global.right_vertical_mirror
if fill_with == 1: # Pattern fill
pattern_fill(sprite, mouse_pos, pattern_image, sprite.get_pixelv(mouse_pos))
pattern_fill(sprite, mouse_pos, pattern_image, sprite.get_pixelv(mouse_pos), pattern_offset)
if horizontal_mirror:
var pos := Vector2(mirror_x, mouse_pos.y)
pattern_fill(sprite, pos, pattern_image, sprite.get_pixelv(mouse_pos))
pattern_fill(sprite, pos, pattern_image, sprite.get_pixelv(mouse_pos), pattern_offset)
if vertical_mirror:
var pos := Vector2(mouse_pos.x, mirror_y)
pattern_fill(sprite, pos, pattern_image, sprite.get_pixelv(mouse_pos))
pattern_fill(sprite, pos, pattern_image, sprite.get_pixelv(mouse_pos), pattern_offset)
if horizontal_mirror && vertical_mirror:
var pos := Vector2(mirror_x, mirror_y)
pattern_fill(sprite, pos, pattern_image, sprite.get_pixelv(mouse_pos))
pattern_fill(sprite, pos, pattern_image, sprite.get_pixelv(mouse_pos), pattern_offset)
else: # Flood fill
flood_fill(sprite, mouse_pos, sprite.get_pixelv(mouse_pos), current_color)
if horizontal_mirror:
@ -391,8 +394,8 @@ func _input(event : InputEvent) -> void:
if fill_with == 1: # Pattern fill
pattern_image.lock()
var pattern_size := pattern_image.get_size()
var xxx : int = int(xx) % int(pattern_size.x)
var yyy : int = int(yy) % int(pattern_size.y)
var xxx : int = int(xx + pattern_offset.x) % int(pattern_size.x)
var yyy : int = int(yy + pattern_offset.y) % int(pattern_size.y)
var pattern_color : Color = pattern_image.get_pixel(xxx, yyy)
sprite.set_pixel(xx, yy, pattern_color)
pattern_image.unlock()
@ -889,7 +892,7 @@ func flood_fill(sprite : Image, pos : Vector2, target_color : Color, replace_col
sprite_changed_this_frame = true
func pattern_fill(sprite : Image, pos : Vector2, pattern : Image, target_color : Color) -> void:
func pattern_fill(sprite : Image, pos : Vector2, pattern : Image, target_color : Color, var offset : Vector2) -> void:
pos = pos.floor()
if !point_in_rectangle(pos, Vector2(west_limit - 1, north_limit - 1), Vector2(east_limit, south_limit)):
return
@ -908,8 +911,8 @@ func pattern_fill(sprite : Image, pos : Vector2, pattern : Image, target_color :
for px in range(west.x + 1, east.x):
var p := Vector2(px, n.y)
var xx : int = int(px) % int(pattern_size.x)
var yy : int = int(n.y) % int(pattern_size.y)
var xx : int = int(px + offset.x) % int(pattern_size.x)
var yy : int = int(n.y + offset.y) % int(pattern_size.y)
var pattern_color : Color = pattern.get_pixel(xx, yy)
if pattern_color == target_color:
continue

View file

@ -83,6 +83,9 @@ var right_fill_area := 0
var left_fill_with := 0
var right_fill_with := 0
var left_fill_pattern_offset := Vector2.ZERO
var right_fill_pattern_offset := Vector2.ZERO
# 0 for lighten, 1 for darken
var left_ld := 0
var right_ld := 0

View file

@ -245,15 +245,22 @@ func import_patterns(priority_ordered_search_path: Array) -> void:
pattern_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
Global.patterns_popup.get_node("ScrollContainer/PatternContainer").add_child(pattern_button)
Global.pattern_left_image = Global.patterns[0]
var pattern_left_tex := ImageTexture.new()
pattern_left_tex.create_from_image(Global.pattern_left_image, 0)
Global.left_fill_pattern_container.get_child(0).get_child(0).texture = pattern_left_tex
if Global.patterns.size() > 0:
var image_size = Global.patterns[0].get_size()
Global.pattern_right_image = Global.patterns[0]
var pattern_right_tex := ImageTexture.new()
pattern_right_tex.create_from_image(Global.pattern_right_image, 0)
Global.right_fill_pattern_container.get_child(0).get_child(0).texture = pattern_right_tex
Global.pattern_left_image = Global.patterns[0]
var pattern_left_tex := ImageTexture.new()
pattern_left_tex.create_from_image(Global.pattern_left_image, 0)
Global.left_fill_pattern_container.get_child(0).get_child(0).texture = pattern_left_tex
Global.left_fill_pattern_container.get_child(2).get_child(1).max_value = image_size.x - 1
Global.left_fill_pattern_container.get_child(3).get_child(1).max_value = image_size.y - 1
Global.pattern_right_image = Global.patterns[0]
var pattern_right_tex := ImageTexture.new()
pattern_right_tex.create_from_image(Global.pattern_right_image, 0)
Global.right_fill_pattern_container.get_child(0).get_child(0).texture = pattern_right_tex
Global.right_fill_pattern_container.get_child(2).get_child(1).max_value = image_size.x - 1
Global.right_fill_pattern_container.get_child(3).get_child(1).max_value = image_size.y - 1
func import_gpl(path : String) -> Palette:

View file

@ -657,6 +657,22 @@ func _on_LeftPatternTypeButton_pressed() -> void:
Global.patterns_popup.popup(Rect2(Global.left_brush_type_button.rect_global_position, Vector2(226, 72)))
func _on_LeftPatternOffsetX_value_changed(value : float) -> void:
Global.left_fill_pattern_offset.x = value
func _on_LeftPatternOffsetY_value_changed(value : float) -> void:
Global.left_fill_pattern_offset.y = value
func _on_RightPatternOffsetX_value_changed(value : float) -> void:
Global.right_fill_pattern_offset.x = value
func _on_RightPatternOffsetY_value_changed(value : float) -> void:
Global.right_fill_pattern_offset.y = value
func _on_RightFillAreaOptions_item_selected(ID : int) -> void:
Global.right_fill_area = ID

View file

@ -606,18 +606,24 @@ msgstr ""
msgid "Fill area:"
msgstr ""
msgid "Area of the same color"
msgstr ""
msgid "All pixels of the same color"
msgstr ""
msgid "Same color area"
msgstr ""
msgid "Same color pixels"
msgstr ""
msgid "Fill with:"
msgstr ""
msgid "Selected Color"
msgstr ""
msgid "Pattern"
msgstr ""
msgid "Offset"
msgstr ""
msgid "Lighten"
msgstr ""