mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 09:09:47 +00:00
Remove trailing whitespace and ensure newlines at end of files
This commit is contained in:
parent
c08561b92b
commit
f407de234b
|
@ -10,4 +10,3 @@ source_file="res://Assets/Graphics/Transparent Background.png"
|
|||
dest_files=[ "res://.import/Transparent Background.png-62a2c5eb3e805ff7dbb890edc2b8d883.image" ]
|
||||
|
||||
[params]
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# Pixelorama - your free and open-source sprite editor!
|
||||
A free & open-source 2D sprite editor, made with Godot Engine, using GDScript!
|
||||
|
||||
|
||||
[![Pixelorama's horrible UI](https://functionoverload590613498.files.wordpress.com/2019/10/screenshot_265.png)](https://www.youtube.com/watch?v=L8o8QKB8lPs)
|
||||
|
||||
|
||||
Current features as of version v0.3:
|
||||
|
||||
- Choosing between 4 tools – pencil, eraser, fill bucket and rectangle select – and mapping them to both of your left and right mouse buttons. That’s, pretty wild, huh?
|
||||
|
|
|
@ -11,11 +11,11 @@ func _on_BrushButton_pressed() -> void:
|
|||
if custom_brush_index > -1:
|
||||
Global.custom_left_brush_index = custom_brush_index
|
||||
Global.update_left_custom_brush()
|
||||
|
||||
|
||||
elif Input.is_action_just_released("right_mouse"):
|
||||
Global.current_right_brush_type = brush_type
|
||||
Global.right_brush_indicator.get_parent().remove_child(Global.right_brush_indicator)
|
||||
add_child(Global.right_brush_indicator)
|
||||
if custom_brush_index > -1:
|
||||
Global.custom_right_brush_index = custom_brush_index
|
||||
Global.update_right_custom_brush()
|
||||
Global.update_right_custom_brush()
|
||||
|
|
|
@ -15,7 +15,7 @@ func _input(event) -> void:
|
|||
drag = true
|
||||
elif event.is_action_released("camera_drag"):
|
||||
drag = false
|
||||
|
||||
|
||||
if Global.can_draw && Global.has_focus && Rect2(Vector2.ZERO, viewport_size).has_point(mouse_pos):
|
||||
if event.is_action_pressed("zoom_in"): # Wheel Up Event
|
||||
zoom_camera(-1)
|
||||
|
@ -30,8 +30,8 @@ func zoom_camera(dir : int) -> void:
|
|||
#if zoom + zoom_margin > zoom_min && zoom + zoom_margin < zoom_max:
|
||||
if zoom + zoom_margin > zoom_min:
|
||||
zoom += zoom_margin
|
||||
|
||||
|
||||
if zoom > zoom_max:
|
||||
zoom = zoom_max
|
||||
if name == "Camera2D":
|
||||
Global.zoom_level_label.text = "Zoom: x%s" % [stepify(1 / zoom.x, 0.01)]
|
||||
Global.zoom_level_label.text = "Zoom: x%s" % [stepify(1 / zoom.x, 0.01)]
|
||||
|
|
|
@ -24,30 +24,30 @@ func _ready() -> void:
|
|||
#Background
|
||||
trans_background = ImageTexture.new()
|
||||
trans_background.create_from_image(load("res://Assets/Graphics/Transparent Background.png"), 0)
|
||||
|
||||
|
||||
#The sprite itself
|
||||
if layers.empty():
|
||||
var sprite := Image.new()
|
||||
sprite.create(size.x, size.y, false, Image.FORMAT_RGBA8)
|
||||
|
||||
|
||||
sprite.lock()
|
||||
var tex := ImageTexture.new()
|
||||
tex.create_from_image(sprite, 0)
|
||||
|
||||
|
||||
#Store [Image, ImageTexture, Layer Name, Visibity boolean]
|
||||
layers.append([sprite, tex, "Layer 0", true])
|
||||
|
||||
|
||||
generate_layer_panels()
|
||||
|
||||
|
||||
frame_button = load("res://Prefabs/FrameButton.tscn").instance()
|
||||
frame_button.name = "Frame_%s" % frame
|
||||
frame_button.get_node("FrameButton").frame = frame
|
||||
frame_button.get_node("FrameID").text = str(frame + 1)
|
||||
Global.frame_container.add_child(frame_button)
|
||||
|
||||
|
||||
frame_texture_rect = Global.find_node_by_name(frame_button, "FrameTexture")
|
||||
frame_texture_rect.texture = layers[0][1] #ImageTexture current_layer_index
|
||||
|
||||
|
||||
camera_zoom()
|
||||
|
||||
func camera_zoom() -> void:
|
||||
|
@ -82,7 +82,7 @@ func _process(delta) -> void:
|
|||
elif Input.is_mouse_button_pressed(BUTTON_RIGHT):
|
||||
current_mouse_button = "right_mouse"
|
||||
current_action = Global.current_right_tool
|
||||
|
||||
|
||||
if visible:
|
||||
if !point_in_rectangle(mouse_pos, location, location + size):
|
||||
if !Input.is_mouse_button_pressed(BUTTON_LEFT) && !Input.is_mouse_button_pressed(BUTTON_RIGHT):
|
||||
|
@ -117,7 +117,7 @@ func _process(delta) -> void:
|
|||
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)
|
||||
|
@ -128,7 +128,7 @@ func _process(delta) -> void:
|
|||
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) && Global.current_frame == frame:
|
||||
var current_color : Color
|
||||
|
@ -136,7 +136,7 @@ func _process(delta) -> void:
|
|||
current_color = Global.left_color_picker.color
|
||||
elif current_mouse_button == "right_mouse":
|
||||
current_color = Global.right_color_picker.color
|
||||
|
||||
|
||||
var pixel_color : Color = layers[current_layer_index][0].get_pixelv(mouse_pos)
|
||||
for xx in size.x:
|
||||
for yy in size.y:
|
||||
|
@ -177,14 +177,14 @@ func _process(delta) -> void:
|
|||
Global.selection_rectangle.polygon[1] = Vector2(end_pos.x, start_pos.y)
|
||||
Global.selection_rectangle.polygon[2] = end_pos
|
||||
Global.selection_rectangle.polygon[3] = Vector2(start_pos.x, end_pos.y)
|
||||
|
||||
|
||||
if !is_making_line:
|
||||
previous_mouse_pos = mouse_pos
|
||||
previous_mouse_pos.x = clamp(previous_mouse_pos.x, location.x, location.x + size.x)
|
||||
previous_mouse_pos.y = clamp(previous_mouse_pos.y, location.y, location.y + size.y)
|
||||
else:
|
||||
line_2d.set_point_position(1, mouse_pos)
|
||||
|
||||
|
||||
if is_making_selection != "None": #If we're making a selection
|
||||
if Input.is_action_just_released(is_making_selection): #Finish selection when button is released
|
||||
var start_pos = Global.selection_rectangle.polygon[0]
|
||||
|
@ -193,30 +193,30 @@ func _process(delta) -> void:
|
|||
var temp = end_pos.x
|
||||
end_pos.x = start_pos.x
|
||||
start_pos.x = temp
|
||||
|
||||
|
||||
if start_pos.y > end_pos.y:
|
||||
var temp = end_pos.y
|
||||
end_pos.y = start_pos.y
|
||||
start_pos.y = temp
|
||||
|
||||
|
||||
Global.selection_rectangle.polygon[0] = start_pos
|
||||
Global.selection_rectangle.polygon[1] = Vector2(end_pos.x, start_pos.y)
|
||||
Global.selection_rectangle.polygon[2] = end_pos
|
||||
Global.selection_rectangle.polygon[3] = Vector2(start_pos.x, end_pos.y)
|
||||
|
||||
|
||||
for xx in range(start_pos.x, end_pos.x):
|
||||
for yy in range(start_pos.y, end_pos.y):
|
||||
Global.selected_pixels.append(Vector2(xx, yy))
|
||||
is_making_selection = "None"
|
||||
|
||||
|
||||
if sprite_changed_this_frame:
|
||||
update_texture(current_layer_index)
|
||||
|
||||
|
||||
|
||||
func update_texture(layer_index : int) -> void:
|
||||
layers[layer_index][1].create_from_image(layers[layer_index][0], 0)
|
||||
get_layer_container(layer_index).get_child(0).get_child(1).texture = layers[layer_index][1]
|
||||
|
||||
|
||||
#This code is used to update the texture in the animation timeline frame button
|
||||
#but blend_rect causes major performance issues on large images
|
||||
var whole_image := Image.new()
|
||||
|
@ -249,7 +249,7 @@ func _draw() -> void:
|
|||
for texture in Global.canvases[Global.current_frame - i].layers:
|
||||
color.a = 0.6/i
|
||||
draw_texture(texture[1], location, color)
|
||||
|
||||
|
||||
#Future
|
||||
if Global.onion_skinning_future_rate > 0:
|
||||
var color : Color
|
||||
|
@ -262,12 +262,12 @@ func _draw() -> void:
|
|||
for texture in Global.canvases[Global.current_frame + i].layers:
|
||||
color.a = 0.6/i
|
||||
draw_texture(texture[1], location, color)
|
||||
|
||||
|
||||
#Draw current frame layers
|
||||
for texture in layers:
|
||||
if texture[3]: #if it's visible
|
||||
draw_texture(texture[1], location)
|
||||
|
||||
|
||||
if Global.tile_mode:
|
||||
draw_texture(texture[1], Vector2(location.x, location.y + size.y)) #Down
|
||||
draw_texture(texture[1], Vector2(location.x - size.x, location.y + size.y)) #Down Left
|
||||
|
@ -277,14 +277,14 @@ func _draw() -> void:
|
|||
draw_texture(texture[1], Vector2(location.x + size.x, location.y - size.y)) #Up right
|
||||
draw_texture(texture[1], Vector2(location.x + size.x, location.y)) #Right
|
||||
draw_texture(texture[1], location + size) #Down right
|
||||
|
||||
|
||||
#Idea taken from flurick (on GitHub)
|
||||
if Global.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_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):
|
||||
|
@ -299,7 +299,7 @@ func _draw() -> void:
|
|||
var custom_brush_size = Global.custom_left_brush_image.get_size() - Vector2.ONE
|
||||
var dst := rectangle_center(mouse_pos, custom_brush_size)
|
||||
draw_texture(Global.custom_left_brush_texture, dst)
|
||||
|
||||
|
||||
if Global.right_square_indicator_visible:
|
||||
match Global.current_right_brush_type:
|
||||
Global.BRUSH_TYPES.PIXEL:
|
||||
|
@ -315,7 +315,7 @@ func generate_layer_panels() -> void:
|
|||
for child in Global.vbox_layer_container.get_children():
|
||||
if child is PanelContainer:
|
||||
child.queue_free()
|
||||
|
||||
|
||||
current_layer_index = layers.size() - 1
|
||||
if layers.size() == 1:
|
||||
Global.remove_layer_button.disabled = true
|
||||
|
@ -323,7 +323,7 @@ func generate_layer_panels() -> void:
|
|||
else:
|
||||
Global.remove_layer_button.disabled = false
|
||||
Global.remove_layer_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
|
||||
|
||||
for i in range(layers.size() -1, -1, -1):
|
||||
var layer_container = load("res://Prefabs/LayerContainer.tscn").instance()
|
||||
layers[i][2] = "Layer %s" % i
|
||||
|
@ -365,7 +365,7 @@ func draw_pixel(pos : Vector2, color : Color, current_mouse_button : String) ->
|
|||
var brush_index := -1
|
||||
var custom_brush_image : Image
|
||||
var horizontal_mirror := false
|
||||
var vertical_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
|
||||
|
@ -380,7 +380,7 @@ func draw_pixel(pos : Vector2, color : Color, current_mouse_button : String) ->
|
|||
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
|
||||
|
@ -390,12 +390,12 @@ func draw_pixel(pos : Vector2, color : Color, current_mouse_button : String) ->
|
|||
east_limit = min(east_limit, Global.selection_rectangle.polygon[2].x)
|
||||
north_limit = max(north_limit, Global.selection_rectangle.polygon[0].y)
|
||||
south_limit = min(south_limit, Global.selection_rectangle.polygon[2].y)
|
||||
|
||||
|
||||
var start_pos_x
|
||||
var start_pos_y
|
||||
var end_pos_x
|
||||
var end_pos_y
|
||||
|
||||
|
||||
match(brush_type):
|
||||
Global.BRUSH_TYPES.PIXEL:
|
||||
start_pos_x = pos.x - (brush_size >> 1)
|
||||
|
@ -423,7 +423,7 @@ func draw_pixel(pos : Vector2, color : Color, current_mouse_button : String) ->
|
|||
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
|
||||
pos = pos.floor()
|
||||
|
@ -432,7 +432,7 @@ func draw_pixel(pos : Vector2, color : Color, current_mouse_button : String) ->
|
|||
#Rectangle with the same size as the brush, but at cursor's position
|
||||
#var pos_rect_position := rectangle_center(pos, custom_brush_size)
|
||||
var pos_rect := Rect2(dst, custom_brush_size + Vector2.ONE)
|
||||
|
||||
|
||||
#The selection rectangle
|
||||
#If there's no rectangle, the whole canvas is considered a selection
|
||||
var selection_rect := Rect2()
|
||||
|
@ -443,7 +443,7 @@ func draw_pixel(pos : Vector2, color : Color, current_mouse_button : String) ->
|
|||
#If the size is 0, that means that the brush wasn't positioned inside the selection
|
||||
if pos_rect_clipped.size == Vector2.ZERO:
|
||||
return
|
||||
|
||||
|
||||
#Re-position src_rect and dst based on the clipped position
|
||||
var pos_difference := (pos_rect.position - pos_rect_clipped.position).abs()
|
||||
#Obviously, if pos_rect and pos_rect_clipped are the same, pos_difference is Vector2.ZERO
|
||||
|
@ -454,11 +454,11 @@ func draw_pixel(pos : Vector2, color : Color, current_mouse_button : String) ->
|
|||
#... make sure pixels aren't being drawn outside the selection by adjusting src_rect's size
|
||||
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:
|
||||
|
@ -467,14 +467,14 @@ func draw_pixel(pos : Vector2, color : Color, current_mouse_button : String) ->
|
|||
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))
|
||||
|
@ -482,7 +482,7 @@ func draw_pixel(pos : Vector2, color : Color, current_mouse_button : String) ->
|
|||
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
|
||||
|
||||
|
@ -529,10 +529,10 @@ func flood_fill(pos : Vector2, target_color : Color, replace_color : Color) -> v
|
|||
east_limit = min(east_limit, Global.selection_rectangle.polygon[2].x)
|
||||
north_limit = max(north_limit, Global.selection_rectangle.polygon[0].y)
|
||||
south_limit = min(south_limit, Global.selection_rectangle.polygon[2].y)
|
||||
|
||||
|
||||
if !point_in_rectangle(pos, Vector2(west_limit - 1, north_limit - 1), Vector2(east_limit, south_limit)):
|
||||
return
|
||||
|
||||
|
||||
var q = [pos]
|
||||
for n in q:
|
||||
var west : Vector2 = n
|
||||
|
@ -566,4 +566,3 @@ func rectangle_center(pos : Vector2, size : Vector2) -> Vector2:
|
|||
|
||||
func _on_Timer_timeout() -> void:
|
||||
Global.can_draw = true
|
||||
|
|
@ -4,4 +4,4 @@ var frame := 0
|
|||
|
||||
func _on_FrameButton_pressed() -> void:
|
||||
Global.current_frame = frame
|
||||
Global.change_frame()
|
||||
Global.change_frame()
|
||||
|
|
|
@ -111,10 +111,10 @@ func _ready() -> void:
|
|||
split_screen_button = find_node_by_name(root, "SplitScreenButton")
|
||||
camera = find_node_by_name(canvas_parent, "Camera2D")
|
||||
camera2 = find_node_by_name(canvas_parent.get_parent().get_parent(), "Camera2D2")
|
||||
|
||||
|
||||
selection_rectangle = find_node_by_name(root, "SelectionRectangle")
|
||||
image_clipboard = Image.new()
|
||||
|
||||
|
||||
file_menu = find_node_by_name(root, "FileMenu")
|
||||
edit_menu = find_node_by_name(root, "EditMenu")
|
||||
view_menu = find_node_by_name(root, "ViewMenu")
|
||||
|
@ -127,10 +127,10 @@ func _ready() -> void:
|
|||
right_brush_size_edit = find_node_by_name(root, "RightBrushSizeEdit")
|
||||
left_interpolate_slider = find_node_by_name(root, "LeftInterpolateFactor")
|
||||
right_interpolate_slider = find_node_by_name(root, "RightInterpolateFactor")
|
||||
|
||||
|
||||
left_brush_indicator = find_node_by_name(root, "LeftBrushIndicator")
|
||||
right_brush_indicator = find_node_by_name(root, "RightBrushIndicator")
|
||||
|
||||
|
||||
loop_animation_button = find_node_by_name(root, "LoopAnim")
|
||||
play_forward = find_node_by_name(root, "PlayForward")
|
||||
play_backwards = find_node_by_name(root, "PlayBackwards")
|
||||
|
@ -147,15 +147,15 @@ func _ready() -> void:
|
|||
zoom_level_label = find_node_by_name(root, "ZoomLevel")
|
||||
current_frame_label = find_node_by_name(root, "CurrentFrame")
|
||||
|
||||
#Thanks to https://godotengine.org/qa/17524/how-to-find-an-instanced-scene-by-its-name
|
||||
#Thanks to https://godotengine.org/qa/17524/how-to-find-an-instanced-scene-by-its-name
|
||||
func find_node_by_name(root, node_name) -> Node:
|
||||
if root.get_name() == node_name:
|
||||
if root.get_name() == node_name:
|
||||
return root
|
||||
for child in root.get_children():
|
||||
if child.get_name() == node_name:
|
||||
return child
|
||||
var found = find_node_by_name(child, node_name)
|
||||
if found:
|
||||
if found:
|
||||
return found
|
||||
return null
|
||||
|
||||
|
@ -174,7 +174,7 @@ func handle_layer_order_buttons() -> void:
|
|||
else:
|
||||
move_left_frame_button.disabled = false
|
||||
move_left_frame_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
|
||||
|
||||
if current_frame == canvases.size() - 1:
|
||||
move_right_frame_button.disabled = true
|
||||
move_right_frame_button.mouse_default_cursor_shape = Control.CURSOR_FORBIDDEN
|
||||
|
@ -212,7 +212,7 @@ func update_left_custom_brush() -> void:
|
|||
custom_brush.resize(custom_brush_size.x * left_brush_size, custom_brush_size.y * left_brush_size, Image.INTERPOLATE_NEAREST)
|
||||
custom_left_brush_image = blend_image_with_color(custom_brush, left_color_picker.color, left_interpolate_slider.value)
|
||||
custom_left_brush_texture.create_from_image(custom_left_brush_image, 0)
|
||||
|
||||
|
||||
func update_right_custom_brush() -> void:
|
||||
if custom_right_brush_index > -1:
|
||||
var custom_brush := Image.new()
|
||||
|
@ -237,4 +237,4 @@ func blend_image_with_color(image : Image, color : Color, interpolate_factor : f
|
|||
blended_image.set_pixel(xx, yy, new_color)
|
||||
else: #If color is transparent - if it's the eraser
|
||||
blended_image.set_pixel(xx, yy, Color(0, 0, 0, 0))
|
||||
return blended_image
|
||||
return blended_image
|
||||
|
|
|
@ -26,14 +26,14 @@ func changed_selection() -> void:
|
|||
if Global.canvas.current_layer_index == child.i:
|
||||
child.currently_selected = true
|
||||
child.get_stylebox("panel").bg_color = Color("282532")
|
||||
|
||||
|
||||
if Global.canvas.current_layer_index < Global.canvas.layers.size() - 1:
|
||||
Global.move_up_layer_button.disabled = false
|
||||
Global.move_up_layer_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
else:
|
||||
Global.move_up_layer_button.disabled = true
|
||||
Global.move_up_layer_button.mouse_default_cursor_shape = Control.CURSOR_FORBIDDEN
|
||||
|
||||
|
||||
if Global.canvas.current_layer_index > 0:
|
||||
Global.move_down_layer_button.disabled = false
|
||||
Global.move_down_layer_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
|
@ -61,4 +61,4 @@ func _on_VisibilityButton_button_down() -> void:
|
|||
visibility_toggled = true
|
||||
|
||||
func _on_VisibilityButton_button_up() -> void:
|
||||
visibility_toggled = false
|
||||
visibility_toggled = false
|
||||
|
|
|
@ -19,7 +19,7 @@ func _ready() -> void:
|
|||
# Set a minimum window size to prevent UI elements from collapsing on each other.
|
||||
# This property is only available in 3.2alpha or later, so use `set()` to fail gracefully if it doesn't exist.
|
||||
OS.set("min_window_size", Vector2(1024, 600))
|
||||
|
||||
|
||||
var file_menu_items := {
|
||||
"New..." : KEY_MASK_CTRL + KEY_N,
|
||||
"Open..." : KEY_MASK_CTRL + KEY_O,
|
||||
|
@ -50,7 +50,7 @@ func _ready() -> void:
|
|||
var edit_menu : PopupMenu = Global.edit_menu.get_popup()
|
||||
view_menu = Global.view_menu.get_popup()
|
||||
var help_menu : PopupMenu = Global.help_menu.get_popup()
|
||||
|
||||
|
||||
var i = 0
|
||||
for item in file_menu_items.keys():
|
||||
file_menu.add_item(item, i, file_menu_items[item])
|
||||
|
@ -67,12 +67,12 @@ func _ready() -> void:
|
|||
for item in help_menu_items.keys():
|
||||
help_menu.add_item(item, i, help_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")
|
||||
view_menu.connect("id_pressed", self, "view_menu_id_pressed")
|
||||
help_menu.connect("id_pressed", self, "help_menu_id_pressed")
|
||||
|
||||
|
||||
var root = get_tree().get_root()
|
||||
#Node, left mouse shortcut, right mouse shortcut
|
||||
tools.append([Global.find_node_by_name(root, "Pencil"), "left_pencil_tool", "right_pencil_tool"])
|
||||
|
@ -81,15 +81,15 @@ func _ready() -> void:
|
|||
tools.append([Global.find_node_by_name(root, "PaintAllPixelsSameColor"), "left_paint_all_tool", "right_paint_all_tool"])
|
||||
tools.append([Global.find_node_by_name(root, "LightenDarken"), "left_lightdark_tool", "right_lightdark_tool"])
|
||||
tools.append([Global.find_node_by_name(root, "RectSelect"), "left_rectangle_select_tool", "right_rectangle_select_tool"])
|
||||
|
||||
|
||||
for t in tools:
|
||||
t[0].connect("pressed", self, "_on_Tool_pressed", [t[0]])
|
||||
|
||||
|
||||
#Options for Import
|
||||
import_as_new_frame = CheckBox.new()
|
||||
import_as_new_frame.text = "Import as new frame?"
|
||||
$ImportSprites.get_vbox().add_child(import_as_new_frame)
|
||||
|
||||
|
||||
#Options for Export
|
||||
export_all_frames = CheckBox.new()
|
||||
export_all_frames.text = "Export all frames?"
|
||||
|
@ -100,7 +100,7 @@ func _ready() -> void:
|
|||
$ExportSprites.get_vbox().add_child(export_all_frames)
|
||||
$ExportSprites.get_vbox().add_child(export_as_single_file)
|
||||
$ExportSprites.get_vbox().add_child(export_vertical_spritesheet)
|
||||
|
||||
|
||||
|
||||
func _input(event):
|
||||
for t in tools: #Handle tool shortcuts
|
||||
|
@ -156,16 +156,16 @@ func edit_menu_id_pressed(id : int) -> void:
|
|||
while(i < Global.canvas.layers.size() - 1 && Global.canvas.layers[i][0].get_used_rect() == Rect2(0, 0, 0, 0)):
|
||||
i += 1
|
||||
used_rect = Global.canvas.layers[i][0].get_used_rect()
|
||||
|
||||
|
||||
#Merge all layers with content
|
||||
for j in range(Global.canvas.layers.size() - 1, i, -1):
|
||||
if Global.canvas.layers[j][0].get_used_rect() != Rect2(0, 0, 0, 0):
|
||||
used_rect = used_rect.merge(Global.canvas.layers[j][0].get_used_rect())
|
||||
|
||||
|
||||
#If no layer has any content, just return
|
||||
if used_rect == Rect2(0, 0, 0, 0):
|
||||
return
|
||||
|
||||
|
||||
#Loop through all the layers to crop them
|
||||
for j in range(Global.canvas.layers.size() - 1, -1, -1):
|
||||
var sprite := Image.new()
|
||||
|
@ -173,7 +173,7 @@ func edit_menu_id_pressed(id : int) -> void:
|
|||
Global.canvas.layers[j][0] = sprite
|
||||
Global.canvas.layers[j][0].lock()
|
||||
Global.canvas.update_texture(j)
|
||||
|
||||
|
||||
var width = Global.canvas.layers[0][0].get_width()
|
||||
var height = Global.canvas.layers[0][0].get_height()
|
||||
Global.canvas.size = Vector2(width, height).floor()
|
||||
|
@ -219,7 +219,7 @@ func _on_CreateNewImage_confirmed() -> void:
|
|||
clear_canvases()
|
||||
Global.canvas = load("res://Prefabs/Canvas.tscn").instance()
|
||||
Global.canvas.size = Vector2(width, height).floor()
|
||||
|
||||
|
||||
Global.canvas_parent.add_child(Global.canvas)
|
||||
Global.canvases.append(Global.canvas)
|
||||
Global.current_frame = 0
|
||||
|
@ -246,10 +246,10 @@ func _on_OpenSprite_file_selected(path) -> void:
|
|||
Global.canvas = canvas
|
||||
var width := file.get_16()
|
||||
var height := file.get_16()
|
||||
|
||||
|
||||
var layer := 0
|
||||
var layer_line := file.get_line()
|
||||
|
||||
|
||||
while layer_line == "-":
|
||||
var buffer := file.get_buffer(width * height * 4)
|
||||
var image := Image.new()
|
||||
|
@ -260,14 +260,14 @@ func _on_OpenSprite_file_selected(path) -> void:
|
|||
canvas.layers.append([image, tex, "Layer %s" % layer, true])
|
||||
layer_line = file.get_line()
|
||||
layer += 1
|
||||
|
||||
|
||||
canvas.size = Vector2(width, height)
|
||||
Global.canvases.append(canvas)
|
||||
canvas.frame = frame
|
||||
Global.canvas_parent.add_child(canvas)
|
||||
frame_line = file.get_line()
|
||||
frame += 1
|
||||
|
||||
|
||||
Global.current_frame = frame - 1
|
||||
#Load tool options
|
||||
Global.left_color_picker.color = file.get_var()
|
||||
|
@ -282,11 +282,11 @@ func _on_OpenSprite_file_selected(path) -> void:
|
|||
Global.left_color_picker.get_picker().add_preset(color)
|
||||
for color in right_palette:
|
||||
Global.right_color_picker.get_picker().add_preset(color)
|
||||
|
||||
|
||||
#Load custom brushes
|
||||
Global.custom_brushes.clear()
|
||||
Global.remove_brush_buttons()
|
||||
|
||||
|
||||
var brush_line := file.get_line()
|
||||
while brush_line == "/":
|
||||
var b_width := file.get_16()
|
||||
|
@ -297,7 +297,7 @@ func _on_OpenSprite_file_selected(path) -> void:
|
|||
Global.custom_brushes.append(image)
|
||||
Global.create_brush_button(image)
|
||||
brush_line = file.get_line()
|
||||
|
||||
|
||||
file.close()
|
||||
|
||||
func _on_SaveSprite_file_selected(path) -> void:
|
||||
|
@ -315,7 +315,7 @@ func _on_SaveSprite_file_selected(path) -> void:
|
|||
file.store_buffer(layer[0].get_data())
|
||||
file.store_line("END_LAYERS")
|
||||
file.store_line("END_FRAMES")
|
||||
|
||||
|
||||
#Save tool options
|
||||
var left_color := Global.left_color_picker.color
|
||||
var right_color := Global.right_color_picker.color
|
||||
|
@ -341,7 +341,7 @@ func _on_SaveSprite_file_selected(path) -> void:
|
|||
func _on_ImportSprites_files_selected(paths) -> void:
|
||||
if !import_as_new_frame.pressed: #If we're not adding a new frame, delete the previous
|
||||
clear_canvases()
|
||||
|
||||
|
||||
#Find the biggest image and let it handle the camera zoom options
|
||||
var max_size : Vector2
|
||||
var biggest_canvas : Canvas
|
||||
|
@ -369,10 +369,10 @@ func _on_ImportSprites_files_selected(paths) -> void:
|
|||
else:
|
||||
if canvas.size > max_size:
|
||||
biggest_canvas = canvas
|
||||
|
||||
|
||||
else:
|
||||
OS.alert("Can't load file")
|
||||
|
||||
|
||||
i += 1
|
||||
Global.current_frame = i - 1
|
||||
Global.canvas = Global.canvases[Global.canvases.size() - 1]
|
||||
|
@ -385,7 +385,7 @@ func _on_ImportSprites_files_selected(paths) -> void:
|
|||
else:
|
||||
Global.remove_frame_button.disabled = true
|
||||
Global.remove_frame_button.mouse_default_cursor_shape = Control.CURSOR_FORBIDDEN
|
||||
|
||||
|
||||
func clear_canvases() -> void:
|
||||
for child in Global.vbox_layer_container.get_children():
|
||||
if child is PanelContainer:
|
||||
|
@ -454,7 +454,7 @@ func save_spritesheet() -> void:
|
|||
dst += Vector2(0, canvas.size.y)
|
||||
else:
|
||||
dst += Vector2(canvas.size.x, 0)
|
||||
|
||||
|
||||
var err = whole_image.save_png(current_export_path)
|
||||
if err != OK:
|
||||
OS.alert("Can't save file")
|
||||
|
@ -468,7 +468,7 @@ func _on_ViewportContainer_mouse_entered() -> void:
|
|||
|
||||
func _on_ViewportContainer_mouse_exited() -> void:
|
||||
Global.has_focus = false
|
||||
|
||||
|
||||
func _can_draw_true() -> void:
|
||||
Global.can_draw = true
|
||||
func _can_draw_false() -> void:
|
||||
|
@ -495,7 +495,7 @@ func _on_ScaleImage_confirmed() -> void:
|
|||
Global.canvas.layers[i][0] = sprite
|
||||
Global.canvas.layers[i][0].lock()
|
||||
Global.canvas.update_texture(i)
|
||||
|
||||
|
||||
Global.canvas.size = Vector2(width, height).floor()
|
||||
Global.canvas.camera_zoom()
|
||||
|
||||
|
@ -526,15 +526,15 @@ func _on_MoveDownLayer_pressed() -> void:
|
|||
|
||||
func change_layer_order(rate : int) -> void:
|
||||
var change = Global.canvas.current_layer_index + rate
|
||||
|
||||
|
||||
var temp = Global.canvas.layers[Global.canvas.current_layer_index]
|
||||
Global.canvas.layers[Global.canvas.current_layer_index] = Global.canvas.layers[change]
|
||||
Global.canvas.layers[change] = temp
|
||||
|
||||
|
||||
Global.canvas.generate_layer_panels()
|
||||
Global.canvas.current_layer_index = change
|
||||
Global.canvas.get_layer_container(Global.canvas.current_layer_index).changed_selection()
|
||||
|
||||
|
||||
func _on_CloneLayer_pressed() -> void:
|
||||
add_layer(false)
|
||||
|
||||
|
@ -570,7 +570,7 @@ func _on_AddFrame_pressed() -> void:
|
|||
Global.canvases.append(canvas)
|
||||
Global.current_frame = Global.canvases.size() - 1
|
||||
Global.canvas = canvas
|
||||
|
||||
|
||||
Global.canvas_parent.add_child(canvas)
|
||||
Global.remove_frame_button.disabled = false
|
||||
Global.remove_frame_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
|
@ -614,7 +614,7 @@ func _on_CloneFrame_pressed() -> void:
|
|||
Global.canvases.append(canvas)
|
||||
Global.current_frame = Global.canvases.size() - 1
|
||||
Global.canvas = canvas
|
||||
|
||||
|
||||
Global.canvas_parent.add_child(canvas)
|
||||
Global.remove_frame_button.disabled = false
|
||||
Global.remove_frame_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
|
@ -630,21 +630,21 @@ func _on_MoveFrameRight_pressed() -> void:
|
|||
func change_frame_order(rate : int) -> void:
|
||||
var frame_button = Global.frame_container.get_node("Frame_%s" % Global.current_frame)
|
||||
var change = Global.current_frame + rate
|
||||
|
||||
|
||||
var temp = Global.canvases[Global.current_frame]
|
||||
Global.canvases[Global.current_frame] = Global.canvases[change]
|
||||
Global.canvases[change] = temp
|
||||
|
||||
|
||||
#Clear frame button names first, to avoid duplicates like two Frame_0s
|
||||
for canvas in Global.canvases:
|
||||
canvas.frame_button.name = "frame"
|
||||
|
||||
|
||||
for canvas in Global.canvases:
|
||||
canvas.frame = Global.canvases.find(canvas)
|
||||
canvas.frame_button.name = "Frame_%s" % canvas.frame
|
||||
canvas.frame_button.get_node("FrameButton").frame = canvas.frame
|
||||
canvas.frame_button.get_node("FrameID").text = str(canvas.frame + 1)
|
||||
|
||||
|
||||
Global.current_frame = change
|
||||
Global.frame_container.move_child(frame_button, Global.current_frame)
|
||||
Global.canvas_parent.move_child(Global.canvas, Global.current_frame)
|
||||
|
@ -669,7 +669,7 @@ func _on_LoopAnim_pressed() -> void:
|
|||
func _on_PlayForward_toggled(button_pressed) -> void:
|
||||
Global.play_backwards.pressed = false
|
||||
Global.play_backwards.text = "Play Backwards"
|
||||
|
||||
|
||||
if button_pressed:
|
||||
Global.play_forward.text = "Stop"
|
||||
$AnimationTimer.wait_time = 1 / fps
|
||||
|
@ -682,7 +682,7 @@ func _on_PlayForward_toggled(button_pressed) -> void:
|
|||
func _on_PlayBackwards_toggled(button_pressed) -> void:
|
||||
Global.play_forward.pressed = false
|
||||
Global.play_forward.text = "Play Forward"
|
||||
|
||||
|
||||
if button_pressed:
|
||||
Global.play_backwards.text = "Stop"
|
||||
$AnimationTimer.wait_time = 1 / fps
|
||||
|
@ -709,7 +709,7 @@ func _on_AnimationTimer_timeout() -> void:
|
|||
2: #Ping pong loop
|
||||
animation_forward = false
|
||||
_on_AnimationTimer_timeout()
|
||||
|
||||
|
||||
else:
|
||||
if Global.current_frame > 0:
|
||||
Global.current_frame -= 1
|
||||
|
@ -726,7 +726,7 @@ func _on_AnimationTimer_timeout() -> void:
|
|||
2: #Ping pong loop
|
||||
animation_forward = true
|
||||
_on_AnimationTimer_timeout()
|
||||
|
||||
|
||||
Global.change_frame()
|
||||
|
||||
func _on_FPSValue_value_changed(value) -> void:
|
||||
|
@ -781,4 +781,4 @@ func _on_LeftVerticalMirroring_toggled(button_pressed) -> void:
|
|||
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
|
||||
Global.right_vertical_mirror = button_pressed
|
||||
|
|
|
@ -25,7 +25,7 @@ func _process(delta) -> void:
|
|||
var start_pos := polygon[0]
|
||||
var end_pos := polygon[2]
|
||||
var layer : Image = Global.canvas.layers[Global.canvas.current_layer_index][0]
|
||||
|
||||
|
||||
if point_in_rectangle(mouse_pos, polygon[0], polygon[2]) && Global.selected_pixels.size() > 0 && (Global.current_left_tool == "RectSelect" || Global.current_right_tool == "RectSelect"):
|
||||
get_parent().get_parent().mouse_default_cursor_shape = Input.CURSOR_MOVE
|
||||
if (Global.current_left_tool == "RectSelect" && Input.is_action_just_pressed("left_mouse")) || (Global.current_right_tool == "RectSelect" && Input.is_action_just_pressed("right_mouse")):
|
||||
|
@ -57,14 +57,14 @@ func _process(delta) -> void:
|
|||
update()
|
||||
else:
|
||||
get_parent().get_parent().mouse_default_cursor_shape = Input.CURSOR_CROSS
|
||||
|
||||
|
||||
if is_dragging:
|
||||
if (Global.current_left_tool == "RectSelect" && Input.is_action_pressed("left_mouse")) || (Global.current_right_tool == "RectSelect" && Input.is_action_pressed("right_mouse")):
|
||||
#Drag
|
||||
#if orig_x + mouse_pos_floored.x >= Global.canvas.location.x && diff_x + mouse_pos_floored.x <= Global.canvas.size.x:
|
||||
start_pos.x = orig_x + mouse_pos_floored.x
|
||||
end_pos.x = diff_x + mouse_pos_floored.x
|
||||
|
||||
|
||||
#if orig_y + mouse_pos_floored.y >= Global.canvas.location.y && diff_y + mouse_pos_floored.y <= Global.canvas.size.y:
|
||||
start_pos.y = orig_y + mouse_pos_floored.y
|
||||
end_pos.y = diff_y + mouse_pos_floored.y
|
||||
|
@ -72,7 +72,7 @@ func _process(delta) -> void:
|
|||
polygon[1] = Vector2(end_pos.x, start_pos.y)
|
||||
polygon[2] = end_pos
|
||||
polygon[3] = Vector2(start_pos.x, end_pos.y)
|
||||
|
||||
|
||||
if (Global.current_left_tool == "RectSelect" && Input.is_action_just_released("left_mouse")) || (Global.current_right_tool == "RectSelect" && Input.is_action_just_released("right_mouse")):
|
||||
#Release Drag
|
||||
is_dragging = false
|
||||
|
@ -86,13 +86,13 @@ func _process(delta) -> void:
|
|||
img.fill(Color(0, 0, 0, 0))
|
||||
tex.create_from_image(img, 0)
|
||||
update()
|
||||
|
||||
|
||||
orig_colors.clear()
|
||||
Global.selected_pixels.clear()
|
||||
for xx in range(start_pos.x, end_pos.x):
|
||||
for yy in range(start_pos.y, end_pos.y):
|
||||
Global.selected_pixels.append(Vector2(xx, yy))
|
||||
|
||||
|
||||
#Handle copy
|
||||
if Input.is_action_just_pressed("copy") && Global.selected_pixels.size() > 0:
|
||||
Global.image_clipboard = layer.get_rect(Rect2(polygon[0], polygon[2] - polygon[0]))
|
||||
|
@ -101,9 +101,9 @@ func _process(delta) -> void:
|
|||
brush_img = layer.get_rect(Rect2(polygon[0], polygon[2] - polygon[0]))
|
||||
brush_img = brush_img.get_rect(brush_img.get_used_rect()) #save only the visible pixels
|
||||
Global.custom_brushes.append(brush_img)
|
||||
|
||||
|
||||
Global.create_brush_button(brush_img)
|
||||
|
||||
|
||||
#Handle paste
|
||||
#if Input.is_action_just_pressed("paste") && Global.selected_pixels.size() > 0 && !is_dragging:
|
||||
if Input.is_action_just_pressed("paste") && Global.selected_pixels.size() > 0 && Global.image_clipboard.get_size() > Vector2.ZERO:
|
||||
|
@ -117,4 +117,3 @@ func _draw() -> void:
|
|||
|
||||
func point_in_rectangle(p : Vector2, coord1 : Vector2, coord2 : Vector2) -> bool:
|
||||
return p.x > coord1.x && p.y > coord1.y && p.x < coord2.x && p.y < coord2.y
|
||||
|
Loading…
Reference in a new issue