diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index 6a4987c26..56fb2eee4 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -44,8 +44,8 @@ var icon_color_from: int = IconColorFrom.THEME var custom_icon_color := Color.gray var tool_button_size: int = ButtonSize.SMALL -var default_image_width := 64 -var default_image_height := 64 +var default_width := 64 +var default_height := 64 var default_fill_color := Color(0, 0, 0, 0) var grid_type = GridTypes.CARTESIAN var grid_width := 2 @@ -179,20 +179,19 @@ func _ready() -> void: panel_layout = config_cache.get_value("window", "panel_layout", PanelLayout.AUTO) - default_image_width = config_cache.get_value( - "preferences", "default_image_width", default_image_width - ) - default_image_height = config_cache.get_value( - "preferences", "default_image_height", default_image_height - ) + default_width = config_cache.get_value("preferences", "default_width", default_width) + default_height = config_cache.get_value("preferences", "default_height", default_height) default_fill_color = config_cache.get_value( "preferences", "default_fill_color", default_fill_color ) - var proj_size := Vector2(default_image_width, default_image_height) + var proj_size := Vector2(default_width, default_height) projects.append(Project.new([], tr("untitled"), proj_size)) - projects[0].layers.append(Layer.new()) - projects[0].fill_color = default_fill_color current_project = projects[0] + current_project.layers.append(Layer.new()) + current_project.fill_color = default_fill_color + var frame: Frame = current_project.new_empty_frame() + current_project.frames.append(frame) + for node in get_tree().get_nodes_in_group("UIButtons"): var tooltip: String = node.hint_tooltip if !tooltip.empty() and node.shortcut: diff --git a/src/Classes/Project.gd b/src/Classes/Project.gd index 47c678cef..84e96bb52 100644 --- a/src/Classes/Project.gd +++ b/src/Classes/Project.gd @@ -101,6 +101,20 @@ func commit_redo() -> void: Global.control.redone = false +func new_empty_frame() -> Frame: + var frame := Frame.new() + var bottom_layer := true + for l in layers: # Create as many cels as there are layers + var image := Image.new() + image.create(size.x, size.y, false, Image.FORMAT_RGBA8) + if bottom_layer: + image.fill(fill_color) + frame.cels.append(Cel.new(image, 1)) + bottom_layer = false + + return frame + + func selection_bitmap_changed() -> void: var image := Image.new() var image_texture := ImageTexture.new() diff --git a/src/Preferences/PreferencesDialog.gd b/src/Preferences/PreferencesDialog.gd index bd639447d..28ff8ceb3 100644 --- a/src/Preferences/PreferencesDialog.gd +++ b/src/Preferences/PreferencesDialog.gd @@ -70,18 +70,8 @@ var preferences = [ "pressed", Global.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_width", "Image/ImageOptions/ImageDefaultWidth", "value", Global.default_width], + ["default_height", "Image/ImageOptions/ImageDefaultHeight", "value", Global.default_height], [ "default_fill_color", "Image/ImageOptions/DefaultFillColor", diff --git a/src/UI/Canvas/Canvas.gd b/src/UI/Canvas/Canvas.gd index 99b5004ca..217374460 100644 --- a/src/UI/Canvas/Canvas.gd +++ b/src/UI/Canvas/Canvas.gd @@ -20,9 +20,6 @@ func _ready() -> void: $OnionPast.blue_red_color = Color.blue $OnionFuture.type = $OnionFuture.FUTURE $OnionFuture.blue_red_color = Color.red - var project: Project = Global.current_project - var frame: Frame = new_empty_frame(project.fill_color, project.size) - project.frames.append(frame) yield(get_tree(), "idle_frame") camera_zoom() @@ -106,21 +103,6 @@ func camera_zoom() -> void: Global.transparent_checker.update_rect() -func new_empty_frame(fill_color: Color, size: Vector2, single_layer := false) -> Frame: - var frame := Frame.new() - for l in Global.current_project.layers: # Create as many cels as there are layers - # The sprite itself - var sprite := Image.new() - sprite.create(size.x, size.y, false, Image.FORMAT_RGBA8) - sprite.fill(fill_color) - frame.cels.append(Cel.new(sprite, 1)) - - if single_layer: - break - - return frame - - func update_texture(layer_i: int, frame_i := -1, project: Project = Global.current_project) -> void: if frame_i == -1: frame_i = project.current_frame diff --git a/src/UI/Dialogs/CreateNewImage.gd b/src/UI/Dialogs/CreateNewImage.gd index 4afdf46e8..99ce4d755 100644 --- a/src/UI/Dialogs/CreateNewImage.gd +++ b/src/UI/Dialogs/CreateNewImage.gd @@ -64,8 +64,8 @@ class Template: func _ready() -> void: - width_value.value = Global.default_image_width - height_value.value = Global.default_image_height + width_value.value = Global.default_width + height_value.value = Global.default_height aspect_ratio = width_value.value / height_value.value fill_color_node.color = Global.default_fill_color fill_color_node.get_picker().presets_visible = false @@ -103,16 +103,15 @@ func _on_CreateNewImage_confirmed() -> void: var height: int = height_value.value var fill_color: Color = fill_color_node.color - var frame: Frame = Global.canvas.new_empty_frame(fill_color, Vector2(width, height), true) - var new_project: Project var proj_name: String = $VBoxContainer/ProjectName/NameInput.text - if proj_name.is_valid_filename(): - new_project = Project.new([frame], tr(proj_name), Vector2(width, height).floor()) - else: - # an empty field or non valid name... - new_project = Project.new([frame], tr("untitled"), Vector2(width, height).floor()) + if !proj_name.is_valid_filename(): + proj_name = tr("untitled") + + var new_project := Project.new([], proj_name, Vector2(width, height).floor()) new_project.layers.append(Layer.new()) new_project.fill_color = fill_color + var frame: Frame = new_project.new_empty_frame() + new_project.frames.append(frame) Global.projects.append(new_project) Global.tabs.current_tab = Global.tabs.get_tab_count() - 1 Global.canvas.camera_zoom() @@ -153,8 +152,8 @@ func _on_TemplatesOptions_item_selected(id: int) -> void: width_value.value = templates[id - 1].resolution.x height_value.value = templates[id - 1].resolution.y else: - width_value.value = Global.default_image_width - height_value.value = Global.default_image_height + width_value.value = Global.default_width + height_value.value = Global.default_height if temporary_release: ratio_box.pressed = true diff --git a/src/UI/Timeline/AnimationTimeline.gd b/src/UI/Timeline/AnimationTimeline.gd index 4e89dd4f4..0fdbcd063 100644 --- a/src/UI/Timeline/AnimationTimeline.gd +++ b/src/UI/Timeline/AnimationTimeline.gd @@ -81,7 +81,7 @@ func cel_size_changed(value: int) -> void: func add_frame() -> void: var project: Project = Global.current_project - var frame: Frame = Global.canvas.new_empty_frame(project.fill_color, project.size) + var frame: Frame = project.new_empty_frame() var new_frames: Array = project.frames.duplicate() var new_layers: Array = project.layers.duplicate() new_frames.insert(project.current_frame + 1, frame)