mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Brush sizes and grid
- Changed UI layout - The user can now change brush sizes for both left and right mouse buttons. - A working grid - thanks to flurick!
This commit is contained in:
parent
dce7c4b110
commit
21397fefb2
173
Main.tscn
173
Main.tscn
|
@ -21,82 +21,185 @@ size_flags_horizontal = 3
|
|||
margin_right = 320.0
|
||||
margin_bottom = 600.0
|
||||
rect_min_size = Vector2( 320, 0 )
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="UI/ToolPanel"]
|
||||
margin_right = 40.0
|
||||
margin_bottom = 44.0
|
||||
[node name="Tools" type="VBoxContainer" parent="UI/ToolPanel"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="MenuItems" type="HBoxContainer" parent="UI/ToolPanel/VBoxContainer"]
|
||||
margin_right = 166.0
|
||||
[node name="MenusAndTools" type="VBoxContainer" parent="UI/ToolPanel/Tools"]
|
||||
margin_right = 320.0
|
||||
margin_bottom = 294.0
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="MenuItems" type="HBoxContainer" parent="UI/ToolPanel/Tools/MenusAndTools"]
|
||||
editor/display_folded = true
|
||||
margin_right = 320.0
|
||||
margin_bottom = 20.0
|
||||
|
||||
[node name="FileMenu" type="MenuButton" parent="UI/ToolPanel/VBoxContainer/MenuItems"]
|
||||
[node name="FileMenu" type="MenuButton" parent="UI/ToolPanel/Tools/MenusAndTools/MenuItems"]
|
||||
margin_right = 35.0
|
||||
margin_bottom = 20.0
|
||||
theme = ExtResource( 2 )
|
||||
text = "File"
|
||||
|
||||
[node name="EditMenu" type="MenuButton" parent="UI/ToolPanel/VBoxContainer/MenuItems"]
|
||||
[node name="EditMenu" type="MenuButton" parent="UI/ToolPanel/Tools/MenusAndTools/MenuItems"]
|
||||
margin_left = 39.0
|
||||
margin_right = 75.0
|
||||
margin_bottom = 20.0
|
||||
theme = ExtResource( 2 )
|
||||
text = "Edit"
|
||||
|
||||
[node name="ToolsContainer" type="HBoxContainer" parent="UI/ToolPanel/VBoxContainer"]
|
||||
[node name="ToolsContainer" type="HBoxContainer" parent="UI/ToolPanel/Tools/MenusAndTools"]
|
||||
margin_top = 24.0
|
||||
margin_right = 166.0
|
||||
margin_right = 320.0
|
||||
margin_bottom = 44.0
|
||||
|
||||
[node name="Pencil" type="Button" parent="UI/ToolPanel/VBoxContainer/ToolsContainer"]
|
||||
[node name="Pencil" type="Button" parent="UI/ToolPanel/Tools/MenusAndTools/ToolsContainer"]
|
||||
editor/display_folded = true
|
||||
margin_right = 51.0
|
||||
margin_bottom = 20.0
|
||||
hint_tooltip = "P for left mouse button
|
||||
Alt + P for right mouse button"
|
||||
button_mask = 3
|
||||
text = "Pencil"
|
||||
|
||||
[node name="LeftIndicator" type="Sprite" parent="UI/ToolPanel/VBoxContainer/ToolsContainer/Pencil"]
|
||||
z_index = 1
|
||||
[node name="LeftIndicator" type="Sprite" parent="UI/ToolPanel/Tools/MenusAndTools/ToolsContainer/Pencil"]
|
||||
texture = ExtResource( 3 )
|
||||
centered = false
|
||||
offset = Vector2( 0, -10 )
|
||||
|
||||
[node name="Eraser" type="Button" parent="UI/ToolPanel/VBoxContainer/ToolsContainer"]
|
||||
[node name="Eraser" type="Button" parent="UI/ToolPanel/Tools/MenusAndTools/ToolsContainer"]
|
||||
editor/display_folded = true
|
||||
margin_left = 55.0
|
||||
margin_right = 106.0
|
||||
margin_bottom = 20.0
|
||||
hint_tooltip = "E for left mouse button
|
||||
Alt + E for right mouse button"
|
||||
button_mask = 3
|
||||
text = "Eraser"
|
||||
|
||||
[node name="RightIndicator" type="Sprite" parent="UI/ToolPanel/VBoxContainer/ToolsContainer/Eraser"]
|
||||
z_index = 1
|
||||
[node name="RightIndicator" type="Sprite" parent="UI/ToolPanel/Tools/MenusAndTools/ToolsContainer/Eraser"]
|
||||
texture = ExtResource( 4 )
|
||||
centered = false
|
||||
offset = Vector2( 35, -10 )
|
||||
|
||||
[node name="Fill" type="Button" parent="UI/ToolPanel/VBoxContainer/ToolsContainer"]
|
||||
[node name="Fill" type="Button" parent="UI/ToolPanel/Tools/MenusAndTools/ToolsContainer"]
|
||||
margin_left = 110.0
|
||||
margin_right = 166.0
|
||||
margin_bottom = 20.0
|
||||
hint_tooltip = "B for left mouse button
|
||||
Alt + B for right mouse button"
|
||||
button_mask = 3
|
||||
text = "Bucket"
|
||||
|
||||
[node name="ColorPickers" type="HBoxContainer" parent="UI/ToolPanel/VBoxContainer"]
|
||||
margin_top = 48.0
|
||||
margin_right = 166.0
|
||||
margin_bottom = 80.0
|
||||
[node name="HSeparator" type="HSeparator" parent="UI/ToolPanel/Tools"]
|
||||
margin_top = 298.0
|
||||
margin_right = 320.0
|
||||
margin_bottom = 302.0
|
||||
|
||||
[node name="LeftColorPickerButton" type="ColorPickerButton" parent="UI/ToolPanel/VBoxContainer/ColorPickers"]
|
||||
[node name="ToolOptions" type="HBoxContainer" parent="UI/ToolPanel/Tools"]
|
||||
margin_top = 306.0
|
||||
margin_right = 320.0
|
||||
margin_bottom = 600.0
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="LeftToolOptions" type="VBoxContainer" parent="UI/ToolPanel/Tools/ToolOptions"]
|
||||
margin_right = 154.0
|
||||
margin_bottom = 294.0
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="LeftLabel" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"]
|
||||
margin_right = 154.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 = 154.0
|
||||
margin_bottom = 42.0
|
||||
pressed = true
|
||||
text = "Show left indicator"
|
||||
|
||||
[node name="LeftColorPickerButton" type="ColorPickerButton" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"]
|
||||
margin_top = 46.0
|
||||
margin_right = 32.0
|
||||
margin_bottom = 32.0
|
||||
margin_bottom = 78.0
|
||||
rect_min_size = Vector2( 32, 32 )
|
||||
hint_tooltip = "Color picker for the left tool"
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 0
|
||||
|
||||
[node name="RightColorPickerButton" type="ColorPickerButton" parent="UI/ToolPanel/VBoxContainer/ColorPickers"]
|
||||
margin_left = 36.0
|
||||
margin_right = 68.0
|
||||
margin_bottom = 32.0
|
||||
[node name="BrushSize" type="HBoxContainer" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"]
|
||||
margin_top = 82.0
|
||||
margin_right = 154.0
|
||||
margin_bottom = 106.0
|
||||
|
||||
[node name="BrushSizeLabel" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/BrushSize"]
|
||||
margin_top = 5.0
|
||||
margin_right = 75.0
|
||||
margin_bottom = 19.0
|
||||
text = "Brush size: "
|
||||
|
||||
[node name="LeftBrushSizeEdit" type="SpinBox" parent="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/BrushSize"]
|
||||
margin_left = 79.0
|
||||
margin_right = 153.0
|
||||
margin_bottom = 24.0
|
||||
min_value = 1.0
|
||||
value = 1.0
|
||||
suffix = "px"
|
||||
|
||||
[node name="VSeparator" type="VSeparator" parent="UI/ToolPanel/Tools/ToolOptions"]
|
||||
margin_left = 158.0
|
||||
margin_right = 162.0
|
||||
margin_bottom = 294.0
|
||||
|
||||
[node name="RightToolOptions" type="VBoxContainer" parent="UI/ToolPanel/Tools/ToolOptions"]
|
||||
margin_left = 166.0
|
||||
margin_right = 320.0
|
||||
margin_bottom = 294.0
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="RightLabel" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions"]
|
||||
margin_right = 154.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 = 154.0
|
||||
margin_bottom = 42.0
|
||||
text = "Show right indicator"
|
||||
|
||||
[node name="RightColorPickerButton" type="ColorPickerButton" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions"]
|
||||
margin_top = 46.0
|
||||
margin_right = 32.0
|
||||
margin_bottom = 78.0
|
||||
rect_min_size = Vector2( 32, 32 )
|
||||
hint_tooltip = "Color picker for the right tool"
|
||||
size_flags_horizontal = 0
|
||||
size_flags_vertical = 0
|
||||
|
||||
[node name="BrushSize" type="HBoxContainer" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions"]
|
||||
margin_top = 82.0
|
||||
margin_right = 154.0
|
||||
margin_bottom = 106.0
|
||||
|
||||
[node name="BrushSizeLabel" type="Label" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions/BrushSize"]
|
||||
margin_top = 5.0
|
||||
margin_right = 75.0
|
||||
margin_bottom = 19.0
|
||||
text = "Brush size: "
|
||||
|
||||
[node name="RightBrushSizeEdit" type="SpinBox" parent="UI/ToolPanel/Tools/ToolOptions/RightToolOptions/BrushSize"]
|
||||
margin_left = 79.0
|
||||
margin_right = 153.0
|
||||
margin_bottom = 24.0
|
||||
min_value = 1.0
|
||||
value = 1.0
|
||||
suffix = "px"
|
||||
|
||||
[node name="ViewportContainer" type="ViewportContainer" parent="UI"]
|
||||
editor/display_folded = true
|
||||
|
@ -151,12 +254,14 @@ margin_bottom = 38.0
|
|||
[node name="AddLayerButton" type="Button" parent="UI/LayerPanel/ScrollContainer/VBoxLayerContainer/HBoxContainer"]
|
||||
margin_right = 20.0
|
||||
margin_bottom = 20.0
|
||||
hint_tooltip = "Create a new layer"
|
||||
text = "+"
|
||||
|
||||
[node name="RemoveLayerButton" type="Button" parent="UI/LayerPanel/ScrollContainer/VBoxLayerContainer/HBoxContainer"]
|
||||
margin_left = 24.0
|
||||
margin_right = 44.0
|
||||
margin_bottom = 20.0
|
||||
hint_tooltip = "Remove current layer"
|
||||
disabled = true
|
||||
text = "X"
|
||||
|
||||
|
@ -164,6 +269,7 @@ text = "X"
|
|||
margin_left = 48.0
|
||||
margin_right = 67.0
|
||||
margin_bottom = 20.0
|
||||
hint_tooltip = "Move up the current layer"
|
||||
disabled = true
|
||||
text = "^"
|
||||
|
||||
|
@ -171,6 +277,7 @@ text = "^"
|
|||
margin_left = 71.0
|
||||
margin_right = 90.0
|
||||
margin_bottom = 20.0
|
||||
hint_tooltip = "Move down the current layer"
|
||||
disabled = true
|
||||
text = "v"
|
||||
|
||||
|
@ -178,12 +285,14 @@ text = "v"
|
|||
margin_left = 94.0
|
||||
margin_right = 118.0
|
||||
margin_bottom = 20.0
|
||||
hint_tooltip = "Clone current layer"
|
||||
text = "Cl"
|
||||
|
||||
[node name="MergeDownLayer" type="Button" parent="UI/LayerPanel/ScrollContainer/VBoxLayerContainer/HBoxContainer"]
|
||||
margin_left = 122.0
|
||||
margin_right = 146.0
|
||||
margin_bottom = 20.0
|
||||
hint_tooltip = "Merge down current layer"
|
||||
disabled = true
|
||||
text = "M"
|
||||
|
||||
|
@ -313,10 +422,14 @@ margin_left = 50.0
|
|||
margin_right = 108.0
|
||||
margin_bottom = 24.0
|
||||
text = "64"
|
||||
[connection signal="popup_closed" from="UI/ToolPanel/VBoxContainer/ColorPickers/LeftColorPickerButton" to="." method="_can_draw_true"]
|
||||
[connection signal="pressed" from="UI/ToolPanel/VBoxContainer/ColorPickers/LeftColorPickerButton" to="." method="_can_draw_false"]
|
||||
[connection signal="popup_closed" from="UI/ToolPanel/VBoxContainer/ColorPickers/RightColorPickerButton" to="." method="_can_draw_true"]
|
||||
[connection signal="pressed" from="UI/ToolPanel/VBoxContainer/ColorPickers/RightColorPickerButton" to="." method="_can_draw_false"]
|
||||
[connection signal="toggled" from="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/LeftIndicatorCheckbox" to="." method="_on_LeftIndicatorCheckbox_toggled"]
|
||||
[connection signal="popup_closed" from="UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/LeftColorPickerButton" to="." method="_can_draw_true"]
|
||||
[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/BrushSize/LeftBrushSizeEdit" to="." method="_on_LeftBrushSizeEdit_value_changed"]
|
||||
[connection signal="toggled" from="UI/ToolPanel/Tools/ToolOptions/RightToolOptions/RightIndicatorCheckbox" to="." method="_on_RightIndicatorCheckbox_toggled"]
|
||||
[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/BrushSize/RightBrushSizeEdit" to="." method="_on_RightBrushSizeEdit_value_changed"]
|
||||
[connection signal="mouse_entered" from="UI/ViewportContainer" to="." method="_on_ViewportContainer_mouse_entered"]
|
||||
[connection signal="mouse_exited" from="UI/ViewportContainer" to="." method="_on_ViewportContainer_mouse_exited"]
|
||||
[connection signal="pressed" from="UI/LayerPanel/ScrollContainer/VBoxLayerContainer/HBoxContainer/AddLayerButton" to="." method="_on_AddLayerButton_pressed"]
|
||||
|
|
|
@ -11,6 +11,10 @@ var size := Vector2(64, 64)
|
|||
var previous_mouse_pos := Vector2.ZERO
|
||||
var mouse_inside_canvas := false #used for undo
|
||||
var sprite_changed_this_frame := false #for optimization purposes
|
||||
var left_square_indicator_visible := true
|
||||
var right_square_indicator_visible := false
|
||||
var left_brush_size := 1
|
||||
var right_brush_size := 1
|
||||
var is_making_line := false
|
||||
var line_2d : Line2D
|
||||
var draw_grid := false
|
||||
|
@ -68,9 +72,9 @@ func _process(delta) -> void:
|
|||
current_color = Global.left_color_picker.color
|
||||
elif current_mouse_button == "R":
|
||||
current_color = Global.right_color_picker.color
|
||||
pencil_and_eraser(mouse_pos, current_color)
|
||||
pencil_and_eraser(mouse_pos, current_color, current_mouse_button)
|
||||
"Eraser":
|
||||
pencil_and_eraser(mouse_pos, Color(0, 0, 0, 0))
|
||||
pencil_and_eraser(mouse_pos, Color(0, 0, 0, 0), current_mouse_button)
|
||||
"Fill":
|
||||
if point_in_rectangle(mouse_pos, location, location + size) && Global.can_draw && Global.has_focus:
|
||||
var current_color : Color
|
||||
|
@ -107,17 +111,25 @@ func _draw() -> void:
|
|||
if texture[3]: #if it's visible
|
||||
draw_texture(texture[1], location)
|
||||
|
||||
#Draw grid (causes lag - unused. If you wanna test it just set draw_grid = true)
|
||||
#Idea taken from flurick (on GitHub)
|
||||
if draw_grid:
|
||||
for x in size.x:
|
||||
draw_line(Vector2(x, location.y), Vector2(x, size.y), Color.black, true)
|
||||
for y in size.y:
|
||||
draw_rect(Rect2(location.x + x, location.y + y, 1, 1), Color.black, false)
|
||||
draw_line(Vector2(location.x, y), Vector2(size.x, y), Color.black, true)
|
||||
|
||||
#Draw rectangle to indicate the pixel currently being hovered on
|
||||
var mouse_pos := get_local_mouse_position() - location
|
||||
if point_in_rectangle(mouse_pos, location, location + size):
|
||||
mouse_pos = mouse_pos.floor()
|
||||
draw_rect(Rect2(mouse_pos.x, mouse_pos.y, 1, 1), Color.red, false)
|
||||
if left_square_indicator_visible:
|
||||
var start_pos_x = mouse_pos.x - (left_brush_size >> 1)
|
||||
var start_pos_y = mouse_pos.y - (left_brush_size >> 1)
|
||||
draw_rect(Rect2(start_pos_x, start_pos_y, left_brush_size, left_brush_size), Color.blue, false)
|
||||
if right_square_indicator_visible:
|
||||
var start_pos_x = mouse_pos.x - (right_brush_size >> 1)
|
||||
var start_pos_y = mouse_pos.y - (right_brush_size >> 1)
|
||||
draw_rect(Rect2(start_pos_x, start_pos_y, right_brush_size, right_brush_size), Color.red, false)
|
||||
|
||||
func generate_layer_panels() -> void:
|
||||
for child in Global.vbox_layer_container.get_children():
|
||||
|
@ -141,7 +153,7 @@ func generate_layer_panels() -> void:
|
|||
layer_container.get_child(0).get_child(1).texture = layers[i][1]
|
||||
Global.vbox_layer_container.add_child(layer_container)
|
||||
|
||||
func pencil_and_eraser(mouse_pos : Vector2, color : Color) -> void:
|
||||
func pencil_and_eraser(mouse_pos : Vector2, color : Color, current_mouse_button : String) -> void:
|
||||
if Input.is_key_pressed(KEY_SHIFT):
|
||||
if !is_making_line:
|
||||
line_2d = Line2D.new()
|
||||
|
@ -152,26 +164,36 @@ func pencil_and_eraser(mouse_pos : Vector2, color : Color) -> void:
|
|||
add_child(line_2d)
|
||||
is_making_line = true
|
||||
else:
|
||||
var brush_size := 1
|
||||
if current_mouse_button == "L":
|
||||
brush_size = left_brush_size
|
||||
elif current_mouse_button == "R":
|
||||
brush_size = right_brush_size
|
||||
|
||||
if is_making_line:
|
||||
fill_gaps(mouse_pos, color)
|
||||
fill_gaps(mouse_pos, color, brush_size)
|
||||
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)
|
||||
fill_gaps(mouse_pos, color) #Fill the gaps
|
||||
draw_pixel(mouse_pos, color, brush_size)
|
||||
fill_gaps(mouse_pos, color, brush_size) #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)
|
||||
fill_gaps(mouse_pos, color, brush_size)
|
||||
|
||||
func draw_pixel(pos : Vector2, color : Color) -> void:
|
||||
if layers[current_layer_index][0].get_pixelv(pos) != color: #don't draw the same pixel over and over
|
||||
func draw_pixel(pos : Vector2, color : Color, brush_size : int) -> void:
|
||||
if Global.can_draw && Global.has_focus:
|
||||
#sprite.lock()
|
||||
layers[current_layer_index][0].set_pixelv(pos, color)
|
||||
#sprite.unlock()
|
||||
var start_pos_x = pos.x - (brush_size >> 1)
|
||||
var start_pos_y = pos.y - (brush_size >> 1)
|
||||
for cur_pos_x in range(start_pos_x, start_pos_x + brush_size):
|
||||
#layers[current_layer_index][0].set_pixel(cur_pos_x, pos.y, color)
|
||||
for cur_pos_y in range(start_pos_y, start_pos_y + brush_size):
|
||||
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)
|
||||
#layers[current_layer_index][0].set_pixelv(pos, color)
|
||||
sprite_changed_this_frame = true
|
||||
|
||||
func point_in_rectangle(p : Vector2, coord1 : Vector2, coord2 : Vector2) -> bool:
|
||||
|
@ -179,7 +201,7 @@ func point_in_rectangle(p : Vector2, coord1 : Vector2, coord2 : Vector2) -> bool
|
|||
|
||||
#Bresenham's Algorithm
|
||||
#Thanks to https://godotengine.org/qa/35276/tile-based-line-drawing-algorithm-efficiency
|
||||
func fill_gaps(mouse_pos : Vector2, color : Color) -> void:
|
||||
func fill_gaps(mouse_pos : Vector2, color : Color, brush_size : int) -> 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)
|
||||
|
@ -193,7 +215,7 @@ func fill_gaps(mouse_pos : Vector2, color : Color) -> void:
|
|||
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)
|
||||
draw_pixel(Vector2(x, y), color, brush_size)
|
||||
e2 = err << 1
|
||||
if e2 >= dy:
|
||||
err += dy
|
||||
|
@ -221,7 +243,7 @@ func flood_fill(pos : Vector2, target_color : Color, replace_color : Color) -> v
|
|||
east += Vector2.RIGHT
|
||||
for px in range(west.x + 1, east.x):
|
||||
var p := Vector2(px, n.y)
|
||||
draw_pixel(p, replace_color)
|
||||
draw_pixel(p, replace_color, 1)
|
||||
var north := p + Vector2.UP
|
||||
var south := p + Vector2.DOWN
|
||||
if north.y >= location.y && layers[current_layer_index][0].get_pixelv(north) == target_color:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
extends PanelContainer
|
||||
|
||||
var i
|
||||
# warning-ignore:unused_class_variable
|
||||
var currently_selected := false
|
||||
var visibility_toggled := false
|
||||
|
||||
|
|
|
@ -15,34 +15,32 @@ func _ready() -> void:
|
|||
"Export as..." : KEY_MASK_SHIFT + KEY_MASK_CTRL + KEY_S,
|
||||
"Quit" : KEY_MASK_CTRL + KEY_Q
|
||||
}
|
||||
# var edit_menu_items := {
|
||||
# "Undo" : KEY_MASK_CTRL + KEY_Z,
|
||||
# "Redo" : KEY_MASK_SHIFT + KEY_MASK_CTRL + KEY_Z,
|
||||
# "Scale Image" : 0
|
||||
# }
|
||||
var edit_menu_items := {
|
||||
"Show Grid" : KEY_MASK_CTRL + KEY_G
|
||||
#"Undo" : KEY_MASK_CTRL + KEY_Z,
|
||||
#"Redo" : KEY_MASK_SHIFT + KEY_MASK_CTRL + KEY_Z,
|
||||
#"Scale Image" : 0
|
||||
}
|
||||
var file_menu : PopupMenu = Global.file_menu.get_popup()
|
||||
var edit_menu : PopupMenu = Global.edit_menu.get_popup()
|
||||
var i = 0
|
||||
for item in file_menu_items.keys():
|
||||
file_menu.add_item(item, i, file_menu_items[item])
|
||||
i += 1
|
||||
# i = 0
|
||||
# for item in edit_menu_items.keys():
|
||||
# edit_menu.add_item(item, i, edit_menu_items[item])
|
||||
# i += 1
|
||||
i = 0
|
||||
for item in edit_menu_items.keys():
|
||||
edit_menu.add_item(item, i, edit_menu_items[item])
|
||||
i += 1
|
||||
file_menu.connect("id_pressed", self, "file_menu_id_pressed")
|
||||
#edit_menu.connect("id_pressed", self, "edit_menu_id_pressed")
|
||||
edit_menu.connect("id_pressed", self, "edit_menu_id_pressed")
|
||||
|
||||
pencil_tool = $UI/ToolPanel/VBoxContainer/ToolsContainer/Pencil
|
||||
eraser_tool = $UI/ToolPanel/VBoxContainer/ToolsContainer/Eraser
|
||||
fill_tool = $UI/ToolPanel/VBoxContainer/ToolsContainer/Fill
|
||||
pencil_tool = $UI/ToolPanel/Tools/MenusAndTools/ToolsContainer/Pencil
|
||||
eraser_tool = $UI/ToolPanel/Tools/MenusAndTools/ToolsContainer/Eraser
|
||||
fill_tool = $UI/ToolPanel/Tools/MenusAndTools/ToolsContainer/Fill
|
||||
|
||||
pencil_tool.connect("pressed", self, "_on_Tool_pressed", [pencil_tool])
|
||||
eraser_tool.connect("pressed", self, "_on_Tool_pressed", [eraser_tool])
|
||||
fill_tool.connect("pressed", self, "_on_Tool_pressed", [fill_tool])
|
||||
pencil_tool.hint_tooltip = "P for left mouse button, Alt + P for right mouse button"
|
||||
eraser_tool.hint_tooltip = "E for left mouse button, Alt + E for right mouse button"
|
||||
fill_tool.hint_tooltip = "B for left mouse button, Alt + B for right mouse button"
|
||||
|
||||
func _input(event):
|
||||
#Handle tool shortcuts
|
||||
|
@ -80,6 +78,11 @@ func file_menu_id_pressed(id : int) -> void:
|
|||
4: #Quit
|
||||
get_tree().quit()
|
||||
|
||||
func edit_menu_id_pressed(id : int) -> void:
|
||||
match id:
|
||||
0: #Show grid
|
||||
Global.canvas.draw_grid = !Global.canvas.draw_grid
|
||||
|
||||
func _on_CreateNewImage_confirmed() -> void:
|
||||
var width = float($CreateNewImage/VBoxContainer/WidthCont/LineEdit.text)
|
||||
var height = float($CreateNewImage/VBoxContainer/HeightCont/LineEdit.text)
|
||||
|
@ -97,12 +100,22 @@ func _on_OpenSprite_file_selected(path : String) -> void:
|
|||
OS.alert("Can't load file")
|
||||
|
||||
func new_canvas(size : Vector2, sprite : Image = null) -> void:
|
||||
var left_indicator_visible = Global.canvas.left_square_indicator_visible
|
||||
var right_indicator_visible = Global.canvas.right_square_indicator_visible
|
||||
var left_brush_size = Global.canvas.left_brush_size
|
||||
var right_brush_size = Global.canvas.right_brush_size
|
||||
|
||||
for child in Global.vbox_layer_container.get_children():
|
||||
if child is PanelContainer:
|
||||
child.queue_free()
|
||||
Global.canvas.queue_free()
|
||||
Global.canvas = load("res://Canvas.tscn").instance()
|
||||
Global.canvas.size = size
|
||||
Global.canvas.left_square_indicator_visible = left_indicator_visible
|
||||
Global.canvas.right_square_indicator_visible = right_indicator_visible
|
||||
Global.canvas.left_brush_size = left_brush_size
|
||||
Global.canvas.right_brush_size = right_brush_size
|
||||
|
||||
if sprite:
|
||||
Global.canvas.current_sprite = sprite
|
||||
Global.canvas.current_sprite.convert(Image.FORMAT_RGBA8)
|
||||
|
@ -212,3 +225,17 @@ func _on_MergeLayer_pressed() -> void:
|
|||
Global.canvas.layers[Global.canvas.current_layer_index - 1][0].lock()
|
||||
Global.canvas.update_texture(Global.canvas.current_layer_index - 1)
|
||||
_on_RemoveLayerButton_pressed()
|
||||
|
||||
func _on_LeftIndicatorCheckbox_toggled(button_pressed):
|
||||
Global.canvas.left_square_indicator_visible = button_pressed
|
||||
|
||||
func _on_RightIndicatorCheckbox_toggled(button_pressed):
|
||||
Global.canvas.right_square_indicator_visible = button_pressed
|
||||
|
||||
func _on_LeftBrushSizeEdit_value_changed(value):
|
||||
var new_size = int(value)
|
||||
Global.canvas.left_brush_size = new_size
|
||||
|
||||
func _on_RightBrushSizeEdit_value_changed(value):
|
||||
var new_size = int(value)
|
||||
Global.canvas.right_brush_size = new_size
|
||||
|
|
|
@ -1,28 +1,5 @@
|
|||
[preset.0]
|
||||
|
||||
name="HTML5"
|
||||
platform="HTML5"
|
||||
runnable=true
|
||||
custom_features=""
|
||||
export_filter="all_resources"
|
||||
include_filter=""
|
||||
exclude_filter=""
|
||||
export_path="C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Sprite Editor/Exported/HTML5/Sprite Editor.html"
|
||||
patch_list=PoolStringArray( )
|
||||
script_export_mode=1
|
||||
script_encryption_key=""
|
||||
|
||||
[preset.0.options]
|
||||
|
||||
vram_texture_compression/for_desktop=true
|
||||
vram_texture_compression/for_mobile=false
|
||||
html/custom_html_shell=""
|
||||
html/head_include=""
|
||||
custom_template/release=""
|
||||
custom_template/debug=""
|
||||
|
||||
[preset.1]
|
||||
|
||||
name="Windows Desktop"
|
||||
platform="Windows Desktop"
|
||||
runnable=true
|
||||
|
@ -30,12 +7,12 @@ custom_features=""
|
|||
export_filter="all_resources"
|
||||
include_filter=""
|
||||
exclude_filter=""
|
||||
export_path="C:/Users/manos/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Sprite Editor/Exported/Sprite Editor.exe"
|
||||
export_path="C:/Users/Overloaded/Dropbox/Orama Interactive/Projects/Pixelorama/Pixelorama.exe"
|
||||
patch_list=PoolStringArray( )
|
||||
script_export_mode=1
|
||||
script_encryption_key=""
|
||||
|
||||
[preset.1.options]
|
||||
[preset.0.options]
|
||||
|
||||
texture_format/bptc=false
|
||||
texture_format/s3tc=true
|
||||
|
@ -46,10 +23,10 @@ binary_format/64_bits=true
|
|||
custom_template/release=""
|
||||
custom_template/debug=""
|
||||
application/icon=""
|
||||
application/file_version=""
|
||||
application/product_version=""
|
||||
application/company_name=""
|
||||
application/product_name=""
|
||||
application/file_version="0.1"
|
||||
application/product_version="0.1"
|
||||
application/company_name="Orama Interactive"
|
||||
application/product_name="Pixelorama"
|
||||
application/file_description=""
|
||||
application/copyright=""
|
||||
application/copyright="Orama Interactive 2019"
|
||||
application/trademarks=""
|
||||
|
|
Loading…
Reference in a new issue