mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Mirrored drawing
- Mirrored drawing in horizontal, vertical or both axes. - Fixed bug where the paint all pixels of the same color tool would affect other frames. - Removed most of the parameters for draw_pixel() - replaced them with "current_mouse_button" instead.
This commit is contained in:
parent
c64c3408e8
commit
38377e1633
96
Main.tscn
96
Main.tscn
|
@ -34,13 +34,13 @@ size_flags_horizontal = 3
|
|||
size_flags_vertical = 3
|
||||
|
||||
[node name="MenusAndTools" type="VBoxContainer" parent="UI/ToolPanel/Tools"]
|
||||
margin_right = 230.0
|
||||
margin_right = 242.0
|
||||
margin_bottom = 266.0
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="MenuItems" type="HBoxContainer" parent="UI/ToolPanel/Tools/MenusAndTools"]
|
||||
editor/display_folded = true
|
||||
margin_right = 230.0
|
||||
margin_right = 242.0
|
||||
margin_bottom = 20.0
|
||||
|
||||
[node name="FileMenu" type="MenuButton" parent="UI/ToolPanel/Tools/MenusAndTools/MenuItems"]
|
||||
|
@ -72,7 +72,7 @@ text = "Help"
|
|||
|
||||
[node name="PaintToolsContainer" type="HBoxContainer" parent="UI/ToolPanel/Tools/MenusAndTools"]
|
||||
margin_top = 24.0
|
||||
margin_right = 230.0
|
||||
margin_right = 242.0
|
||||
margin_bottom = 44.0
|
||||
|
||||
[node name="Pencil" type="Button" parent="UI/ToolPanel/Tools/MenusAndTools/PaintToolsContainer"]
|
||||
|
@ -118,7 +118,7 @@ text = "Bucket"
|
|||
|
||||
[node name="ColorToolsContainer" type="HBoxContainer" parent="UI/ToolPanel/Tools/MenusAndTools"]
|
||||
margin_top = 48.0
|
||||
margin_right = 230.0
|
||||
margin_right = 242.0
|
||||
margin_bottom = 68.0
|
||||
|
||||
[node name="PaintAllPixelsSameColor" type="Button" parent="UI/ToolPanel/Tools/MenusAndTools/ColorToolsContainer"]
|
||||
|
@ -144,7 +144,7 @@ text = "Lighten/Darken"
|
|||
|
||||
[node name="SelectionToolsContainer2" type="HBoxContainer" parent="UI/ToolPanel/Tools/MenusAndTools"]
|
||||
margin_top = 72.0
|
||||
margin_right = 230.0
|
||||
margin_right = 242.0
|
||||
margin_bottom = 92.0
|
||||
|
||||
[node name="RectSelect" type="Button" parent="UI/ToolPanel/Tools/MenusAndTools/SelectionToolsContainer2"]
|
||||
|
@ -159,29 +159,29 @@ text = "RectSelect"
|
|||
|
||||
[node name="HSeparator" type="HSeparator" parent="UI/ToolPanel/Tools"]
|
||||
margin_top = 270.0
|
||||
margin_right = 230.0
|
||||
margin_right = 242.0
|
||||
margin_bottom = 274.0
|
||||
|
||||
[node name="ToolOptions" type="HBoxContainer" parent="UI/ToolPanel/Tools"]
|
||||
margin_top = 278.0
|
||||
margin_right = 230.0
|
||||
margin_right = 242.0
|
||||
margin_bottom = 544.0
|
||||
size_flags_vertical = 3
|
||||
custom_constants/separation = 0
|
||||
|
||||
[node name="LeftToolOptions" type="VBoxContainer" parent="UI/ToolPanel/Tools/ToolOptions"]
|
||||
margin_right = 113.0
|
||||
margin_right = 119.0
|
||||
margin_bottom = 266.0
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="LeftLabel" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"]
|
||||
margin_right = 113.0
|
||||
margin_right = 119.0
|
||||
margin_bottom = 14.0
|
||||
text = "Left tool options"
|
||||
|
||||
[node name="LeftIndicatorCheckbox" type="CheckBox" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"]
|
||||
margin_top = 18.0
|
||||
margin_right = 113.0
|
||||
margin_right = 119.0
|
||||
margin_bottom = 42.0
|
||||
hint_tooltip = "Show left mouse indicator when drawing"
|
||||
mouse_default_cursor_shape = 2
|
||||
|
@ -200,13 +200,13 @@ size_flags_vertical = 0
|
|||
|
||||
[node name="BrushSizeLabel" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"]
|
||||
margin_top = 82.0
|
||||
margin_right = 113.0
|
||||
margin_right = 119.0
|
||||
margin_bottom = 96.0
|
||||
text = "Brush size: "
|
||||
|
||||
[node name="LeftBrushSizeEdit" type="SpinBox" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"]
|
||||
margin_top = 100.0
|
||||
margin_right = 113.0
|
||||
margin_right = 119.0
|
||||
margin_bottom = 124.0
|
||||
mouse_default_cursor_shape = 2
|
||||
min_value = 1.0
|
||||
|
@ -215,13 +215,14 @@ suffix = "px"
|
|||
|
||||
[node name="ColorComesFrom" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"]
|
||||
margin_top = 128.0
|
||||
margin_right = 113.0
|
||||
margin_right = 119.0
|
||||
margin_bottom = 142.0
|
||||
text = "Brush color from"
|
||||
|
||||
[node name="InterpolateColor" type="HBoxContainer" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"]
|
||||
editor/display_folded = true
|
||||
margin_top = 146.0
|
||||
margin_right = 113.0
|
||||
margin_right = 119.0
|
||||
margin_bottom = 162.0
|
||||
|
||||
[node name="BrushColorLabel" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/InterpolateColor"]
|
||||
|
@ -233,7 +234,7 @@ text = "B"
|
|||
|
||||
[node name="LeftInterpolateFactor" type="HSlider" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/InterpolateColor"]
|
||||
margin_left = 13.0
|
||||
margin_right = 101.0
|
||||
margin_right = 107.0
|
||||
margin_bottom = 16.0
|
||||
hint_tooltip = "Choose if the brush's color should come from the brush itself (left), or the currently selected color (right)"
|
||||
size_flags_horizontal = 3
|
||||
|
@ -243,32 +244,44 @@ value = 0.5
|
|||
ticks_on_borders = true
|
||||
|
||||
[node name="SelectedColorLabel" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/InterpolateColor"]
|
||||
margin_left = 105.0
|
||||
margin_left = 111.0
|
||||
margin_top = 1.0
|
||||
margin_right = 113.0
|
||||
margin_right = 119.0
|
||||
margin_bottom = 15.0
|
||||
rect_pivot_offset = Vector2( -90, -47 )
|
||||
text = "C"
|
||||
|
||||
[node name="LeftHorizontalMirroring" type="CheckBox" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"]
|
||||
margin_top = 166.0
|
||||
margin_right = 119.0
|
||||
margin_bottom = 190.0
|
||||
text = "Horiz. Mirror"
|
||||
|
||||
[node name="LeftVerticalMirroring" type="CheckBox" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"]
|
||||
margin_top = 194.0
|
||||
margin_right = 119.0
|
||||
margin_bottom = 218.0
|
||||
text = "Vert. Mirror"
|
||||
|
||||
[node name="VSeparator" type="VSeparator" parent="UI/ToolPanel/Tools/ToolOptions"]
|
||||
margin_left = 113.0
|
||||
margin_right = 117.0
|
||||
margin_left = 119.0
|
||||
margin_right = 123.0
|
||||
margin_bottom = 266.0
|
||||
|
||||
[node name="RightToolOptions" type="VBoxContainer" parent="UI/ToolPanel/Tools/ToolOptions"]
|
||||
margin_left = 117.0
|
||||
margin_right = 230.0
|
||||
margin_left = 123.0
|
||||
margin_right = 242.0
|
||||
margin_bottom = 266.0
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="RightLabel" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions"]
|
||||
margin_right = 113.0
|
||||
margin_right = 119.0
|
||||
margin_bottom = 14.0
|
||||
text = "Right tool options"
|
||||
|
||||
[node name="RightIndicatorCheckbox" type="CheckBox" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions"]
|
||||
margin_top = 18.0
|
||||
margin_right = 113.0
|
||||
margin_right = 119.0
|
||||
margin_bottom = 42.0
|
||||
hint_tooltip = "Show right mouse indicator when drawing"
|
||||
mouse_default_cursor_shape = 2
|
||||
|
@ -286,13 +299,13 @@ size_flags_vertical = 0
|
|||
|
||||
[node name="BrushSizeLabel" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions"]
|
||||
margin_top = 82.0
|
||||
margin_right = 113.0
|
||||
margin_right = 119.0
|
||||
margin_bottom = 96.0
|
||||
text = "Brush size: "
|
||||
|
||||
[node name="RightBrushSizeEdit" type="SpinBox" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions"]
|
||||
margin_top = 100.0
|
||||
margin_right = 113.0
|
||||
margin_right = 119.0
|
||||
margin_bottom = 124.0
|
||||
mouse_default_cursor_shape = 2
|
||||
min_value = 1.0
|
||||
|
@ -301,13 +314,14 @@ suffix = "px"
|
|||
|
||||
[node name="ColorComesFrom" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions"]
|
||||
margin_top = 128.0
|
||||
margin_right = 113.0
|
||||
margin_right = 119.0
|
||||
margin_bottom = 142.0
|
||||
text = "Brush color from"
|
||||
|
||||
[node name="InterpolateColor" type="HBoxContainer" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions"]
|
||||
editor/display_folded = true
|
||||
margin_top = 146.0
|
||||
margin_right = 113.0
|
||||
margin_right = 119.0
|
||||
margin_bottom = 162.0
|
||||
|
||||
[node name="BrushColorLabel" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions/InterpolateColor"]
|
||||
|
@ -319,7 +333,7 @@ text = "B"
|
|||
|
||||
[node name="RightInterpolateFactor" type="HSlider" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions/InterpolateColor"]
|
||||
margin_left = 13.0
|
||||
margin_right = 101.0
|
||||
margin_right = 107.0
|
||||
margin_bottom = 16.0
|
||||
hint_tooltip = "Choose if the brush's color should come from the brush itself (left), or the currently selected color (right)"
|
||||
size_flags_horizontal = 3
|
||||
|
@ -329,21 +343,33 @@ value = 0.5
|
|||
ticks_on_borders = true
|
||||
|
||||
[node name="SelectedColorLabel" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions/InterpolateColor"]
|
||||
margin_left = 105.0
|
||||
margin_left = 111.0
|
||||
margin_top = 1.0
|
||||
margin_right = 113.0
|
||||
margin_right = 119.0
|
||||
margin_bottom = 15.0
|
||||
rect_pivot_offset = Vector2( -90, -47 )
|
||||
text = "C"
|
||||
|
||||
[node name="RightHorizontalMirroring" type="CheckBox" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions"]
|
||||
margin_top = 166.0
|
||||
margin_right = 119.0
|
||||
margin_bottom = 190.0
|
||||
text = "Horiz. Mirror"
|
||||
|
||||
[node name="RightVerticalMirroring" type="CheckBox" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions"]
|
||||
margin_top = 194.0
|
||||
margin_right = 119.0
|
||||
margin_bottom = 218.0
|
||||
text = "Vert. Mirror"
|
||||
|
||||
[node name="HSeparator2" type="HSeparator" parent="UI/ToolPanel/Tools"]
|
||||
margin_top = 548.0
|
||||
margin_right = 230.0
|
||||
margin_right = 242.0
|
||||
margin_bottom = 552.0
|
||||
|
||||
[node name="BrushesContainer" type="ScrollContainer" parent="UI/ToolPanel/Tools"]
|
||||
margin_top = 556.0
|
||||
margin_right = 230.0
|
||||
margin_right = 242.0
|
||||
margin_bottom = 592.0
|
||||
size_flags_horizontal = 3
|
||||
scroll_vertical_enabled = false
|
||||
|
@ -368,7 +394,7 @@ offset = Vector2( 28, 0 )
|
|||
|
||||
[node name="HSeparator3" type="HSeparator" parent="UI/ToolPanel/Tools"]
|
||||
margin_top = 596.0
|
||||
margin_right = 230.0
|
||||
margin_right = 242.0
|
||||
margin_bottom = 600.0
|
||||
|
||||
[node name="CanvasAndTimeline" type="VBoxContainer" parent="UI"]
|
||||
|
@ -1032,12 +1058,16 @@ align = 1
|
|||
[connection signal="pressed" from="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/LeftColorPickerButton" to="." method="_can_draw_false"]
|
||||
[connection signal="value_changed" from="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/LeftBrushSizeEdit" to="." method="_on_LeftBrushSizeEdit_value_changed"]
|
||||
[connection signal="value_changed" from="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/InterpolateColor/LeftInterpolateFactor" to="." method="_on_LeftInterpolateFactor_value_changed"]
|
||||
[connection signal="toggled" from="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/LeftHorizontalMirroring" to="." method="_on_LeftHorizontalMirroring_toggled"]
|
||||
[connection signal="toggled" from="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/LeftVerticalMirroring" to="." method="_on_LeftVerticalMirroring_toggled"]
|
||||
[connection signal="toggled" from="UI/ToolPanel/Tools/ToolOptions/RightToolOptions/RightIndicatorCheckbox" to="." method="_on_RightIndicatorCheckbox_toggled"]
|
||||
[connection signal="color_changed" from="UI/ToolPanel/Tools/ToolOptions/RightToolOptions/RightColorPickerButton" to="." method="_on_RightColorPickerButton_color_changed"]
|
||||
[connection signal="popup_closed" from="UI/ToolPanel/Tools/ToolOptions/RightToolOptions/RightColorPickerButton" to="." method="_can_draw_true"]
|
||||
[connection signal="pressed" from="UI/ToolPanel/Tools/ToolOptions/RightToolOptions/RightColorPickerButton" to="." method="_can_draw_false"]
|
||||
[connection signal="value_changed" from="UI/ToolPanel/Tools/ToolOptions/RightToolOptions/RightBrushSizeEdit" to="." method="_on_RightBrushSizeEdit_value_changed"]
|
||||
[connection signal="value_changed" from="UI/ToolPanel/Tools/ToolOptions/RightToolOptions/InterpolateColor/RightInterpolateFactor" to="." method="_on_RightInterpolateFactor_value_changed"]
|
||||
[connection signal="toggled" from="UI/ToolPanel/Tools/ToolOptions/RightToolOptions/RightHorizontalMirroring" to="." method="_on_RightHorizontalMirroring_toggled"]
|
||||
[connection signal="toggled" from="UI/ToolPanel/Tools/ToolOptions/RightToolOptions/RightVerticalMirroring" to="." method="_on_RightVerticalMirroring_toggled"]
|
||||
[connection signal="mouse_entered" from="UI/CanvasAndTimeline/HBoxContainer/ViewportContainer" to="." method="_on_ViewportContainer_mouse_entered"]
|
||||
[connection signal="mouse_exited" from="UI/CanvasAndTimeline/HBoxContainer/ViewportContainer" to="." method="_on_ViewportContainer_mouse_exited"]
|
||||
[connection signal="mouse_entered" from="UI/CanvasAndTimeline/HBoxContainer/ViewportContainer2" to="." method="_on_ViewportContainer_mouse_entered"]
|
||||
|
|
|
@ -105,13 +105,32 @@ func _process(delta) -> void:
|
|||
"Fill":
|
||||
if point_in_rectangle(mouse_pos, location, location + size) && Global.can_draw && Global.has_focus && Global.current_frame == frame:
|
||||
var current_color : Color
|
||||
var horizontal_mirror := false
|
||||
var vertical_mirror := false
|
||||
var mirror_x := size.x - mouse_pos.x - 1
|
||||
var mirror_y := size.y - mouse_pos.y - 1
|
||||
if current_mouse_button == "left_mouse":
|
||||
current_color = Global.left_color_picker.color
|
||||
horizontal_mirror = Global.left_horizontal_mirror
|
||||
vertical_mirror = Global.left_vertical_mirror
|
||||
elif current_mouse_button == "right_mouse":
|
||||
current_color = Global.right_color_picker.color
|
||||
horizontal_mirror = Global.right_horizontal_mirror
|
||||
vertical_mirror = Global.right_vertical_mirror
|
||||
|
||||
flood_fill(mouse_pos, layers[current_layer_index][0].get_pixelv(mouse_pos), current_color)
|
||||
if horizontal_mirror:
|
||||
var pos := Vector2(mirror_x, mouse_pos.y)
|
||||
flood_fill(pos, layers[current_layer_index][0].get_pixelv(pos), current_color)
|
||||
if vertical_mirror:
|
||||
var pos := Vector2(mouse_pos.x, mirror_y)
|
||||
flood_fill(pos, layers[current_layer_index][0].get_pixelv(pos), current_color)
|
||||
if horizontal_mirror && vertical_mirror:
|
||||
var pos := Vector2(mirror_x, mirror_y)
|
||||
flood_fill(pos, layers[current_layer_index][0].get_pixelv(pos), current_color)
|
||||
|
||||
"PaintAllPixelsSameColor":
|
||||
if point_in_rectangle(mouse_pos, location, location + size):
|
||||
if point_in_rectangle(mouse_pos, location, location + size) && Global.current_frame == frame:
|
||||
var current_color : Color
|
||||
if current_mouse_button == "left_mouse":
|
||||
current_color = Global.left_color_picker.color
|
||||
|
@ -216,7 +235,6 @@ func get_layer_container(layer_index : int) -> PanelContainer:
|
|||
|
||||
func _draw() -> void:
|
||||
draw_texture_rect(trans_background, Rect2(location, size), true) #Draw transparent background
|
||||
|
||||
#Onion Skinning
|
||||
#Past
|
||||
if Global.onion_skinning_past_rate > 0:
|
||||
|
@ -325,37 +343,43 @@ func pencil_and_eraser(mouse_pos : Vector2, color : Color, current_mouse_button
|
|||
add_child(line_2d)
|
||||
is_making_line = true
|
||||
else:
|
||||
var brush_size := 1
|
||||
var brush_type = Global.BRUSH_TYPES.PIXEL
|
||||
var brush_index := -1
|
||||
var custom_brush_image : Image
|
||||
if current_mouse_button == "left_mouse":
|
||||
brush_size = Global.left_brush_size
|
||||
brush_type = Global.current_left_brush_type
|
||||
brush_index = Global.custom_left_brush_index
|
||||
custom_brush_image = Global.custom_left_brush_image
|
||||
elif current_mouse_button == "right_mouse":
|
||||
brush_size = Global.right_brush_size
|
||||
brush_type = Global.current_right_brush_type
|
||||
brush_index = Global.custom_right_brush_index
|
||||
custom_brush_image = Global.custom_right_brush_image
|
||||
|
||||
if is_making_line:
|
||||
fill_gaps(mouse_pos, color, brush_size, brush_type, brush_index, custom_brush_image)
|
||||
fill_gaps(mouse_pos, color, current_mouse_button)
|
||||
is_making_line = false
|
||||
line_2d.queue_free()
|
||||
else:
|
||||
if point_in_rectangle(mouse_pos, location, location + size):
|
||||
mouse_inside_canvas = true
|
||||
#Draw
|
||||
draw_pixel(mouse_pos, color, brush_size, brush_type, brush_index, custom_brush_image)
|
||||
fill_gaps(mouse_pos, color, brush_size, brush_type, brush_index, custom_brush_image) #Fill the gaps
|
||||
draw_pixel(mouse_pos, color, current_mouse_button)
|
||||
fill_gaps(mouse_pos, color, current_mouse_button) #Fill the gaps
|
||||
#If mouse is not inside bounds but it used to be, fill the gaps
|
||||
elif point_in_rectangle(previous_mouse_pos, location, location + size):
|
||||
fill_gaps(mouse_pos, color, brush_size, brush_type, brush_index, custom_brush_image)
|
||||
fill_gaps(mouse_pos, color, current_mouse_button)
|
||||
|
||||
func draw_pixel(pos : Vector2, color : Color, brush_size : int, brush_type : int, brush_index : int, custom_brush_image : Image) -> void:
|
||||
func draw_pixel(pos : Vector2, color : Color, current_mouse_button : String) -> void:
|
||||
if Global.can_draw && Global.has_focus && Global.current_frame == frame:
|
||||
var brush_size := 1
|
||||
var brush_type = Global.BRUSH_TYPES.PIXEL
|
||||
var brush_index := -1
|
||||
var custom_brush_image : Image
|
||||
var horizontal_mirror := false
|
||||
var vertical_mirror := false
|
||||
if current_mouse_button == "left_mouse":
|
||||
brush_size = Global.left_brush_size
|
||||
brush_type = Global.current_left_brush_type
|
||||
brush_index = Global.custom_left_brush_index
|
||||
custom_brush_image = Global.custom_left_brush_image
|
||||
horizontal_mirror = Global.left_horizontal_mirror
|
||||
vertical_mirror = Global.left_vertical_mirror
|
||||
elif current_mouse_button == "right_mouse":
|
||||
brush_size = Global.right_brush_size
|
||||
brush_type = Global.current_right_brush_type
|
||||
brush_index = Global.custom_right_brush_index
|
||||
custom_brush_image = Global.custom_right_brush_image
|
||||
horizontal_mirror = Global.right_horizontal_mirror
|
||||
vertical_mirror = Global.right_vertical_mirror
|
||||
|
||||
var west_limit := location.x
|
||||
var east_limit := location.x + size.x
|
||||
var north_limit := location.y
|
||||
|
@ -383,6 +407,21 @@ func draw_pixel(pos : Vector2, color : Color, brush_size : int, brush_type : int
|
|||
if layers[current_layer_index][0].get_pixel(cur_pos_x, cur_pos_y) != color: #don't draw the same pixel over and over
|
||||
layers[current_layer_index][0].set_pixel(cur_pos_x, cur_pos_y, color)
|
||||
sprite_changed_this_frame = true
|
||||
#Handle mirroring
|
||||
var mirror_x := east_limit + west_limit - cur_pos_x - 1
|
||||
var mirror_y := south_limit + north_limit - cur_pos_y - 1
|
||||
if horizontal_mirror:
|
||||
if layers[current_layer_index][0].get_pixel(mirror_x, cur_pos_y) != color: #don't draw the same pixel over and over
|
||||
layers[current_layer_index][0].set_pixel(mirror_x, cur_pos_y, color)
|
||||
sprite_changed_this_frame = true
|
||||
if vertical_mirror:
|
||||
if layers[current_layer_index][0].get_pixel(cur_pos_x, mirror_y) != color: #don't draw the same pixel over and over
|
||||
layers[current_layer_index][0].set_pixel(cur_pos_x, mirror_y, color)
|
||||
sprite_changed_this_frame = true
|
||||
if horizontal_mirror && vertical_mirror:
|
||||
if layers[current_layer_index][0].get_pixel(mirror_x, mirror_y) != color: #don't draw the same pixel over and over
|
||||
layers[current_layer_index][0].set_pixel(mirror_x, mirror_y, color)
|
||||
sprite_changed_this_frame = true
|
||||
|
||||
Global.BRUSH_TYPES.CUSTOM:
|
||||
var custom_brush_size := custom_brush_image.get_size() - Vector2.ONE
|
||||
|
@ -415,22 +454,40 @@ func draw_pixel(pos : Vector2, color : Color, brush_size : int, brush_type : int
|
|||
src_rect.size.x = min(src_rect.size.x, selection_rect.size.x)
|
||||
src_rect.size.y = min(src_rect.size.y, selection_rect.size.y)
|
||||
|
||||
#Handle mirroring
|
||||
var mirror_x := east_limit + west_limit - dst.x - 1
|
||||
var mirror_y := south_limit + north_limit - dst.y - 1
|
||||
|
||||
if color.a > 0: #If it's the pencil
|
||||
layers[current_layer_index][0].blend_rect(custom_brush_image, src_rect, dst)
|
||||
if horizontal_mirror:
|
||||
layers[current_layer_index][0].blend_rect(custom_brush_image, src_rect, Vector2(mirror_x, dst.y))
|
||||
if vertical_mirror:
|
||||
layers[current_layer_index][0].blend_rect(custom_brush_image, src_rect, Vector2(dst.x, mirror_y))
|
||||
if horizontal_mirror && vertical_mirror:
|
||||
layers[current_layer_index][0].blend_rect(custom_brush_image, src_rect, Vector2(mirror_x, mirror_y))
|
||||
|
||||
else: #if it's transparent - if it's the eraser
|
||||
var custom_brush := Image.new()
|
||||
custom_brush.copy_from(Global.custom_brushes[brush_index])
|
||||
custom_brush_size = custom_brush.get_size()
|
||||
custom_brush.resize(custom_brush_size.x * brush_size, custom_brush_size.y * brush_size, Image.INTERPOLATE_NEAREST)
|
||||
var custom_brush_blended = Global.blend_image_with_color(custom_brush, color, 1)
|
||||
|
||||
layers[current_layer_index][0].blit_rect_mask(custom_brush_blended, custom_brush, src_rect, dst)
|
||||
if horizontal_mirror:
|
||||
layers[current_layer_index][0].blit_rect_mask(custom_brush_blended, custom_brush, src_rect, Vector2(mirror_x, dst.y))
|
||||
if vertical_mirror:
|
||||
layers[current_layer_index][0].blit_rect_mask(custom_brush_blended, custom_brush, src_rect, Vector2(dst.x, mirror_y))
|
||||
if horizontal_mirror && vertical_mirror:
|
||||
layers[current_layer_index][0].blit_rect_mask(custom_brush_blended, custom_brush, src_rect, Vector2(mirror_x, mirror_y))
|
||||
|
||||
layers[current_layer_index][0].lock()
|
||||
sprite_changed_this_frame = true
|
||||
|
||||
#Bresenham's Algorithm
|
||||
#Thanks to https://godotengine.org/qa/35276/tile-based-line-drawing-algorithm-efficiency
|
||||
func fill_gaps(mouse_pos : Vector2, color : Color, brush_size : int, brush_type : int, brush_index : int, custom_brush_image : Image) -> void:
|
||||
func fill_gaps(mouse_pos : Vector2, color : Color, current_mouse_button : String) -> void:
|
||||
var previous_mouse_pos_floored = previous_mouse_pos.floor()
|
||||
var mouse_pos_floored = mouse_pos.floor()
|
||||
mouse_pos_floored.x = clamp(mouse_pos_floored.x, location.x - 1, location.x + size.x)
|
||||
|
@ -444,7 +501,7 @@ func fill_gaps(mouse_pos : Vector2, color : Color, brush_size : int, brush_type
|
|||
var x = previous_mouse_pos_floored.x
|
||||
var y = previous_mouse_pos_floored.y
|
||||
while !(x == mouse_pos_floored.x && y == mouse_pos_floored.y):
|
||||
draw_pixel(Vector2(x, y), color, brush_size, brush_type, brush_index, custom_brush_image)
|
||||
draw_pixel(Vector2(x, y), color, current_mouse_button)
|
||||
e2 = err << 1
|
||||
if e2 >= dy:
|
||||
err += dy
|
||||
|
|
|
@ -78,6 +78,14 @@ var current_left_brush_type = BRUSH_TYPES.PIXEL
|
|||
# warning-ignore:unused_class_variable
|
||||
var current_right_brush_type = BRUSH_TYPES.PIXEL
|
||||
# warning-ignore:unused_class_variable
|
||||
var left_horizontal_mirror := false
|
||||
# warning-ignore:unused_class_variable
|
||||
var left_vertical_mirror := false
|
||||
# warning-ignore:unused_class_variable
|
||||
var right_horizontal_mirror := false
|
||||
# warning-ignore:unused_class_variable
|
||||
var right_vertical_mirror := false
|
||||
# warning-ignore:unused_class_variable
|
||||
var custom_brushes := []
|
||||
# warning-ignore:unused_class_variable
|
||||
var custom_left_brush_index := -1
|
||||
|
|
|
@ -757,4 +757,14 @@ func _on_RightInterpolateFactor_value_changed(value : float) -> void:
|
|||
func update_left_custom_brush() -> void:
|
||||
Global.update_left_custom_brush()
|
||||
func update_right_custom_brush() -> void:
|
||||
Global.update_right_custom_brush()
|
||||
Global.update_right_custom_brush()
|
||||
|
||||
func _on_LeftHorizontalMirroring_toggled(button_pressed) -> void:
|
||||
Global.left_horizontal_mirror = button_pressed
|
||||
func _on_LeftVerticalMirroring_toggled(button_pressed) -> void:
|
||||
Global.left_vertical_mirror = button_pressed
|
||||
|
||||
func _on_RightHorizontalMirroring_toggled(button_pressed) -> void:
|
||||
Global.right_horizontal_mirror = button_pressed
|
||||
func _on_RightVerticalMirroring_toggled(button_pressed) -> void:
|
||||
Global.right_vertical_mirror = button_pressed
|
Loading…
Reference in a new issue