Rename the Global autoload to DrawGD.

This commit is contained in:
Relintai 2020-11-29 14:59:31 +01:00
parent 932b8809bc
commit 1cc49621d3
65 changed files with 1228 additions and 1228 deletions

View File

@ -121,7 +121,7 @@ driver="Dummy"
[autoload]
Global="*res://src/Autoload/Global.gd"
DrawGD="*res://src/Autoload/Global.gd"
OpenSave="*res://src/Autoload/OpenSave.gd"
Tools="*res://src/Autoload/Tools.gd"

View File

@ -218,11 +218,11 @@ func colorDistance(c1 : Color, c2 : Color) -> float:
# Image effects
func scale_image(width : int, height : int, interpolation : int) -> void:
Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Scale")
Global.current_project.undo_redo.add_do_property(Global.current_project, "size", Vector2(width, height).floor())
DrawGD.current_project.undos += 1
DrawGD.current_project.undo_redo.create_action("Scale")
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "size", Vector2(width, height).floor())
for f in Global.current_project.frames:
for f in DrawGD.current_project.frames:
for i in range(f.cels.size() - 1, -1, -1):
var sprite := Image.new()
sprite.copy_from(f.cels[i].image)
@ -234,20 +234,20 @@ func scale_image(width : int, height : int, interpolation : int) -> void:
sprite.resize(width, height, 0)
else:
sprite.resize(width, height, interpolation)
Global.current_project.undo_redo.add_do_property(f.cels[i].image, "data", sprite.data)
Global.current_project.undo_redo.add_undo_property(f.cels[i].image, "data", f.cels[i].image.data)
DrawGD.current_project.undo_redo.add_do_property(f.cels[i].image, "data", sprite.data)
DrawGD.current_project.undo_redo.add_undo_property(f.cels[i].image, "data", f.cels[i].image.data)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "size", Global.current_project.size)
Global.current_project.undo_redo.add_undo_method(Global, "undo")
Global.current_project.undo_redo.add_do_method(Global, "redo")
Global.current_project.undo_redo.commit_action()
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "size", DrawGD.current_project.size)
DrawGD.current_project.undo_redo.add_undo_method(DrawGD, "undo")
DrawGD.current_project.undo_redo.add_do_method(DrawGD, "redo")
DrawGD.current_project.undo_redo.commit_action()
func crop_image(image : Image) -> void:
# Use first cel as a starting rectangle
var used_rect : Rect2 = image.get_used_rect()
for f in Global.current_project.frames:
for f in DrawGD.current_project.frames:
# However, if first cel is empty, loop through all cels until we find one that isn't
for cel in f.cels:
if used_rect != Rect2(0, 0, 0, 0):
@ -267,38 +267,38 @@ func crop_image(image : Image) -> void:
var width := used_rect.size.x
var height := used_rect.size.y
Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Scale")
Global.current_project.undo_redo.add_do_property(Global.current_project, "size", Vector2(width, height).floor())
for f in Global.current_project.frames:
DrawGD.current_project.undos += 1
DrawGD.current_project.undo_redo.create_action("Scale")
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "size", Vector2(width, height).floor())
for f in DrawGD.current_project.frames:
# Loop through all the layers to crop them
for j in range(Global.current_project.layers.size() - 1, -1, -1):
for j in range(DrawGD.current_project.layers.size() - 1, -1, -1):
var sprite : Image = f.cels[j].image.get_rect(used_rect)
Global.current_project.undo_redo.add_do_property(f.cels[j].image, "data", sprite.data)
Global.current_project.undo_redo.add_undo_property(f.cels[j].image, "data", f.cels[j].image.data)
DrawGD.current_project.undo_redo.add_do_property(f.cels[j].image, "data", sprite.data)
DrawGD.current_project.undo_redo.add_undo_property(f.cels[j].image, "data", f.cels[j].image.data)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "size", Global.current_project.size)
Global.current_project.undo_redo.add_undo_method(Global, "undo")
Global.current_project.undo_redo.add_do_method(Global, "redo")
Global.current_project.undo_redo.commit_action()
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "size", DrawGD.current_project.size)
DrawGD.current_project.undo_redo.add_undo_method(DrawGD, "undo")
DrawGD.current_project.undo_redo.add_do_method(DrawGD, "redo")
DrawGD.current_project.undo_redo.commit_action()
func resize_canvas(width : int, height : int, offset_x : int, offset_y : int) -> void:
Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Scale")
Global.current_project.undo_redo.add_do_property(Global.current_project, "size", Vector2(width, height).floor())
for f in Global.current_project.frames:
DrawGD.current_project.undos += 1
DrawGD.current_project.undo_redo.create_action("Scale")
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "size", Vector2(width, height).floor())
for f in DrawGD.current_project.frames:
for c in f.cels:
var sprite := Image.new()
sprite.create(width, height, false, Image.FORMAT_RGBA8)
sprite.blend_rect(c.image, Rect2(Vector2.ZERO, Global.current_project.size), Vector2(offset_x, offset_y))
Global.current_project.undo_redo.add_do_property(c.image, "data", sprite.data)
Global.current_project.undo_redo.add_undo_property(c.image, "data", c.image.data)
sprite.blend_rect(c.image, Rect2(Vector2.ZERO, DrawGD.current_project.size), Vector2(offset_x, offset_y))
DrawGD.current_project.undo_redo.add_do_property(c.image, "data", sprite.data)
DrawGD.current_project.undo_redo.add_undo_property(c.image, "data", c.image.data)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "size", Global.current_project.size)
Global.current_project.undo_redo.add_undo_method(Global, "undo")
Global.current_project.undo_redo.add_do_method(Global, "redo")
Global.current_project.undo_redo.commit_action()
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "size", DrawGD.current_project.size)
DrawGD.current_project.undo_redo.add_undo_method(DrawGD, "undo")
DrawGD.current_project.undo_redo.add_do_method(DrawGD, "redo")
DrawGD.current_project.undo_redo.commit_action()
func invert_image_colors(image : Image, pixels : Array, red := true, green := true, blue := true, alpha := false) -> void:
@ -352,13 +352,13 @@ func generate_outline(image : Image, pixels : Array, outline_color : Color, thic
var outline_pos : Vector2 = pos + Vector2.LEFT # Left
if outline_pos.x < 0 || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + Vector2.RIGHT * (i - 1)
if new_pos.x < Global.current_project.size.x:
if new_pos.x < DrawGD.current_project.size.x:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a > 0:
new_image.set_pixelv(new_pos, outline_color)
outline_pos = pos + Vector2.RIGHT # Right
if outline_pos.x >= Global.current_project.size.x || image.get_pixelv(outline_pos).a == 0:
if outline_pos.x >= DrawGD.current_project.size.x || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + Vector2.LEFT * (i - 1)
if new_pos.x >= 0:
var new_pixel = image.get_pixelv(new_pos)
@ -368,13 +368,13 @@ func generate_outline(image : Image, pixels : Array, outline_color : Color, thic
outline_pos = pos + Vector2.UP # Up
if outline_pos.y < 0 || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + Vector2.DOWN * (i - 1)
if new_pos.y < Global.current_project.size.y:
if new_pos.y < DrawGD.current_project.size.y:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a > 0:
new_image.set_pixelv(new_pos, outline_color)
outline_pos = pos + Vector2.DOWN # Down
if outline_pos.y >= Global.current_project.size.y || image.get_pixelv(outline_pos).a == 0:
if outline_pos.y >= DrawGD.current_project.size.y || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + Vector2.UP * (i - 1)
if new_pos.y >= 0:
var new_pixel = image.get_pixelv(new_pos)
@ -385,29 +385,29 @@ func generate_outline(image : Image, pixels : Array, outline_color : Color, thic
outline_pos = pos + (Vector2.LEFT + Vector2.UP) # Top left
if (outline_pos.x < 0 && outline_pos.y < 0) || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + (Vector2.RIGHT + Vector2.DOWN) * (i - 1)
if new_pos.x < Global.current_project.size.x && new_pos.y < Global.current_project.size.y:
if new_pos.x < DrawGD.current_project.size.x && new_pos.y < DrawGD.current_project.size.y:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a > 0:
new_image.set_pixelv(new_pos, outline_color)
outline_pos = pos + (Vector2.LEFT + Vector2.DOWN) # Bottom left
if (outline_pos.x < 0 && outline_pos.y >= Global.current_project.size.y) || image.get_pixelv(outline_pos).a == 0:
if (outline_pos.x < 0 && outline_pos.y >= DrawGD.current_project.size.y) || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + (Vector2.RIGHT + Vector2.UP) * (i - 1)
if new_pos.x < Global.current_project.size.x && new_pos.y >= 0:
if new_pos.x < DrawGD.current_project.size.x && new_pos.y >= 0:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a > 0:
new_image.set_pixelv(new_pos, outline_color)
outline_pos = pos + (Vector2.RIGHT + Vector2.UP) # Top right
if (outline_pos.x >= Global.current_project.size.x && outline_pos.y < 0) || image.get_pixelv(outline_pos).a == 0:
if (outline_pos.x >= DrawGD.current_project.size.x && outline_pos.y < 0) || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + (Vector2.LEFT + Vector2.DOWN) * (i - 1)
if new_pos.x >= 0 && new_pos.y < Global.current_project.size.y:
if new_pos.x >= 0 && new_pos.y < DrawGD.current_project.size.y:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a > 0:
new_image.set_pixelv(new_pos, outline_color)
outline_pos = pos + (Vector2.RIGHT + Vector2.DOWN) # Bottom right
if (outline_pos.x >= Global.current_project.size.x && outline_pos.y >= Global.current_project.size.y) || image.get_pixelv(outline_pos).a == 0:
if (outline_pos.x >= DrawGD.current_project.size.x && outline_pos.y >= DrawGD.current_project.size.y) || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + (Vector2.LEFT + Vector2.UP) * (i - 1)
if new_pos.x >= 0 && new_pos.y >= 0:
var new_pixel = image.get_pixelv(new_pos)
@ -422,7 +422,7 @@ func generate_outline(image : Image, pixels : Array, outline_color : Color, thic
new_image.set_pixelv(new_pos, outline_color)
new_pos = pos + Vector2.RIGHT * i # Right
if new_pos.x < Global.current_project.size.x:
if new_pos.x < DrawGD.current_project.size.x:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color)
@ -434,7 +434,7 @@ func generate_outline(image : Image, pixels : Array, outline_color : Color, thic
new_image.set_pixelv(new_pos, outline_color)
new_pos = pos + Vector2.DOWN * i # Down
if new_pos.y < Global.current_project.size.y:
if new_pos.y < DrawGD.current_project.size.y:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color)
@ -447,19 +447,19 @@ func generate_outline(image : Image, pixels : Array, outline_color : Color, thic
new_image.set_pixelv(new_pos, outline_color)
new_pos = pos + (Vector2.LEFT + Vector2.DOWN) * i # Bottom left
if new_pos.x >= 0 && new_pos.y < Global.current_project.size.y:
if new_pos.x >= 0 && new_pos.y < DrawGD.current_project.size.y:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color)
new_pos = pos + (Vector2.RIGHT + Vector2.UP) * i # Top right
if new_pos.x < Global.current_project.size.x && new_pos.y >= 0:
if new_pos.x < DrawGD.current_project.size.x && new_pos.y >= 0:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color)
new_pos = pos + (Vector2.RIGHT + Vector2.DOWN) * i # Bottom right
if new_pos.x < Global.current_project.size.x && new_pos.y < Global.current_project.size.y:
if new_pos.x < DrawGD.current_project.size.x && new_pos.y < DrawGD.current_project.size.y:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color)
@ -504,7 +504,7 @@ func adjust_hsv(img: Image, delta_h : float, delta_s : float, delta_v : float, p
img.unlock()
func generate_gradient(image : Image, colors : Array, steps := 2, direction : int = GradientDirection.TOP, pixels = Global.current_project.selected_pixels) -> void:
func generate_gradient(image : Image, colors : Array, steps := 2, direction : int = GradientDirection.TOP, pixels = DrawGD.current_project.selected_pixels) -> void:
if colors.size() < 2:
return

View File

@ -55,14 +55,14 @@ func external_export() -> void:
process_spritesheet()
ExportTab.ANIMATION:
process_animation()
export_processed_images(true, Global.export_dialog)
export_processed_images(true, DrawGD.export_dialog)
func process_frame() -> void:
processed_images.clear()
var frame = Global.current_project.frames[frame_number - 1]
var frame = DrawGD.current_project.frames[frame_number - 1]
var image := Image.new()
image.create(Global.current_project.size.x, Global.current_project.size.y, false, Image.FORMAT_RGBA8)
image.create(DrawGD.current_project.size.x, DrawGD.current_project.size.y, false, Image.FORMAT_RGBA8)
blend_layers(image, frame)
processed_images.append(image)
@ -72,11 +72,11 @@ func process_spritesheet() -> void:
# Range of frames determined by tags
var frames := []
if frame_current_tag > 0:
var frame_start = Global.current_project.animation_tags[frame_current_tag - 1].from
var frame_end = Global.current_project.animation_tags[frame_current_tag - 1].to
frames = Global.current_project.frames.slice(frame_start-1, frame_end-1, 1, true)
var frame_start = DrawGD.current_project.animation_tags[frame_current_tag - 1].from
var frame_end = DrawGD.current_project.animation_tags[frame_current_tag - 1].to
frames = DrawGD.current_project.frames.slice(frame_start-1, frame_end-1, 1, true)
else:
frames = Global.current_project.frames
frames = DrawGD.current_project.frames
# Then store the size of frames for other functions
number_of_frames = frames.size()
@ -85,8 +85,8 @@ func process_spritesheet() -> void:
var spritesheet_columns = lines_count if orientation == Orientation.ROWS else frames_divided_by_spritesheet_lines()
var spritesheet_rows = lines_count if orientation == Orientation.COLUMNS else frames_divided_by_spritesheet_lines()
var width = Global.current_project.size.x * spritesheet_columns
var height = Global.current_project.size.y * spritesheet_rows
var width = DrawGD.current_project.size.x * spritesheet_columns
var height = DrawGD.current_project.size.y * spritesheet_rows
var whole_image := Image.new()
whole_image.create(width, height, false, Image.FORMAT_RGBA8)
@ -97,22 +97,22 @@ func process_spritesheet() -> void:
for frame in frames:
if orientation == Orientation.ROWS:
if vv < spritesheet_columns:
origin.x = Global.current_project.size.x * vv
origin.x = DrawGD.current_project.size.x * vv
vv += 1
else:
hh += 1
origin.x = 0
vv = 1
origin.y = Global.current_project.size.y * hh
origin.y = DrawGD.current_project.size.y * hh
else:
if hh < spritesheet_rows:
origin.y = Global.current_project.size.y * hh
origin.y = DrawGD.current_project.size.y * hh
hh += 1
else:
vv += 1
origin.y = 0
hh = 1
origin.x = Global.current_project.size.x * vv
origin.x = DrawGD.current_project.size.x * vv
blend_layers(whole_image, frame, origin)
processed_images.append(whole_image)
@ -120,9 +120,9 @@ func process_spritesheet() -> void:
func process_animation() -> void:
processed_images.clear()
for frame in Global.current_project.frames:
for frame in DrawGD.current_project.frames:
var image := Image.new()
image.create(Global.current_project.size.x, Global.current_project.size.y, false, Image.FORMAT_RGBA8)
image.create(DrawGD.current_project.size.x, DrawGD.current_project.size.y, false, Image.FORMAT_RGBA8)
blend_layers(image, frame)
processed_images.append(image)
@ -176,11 +176,11 @@ func export_processed_images(ignore_overwrites: bool, export_dialog: AcceptDialo
# Store settings for quick export and when the dialog is opened again
was_exported = true
Global.file_menu.get_popup().set_item_text(5, tr("Export") + " %s" % (file_name + file_format_string(file_format)))
DrawGD.file_menu.get_popup().set_item_text(5, tr("Export") + " %s" % (file_name + file_format_string(file_format)))
# Only show when not exporting gif - gif export finishes in thread
if not (current_tab == ExportTab.ANIMATION and animation_type == AnimationType.ANIMATED):
Global.notification_label("File(s) exported")
DrawGD.notification_label("File(s) exported")
return true
func increase_export_progress(export_dialog: Node) -> void:
@ -233,7 +233,7 @@ func create_export_path(multifile: bool, frame: int = 0) -> String:
func get_proccessed_image_animation_tag_and_start_id(processed_image_id : int) -> Array:
var result_animation_tag_and_start_id = null
for animation_tag in Global.current_project.animation_tags:
for animation_tag in DrawGD.current_project.animation_tags:
# Check if processed image is in frame tag and assign frame tag and start id if yes
# Then stop
if (processed_image_id + 1) >= animation_tag.from and (processed_image_id + 1) <= animation_tag.to:
@ -247,7 +247,7 @@ func blend_layers(image : Image, frame : Frame, origin : Vector2 = Vector2(0, 0)
image.lock()
var layer_i := 0
for cel in frame.cels:
if Global.current_project.layers[layer_i].visible:
if DrawGD.current_project.layers[layer_i].visible:
var cel_image := Image.new()
cel_image.copy_from(cel.image)
cel_image.lock()
@ -257,7 +257,7 @@ func blend_layers(image : Image, frame : Frame, origin : Vector2 = Vector2(0, 0)
var pixel_color := cel_image.get_pixel(xx, yy)
var alpha : float = pixel_color.a * cel.opacity
cel_image.set_pixel(xx, yy, Color(pixel_color.r, pixel_color.g, pixel_color.b, alpha))
image.blend_rect(cel_image, Rect2(Global.canvas.location, Global.current_project.size), origin)
image.blend_rect(cel_image, Rect2(DrawGD.canvas.location, DrawGD.current_project.size), origin)
cel_image.unlock()
layer_i += 1
image.unlock()

View File

@ -178,7 +178,7 @@ func _ready() -> void:
# XDGDataDirs depends on it nyaa
directory_module = XDGDataPaths.new()
image_clipboard = Image.new()
Input.set_custom_mouse_cursor(Global.cursor_image, Input.CURSOR_CROSS, Vector2(15, 15))
Input.set_custom_mouse_cursor(DrawGD.cursor_image, Input.CURSOR_CROSS, Vector2(15, 15))
var root = get_tree().get_root()
control = find_node_by_name(root, "Control")
@ -314,9 +314,9 @@ func undo(_frame_index := -1, _layer_index := -1, project : Project = current_pr
if action_name == "Scale":
canvas.camera_zoom()
Global.canvas.grid.isometric_polylines.clear()
Global.canvas.grid.update()
Global.cursor_position_label.text = "[%s×%s]" % [project.size.x, project.size.y]
DrawGD.canvas.grid.isometric_polylines.clear()
DrawGD.canvas.grid.update()
DrawGD.cursor_position_label.text = "[%s×%s]" % [project.size.x, project.size.y]
elif "Frame" in action_name:
# This actually means that frames.size is one, but it hasn't been updated yet
@ -345,9 +345,9 @@ func redo(_frame_index := -1, _layer_index := -1, project : Project = current_pr
if action_name == "Scale":
canvas.camera_zoom()
Global.canvas.grid.isometric_polylines.clear()
Global.canvas.grid.update()
Global.cursor_position_label.text = "[%s×%s]" % [project.size.x, project.size.y]
DrawGD.canvas.grid.isometric_polylines.clear()
DrawGD.canvas.grid.update()
DrawGD.cursor_position_label.text = "[%s×%s]" % [project.size.x, project.size.y]
elif "Frame" in action_name:
if project.frames.size() == 1: # Stop animating

View File

@ -222,7 +222,7 @@ func import_patterns(priority_ordered_search_path: Array) -> void:
if err == OK:
image.convert(Image.FORMAT_RGBA8)
var tooltip_name = pattern.get_basename()
Global.patterns_popup.add(image, tooltip_name)
DrawGD.patterns_popup.add(image, tooltip_name)
func import_gpl(path : String, text : String) -> Palette:

View File

@ -25,15 +25,15 @@ func handle_loading_files(files : PoolStringArray) -> void:
if file_ext == "pxo": # Pixelorama project file
open_pxo_file(file)
elif file_ext == "json" or file_ext == "gpl" or file_ext == "pal": # Palettes
Global.palette_container.on_palette_import_file_selected(file)
DrawGD.palette_container.on_palette_import_file_selected(file)
else: # Image files
var image := Image.new()
var err := image.load(file)
if err != OK: # An error occured
var file_name : String = file.get_file()
Global.error_dialog.set_text(tr("Can't load file '%s'.\nError code: %s") % [file_name, str(err)])
Global.error_dialog.popup_centered()
Global.dialog_open(true)
DrawGD.error_dialog.set_text(tr("Can't load file '%s'.\nError code: %s") % [file_name, str(err)])
DrawGD.error_dialog.popup_centered()
DrawGD.dialog_open(true)
continue
handle_loading_image(file, image)
@ -42,9 +42,9 @@ func handle_loading_image(file : String, image : Image) -> void:
var preview_dialog : ConfirmationDialog = preload("res://src/UI/Dialogs/PreviewDialog.tscn").instance()
preview_dialog.path = file
preview_dialog.image = image
Global.control.add_child(preview_dialog)
DrawGD.control.add_child(preview_dialog)
preview_dialog.popup_centered()
Global.dialog_open(true)
DrawGD.dialog_open(true)
func open_pxo_file(path : String, untitled_backup : bool = false) -> void:
@ -54,14 +54,14 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void:
err = file.open(path, File.READ) # If the file is not compressed open it raw (pre-v0.7)
if err != OK:
Global.notification_label(tr("File failed to open. Error code %s") % err)
DrawGD.notification_label(tr("File failed to open. Error code %s") % err)
file.close()
return
var empty_project : bool = Global.current_project.frames.size() == 1 and Global.current_project.layers.size() == 1 and Global.current_project.frames[0].cels[0].image.is_invisible() and Global.current_project.animation_tags.size() == 0
var empty_project : bool = DrawGD.current_project.frames.size() == 1 and DrawGD.current_project.layers.size() == 1 and DrawGD.current_project.frames[0].cels[0].image.is_invisible() and DrawGD.current_project.animation_tags.size() == 0
var new_project : Project
if empty_project:
new_project = Global.current_project
new_project = DrawGD.current_project
new_project.frames = []
new_project.layers = []
new_project.animation_tags.clear()
@ -98,26 +98,26 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void:
file.close()
if !empty_project:
Global.projects.append(new_project)
Global.tabs.current_tab = Global.tabs.get_tab_count() - 1
DrawGD.projects.append(new_project)
DrawGD.tabs.current_tab = DrawGD.tabs.get_tab_count() - 1
else:
new_project.frames = new_project.frames # Just to call frames_changed
new_project.layers = new_project.layers # Just to call layers_changed
Global.canvas.camera_zoom()
DrawGD.canvas.camera_zoom()
if not untitled_backup:
# Untitled backup should not change window title and save path
current_save_paths[Global.current_project_index] = path
Global.window_title = path.get_file() + " - Pixelorama " + Global.current_version
Global.save_sprites_dialog.current_path = path
current_save_paths[DrawGD.current_project_index] = path
DrawGD.window_title = path.get_file() + " - Pixelorama " + DrawGD.current_version
DrawGD.save_sprites_dialog.current_path = path
# Set last opened project path and save
Global.config_cache.set_value("preferences", "last_project_path", path)
Global.config_cache.save("user://cache.ini")
DrawGD.config_cache.set_value("preferences", "last_project_path", path)
DrawGD.config_cache.save("user://cache.ini")
Export.file_name = path.get_file().trim_suffix(".pxo")
Export.directory_path = path.get_base_dir()
Export.was_exported = false
Global.file_menu.get_popup().set_item_text(3, tr("Save") + " %s" % path.get_file())
Global.file_menu.get_popup().set_item_text(5, tr("Export"))
DrawGD.file_menu.get_popup().set_item_text(3, tr("Save") + " %s" % path.get_file())
DrawGD.file_menu.get_popup().set_item_text(5, tr("Export"))
# For pxo files older than v0.8
@ -141,7 +141,7 @@ func open_old_pxo_file(file : File, new_project : Project, first_line : String)
_file_status_version = file_ver_splitted[1]
if file_major_version == 0 and file_minor_version < 5:
Global.notification_label("File is from an older version of Pixelorama, as such it might not work properly")
DrawGD.notification_label("File is from an older version of Pixelorama, as such it might not work properly")
var new_guides := true
if file_major_version == 0:
@ -207,7 +207,7 @@ func open_old_pxo_file(file : File, new_project : Project, first_line : String)
guide.add_point(Vector2(file.get_16(), -99999))
guide.add_point(Vector2(file.get_16(), 99999))
guide.has_focus = false
Global.canvas.add_child(guide)
DrawGD.canvas.add_child(guide)
new_project.guides.append(guide)
guide_line = file.get_line()
@ -228,7 +228,7 @@ func open_old_pxo_file(file : File, new_project : Project, first_line : String)
guide.add_point(Vector2(file.get_16(), -99999))
guide.add_point(Vector2(file.get_16(), 99999))
guide.has_focus = false
Global.canvas.add_child(guide)
DrawGD.canvas.add_child(guide)
new_project.guides.append(guide)
guide_line = file.get_line()
@ -265,7 +265,7 @@ func open_old_pxo_file(file : File, new_project : Project, first_line : String)
tag_line = file.get_line()
func save_pxo_file(path : String, autosave : bool, use_zstd_compression := true, project : Project = Global.current_project) -> void:
func save_pxo_file(path : String, autosave : bool, use_zstd_compression := true, project : Project = DrawGD.current_project) -> void:
var file : File = File.new()
var err
if use_zstd_compression:
@ -276,7 +276,7 @@ func save_pxo_file(path : String, autosave : bool, use_zstd_compression := true,
if err == OK:
if !autosave:
project.name = path.get_file()
current_save_paths[Global.current_project_index] = path
current_save_paths[DrawGD.current_project_index] = path
var to_save = JSON.print(project.serialize())
file.store_line(to_save)
@ -300,32 +300,32 @@ func save_pxo_file(path : String, autosave : bool, use_zstd_compression := true,
dir.remove(path)
if autosave:
Global.notification_label("File autosaved")
DrawGD.notification_label("File autosaved")
else:
# First remove backup then set current save path
if project.has_changed:
project.has_changed = false
remove_backup(Global.current_project_index)
Global.notification_label("File saved")
Global.window_title = path.get_file() + " - Pixelorama " + Global.current_version
remove_backup(DrawGD.current_project_index)
DrawGD.notification_label("File saved")
DrawGD.window_title = path.get_file() + " - Pixelorama " + DrawGD.current_version
# Set last opened project path and save
Global.config_cache.set_value("preferences", "last_project_path", path)
Global.config_cache.save("user://cache.ini")
DrawGD.config_cache.set_value("preferences", "last_project_path", path)
DrawGD.config_cache.save("user://cache.ini")
Export.file_name = path.get_file().trim_suffix(".pxo")
Export.directory_path = path.get_base_dir()
Export.was_exported = false
Global.file_menu.get_popup().set_item_text(3, tr("Save") + " %s" % path.get_file())
DrawGD.file_menu.get_popup().set_item_text(3, tr("Save") + " %s" % path.get_file())
else:
Global.notification_label(tr("File failed to save. Error code %s") % err)
DrawGD.notification_label(tr("File failed to save. Error code %s") % err)
file.close()
func open_image_as_new_tab(path : String, image : Image) -> void:
var project = Project.new([], path.get_file(), image.get_size())
project.layers.append(Layer.new())
Global.projects.append(project)
DrawGD.projects.append(project)
var frame := Frame.new()
image.convert(Image.FORMAT_RGBA8)
@ -339,7 +339,7 @@ func open_image_as_new_tab(path : String, image : Image) -> void:
func open_image_as_spritesheet(path : String, image : Image, horizontal : int, vertical : int) -> void:
var project = Project.new([], path.get_file())
project.layers.append(Layer.new())
Global.projects.append(project)
DrawGD.projects.append(project)
horizontal = min(horizontal, image.get_size().x)
vertical = min(vertical, image.get_size().y)
var frame_width := image.get_size().x / horizontal
@ -367,7 +367,7 @@ func open_image_as_spritesheet(path : String, image : Image, horizontal : int, v
func open_image_as_new_frame(image : Image, layer_index := 0) -> void:
var project = Global.current_project
var project = DrawGD.current_project
image.crop(project.size.x, project.size.y)
var new_frames : Array = project.frames.duplicate()
@ -387,8 +387,8 @@ func open_image_as_new_frame(image : Image, layer_index := 0) -> void:
project.undos += 1
project.undo_redo.create_action("Add Frame")
project.undo_redo.add_do_method(Global, "redo")
project.undo_redo.add_undo_method(Global, "undo")
project.undo_redo.add_do_method(DrawGD, "redo")
project.undo_redo.add_undo_method(DrawGD, "undo")
project.undo_redo.add_do_property(project, "frames", new_frames)
project.undo_redo.add_do_property(project, "current_frame", new_frames.size() - 1)
@ -401,13 +401,13 @@ func open_image_as_new_frame(image : Image, layer_index := 0) -> void:
func open_image_as_new_layer(image : Image, file_name : String, frame_index := 0) -> void:
var project = Global.current_project
var project = DrawGD.current_project
image.crop(project.size.x, project.size.y)
var new_layers : Array = Global.current_project.layers.duplicate()
var new_layers : Array = DrawGD.current_project.layers.duplicate()
var layer := Layer.new(file_name)
Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Add Layer")
DrawGD.current_project.undos += 1
DrawGD.current_project.undo_redo.create_action("Add Layer")
for i in project.frames.size():
var new_cels : Array = project.frames[i].cels.duplicate(true)
if i == frame_index:
@ -433,18 +433,18 @@ func open_image_as_new_layer(image : Image, file_name : String, frame_index := 0
project.undo_redo.add_undo_property(project, "layers", project.layers)
project.undo_redo.add_undo_property(project, "current_frame", project.current_frame)
project.undo_redo.add_undo_method(Global, "undo")
project.undo_redo.add_do_method(Global, "redo")
project.undo_redo.add_undo_method(DrawGD, "undo")
project.undo_redo.add_do_method(DrawGD, "redo")
project.undo_redo.commit_action()
func set_new_tab(project : Project, path : String) -> void:
Global.tabs.current_tab = Global.tabs.get_tab_count() - 1
Global.canvas.camera_zoom()
DrawGD.tabs.current_tab = DrawGD.tabs.get_tab_count() - 1
DrawGD.canvas.camera_zoom()
Global.window_title = path.get_file() + " (" + tr("imported") + ") - Pixelorama " + Global.current_version
DrawGD.window_title = path.get_file() + " (" + tr("imported") + ") - Pixelorama " + DrawGD.current_version
if project.has_changed:
Global.window_title = Global.window_title + "(*)"
DrawGD.window_title = DrawGD.window_title + "(*)"
var file_name := path.get_basename().get_file()
var directory_path := path.get_basename().replace(file_name, "")
Export.directory_path = directory_path
@ -453,8 +453,8 @@ func set_new_tab(project : Project, path : String) -> void:
func update_autosave() -> void:
autosave_timer.stop()
autosave_timer.wait_time = Global.autosave_interval * 60 # Interval parameter is in minutes, wait_time is seconds
if Global.enable_autosave:
autosave_timer.wait_time = DrawGD.autosave_interval * 60 # Interval parameter is in minutes, wait_time is seconds
if DrawGD.enable_autosave:
autosave_timer.start()
@ -465,7 +465,7 @@ func _on_Autosave_timeout() -> void:
backup_save_paths[i] = "user://backup-" + String(OS.get_unix_time()) + "-%s" % i
store_backup_path(i)
save_pxo_file(backup_save_paths[i], true, true, Global.projects[i])
save_pxo_file(backup_save_paths[i], true, true, DrawGD.projects[i])
# Backup paths are stored in two ways:
@ -474,14 +474,14 @@ func _on_Autosave_timeout() -> void:
func store_backup_path(i : int) -> void:
if current_save_paths[i] != "":
# Remove "untitled" backup if it existed on this project instance
if Global.config_cache.has_section_key("backups", backup_save_paths[i]):
Global.config_cache.erase_section_key("backups", backup_save_paths[i])
if DrawGD.config_cache.has_section_key("backups", backup_save_paths[i]):
DrawGD.config_cache.erase_section_key("backups", backup_save_paths[i])
Global.config_cache.set_value("backups", current_save_paths[i], backup_save_paths[i])
DrawGD.config_cache.set_value("backups", current_save_paths[i], backup_save_paths[i])
else:
Global.config_cache.set_value("backups", backup_save_paths[i], backup_save_paths[i])
DrawGD.config_cache.set_value("backups", backup_save_paths[i], backup_save_paths[i])
Global.config_cache.save("user://cache.ini")
DrawGD.config_cache.save("user://cache.ini")
func remove_backup(i : int) -> void:
@ -497,11 +497,11 @@ func remove_backup(i : int) -> void:
func remove_backup_by_path(project_path : String, backup_path : String) -> void:
Directory.new().remove(backup_path)
if Global.config_cache.has_section_key("backups", project_path):
Global.config_cache.erase_section_key("backups", project_path)
elif Global.config_cache.has_section_key("backups", backup_path):
Global.config_cache.erase_section_key("backups", backup_path)
Global.config_cache.save("user://cache.ini")
if DrawGD.config_cache.has_section_key("backups", project_path):
DrawGD.config_cache.erase_section_key("backups", project_path)
elif DrawGD.config_cache.has_section_key("backups", backup_path):
DrawGD.config_cache.erase_section_key("backups", backup_path)
DrawGD.config_cache.save("user://cache.ini")
func reload_backup_file(project_paths : Array, backup_paths : Array) -> void:
@ -510,9 +510,9 @@ func reload_backup_file(project_paths : Array, backup_paths : Array) -> void:
var dir := Directory.new()
for backup in backup_paths:
if !dir.file_exists(backup):
if Global.config_cache.has_section_key("backups", backup):
Global.config_cache.erase_section_key("backups", backup)
Global.config_cache.save("user://cache.ini")
if DrawGD.config_cache.has_section_key("backups", backup):
DrawGD.config_cache.erase_section_key("backups", backup)
DrawGD.config_cache.save("user://cache.ini")
project_paths.remove(backup_paths.find(backup))
deleted_backup_paths.append(backup)
@ -527,7 +527,7 @@ func reload_backup_file(project_paths : Array, backup_paths : Array) -> void:
# If project path is the same as backup save path -> the backup was untitled
if project_paths[i] != backup_paths[i]: # If the user has saved
current_save_paths[i] = project_paths[i]
Global.window_title = project_paths[i].get_file() + " - Pixelorama(*) " + Global.current_version
Global.current_project.has_changed = true
DrawGD.window_title = project_paths[i].get_file() + " - Pixelorama(*) " + DrawGD.current_version
DrawGD.current_project.has_changed = true
Global.notification_label("Backup reloaded")
DrawGD.notification_label("Backup reloaded")

View File

@ -26,11 +26,11 @@ class Slot:
"horizontal_mirror" : horizontal_mirror,
"vertical_mirror" : vertical_mirror,
}
Global.config_cache.set_value(kname, "slot", config)
DrawGD.config_cache.set_value(kname, "slot", config)
func load_config() -> void:
var config = Global.config_cache.get_value(kname, "slot", {})
var config = DrawGD.config_cache.get_value(kname, "slot", {})
pixel_perfect = config.get("pixel_perfect", pixel_perfect)
horizontal_mirror = config.get("horizontal_mirror", horizontal_mirror)
vertical_mirror = config.get("vertical_mirror", vertical_mirror)
@ -63,17 +63,17 @@ func _ready():
yield(get_tree(), "idle_frame")
_slots[BUTTON_LEFT] = Slot.new("Left tool")
_slots[BUTTON_RIGHT] = Slot.new("Right tool")
_panels[BUTTON_LEFT] = Global.find_node_by_name(Global.control, "LeftPanelContainer")
_panels[BUTTON_RIGHT] = Global.find_node_by_name(Global.control, "RightPanelContainer")
_tool_buttons = Global.find_node_by_name(Global.control, "ToolButtons")
_panels[BUTTON_LEFT] = DrawGD.find_node_by_name(DrawGD.control, "LeftPanelContainer")
_panels[BUTTON_RIGHT] = DrawGD.find_node_by_name(DrawGD.control, "RightPanelContainer")
_tool_buttons = DrawGD.find_node_by_name(DrawGD.control, "ToolButtons")
var value = Global.config_cache.get_value(_slots[BUTTON_LEFT].kname, "tool", "Pencil")
var value = DrawGD.config_cache.get_value(_slots[BUTTON_LEFT].kname, "tool", "Pencil")
set_tool(value, BUTTON_LEFT)
value = Global.config_cache.get_value(_slots[BUTTON_RIGHT].kname, "tool", "Eraser")
value = DrawGD.config_cache.get_value(_slots[BUTTON_RIGHT].kname, "tool", "Eraser")
set_tool(value, BUTTON_RIGHT)
value = Global.config_cache.get_value(_slots[BUTTON_LEFT].kname, "color", Color.black)
value = DrawGD.config_cache.get_value(_slots[BUTTON_LEFT].kname, "color", Color.black)
assign_color(value, BUTTON_LEFT)
value = Global.config_cache.get_value(_slots[BUTTON_RIGHT].kname, "color", Color.white)
value = DrawGD.config_cache.get_value(_slots[BUTTON_RIGHT].kname, "color", Color.white)
assign_color(value, BUTTON_RIGHT)
update_tool_buttons()
@ -104,7 +104,7 @@ func assign_tool(name : String, button : int) -> void:
set_tool(name, button)
update_tool_buttons()
update_tool_cursors()
Global.config_cache.set_value(slot.kname, "tool", name)
DrawGD.config_cache.set_value(slot.kname, "tool", name)
func default_color() -> void:
@ -125,7 +125,7 @@ func assign_color(color : Color, button : int) -> void:
if color.r != c.r or color.g != c.g or color.b != c.b:
color.a = 1
_slots[button].color = color
Global.config_cache.set_value(_slots[button].kname, "color", color)
DrawGD.config_cache.set_value(_slots[button].kname, "color", color)
emit_signal("color_changed", color, button)
@ -142,25 +142,25 @@ func update_tool_buttons() -> void:
if _slots[BUTTON_RIGHT].tool_node.name == child.name:
filename += "_r"
filename += ".png"
Global.change_button_texturerect(texture, filename)
DrawGD.change_button_texturerect(texture, filename)
func update_tool_cursors() -> void:
var image = "res://assets/graphics/cursor_icons/%s_cursor.png" % _slots[BUTTON_LEFT].tool_node.name.to_lower()
Global.left_cursor_tool_texture.create_from_image(load(image), 0)
DrawGD.left_cursor_tool_texture.create_from_image(load(image), 0)
image = "res://assets/graphics/cursor_icons/%s_cursor.png" % _slots[BUTTON_RIGHT].tool_node.name.to_lower()
Global.right_cursor_tool_texture.create_from_image(load(image), 0)
DrawGD.right_cursor_tool_texture.create_from_image(load(image), 0)
func draw_indicator() -> void:
if Global.left_square_indicator_visible:
if DrawGD.left_square_indicator_visible:
_slots[BUTTON_LEFT].tool_node.draw_indicator()
if Global.right_square_indicator_visible:
if DrawGD.right_square_indicator_visible:
_slots[BUTTON_RIGHT].tool_node.draw_indicator()
func handle_draw(position : Vector2, event : InputEvent) -> void:
if not (Global.can_draw and Global.has_focus):
if not (DrawGD.can_draw and DrawGD.has_focus):
return
if event is InputEventWithModifiers:
@ -180,7 +180,7 @@ func handle_draw(position : Vector2, event : InputEvent) -> void:
if event is InputEventMouseMotion:
if Engine.get_version_info().major == 3 && Engine.get_version_info().minor >= 2:
pen_pressure = event.pressure
if Global.pressure_sensitivity_mode == Global.Pressure_Sensitivity.NONE:
if DrawGD.pressure_sensitivity_mode == DrawGD.Pressure_Sensitivity.NONE:
pen_pressure = 1.0
if not position.is_equal_approx(_last_position):
@ -190,12 +190,12 @@ func handle_draw(position : Vector2, event : InputEvent) -> void:
if _active_button != -1:
_slots[_active_button].tool_node.draw_move(position)
var project : Project = Global.current_project
var project : Project = DrawGD.current_project
var text := "[%s×%s]" % [project.size.x, project.size.y]
if Global.has_focus:
if DrawGD.has_focus:
text += " %s, %s" % [position.x, position.y]
if not _slots[BUTTON_LEFT].tool_node.cursor_text.empty():
text += " %s" % _slots[BUTTON_LEFT].tool_node.cursor_text
if not _slots[BUTTON_RIGHT].tool_node.cursor_text.empty():
text += " %s" % _slots[BUTTON_RIGHT].tool_node.cursor_text
Global.cursor_position_label.text = text
DrawGD.cursor_position_label.text = text

View File

@ -67,7 +67,7 @@ func set_pixel_perfect(value: bool) -> void:
func set_pixel(image: Image, position: Vector2, color: Color) -> void:
var project : Project = Global.current_project
var project : Project = DrawGD.current_project
drawers[0].set_pixel(image, position, color, color_op)
# Handle Mirroring

View File

@ -21,7 +21,7 @@ func _ready() -> void:
set_nodes()
current_cel = Image.new()
current_frame = Image.new()
current_frame.create(Global.current_project.size.x, Global.current_project.size.y, false, Image.FORMAT_RGBA8)
current_frame.create(DrawGD.current_project.size.x, DrawGD.current_project.size.y, false, Image.FORMAT_RGBA8)
preview_image = Image.new()
preview_texture = ImageTexture.new()
connect("about_to_show", self, "_about_to_show")
@ -34,9 +34,9 @@ func _ready() -> void:
func _about_to_show() -> void:
current_cel = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image
current_cel = DrawGD.current_project.frames[DrawGD.current_project.current_frame].cels[DrawGD.current_project.current_layer].image
current_frame.fill(Color(0, 0, 0, 0))
var frame = Global.current_project.frames[Global.current_project.current_frame]
var frame = DrawGD.current_project.frames[DrawGD.current_project.current_frame]
Export.blend_layers(current_frame, frame)
if selection_checkbox:
_on_SelectionCheckBox_toggled(selection_checkbox.pressed)
@ -47,24 +47,24 @@ func _about_to_show() -> void:
func _confirmed() -> void:
if affect == CEL:
Global.canvas.handle_undo("Draw")
DrawGD.canvas.handle_undo("Draw")
commit_action(current_cel, pixels)
Global.canvas.handle_redo("Draw")
DrawGD.canvas.handle_redo("Draw")
elif affect == FRAME:
Global.canvas.handle_undo("Draw", Global.current_project, -1)
for cel in Global.current_project.frames[Global.current_project.current_frame].cels:
DrawGD.canvas.handle_undo("Draw", DrawGD.current_project, -1)
for cel in DrawGD.current_project.frames[DrawGD.current_project.current_frame].cels:
commit_action(cel.image, pixels)
Global.canvas.handle_redo("Draw", Global.current_project, -1)
DrawGD.canvas.handle_redo("Draw", DrawGD.current_project, -1)
elif affect == ALL_FRAMES:
Global.canvas.handle_undo("Draw", Global.current_project, -1, -1)
for frame in Global.current_project.frames:
DrawGD.canvas.handle_undo("Draw", DrawGD.current_project, -1, -1)
for frame in DrawGD.current_project.frames:
for cel in frame.cels:
commit_action(cel.image, pixels)
Global.canvas.handle_redo("Draw", Global.current_project, -1, -1)
DrawGD.canvas.handle_redo("Draw", DrawGD.current_project, -1, -1)
elif affect == ALL_PROJECTS:
for project in Global.projects:
for project in DrawGD.projects:
var _pixels := []
if selection_checkbox.pressed:
_pixels = project.selected_pixels.duplicate()
@ -73,14 +73,14 @@ func _confirmed() -> void:
for y in project.size.y:
_pixels.append(Vector2(x, y))
Global.canvas.handle_undo("Draw", project, -1, -1)
DrawGD.canvas.handle_undo("Draw", project, -1, -1)
for frame in project.frames:
for cel in frame.cels:
commit_action(cel.image, _pixels, project)
Global.canvas.handle_redo("Draw", project, -1, -1)
DrawGD.canvas.handle_redo("Draw", project, -1, -1)
func commit_action(_cel : Image, _pixels : Array, _project : Project = Global.current_project) -> void:
func commit_action(_cel : Image, _pixels : Array, _project : Project = DrawGD.current_project) -> void:
pass
@ -91,10 +91,10 @@ func set_nodes() -> void:
func _on_SelectionCheckBox_toggled(button_pressed : bool) -> void:
pixels.clear()
if button_pressed:
pixels = Global.current_project.selected_pixels.duplicate()
pixels = DrawGD.current_project.selected_pixels.duplicate()
else:
for x in Global.current_project.size.x:
for y in Global.current_project.size.y:
for x in DrawGD.current_project.size.x:
for y in DrawGD.current_project.size.y:
pixels.append(Vector2(x, y))
update_preview()
@ -133,4 +133,4 @@ func update_transparent_background_size() -> void:
func _popup_hide() -> void:
Global.dialog_open(false)
DrawGD.dialog_open(false)

View File

@ -43,7 +43,7 @@ func _init(_frames := [], _name := tr("untitled"), _size := Vector2(64, 64)) ->
undo_redo = UndoRedo.new()
Global.tabs.add_tab(name)
DrawGD.tabs.add_tab(name)
OpenSave.current_save_paths.append("")
OpenSave.backup_save_paths.append("")
@ -56,7 +56,7 @@ func _init(_frames := [], _name := tr("untitled"), _size := Vector2(64, 64)) ->
x_symmetry_axis.project = self
x_symmetry_axis.add_point(Vector2(-19999, y_symmetry_point))
x_symmetry_axis.add_point(Vector2(19999, y_symmetry_point))
Global.canvas.add_child(x_symmetry_axis)
DrawGD.canvas.add_child(x_symmetry_axis)
if !y_symmetry_axis:
y_symmetry_axis = SymmetryGuide.new()
@ -64,7 +64,7 @@ func _init(_frames := [], _name := tr("untitled"), _size := Vector2(64, 64)) ->
y_symmetry_axis.project = self
y_symmetry_axis.add_point(Vector2(x_symmetry_point, -19999))
y_symmetry_axis.add_point(Vector2(x_symmetry_point, 19999))
Global.canvas.add_child(y_symmetry_axis)
DrawGD.canvas.add_child(y_symmetry_axis)
if OS.get_name() == "HTML5":
directory_path = "user://"
@ -85,18 +85,18 @@ func clear_selection() -> void:
func _set_selected_rect(value : Rect2) -> void:
selected_rect = value
Global.selection_rectangle.set_rect(value)
DrawGD.selection_rectangle.set_rect(value)
func change_project() -> void:
# Remove old nodes
for container in Global.layers_container.get_children():
for container in DrawGD.layers_container.get_children():
container.queue_free()
remove_cel_buttons()
for frame_id in Global.frame_ids.get_children():
Global.frame_ids.remove_child(frame_id)
for frame_id in DrawGD.frame_ids.get_children():
DrawGD.frame_ids.remove_child(frame_id)
frame_id.queue_free()
# Create new ones
@ -107,11 +107,11 @@ func change_project() -> void:
if layers[i].name == tr("Layer") + " 0":
layers[i].name = tr("Layer") + " %s" % i
Global.layers_container.add_child(layer_container)
DrawGD.layers_container.add_child(layer_container)
layer_container.label.text = layers[i].name
layer_container.line_edit.text = layers[i].name
Global.frames_container.add_child(layers[i].frame_container)
DrawGD.frames_container.add_child(layers[i].frame_container)
for j in range(frames.size()): # Create Cel buttons
var cel_button = load("res://src/UI/Timeline/CelButton.tscn").instance()
cel_button.frame = j
@ -128,35 +128,35 @@ func change_project() -> void:
label.align = Label.ALIGN_CENTER
label.text = str(j + 1)
if j == current_frame:
label.add_color_override("font_color", Global.control.theme.get_color("Selected Color", "Label"))
Global.frame_ids.add_child(label)
label.add_color_override("font_color", DrawGD.control.theme.get_color("Selected Color", "Label"))
DrawGD.frame_ids.add_child(label)
var layer_button = Global.layers_container.get_child(Global.layers_container.get_child_count() - 1 - current_layer)
var layer_button = DrawGD.layers_container.get_child(DrawGD.layers_container.get_child_count() - 1 - current_layer)
layer_button.pressed = true
Global.current_frame_mark_label.text = "%s/%s" % [str(current_frame + 1), frames.size()]
DrawGD.current_frame_mark_label.text = "%s/%s" % [str(current_frame + 1), frames.size()]
Global.disable_button(Global.remove_frame_button, frames.size() == 1)
Global.disable_button(Global.move_left_frame_button, frames.size() == 1 or current_frame == 0)
Global.disable_button(Global.move_right_frame_button, frames.size() == 1 or current_frame == frames.size() - 1)
DrawGD.disable_button(DrawGD.remove_frame_button, frames.size() == 1)
DrawGD.disable_button(DrawGD.move_left_frame_button, frames.size() == 1 or current_frame == 0)
DrawGD.disable_button(DrawGD.move_right_frame_button, frames.size() == 1 or current_frame == frames.size() - 1)
toggle_layer_buttons_layers()
toggle_layer_buttons_current_layer()
self.animation_tags = animation_tags
# Change the selection rectangle
Global.selection_rectangle.set_rect(selected_rect)
DrawGD.selection_rectangle.set_rect(selected_rect)
# Change the guides
for guide in Global.canvas.get_children():
for guide in DrawGD.canvas.get_children():
if guide is Guide:
if guide in guides:
guide.visible = Global.show_guides
guide.visible = DrawGD.show_guides
if guide is SymmetryGuide:
if guide.type == Guide.Types.HORIZONTAL:
guide.visible = Global.show_x_symmetry_axis and Global.show_guides
guide.visible = DrawGD.show_x_symmetry_axis and DrawGD.show_guides
else:
guide.visible = Global.show_y_symmetry_axis and Global.show_guides
guide.visible = DrawGD.show_y_symmetry_axis and DrawGD.show_guides
else:
guide.visible = false
@ -165,42 +165,42 @@ func change_project() -> void:
for brush in brushes:
Brushes.add_project_brush(brush)
var cameras = [Global.camera, Global.camera2, Global.camera_preview]
var cameras = [DrawGD.camera, DrawGD.camera2, DrawGD.camera_preview]
var i := 0
for camera in cameras:
camera.zoom = cameras_zoom[i]
camera.offset = cameras_offset[i]
i += 1
Global.zoom_level_label.text = str(round(100 / Global.camera.zoom.x)) + " %"
Global.canvas.update()
Global.canvas.grid.isometric_polylines.clear()
Global.canvas.grid.update()
Global.transparent_checker._ready()
Global.horizontal_ruler.update()
Global.vertical_ruler.update()
Global.preview_zoom_slider.value = -Global.camera_preview.zoom.x
Global.cursor_position_label.text = "[%s×%s]" % [size.x, size.y]
DrawGD.zoom_level_label.text = str(round(100 / DrawGD.camera.zoom.x)) + " %"
DrawGD.canvas.update()
DrawGD.canvas.grid.isometric_polylines.clear()
DrawGD.canvas.grid.update()
DrawGD.transparent_checker._ready()
DrawGD.horizontal_ruler.update()
DrawGD.vertical_ruler.update()
DrawGD.preview_zoom_slider.value = -DrawGD.camera_preview.zoom.x
DrawGD.cursor_position_label.text = "[%s×%s]" % [size.x, size.y]
Global.window_title = "%s - Pixelorama %s" % [name, Global.current_version]
DrawGD.window_title = "%s - Pixelorama %s" % [name, DrawGD.current_version]
if has_changed:
Global.window_title = Global.window_title + "(*)"
DrawGD.window_title = DrawGD.window_title + "(*)"
var save_path = OpenSave.current_save_paths[Global.current_project_index]
var save_path = OpenSave.current_save_paths[DrawGD.current_project_index]
if save_path != "":
Global.open_sprites_dialog.current_path = save_path
Global.save_sprites_dialog.current_path = save_path
Global.file_menu.get_popup().set_item_text(3, tr("Save") + " %s" % save_path.get_file())
DrawGD.open_sprites_dialog.current_path = save_path
DrawGD.save_sprites_dialog.current_path = save_path
DrawGD.file_menu.get_popup().set_item_text(3, tr("Save") + " %s" % save_path.get_file())
else:
Global.file_menu.get_popup().set_item_text(3, tr("Save"))
DrawGD.file_menu.get_popup().set_item_text(3, tr("Save"))
Export.directory_path = directory_path
Export.file_name = file_name
Export.file_format = file_format
if directory_path.empty():
Global.file_menu.get_popup().set_item_text(5, tr("Export"))
DrawGD.file_menu.get_popup().set_item_text(5, tr("Export"))
else:
Global.file_menu.get_popup().set_item_text(5, tr("Export") + " %s" % (file_name + Export.file_format_string(file_format)))
DrawGD.file_menu.get_popup().set_item_text(5, tr("Export") + " %s" % (file_name + Export.file_format_string(file_format)))
func serialize() -> Dictionary:
@ -258,11 +258,11 @@ func serialize() -> Dictionary:
})
var project_data := {
"pixelorama_version" : Global.current_version,
"pixelorama_version" : DrawGD.current_version,
"name" : name,
"size_x" : size.x,
"size_y" : size.y,
"save_path" : OpenSave.current_save_paths[Global.projects.find(self)],
"save_path" : OpenSave.current_save_paths[DrawGD.projects.find(self)],
"layers" : layer_data,
"tags" : tag_data,
"guides" : guide_data,
@ -285,7 +285,7 @@ func deserialize(dict : Dictionary) -> void:
size.y = dict.size_y
select_all_pixels()
if dict.has("save_path"):
OpenSave.current_save_paths[Global.projects.find(self)] = dict.save_path
OpenSave.current_save_paths[DrawGD.projects.find(self)] = dict.save_path
if dict.has("frames"):
for frame in dict.frames:
var cels := []
@ -318,7 +318,7 @@ func deserialize(dict : Dictionary) -> void:
guide.add_point(Vector2(g.pos, -99999))
guide.add_point(Vector2(g.pos, 99999))
guide.has_focus = false
Global.canvas.add_child(guide)
DrawGD.canvas.add_child(guide)
guides.append(guide)
if dict.has("symmetry_points"):
x_symmetry_point = dict.symmetry_points[0]
@ -337,12 +337,12 @@ func deserialize(dict : Dictionary) -> void:
func name_changed(value : String) -> void:
name = value
Global.tabs.set_tab_title(Global.tabs.current_tab, name)
DrawGD.tabs.set_tab_title(DrawGD.tabs.current_tab, name)
func size_changed(value : Vector2) -> void:
size = value
if Global.selection_rectangle._selected_rect.has_no_area():
if DrawGD.selection_rectangle._selected_rect.has_no_area():
select_all_pixels()
@ -350,19 +350,19 @@ func frames_changed(value : Array) -> void:
frames = value
remove_cel_buttons()
for frame_id in Global.frame_ids.get_children():
Global.frame_ids.remove_child(frame_id)
for frame_id in DrawGD.frame_ids.get_children():
DrawGD.frame_ids.remove_child(frame_id)
frame_id.queue_free()
for i in range(layers.size() - 1, -1, -1):
Global.frames_container.add_child(layers[i].frame_container)
DrawGD.frames_container.add_child(layers[i].frame_container)
for j in range(frames.size()):
var label := Label.new()
label.rect_min_size.x = 36
label.align = Label.ALIGN_CENTER
label.text = str(j + 1)
Global.frame_ids.add_child(label)
DrawGD.frame_ids.add_child(label)
for i in range(layers.size() - 1, -1, -1):
var cel_button = load("res://src/UI/Timeline/CelButton.tscn").instance()
@ -377,11 +377,11 @@ func frames_changed(value : Array) -> void:
func layers_changed(value : Array) -> void:
layers = value
if Global.layers_changed_skip:
Global.layers_changed_skip = false
if DrawGD.layers_changed_skip:
DrawGD.layers_changed_skip = false
return
for container in Global.layers_container.get_children():
for container in DrawGD.layers_container.get_children():
container.queue_free()
remove_cel_buttons()
@ -392,11 +392,11 @@ func layers_changed(value : Array) -> void:
if layers[i].name == tr("Layer") + " 0":
layers[i].name = tr("Layer") + " %s" % i
Global.layers_container.add_child(layer_container)
DrawGD.layers_container.add_child(layer_container)
layer_container.label.text = layers[i].name
layer_container.line_edit.text = layers[i].name
Global.frames_container.add_child(layers[i].frame_container)
DrawGD.frames_container.add_child(layers[i].frame_container)
for j in range(frames.size()):
var cel_button = load("res://src/UI/Timeline/CelButton.tscn").instance()
cel_button.frame = j
@ -405,29 +405,29 @@ func layers_changed(value : Array) -> void:
layers[i].frame_container.add_child(cel_button)
var layer_button = Global.layers_container.get_child(Global.layers_container.get_child_count() - 1 - current_layer)
var layer_button = DrawGD.layers_container.get_child(DrawGD.layers_container.get_child_count() - 1 - current_layer)
layer_button.pressed = true
self.current_frame = current_frame # Call frame_changed to update UI
toggle_layer_buttons_layers()
func remove_cel_buttons() -> void:
for container in Global.frames_container.get_children():
for container in DrawGD.frames_container.get_children():
for button in container.get_children():
container.remove_child(button)
button.queue_free()
Global.frames_container.remove_child(container)
DrawGD.frames_container.remove_child(container)
func frame_changed(value : int) -> void:
current_frame = value
Global.current_frame_mark_label.text = "%s/%s" % [str(current_frame + 1), frames.size()]
DrawGD.current_frame_mark_label.text = "%s/%s" % [str(current_frame + 1), frames.size()]
for i in frames.size():
var text_color := Color.white
if Global.theme_type == Global.Theme_Types.CARAMEL || Global.theme_type == Global.Theme_Types.LIGHT:
if DrawGD.theme_type == DrawGD.Theme_Types.CARAMEL || DrawGD.theme_type == DrawGD.Theme_Types.LIGHT:
text_color = Color.black
Global.frame_ids.get_child(i).add_color_override("font_color", text_color)
DrawGD.frame_ids.get_child(i).add_color_override("font_color", text_color)
for layer in layers: # De-select all the other frames
if i < layer.frame_container.get_child_count():
layer.frame_container.get_child(i).pressed = false
@ -436,30 +436,30 @@ func frame_changed(value : int) -> void:
if layers and current_frame < layers[current_layer].frame_container.get_child_count():
layers[current_layer].frame_container.get_child(current_frame).pressed = true
Global.disable_button(Global.remove_frame_button, frames.size() == 1)
Global.disable_button(Global.move_left_frame_button, frames.size() == 1 or current_frame == 0)
Global.disable_button(Global.move_right_frame_button, frames.size() == 1 or current_frame == frames.size() - 1)
DrawGD.disable_button(DrawGD.remove_frame_button, frames.size() == 1)
DrawGD.disable_button(DrawGD.move_left_frame_button, frames.size() == 1 or current_frame == 0)
DrawGD.disable_button(DrawGD.move_right_frame_button, frames.size() == 1 or current_frame == frames.size() - 1)
Global.canvas.update()
Global.transparent_checker._ready() # To update the rect size
DrawGD.canvas.update()
DrawGD.transparent_checker._ready() # To update the rect size
func layer_changed(value : int) -> void:
current_layer = value
if current_frame < frames.size():
Global.layer_opacity_slider.value = frames[current_frame].cels[current_layer].opacity * 100
Global.layer_opacity_spinbox.value = frames[current_frame].cels[current_layer].opacity * 100
DrawGD.layer_opacity_slider.value = frames[current_frame].cels[current_layer].opacity * 100
DrawGD.layer_opacity_spinbox.value = frames[current_frame].cels[current_layer].opacity * 100
for container in Global.layers_container.get_children():
for container in DrawGD.layers_container.get_children():
container.pressed = false
if current_layer < Global.layers_container.get_child_count():
var layer_button = Global.layers_container.get_child(Global.layers_container.get_child_count() - 1 - current_layer)
if current_layer < DrawGD.layers_container.get_child_count():
var layer_button = DrawGD.layers_container.get_child(DrawGD.layers_container.get_child_count() - 1 - current_layer)
layer_button.pressed = true
toggle_layer_buttons_current_layer()
yield(Global.get_tree().create_timer(0.01), "timeout")
yield(DrawGD.get_tree().create_timer(0.01), "timeout")
self.current_frame = current_frame # Call frame_changed to update UI
@ -467,48 +467,48 @@ func toggle_layer_buttons_layers() -> void:
if !layers:
return
if layers[current_layer].locked:
Global.disable_button(Global.remove_layer_button, true)
DrawGD.disable_button(DrawGD.remove_layer_button, true)
if layers.size() == 1:
Global.disable_button(Global.remove_layer_button, true)
Global.disable_button(Global.move_up_layer_button, true)
Global.disable_button(Global.move_down_layer_button, true)
Global.disable_button(Global.merge_down_layer_button, true)
DrawGD.disable_button(DrawGD.remove_layer_button, true)
DrawGD.disable_button(DrawGD.move_up_layer_button, true)
DrawGD.disable_button(DrawGD.move_down_layer_button, true)
DrawGD.disable_button(DrawGD.merge_down_layer_button, true)
elif !layers[current_layer].locked:
Global.disable_button(Global.remove_layer_button, false)
DrawGD.disable_button(DrawGD.remove_layer_button, false)
func toggle_layer_buttons_current_layer() -> void:
if current_layer < layers.size() - 1:
Global.disable_button(Global.move_up_layer_button, false)
DrawGD.disable_button(DrawGD.move_up_layer_button, false)
else:
Global.disable_button(Global.move_up_layer_button, true)
DrawGD.disable_button(DrawGD.move_up_layer_button, true)
if current_layer > 0:
Global.disable_button(Global.move_down_layer_button, false)
Global.disable_button(Global.merge_down_layer_button, false)
DrawGD.disable_button(DrawGD.move_down_layer_button, false)
DrawGD.disable_button(DrawGD.merge_down_layer_button, false)
else:
Global.disable_button(Global.move_down_layer_button, true)
Global.disable_button(Global.merge_down_layer_button, true)
DrawGD.disable_button(DrawGD.move_down_layer_button, true)
DrawGD.disable_button(DrawGD.merge_down_layer_button, true)
if current_layer < layers.size():
if layers[current_layer].locked:
Global.disable_button(Global.remove_layer_button, true)
DrawGD.disable_button(DrawGD.remove_layer_button, true)
else:
if layers.size() > 1:
Global.disable_button(Global.remove_layer_button, false)
DrawGD.disable_button(DrawGD.remove_layer_button, false)
func animation_tags_changed(value : Array) -> void:
animation_tags = value
for child in Global.tag_container.get_children():
for child in DrawGD.tag_container.get_children():
child.queue_free()
for tag in animation_tags:
var tag_c : Container = load("res://src/UI/Timeline/AnimationTag.tscn").instance()
Global.tag_container.add_child(tag_c)
var tag_position : int = Global.tag_container.get_child_count() - 1
Global.tag_container.move_child(tag_c, tag_position)
DrawGD.tag_container.add_child(tag_c)
var tag_position : int = DrawGD.tag_container.get_child_count() - 1
DrawGD.tag_container.move_child(tag_c, tag_position)
tag_c.get_node("Label").text = tag.name
tag_c.get_node("Label").modulate = tag.color
tag_c.get_node("Line2D").default_color = tag.color
@ -527,18 +527,18 @@ func set_timeline_first_and_last_frames() -> void:
# This is useful in case tags get modified DURING the animation is playing
# otherwise, this code is useless in this context, since these values are being set
# when the play buttons get pressed anyway
Global.animation_timeline.first_frame = 0
Global.animation_timeline.last_frame = frames.size() - 1
if Global.play_only_tags:
DrawGD.animation_timeline.first_frame = 0
DrawGD.animation_timeline.last_frame = frames.size() - 1
if DrawGD.play_only_tags:
for tag in animation_tags:
if current_frame + 1 >= tag.from && current_frame + 1 <= tag.to:
Global.animation_timeline.first_frame = tag.from - 1
Global.animation_timeline.last_frame = min(frames.size() - 1, tag.to - 1)
DrawGD.animation_timeline.first_frame = tag.from - 1
DrawGD.animation_timeline.last_frame = min(frames.size() - 1, tag.to - 1)
func has_changed_changed(value : bool) -> void:
has_changed = value
if value:
Global.tabs.set_tab_title(Global.tabs.current_tab, name + "(*)")
DrawGD.tabs.set_tab_title(DrawGD.tabs.current_tab, name + "(*)")
else:
Global.tabs.set_tab_title(Global.tabs.current_tab, name)
DrawGD.tabs.set_tab_title(DrawGD.tabs.current_tab, name)

View File

@ -14,27 +14,27 @@ func _ready() -> void:
get_tree().set_auto_accept_quit(false)
setup_application_window_size()
Global.window_title = tr("untitled") + " - Pixelorama " + Global.current_version
DrawGD.window_title = tr("untitled") + " - Pixelorama " + DrawGD.current_version
Global.current_project.layers[0].name = tr("Layer") + " 0"
Global.layers_container.get_child(0).label.text = Global.current_project.layers[0].name
Global.layers_container.get_child(0).line_edit.text = Global.current_project.layers[0].name
DrawGD.current_project.layers[0].name = tr("Layer") + " 0"
DrawGD.layers_container.get_child(0).label.text = DrawGD.current_project.layers[0].name
DrawGD.layers_container.get_child(0).line_edit.text = DrawGD.current_project.layers[0].name
Import.import_brushes(Global.directory_module.get_brushes_search_path_in_order())
Import.import_patterns(Global.directory_module.get_patterns_search_path_in_order())
Import.import_brushes(DrawGD.directory_module.get_brushes_search_path_in_order())
Import.import_patterns(DrawGD.directory_module.get_patterns_search_path_in_order())
Global.quit_and_save_dialog.add_button("Save & Exit", false, "Save")
Global.quit_and_save_dialog.get_ok().text = "Exit without saving"
DrawGD.quit_and_save_dialog.add_button("Save & Exit", false, "Save")
DrawGD.quit_and_save_dialog.get_ok().text = "Exit without saving"
var zstd_checkbox := CheckBox.new()
zstd_checkbox.name = "ZSTDCompression"
zstd_checkbox.pressed = true
zstd_checkbox.text = "Use ZSTD Compression"
zstd_checkbox.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
Global.save_sprites_dialog.get_vbox().add_child(zstd_checkbox)
DrawGD.save_sprites_dialog.get_vbox().add_child(zstd_checkbox)
if not Global.config_cache.has_section_key("preferences", "startup"):
Global.config_cache.set_value("preferences", "startup", true)
if not DrawGD.config_cache.has_section_key("preferences", "startup"):
DrawGD.config_cache.set_value("preferences", "startup", true)
show_splash_screen()
handle_backup()
@ -47,10 +47,10 @@ func _ready() -> void:
func _input(event : InputEvent) -> void:
Global.left_cursor.position = get_global_mouse_position() + Vector2(-32, 32)
Global.left_cursor.texture = Global.left_cursor_tool_texture
Global.right_cursor.position = get_global_mouse_position() + Vector2(32, 32)
Global.right_cursor.texture = Global.right_cursor_tool_texture
DrawGD.left_cursor.position = get_global_mouse_position() + Vector2(-32, 32)
DrawGD.left_cursor.texture = DrawGD.left_cursor_tool_texture
DrawGD.right_cursor.position = get_global_mouse_position() + Vector2(32, 32)
DrawGD.right_cursor.texture = DrawGD.right_cursor_tool_texture
if event is InputEventKey and (event.scancode == KEY_ENTER or event.scancode == KEY_KP_ENTER):
if get_focus_owner() is LineEdit:
@ -58,7 +58,7 @@ func _input(event : InputEvent) -> void:
if event.is_action_pressed("redo_secondary"): # Shift + Ctrl + Z
redone = true
Global.current_project.undo_redo.redo()
DrawGD.current_project.undo_redo.redo()
redone = false
@ -69,48 +69,48 @@ func setup_application_window_size() -> void:
OS.min_window_size = Vector2(1024, 576)
# Restore the window position/size if values are present in the configuration cache
if Global.config_cache.has_section_key("window", "screen"):
OS.current_screen = Global.config_cache.get_value("window", "screen")
if Global.config_cache.has_section_key("window", "maximized"):
OS.window_maximized = Global.config_cache.get_value("window", "maximized")
if DrawGD.config_cache.has_section_key("window", "screen"):
OS.current_screen = DrawGD.config_cache.get_value("window", "screen")
if DrawGD.config_cache.has_section_key("window", "maximized"):
OS.window_maximized = DrawGD.config_cache.get_value("window", "maximized")
if !OS.window_maximized:
if Global.config_cache.has_section_key("window", "position"):
OS.window_position = Global.config_cache.get_value("window", "position")
if Global.config_cache.has_section_key("window", "size"):
OS.window_size = Global.config_cache.get_value("window", "size")
if DrawGD.config_cache.has_section_key("window", "position"):
OS.window_position = DrawGD.config_cache.get_value("window", "position")
if DrawGD.config_cache.has_section_key("window", "size"):
OS.window_size = DrawGD.config_cache.get_value("window", "size")
func show_splash_screen() -> void:
# Wait for the window to adjust itself, so the popup is correctly centered
yield(get_tree().create_timer(0.2), "timeout")
Global.can_draw = true
DrawGD.can_draw = true
func handle_backup() -> void:
# If backup file exists then Pixelorama was not closed properly (probably crashed) - reopen backup
var backup_confirmation : ConfirmationDialog = $Dialogs/BackupConfirmation
backup_confirmation.get_cancel().text = tr("Delete")
if Global.config_cache.has_section("backups"):
var project_paths = Global.config_cache.get_section_keys("backups")
if DrawGD.config_cache.has_section("backups"):
var project_paths = DrawGD.config_cache.get_section_keys("backups")
if project_paths.size() > 0:
# Get backup paths
var backup_paths := []
for p_path in project_paths:
backup_paths.append(Global.config_cache.get_value("backups", p_path))
backup_paths.append(DrawGD.config_cache.get_value("backups", p_path))
# Temporatily stop autosave until user confirms backup
OpenSave.autosave_timer.stop()
backup_confirmation.dialog_text = tr(backup_confirmation.dialog_text) % project_paths
backup_confirmation.connect("confirmed", self, "_on_BackupConfirmation_confirmed", [project_paths, backup_paths])
backup_confirmation.get_cancel().connect("pressed", self, "_on_BackupConfirmation_delete", [project_paths, backup_paths])
backup_confirmation.popup_centered()
Global.can_draw = false
DrawGD.can_draw = false
modulate = Color(0.5, 0.5, 0.5)
else:
if Global.open_last_project:
if DrawGD.open_last_project:
load_last_project()
else:
if Global.open_last_project:
if DrawGD.open_last_project:
load_last_project()
@ -127,17 +127,17 @@ func load_last_project() -> void:
if OS.get_name() == "HTML5":
return
# Check if any project was saved or opened last time
if Global.config_cache.has_section_key("preferences", "last_project_path"):
if DrawGD.config_cache.has_section_key("preferences", "last_project_path"):
# Check if file still exists on disk
var file_path = Global.config_cache.get_value("preferences", "last_project_path")
var file_path = DrawGD.config_cache.get_value("preferences", "last_project_path")
var file_check := File.new()
if file_check.file_exists(file_path): # If yes then load the file
OpenSave.open_pxo_file(file_path)
else:
# If file doesn't exist on disk then warn user about this
Global.error_dialog.set_text("Cannot find last project file.")
Global.error_dialog.popup_centered()
Global.dialog_open(true)
DrawGD.error_dialog.set_text("Cannot find last project file.")
DrawGD.error_dialog.popup_centered()
DrawGD.dialog_open(true)
func _on_OpenSprite_file_selected(path : String) -> void:
@ -145,7 +145,7 @@ func _on_OpenSprite_file_selected(path : String) -> void:
func _on_SaveSprite_file_selected(path : String) -> void:
var zstd = Global.save_sprites_dialog.get_vbox().get_node("ZSTDCompression").pressed
var zstd = DrawGD.save_sprites_dialog.get_vbox().get_node("ZSTDCompression").pressed
OpenSave.save_pxo_file(path, false, zstd)
if is_quitting_on_save:
@ -153,7 +153,7 @@ func _on_SaveSprite_file_selected(path : String) -> void:
func _on_SaveSpriteHTML5_confirmed() -> void:
var file_name = Global.save_sprites_html5_dialog.get_node("FileNameContainer/FileNameLineEdit").text
var file_name = DrawGD.save_sprites_html5_dialog.get_node("FileNameContainer/FileNameLineEdit").text
file_name += ".pxo"
var path = "user://".plus_file(file_name)
OpenSave.save_pxo_file(path, false, false)
@ -165,25 +165,25 @@ func _on_OpenSprite_popup_hide() -> void:
func _can_draw_true() -> void:
Global.dialog_open(false)
DrawGD.dialog_open(false)
func show_quit_dialog() -> void:
if !Global.quit_dialog.visible:
if !Global.current_project.has_changed:
Global.quit_dialog.call_deferred("popup_centered")
if !DrawGD.quit_dialog.visible:
if !DrawGD.current_project.has_changed:
DrawGD.quit_dialog.call_deferred("popup_centered")
else:
Global.quit_and_save_dialog.call_deferred("popup_centered")
DrawGD.quit_and_save_dialog.call_deferred("popup_centered")
Global.dialog_open(true)
DrawGD.dialog_open(true)
func _on_QuitAndSaveDialog_custom_action(action : String) -> void:
if action == "Save":
is_quitting_on_save = true
Global.save_sprites_dialog.popup_centered()
Global.quit_dialog.hide()
Global.dialog_open(true)
DrawGD.save_sprites_dialog.popup_centered()
DrawGD.quit_dialog.hide()
DrawGD.dialog_open(true)
func _on_QuitDialog_confirmed() -> void:
@ -199,8 +199,8 @@ func _on_BackupConfirmation_confirmed(project_paths : Array, backup_paths : Arra
Export.file_name = OpenSave.current_save_paths[0].get_file().trim_suffix(".pxo")
Export.directory_path = OpenSave.current_save_paths[0].get_base_dir()
Export.was_exported = false
Global.file_menu.get_popup().set_item_text(3, tr("Save") + " %s" % OpenSave.current_save_paths[0].get_file())
Global.file_menu.get_popup().set_item_text(5, tr("Export"))
DrawGD.file_menu.get_popup().set_item_text(3, tr("Save") + " %s" % OpenSave.current_save_paths[0].get_file())
DrawGD.file_menu.get_popup().set_item_text(5, tr("Export"))
func _on_BackupConfirmation_delete(project_paths : Array, backup_paths : Array) -> void:
@ -208,5 +208,5 @@ func _on_BackupConfirmation_delete(project_paths : Array, backup_paths : Array)
OpenSave.remove_backup_by_path(project_paths[i], backup_paths[i])
OpenSave.autosave_timer.start()
# Reopen last project
if Global.open_last_project:
if DrawGD.open_last_project:
load_last_project()

View File

@ -22,11 +22,11 @@ func _ready() -> void:
func open(palette : String) -> void:
current_palette = palette
palette_name_edit.text = current_palette
if Global.palettes.has(palette):
working_palette = Global.palettes[palette].duplicate()
if DrawGD.palettes.has(palette):
working_palette = DrawGD.palettes[palette].duplicate()
_display_palette()
self.popup_centered()
Global.dialog_open(true)
DrawGD.dialog_open(true)
left_color_button.modulate = Tools.get_assigned_color(BUTTON_LEFT)
right_color_button.modulate = Tools.get_assigned_color(BUTTON_RIGHT)
@ -121,15 +121,15 @@ func re_index_swatches() -> void:
# Rename a palette, copying to user directory if necessary.
func rename_palette_file_with_priority_dirs(old_fname: String, new_fname: String) -> void:
var user_write_directory: String = Global.directory_module.get_palette_write_path()
var user_write_directory: String = DrawGD.directory_module.get_palette_write_path()
var usrwrite_dir := Directory.new()
usrwrite_dir.open(user_write_directory)
if usrwrite_dir.file_exists(old_fname):
usrwrite_dir.rename(old_fname, new_fname)
else:
# Scan through the main system directories
var priority_dirs : Array = Global.directory_module.get_palette_search_path_in_order()
var best_clone_location = Global.palette_container.get_best_palette_file_location(
var priority_dirs : Array = DrawGD.directory_module.get_palette_search_path_in_order()
var best_clone_location = DrawGD.palette_container.get_best_palette_file_location(
priority_dirs,
old_fname
)
@ -139,7 +139,7 @@ func rename_palette_file_with_priority_dirs(old_fname: String, new_fname: String
func _on_EditPaletteSaveButton_pressed() -> void:
if palette_name_edit.text != current_palette:
Global.palettes.erase(current_palette)
DrawGD.palettes.erase(current_palette)
rename_palette_file_with_priority_dirs(
current_palette + ".json",
palette_name_edit.text + ".json"
@ -147,14 +147,14 @@ func _on_EditPaletteSaveButton_pressed() -> void:
current_palette = palette_name_edit.text
working_palette.name = current_palette
var optionbutton_index = Global.palette_option_button.selected
Global.palette_option_button.set_item_text(optionbutton_index, current_palette)
Global.palette_option_button.set_item_metadata(optionbutton_index, current_palette)
Global.palette_option_button.text = current_palette
var optionbutton_index = DrawGD.palette_option_button.selected
DrawGD.palette_option_button.set_item_text(optionbutton_index, current_palette)
DrawGD.palette_option_button.set_item_metadata(optionbutton_index, current_palette)
DrawGD.palette_option_button.text = current_palette
Global.palettes[current_palette] = working_palette
Global.palette_container.on_palette_select(current_palette)
Global.palette_container.save_palette(current_palette, working_palette.name + ".json")
DrawGD.palettes[current_palette] = working_palette
DrawGD.palette_container.on_palette_select(current_palette)
DrawGD.palette_container.save_palette(current_palette, working_palette.name + ".json")
self.hide()
@ -190,4 +190,4 @@ func _on_RightColor_pressed() -> void:
func _on_EditPalettePopup_popup_hide() -> void:
Global.dialog_open(false)
DrawGD.dialog_open(false)

View File

@ -20,7 +20,7 @@ func _ready() -> void:
# Select default palette "Default"
on_palette_select(current_palette)
var add_palette_menu : PopupMenu = Global.add_palette_button.get_node("PopupMenu")
var add_palette_menu : PopupMenu = DrawGD.add_palette_button.get_node("PopupMenu")
add_palette_menu.connect("id_pressed", self, "add_palette_menu_id_pressed")
@ -33,23 +33,23 @@ func _clear_swatches() -> void:
func on_palette_select(palette_name : String) -> void:
_clear_swatches()
if Global.palettes.has(palette_name): # Palette exists in memory
if DrawGD.palettes.has(palette_name): # Palette exists in memory
current_palette = palette_name
var palette : Palette = Global.palettes[palette_name]
var palette : Palette = DrawGD.palettes[palette_name]
_display_palette(palette)
func on_new_empty_palette() -> void:
Global.new_palette_dialog.window_title = "Create a new empty palette?"
Global.new_palette_name_line_edit.text = "Custom_Palette"
DrawGD.new_palette_dialog.window_title = "Create a new empty palette?"
DrawGD.new_palette_name_line_edit.text = "Custom_Palette"
from_palette = null
Global.new_palette_dialog.popup_centered()
Global.dialog_open(true)
DrawGD.new_palette_dialog.popup_centered()
DrawGD.dialog_open(true)
func on_import_palette() -> void:
Global.palette_import_file_dialog.popup_centered()
Global.dialog_open(true)
DrawGD.palette_import_file_dialog.popup_centered()
DrawGD.dialog_open(true)
func on_palette_import_file_selected(path : String) -> void:
@ -89,30 +89,30 @@ func import_image_palette(path : String, image : Image) -> void:
func attempt_to_import_palette(palette : Palette) -> void:
if palette:
palette.name = palette_name_replace(palette.name)
Global.palettes[palette.name] = palette
Global.palette_option_button.add_item(palette.name)
var index: int = Global.palette_option_button.get_item_count() - 1
Global.palette_option_button.set_item_metadata(index, palette.name)
Global.palette_option_button.select(index)
DrawGD.palettes[palette.name] = palette
DrawGD.palette_option_button.add_item(palette.name)
var index: int = DrawGD.palette_option_button.get_item_count() - 1
DrawGD.palette_option_button.set_item_metadata(index, palette.name)
DrawGD.palette_option_button.select(index)
on_palette_select(palette.name)
save_palette(palette.name, palette.name + ".json")
else:
Global.error_dialog.set_text("Invalid Palette file!")
Global.error_dialog.popup_centered()
Global.dialog_open(true)
DrawGD.error_dialog.set_text("Invalid Palette file!")
DrawGD.error_dialog.popup_centered()
DrawGD.dialog_open(true)
func _on_AddPalette_pressed() -> void:
Global.add_palette_button.get_node("PopupMenu").popup(Rect2(Global.add_palette_button.rect_global_position, Vector2.ONE))
DrawGD.add_palette_button.get_node("PopupMenu").popup(Rect2(DrawGD.add_palette_button.rect_global_position, Vector2.ONE))
func on_new_palette_confirmed() -> void:
var new_palette_name : String = Global.new_palette_name_line_edit.text
var new_palette_name : String = DrawGD.new_palette_name_line_edit.text
var result : String = create_new_palette(new_palette_name, from_palette)
if not result.empty():
Global.error_dialog.set_text(result)
Global.error_dialog.popup_centered()
Global.dialog_open(true)
DrawGD.error_dialog.set_text(result)
DrawGD.error_dialog.popup_centered()
DrawGD.dialog_open(true)
func add_palette_menu_id_pressed(id : int) -> void:
@ -123,7 +123,7 @@ func add_palette_menu_id_pressed(id : int) -> void:
on_import_palette()
2: # Create Palette From Current Sprite
palette_from_sprite_dialog.popup_centered()
Global.dialog_open(true)
DrawGD.dialog_open(true)
func create_new_palette(name : String, _from_palette : Palette) -> String: # Returns empty string, else error string
@ -142,12 +142,12 @@ func create_new_palette(name : String, _from_palette : Palette) -> String: # Ret
new_palette.name = name
new_palette.editable = true
# Add palette to Global and options
Global.palettes[name] = new_palette
Global.palette_option_button.add_item(name)
var index : int = Global.palette_option_button.get_item_count() - 1
Global.palette_option_button.set_item_metadata(index, name)
Global.palette_option_button.select(index)
# Add palette to DrawGD and options
DrawGD.palettes[name] = new_palette
DrawGD.palette_option_button.add_item(name)
var index : int = DrawGD.palette_option_button.get_item_count() - 1
DrawGD.palette_option_button.set_item_metadata(index, name)
DrawGD.palette_option_button.select(index)
save_palette(name, name + ".json")
@ -161,7 +161,7 @@ func create_new_palette(name : String, _from_palette : Palette) -> String: # Ret
func palette_name_replace(name : String) -> String:
var i := 1
var temp_name := name
while Global.palettes.has(temp_name):
while DrawGD.palettes.has(temp_name):
i += 1
temp_name = name + " (%s)" % i
name = temp_name
@ -169,38 +169,38 @@ func palette_name_replace(name : String) -> String:
func on_edit_palette() -> void:
var palette : Palette = Global.palettes[current_palette]
var palette : Palette = DrawGD.palettes[current_palette]
var create_new_palette := true # Create new palette by default
if palette.editable:
create_new_palette = false # Edit if already a custom palette
if create_new_palette:
from_palette = Global.palettes[current_palette]
Global.new_palette_dialog.window_title = "Create a new custom palette from existing default?"
Global.new_palette_name_line_edit.text = "Custom_" + current_palette
Global.new_palette_dialog.popup_centered()
Global.dialog_open(true)
from_palette = DrawGD.palettes[current_palette]
DrawGD.new_palette_dialog.window_title = "Create a new custom palette from existing default?"
DrawGD.new_palette_name_line_edit.text = "Custom_" + current_palette
DrawGD.new_palette_dialog.popup_centered()
DrawGD.dialog_open(true)
else:
from_palette = null
Global.edit_palette_popup.open(current_palette)
DrawGD.edit_palette_popup.open(current_palette)
func create_palette_from_sprite() -> void:
var current_project : Project = Global.current_project
var current_project : Project = DrawGD.current_project
var new_palette_name : String = current_project.name
var result : String = create_new_palette(new_palette_name, null)
if not result.empty():
Global.error_dialog.set_text(result)
Global.error_dialog.popup_centered()
Global.dialog_open(true)
DrawGD.error_dialog.set_text(result)
DrawGD.error_dialog.popup_centered()
DrawGD.dialog_open(true)
return
var alpha_checkbox : CheckBox = palette_from_sprite_dialog.get_node("VBoxContainer/AlphaCheckBox")
var selection_checkbox : CheckBox = palette_from_sprite_dialog.get_node("VBoxContainer/SelectionCheckBox")
var colors_from_optionbutton : OptionButton = palette_from_sprite_dialog.get_node("VBoxContainer/HBoxContainer/ColorsFromOptionButton")
var palette : Palette = Global.palettes[current_palette]
var palette : Palette = DrawGD.palettes[current_palette]
var pixels := []
if selection_checkbox.pressed:
@ -242,7 +242,7 @@ func create_palette_from_sprite() -> void:
func _on_PaletteOptionButton_item_selected(ID : int) -> void:
var palette_name = Global.palette_option_button.get_item_metadata(ID)
var palette_name = DrawGD.palette_option_button.get_item_metadata(ID)
if palette_name != null:
on_palette_select(palette_name)
@ -264,7 +264,7 @@ func _display_palette(palette : Palette) -> void:
func on_color_select(index : int) -> void:
var color : Color = Global.palettes[current_palette].get_color(index)
var color : Color = DrawGD.palettes[current_palette].get_color(index)
if Input.is_action_just_pressed("left_mouse"):
Tools.assign_color(color, BUTTON_LEFT)
@ -273,8 +273,8 @@ func on_color_select(index : int) -> void:
func _load_palettes() -> void:
Global.directory_module.ensure_xdg_user_dirs_exist()
var search_locations = Global.directory_module.get_palette_search_path_in_order()
DrawGD.directory_module.ensure_xdg_user_dirs_exist()
var search_locations = DrawGD.directory_module.get_palette_search_path_in_order()
var priority_ordered_files := get_palette_priority_file_map(search_locations)
# Iterate backwards, so any palettes defined in default files
@ -287,20 +287,20 @@ func _load_palettes() -> void:
for file_name in palette_files:
var palette : Palette = Palette.new().load_from_file(base_directory.plus_file(file_name))
if palette:
Global.palettes[palette.name] = palette
Global.palette_option_button.add_item(palette.name)
var index: int = Global.palette_option_button.get_item_count() - 1
Global.palette_option_button.set_item_metadata(index, palette.name)
DrawGD.palettes[palette.name] = palette
DrawGD.palette_option_button.add_item(palette.name)
var index: int = DrawGD.palette_option_button.get_item_count() - 1
DrawGD.palette_option_button.set_item_metadata(index, palette.name)
if palette.name == "Default":
# You need these two lines because when you remove a palette
# Then this just won't work and _on_PaletteOptionButton_item_selected
# method won't fire.
Global.palette_option_button.selected = index
DrawGD.palette_option_button.selected = index
on_palette_select("Default")
Global.palette_option_button.select(index)
DrawGD.palette_option_button.select(index)
if not "Default" in Global.palettes && Global.palettes.size() > 0:
Global.palette_container._on_PaletteOptionButton_item_selected(0)
if not "Default" in DrawGD.palettes && DrawGD.palettes.size() > 0:
DrawGD.palette_container._on_PaletteOptionButton_item_selected(0)
# Get the palette files in a single directory.
@ -372,47 +372,47 @@ func get_best_palette_file_location(looking_paths: Array, fname: String): # ->
func remove_palette(palette_name : String) -> void:
# Don't allow user to remove palette if there is no one left
if Global.palettes.size() < 2:
Global.error_dialog.set_text("You can't remove more palettes!")
Global.error_dialog.popup_centered()
Global.dialog_open(true)
if DrawGD.palettes.size() < 2:
DrawGD.error_dialog.set_text("You can't remove more palettes!")
DrawGD.error_dialog.popup_centered()
DrawGD.dialog_open(true)
return
# Don't allow user to try to remove not existing palettes
if not palette_name in Global.palettes:
Global.error_dialog.set_text("Cannot remove the palette, because it doesn't exist!")
Global.error_dialog.popup_centered()
Global.dialog_open(true)
if not palette_name in DrawGD.palettes:
DrawGD.error_dialog.set_text("Cannot remove the palette, because it doesn't exist!")
DrawGD.error_dialog.popup_centered()
DrawGD.dialog_open(true)
return
Global.directory_module.ensure_xdg_user_dirs_exist()
var palette = Global.palettes[palette_name]
DrawGD.directory_module.ensure_xdg_user_dirs_exist()
var palette = DrawGD.palettes[palette_name]
var result = palette.remove_file()
# Inform user if pallete hasn't been removed from disk because of an error
if result != OK:
Global.error_dialog.set_text(tr("An error occured while removing the palette! Error code: %s") % str(result))
Global.error_dialog.popup_centered()
Global.dialog_open(true)
DrawGD.error_dialog.set_text(tr("An error occured while removing the palette! Error code: %s") % str(result))
DrawGD.error_dialog.popup_centered()
DrawGD.dialog_open(true)
# Remove palette in the program anyway, because if you don't do it
# then Pixelorama will crash
Global.palettes.erase(palette_name)
Global.palette_option_button.clear()
DrawGD.palettes.erase(palette_name)
DrawGD.palette_option_button.clear()
current_palette = "Default"
_load_palettes()
func save_palette(palette_name : String, filename : String) -> void:
Global.directory_module.ensure_xdg_user_dirs_exist()
var palette = Global.palettes[palette_name]
var palettes_write_path: String = Global.directory_module.get_palette_write_path()
DrawGD.directory_module.ensure_xdg_user_dirs_exist()
var palette = DrawGD.palettes[palette_name]
var palettes_write_path: String = DrawGD.directory_module.get_palette_write_path()
palette.save_to_file(palettes_write_path.plus_file(filename))
func _on_NewPaletteDialog_popup_hide() -> void:
Global.dialog_open(false)
DrawGD.dialog_open(false)
func _on_RemovePalette_pressed() -> void:
remove_palette_warning.popup_centered()
Global.dialog_open(true)
DrawGD.dialog_open(true)
func _on_PaletteFromSpriteDialog_confirmed() -> void:
@ -420,7 +420,7 @@ func _on_PaletteFromSpriteDialog_confirmed() -> void:
func _on_PaletteFromSpriteDialog_popup_hide() -> void:
Global.dialog_open(false)
DrawGD.dialog_open(false)
func _on_RemovePaletteWarning_confirmed() -> void:
@ -428,4 +428,4 @@ func _on_RemovePaletteWarning_confirmed() -> void:
func _on_RemovePaletteWarning_popup_hide() -> void:
Global.dialog_open(false)
DrawGD.dialog_open(false)

View File

@ -49,8 +49,8 @@ func _ready() -> void:
add_child(button)
# Load language
if Global.config_cache.has_section_key("preferences", "locale"):
var saved_locale : String = Global.config_cache.get_value("preferences", "locale")
if DrawGD.config_cache.has_section_key("preferences", "locale"):
var saved_locale : String = DrawGD.config_cache.get_value("preferences", "locale")
TranslationServer.set_locale(saved_locale)
# Set the language option menu's default selected option to the loaded locale
@ -74,17 +74,17 @@ func _on_Language_pressed(index : int) -> void:
TranslationServer.set_locale(loaded_locales[index - 1])
if is_cjk(TranslationServer.get_locale()):
Global.control.theme.default_font = preload("res://assets/fonts/CJK/NotoSansCJKtc-Regular.tres")
DrawGD.control.theme.default_font = preload("res://assets/fonts/CJK/NotoSansCJKtc-Regular.tres")
else:
Global.control.theme.default_font = preload("res://assets/fonts/Roboto-Regular.tres")
DrawGD.control.theme.default_font = preload("res://assets/fonts/Roboto-Regular.tres")
Global.config_cache.set_value("preferences", "locale", TranslationServer.get_locale())
Global.config_cache.save("user://cache.ini")
DrawGD.config_cache.set_value("preferences", "locale", TranslationServer.get_locale())
DrawGD.config_cache.save("user://cache.ini")
# Update Translations
Global.update_hint_tooltips()
Global.preferences_dialog._on_PreferencesDialog_popup_hide()
Global.preferences_dialog._on_PreferencesDialog_about_to_show(true)
DrawGD.update_hint_tooltips()
DrawGD.preferences_dialog._on_PreferencesDialog_popup_hide()
DrawGD.preferences_dialog._on_PreferencesDialog_about_to_show(true)
func is_cjk(locale : String) -> bool:

View File

@ -7,8 +7,8 @@ var shortcut_already_assigned = false
var old_input_event : InputEventKey
var new_input_event : InputEventKey
onready var shortcut_selector_popup = Global.preferences_dialog.get_node("Popups/ShortcutSelector")
onready var theme_font_color : Color = Global.preferences_dialog.get_node("Popups/ShortcutSelector/EnteredShortcut").get_color("font_color")
onready var shortcut_selector_popup = DrawGD.preferences_dialog.get_node("Popups/ShortcutSelector")
onready var theme_font_color : Color = DrawGD.preferences_dialog.get_node("Popups/ShortcutSelector/EnteredShortcut").get_color("font_color")
func _ready() -> void:
@ -29,11 +29,11 @@ func _ready() -> void:
# Load custom shortcuts from the config file
custom_shortcuts_preset = default_shortcuts_preset.duplicate()
for action in default_shortcuts_preset:
var saved_input_event = Global.config_cache.get_value("shortcuts", action, 0)
var saved_input_event = DrawGD.config_cache.get_value("shortcuts", action, 0)
if saved_input_event is InputEventKey:
custom_shortcuts_preset[action] = saved_input_event
var shortcuts_preset = Global.config_cache.get_value("shortcuts", "shortcuts_preset", 0)
var shortcuts_preset = DrawGD.config_cache.get_value("shortcuts", "shortcuts_preset", 0)
get_node("HBoxContainer/PresetOptionButton").select(shortcuts_preset)
_on_PresetOptionButton_item_selected(shortcuts_preset)
@ -72,8 +72,8 @@ func _on_PresetOptionButton_item_selected(id : int) -> void:
apply_shortcuts_preset(default_shortcuts_preset)
1:
apply_shortcuts_preset(custom_shortcuts_preset)
Global.config_cache.set_value("shortcuts", "shortcuts_preset", id)
Global.config_cache.save("user://cache.ini")
DrawGD.config_cache.set_value("shortcuts", "shortcuts_preset", id)
DrawGD.config_cache.save("user://cache.ini")
func apply_shortcuts_preset(preset) -> void:
@ -96,10 +96,10 @@ func toggle_shortcut_buttons(enabled : bool) -> void:
func set_action_shortcut(action : String, old_input : InputEventKey, new_input : InputEventKey) -> void:
InputMap.action_erase_event(action, old_input)
InputMap.action_add_event(action, new_input)
Global.update_hint_tooltips()
DrawGD.update_hint_tooltips()
# Set shortcut to switch colors button
if action == "switch_colors":
Global.color_switch_button.shortcut.shortcut = InputMap.get_action_list("switch_colors")[0]
DrawGD.color_switch_button.shortcut.shortcut = InputMap.get_action_list("switch_colors")[0]
func _on_Shortcut_button_pressed(button : Button) -> void:
@ -119,7 +119,7 @@ func _on_ShortcutSelector_confirmed() -> void:
if not shortcut_already_assigned:
set_action_shortcut(action_being_edited, old_input_event, new_input_event)
custom_shortcuts_preset[action_being_edited] = new_input_event
Global.config_cache.set_value("shortcuts", action_being_edited, new_input_event)
Global.config_cache.save("user://cache.ini")
DrawGD.config_cache.set_value("shortcuts", action_being_edited, new_input_event)
DrawGD.config_cache.save("user://cache.ini")
get_node("Shortcuts/" + action_being_edited).text = OS.get_scancode_string(new_input_event.get_scancode_with_modifiers())
shortcut_selector_popup.hide()

View File

@ -1,32 +1,32 @@
extends AcceptDialog
# Preferences table: [Prop name in Global, relative node path, value type, default value]
# Preferences table: [Prop name in DrawGD, relative node path, value type, default value]
var preferences = [
["open_last_project", "Startup/StartupContainer/OpenLastProject", "pressed", Global.open_last_project],
["smooth_zoom", "Canvas/ZoomOptions/SmoothZoom", "pressed", Global.smooth_zoom],
["pressure_sensitivity_mode", "Startup/PressureSentivity/PressureSensitivityOptionButton", "selected", Global.pressure_sensitivity_mode],
["show_left_tool_icon", "Indicators/IndicatorsContainer/LeftToolIconCheckbox", "pressed", Global.show_left_tool_icon],
["show_right_tool_icon", "Indicators/IndicatorsContainer/RightToolIconCheckbox", "pressed", Global.show_right_tool_icon],
["left_square_indicator_visible", "Indicators/IndicatorsContainer/LeftIndicatorCheckbox", "pressed", Global.left_square_indicator_visible],
["right_square_indicator_visible", "Indicators/IndicatorsContainer/RightIndicatorCheckbox", "pressed", Global.right_square_indicator_visible],
["autosave_interval", "Backup/AutosaveContainer/AutosaveInterval", "value", Global.autosave_interval],
["enable_autosave", "Backup/AutosaveContainer/EnableAutosave", "pressed", Global.enable_autosave],
["open_last_project", "Startup/StartupContainer/OpenLastProject", "pressed", DrawGD.open_last_project],
["smooth_zoom", "Canvas/ZoomOptions/SmoothZoom", "pressed", DrawGD.smooth_zoom],
["pressure_sensitivity_mode", "Startup/PressureSentivity/PressureSensitivityOptionButton", "selected", DrawGD.pressure_sensitivity_mode],
["show_left_tool_icon", "Indicators/IndicatorsContainer/LeftToolIconCheckbox", "pressed", DrawGD.show_left_tool_icon],
["show_right_tool_icon", "Indicators/IndicatorsContainer/RightToolIconCheckbox", "pressed", DrawGD.show_right_tool_icon],
["left_square_indicator_visible", "Indicators/IndicatorsContainer/LeftIndicatorCheckbox", "pressed", DrawGD.left_square_indicator_visible],
["right_square_indicator_visible", "Indicators/IndicatorsContainer/RightIndicatorCheckbox", "pressed", DrawGD.right_square_indicator_visible],
["autosave_interval", "Backup/AutosaveContainer/AutosaveInterval", "value", DrawGD.autosave_interval],
["enable_autosave", "Backup/AutosaveContainer/EnableAutosave", "pressed", DrawGD.enable_autosave],
["default_image_width", "Image/ImageOptions/ImageDefaultWidth", "value", Global.default_image_width],
["default_image_height", "Image/ImageOptions/ImageDefaultHeight", "value", Global.default_image_height],
["default_fill_color", "Image/ImageOptions/DefaultFillColor", "color", Global.default_fill_color],
["default_image_width", "Image/ImageOptions/ImageDefaultWidth", "value", DrawGD.default_image_width],
["default_image_height", "Image/ImageOptions/ImageDefaultHeight", "value", DrawGD.default_image_height],
["default_fill_color", "Image/ImageOptions/DefaultFillColor", "color", DrawGD.default_fill_color],
["grid_type", "Canvas/GridOptions/GridType", "selected", Global.grid_type],
["grid_width", "Canvas/GridOptions/GridWidthValue", "value", Global.grid_width],
["grid_height", "Canvas/GridOptions/GridHeightValue", "value", Global.grid_height],
["grid_isometric_cell_size", "Canvas/GridOptions/IsometricCellSizeValue", "value", Global.grid_isometric_cell_size],
["grid_color", "Canvas/GridOptions/GridColor", "color", Global.grid_color],
["guide_color", "Canvas/GuideOptions/GuideColor", "color", Global.guide_color],
["checker_size", "Canvas/CheckerOptions/CheckerSizeValue", "value", Global.checker_size],
["checker_color_1", "Canvas/CheckerOptions/CheckerColor1", "color", Global.checker_color_1],
["checker_color_2", "Canvas/CheckerOptions/CheckerColor2", "color", Global.checker_color_2],
["checker_follow_movement", "Canvas/CheckerOptions/CheckerFollowMovement", "pressed", Global.checker_follow_movement],
["checker_follow_scale", "Canvas/CheckerOptions/CheckerFollowScale", "pressed", Global.checker_follow_scale],
["grid_type", "Canvas/GridOptions/GridType", "selected", DrawGD.grid_type],
["grid_width", "Canvas/GridOptions/GridWidthValue", "value", DrawGD.grid_width],
["grid_height", "Canvas/GridOptions/GridHeightValue", "value", DrawGD.grid_height],
["grid_isometric_cell_size", "Canvas/GridOptions/IsometricCellSizeValue", "value", DrawGD.grid_isometric_cell_size],
["grid_color", "Canvas/GridOptions/GridColor", "color", DrawGD.grid_color],
["guide_color", "Canvas/GuideOptions/GuideColor", "color", DrawGD.guide_color],
["checker_size", "Canvas/CheckerOptions/CheckerSizeValue", "value", DrawGD.checker_size],
["checker_color_1", "Canvas/CheckerOptions/CheckerColor1", "color", DrawGD.checker_color_1],
["checker_color_2", "Canvas/CheckerOptions/CheckerColor2", "color", DrawGD.checker_color_2],
["checker_follow_movement", "Canvas/CheckerOptions/CheckerFollowMovement", "pressed", DrawGD.checker_follow_movement],
["checker_follow_scale", "Canvas/CheckerOptions/CheckerFollowScale", "pressed", DrawGD.checker_follow_scale],
]
var selected_item := 0
@ -44,7 +44,7 @@ func _ready() -> void:
if OS.get_name() == "HTML5":
right_side.get_node("Startup").queue_free()
right_side.get_node("Languages").visible = true
Global.open_last_project = false
DrawGD.open_last_project = false
for pref in preferences:
var node = right_side.get_node(pref[1])
@ -69,70 +69,70 @@ func _ready() -> void:
"selected":
node.connect("item_selected", self, "_on_Preference_item_selected", [pref[0], pref[3], restore_default_button])
if Global.config_cache.has_section_key("preferences", pref[0]):
var value = Global.config_cache.get_value("preferences", pref[0])
Global.set(pref[0], value)
if DrawGD.config_cache.has_section_key("preferences", pref[0]):
var value = DrawGD.config_cache.get_value("preferences", pref[0])
DrawGD.set(pref[0], value)
node.set(pref[2], value)
# This is needed because color_changed doesn't fire if the color changes in code
if pref[2] == "color":
preference_update(pref[0])
disable_restore_default_button(restore_default_button, Global.get(pref[0]).is_equal_approx(pref[3]))
disable_restore_default_button(restore_default_button, DrawGD.get(pref[0]).is_equal_approx(pref[3]))
elif pref[2] == "selected":
preference_update(pref[0])
disable_restore_default_button(restore_default_button, Global.get(pref[0]) == pref[3])
disable_restore_default_button(restore_default_button, DrawGD.get(pref[0]) == pref[3])
func _on_Preference_toggled(button_pressed : bool, prop : String, default_value, restore_default_button : BaseButton) -> void:
Global.set(prop, button_pressed)
Global.config_cache.set_value("preferences", prop, button_pressed)
DrawGD.set(prop, button_pressed)
DrawGD.config_cache.set_value("preferences", prop, button_pressed)
preference_update(prop)
disable_restore_default_button(restore_default_button, Global.get(prop) == default_value)
disable_restore_default_button(restore_default_button, DrawGD.get(prop) == default_value)
func _on_Preference_value_changed(value : float, prop : String, default_value, restore_default_button : BaseButton) -> void:
Global.set(prop, value)
Global.config_cache.set_value("preferences", prop, value)
DrawGD.set(prop, value)
DrawGD.config_cache.set_value("preferences", prop, value)
preference_update(prop)
disable_restore_default_button(restore_default_button, Global.get(prop) == default_value)
disable_restore_default_button(restore_default_button, DrawGD.get(prop) == default_value)
func _on_Preference_color_changed(color : Color, prop : String, default_value, restore_default_button : BaseButton) -> void:
Global.set(prop, color)
Global.config_cache.set_value("preferences", prop, color)
DrawGD.set(prop, color)
DrawGD.config_cache.set_value("preferences", prop, color)
preference_update(prop)
disable_restore_default_button(restore_default_button, Global.get(prop).is_equal_approx(default_value))
disable_restore_default_button(restore_default_button, DrawGD.get(prop).is_equal_approx(default_value))
func _on_Preference_item_selected(id : int, prop : String, default_value, restore_default_button : BaseButton) -> void:
Global.set(prop, id)
Global.config_cache.set_value("preferences", prop, id)
DrawGD.set(prop, id)
DrawGD.config_cache.set_value("preferences", prop, id)
preference_update(prop)
disable_restore_default_button(restore_default_button, Global.get(prop) == default_value)
disable_restore_default_button(restore_default_button, DrawGD.get(prop) == default_value)
func preference_update(prop : String) -> void:
if prop in ["autosave_interval", "enable_autosave"]:
OpenSave.update_autosave()
autosave_interval.editable = Global.enable_autosave
autosave_interval.editable = DrawGD.enable_autosave
if autosave_interval.editable:
autosave_interval.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
else:
autosave_interval.mouse_default_cursor_shape = Control.CURSOR_FORBIDDEN
if prop in ["grid_type", "grid_width", "grid_height", "grid_isometric_cell_size", "grid_color"]:
Global.canvas.grid.isometric_polylines.clear()
Global.canvas.grid.update()
DrawGD.canvas.grid.isometric_polylines.clear()
DrawGD.canvas.grid.update()
if prop in ["checker_size", "checker_color_1", "checker_color_2", "checker_follow_movement", "checker_follow_scale"]:
Global.transparent_checker._ready()
DrawGD.transparent_checker._ready()
if prop in ["guide_color"]:
for guide in Global.canvas.get_children():
for guide in DrawGD.canvas.get_children():
if guide is Guide:
guide.default_color = Global.guide_color
guide.default_color = DrawGD.guide_color
Global.config_cache.save("user://cache.ini")
DrawGD.config_cache.save("user://cache.ini")
func disable_restore_default_button(button : BaseButton, disable : bool) -> void:

View File

@ -9,15 +9,15 @@ var node : Node
func _ready() -> void:
# Handle themes
if Global.theme_type == Global.Theme_Types.LIGHT:
if DrawGD.theme_type == DrawGD.Theme_Types.LIGHT:
texture_normal = load("res://assets/graphics/light_themes/misc/icon_reload.png")
elif Global.theme_type == Global.Theme_Types.CARAMEL:
elif DrawGD.theme_type == DrawGD.Theme_Types.CARAMEL:
texture_normal = load("res://assets/graphics/caramel_themes/misc/icon_reload.png")
func _on_RestoreDefaultButton_pressed() -> void:
Global.set(setting_name, default_value)
Global.config_cache.set_value("preferences", setting_name, default_value)
Global.preferences_dialog.preference_update(setting_name)
Global.preferences_dialog.disable_restore_default_button(self, true)
DrawGD.set(setting_name, default_value)
DrawGD.config_cache.set_value("preferences", setting_name, default_value)
DrawGD.preferences_dialog.preference_update(setting_name)
DrawGD.preferences_dialog.disable_restore_default_button(self, true)
node.set(value_type, default_value)

View File

@ -37,7 +37,7 @@ func set_rect(rect : Rect2) -> void:
polygon[3] = Vector2(rect.position.x, rect.end.y)
visible = not rect.has_no_area()
var project : Project = Global.current_project
var project : Project = DrawGD.current_project
if rect.has_no_area():
project.select_all_pixels()
else:
@ -59,7 +59,7 @@ func move_rect(move : Vector2) -> void:
func select_rect() -> void:
var undo_data = _get_undo_data(false)
Global.current_project.selected_rect = _selected_rect
DrawGD.current_project.selected_rect = _selected_rect
commit_undo("Rectangle Select", undo_data)
@ -68,7 +68,7 @@ func move_start(move_pixel : bool) -> void:
return
_undo_data = _get_undo_data(true)
var project := Global.current_project
var project := DrawGD.current_project
var image : Image = project.frames[project.current_frame].cels[project.current_layer].image
var rect = Rect2(Vector2.ZERO, project.size)
@ -80,7 +80,7 @@ func move_start(move_pixel : bool) -> void:
rect = Rect2(Vector2.ZERO, size)
_clear_image.resize(size.x, size.y, Image.INTERPOLATE_NEAREST)
image.blit_rect(_clear_image, rect, _clipped_rect.position)
Global.canvas.update_texture(project.current_layer)
DrawGD.canvas.update_texture(project.current_layer)
_move_pixel = true
update()
@ -90,7 +90,7 @@ func move_end() -> void:
var undo_data = _undo_data if _move_pixel else _get_undo_data(false)
if _move_pixel:
var project := Global.current_project
var project := DrawGD.current_project
var image : Image = project.frames[project.current_frame].cels[project.current_layer].image
var size := _clipped_rect.size
var rect = Rect2(Vector2.ZERO, size)
@ -98,7 +98,7 @@ func move_end() -> void:
_move_pixel = false
update()
Global.current_project.selected_rect = _selected_rect
DrawGD.current_project.selected_rect = _selected_rect
commit_undo("Rectangle Select", undo_data)
_undo_data.clear()
@ -107,7 +107,7 @@ func copy() -> void:
if _selected_rect.has_no_area():
return
var project := Global.current_project
var project := DrawGD.current_project
var image : Image = project.frames[project.current_frame].cels[project.current_layer].image
_clipboard = image.get_rect(_selected_rect)
if _clipboard.is_invisible():
@ -121,7 +121,7 @@ func cut() -> void: # This is basically the same as copy + delete
return
var undo_data = _get_undo_data(true)
var project := Global.current_project
var project := DrawGD.current_project
var image : Image = project.frames[project.current_frame].cels[project.current_layer].image
var size := _selected_rect.size
var rect = Rect2(Vector2.ZERO, size)
@ -142,7 +142,7 @@ func paste() -> void:
return
var undo_data = _get_undo_data(true)
var project := Global.current_project
var project := DrawGD.current_project
var image : Image = project.frames[project.current_frame].cels[project.current_layer].image
var size := _selected_rect.size
var rect = Rect2(Vector2.ZERO, size)
@ -153,7 +153,7 @@ func paste() -> void:
func delete() -> void:
var undo_data = _get_undo_data(true)
var project := Global.current_project
var project := DrawGD.current_project
var image : Image = project.frames[project.current_frame].cels[project.current_layer].image
var size := _selected_rect.size
var rect = Rect2(Vector2.ZERO, size)
@ -165,7 +165,7 @@ func delete() -> void:
func commit_undo(action : String, undo_data : Dictionary) -> void:
var redo_data = _get_undo_data("image_data" in undo_data)
var project := Global.current_project
var project := DrawGD.current_project
project.undos += 1
project.undo_redo.create_action(action)
@ -175,15 +175,15 @@ func commit_undo(action : String, undo_data : Dictionary) -> void:
var image : Image = project.frames[project.current_frame].cels[project.current_layer].image
project.undo_redo.add_do_property(image, "data", redo_data["image_data"])
project.undo_redo.add_undo_property(image, "data", undo_data["image_data"])
project.undo_redo.add_do_method(Global, "redo", project.current_frame, project.current_layer)
project.undo_redo.add_undo_method(Global, "undo", project.current_frame, project.current_layer)
project.undo_redo.add_do_method(DrawGD, "redo", project.current_frame, project.current_layer)
project.undo_redo.add_undo_method(DrawGD, "undo", project.current_frame, project.current_layer)
project.undo_redo.commit_action()
func _get_undo_data(undo_image : bool) -> Dictionary:
var data = {}
var project := Global.current_project
data["selected_rect"] = Global.current_project.selected_rect
var project := DrawGD.current_project
data["selected_rect"] = DrawGD.current_project.selected_rect
if undo_image:
var image : Image = project.frames[project.current_frame].cels[project.current_layer].image
image.unlock()

View File

@ -27,30 +27,30 @@ func _on_PixelPerfect_toggled(button_pressed : bool):
func _on_Horizontal_toggled(button_pressed : bool):
tool_slot.horizontal_mirror = button_pressed
tool_slot.save_config()
Global.show_y_symmetry_axis = button_pressed
DrawGD.show_y_symmetry_axis = button_pressed
# If the button is not pressed but another button is, keep the symmetry guide visible
if !button_pressed and (Tools._slots[BUTTON_LEFT].horizontal_mirror or Tools._slots[BUTTON_RIGHT].horizontal_mirror):
Global.show_y_symmetry_axis = true
Global.current_project.y_symmetry_axis.visible = Global.show_y_symmetry_axis and Global.show_guides
DrawGD.show_y_symmetry_axis = true
DrawGD.current_project.y_symmetry_axis.visible = DrawGD.show_y_symmetry_axis and DrawGD.show_guides
func _on_Vertical_toggled(button_pressed : bool):
tool_slot.vertical_mirror = button_pressed
tool_slot.save_config()
Global.show_x_symmetry_axis = button_pressed
DrawGD.show_x_symmetry_axis = button_pressed
# If the button is not pressed but another button is, keep the symmetry guide visible
if !button_pressed and (Tools._slots[BUTTON_LEFT].vertical_mirror or Tools._slots[BUTTON_RIGHT].vertical_mirror):
Global.show_x_symmetry_axis = true
Global.current_project.x_symmetry_axis.visible = Global.show_x_symmetry_axis and Global.show_guides
DrawGD.show_x_symmetry_axis = true
DrawGD.current_project.x_symmetry_axis.visible = DrawGD.show_x_symmetry_axis and DrawGD.show_guides
func save_config() -> void:
var config := get_config()
Global.config_cache.set_value(tool_slot.kname, kname, config)
DrawGD.config_cache.set_value(tool_slot.kname, kname, config)
func load_config() -> void:
var value = Global.config_cache.get_value(tool_slot.kname, kname, {})
var value = DrawGD.config_cache.get_value(tool_slot.kname, kname, {})
set_config(value)
update_config()
@ -73,20 +73,20 @@ func cursor_move(position : Vector2) -> void:
func draw_indicator() -> void:
var rect := Rect2(_cursor, Vector2.ONE)
Global.canvas.indicators.draw_rect(rect, Color.blue, false)
DrawGD.canvas.indicators.draw_rect(rect, Color.blue, false)
func _get_draw_rect() -> Rect2:
var selected_pixels = Global.current_project.selected_pixels
var selected_pixels = DrawGD.current_project.selected_pixels
return Rect2(selected_pixels[0].x, selected_pixels[0].y, selected_pixels[-1].x - selected_pixels[0].x + 1, selected_pixels[-1].y - selected_pixels[0].y + 1)
func _get_tile_mode_rect() -> Rect2:
return Rect2(-Global.current_project.size, Global.current_project.size * 3)
return Rect2(-DrawGD.current_project.size, DrawGD.current_project.size * 3)
func _get_draw_image() -> Image:
var project : Project = Global.current_project
var project : Project = DrawGD.current_project
return project.frames[project.current_frame].cels[project.current_layer].image

View File

@ -25,8 +25,8 @@ func _on_FillWithOptions_item_selected(index : int) -> void:
func _on_PatternType_pressed():
Global.patterns_popup.connect("pattern_selected", self, "_on_Pattern_selected", [], CONNECT_ONESHOT)
Global.patterns_popup.popup(Rect2($FillPattern/Type.rect_global_position, Vector2(226, 72)))
DrawGD.patterns_popup.connect("pattern_selected", self, "_on_Pattern_selected", [], CONNECT_ONESHOT)
DrawGD.patterns_popup.popup(Rect2($FillPattern/Type.rect_global_position, Vector2(226, 72)))
func _on_Pattern_selected(pattern : Patterns.Pattern) -> void:
@ -62,7 +62,7 @@ func get_config() -> Dictionary:
func set_config(config : Dictionary) -> void:
if _pattern:
var index = config.get("pattern_index", _pattern.index)
_pattern = Global.patterns_popup.get_pattern(index)
_pattern = DrawGD.patterns_popup.get_pattern(index)
_fill_area = config.get("fill_area", _fill_area)
_fill_with = config.get("fill_with", _fill_with)
_offset_x = config.get("offset_x", _offset_x)
@ -81,10 +81,10 @@ func update_config() -> void:
func update_pattern() -> void:
if _pattern == null:
if Global.patterns_popup.default_pattern == null:
if DrawGD.patterns_popup.default_pattern == null:
return
else:
_pattern = Global.patterns_popup.default_pattern
_pattern = DrawGD.patterns_popup.default_pattern
var tex := ImageTexture.new()
tex.create_from_image(_pattern.image, 0)
$FillPattern/Type/Texture.texture = tex
@ -94,7 +94,7 @@ func update_pattern() -> void:
func draw_start(position : Vector2) -> void:
if not position in Global.current_project.selected_pixels or Global.current_project.layers[Global.current_project.current_layer].locked:
if not position in DrawGD.current_project.selected_pixels or DrawGD.current_project.layers[DrawGD.current_project.current_layer].locked:
return
var undo_data = _get_undo_data()
if _fill_area == 0:
@ -113,7 +113,7 @@ func draw_end(_position : Vector2) -> void:
func fill_in_color(position : Vector2) -> void:
var project : Project = Global.current_project
var project : Project = DrawGD.current_project
var image := _get_draw_image()
var color := image.get_pixelv(position)
if _fill_with == 0 or _pattern == null:
@ -127,7 +127,7 @@ func fill_in_color(position : Vector2) -> void:
func fill_in_area(position : Vector2) -> void:
var project : Project = Global.current_project
var project : Project = DrawGD.current_project
_flood_fill(position)
# Handle Mirroring
@ -158,7 +158,7 @@ func fill_in_area(position : Vector2) -> void:
func _flood_fill(position : Vector2) -> void:
var project : Project = Global.current_project
var project : Project = DrawGD.current_project
var image := _get_draw_image()
var color := image.get_pixelv(position)
if _fill_with == 0 or _pattern == null:
@ -191,7 +191,7 @@ func _flood_fill(position : Vector2) -> void:
func _set_pixel(image : Image, x : int, y : int, color : Color) -> void:
var project : Project = Global.current_project
var project : Project = DrawGD.current_project
var entire_image_selected : bool = project.selected_pixels.size() == project.size.x * project.size.y
if entire_image_selected:
if not _get_draw_rect().has_point(Vector2(x, y)):
@ -213,21 +213,21 @@ func _set_pixel(image : Image, x : int, y : int, color : Color) -> void:
func commit_undo(action : String, undo_data : Dictionary) -> void:
var redo_data = _get_undo_data()
var project : Project = Global.current_project
var project : Project = DrawGD.current_project
var image : Image = project.frames[project.current_frame].cels[project.current_layer].image
project.undos += 1
project.undo_redo.create_action(action)
project.undo_redo.add_do_property(image, "data", redo_data["image_data"])
project.undo_redo.add_undo_property(image, "data", undo_data["image_data"])
project.undo_redo.add_do_method(Global, "redo", project.current_frame, project.current_layer)
project.undo_redo.add_undo_method(Global, "undo", project.current_frame, project.current_layer)
project.undo_redo.add_do_method(DrawGD, "redo", project.current_frame, project.current_layer)
project.undo_redo.add_undo_method(DrawGD, "undo", project.current_frame, project.current_layer)
project.undo_redo.commit_action()
func _get_undo_data() -> Dictionary:
var data = {}
var project : Project = Global.current_project
var project : Project = DrawGD.current_project
var image : Image = project.frames[project.current_frame].cels[project.current_layer].image
image.unlock()
data["image_data"] = image.data

View File

@ -23,13 +23,13 @@ var _line_polylines := []
func _ready() -> void:
Tools.connect("color_changed", self, "_on_Color_changed")
Global.brushes_popup.connect("brush_removed", self, "_on_Brush_removed")
DrawGD.brushes_popup.connect("brush_removed", self, "_on_Brush_removed")
func _on_BrushType_pressed() -> void:
if not Global.brushes_popup.is_connected("brush_selected", self, "_on_Brush_selected"):
Global.brushes_popup.connect("brush_selected", self, "_on_Brush_selected", [], CONNECT_ONESHOT)
Global.brushes_popup.popup(Rect2($Brush/Type.rect_global_position, Vector2(226, 72)))
if not DrawGD.brushes_popup.is_connected("brush_selected", self, "_on_Brush_selected"):
DrawGD.brushes_popup.connect("brush_selected", self, "_on_Brush_selected", [], CONNECT_ONESHOT)
DrawGD.brushes_popup.popup(Rect2($Brush/Type.rect_global_position, Vector2(226, 72)))
func _on_Brush_selected(brush : Brushes.Brush) -> void:
@ -73,7 +73,7 @@ func get_config() -> Dictionary:
func set_config(config : Dictionary) -> void:
var type = config.get("brush_type", _brush.type)
var index = config.get("brush_index", _brush.index)
_brush = Global.brushes_popup.get_brush(type, index)
_brush = DrawGD.brushes_popup.get_brush(type, index)
_brush_size = config.get("brush_size", _brush_size)
_brush_interpolate = config.get("brush_interpolate", _brush_interpolate)
@ -143,7 +143,7 @@ func update_line_polylines(start : Vector2, end : Vector2) -> void:
func restore_image() -> void:
var project : Project = Global.current_project
var project : Project = DrawGD.current_project
var image = project.frames[project.current_frame].cels[project.current_layer].image
image.unlock()
image.data = _undo_data[image]
@ -156,10 +156,10 @@ func prepare_undo() -> void:
func commit_undo(action : String) -> void:
var redo_data = _get_undo_data()
var project : Project = Global.current_project
var project : Project = DrawGD.current_project
var frame := -1
var layer := -1
if Global.animation_timer.is_stopped():
if DrawGD.animation_timer.is_stopped():
frame = project.current_frame
layer = project.current_layer
@ -169,18 +169,18 @@ func commit_undo(action : String) -> void:
project.undo_redo.add_do_property(image, "data", redo_data[image])
for image in _undo_data:
project.undo_redo.add_undo_property(image, "data", _undo_data[image])
project.undo_redo.add_do_method(Global, "redo", frame, layer)
project.undo_redo.add_undo_method(Global, "undo", frame, layer)
project.undo_redo.add_do_method(DrawGD, "redo", frame, layer)
project.undo_redo.add_undo_method(DrawGD, "undo", frame, layer)
project.undo_redo.commit_action()
_undo_data.clear()
func draw_tool(position : Vector2) -> void:
if Global.current_project.layers[Global.current_project.current_layer].locked:
if DrawGD.current_project.layers[DrawGD.current_project.current_layer].locked:
return
var strength := _strength
if Global.pressure_sensitivity_mode == Global.Pressure_Sensitivity.ALPHA:
if DrawGD.pressure_sensitivity_mode == DrawGD.Pressure_Sensitivity.ALPHA:
strength *= Tools.pen_pressure
_drawer.pixel_perfect = tool_slot.pixel_perfect if _brush_size == 1 else false
@ -257,8 +257,8 @@ func draw_tool_circle(position : Vector2, fill := false) -> void:
func draw_tool_brush(position : Vector2) -> void:
if Global.tile_mode and _get_tile_mode_rect().has_point(position):
position = position.posmodv(Global.current_project.size)
if DrawGD.tile_mode and _get_tile_mode_rect().has_point(position):
position = position.posmodv(DrawGD.current_project.size)
var size := _brush_image.get_size()
var dst := position - (size / 2).floor()
@ -270,7 +270,7 @@ func draw_tool_brush(position : Vector2) -> void:
var src_rect := Rect2(dst_rect.position - dst, dst_rect.size)
dst = dst_rect.position
var project : Project = Global.current_project
var project : Project = DrawGD.current_project
_draw_brush_image(_brush_image, src_rect, dst)
# Handle Mirroring
@ -302,15 +302,15 @@ func draw_tool_brush(position : Vector2) -> void:
func draw_indicator() -> void:
draw_indicator_at(_cursor, Vector2.ZERO, Color.blue)
if Global.tile_mode and _get_tile_mode_rect().has_point(_cursor):
if DrawGD.tile_mode and _get_tile_mode_rect().has_point(_cursor):
var tile := _line_start if _draw_line else _cursor
if not tile in Global.current_project.selected_pixels:
var offset := tile - tile.posmodv(Global.current_project.size)
if not tile in DrawGD.current_project.selected_pixels:
var offset := tile - tile.posmodv(DrawGD.current_project.size)
draw_indicator_at(_cursor, offset, Color.green)
func draw_indicator_at(position : Vector2, offset : Vector2, color : Color) -> void:
var canvas = Global.canvas.indicators
var canvas = DrawGD.canvas.indicators
if _brush.type in [Brushes.FILE, Brushes.RANDOM_FILE, Brushes.CUSTOM] and not _draw_line:
position -= (_brush_image.get_size() / 2).floor()
position -= offset
@ -330,8 +330,8 @@ func draw_indicator_at(position : Vector2, offset : Vector2, color : Color) -> v
func _set_pixel(position : Vector2) -> void:
var project : Project = Global.current_project
if Global.tile_mode and _get_tile_mode_rect().has_point(position):
var project : Project = DrawGD.current_project
if DrawGD.tile_mode and _get_tile_mode_rect().has_point(position):
position = position.posmodv(project.size)
var entire_image_selected : bool = project.selected_pixels.size() == project.size.x * project.size.y
@ -508,9 +508,9 @@ func _line_angle_constraint(start : Vector2, end : Vector2) -> Dictionary:
func _get_undo_data() -> Dictionary:
var data = {}
var project : Project = Global.current_project
var project : Project = DrawGD.current_project
var frames := project.frames
if Global.animation_timer.is_stopped():
if DrawGD.animation_timer.is_stopped():
frames = [project.frames[project.current_frame]]
for frame in frames:
var image : Image = frame.cels[project.current_layer].image

View File

@ -39,7 +39,7 @@ func draw_start(position : Vector2) -> void:
else:
draw_tool(position)
_last_position = position
Global.canvas.sprite_changed_this_frame = true
DrawGD.canvas.sprite_changed_this_frame = true
cursor_text = ""
@ -53,7 +53,7 @@ func draw_move(position : Vector2) -> void:
draw_fill_gap(_last_position, position)
_last_position = position
cursor_text = ""
Global.canvas.sprite_changed_this_frame = true
DrawGD.canvas.sprite_changed_this_frame = true
func draw_end(_position : Vector2) -> void:

View File

@ -79,7 +79,7 @@ func draw_start(position : Vector2) -> void:
else:
draw_tool(position)
_last_position = position
Global.canvas.sprite_changed_this_frame = true
DrawGD.canvas.sprite_changed_this_frame = true
cursor_text = ""
@ -93,7 +93,7 @@ func draw_move(position : Vector2) -> void:
draw_fill_gap(_last_position, position)
_last_position = position
cursor_text = ""
Global.canvas.sprite_changed_this_frame = true
DrawGD.canvas.sprite_changed_this_frame = true
func draw_end(_position : Vector2) -> void:

View File

@ -62,7 +62,7 @@ func draw_start(position : Vector2) -> void:
else:
draw_tool(position)
_last_position = position
Global.canvas.sprite_changed_this_frame = true
DrawGD.canvas.sprite_changed_this_frame = true
cursor_text = ""
@ -76,7 +76,7 @@ func draw_move(position : Vector2) -> void:
draw_fill_gap(_last_position, position)
_last_position = position
cursor_text = ""
Global.canvas.sprite_changed_this_frame = true
DrawGD.canvas.sprite_changed_this_frame = true
func draw_end(_position : Vector2) -> void:

View File

@ -8,34 +8,34 @@ var _move := false
func draw_start(position : Vector2) -> void:
if Global.selection_rectangle.has_point(position):
if DrawGD.selection_rectangle.has_point(position):
_move = true
_offset = position
Global.selection_rectangle.move_start(Tools.shift)
_set_cursor_text(Global.selection_rectangle.get_rect())
DrawGD.selection_rectangle.move_start(Tools.shift)
_set_cursor_text(DrawGD.selection_rectangle.get_rect())
else:
_drag = true
_start = Rect2(position, Vector2.ZERO)
Global.selection_rectangle.set_rect(_start)
DrawGD.selection_rectangle.set_rect(_start)
func draw_move(position : Vector2) -> void:
if _move:
Global.selection_rectangle.move_rect(position - _offset)
DrawGD.selection_rectangle.move_rect(position - _offset)
_offset = position
_set_cursor_text(Global.selection_rectangle.get_rect())
_set_cursor_text(DrawGD.selection_rectangle.get_rect())
else:
var rect := _start.expand(position).abs()
rect = rect.grow_individual(0, 0, 1, 1)
Global.selection_rectangle.set_rect(rect)
DrawGD.selection_rectangle.set_rect(rect)
_set_cursor_text(rect)
func draw_end(_position : Vector2) -> void:
if _move:
Global.selection_rectangle.move_end()
DrawGD.selection_rectangle.move_end()
else:
Global.selection_rectangle.select_rect()
DrawGD.selection_rectangle.select_rect()
_drag = false
_move = false
cursor_text = ""
@ -44,13 +44,13 @@ func draw_end(_position : Vector2) -> void:
func cursor_move(position : Vector2) -> void:
if _drag:
_cursor = Vector2.INF
elif Global.selection_rectangle.has_point(position):
elif DrawGD.selection_rectangle.has_point(position):
_cursor = Vector2.INF
Global.main_viewport.mouse_default_cursor_shape = Input.CURSOR_MOVE
DrawGD.main_viewport.mouse_default_cursor_shape = Input.CURSOR_MOVE
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
else:
_cursor = position
Global.main_viewport.mouse_default_cursor_shape = Input.CURSOR_CROSS
DrawGD.main_viewport.mouse_default_cursor_shape = Input.CURSOR_CROSS
func _set_cursor_text(rect : Rect2) -> void:

View File

@ -11,11 +11,11 @@ func _on_ModeOptions_item_selected(id):
func _on_FitToFrame_pressed():
Global.camera.fit_to_frame(Global.current_project.size)
DrawGD.camera.fit_to_frame(DrawGD.current_project.size)
func _on_100_pressed():
Global.camera.zoom_100()
DrawGD.camera.zoom_100()
func get_config() -> Dictionary:
@ -33,7 +33,7 @@ func update_config() -> void:
func draw_start(_position : Vector2) -> void:
Global.camera.zoom_camera(_zoom_mode * 2 - 1)
DrawGD.camera.zoom_camera(_zoom_mode * 2 - 1)
func draw_move(_position : Vector2) -> void:

View File

@ -9,14 +9,14 @@ func _on_BrushButton_pressed() -> void:
if Input.is_action_just_released("middle_mouse"):
_on_DeleteButton_pressed()
else:
Global.brushes_popup.select_brush(brush)
DrawGD.brushes_popup.select_brush(brush)
func _on_DeleteButton_pressed() -> void:
if brush.type != Brushes.CUSTOM:
return
Global.brushes_popup.remove_brush(self)
DrawGD.brushes_popup.remove_brush(self)
func _on_BrushButton_mouse_entered() -> void:

View File

@ -19,7 +19,7 @@ var circle_filled_image = preload("res://assets/graphics/circle_filled_9x9.png")
func _ready() -> void:
var container = Global.brushes_popup.get_node("TabContainer/File/FileBrushContainer")
var container = DrawGD.brushes_popup.get_node("TabContainer/File/FileBrushContainer")
var button = create_button(pixel_image)
button.brush.type = PIXEL
button.hint_tooltip = "Pixel brush"
@ -66,7 +66,7 @@ static func add_file_brush(images : Array, hint := "") -> void:
button.brush.image = images[0]
button.brush.random = images
button.hint_tooltip = hint
var container = Global.brushes_popup.get_node("TabContainer/File/FileBrushContainer")
var container = DrawGD.brushes_popup.get_node("TabContainer/File/FileBrushContainer")
container.add_child(button)
button.brush.index = button.get_index()
@ -76,24 +76,24 @@ static func add_project_brush(image : Image, hint := "") -> void:
button.brush.type = CUSTOM
button.brush.image = image
button.hint_tooltip = hint
var container = Global.brushes_popup.get_node("TabContainer/Project/ProjectBrushContainer")
var container = DrawGD.brushes_popup.get_node("TabContainer/Project/ProjectBrushContainer")
container.add_child(button)
button.brush.index = button.get_index()
static func clear_project_brush() -> void:
var container = Global.brushes_popup.get_node("TabContainer/Project/ProjectBrushContainer")
var container = DrawGD.brushes_popup.get_node("TabContainer/Project/ProjectBrushContainer")
for child in container.get_children():
child.queue_free()
Global.brushes_popup.emit_signal("brush_removed", child.brush)
DrawGD.brushes_popup.emit_signal("brush_removed", child.brush)
func get_brush(type : int, index : int) -> Brush:
var container
if type == CUSTOM:
container = Global.brushes_popup.get_node("TabContainer/Project/ProjectBrushContainer")
container = DrawGD.brushes_popup.get_node("TabContainer/Project/ProjectBrushContainer")
else:
container = Global.brushes_popup.get_node("TabContainer/File/FileBrushContainer")
container = DrawGD.brushes_popup.get_node("TabContainer/File/FileBrushContainer")
var brush = get_default_brush()
if index < container.get_child_count():
brush = container.get_child(index).brush
@ -103,7 +103,7 @@ func get_brush(type : int, index : int) -> Brush:
func remove_brush(brush_button : Node) -> void:
emit_signal("brush_removed", brush_button.brush)
var project = Global.current_project
var project = DrawGD.current_project
var undo_brushes = project.brushes.duplicate()
project.brushes.erase(brush_button.brush.image)
@ -118,8 +118,8 @@ func remove_brush(brush_button : Node) -> void:
func undo_custom_brush(brush_button : BaseButton = null) -> void:
Global.general_undo()
var action_name : String = Global.current_project.undo_redo.get_current_action_name()
DrawGD.general_undo()
var action_name : String = DrawGD.current_project.undo_redo.get_current_action_name()
if action_name == "Delete Custom Brush":
$TabContainer/Project/ProjectBrushContainer.add_child(brush_button)
$TabContainer/Project/ProjectBrushContainer.move_child(brush_button, brush_button.brush.index)
@ -127,7 +127,7 @@ func undo_custom_brush(brush_button : BaseButton = null) -> void:
func redo_custom_brush(brush_button : BaseButton = null) -> void:
Global.general_redo()
var action_name : String = Global.current_project.undo_redo.get_current_action_name()
DrawGD.general_redo()
var action_name : String = DrawGD.current_project.undo_redo.get_current_action_name()
if action_name == "Delete Custom Brush":
$TabContainer/Project/ProjectBrushContainer.remove_child(brush_button)

View File

@ -31,19 +31,19 @@ func dir_move_zoom_multiplier(press_time : float) -> float:
if press_time < 0:
return 0.0
if Input.is_key_pressed(KEY_SHIFT) and Input.is_key_pressed(KEY_CONTROL) :
return Global.high_speed_move_rate
return DrawGD.high_speed_move_rate
elif Input.is_key_pressed(KEY_SHIFT):
return Global.medium_speed_move_rate
return DrawGD.medium_speed_move_rate
elif !Input.is_key_pressed(KEY_CONTROL):
# control + right/left is used to move frames so
# we do this check to ensure that there is no conflict
return Global.low_speed_move_rate
return DrawGD.low_speed_move_rate
else:
return 0.0
func reset_dir_move_time(direction) -> void:
Global.key_move_press_time[direction] = 0.0
DrawGD.key_move_press_time[direction] = 0.0
const key_move_action_names := ["ui_up", "ui_down", "ui_left", "ui_right"]
@ -68,18 +68,18 @@ func is_action_direction_released(event: InputEvent) -> bool:
# if not a direction event return null
func get_action_direction(event: InputEvent): # -> Optional[Direction]
if event.is_action("ui_up"):
return Global.Direction.UP
return DrawGD.Direction.UP
elif event.is_action("ui_down"):
return Global.Direction.DOWN
return DrawGD.Direction.DOWN
elif event.is_action("ui_left"):
return Global.Direction.LEFT
return DrawGD.Direction.LEFT
elif event.is_action("ui_right"):
return Global.Direction.RIGHT
return DrawGD.Direction.RIGHT
return null
# Holds sign multipliers for the given directions nyaa
# (per the indices in Global.gd defined by Direction)
# (per the indices in DrawGD.gd defined by Direction)
# UP, DOWN, LEFT, RIGHT in that order
const directional_sign_multipliers := [
Vector2(0.0, -1.0),
@ -97,8 +97,8 @@ func process_direction_action_pressed(event: InputEvent) -> void:
return
var increment := get_process_delta_time()
# Count the total time we've been doing this ^.^
Global.key_move_press_time[dir] += increment
var this_direction_press_time : float = Global.key_move_press_time[dir]
DrawGD.key_move_press_time[dir] += increment
var this_direction_press_time : float = DrawGD.key_move_press_time[dir]
var move_speed := dir_move_zoom_multiplier(this_direction_press_time)
offset = offset + move_speed * increment * directional_sign_multipliers[dir] * zoom
update_rulers()
@ -121,7 +121,7 @@ func _input(event : InputEvent) -> void:
elif event.is_action_released("middle_mouse") || event.is_action_released("space"):
drag = false
if Global.can_draw && Rect2(Vector2.ZERO, viewport_size).has_point(mouse_pos):
if DrawGD.can_draw && Rect2(Vector2.ZERO, viewport_size).has_point(mouse_pos):
if event.is_action_pressed("zoom_in"): # Wheel Up Event
zoom_camera(-1)
elif event.is_action_pressed("zoom_out"): # Wheel Down Event
@ -141,7 +141,7 @@ func _input(event : InputEvent) -> void:
# Zoom Camera
func zoom_camera(dir : int) -> void:
var viewport_size := viewport_container.rect_size
if Global.smooth_zoom:
if DrawGD.smooth_zoom:
var zoom_margin = zoom * dir / 5
var new_zoom = zoom + zoom_margin
if new_zoom > zoom_min && new_zoom < zoom_max:
@ -166,17 +166,17 @@ func zoom_camera(dir : int) -> void:
func zoom_changed() -> void:
update_transparent_checker_offset()
if name == "Camera2D":
Global.zoom_level_label.text = str(round(100 / zoom.x)) + " %"
DrawGD.zoom_level_label.text = str(round(100 / zoom.x)) + " %"
update_rulers()
for guide in Global.current_project.guides:
for guide in DrawGD.current_project.guides:
guide.width = zoom.x * 2
elif name == "CameraPreview":
Global.preview_zoom_slider.value = -zoom.x
DrawGD.preview_zoom_slider.value = -zoom.x
func update_rulers() -> void:
Global.horizontal_ruler.update()
Global.vertical_ruler.update()
DrawGD.horizontal_ruler.update()
DrawGD.vertical_ruler.update()
func _on_tween_step(_object: Object, _key: NodePath, _elapsed: float, _value: Object) -> void:
@ -185,7 +185,7 @@ func _on_tween_step(_object: Object, _key: NodePath, _elapsed: float, _value: Ob
func zoom_100() -> void:
zoom = Vector2.ONE
offset = Global.current_project.size / 2
offset = DrawGD.current_project.size / 2
zoom_changed()
@ -199,12 +199,12 @@ func fit_to_frame(size : Vector2) -> void:
# If the ratio is 0, it means that the viewport container is hidden
# in that case, use the other viewport to get the ratio
if name == "Camera2D":
h_ratio = Global.second_viewport.rect_size.x / size.x
v_ratio = Global.second_viewport.rect_size.y / size.y
h_ratio = DrawGD.second_viewport.rect_size.x / size.x
v_ratio = DrawGD.second_viewport.rect_size.y / size.y
ratio = min(h_ratio, v_ratio)
elif name == "Camera2D2":
h_ratio = Global.main_viewport.rect_size.x / size.x
v_ratio = Global.main_viewport.rect_size.y / size.y
h_ratio = DrawGD.main_viewport.rect_size.x / size.x
v_ratio = DrawGD.main_viewport.rect_size.y / size.y
ratio = min(h_ratio, v_ratio)
zoom = Vector2(1 / ratio, 1 / ratio)
@ -214,11 +214,11 @@ func fit_to_frame(size : Vector2) -> void:
func save_values_to_project() -> void:
if name == "Camera2D":
Global.current_project.cameras_zoom[0] = zoom
Global.current_project.cameras_offset[0] = offset
DrawGD.current_project.cameras_zoom[0] = zoom
DrawGD.current_project.cameras_offset[0] = offset
elif name == "Camera2D2":
Global.current_project.cameras_zoom[1] = zoom
Global.current_project.cameras_offset[1] = offset
DrawGD.current_project.cameras_zoom[1] = zoom
DrawGD.current_project.cameras_offset[1] = offset
elif name == "CameraPreview":
Global.current_project.cameras_zoom[2] = zoom
Global.current_project.cameras_offset[2] = offset
DrawGD.current_project.cameras_zoom[2] = zoom
DrawGD.current_project.cameras_offset[2] = offset

View File

@ -17,23 +17,23 @@ onready var indicators = $Indicators
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
var frame : Frame = new_empty_frame(true)
Global.current_project.frames.append(frame)
DrawGD.current_project.frames.append(frame)
yield(get_tree().create_timer(0.2), "timeout")
camera_zoom()
func _draw() -> void:
Global.second_viewport.get_child(0).get_node("CanvasPreview").update()
Global.small_preview_viewport.get_child(0).get_node("CanvasPreview").update()
DrawGD.second_viewport.get_child(0).get_node("CanvasPreview").update()
DrawGD.small_preview_viewport.get_child(0).get_node("CanvasPreview").update()
var current_cels : Array = Global.current_project.frames[Global.current_project.current_frame].cels
if Global.onion_skinning:
var current_cels : Array = DrawGD.current_project.frames[DrawGD.current_project.current_frame].cels
if DrawGD.onion_skinning:
onion_skinning()
# Draw current frame layers
for i in range(Global.current_project.layers.size()):
for i in range(DrawGD.current_project.layers.size()):
var modulate_color := Color(1, 1, 1, current_cels[i].opacity)
if Global.current_project.layers[i].visible: # if it's visible
if DrawGD.current_project.layers[i].visible: # if it's visible
draw_texture(current_cels[i].image_texture, location, modulate_color)
tile_mode.update()
@ -52,25 +52,25 @@ func _input(event : InputEvent) -> void:
current_pixel = get_local_mouse_position() + location
if Global.has_focus:
if DrawGD.has_focus:
update()
sprite_changed_this_frame = false
var current_project : Project = Global.current_project
var current_project : Project = DrawGD.current_project
if Global.has_focus:
if DrawGD.has_focus:
if !cursor_image_has_changed:
cursor_image_has_changed = true
if Global.show_left_tool_icon:
Global.left_cursor.visible = true
if Global.show_right_tool_icon:
Global.right_cursor.visible = true
if DrawGD.show_left_tool_icon:
DrawGD.left_cursor.visible = true
if DrawGD.show_right_tool_icon:
DrawGD.right_cursor.visible = true
else:
if cursor_image_has_changed:
cursor_image_has_changed = false
Global.left_cursor.visible = false
Global.right_cursor.visible = false
DrawGD.left_cursor.visible = false
DrawGD.right_cursor.visible = false
Tools.handle_draw(current_pixel.floor(), event)
@ -80,37 +80,37 @@ func _input(event : InputEvent) -> void:
func camera_zoom() -> void:
# Set camera zoom based on the sprite size
var bigger_canvas_axis = max(Global.current_project.size.x, Global.current_project.size.y)
var bigger_canvas_axis = max(DrawGD.current_project.size.x, DrawGD.current_project.size.y)
var zoom_max := Vector2(bigger_canvas_axis, bigger_canvas_axis) * 0.01
var cameras = [Global.camera, Global.camera2, Global.camera_preview]
var cameras = [DrawGD.camera, DrawGD.camera2, DrawGD.camera_preview]
for camera in cameras:
if zoom_max > Vector2.ONE:
camera.zoom_max = zoom_max
else:
camera.zoom_max = Vector2.ONE
if camera == Global.camera_preview:
Global.preview_zoom_slider.max_value = -camera.zoom_min.x
Global.preview_zoom_slider.min_value = -camera.zoom_max.x
if camera == DrawGD.camera_preview:
DrawGD.preview_zoom_slider.max_value = -camera.zoom_min.x
DrawGD.preview_zoom_slider.min_value = -camera.zoom_max.x
camera.fit_to_frame(Global.current_project.size)
camera.fit_to_frame(DrawGD.current_project.size)
camera.save_values_to_project()
Global.transparent_checker._ready() # To update the rect size
DrawGD.transparent_checker._ready() # To update the rect size
func new_empty_frame(first_time := false, single_layer := false, size := Global.current_project.size) -> Frame:
func new_empty_frame(first_time := false, single_layer := false, size := DrawGD.current_project.size) -> Frame:
var frame := Frame.new()
for l in Global.current_project.layers: # Create as many cels as there are layers
for l in DrawGD.current_project.layers: # Create as many cels as there are layers
# The sprite itself
var sprite := Image.new()
if first_time:
if Global.config_cache.has_section_key("preferences", "default_image_width"):
Global.current_project.size.x = Global.config_cache.get_value("preferences", "default_image_width")
if Global.config_cache.has_section_key("preferences", "default_image_height"):
Global.current_project.size.y = Global.config_cache.get_value("preferences", "default_image_height")
if Global.config_cache.has_section_key("preferences", "default_fill_color"):
fill_color = Global.config_cache.get_value("preferences", "default_fill_color")
if DrawGD.config_cache.has_section_key("preferences", "default_image_width"):
DrawGD.current_project.size.x = DrawGD.config_cache.get_value("preferences", "default_image_width")
if DrawGD.config_cache.has_section_key("preferences", "default_image_height"):
DrawGD.current_project.size.y = DrawGD.config_cache.get_value("preferences", "default_image_height")
if DrawGD.config_cache.has_section_key("preferences", "default_fill_color"):
fill_color = DrawGD.config_cache.get_value("preferences", "default_fill_color")
sprite.create(size.x, size.y, false, Image.FORMAT_RGBA8)
sprite.fill(fill_color)
sprite.lock()
@ -122,7 +122,7 @@ func new_empty_frame(first_time := false, single_layer := false, size := Global.
return frame
func handle_undo(action : String, project : Project = Global.current_project, layer_index := -2, frame_index := -2) -> void:
func handle_undo(action : String, project : Project = DrawGD.current_project, layer_index := -2, frame_index := -2) -> void:
if !can_undo:
return
@ -157,12 +157,12 @@ func handle_undo(action : String, project : Project = Global.current_project, la
var data = cel.image.data
cel.image.lock()
project.undo_redo.add_undo_property(cel.image, "data", data)
project.undo_redo.add_undo_method(Global, "undo", frame_index, layer_index, project)
project.undo_redo.add_undo_method(DrawGD, "undo", frame_index, layer_index, project)
can_undo = false
func handle_redo(_action : String, project : Project = Global.current_project, layer_index := -2, frame_index := -2) -> void:
func handle_redo(_action : String, project : Project = DrawGD.current_project, layer_index := -2, frame_index := -2) -> void:
can_undo = true
if project.undos < project.undo_redo.get_version():
return
@ -192,51 +192,51 @@ func handle_redo(_action : String, project : Project = Global.current_project, l
for cel in cels:
project.undo_redo.add_do_property(cel.image, "data", cel.image.data)
project.undo_redo.add_do_method(Global, "redo", frame_index, layer_index, project)
project.undo_redo.add_do_method(DrawGD, "redo", frame_index, layer_index, project)
project.undo_redo.commit_action()
func update_texture(layer_index : int, frame_index := -1, project : Project = Global.current_project) -> void:
func update_texture(layer_index : int, frame_index := -1, project : Project = DrawGD.current_project) -> void:
if frame_index == -1:
frame_index = project.current_frame
var current_cel : Cel = project.frames[frame_index].cels[layer_index]
current_cel.image_texture.create_from_image(current_cel.image, 0)
if project == Global.current_project:
if project == DrawGD.current_project:
var frame_texture_rect : TextureRect
frame_texture_rect = Global.find_node_by_name(project.layers[layer_index].frame_container.get_child(frame_index), "CelTexture")
frame_texture_rect = DrawGD.find_node_by_name(project.layers[layer_index].frame_container.get_child(frame_index), "CelTexture")
frame_texture_rect.texture = current_cel.image_texture
func onion_skinning() -> void:
# Past
if Global.onion_skinning_past_rate > 0:
if DrawGD.onion_skinning_past_rate > 0:
var color : Color
if Global.onion_skinning_blue_red:
if DrawGD.onion_skinning_blue_red:
color = Color.blue
else:
color = Color.white
for i in range(1, Global.onion_skinning_past_rate + 1):
if Global.current_project.current_frame >= i:
for i in range(1, DrawGD.onion_skinning_past_rate + 1):
if DrawGD.current_project.current_frame >= i:
var layer_i := 0
for layer in Global.current_project.frames[Global.current_project.current_frame - i].cels:
if Global.current_project.layers[layer_i].visible:
for layer in DrawGD.current_project.frames[DrawGD.current_project.current_frame - i].cels:
if DrawGD.current_project.layers[layer_i].visible:
color.a = 0.6 / i
draw_texture(layer.image_texture, location, color)
layer_i += 1
# Future
if Global.onion_skinning_future_rate > 0:
if DrawGD.onion_skinning_future_rate > 0:
var color : Color
if Global.onion_skinning_blue_red:
if DrawGD.onion_skinning_blue_red:
color = Color.red
else:
color = Color.white
for i in range(1, Global.onion_skinning_future_rate + 1):
if Global.current_project.current_frame < Global.current_project.frames.size() - i:
for i in range(1, DrawGD.onion_skinning_future_rate + 1):
if DrawGD.current_project.current_frame < DrawGD.current_project.frames.size() - i:
var layer_i := 0
for layer in Global.current_project.frames[Global.current_project.current_frame + i].cels:
if Global.current_project.layers[layer_i].visible:
for layer in DrawGD.current_project.frames[DrawGD.current_project.current_frame + i].cels:
if DrawGD.current_project.layers[layer_i].visible:
color.a = 0.6 / i
draw_texture(layer.image_texture, location, color)
layer_i += 1

View File

@ -5,11 +5,11 @@ var frame : int = 0
onready var animation_timer : Timer = $AnimationTimer
func _draw() -> void:
var current_project : Project = Global.current_project
var current_project : Project = DrawGD.current_project
if frame >= current_project.frames.size():
frame = current_project.current_frame
$AnimationTimer.wait_time = Global.animation_timer.wait_time
$AnimationTimer.wait_time = DrawGD.animation_timer.wait_time
if animation_timer.is_stopped():
frame = current_project.current_frame
@ -23,7 +23,7 @@ func _draw() -> void:
func _on_AnimationTimer_timeout() -> void:
var current_project : Project = Global.current_project
var current_project : Project = DrawGD.current_project
if frame < current_project.frames.size() - 1:
frame += 1

View File

@ -6,28 +6,28 @@ var isometric_polylines := [] # An array of PoolVector2Arrays
func _draw() -> void:
if Global.draw_grid:
draw_grid(Global.grid_type)
if DrawGD.draw_grid:
draw_grid(DrawGD.grid_type)
func draw_grid(grid_type : int) -> void:
var size : Vector2 = Global.current_project.size
if grid_type == Global.Grid_Types.CARTESIAN || grid_type == Global.Grid_Types.ALL:
for x in range(Global.grid_width, size.x, Global.grid_width):
draw_line(Vector2(x, location.y), Vector2(x, size.y), Global.grid_color, true)
var size : Vector2 = DrawGD.current_project.size
if grid_type == DrawGD.Grid_Types.CARTESIAN || grid_type == DrawGD.Grid_Types.ALL:
for x in range(DrawGD.grid_width, size.x, DrawGD.grid_width):
draw_line(Vector2(x, location.y), Vector2(x, size.y), DrawGD.grid_color, true)
for y in range(Global.grid_height, size.y, Global.grid_height):
draw_line(Vector2(location.x, y), Vector2(size.x, y), Global.grid_color, true)
for y in range(DrawGD.grid_height, size.y, DrawGD.grid_height):
draw_line(Vector2(location.x, y), Vector2(size.x, y), DrawGD.grid_color, true)
if grid_type == Global.Grid_Types.ISOMETRIC || grid_type == Global.Grid_Types.ALL:
if grid_type == DrawGD.Grid_Types.ISOMETRIC || grid_type == DrawGD.Grid_Types.ALL:
var i := 0
for x in range(Global.grid_isometric_cell_size, size.x + 2, Global.grid_isometric_cell_size * 2):
for y in range(0, size.y + 1, Global.grid_isometric_cell_size):
for x in range(DrawGD.grid_isometric_cell_size, size.x + 2, DrawGD.grid_isometric_cell_size * 2):
for y in range(0, size.y + 1, DrawGD.grid_isometric_cell_size):
draw_isometric_tile(i, Vector2(x, y))
i += 1
func draw_isometric_tile(i : int, origin := Vector2.RIGHT, cell_size : int = Global.grid_isometric_cell_size) -> void:
func draw_isometric_tile(i : int, origin := Vector2.RIGHT, cell_size : int = DrawGD.grid_isometric_cell_size) -> void:
# A random value I found by trial and error, I have no idea why it "works"
var diff = 1.11754
var approx_30_degrees = deg2rad(26.565)
@ -48,4 +48,4 @@ func draw_isometric_tile(i : int, origin := Vector2.RIGHT, cell_size : int = Glo
isometric_polylines.append(pool)
if pool.size() > 2:
draw_polyline(pool, Global.grid_color)
draw_polyline(pool, DrawGD.grid_color)

View File

@ -2,11 +2,11 @@ extends Node2D
func _input(event : InputEvent) -> void:
if Global.has_focus and event is InputEventMouseMotion:
if DrawGD.has_focus and event is InputEventMouseMotion:
update()
func _draw() -> void:
# Draw rectangle to indicate the pixel currently being hovered on
if Global.has_focus and Global.can_draw:
if DrawGD.has_focus and DrawGD.can_draw:
Tools.draw_indicator()

View File

@ -6,12 +6,12 @@ var font := preload("res://assets/fonts/Roboto-Regular.tres")
var has_focus := true
var mouse_pos := Vector2.ZERO
var type = Types.HORIZONTAL
var project = Global.current_project
var project = DrawGD.current_project
func _ready() -> void:
width = Global.camera.zoom.x
default_color = Global.guide_color
width = DrawGD.camera.zoom.x
default_color = DrawGD.guide_color
project.guides.append(self)
@ -27,10 +27,10 @@ func _input(_event : InputEvent):
else:
point0.x -= width * 3
point1.x += width * 3
if Global.can_draw and Global.has_focus and point_in_rectangle(mouse_pos, point0, point1) and Input.is_action_just_pressed("left_mouse"):
if !point_in_rectangle(Global.canvas.current_pixel, Global.canvas.location, Global.canvas.location + project.size):
if DrawGD.can_draw and DrawGD.has_focus and point_in_rectangle(mouse_pos, point0, point1) and Input.is_action_just_pressed("left_mouse"):
if !point_in_rectangle(DrawGD.canvas.current_pixel, DrawGD.canvas.location, DrawGD.canvas.location + project.size):
has_focus = true
Global.has_focus = false
DrawGD.has_focus = false
update()
if has_focus and visible:
if Input.is_action_pressed("left_mouse"):
@ -43,7 +43,7 @@ func _input(_event : InputEvent):
points[0].x = xx
points[1].x = xx
if Input.is_action_just_released("left_mouse"):
Global.has_focus = true
DrawGD.has_focus = true
has_focus = false
if !outside_canvas():
update()
@ -51,13 +51,13 @@ func _input(_event : InputEvent):
func _draw() -> void:
if has_focus:
var viewport_size: Vector2 = Global.main_viewport.rect_size
var zoom: Vector2 = Global.camera.zoom
var viewport_size: Vector2 = DrawGD.main_viewport.rect_size
var zoom: Vector2 = DrawGD.camera.zoom
if type == Types.HORIZONTAL:
draw_set_transform(Vector2(Global.camera.offset.x - (viewport_size.x / 2) * zoom.x, points[0].y + font.get_height() * zoom.x * 2), rotation, zoom * 2)
draw_set_transform(Vector2(DrawGD.camera.offset.x - (viewport_size.x / 2) * zoom.x, points[0].y + font.get_height() * zoom.x * 2), rotation, zoom * 2)
draw_string(font, Vector2.ZERO, "%spx" % str(stepify(mouse_pos.y, 0.5)))
else:
draw_set_transform(Vector2(points[0].x + font.get_height() * zoom.y, Global.camera.offset.y - (viewport_size.y / 2.25) * zoom.y), rotation, zoom * 2)
draw_set_transform(Vector2(points[0].x + font.get_height() * zoom.y, DrawGD.camera.offset.y - (viewport_size.y / 2.25) * zoom.y), rotation, zoom * 2)
draw_string(font, Vector2.ZERO, "%spx" % str(stepify(mouse_pos.x, 0.5)))

View File

@ -11,7 +11,7 @@ var last : Vector2
func _ready() -> void:
Global.main_viewport.connect("item_rect_changed", self, "update")
DrawGD.main_viewport.connect("item_rect_changed", self, "update")
# Code taken and modified from Godot's source code
@ -20,10 +20,10 @@ func _draw() -> void:
var ruler_transform := Transform2D()
var major_subdivide := Transform2D()
var minor_subdivide := Transform2D()
var zoom: float = 1 / Global.camera.zoom.x
var zoom: float = 1 / DrawGD.camera.zoom.x
transform.x = Vector2(zoom, zoom)
transform.origin = Global.main_viewport.rect_size / 2 + Global.camera.offset * -zoom
transform.origin = DrawGD.main_viewport.rect_size / 2 + DrawGD.camera.offset * -zoom
var basic_rule := 100.0
var i := 0
@ -41,7 +41,7 @@ func _draw() -> void:
minor_subdivide = minor_subdivide.scaled(Vector2(1.0 / minor_subdivision, 1.0 / minor_subdivision))
first = (transform * ruler_transform * major_subdivide * minor_subdivide).affine_inverse().xform(Vector2.ZERO)
last = (transform * ruler_transform * major_subdivide * minor_subdivide).affine_inverse().xform(Global.main_viewport.rect_size)
last = (transform * ruler_transform * major_subdivide * minor_subdivide).affine_inverse().xform(DrawGD.main_viewport.rect_size)
for j in range(ceil(first.x), ceil(last.x)):
var position : Vector2 = (transform * ruler_transform * major_subdivide * minor_subdivide).xform(Vector2(j, 0))
@ -57,20 +57,20 @@ func _draw() -> void:
func _on_HorizontalRuler_pressed() -> void:
if !Global.show_guides:
if !DrawGD.show_guides:
return
var mouse_pos := get_local_mouse_position()
if mouse_pos.x < RULER_WIDTH: # For double guides
Global.vertical_ruler._on_VerticalRuler_pressed()
DrawGD.vertical_ruler._on_VerticalRuler_pressed()
var guide := Guide.new()
guide.type = guide.Types.HORIZONTAL
guide.add_point(Vector2(-19999, Global.canvas.current_pixel.y))
guide.add_point(Vector2(19999, Global.canvas.current_pixel.y))
guide.add_point(Vector2(-19999, DrawGD.canvas.current_pixel.y))
guide.add_point(Vector2(19999, DrawGD.canvas.current_pixel.y))
if guide.points.size() < 2:
guide.queue_free()
return
Global.canvas.add_child(guide)
Global.has_focus = false
DrawGD.canvas.add_child(guide)
DrawGD.has_focus = false
update()

View File

@ -9,9 +9,9 @@ func _ready() -> void:
visible = false
texture = _texture
texture_mode = Line2D.LINE_TEXTURE_TILE
width = Global.camera.zoom.x * 4
width = DrawGD.camera.zoom.x * 4
yield(get_tree().create_timer(0.01), "timeout")
modulate = Global.guide_color
modulate = DrawGD.guide_color
func _input(_event : InputEvent) -> void:
@ -26,10 +26,10 @@ func _input(_event : InputEvent) -> void:
func outside_canvas() -> bool:
if type == Types.HORIZONTAL:
points[0].y = clamp(points[0].y, 0, Global.current_project.size.y)
points[1].y = clamp(points[1].y, 0, Global.current_project.size.y)
points[0].y = clamp(points[0].y, 0, DrawGD.current_project.size.y)
points[1].y = clamp(points[1].y, 0, DrawGD.current_project.size.y)
elif type == Types.VERTICAL:
points[0].x = clamp(points[0].x, 0, Global.current_project.size.x)
points[1].x = clamp(points[1].x, 0, Global.current_project.size.x)
points[0].x = clamp(points[0].x, 0, DrawGD.current_project.size.x)
points[1].x = clamp(points[1].x, 0, DrawGD.current_project.size.x)
return false

View File

@ -11,7 +11,7 @@ var last : Vector2
func _ready() -> void:
Global.main_viewport.connect("item_rect_changed", self, "update")
DrawGD.main_viewport.connect("item_rect_changed", self, "update")
# Code taken and modified from Godot's source code
@ -20,10 +20,10 @@ func _draw() -> void:
var ruler_transform := Transform2D()
var major_subdivide := Transform2D()
var minor_subdivide := Transform2D()
var zoom: float = 1 / Global.camera.zoom.x
var zoom: float = 1 / DrawGD.camera.zoom.x
transform.y = Vector2(zoom, zoom)
transform.origin = Global.main_viewport.rect_size / 2 + Global.camera.offset * -zoom
transform.origin = DrawGD.main_viewport.rect_size / 2 + DrawGD.camera.offset * -zoom
var basic_rule := 100.0
var i := 0
@ -41,7 +41,7 @@ func _draw() -> void:
minor_subdivide = minor_subdivide.scaled(Vector2(1.0 / minor_subdivision, 1.0 / minor_subdivision))
first = (transform * ruler_transform * major_subdivide * minor_subdivide).affine_inverse().xform(Vector2.ZERO)
last = (transform * ruler_transform * major_subdivide * minor_subdivide).affine_inverse().xform(Global.main_viewport.rect_size)
last = (transform * ruler_transform * major_subdivide * minor_subdivide).affine_inverse().xform(DrawGD.main_viewport.rect_size)
for j in range(ceil(first.y), ceil(last.y)):
var position : Vector2 = (transform * ruler_transform * major_subdivide * minor_subdivide).xform(Vector2(0, j))
@ -60,15 +60,15 @@ func _draw() -> void:
func _on_VerticalRuler_pressed() -> void:
if !Global.show_guides:
if !DrawGD.show_guides:
return
var guide := Guide.new()
guide.type = guide.Types.VERTICAL
guide.add_point(Vector2(Global.canvas.current_pixel.x, -19999))
guide.add_point(Vector2(Global.canvas.current_pixel.x, 19999))
guide.add_point(Vector2(DrawGD.canvas.current_pixel.x, -19999))
guide.add_point(Vector2(DrawGD.canvas.current_pixel.x, 19999))
if guide.points.size() < 2:
guide.queue_free()
return
Global.canvas.add_child(guide)
Global.has_focus = false
DrawGD.canvas.add_child(guide)
DrawGD.has_focus = false
update()

View File

@ -5,8 +5,8 @@ var location := Vector2.ZERO
func _draw() -> void:
var current_cels : Array = Global.current_project.frames[Global.current_project.current_frame].cels
var size : Vector2 = Global.current_project.size
var current_cels : Array = DrawGD.current_project.frames[DrawGD.current_project.current_frame].cels
var size : Vector2 = DrawGD.current_project.size
var positions := [
Vector2(location.x, location.y + size.y), # Down
Vector2(location.x - size.x, location.y + size.y), # Down left
@ -21,11 +21,11 @@ func _draw() -> void:
for pos in positions:
# Draw a blank rectangle behind the textures
# Mostly used to hide the grid if it goes outside the canvas boundaries
draw_rect(Rect2(pos, size), Global.default_clear_color)
draw_rect(Rect2(pos, size), DrawGD.default_clear_color)
for i in range(Global.current_project.layers.size()):
for i in range(DrawGD.current_project.layers.size()):
var modulate_color := Color(1, 1, 1, current_cels[i].opacity)
if Global.current_project.layers[i].visible: # if it's visible
if Global.tile_mode:
if DrawGD.current_project.layers[i].visible: # if it's visible
if DrawGD.tile_mode:
for pos in positions:
draw_texture(current_cels[i].image_texture, pos, modulate_color)

View File

@ -14,11 +14,11 @@ func _on_PreviewZoomSlider_value_changed(value : float) -> void:
func _on_PlayButton_toggled(button_pressed : bool) -> void:
if button_pressed:
if Global.current_project.frames.size() <= 1:
if DrawGD.current_project.frames.size() <= 1:
play_button.pressed = false
return
canvas_preview.animation_timer.start()
Global.change_button_texturerect(play_button.get_child(0), "pause.png")
DrawGD.change_button_texturerect(play_button.get_child(0), "pause.png")
else:
canvas_preview.animation_timer.stop()
Global.change_button_texturerect(play_button.get_child(0), "play.png")
DrawGD.change_button_texturerect(play_button.get_child(0), "play.png")

View File

@ -21,11 +21,11 @@ func _on_ColorPickerButton_color_changed(color : Color, right : bool):
func _on_ColorPickerButton_pressed() -> void:
Global.can_draw = false
DrawGD.can_draw = false
func _on_ColorPickerButton_popup_closed() -> void:
Global.can_draw = true
DrawGD.can_draw = true
func _on_ColorDefaults_pressed() -> void:

View File

@ -22,7 +22,7 @@ enum Templates {
SNES_NTSC = 9,
SNES_PAL = 10
}
# Template actual value, without Default because we get it from Global
# Template actual value, without Default because we get it from DrawGD
var TResolutions = {
Templates.T16: Vector2(16,16),
Templates.T32: Vector2(32,32),
@ -53,9 +53,9 @@ var TStrings ={
func _ready() -> void:
width_value.value = Global.default_image_width
height_value.value = Global.default_image_height
fill_color_node.color = Global.default_fill_color
width_value.value = DrawGD.default_image_width
height_value.value = DrawGD.default_image_height
fill_color_node.color = DrawGD.default_fill_color
fill_color_node.get_picker().presets_visible = false
ratio_box.connect("pressed", self, "_on_RatioCheckBox_toggled", [ratio_box.pressed])
@ -77,14 +77,14 @@ func _on_CreateNewImage_confirmed() -> void:
var width : int = width_value.value
var height : int = height_value.value
var fill_color : Color = fill_color_node.color
Global.canvas.fill_color = fill_color
DrawGD.canvas.fill_color = fill_color
var frame : Frame = Global.canvas.new_empty_frame(false, true, Vector2(width, height))
var frame : Frame = DrawGD.canvas.new_empty_frame(false, true, Vector2(width, height))
var new_project := Project.new([frame], tr("untitled"), Vector2(width, height).floor())
new_project.layers.append(Layer.new())
Global.projects.append(new_project)
Global.tabs.current_tab = Global.tabs.get_tab_count() - 1
Global.canvas.camera_zoom()
DrawGD.projects.append(new_project)
DrawGD.tabs.current_tab = DrawGD.tabs.get_tab_count() - 1
DrawGD.canvas.camera_zoom()
var aspect_ratio: float
@ -109,8 +109,8 @@ func _on_TemplatesOptions_item_selected(id: int) -> void:
if id != Templates.TDefault:
size_value = TResolutions[id]
else:
width_value.value = Global.default_image_width
height_value.value = Global.default_image_height
width_value.value = DrawGD.default_image_width
height_value.value = DrawGD.default_image_height
width_value.value = size_value.x
height_value.value = size_value.y

View File

@ -70,8 +70,8 @@ func show_tab() -> void:
file_file_format.selected = Export.FileFormat.PNG
frame_timer.stop()
if not Export.was_exported:
Export.frame_number = Global.current_project.current_frame + 1
frame_options_frame_number.max_value = Global.current_project.frames.size() + 1
Export.frame_number = DrawGD.current_project.current_frame + 1
frame_options_frame_number.max_value = DrawGD.current_project.frames.size() + 1
var prev_frame_number = frame_options_frame_number.value
frame_options_frame_number.value = Export.frame_number
if prev_frame_number == Export.frame_number:
@ -189,7 +189,7 @@ func set_file_format_selector() -> void:
Export.AnimationType.ANIMATED:
Export.file_format = Export.FileFormat.GIF
file_file_format.selected = Export.FileFormat.GIF
frame_timer.wait_time = Global.animation_timer.wait_time
frame_timer.wait_time = DrawGD.animation_timer.wait_time
animation_options_animation_options.show()
@ -199,7 +199,7 @@ func create_frame_tag_list() -> void:
spritesheet_options_frames.add_item("All Frames", 0) # Re-add removed 'All Frames' item
# Repopulate list with current tag list
for item in Global.current_project.animation_tags:
for item in DrawGD.current_project.animation_tags:
spritesheet_options_frames.add_item(item.name)
@ -242,7 +242,7 @@ func _on_ExportDialog_about_to_show() -> void:
show_tab()
for child in popups.get_children(): # Set the theme for the popups
child.theme = Global.control.theme
child.theme = DrawGD.control.theme
Export.file_exists_alert = tr("File %s already exists. Overwrite?") # Update translation
@ -319,23 +319,23 @@ func _on_PathButton_pressed() -> void:
func _on_PathLineEdit_text_changed(new_text : String) -> void:
Global.current_project.directory_path = new_text
DrawGD.current_project.directory_path = new_text
Export.directory_path = new_text
func _on_FileLineEdit_text_changed(new_text : String) -> void:
Global.current_project.file_name = new_text
DrawGD.current_project.file_name = new_text
Export.file_name = new_text
func _on_FileDialog_dir_selected(dir : String) -> void:
path_line_edit.text = dir
Global.current_project.directory_path = dir
DrawGD.current_project.directory_path = dir
Export.directory_path = dir
func _on_FileFormat_item_selected(id : int) -> void:
Global.current_project.file_format = id
DrawGD.current_project.file_format = id
Export.file_format = id

View File

@ -14,7 +14,7 @@ func set_nodes() -> void:
affect_option_button = $VBoxContainer/OptionsContainer/AffectOptionButton
func commit_action(_cel : Image, _pixels : Array, _project : Project = Global.current_project) -> void:
func commit_action(_cel : Image, _pixels : Array, _project : Project = DrawGD.current_project) -> void:
DrawingAlgos.desaturate_image(_cel, _pixels, red, green, blue, alpha)

View File

@ -11,7 +11,7 @@ func set_nodes() -> void:
affect_option_button = $VBoxContainer/OptionsContainer/AffectOptionButton
func commit_action(_cel : Image, _pixels : Array, project : Project = Global.current_project) -> void:
func commit_action(_cel : Image, _pixels : Array, project : Project = DrawGD.current_project) -> void:
flip_image(_cel, _pixels, project)
@ -28,7 +28,7 @@ func _on_SelectionCheckBox_toggled(button_pressed : bool) -> void:
update_preview()
func flip_image(image : Image, _pixels : Array, project : Project = Global.current_project) -> void:
func flip_image(image : Image, _pixels : Array, project : Project = DrawGD.current_project) -> void:
var entire_image_selected : bool = _pixels.size() == project.size.x * project.size.y
if entire_image_selected:
if flip_h.pressed:

View File

@ -19,7 +19,7 @@ func set_nodes() -> void:
affect_option_button = $VBoxContainer/OptionsContainer/AffectOptionButton
func commit_action(_cel : Image, _pixels : Array, _project : Project = Global.current_project) -> void:
func commit_action(_cel : Image, _pixels : Array, _project : Project = DrawGD.current_project) -> void:
DrawingAlgos.generate_gradient(_cel, [color1.color, color2.color], steps.value, direction.selected, _pixels)

View File

@ -22,7 +22,7 @@ func _confirmed() -> void:
reset()
func commit_action(_cel : Image, _pixels : Array, _project : Project = Global.current_project) -> void:
func commit_action(_cel : Image, _pixels : Array, _project : Project = DrawGD.current_project) -> void:
DrawingAlgos.adjust_hsv(_cel, hue_slider.value, sat_slider.value, val_slider.value, _pixels)

View File

@ -14,7 +14,7 @@ func set_nodes() -> void:
affect_option_button = $VBoxContainer/OptionsContainer/AffectOptionButton
func commit_action(_cel : Image, _pixels : Array, _project : Project = Global.current_project) -> void:
func commit_action(_cel : Image, _pixels : Array, _project : Project = DrawGD.current_project) -> void:
DrawingAlgos.invert_image_colors(_cel, _pixels, red, green, blue, alpha)

View File

@ -21,7 +21,7 @@ func set_nodes() -> void:
affect_option_button = $VBoxContainer/OptionsContainer/AffectOptionButton
func commit_action(_cel : Image, _pixels : Array, _project : Project = Global.current_project) -> void:
func commit_action(_cel : Image, _pixels : Array, _project : Project = DrawGD.current_project) -> void:
DrawingAlgos.generate_outline(_cel, _pixels, color, thickness, diagonal, inside_image)

View File

@ -18,15 +18,15 @@ onready var preview_rect : TextureRect = $VBoxContainer/Preview
func _on_ResizeCanvas_about_to_show() -> void:
if first_time:
width_spinbox.value = Global.current_project.size.x
height_spinbox.value = Global.current_project.size.y
width_spinbox.value = DrawGD.current_project.size.x
height_spinbox.value = DrawGD.current_project.size.y
image = Image.new()
image.create(Global.current_project.size.x, Global.current_project.size.y, false, Image.FORMAT_RGBA8)
image.create(DrawGD.current_project.size.x, DrawGD.current_project.size.y, false, Image.FORMAT_RGBA8)
image.lock()
var layer_i := 0
for cel in Global.current_project.frames[Global.current_project.current_frame].cels:
if Global.current_project.layers[layer_i].visible:
for cel in DrawGD.current_project.frames[DrawGD.current_project.current_frame].cels:
if DrawGD.current_project.layers[layer_i].visible:
var cel_image := Image.new()
cel_image.copy_from(cel.image)
cel_image.lock()
@ -36,7 +36,7 @@ func _on_ResizeCanvas_about_to_show() -> void:
var pixel_color := cel_image.get_pixel(xx, yy)
var alpha : float = pixel_color.a * cel.opacity
cel_image.set_pixel(xx, yy, Color(pixel_color.r, pixel_color.g, pixel_color.b, alpha))
image.blend_rect(cel_image, Rect2(Global.canvas.location, Global.current_project.size), Vector2.ZERO)
image.blend_rect(cel_image, Rect2(DrawGD.canvas.location, DrawGD.current_project.size), Vector2.ZERO)
layer_i += 1
image.unlock()
@ -50,16 +50,16 @@ func _on_ResizeCanvas_confirmed() -> void:
func _on_WidthValue_value_changed(value : int) -> void:
width = value
x_spinbox.min_value = min(width - Global.current_project.size.x, 0)
x_spinbox.max_value = max(width - Global.current_project.size.x, 0)
x_spinbox.min_value = min(width - DrawGD.current_project.size.x, 0)
x_spinbox.max_value = max(width - DrawGD.current_project.size.x, 0)
x_spinbox.value = clamp(x_spinbox.value, x_spinbox.min_value, x_spinbox.max_value)
update_preview()
func _on_HeightValue_value_changed(value : int) -> void:
height = value
y_spinbox.min_value = min(height - Global.current_project.size.y, 0)
y_spinbox.max_value = max(height - Global.current_project.size.y, 0)
y_spinbox.min_value = min(height - DrawGD.current_project.size.y, 0)
y_spinbox.max_value = max(height - DrawGD.current_project.size.y, 0)
y_spinbox.value = clamp(y_spinbox.value, y_spinbox.min_value, y_spinbox.max_value)
update_preview()
@ -83,7 +83,7 @@ func update_preview() -> void:
# preview_image is the same as image but offsetted
var preview_image := Image.new()
preview_image.create(width, height, false, Image.FORMAT_RGBA8)
preview_image.blend_rect(image, Rect2(Vector2.ZERO, Global.current_project.size), Vector2(offset_x, offset_y))
preview_image.blend_rect(image, Rect2(Vector2.ZERO, DrawGD.current_project.size), Vector2(offset_x, offset_y))
var preview_texture := ImageTexture.new()
preview_texture.create_from_image(preview_image, 0)
preview_rect.texture = preview_texture
@ -105,4 +105,4 @@ func update_transparent_background_size(preview_image : Image) -> void:
func _on_ResizeCanvas_popup_hide() -> void:
Global.dialog_open(false)
DrawGD.dialog_open(false)

View File

@ -22,7 +22,7 @@ func _about_to_show() -> void:
angle_hslider.value = 0
func commit_action(_cel : Image, _pixels : Array, _project : Project = Global.current_project) -> void:
func commit_action(_cel : Image, _pixels : Array, _project : Project = DrawGD.current_project) -> void:
match type_option_button.text:
"Rotxel":
DrawingAlgos.rotxel(_cel,angle_hslider.value*PI/180)

View File

@ -10,4 +10,4 @@ func _on_ScaleImage_confirmed() -> void:
func _on_ScaleImage_popup_hide() -> void:
Global.dialog_open(false)
DrawGD.dialog_open(false)

View File

@ -11,7 +11,7 @@ onready var shader_params : BoxContainer = $VBoxContainer/ShaderParams
func _on_ShaderEffect_about_to_show() -> void:
current_cel = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image
current_cel = DrawGD.current_project.frames[DrawGD.current_project.current_frame].cels[DrawGD.current_project.current_layer].image
var preview_image := Image.new()
preview_image.copy_from(current_cel)
@ -25,7 +25,7 @@ func _on_ShaderEffect_confirmed() -> void:
return
current_cel.unlock()
var viewport_texture := Image.new()
var size : Vector2 = Global.current_project.size
var size : Vector2 = DrawGD.current_project.size
var vp = VisualServer.viewport_create()
var canvas = VisualServer.canvas_create()
VisualServer.viewport_attach_canvas(vp, canvas)
@ -60,14 +60,14 @@ func _on_ShaderEffect_confirmed() -> void:
VisualServer.free_rid(mat_rid)
print(viewport_texture.data)
viewport_texture.convert(Image.FORMAT_RGBA8)
Global.canvas.handle_undo("Draw")
DrawGD.canvas.handle_undo("Draw")
current_cel.copy_from(viewport_texture)
Global.canvas.handle_redo("Draw")
DrawGD.canvas.handle_redo("Draw")
current_cel.lock()
func _on_ShaderEffect_popup_hide() -> void:
Global.dialog_open(false)
DrawGD.dialog_open(false)
func _on_ChooseShader_pressed() -> void:

View File

@ -33,11 +33,11 @@ func _on_PreviewDialog_about_to_show() -> void:
func _on_PreviewDialog_popup_hide() -> void:
queue_free()
# Call Global.dialog_open() only if it's the only preview dialog opened
for child in Global.control.get_children():
# Call DrawGD.dialog_open() only if it's the only preview dialog opened
for child in DrawGD.control.get_children():
if child != self and "PreviewDialog" in child.name:
return
Global.dialog_open(false)
DrawGD.dialog_open(false)
func _on_PreviewDialog_confirmed() -> void:
@ -56,7 +56,7 @@ func _on_PreviewDialog_confirmed() -> void:
OpenSave.open_image_as_new_layer(image, path.get_basename().get_file(), frame_index)
elif current_import_option == ImageImportOptions.PALETTE:
Global.palette_container.import_image_palette(path, image)
DrawGD.palette_container.import_image_palette(path, image)
elif current_import_option == ImageImportOptions.BRUSH:
add_brush()
@ -66,12 +66,12 @@ func _on_PreviewDialog_confirmed() -> void:
file_name_ext = file_name_replace(file_name_ext, "Patterns")
var file_name : String = file_name_ext.get_basename()
image.convert(Image.FORMAT_RGBA8)
Global.patterns_popup.add(image, file_name)
DrawGD.patterns_popup.add(image, file_name)
# Copy the image file into the "pixelorama/Patterns" directory
var location := "Patterns".plus_file(file_name_ext)
var dir = Directory.new()
dir.copy(path, Global.directory_module.xdg_data_home.plus_file(location))
dir.copy(path, DrawGD.directory_module.xdg_data_home.plus_file(location))
func _on_ImportOption_item_selected(id : int) -> void:
@ -92,11 +92,11 @@ func _on_ImportOption_item_selected(id : int) -> void:
elif id == ImageImportOptions.NEW_FRAME:
new_frame_options.visible = true
new_frame_options.get_node("AtLayerSpinbox").max_value = Global.current_project.layers.size() - 1
new_frame_options.get_node("AtLayerSpinbox").max_value = DrawGD.current_project.layers.size() - 1
elif id == ImageImportOptions.NEW_LAYER:
new_layer_options.visible = true
new_layer_options.get_node("AtFrameSpinbox").max_value = Global.current_project.frames.size()
new_layer_options.get_node("AtFrameSpinbox").max_value = DrawGD.current_project.frames.size()
elif id == ImageImportOptions.BRUSH:
new_brush_options.visible = true
@ -175,11 +175,11 @@ func add_brush() -> void:
# Copy the image file into the "pixelorama/Brushes" directory
var location := "Brushes".plus_file(file_name_ext)
var dir = Directory.new()
dir.copy(path, Global.directory_module.xdg_data_home.plus_file(location))
dir.copy(path, DrawGD.directory_module.xdg_data_home.plus_file(location))
elif brush_type == BrushTypes.PROJECT:
var file_name : String = path.get_file().get_basename()
Global.current_project.brushes.append(image)
DrawGD.current_project.brushes.append(image)
Brushes.add_project_brush(image, file_name)
elif brush_type == BrushTypes.RANDOM:
@ -187,11 +187,11 @@ func add_brush() -> void:
if !brush_name.is_valid_filename():
return
var dir := Directory.new()
dir.open(Global.directory_module.xdg_data_home.plus_file("Brushes"))
dir.open(DrawGD.directory_module.xdg_data_home.plus_file("Brushes"))
if !dir.dir_exists(brush_name):
dir.make_dir(brush_name)
dir.open(Global.directory_module.xdg_data_home.plus_file("Brushes").plus_file(brush_name))
dir.open(DrawGD.directory_module.xdg_data_home.plus_file("Brushes").plus_file(brush_name))
var random_brushes := []
dir.list_dir_begin()
var curr_file := dir.get_next()
@ -205,7 +205,7 @@ func add_brush() -> void:
var index : int = random_brushes.size() + 1
var file_name = "%" + brush_name + str(index) + "." + file_ext
var location := "Brushes".plus_file(brush_name).plus_file(file_name)
dir.copy(path, Global.directory_module.xdg_data_home.plus_file(location))
dir.copy(path, DrawGD.directory_module.xdg_data_home.plus_file(location))
# Checks if the file already exists
@ -216,7 +216,7 @@ func file_name_replace(name : String, folder : String) -> String:
var file_ext = name.get_extension()
var temp_name := name
var dir := Directory.new()
dir.open(Global.directory_module.xdg_data_home.plus_file(folder))
dir.open(DrawGD.directory_module.xdg_data_home.plus_file(folder))
while dir.file_exists(temp_name):
i += 1
temp_name = name.get_basename() + " (%s)" % i

View File

@ -5,4 +5,4 @@ var pattern := Patterns.Pattern.new()
func _on_PatternButton_pressed() -> void:
Global.patterns_popup.select_pattern(pattern)
DrawGD.patterns_popup.select_pattern(pattern)

View File

@ -29,16 +29,16 @@ static func add(image : Image, hint := "") -> void:
var button = create_button(image)
button.pattern.image = image
button.hint_tooltip = hint
var container = Global.patterns_popup.get_node("ScrollContainer/PatternContainer")
var container = DrawGD.patterns_popup.get_node("ScrollContainer/PatternContainer")
container.add_child(button)
button.pattern.index = button.get_index()
if Global.patterns_popup.default_pattern == null:
Global.patterns_popup.default_pattern = button.pattern
if DrawGD.patterns_popup.default_pattern == null:
DrawGD.patterns_popup.default_pattern = button.pattern
func get_pattern(index : int) -> Pattern:
var container = Global.patterns_popup.get_node("ScrollContainer/PatternContainer")
var container = DrawGD.patterns_popup.get_node("ScrollContainer/PatternContainer")
var pattern = default_pattern
if index < container.get_child_count():
pattern = container.get_child(index).pattern

View File

@ -2,46 +2,46 @@ extends Tabs
func _on_Tabs_tab_changed(tab : int) -> void:
Global.current_project_index = tab
DrawGD.current_project_index = tab
func _on_Tabs_tab_close(tab : int) -> void:
if Global.projects.size() == 1 or Global.current_project_index != tab:
if DrawGD.projects.size() == 1 or DrawGD.current_project_index != tab:
return
if Global.current_project.has_changed:
if !Global.unsaved_changes_dialog.is_connected("confirmed", self, "delete_tab"):
Global.unsaved_changes_dialog.connect("confirmed", self, "delete_tab", [tab])
Global.unsaved_changes_dialog.popup_centered()
Global.dialog_open(true)
if DrawGD.current_project.has_changed:
if !DrawGD.unsaved_changes_dialog.is_connected("confirmed", self, "delete_tab"):
DrawGD.unsaved_changes_dialog.connect("confirmed", self, "delete_tab", [tab])
DrawGD.unsaved_changes_dialog.popup_centered()
DrawGD.dialog_open(true)
else:
delete_tab(tab)
func _on_Tabs_reposition_active_tab_request(idx_to : int) -> void:
var temp = Global.projects[Global.current_project_index]
Global.projects.erase(temp)
Global.projects.insert(idx_to, temp)
var temp = DrawGD.projects[DrawGD.current_project_index]
DrawGD.projects.erase(temp)
DrawGD.projects.insert(idx_to, temp)
# Change save paths
var temp_save_path = OpenSave.current_save_paths[Global.current_project_index]
OpenSave.current_save_paths[Global.current_project_index] = OpenSave.current_save_paths[idx_to]
var temp_save_path = OpenSave.current_save_paths[DrawGD.current_project_index]
OpenSave.current_save_paths[DrawGD.current_project_index] = OpenSave.current_save_paths[idx_to]
OpenSave.current_save_paths[idx_to] = temp_save_path
var temp_backup_path = OpenSave.backup_save_paths[Global.current_project_index]
OpenSave.backup_save_paths[Global.current_project_index] = OpenSave.backup_save_paths[idx_to]
var temp_backup_path = OpenSave.backup_save_paths[DrawGD.current_project_index]
OpenSave.backup_save_paths[DrawGD.current_project_index] = OpenSave.backup_save_paths[idx_to]
OpenSave.backup_save_paths[idx_to] = temp_backup_path
func delete_tab(tab : int) -> void:
remove_tab(tab)
Global.projects[tab].undo_redo.free()
DrawGD.projects[tab].undo_redo.free()
OpenSave.remove_backup(tab)
OpenSave.current_save_paths.remove(tab)
OpenSave.backup_save_paths.remove(tab)
Global.projects.remove(tab)
DrawGD.projects.remove(tab)
if tab > 0:
Global.current_project_index -= 1
DrawGD.current_project_index -= 1
else:
Global.current_project_index = 0
if Global.unsaved_changes_dialog.is_connected("confirmed", self, "delete_tab"):
Global.unsaved_changes_dialog.disconnect("confirmed", self, "delete_tab")
DrawGD.current_project_index = 0
if DrawGD.unsaved_changes_dialog.is_connected("confirmed", self, "delete_tab"):
DrawGD.unsaved_changes_dialog.disconnect("confirmed", self, "delete_tab")

View File

@ -11,10 +11,10 @@ var tag_scroll_container : ScrollContainer
func _ready() -> void:
timeline_scroll = Global.find_node_by_name(self, "TimelineScroll")
tag_scroll_container = Global.find_node_by_name(self, "TagScroll")
timeline_scroll = DrawGD.find_node_by_name(self, "TimelineScroll")
tag_scroll_container = DrawGD.find_node_by_name(self, "TagScroll")
timeline_scroll.get_h_scrollbar().connect("value_changed", self, "_h_scroll_changed")
Global.animation_timer.wait_time = 1 / fps
DrawGD.animation_timer.wait_time = 1 / fps
func _h_scroll_changed(value : float) -> void:
@ -24,10 +24,10 @@ func _h_scroll_changed(value : float) -> void:
func add_frame() -> void:
var frame : Frame = Global.canvas.new_empty_frame()
var new_frames : Array = Global.current_project.frames.duplicate()
var frame : Frame = DrawGD.canvas.new_empty_frame()
var new_frames : Array = DrawGD.current_project.frames.duplicate()
new_frames.append(frame)
var new_layers : Array = Global.current_project.layers.duplicate()
var new_layers : Array = DrawGD.current_project.layers.duplicate()
# Loop through the array to create new classes for each element, so that they
# won't be the same as the original array's classes. Needed for undo/redo to work properly.
for i in new_layers.size():
@ -40,37 +40,37 @@ func add_frame() -> void:
frame.cels[l_i].image = new_layers[l_i].linked_cels[0].cels[l_i].image
frame.cels[l_i].image_texture = new_layers[l_i].linked_cels[0].cels[l_i].image_texture
Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Add Frame")
Global.current_project.undo_redo.add_do_method(Global, "redo")
Global.current_project.undo_redo.add_undo_method(Global, "undo")
DrawGD.current_project.undos += 1
DrawGD.current_project.undo_redo.create_action("Add Frame")
DrawGD.current_project.undo_redo.add_do_method(DrawGD, "redo")
DrawGD.current_project.undo_redo.add_undo_method(DrawGD, "undo")
Global.current_project.undo_redo.add_do_property(Global.current_project, "frames", new_frames)
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_frame", new_frames.size() - 1)
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "frames", new_frames)
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "current_frame", new_frames.size() - 1)
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "layers", new_layers)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "frames", Global.current_project.frames)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_frame", Global.current_project.current_frame)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
Global.current_project.undo_redo.commit_action()
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "frames", DrawGD.current_project.frames)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "current_frame", DrawGD.current_project.current_frame)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "layers", DrawGD.current_project.layers)
DrawGD.current_project.undo_redo.commit_action()
func _on_DeleteFrame_pressed(frame := -1) -> void:
if Global.current_project.frames.size() == 1:
if DrawGD.current_project.frames.size() == 1:
return
if frame == -1:
frame = Global.current_project.current_frame
frame = DrawGD.current_project.current_frame
var frame_to_delete : Frame = Global.current_project.frames[frame]
var new_frames : Array = Global.current_project.frames.duplicate()
var frame_to_delete : Frame = DrawGD.current_project.frames[frame]
var new_frames : Array = DrawGD.current_project.frames.duplicate()
new_frames.erase(frame_to_delete)
var current_frame := Global.current_project.current_frame
var current_frame := DrawGD.current_project.current_frame
if current_frame > 0 && current_frame == new_frames.size(): # If it's the last frame
current_frame -= 1
var new_animation_tags := Global.current_project.animation_tags.duplicate()
var new_animation_tags := DrawGD.current_project.animation_tags.duplicate()
# Loop through the tags to create new classes for them, so that they won't be the same
# as Global.current_project.animation_tags's classes. Needed for undo/redo to work properly.
# as DrawGD.current_project.animation_tags's classes. Needed for undo/redo to work properly.
for i in new_animation_tags.size():
new_animation_tags[i] = AnimationTag.new(new_animation_tags[i].name, new_animation_tags[i].color, new_animation_tags[i].from, new_animation_tags[i].to)
@ -88,7 +88,7 @@ func _on_DeleteFrame_pressed(frame := -1) -> void:
# Check if one of the cels of the frame is linked
# if they are, unlink them too
# this prevents removed cels being kept in linked memory
var new_layers : Array = Global.current_project.layers.duplicate()
var new_layers : Array = DrawGD.current_project.layers.duplicate()
# Loop through the array to create new classes for each element, so that they
# won't be the same as the original array's classes. Needed for undo/redo to work properly.
for i in new_layers.size():
@ -97,45 +97,45 @@ func _on_DeleteFrame_pressed(frame := -1) -> void:
for layer in new_layers:
for linked in layer.linked_cels:
if linked == Global.current_project.frames[frame]:
if linked == DrawGD.current_project.frames[frame]:
layer.linked_cels.erase(linked)
Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Remove Frame")
DrawGD.current_project.undos += 1
DrawGD.current_project.undo_redo.create_action("Remove Frame")
Global.current_project.undo_redo.add_do_property(Global.current_project, "frames", new_frames)
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_frame", current_frame)
Global.current_project.undo_redo.add_do_property(Global.current_project, "animation_tags", new_animation_tags)
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "frames", new_frames)
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "current_frame", current_frame)
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "animation_tags", new_animation_tags)
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "layers", new_layers)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "frames", Global.current_project.frames)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_frame", Global.current_project.current_frame)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "animation_tags", Global.current_project.animation_tags)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "frames", DrawGD.current_project.frames)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "current_frame", DrawGD.current_project.current_frame)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "animation_tags", DrawGD.current_project.animation_tags)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "layers", DrawGD.current_project.layers)
Global.current_project.undo_redo.add_do_method(Global, "redo")
Global.current_project.undo_redo.add_undo_method(Global, "undo")
Global.current_project.undo_redo.commit_action()
DrawGD.current_project.undo_redo.add_do_method(DrawGD, "redo")
DrawGD.current_project.undo_redo.add_undo_method(DrawGD, "undo")
DrawGD.current_project.undo_redo.commit_action()
func _on_CopyFrame_pressed(frame := -1) -> void:
if frame == -1:
frame = Global.current_project.current_frame
frame = DrawGD.current_project.current_frame
var new_frame := Frame.new()
var new_frames := Global.current_project.frames.duplicate()
var new_frames := DrawGD.current_project.frames.duplicate()
new_frames.insert(frame + 1, new_frame)
for cel in Global.current_project.frames[frame].cels: # Copy every cel
for cel in DrawGD.current_project.frames[frame].cels: # Copy every cel
var sprite := Image.new()
sprite.copy_from(cel.image)
sprite.lock()
new_frame.cels.append(Cel.new(sprite, cel.opacity))
var new_animation_tags := Global.current_project.animation_tags.duplicate()
var new_animation_tags := DrawGD.current_project.animation_tags.duplicate()
# Loop through the tags to create new classes for them, so that they won't be the same
# as Global.current_project.animation_tags's classes. Needed for undo/redo to work properly.
# as DrawGD.current_project.animation_tags's classes. Needed for undo/redo to work properly.
for i in new_animation_tags.size():
new_animation_tags[i] = AnimationTag.new(new_animation_tags[i].name, new_animation_tags[i].color, new_animation_tags[i].from, new_animation_tags[i].to)
@ -144,84 +144,84 @@ func _on_CopyFrame_pressed(frame := -1) -> void:
if frame + 1 >= tag.from && frame + 1 <= tag.to:
tag.to += 1
Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Add Frame")
Global.current_project.undo_redo.add_do_method(Global, "redo")
Global.current_project.undo_redo.add_undo_method(Global, "undo")
DrawGD.current_project.undos += 1
DrawGD.current_project.undo_redo.create_action("Add Frame")
DrawGD.current_project.undo_redo.add_do_method(DrawGD, "redo")
DrawGD.current_project.undo_redo.add_undo_method(DrawGD, "undo")
Global.current_project.undo_redo.add_do_property(Global.current_project, "frames", new_frames)
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_frame", frame + 1)
Global.current_project.undo_redo.add_do_property(Global.current_project, "animation_tags", new_animation_tags)
for i in range(Global.current_project.layers.size()):
for child in Global.current_project.layers[i].frame_container.get_children():
Global.current_project.undo_redo.add_do_property(child, "pressed", false)
Global.current_project.undo_redo.add_undo_property(child, "pressed", child.pressed)
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "frames", new_frames)
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "current_frame", frame + 1)
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "animation_tags", new_animation_tags)
for i in range(DrawGD.current_project.layers.size()):
for child in DrawGD.current_project.layers[i].frame_container.get_children():
DrawGD.current_project.undo_redo.add_do_property(child, "pressed", false)
DrawGD.current_project.undo_redo.add_undo_property(child, "pressed", child.pressed)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "frames", Global.current_project.frames)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_frame", frame)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "animation_tags", Global.current_project.animation_tags)
Global.current_project.undo_redo.commit_action()
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "frames", DrawGD.current_project.frames)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "current_frame", frame)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "animation_tags", DrawGD.current_project.animation_tags)
DrawGD.current_project.undo_redo.commit_action()
func _on_FrameTagButton_pressed() -> void:
Global.tag_dialog.popup_centered()
DrawGD.tag_dialog.popup_centered()
func _on_MoveLeft_pressed() -> void:
var frame : int = Global.current_project.current_frame
var frame : int = DrawGD.current_project.current_frame
if frame == 0:
return
Global.current_project.layers[Global.current_project.current_layer].frame_container.get_child(frame).change_frame_order(-1)
DrawGD.current_project.layers[DrawGD.current_project.current_layer].frame_container.get_child(frame).change_frame_order(-1)
func _on_MoveRight_pressed() -> void:
var frame : int = Global.current_project.current_frame
var frame : int = DrawGD.current_project.current_frame
if frame == last_frame:
return
Global.current_project.layers[Global.current_project.current_layer].frame_container.get_child(frame).change_frame_order(1)
DrawGD.current_project.layers[DrawGD.current_project.current_layer].frame_container.get_child(frame).change_frame_order(1)
func _on_OnionSkinning_pressed() -> void:
Global.onion_skinning = !Global.onion_skinning
Global.canvas.update()
var texture_button : TextureRect = Global.onion_skinning_button.get_child(0)
if Global.onion_skinning:
Global.change_button_texturerect(texture_button, "onion_skinning.png")
DrawGD.onion_skinning = !DrawGD.onion_skinning
DrawGD.canvas.update()
var texture_button : TextureRect = DrawGD.onion_skinning_button.get_child(0)
if DrawGD.onion_skinning:
DrawGD.change_button_texturerect(texture_button, "onion_skinning.png")
else:
Global.change_button_texturerect(texture_button, "onion_skinning_off.png")
DrawGD.change_button_texturerect(texture_button, "onion_skinning_off.png")
func _on_OnionSkinningSettings_pressed() -> void:
$OnionSkinningSettings.popup(Rect2(Global.onion_skinning_button.rect_global_position.x - $OnionSkinningSettings.rect_size.x - 16, Global.onion_skinning_button.rect_global_position.y - 106, 136, 126))
$OnionSkinningSettings.popup(Rect2(DrawGD.onion_skinning_button.rect_global_position.x - $OnionSkinningSettings.rect_size.x - 16, DrawGD.onion_skinning_button.rect_global_position.y - 106, 136, 126))
func _on_LoopAnim_pressed() -> void:
var texture_button : TextureRect = Global.loop_animation_button.get_child(0)
var texture_button : TextureRect = DrawGD.loop_animation_button.get_child(0)
match animation_loop:
0: # Make it loop
animation_loop = 1
Global.change_button_texturerect(texture_button, "loop.png")
Global.loop_animation_button.hint_tooltip = "Cycle loop"
DrawGD.change_button_texturerect(texture_button, "loop.png")
DrawGD.loop_animation_button.hint_tooltip = "Cycle loop"
1: # Make it ping-pong
animation_loop = 2
Global.change_button_texturerect(texture_button, "loop_pingpong.png")
Global.loop_animation_button.hint_tooltip = "Ping-pong loop"
DrawGD.change_button_texturerect(texture_button, "loop_pingpong.png")
DrawGD.loop_animation_button.hint_tooltip = "Ping-pong loop"
2: # Make it stop
animation_loop = 0
Global.change_button_texturerect(texture_button, "loop_none.png")
Global.loop_animation_button.hint_tooltip = "No loop"
DrawGD.change_button_texturerect(texture_button, "loop_none.png")
DrawGD.loop_animation_button.hint_tooltip = "No loop"
func _on_PlayForward_toggled(button_pressed : bool) -> void:
if button_pressed:
Global.change_button_texturerect(Global.play_forward.get_child(0), "pause.png")
DrawGD.change_button_texturerect(DrawGD.play_forward.get_child(0), "pause.png")
else:
Global.change_button_texturerect(Global.play_forward.get_child(0), "play.png")
DrawGD.change_button_texturerect(DrawGD.play_forward.get_child(0), "play.png")
play_animation(button_pressed, true)
func _on_PlayBackwards_toggled(button_pressed : bool) -> void:
if button_pressed:
Global.change_button_texturerect(Global.play_backwards.get_child(0), "pause.png")
DrawGD.change_button_texturerect(DrawGD.play_backwards.get_child(0), "pause.png")
else:
Global.change_button_texturerect(Global.play_backwards.get_child(0), "play_backwards.png")
DrawGD.change_button_texturerect(DrawGD.play_backwards.get_child(0), "play_backwards.png")
play_animation(button_pressed, false)
@ -232,31 +232,31 @@ func _on_AnimationTimer_timeout() -> void:
return
if animation_forward:
if Global.current_project.current_frame < last_frame:
Global.current_project.current_frame += 1
if DrawGD.current_project.current_frame < last_frame:
DrawGD.current_project.current_frame += 1
else:
match animation_loop:
0: # No loop
Global.play_forward.pressed = false
Global.play_backwards.pressed = false
Global.animation_timer.stop()
DrawGD.play_forward.pressed = false
DrawGD.play_backwards.pressed = false
DrawGD.animation_timer.stop()
1: # Cycle loop
Global.current_project.current_frame = first_frame
DrawGD.current_project.current_frame = first_frame
2: # Ping pong loop
animation_forward = false
_on_AnimationTimer_timeout()
else:
if Global.current_project.current_frame > first_frame:
Global.current_project.current_frame -= 1
if DrawGD.current_project.current_frame > first_frame:
DrawGD.current_project.current_frame -= 1
else:
match animation_loop:
0: # No loop
Global.play_backwards.pressed = false
Global.play_forward.pressed = false
Global.animation_timer.stop()
DrawGD.play_backwards.pressed = false
DrawGD.play_forward.pressed = false
DrawGD.animation_timer.stop()
1: # Cycle loop
Global.current_project.current_frame = last_frame
DrawGD.current_project.current_frame = last_frame
2: # Ping pong loop
animation_forward = true
_on_AnimationTimer_timeout()
@ -264,224 +264,224 @@ func _on_AnimationTimer_timeout() -> void:
func play_animation(play : bool, forward_dir : bool) -> void:
first_frame = 0
last_frame = Global.current_project.frames.size() - 1
if Global.play_only_tags:
for tag in Global.current_project.animation_tags:
if Global.current_project.current_frame + 1 >= tag.from && Global.current_project.current_frame + 1 <= tag.to:
last_frame = DrawGD.current_project.frames.size() - 1
if DrawGD.play_only_tags:
for tag in DrawGD.current_project.animation_tags:
if DrawGD.current_project.current_frame + 1 >= tag.from && DrawGD.current_project.current_frame + 1 <= tag.to:
first_frame = tag.from - 1
last_frame = min(Global.current_project.frames.size() - 1, tag.to - 1)
last_frame = min(DrawGD.current_project.frames.size() - 1, tag.to - 1)
if first_frame == last_frame:
if forward_dir:
Global.play_forward.pressed = false
DrawGD.play_forward.pressed = false
else:
Global.play_backwards.pressed = false
DrawGD.play_backwards.pressed = false
return
if forward_dir:
Global.play_backwards.disconnect("toggled", self, "_on_PlayBackwards_toggled")
Global.play_backwards.pressed = false
Global.change_button_texturerect(Global.play_backwards.get_child(0), "play_backwards.png")
Global.play_backwards.connect("toggled", self, "_on_PlayBackwards_toggled")
DrawGD.play_backwards.disconnect("toggled", self, "_on_PlayBackwards_toggled")
DrawGD.play_backwards.pressed = false
DrawGD.change_button_texturerect(DrawGD.play_backwards.get_child(0), "play_backwards.png")
DrawGD.play_backwards.connect("toggled", self, "_on_PlayBackwards_toggled")
else:
Global.play_forward.disconnect("toggled", self, "_on_PlayForward_toggled")
Global.play_forward.pressed = false
Global.change_button_texturerect(Global.play_forward.get_child(0), "play.png")
Global.play_forward.connect("toggled", self, "_on_PlayForward_toggled")
DrawGD.play_forward.disconnect("toggled", self, "_on_PlayForward_toggled")
DrawGD.play_forward.pressed = false
DrawGD.change_button_texturerect(DrawGD.play_forward.get_child(0), "play.png")
DrawGD.play_forward.connect("toggled", self, "_on_PlayForward_toggled")
if play:
Global.animation_timer.wait_time = 1 / fps
Global.animation_timer.start()
DrawGD.animation_timer.wait_time = 1 / fps
DrawGD.animation_timer.start()
animation_forward = forward_dir
else:
Global.animation_timer.stop()
DrawGD.animation_timer.stop()
func _on_NextFrame_pressed() -> void:
if Global.current_project.current_frame < Global.current_project.frames.size() - 1:
Global.current_project.current_frame += 1
if DrawGD.current_project.current_frame < DrawGD.current_project.frames.size() - 1:
DrawGD.current_project.current_frame += 1
func _on_PreviousFrame_pressed() -> void:
if Global.current_project.current_frame > 0:
Global.current_project.current_frame -= 1
if DrawGD.current_project.current_frame > 0:
DrawGD.current_project.current_frame -= 1
func _on_LastFrame_pressed() -> void:
Global.current_project.current_frame = Global.current_project.frames.size() - 1
DrawGD.current_project.current_frame = DrawGD.current_project.frames.size() - 1
func _on_FirstFrame_pressed() -> void:
Global.current_project.current_frame = 0
DrawGD.current_project.current_frame = 0
func _on_FPSValue_value_changed(value : float) -> void:
fps = float(value)
Global.animation_timer.wait_time = 1 / fps
DrawGD.animation_timer.wait_time = 1 / fps
func _on_PastOnionSkinning_value_changed(value : float) -> void:
Global.onion_skinning_past_rate = int(value)
Global.canvas.update()
DrawGD.onion_skinning_past_rate = int(value)
DrawGD.canvas.update()
func _on_FutureOnionSkinning_value_changed(value : float) -> void:
Global.onion_skinning_future_rate = int(value)
Global.canvas.update()
DrawGD.onion_skinning_future_rate = int(value)
DrawGD.canvas.update()
func _on_BlueRedMode_toggled(button_pressed : bool) -> void:
Global.onion_skinning_blue_red = button_pressed
Global.canvas.update()
DrawGD.onion_skinning_blue_red = button_pressed
DrawGD.canvas.update()
# Layer buttons
func add_layer(is_new := true) -> void:
var new_layers : Array = Global.current_project.layers.duplicate()
var new_layers : Array = DrawGD.current_project.layers.duplicate()
var l := Layer.new()
if !is_new: # Clone layer
l.name = Global.current_project.layers[Global.current_project.current_layer].name + " (" + tr("copy") + ")"
l.name = DrawGD.current_project.layers[DrawGD.current_project.current_layer].name + " (" + tr("copy") + ")"
new_layers.append(l)
Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Add Layer")
DrawGD.current_project.undos += 1
DrawGD.current_project.undo_redo.create_action("Add Layer")
for f in Global.current_project.frames:
for f in DrawGD.current_project.frames:
var new_layer := Image.new()
if is_new:
new_layer.create(Global.current_project.size.x, Global.current_project.size.y, false, Image.FORMAT_RGBA8)
new_layer.create(DrawGD.current_project.size.x, DrawGD.current_project.size.y, false, Image.FORMAT_RGBA8)
else: # Clone layer
new_layer.copy_from(f.cels[Global.current_project.current_layer].image)
new_layer.copy_from(f.cels[DrawGD.current_project.current_layer].image)
new_layer.lock()
var new_cels : Array = f.cels.duplicate()
new_cels.append(Cel.new(new_layer, 1))
Global.current_project.undo_redo.add_do_property(f, "cels", new_cels)
Global.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
DrawGD.current_project.undo_redo.add_do_property(f, "cels", new_cels)
DrawGD.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_layer", Global.current_project.current_layer + 1)
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_layer", Global.current_project.current_layer)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "current_layer", DrawGD.current_project.current_layer + 1)
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "layers", new_layers)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "current_layer", DrawGD.current_project.current_layer)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "layers", DrawGD.current_project.layers)
Global.current_project.undo_redo.add_undo_method(Global, "undo")
Global.current_project.undo_redo.add_do_method(Global, "redo")
Global.current_project.undo_redo.commit_action()
DrawGD.current_project.undo_redo.add_undo_method(DrawGD, "undo")
DrawGD.current_project.undo_redo.add_do_method(DrawGD, "redo")
DrawGD.current_project.undo_redo.commit_action()
func _on_RemoveLayer_pressed() -> void:
if Global.current_project.layers.size() == 1:
if DrawGD.current_project.layers.size() == 1:
return
var new_layers : Array = Global.current_project.layers.duplicate()
new_layers.remove(Global.current_project.current_layer)
Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Remove Layer")
if Global.current_project.current_layer > 0:
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_layer", Global.current_project.current_layer - 1)
var new_layers : Array = DrawGD.current_project.layers.duplicate()
new_layers.remove(DrawGD.current_project.current_layer)
DrawGD.current_project.undos += 1
DrawGD.current_project.undo_redo.create_action("Remove Layer")
if DrawGD.current_project.current_layer > 0:
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "current_layer", DrawGD.current_project.current_layer - 1)
else:
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_layer", Global.current_project.current_layer)
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "current_layer", DrawGD.current_project.current_layer)
for f in Global.current_project.frames:
for f in DrawGD.current_project.frames:
var new_cels : Array = f.cels.duplicate()
new_cels.remove(Global.current_project.current_layer)
Global.current_project.undo_redo.add_do_property(f, "cels", new_cels)
Global.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
new_cels.remove(DrawGD.current_project.current_layer)
DrawGD.current_project.undo_redo.add_do_property(f, "cels", new_cels)
DrawGD.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_layer", Global.current_project.current_layer)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
Global.current_project.undo_redo.add_do_method(Global, "redo")
Global.current_project.undo_redo.add_undo_method(Global, "undo")
Global.current_project.undo_redo.commit_action()
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "layers", new_layers)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "current_layer", DrawGD.current_project.current_layer)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "layers", DrawGD.current_project.layers)
DrawGD.current_project.undo_redo.add_do_method(DrawGD, "redo")
DrawGD.current_project.undo_redo.add_undo_method(DrawGD, "undo")
DrawGD.current_project.undo_redo.commit_action()
func change_layer_order(rate : int) -> void:
var change = Global.current_project.current_layer + rate
var change = DrawGD.current_project.current_layer + rate
var new_layers : Array = Global.current_project.layers.duplicate()
var temp = new_layers[Global.current_project.current_layer]
new_layers[Global.current_project.current_layer] = new_layers[change]
var new_layers : Array = DrawGD.current_project.layers.duplicate()
var temp = new_layers[DrawGD.current_project.current_layer]
new_layers[DrawGD.current_project.current_layer] = new_layers[change]
new_layers[change] = temp
Global.current_project.undo_redo.create_action("Change Layer Order")
for f in Global.current_project.frames:
DrawGD.current_project.undo_redo.create_action("Change Layer Order")
for f in DrawGD.current_project.frames:
var new_cels : Array = f.cels.duplicate()
var temp_canvas = new_cels[Global.current_project.current_layer]
new_cels[Global.current_project.current_layer] = new_cels[change]
var temp_canvas = new_cels[DrawGD.current_project.current_layer]
new_cels[DrawGD.current_project.current_layer] = new_cels[change]
new_cels[change] = temp_canvas
Global.current_project.undo_redo.add_do_property(f, "cels", new_cels)
Global.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
DrawGD.current_project.undo_redo.add_do_property(f, "cels", new_cels)
DrawGD.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_layer", change)
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_layer", Global.current_project.current_layer)
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "current_layer", change)
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "layers", new_layers)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "layers", DrawGD.current_project.layers)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "current_layer", DrawGD.current_project.current_layer)
Global.current_project.undo_redo.add_undo_method(Global, "undo")
Global.current_project.undo_redo.add_do_method(Global, "redo")
Global.current_project.undo_redo.commit_action()
DrawGD.current_project.undo_redo.add_undo_method(DrawGD, "undo")
DrawGD.current_project.undo_redo.add_do_method(DrawGD, "redo")
DrawGD.current_project.undo_redo.commit_action()
func _on_MergeDownLayer_pressed() -> void:
var new_layers : Array = Global.current_project.layers.duplicate()
var new_layers : Array = DrawGD.current_project.layers.duplicate()
# Loop through the array to create new classes for each element, so that they
# won't be the same as the original array's classes. Needed for undo/redo to work properly.
for i in new_layers.size():
var new_linked_cels = new_layers[i].linked_cels.duplicate()
new_layers[i] = Layer.new(new_layers[i].name, new_layers[i].visible, new_layers[i].locked, new_layers[i].frame_container, new_layers[i].new_cels_linked, new_linked_cels)
Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Merge Layer")
for f in Global.current_project.frames:
DrawGD.current_project.undos += 1
DrawGD.current_project.undo_redo.create_action("Merge Layer")
for f in DrawGD.current_project.frames:
var new_cels : Array = f.cels.duplicate()
for i in new_cels.size():
new_cels[i] = Cel.new(new_cels[i].image, new_cels[i].opacity)
var selected_layer := Image.new()
selected_layer.copy_from(new_cels[Global.current_project.current_layer].image)
selected_layer.copy_from(new_cels[DrawGD.current_project.current_layer].image)
selected_layer.lock()
if f.cels[Global.current_project.current_layer].opacity < 1: # If we have layer transparency
if f.cels[DrawGD.current_project.current_layer].opacity < 1: # If we have layer transparency
for xx in selected_layer.get_size().x:
for yy in selected_layer.get_size().y:
var pixel_color : Color = selected_layer.get_pixel(xx, yy)
var alpha : float = pixel_color.a * f.cels[Global.current_project.current_layer].opacity
var alpha : float = pixel_color.a * f.cels[DrawGD.current_project.current_layer].opacity
selected_layer.set_pixel(xx, yy, Color(pixel_color.r, pixel_color.g, pixel_color.b, alpha))
var new_layer := Image.new()
new_layer.copy_from(f.cels[Global.current_project.current_layer - 1].image)
new_layer.copy_from(f.cels[DrawGD.current_project.current_layer - 1].image)
new_layer.lock()
new_layer.blend_rect(selected_layer, Rect2(Global.canvas.location, Global.current_project.size), Vector2.ZERO)
new_cels.remove(Global.current_project.current_layer)
if !selected_layer.is_invisible() and Global.current_project.layers[Global.current_project.current_layer - 1].linked_cels.size() > 1 and (f in Global.current_project.layers[Global.current_project.current_layer - 1].linked_cels):
new_layers[Global.current_project.current_layer - 1].linked_cels.erase(f)
new_cels[Global.current_project.current_layer - 1].image = new_layer
new_layer.blend_rect(selected_layer, Rect2(DrawGD.canvas.location, DrawGD.current_project.size), Vector2.ZERO)
new_cels.remove(DrawGD.current_project.current_layer)
if !selected_layer.is_invisible() and DrawGD.current_project.layers[DrawGD.current_project.current_layer - 1].linked_cels.size() > 1 and (f in DrawGD.current_project.layers[DrawGD.current_project.current_layer - 1].linked_cels):
new_layers[DrawGD.current_project.current_layer - 1].linked_cels.erase(f)
new_cels[DrawGD.current_project.current_layer - 1].image = new_layer
else:
Global.current_project.undo_redo.add_do_property(f.cels[Global.current_project.current_layer - 1].image, "data", new_layer.data)
Global.current_project.undo_redo.add_undo_property(f.cels[Global.current_project.current_layer - 1].image, "data", f.cels[Global.current_project.current_layer - 1].image.data)
DrawGD.current_project.undo_redo.add_do_property(f.cels[DrawGD.current_project.current_layer - 1].image, "data", new_layer.data)
DrawGD.current_project.undo_redo.add_undo_property(f.cels[DrawGD.current_project.current_layer - 1].image, "data", f.cels[DrawGD.current_project.current_layer - 1].image.data)
Global.current_project.undo_redo.add_do_property(f, "cels", new_cels)
Global.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
DrawGD.current_project.undo_redo.add_do_property(f, "cels", new_cels)
DrawGD.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
new_layers.remove(Global.current_project.current_layer)
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_layer", Global.current_project.current_layer - 1)
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_layer", Global.current_project.current_layer)
new_layers.remove(DrawGD.current_project.current_layer)
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "current_layer", DrawGD.current_project.current_layer - 1)
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "layers", new_layers)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "layers", DrawGD.current_project.layers)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "current_layer", DrawGD.current_project.current_layer)
Global.current_project.undo_redo.add_undo_method(Global, "undo")
Global.current_project.undo_redo.add_do_method(Global, "redo")
Global.current_project.undo_redo.commit_action()
DrawGD.current_project.undo_redo.add_undo_method(DrawGD, "undo")
DrawGD.current_project.undo_redo.add_do_method(DrawGD, "redo")
DrawGD.current_project.undo_redo.commit_action()
func _on_OpacitySlider_value_changed(value) -> void:
Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].opacity = value / 100
Global.layer_opacity_slider.value = value
Global.layer_opacity_slider.value = value
Global.layer_opacity_spinbox.value = value
Global.canvas.update()
DrawGD.current_project.frames[DrawGD.current_project.current_frame].cels[DrawGD.current_project.current_layer].opacity = value / 100
DrawGD.layer_opacity_slider.value = value
DrawGD.layer_opacity_slider.value = value
DrawGD.layer_opacity_spinbox.value = value
DrawGD.canvas.update()
func _on_OnionSkinningSettings_popup_hide() -> void:
Global.can_draw = true
DrawGD.can_draw = true

View File

@ -8,7 +8,7 @@ onready var popup_menu : PopupMenu = $PopupMenu
func _ready() -> void:
hint_tooltip = tr("Frame: %s, Layer: %s") % [frame + 1, layer]
if Global.current_project.frames[frame] in Global.current_project.layers[layer].linked_cels:
if DrawGD.current_project.frames[frame] in DrawGD.current_project.layers[layer].linked_cels:
get_node("LinkedIndicator").visible = true
popup_menu.set_item_text(4, "Unlink Cel")
popup_menu.set_item_metadata(4, "Unlink Cel")
@ -24,10 +24,10 @@ func _ready() -> void:
func _on_CelButton_pressed() -> void:
if Input.is_action_just_released("left_mouse"):
Global.current_project.current_frame = frame
Global.current_project.current_layer = layer
DrawGD.current_project.current_frame = frame
DrawGD.current_project.current_layer = layer
elif Input.is_action_just_released("right_mouse"):
if Global.current_project.frames.size() == 1:
if DrawGD.current_project.frames.size() == 1:
popup_menu.set_item_disabled(0, true)
popup_menu.set_item_disabled(2, true)
popup_menu.set_item_disabled(3, true)
@ -35,13 +35,13 @@ func _on_CelButton_pressed() -> void:
popup_menu.set_item_disabled(0, false)
if frame > 0:
popup_menu.set_item_disabled(2, false)
if frame < Global.current_project.frames.size() - 1:
if frame < DrawGD.current_project.frames.size() - 1:
popup_menu.set_item_disabled(3, false)
popup_menu.popup(Rect2(get_global_mouse_position(), Vector2.ONE))
pressed = !pressed
elif Input.is_action_just_released("middle_mouse"): # Middle mouse click
pressed = !pressed
Global.animation_timeline._on_DeleteFrame_pressed(frame)
DrawGD.animation_timeline._on_DeleteFrame_pressed(frame)
else: # An example of this would be Space
pressed = !pressed
@ -49,17 +49,17 @@ func _on_CelButton_pressed() -> void:
func _on_PopupMenu_id_pressed(ID : int) -> void:
match ID:
0: # Remove Frame
Global.animation_timeline._on_DeleteFrame_pressed(frame)
DrawGD.animation_timeline._on_DeleteFrame_pressed(frame)
1: # Clone Frame
Global.animation_timeline._on_CopyFrame_pressed(frame)
DrawGD.animation_timeline._on_CopyFrame_pressed(frame)
2: # Move Left
change_frame_order(-1)
3: # Move Right
change_frame_order(1)
4: # Unlink Cel
var cel_index : int = Global.current_project.layers[layer].linked_cels.find(Global.current_project.frames[frame])
var f = Global.current_project.frames[frame]
var new_layers : Array = Global.current_project.layers.duplicate()
var cel_index : int = DrawGD.current_project.layers[layer].linked_cels.find(DrawGD.current_project.frames[frame])
var f = DrawGD.current_project.frames[frame]
var new_layers : Array = DrawGD.current_project.layers.duplicate()
# Loop through the array to create new classes for each element, so that they
# won't be the same as the original array's classes. Needed for undo/redo to work properly.
for i in new_layers.size():
@ -72,53 +72,53 @@ func _on_PopupMenu_id_pressed(ID : int) -> void:
if popup_menu.get_item_metadata(4) == "Unlink Cel":
new_layers[layer].linked_cels.remove(cel_index)
var sprite := Image.new()
sprite.copy_from(Global.current_project.frames[frame].cels[layer].image)
sprite.copy_from(DrawGD.current_project.frames[frame].cels[layer].image)
sprite.lock()
new_cels[layer].image = sprite
Global.current_project.undo_redo.create_action("Unlink Cel")
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
Global.current_project.undo_redo.add_do_property(f, "cels", new_cels)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
Global.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
DrawGD.current_project.undo_redo.create_action("Unlink Cel")
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "layers", new_layers)
DrawGD.current_project.undo_redo.add_do_property(f, "cels", new_cels)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "layers", DrawGD.current_project.layers)
DrawGD.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
Global.current_project.undo_redo.add_undo_method(Global, "undo")
Global.current_project.undo_redo.add_do_method(Global, "redo")
Global.current_project.undo_redo.commit_action()
DrawGD.current_project.undo_redo.add_undo_method(DrawGD, "undo")
DrawGD.current_project.undo_redo.add_do_method(DrawGD, "redo")
DrawGD.current_project.undo_redo.commit_action()
elif popup_menu.get_item_metadata(4) == "Link Cel":
new_layers[layer].linked_cels.append(Global.current_project.frames[frame])
Global.current_project.undo_redo.create_action("Link Cel")
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
new_layers[layer].linked_cels.append(DrawGD.current_project.frames[frame])
DrawGD.current_project.undo_redo.create_action("Link Cel")
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "layers", new_layers)
if new_layers[layer].linked_cels.size() > 1:
# If there are already linked cels, set the current cel's image
# to the first linked cel's image
new_cels[layer].image = new_layers[layer].linked_cels[0].cels[layer].image
new_cels[layer].image_texture = new_layers[layer].linked_cels[0].cels[layer].image_texture
Global.current_project.undo_redo.add_do_property(f, "cels", new_cels)
Global.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
DrawGD.current_project.undo_redo.add_do_property(f, "cels", new_cels)
DrawGD.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
Global.current_project.undo_redo.add_undo_method(Global, "undo")
Global.current_project.undo_redo.add_do_method(Global, "redo")
Global.current_project.undo_redo.commit_action()
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "layers", DrawGD.current_project.layers)
DrawGD.current_project.undo_redo.add_undo_method(DrawGD, "undo")
DrawGD.current_project.undo_redo.add_do_method(DrawGD, "redo")
DrawGD.current_project.undo_redo.commit_action()
func change_frame_order(rate : int) -> void:
var change = frame + rate
var new_frames : Array = Global.current_project.frames.duplicate()
var new_frames : Array = DrawGD.current_project.frames.duplicate()
var temp = new_frames[frame]
new_frames[frame] = new_frames[change]
new_frames[change] = temp
Global.current_project.undo_redo.create_action("Change Frame Order")
Global.current_project.undo_redo.add_do_property(Global.current_project, "frames", new_frames)
DrawGD.current_project.undo_redo.create_action("Change Frame Order")
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "frames", new_frames)
if Global.current_project.current_frame == frame:
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_frame", change)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_frame", Global.current_project.current_frame)
if DrawGD.current_project.current_frame == frame:
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "current_frame", change)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "current_frame", DrawGD.current_project.current_frame)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "frames", Global.current_project.frames)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "frames", DrawGD.current_project.frames)
Global.current_project.undo_redo.add_undo_method(Global, "undo")
Global.current_project.undo_redo.add_do_method(Global, "redo")
Global.current_project.undo_redo.commit_action()
DrawGD.current_project.undo_redo.add_undo_method(DrawGD, "undo")
DrawGD.current_project.undo_redo.add_do_method(DrawGD, "redo")
DrawGD.current_project.undo_redo.commit_action()

View File

@ -15,13 +15,13 @@ func _ready() -> void:
func _on_FrameTagDialog_about_to_show() -> void:
Global.dialog_open(true)
DrawGD.dialog_open(true)
for vbox in tag_vboxes:
vbox.queue_free()
tag_vboxes.clear()
var i := 0
for tag in Global.current_project.animation_tags:
for tag in DrawGD.current_project.animation_tags:
var vbox_cont := VBoxContainer.new()
var hbox_cont := HBoxContainer.new()
var tag_label := Label.new()
@ -57,23 +57,23 @@ func _on_FrameTagDialog_about_to_show() -> void:
func _on_FrameTagDialog_popup_hide() -> void:
Global.dialog_open(false)
DrawGD.dialog_open(false)
func _on_AddTag_pressed() -> void:
options_dialog.popup_centered()
current_tag_id = Global.current_project.animation_tags.size()
options_dialog.get_node("GridContainer/FromSpinBox").value = Global.current_project.current_frame + 1
options_dialog.get_node("GridContainer/ToSpinBox").value = Global.current_project.current_frame + 1
current_tag_id = DrawGD.current_project.animation_tags.size()
options_dialog.get_node("GridContainer/FromSpinBox").value = DrawGD.current_project.current_frame + 1
options_dialog.get_node("GridContainer/ToSpinBox").value = DrawGD.current_project.current_frame + 1
func _on_EditButton_pressed(_tag_id : int) -> void:
options_dialog.popup_centered()
current_tag_id = _tag_id
options_dialog.get_node("GridContainer/NameLineEdit").text = Global.current_project.animation_tags[_tag_id].name
options_dialog.get_node("GridContainer/ColorPickerButton").color = Global.current_project.animation_tags[_tag_id].color
options_dialog.get_node("GridContainer/FromSpinBox").value = Global.current_project.animation_tags[_tag_id].from
options_dialog.get_node("GridContainer/ToSpinBox").value = Global.current_project.animation_tags[_tag_id].to
options_dialog.get_node("GridContainer/NameLineEdit").text = DrawGD.current_project.animation_tags[_tag_id].name
options_dialog.get_node("GridContainer/ColorPickerButton").color = DrawGD.current_project.animation_tags[_tag_id].color
options_dialog.get_node("GridContainer/FromSpinBox").value = DrawGD.current_project.animation_tags[_tag_id].from
options_dialog.get_node("GridContainer/ToSpinBox").value = DrawGD.current_project.animation_tags[_tag_id].to
if !delete_tag_button:
delete_tag_button = options_dialog.add_button("Delete", true, "delete_tag")
else:
@ -86,19 +86,19 @@ func _on_TagOptions_confirmed() -> void:
var tag_from : int = options_dialog.get_node("GridContainer/FromSpinBox").value
var tag_to : int = options_dialog.get_node("GridContainer/ToSpinBox").value
if tag_to > Global.current_project.frames.size():
tag_to = Global.current_project.frames.size()
if tag_to > DrawGD.current_project.frames.size():
tag_to = DrawGD.current_project.frames.size()
if tag_from > tag_to:
tag_from = tag_to
var new_animation_tags := Global.current_project.animation_tags.duplicate()
var new_animation_tags := DrawGD.current_project.animation_tags.duplicate()
# Loop through the tags to create new classes for them, so that they won't be the same
# as Global.current_project.animation_tags's classes. Needed for undo/redo to work properly.
# as DrawGD.current_project.animation_tags's classes. Needed for undo/redo to work properly.
for i in new_animation_tags.size():
new_animation_tags[i] = AnimationTag.new(new_animation_tags[i].name, new_animation_tags[i].color, new_animation_tags[i].from, new_animation_tags[i].to)
if current_tag_id == Global.current_project.animation_tags.size():
if current_tag_id == DrawGD.current_project.animation_tags.size():
new_animation_tags.append(AnimationTag.new(tag_name, tag_color, tag_from, tag_to))
else:
new_animation_tags[current_tag_id].name = tag_name
@ -107,28 +107,28 @@ func _on_TagOptions_confirmed() -> void:
new_animation_tags[current_tag_id].to = tag_to
# Handle Undo/Redo
Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Modify Frame Tag")
Global.current_project.undo_redo.add_do_method(Global, "general_redo")
Global.current_project.undo_redo.add_undo_method(Global, "general_undo")
Global.current_project.undo_redo.add_do_property(Global.current_project, "animation_tags", new_animation_tags)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "animation_tags", Global.current_project.animation_tags)
Global.current_project.undo_redo.commit_action()
DrawGD.current_project.undos += 1
DrawGD.current_project.undo_redo.create_action("Modify Frame Tag")
DrawGD.current_project.undo_redo.add_do_method(DrawGD, "general_redo")
DrawGD.current_project.undo_redo.add_undo_method(DrawGD, "general_undo")
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "animation_tags", new_animation_tags)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "animation_tags", DrawGD.current_project.animation_tags)
DrawGD.current_project.undo_redo.commit_action()
_on_FrameTagDialog_about_to_show()
func _on_TagOptions_custom_action(action : String) -> void:
if action == "delete_tag":
var new_animation_tags := Global.current_project.animation_tags.duplicate()
var new_animation_tags := DrawGD.current_project.animation_tags.duplicate()
new_animation_tags.remove(current_tag_id)
# Handle Undo/Redo
Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Delete Frame Tag")
Global.current_project.undo_redo.add_do_method(Global, "general_redo")
Global.current_project.undo_redo.add_undo_method(Global, "general_undo")
Global.current_project.undo_redo.add_do_property(Global.current_project, "animation_tags", new_animation_tags)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "animation_tags", Global.current_project.animation_tags)
Global.current_project.undo_redo.commit_action()
DrawGD.current_project.undos += 1
DrawGD.current_project.undo_redo.create_action("Delete Frame Tag")
DrawGD.current_project.undo_redo.add_do_method(DrawGD, "general_redo")
DrawGD.current_project.undo_redo.add_undo_method(DrawGD, "general_undo")
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "animation_tags", new_animation_tags)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "animation_tags", DrawGD.current_project.animation_tags)
DrawGD.current_project.undo_redo.commit_action()
options_dialog.hide()
_on_FrameTagDialog_about_to_show()
@ -140,4 +140,4 @@ func _on_TagOptions_popup_hide() -> void:
func _on_PlayOnlyTags_toggled(button_pressed : bool) -> void:
Global.play_only_tags = button_pressed
DrawGD.play_only_tags = button_pressed

View File

@ -10,30 +10,30 @@ var line_edit : LineEdit
func _ready() -> void:
visibility_button = Global.find_node_by_name(self, "VisibilityButton")
lock_button = Global.find_node_by_name(self, "LockButton")
linked_button = Global.find_node_by_name(self, "LinkButton")
label = Global.find_node_by_name(self, "Label")
line_edit = Global.find_node_by_name(self, "LineEdit")
visibility_button = DrawGD.find_node_by_name(self, "VisibilityButton")
lock_button = DrawGD.find_node_by_name(self, "LockButton")
linked_button = DrawGD.find_node_by_name(self, "LinkButton")
label = DrawGD.find_node_by_name(self, "Label")
line_edit = DrawGD.find_node_by_name(self, "LineEdit")
if Global.current_project.layers[i].visible:
Global.change_button_texturerect(visibility_button.get_child(0), "layer_visible.png")
if DrawGD.current_project.layers[i].visible:
DrawGD.change_button_texturerect(visibility_button.get_child(0), "layer_visible.png")
visibility_button.get_child(0).rect_size = Vector2(24, 14)
visibility_button.get_child(0).rect_position = Vector2(4, 9)
else:
Global.change_button_texturerect(visibility_button.get_child(0), "layer_invisible.png")
DrawGD.change_button_texturerect(visibility_button.get_child(0), "layer_invisible.png")
visibility_button.get_child(0).rect_size = Vector2(24, 8)
visibility_button.get_child(0).rect_position = Vector2(4, 12)
if Global.current_project.layers[i].locked:
Global.change_button_texturerect(lock_button.get_child(0), "lock.png")
if DrawGD.current_project.layers[i].locked:
DrawGD.change_button_texturerect(lock_button.get_child(0), "lock.png")
else:
Global.change_button_texturerect(lock_button.get_child(0), "unlock.png")
DrawGD.change_button_texturerect(lock_button.get_child(0), "unlock.png")
if Global.current_project.layers[i].new_cels_linked: # If new layers will be linked
Global.change_button_texturerect(linked_button.get_child(0), "linked_layer.png")
if DrawGD.current_project.layers[i].new_cels_linked: # If new layers will be linked
DrawGD.change_button_texturerect(linked_button.get_child(0), "linked_layer.png")
else:
Global.change_button_texturerect(linked_button.get_child(0), "unlinked_layer.png")
DrawGD.change_button_texturerect(linked_button.get_child(0), "unlinked_layer.png")
func _input(event : InputEvent) -> void:
@ -58,22 +58,22 @@ func save_layer_name(new_name : String) -> void:
line_edit.visible = false
line_edit.editable = false
label.text = new_name
Global.layers_changed_skip = true
Global.current_project.layers[i].name = new_name
DrawGD.layers_changed_skip = true
DrawGD.current_project.layers[i].name = new_name
func _on_VisibilityButton_pressed() -> void:
Global.current_project.layers[i].visible = !Global.current_project.layers[i].visible
Global.canvas.update()
DrawGD.current_project.layers[i].visible = !DrawGD.current_project.layers[i].visible
DrawGD.canvas.update()
func _on_LockButton_pressed() -> void:
Global.current_project.layers[i].locked = !Global.current_project.layers[i].locked
DrawGD.current_project.layers[i].locked = !DrawGD.current_project.layers[i].locked
func _on_LinkButton_pressed() -> void:
Global.current_project.layers[i].new_cels_linked = !Global.current_project.layers[i].new_cels_linked
if Global.current_project.layers[i].new_cels_linked && !Global.current_project.layers[i].linked_cels:
DrawGD.current_project.layers[i].new_cels_linked = !DrawGD.current_project.layers[i].new_cels_linked
if DrawGD.current_project.layers[i].new_cels_linked && !DrawGD.current_project.layers[i].linked_cels:
# If button is pressed and there are no linked cels in the layer
Global.current_project.layers[i].linked_cels.append(Global.current_project.frames[Global.current_project.current_frame])
Global.current_project.layers[i].frame_container.get_child(Global.current_project.current_frame)._ready()
DrawGD.current_project.layers[i].linked_cels.append(DrawGD.current_project.frames[DrawGD.current_project.current_frame])
DrawGD.current_project.layers[i].frame_container.get_child(DrawGD.current_project.current_frame)._ready()

View File

@ -16,11 +16,11 @@ onready var tools := [
func _ready() -> void:
for t in tools:
t[0].connect("pressed", self, "_on_Tool_pressed", [t[0]])
Global.update_hint_tooltips()
DrawGD.update_hint_tooltips()
func _input(event : InputEvent) -> void:
if not Global.has_focus:
if not DrawGD.has_focus:
return
for action in ["undo", "redo", "redo_secondary"]:
if event.is_action_pressed(action):

View File

@ -27,7 +27,7 @@ func setup_file_menu() -> void:
"Export as..." : InputMap.get_action_list("export_file_as")[0].get_scancode_with_modifiers(),
"Quit" : InputMap.get_action_list("quit")[0].get_scancode_with_modifiers(),
}
file_menu = Global.file_menu.get_popup()
file_menu = DrawGD.file_menu.get_popup()
var i := 0
for item in file_menu_items.keys():
@ -51,7 +51,7 @@ func setup_edit_menu() -> void:
"Clear Selection" : 0,
"Preferences" : 0
}
var edit_menu : PopupMenu = Global.edit_menu.get_popup()
var edit_menu : PopupMenu = DrawGD.edit_menu.get_popup()
var i := 0
for item in edit_menu_items.keys():
@ -71,7 +71,7 @@ func setup_view_menu() -> void:
"Zen Mode" : InputMap.get_action_list("zen_mode")[0].get_scancode_with_modifiers(),
"Fullscreen Mode" : InputMap.get_action_list("toggle_fullscreen")[0].get_scancode_with_modifiers(),
}
view_menu = Global.view_menu.get_popup()
view_menu = DrawGD.view_menu.get_popup()
var i := 0
for item in view_menu_items.keys():
@ -99,7 +99,7 @@ func setup_image_menu() -> void:
"Gradient" : 0,
# "Shader" : 0
}
var image_menu : PopupMenu = Global.image_menu.get_popup()
var image_menu : PopupMenu = DrawGD.image_menu.get_popup()
var i := 0
for item in image_menu_items.keys():
@ -126,59 +126,59 @@ func file_menu_id_pressed(id : int) -> void:
5: # Export
export_file()
6: # Export as
Global.export_dialog.popup_centered()
Global.dialog_open(true)
DrawGD.export_dialog.popup_centered()
DrawGD.dialog_open(true)
7: # Quit
Global.control.show_quit_dialog()
DrawGD.control.show_quit_dialog()
func on_new_project_file_menu_option_pressed() -> void:
Global.new_image_dialog.popup_centered()
Global.dialog_open(true)
DrawGD.new_image_dialog.popup_centered()
DrawGD.dialog_open(true)
func open_project_file() -> void:
Global.open_sprites_dialog.popup_centered()
Global.dialog_open(true)
Global.control.opensprite_file_selected = false
DrawGD.open_sprites_dialog.popup_centered()
DrawGD.dialog_open(true)
DrawGD.control.opensprite_file_selected = false
func on_open_last_project_file_menu_option_pressed() -> void:
# Check if last project path is set and if yes then open
if Global.config_cache.has_section_key("preferences", "last_project_path"):
Global.control.load_last_project()
if DrawGD.config_cache.has_section_key("preferences", "last_project_path"):
DrawGD.control.load_last_project()
else: # if not then warn user that he didn't edit any project yet
Global.error_dialog.set_text("You haven't saved or opened any project in Pixelorama yet!")
Global.error_dialog.popup_centered()
Global.dialog_open(true)
DrawGD.error_dialog.set_text("You haven't saved or opened any project in Pixelorama yet!")
DrawGD.error_dialog.popup_centered()
DrawGD.dialog_open(true)
func save_project_file() -> void:
Global.control.is_quitting_on_save = false
var path = OpenSave.current_save_paths[Global.current_project_index]
DrawGD.control.is_quitting_on_save = false
var path = OpenSave.current_save_paths[DrawGD.current_project_index]
if path == "":
if OS.get_name() == "HTML5":
Global.save_sprites_html5_dialog.popup_centered()
DrawGD.save_sprites_html5_dialog.popup_centered()
else:
Global.save_sprites_dialog.popup_centered()
Global.dialog_open(true)
DrawGD.save_sprites_dialog.popup_centered()
DrawGD.dialog_open(true)
else:
Global.control._on_SaveSprite_file_selected(path)
DrawGD.control._on_SaveSprite_file_selected(path)
func save_project_file_as() -> void:
Global.control.is_quitting_on_save = false
DrawGD.control.is_quitting_on_save = false
if OS.get_name() == "HTML5":
Global.save_sprites_html5_dialog.popup_centered()
DrawGD.save_sprites_html5_dialog.popup_centered()
else:
Global.save_sprites_dialog.popup_centered()
Global.dialog_open(true)
DrawGD.save_sprites_dialog.popup_centered()
DrawGD.dialog_open(true)
func export_file() -> void:
if was_exported == false:
Global.export_dialog.popup_centered()
Global.dialog_open(true)
DrawGD.export_dialog.popup_centered()
DrawGD.dialog_open(true)
else:
Export.external_export()
@ -186,25 +186,25 @@ func export_file() -> void:
func edit_menu_id_pressed(id : int) -> void:
match id:
0: # Undo
Global.current_project.undo_redo.undo()
DrawGD.current_project.undo_redo.undo()
1: # Redo
Global.control.redone = true
Global.current_project.undo_redo.redo()
Global.control.redone = false
DrawGD.control.redone = true
DrawGD.current_project.undo_redo.redo()
DrawGD.control.redone = false
2: # Copy
Global.selection_rectangle.copy()
DrawGD.selection_rectangle.copy()
3: # cut
Global.selection_rectangle.cut()
DrawGD.selection_rectangle.cut()
4: # paste
Global.selection_rectangle.paste()
DrawGD.selection_rectangle.paste()
5: # Delete
Global.selection_rectangle.delete()
DrawGD.selection_rectangle.delete()
6: # Clear selection
Global.selection_rectangle.set_rect(Rect2(0, 0, 0, 0))
Global.selection_rectangle.select_rect()
DrawGD.selection_rectangle.set_rect(Rect2(0, 0, 0, 0))
DrawGD.selection_rectangle.select_rect()
7: # Preferences
Global.preferences_dialog.popup_centered(Vector2(400, 280))
Global.dialog_open(true)
DrawGD.preferences_dialog.popup_centered(Vector2(400, 280))
DrawGD.dialog_open(true)
func view_menu_id_pressed(id : int) -> void:
@ -224,54 +224,54 @@ func view_menu_id_pressed(id : int) -> void:
6: # Fullscreen mode
toggle_fullscreen()
Global.canvas.update()
DrawGD.canvas.update()
func toggle_tile_mode() -> void:
Global.tile_mode = !Global.tile_mode
view_menu.set_item_checked(0, Global.tile_mode)
DrawGD.tile_mode = !DrawGD.tile_mode
view_menu.set_item_checked(0, DrawGD.tile_mode)
func toggle_show_grid() -> void:
Global.draw_grid = !Global.draw_grid
view_menu.set_item_checked(1, Global.draw_grid)
Global.canvas.grid.update()
DrawGD.draw_grid = !DrawGD.draw_grid
view_menu.set_item_checked(1, DrawGD.draw_grid)
DrawGD.canvas.grid.update()
func toggle_show_rulers() -> void:
Global.show_rulers = !Global.show_rulers
view_menu.set_item_checked(2, Global.show_rulers)
Global.horizontal_ruler.visible = Global.show_rulers
Global.vertical_ruler.visible = Global.show_rulers
DrawGD.show_rulers = !DrawGD.show_rulers
view_menu.set_item_checked(2, DrawGD.show_rulers)
DrawGD.horizontal_ruler.visible = DrawGD.show_rulers
DrawGD.vertical_ruler.visible = DrawGD.show_rulers
func toggle_show_guides() -> void:
Global.show_guides = !Global.show_guides
view_menu.set_item_checked(3, Global.show_guides)
for guide in Global.canvas.get_children():
if guide is Guide and guide in Global.current_project.guides:
guide.visible = Global.show_guides
DrawGD.show_guides = !DrawGD.show_guides
view_menu.set_item_checked(3, DrawGD.show_guides)
for guide in DrawGD.canvas.get_children():
if guide is Guide and guide in DrawGD.current_project.guides:
guide.visible = DrawGD.show_guides
if guide is SymmetryGuide:
if guide.type == Guide.Types.HORIZONTAL:
guide.visible = Global.show_x_symmetry_axis and Global.show_guides
guide.visible = DrawGD.show_x_symmetry_axis and DrawGD.show_guides
else:
guide.visible = Global.show_y_symmetry_axis and Global.show_guides
guide.visible = DrawGD.show_y_symmetry_axis and DrawGD.show_guides
func toggle_show_anim_timeline() -> void:
if zen_mode:
return
Global.show_animation_timeline = !Global.show_animation_timeline
view_menu.set_item_checked(4, Global.show_animation_timeline)
Global.animation_timeline.visible = Global.show_animation_timeline
DrawGD.show_animation_timeline = !DrawGD.show_animation_timeline
view_menu.set_item_checked(4, DrawGD.show_animation_timeline)
DrawGD.animation_timeline.visible = DrawGD.show_animation_timeline
func toggle_zen_mode() -> void:
if Global.show_animation_timeline:
Global.animation_timeline.visible = zen_mode
Global.control.get_node("MenuAndUI/UI/ToolPanel").visible = zen_mode
Global.control.get_node("MenuAndUI/UI/RightPanel").visible = zen_mode
Global.control.get_node("MenuAndUI/UI/CanvasAndTimeline/ViewportAndRulers/TabsContainer").visible = zen_mode
if DrawGD.show_animation_timeline:
DrawGD.animation_timeline.visible = zen_mode
DrawGD.control.get_node("MenuAndUI/UI/ToolPanel").visible = zen_mode
DrawGD.control.get_node("MenuAndUI/UI/RightPanel").visible = zen_mode
DrawGD.control.get_node("MenuAndUI/UI/CanvasAndTimeline/ViewportAndRulers/TabsContainer").visible = zen_mode
zen_mode = !zen_mode
view_menu.set_item_checked(5, zen_mode)
@ -282,9 +282,9 @@ func toggle_fullscreen() -> void:
func image_menu_id_pressed(id : int) -> void:
if Global.current_project.layers[Global.current_project.current_layer].locked: # No changes if the layer is locked
if DrawGD.current_project.layers[DrawGD.current_project.current_layer].locked: # No changes if the layer is locked
return
var image : Image = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image
var image : Image = DrawGD.current_project.frames[DrawGD.current_project.current_frame].cels[DrawGD.current_project.current_layer].image
match id:
0: # Scale Image
show_scale_image_popup()
@ -296,19 +296,19 @@ func image_menu_id_pressed(id : int) -> void:
show_resize_canvas_popup()
3: # Flip
Global.control.get_node("Dialogs/ImageEffects/FlipImageDialog").popup_centered()
Global.dialog_open(true)
DrawGD.control.get_node("Dialogs/ImageEffects/FlipImageDialog").popup_centered()
DrawGD.dialog_open(true)
4: # Rotate
show_rotate_image_popup()
5: # Invert Colors
Global.control.get_node("Dialogs/ImageEffects/InvertColorsDialog").popup_centered()
Global.dialog_open(true)
DrawGD.control.get_node("Dialogs/ImageEffects/InvertColorsDialog").popup_centered()
DrawGD.dialog_open(true)
6: # Desaturation
Global.control.get_node("Dialogs/ImageEffects/DesaturateDialog").popup_centered()
Global.dialog_open(true)
DrawGD.control.get_node("Dialogs/ImageEffects/DesaturateDialog").popup_centered()
DrawGD.dialog_open(true)
7: # Outline
show_add_outline_popup()
@ -317,34 +317,34 @@ func image_menu_id_pressed(id : int) -> void:
show_hsv_configuration_popup()
9: # Gradient
Global.control.get_node("Dialogs/ImageEffects/GradientDialog").popup_centered()
Global.dialog_open(true)
DrawGD.control.get_node("Dialogs/ImageEffects/GradientDialog").popup_centered()
DrawGD.dialog_open(true)
10: # Shader
Global.control.get_node("Dialogs/ImageEffects/ShaderEffect").popup_centered()
Global.dialog_open(true)
DrawGD.control.get_node("Dialogs/ImageEffects/ShaderEffect").popup_centered()
DrawGD.dialog_open(true)
func show_scale_image_popup() -> void:
Global.control.get_node("Dialogs/ImageEffects/ScaleImage").popup_centered()
Global.dialog_open(true)
DrawGD.control.get_node("Dialogs/ImageEffects/ScaleImage").popup_centered()
DrawGD.dialog_open(true)
func show_resize_canvas_popup() -> void:
Global.control.get_node("Dialogs/ImageEffects/ResizeCanvas").popup_centered()
Global.dialog_open(true)
DrawGD.control.get_node("Dialogs/ImageEffects/ResizeCanvas").popup_centered()
DrawGD.dialog_open(true)
func show_rotate_image_popup() -> void:
Global.control.get_node("Dialogs/ImageEffects/RotateImage").popup_centered()
Global.dialog_open(true)
DrawGD.control.get_node("Dialogs/ImageEffects/RotateImage").popup_centered()
DrawGD.dialog_open(true)
func show_add_outline_popup() -> void:
Global.control.get_node("Dialogs/ImageEffects/OutlineDialog").popup_centered()
Global.dialog_open(true)
DrawGD.control.get_node("Dialogs/ImageEffects/OutlineDialog").popup_centered()
DrawGD.dialog_open(true)
func show_hsv_configuration_popup() -> void:
Global.control.get_node("Dialogs/ImageEffects/HSVDialog").popup_centered()
Global.dialog_open(true)
DrawGD.control.get_node("Dialogs/ImageEffects/HSVDialog").popup_centered()
DrawGD.dialog_open(true)

View File

@ -2,15 +2,15 @@ extends ColorRect
func _ready() -> void:
rect_size = Global.current_project.size
if get_parent().get_parent() == Global.main_viewport:
Global.second_viewport.get_node("Viewport/TransparentChecker")._ready()
Global.small_preview_viewport.get_node("Viewport/TransparentChecker")._ready()
material.set_shader_param("size", Global.checker_size)
material.set_shader_param("color1", Global.checker_color_1)
material.set_shader_param("color2", Global.checker_color_2)
material.set_shader_param("follow_movement", Global.checker_follow_movement)
material.set_shader_param("follow_scale", Global.checker_follow_scale)
rect_size = DrawGD.current_project.size
if get_parent().get_parent() == DrawGD.main_viewport:
DrawGD.second_viewport.get_node("Viewport/TransparentChecker")._ready()
DrawGD.small_preview_viewport.get_node("Viewport/TransparentChecker")._ready()
material.set_shader_param("size", DrawGD.checker_size)
material.set_shader_param("color1", DrawGD.checker_color_1)
material.set_shader_param("color2", DrawGD.checker_color_2)
material.set_shader_param("follow_movement", DrawGD.checker_follow_movement)
material.set_shader_param("follow_scale", DrawGD.checker_follow_scale)
func update_offset(offset : Vector2, scale : Vector2) -> void:

View File

@ -2,8 +2,8 @@ extends ViewportContainer
func _on_ViewportContainer_mouse_entered() -> void:
Global.has_focus = true
DrawGD.has_focus = true
func _on_ViewportContainer_mouse_exited() -> void:
Global.has_focus = false
DrawGD.has_focus = false

View File

@ -63,10 +63,10 @@ func _init() -> void:
xdg_data_dirs = []
for unapp_subdir in raw_xdg_data_dirs:
xdg_data_dirs.append(unapp_subdir.plus_file(xdg_config_subdir_name))
xdg_data_dirs.append(Global.root_directory.plus_file(config_subdir_name))
xdg_data_dirs.append(DrawGD.root_directory.plus_file(config_subdir_name))
else:
raw_xdg_data_home = Global.root_directory
raw_xdg_data_home = DrawGD.root_directory
xdg_data_home = raw_xdg_data_home.plus_file(config_subdir_name)
raw_xdg_data_dirs = []
xdg_data_dirs = []