1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-31 07:29:49 +00:00

Project brushes change when switching projects

A new Global.file_brushes array is used for the file brushes, and the Project class has its own brushes array for the project brushes
This commit is contained in:
OverloadedOrama 2020-06-05 17:21:35 +03:00
parent 736521246d
commit 4af130bc61
7 changed files with 67 additions and 63 deletions

View file

@ -86,7 +86,7 @@ func draw_brush(sprite : Image, pos : Vector2, color : Color, current_mouse_butt
var brush_index : int = Global.custom_brush_indexes[current_mouse_button]
var custom_brush_image : Image
if brush_type != Global.Brush_Types.RANDOM_FILE:
custom_brush_image = Global.current_project.brush_images[current_mouse_button]
custom_brush_image = Global.brush_images[current_mouse_button]
else: # Handle random brush
var brush_button = Global.file_brush_container.get_child(brush_index + 3)
var random_index = randi() % brush_button.random_brushes.size()
@ -145,7 +145,10 @@ func draw_brush(sprite : Image, pos : Vector2, color : Color, current_mouse_butt
else: # if it's transparent - if it's the eraser
var custom_brush := Image.new()
custom_brush.copy_from(Global.current_project.brushes[brush_index])
if brush_type == Global.Brush_Types.CUSTOM:
custom_brush.copy_from(Global.current_project.brushes[brush_index])
else:
custom_brush.copy_from(Global.file_brushes[brush_index])
custom_brush_size = custom_brush.get_size()
custom_brush.resize(custom_brush_size.x * brush_size, custom_brush_size.y * brush_size, Image.INTERPOLATE_NEAREST)
var custom_brush_blended = Global.blend_image_with_color(custom_brush, color, 1)

View file

@ -103,8 +103,11 @@ var onion_skinning_future_rate := 1.0
var onion_skinning_blue_red := false
# Brushes
var file_brushes := []
var brush_sizes := [1, 1]
var current_brush_types := [Brush_Types.PIXEL, Brush_Types.PIXEL]
var brush_images := [Image.new(), Image.new()]
var brush_textures := [ImageTexture.new(), ImageTexture.new()]
var brush_type_window_position : int = Mouse_Button.LEFT
var left_circle_points := []
@ -596,10 +599,11 @@ func create_brush_button(brush_img : Image, brush_type := Brush_Types.CUSTOM, hi
var brush_container
var brush_button = load("res://src/UI/BrushButton.tscn").instance()
brush_button.brush_type = brush_type
brush_button.custom_brush_index = current_project.brushes.size() - 1
if brush_type == Brush_Types.FILE || brush_type == Brush_Types.RANDOM_FILE:
brush_button.custom_brush_index = file_brushes.size() - 1
brush_container = file_brush_container
else:
brush_button.custom_brush_index = current_project.brushes.size() - 1
brush_container = project_brush_container
var brush_tex := ImageTexture.new()
brush_tex.create_from_image(brush_img, 0)
@ -623,7 +627,7 @@ func undo_custom_brush(_brush_button : BaseButton = null) -> void:
var action_name : String = current_project.undo_redo.get_current_action_name()
if action_name == "Delete Custom Brush":
project_brush_container.add_child(_brush_button)
project_brush_container.move_child(_brush_button, _brush_button.custom_brush_index - brushes_from_files)
project_brush_container.move_child(_brush_button, _brush_button.custom_brush_index)
_brush_button.get_node("DeleteButton").visible = false
@ -635,17 +639,18 @@ func redo_custom_brush(_brush_button : BaseButton = null) -> void:
func update_custom_brush(mouse_button : int) -> void:
if current_brush_types[mouse_button] == Brush_Types.PIXEL:
var brush_type : int = current_brush_types[mouse_button]
if brush_type == Brush_Types.PIXEL:
var pixel := Image.new()
pixel = preload("res://assets/graphics/pixel_image.png")
brush_type_buttons[mouse_button].get_child(0).texture.create_from_image(pixel, 0)
elif current_brush_types[mouse_button] == Brush_Types.CIRCLE:
elif brush_type == Brush_Types.CIRCLE:
var pixel := Image.new()
pixel = preload("res://assets/graphics/circle_9x9.png")
brush_type_buttons[mouse_button].get_child(0).texture.create_from_image(pixel, 0)
left_circle_points = plot_circle(brush_sizes[0])
right_circle_points = plot_circle(brush_sizes[1])
elif current_brush_types[mouse_button] == Brush_Types.FILLED_CIRCLE:
elif brush_type == Brush_Types.FILLED_CIRCLE:
var pixel := Image.new()
pixel = preload("res://assets/graphics/circle_filled_9x9.png")
brush_type_buttons[mouse_button].get_child(0).texture.create_from_image(pixel, 0)
@ -653,13 +658,16 @@ func update_custom_brush(mouse_button : int) -> void:
right_circle_points = plot_circle(brush_sizes[1])
else:
var custom_brush := Image.new()
custom_brush.copy_from(current_project.brushes[custom_brush_indexes[mouse_button]])
if brush_type == Brush_Types.FILE or brush_type == Brush_Types.RANDOM_FILE:
custom_brush.copy_from(file_brushes[custom_brush_indexes[mouse_button]])
else:
custom_brush.copy_from(current_project.brushes[custom_brush_indexes[mouse_button]])
var custom_brush_size = custom_brush.get_size()
custom_brush.resize(custom_brush_size.x * brush_sizes[mouse_button], custom_brush_size.y * brush_sizes[mouse_button], Image.INTERPOLATE_NEAREST)
current_project.brush_images[mouse_button] = blend_image_with_color(custom_brush, color_pickers[mouse_button].color, interpolate_spinboxes[mouse_button].value / 100)
current_project.brush_textures[mouse_button].create_from_image(current_project.brush_images[mouse_button], 0)
brush_images[mouse_button] = blend_image_with_color(custom_brush, color_pickers[mouse_button].color, interpolate_spinboxes[mouse_button].value / 100)
brush_textures[mouse_button].create_from_image(brush_images[mouse_button], 0)
brush_type_buttons[mouse_button].get_child(0).texture = current_project.brush_textures[mouse_button]
brush_type_buttons[mouse_button].get_child(0).texture = brush_textures[mouse_button]
func blend_image_with_color(image : Image, color : Color, interpolate_factor : float) -> Image:

View file

@ -111,7 +111,7 @@ func add_randomised_brush(fpaths : Array, tooltip_name : String) -> void:
# The index which this random brush will be at
var next_random_brush_index := Global.file_brush_container.get_child_count()
Global.current_project.brushes.append(first_image)
Global.file_brushes.append(first_image)
Global.create_brush_button(first_image, Global.Brush_Types.RANDOM_FILE, tooltip_name)
# # Process the rest
for remaining_image in loaded_images:
@ -127,7 +127,7 @@ func add_plain_brush(path: String, tooltip_name: String) -> void:
return
# do the standard conversion thing...
image.convert(Image.FORMAT_RGBA8)
Global.current_project.brushes.append(image)
Global.file_brushes.append(image)
Global.create_brush_button(image, Global.Brush_Types.FILE, tooltip_name)
@ -214,7 +214,7 @@ func import_brushes(priority_ordered_search_path: Array) -> void:
# Mark this as a processed relpath
processed_subdir_paths[nonrandomised_subdir][relative_path] = true
Global.brushes_from_files = Global.current_project.brushes.size()
Global.brushes_from_files = Global.file_brushes.size()
func import_patterns(priority_ordered_search_path: Array) -> void:

View file

@ -155,7 +155,6 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void:
Global.color_pickers[1].get_picker().add_preset(color)
# Load custom brushes
Global.current_project.brushes.resize(Global.brushes_from_files)
Global.remove_brush_buttons()
var brush_line := file.get_line()
@ -248,7 +247,7 @@ func save_pxo_file(path : String, autosave : bool) -> void:
file.store_8(right_brush_size)
# Save custom brushes
for i in range(Global.brushes_from_files, Global.current_project.brushes.size()):
for i in range(Global.current_project.brushes.size()):
var brush = Global.current_project.brushes[i]
file.store_line("/")
file.store_16(brush.get_size().x)

View file

@ -78,9 +78,9 @@ func _draw() -> void:
draw_set_transform(position, rotation, scale)
else:
if Global.current_tools[i] == Global.Tools.PENCIL || Global.current_tools[i] == Global.Tools.ERASER:
var custom_brush_size = Global.current_project.brush_images[i].get_size() - Vector2.ONE
var custom_brush_size = Global.brush_images[i].get_size() - Vector2.ONE
var dst : Vector2 = DrawingAlgos.rectangle_center(mouse_pos, custom_brush_size)
draw_texture(Global.current_project.brush_textures[i], dst)
draw_texture(Global.brush_textures[i], dst)
func _input(event : InputEvent) -> void:

View file

@ -15,8 +15,6 @@ var animation_tags := [] setget animation_tags_changed # Array of AnimationTags
var guides := [] # Array of Guides
var brushes := [] # Array of Images
var brush_images := [Image.new(), Image.new()]
var brush_textures := [ImageTexture.new(), ImageTexture.new()]
var selected_pixels := []
var x_min := 0
@ -103,6 +101,7 @@ func change_project() -> void:
Global.selection_rectangle.polygon[2] = Vector2.ZERO
Global.selection_rectangle.polygon[3] = Vector2.ZERO
# Change the guides
for guide in Global.canvas.get_children():
if guide is Guide:
if guide in guides:
@ -110,6 +109,13 @@ func change_project() -> void:
else:
guide.visible = false
# Change the project brushes
for child in Global.project_brush_container.get_children():
child.queue_free()
for brush in brushes:
Global.create_brush_button(brush)
func frames_changed(value : Array) -> void:
frames = value

View file

@ -1,7 +1,7 @@
extends BaseButton
export var brush_type = 0 # Global.Brush_Types.PIXEL
export var brush_type := 0 # Global.Brush_Types.PIXEL
export var custom_brush_index := -3
var random_brushes := []
@ -15,61 +15,49 @@ func _on_BrushButton_pressed() -> void:
# Change brush
Global.current_brush_types[Global.brush_type_window_position] = brush_type
Global.custom_brush_indexes[Global.brush_type_window_position] = custom_brush_index
if custom_brush_index > -1: # Custom brush
if brush_type == Global.Brush_Types.FILE or brush_type == Global.Brush_Types.RANDOM_FILE or brush_type == Global.Brush_Types.CUSTOM:
if Global.current_tools[Global.brush_type_window_position] == Global.Tools.PENCIL:
Global.color_interpolation_containers[Global.brush_type_window_position].visible = true
# if hint_tooltip == "":
# Global.left_brush_type_label.text = tr("Custom brush")
# else:
# Global.left_brush_type_label.text = tr("Brush:") + " %s" % hint_tooltip
elif custom_brush_index == -3: # Pixel brush
else:
Global.color_interpolation_containers[Global.brush_type_window_position].visible = false
# Global.left_brush_type_label.text = tr("Brush: Pixel")
elif custom_brush_index == -2: # Circle brush
Global.color_interpolation_containers[Global.brush_type_window_position].visible = false
# Global.left_brush_type_label.text = tr("Brush: Circle")
elif custom_brush_index == -1: # Filled Circle brush
Global.color_interpolation_containers[Global.brush_type_window_position].visible = false
# Global.left_brush_type_label.text = tr("Brush: Filled Circle")
Global.update_custom_brush(Global.brush_type_window_position)
Global.brushes_popup.hide()
func _on_DeleteButton_pressed() -> void:
if brush_type == Global.Brush_Types.CUSTOM:
if Global.custom_brush_indexes[0] == custom_brush_index:
Global.custom_brush_indexes[0] = -3
Global.current_brush_types[0] = Global.Brush_Types.PIXEL
# Global.left_brush_type_label.text = "Brush: Pixel"
Global.update_custom_brush(0)
if Global.custom_brush_indexes[1] == custom_brush_index:
Global.custom_brush_indexes[1] = -3
Global.current_brush_types[1] = Global.Brush_Types.PIXEL
# Global.right_brush_type_label.text = "Brush: Pixel"
Global.update_custom_brush(1)
if brush_type != Global.Brush_Types.CUSTOM:
return
var project_brush_index = custom_brush_index - Global.brushes_from_files
Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Delete Custom Brush")
for i in range(project_brush_index, Global.project_brush_container.get_child_count()):
var bb = Global.project_brush_container.get_child(i)
if Global.custom_brush_indexes[0] == bb.custom_brush_index:
Global.custom_brush_indexes[0] -= 1
if Global.custom_brush_indexes[1] == bb.custom_brush_index:
Global.custom_brush_indexes[1] -= 1
if Global.custom_brush_indexes[0] == custom_brush_index:
Global.custom_brush_indexes[0] = -3
Global.current_brush_types[0] = Global.Brush_Types.PIXEL
Global.update_custom_brush(0)
if Global.custom_brush_indexes[1] == custom_brush_index:
Global.custom_brush_indexes[1] = -3
Global.current_brush_types[1] = Global.Brush_Types.PIXEL
Global.update_custom_brush(1)
Global.current_project.undo_redo.add_do_property(bb, "custom_brush_index", bb.custom_brush_index - 1)
Global.current_project.undo_redo.add_undo_property(bb, "custom_brush_index", bb.custom_brush_index)
Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Delete Custom Brush")
for i in range(Global.project_brush_container.get_child_count()):
var bb = Global.project_brush_container.get_child(i)
if Global.custom_brush_indexes[0] == bb.custom_brush_index:
Global.custom_brush_indexes[0] -= 1
if Global.custom_brush_indexes[1] == bb.custom_brush_index:
Global.custom_brush_indexes[1] -= 1
var custom_brushes: Array = Global.current_project.brushes.duplicate()
custom_brushes.remove(custom_brush_index)
Global.current_project.undo_redo.add_do_property(bb, "custom_brush_index", bb.custom_brush_index - 1)
Global.current_project.undo_redo.add_undo_property(bb, "custom_brush_index", bb.custom_brush_index)
Global.current_project.undo_redo.add_do_property(Global.current_project, "brushes", custom_brushes)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "brushes", Global.current_project.brushes)
Global.current_project.undo_redo.add_do_method(Global, "redo_custom_brush", self)
Global.current_project.undo_redo.add_undo_method(Global, "undo_custom_brush", self)
Global.current_project.undo_redo.commit_action()
var custom_brushes: Array = Global.current_project.brushes.duplicate()
custom_brushes.remove(custom_brush_index)
Global.current_project.undo_redo.add_do_property(Global.current_project, "brushes", custom_brushes)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "brushes", Global.current_project.brushes)
Global.current_project.undo_redo.add_do_method(Global, "redo_custom_brush", self)
Global.current_project.undo_redo.add_undo_method(Global, "undo_custom_brush", self)
Global.current_project.undo_redo.commit_action()
func _on_BrushButton_mouse_entered() -> void: