1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Import project brushes from an image file

This commit is contained in:
OverloadedOrama 2020-07-13 21:17:08 +03:00
parent fd3afbfebc
commit 20f28ff492
4 changed files with 74 additions and 18 deletions

View file

@ -21,6 +21,7 @@ Darshan Phaldesai (luiq54), Igor Santarek (jegor377), rob-a-bolton, Kinwailo
- You can import image files as brushes, patterns and palettes. - You can import image files as brushes, patterns and palettes.
- Added "Copy", "Paste" and "Delete" options in the Edit menu. ([#281](https://github.com/Orama-Interactive/Pixelorama/pull/281)) - Added "Copy", "Paste" and "Delete" options in the Edit menu. ([#281](https://github.com/Orama-Interactive/Pixelorama/pull/281))
- Selection region and size are now being shown when making a selection on the top, next to the position label. ([#281](https://github.com/Orama-Interactive/Pixelorama/pull/281)) - Selection region and size are now being shown when making a selection on the top, next to the position label. ([#281](https://github.com/Orama-Interactive/Pixelorama/pull/281))
- Added color overwrite option for the Pencil tool. ([#282](https://github.com/Orama-Interactive/Pixelorama/pull/282))
### Changed ### Changed
- Drawing is no longer limited by the canvas boundaries. This means that, if you have a brush largen than 1px, you can draw on the edges of the canvas. All pixels that are being drawn outside of the canvas will still have no effect. - Drawing is no longer limited by the canvas boundaries. This means that, if you have a brush largen than 1px, you can draw on the edges of the canvas. All pixels that are being drawn outside of the canvas will still have no effect.

View file

@ -193,6 +193,18 @@ msgstr ""
msgid "Vertical frames:" msgid "Vertical frames:"
msgstr "" msgstr ""
msgid "Brush type:"
msgstr ""
msgid "File brush"
msgstr ""
msgid "Project brush"
msgstr ""
msgid "Random brush"
msgstr ""
msgid "Save Sprite as .pxo" msgid "Save Sprite as .pxo"
msgstr "" msgstr ""
@ -705,6 +717,12 @@ msgstr ""
msgid "Brush size:" msgid "Brush size:"
msgstr "" msgstr ""
msgid "Overwrite"
msgstr ""
msgid "Pixel Perfect"
msgstr ""
msgid "Brush color from" msgid "Brush color from"
msgstr "" msgstr ""

View file

@ -2,6 +2,7 @@ extends ConfirmationDialog
enum ImageImportOptions {NEW_TAB, SPRITESHEET, NEW_FRAME, NEW_LAYER, PALETTE, BRUSH, PATTERN} enum ImageImportOptions {NEW_TAB, SPRITESHEET, NEW_FRAME, NEW_LAYER, PALETTE, BRUSH, PATTERN}
enum BrushTypes {FILE, PROJECT, RANDOM}
var path : String var path : String
var image : Image var image : Image
@ -15,6 +16,7 @@ onready var frame_size_label : Label = $VBoxContainer/SizeContainer/FrameSizeLab
onready var spritesheet_options = $VBoxContainer/HBoxContainer/SpritesheetOptions onready var spritesheet_options = $VBoxContainer/HBoxContainer/SpritesheetOptions
onready var new_frame_options = $VBoxContainer/HBoxContainer/NewFrameOptions onready var new_frame_options = $VBoxContainer/HBoxContainer/NewFrameOptions
onready var new_layer_options = $VBoxContainer/HBoxContainer/NewLayerOptions onready var new_layer_options = $VBoxContainer/HBoxContainer/NewLayerOptions
onready var new_brush_options = $VBoxContainer/HBoxContainer/NewBrushOptions
func _on_PreviewDialog_about_to_show() -> void: func _on_PreviewDialog_about_to_show() -> void:
@ -55,14 +57,8 @@ func _on_PreviewDialog_confirmed() -> void:
Global.palette_container.import_image_palette(path, image) Global.palette_container.import_image_palette(path, image)
elif current_import_option == ImageImportOptions.BRUSH: elif current_import_option == ImageImportOptions.BRUSH:
var file_name : String = path.get_basename().get_file() var brush_type_option : int = new_brush_options.get_node("BrushTypeOption").selected
image.convert(Image.FORMAT_RGBA8) add_brush(brush_type_option)
Brushes.add_file_brush([image], file_name)
# Copy the image file into the "pixelorama/Brushes" directory
var location := "Brushes".plus_file(path.get_file())
var dir = Directory.new()
dir.copy(path, Global.directory_module.xdg_data_home.plus_file(location))
elif current_import_option == ImageImportOptions.PATTERN: elif current_import_option == ImageImportOptions.PATTERN:
var file_name : String = path.get_basename().get_file() var file_name : String = path.get_basename().get_file()
@ -81,6 +77,7 @@ func _on_ImportOption_item_selected(id : int) -> void:
spritesheet_options.visible = false spritesheet_options.visible = false
new_frame_options.visible = false new_frame_options.visible = false
new_layer_options.visible = false new_layer_options.visible = false
new_brush_options.visible = false
texture_rect.get_child(0).visible = false texture_rect.get_child(0).visible = false
texture_rect.get_child(1).visible = false texture_rect.get_child(1).visible = false
@ -98,6 +95,9 @@ func _on_ImportOption_item_selected(id : int) -> void:
new_layer_options.visible = true 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 = Global.current_project.frames.size()
elif id == ImageImportOptions.BRUSH:
new_brush_options.visible = true
func _on_HorizontalFrames_value_changed(value : int) -> void: func _on_HorizontalFrames_value_changed(value : int) -> void:
spritesheet_horizontal = value spritesheet_horizontal = value
@ -151,3 +151,19 @@ func spritesheet_frame_value_changed(value : int, vertical : bool) -> void:
var frame_width = floor(image.get_size().x / spritesheet_horizontal) var frame_width = floor(image.get_size().x / spritesheet_horizontal)
var frame_height = floor(image.get_size().y / spritesheet_vertical) var frame_height = floor(image.get_size().y / spritesheet_vertical)
frame_size_label.text = tr("Frame Size") + ": " + str(frame_width) + "×" + str(frame_height) frame_size_label.text = tr("Frame Size") + ": " + str(frame_width) + "×" + str(frame_height)
func add_brush(type : int) -> void:
var file_name : String = path.get_basename().get_file()
image.convert(Image.FORMAT_RGBA8)
if type == BrushTypes.FILE:
Brushes.add_file_brush([image], file_name)
# Copy the image file into the "pixelorama/Brushes" directory
var location := "Brushes".plus_file(path.get_file())
var dir = Directory.new()
dir.copy(path, Global.directory_module.xdg_data_home.plus_file(location))
elif type == BrushTypes.PROJECT:
Global.current_project.brushes.append(image)
Brushes.add_project_brush(image)

View file

@ -26,15 +26,15 @@ __meta__ = {
} }
[node name="CenterContainer" type="CenterContainer" parent="VBoxContainer"] [node name="CenterContainer" type="CenterContainer" parent="VBoxContainer"]
margin_right = 534.0 margin_right = 706.0
margin_bottom = 300.0 margin_bottom = 300.0
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="TextureRect" type="TextureRect" parent="VBoxContainer/CenterContainer"] [node name="TextureRect" type="TextureRect" parent="VBoxContainer/CenterContainer"]
margin_left = 117.0 margin_left = 203.0
margin_right = 417.0 margin_right = 503.0
margin_bottom = 300.0 margin_bottom = 300.0
rect_min_size = Vector2( 300, 300 ) rect_min_size = Vector2( 300, 300 )
expand = true expand = true
@ -49,12 +49,12 @@ __meta__ = {
[node name="SizeContainer" type="HBoxContainer" parent="VBoxContainer"] [node name="SizeContainer" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 304.0 margin_top = 304.0
margin_right = 534.0 margin_right = 706.0
margin_bottom = 318.0 margin_bottom = 318.0
custom_constants/separation = 32 custom_constants/separation = 32
[node name="ImageSizeLabel" type="Label" parent="VBoxContainer/SizeContainer"] [node name="ImageSizeLabel" type="Label" parent="VBoxContainer/SizeContainer"]
margin_right = 117.0 margin_right = 118.0
margin_bottom = 14.0 margin_bottom = 14.0
text = "Image Size: 64×64" text = "Image Size: 64×64"
@ -67,7 +67,7 @@ text = "Frame size: 64×64"
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"] [node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 322.0 margin_top = 322.0
margin_right = 534.0 margin_right = 706.0
margin_bottom = 342.0 margin_bottom = 342.0
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer"] [node name="Label" type="Label" parent="VBoxContainer/HBoxContainer"]
@ -142,23 +142,44 @@ max_value = 0.0
[node name="NewLayerOptions" type="HBoxContainer" parent="VBoxContainer/HBoxContainer"] [node name="NewLayerOptions" type="HBoxContainer" parent="VBoxContainer/HBoxContainer"]
visible = false visible = false
margin_left = 155.0 margin_left = 155.0
margin_right = 286.0 margin_right = 292.0
margin_bottom = 24.0 margin_bottom = 24.0
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/NewLayerOptions"] [node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/NewLayerOptions"]
margin_top = 5.0 margin_top = 5.0
margin_right = 53.0 margin_right = 59.0
margin_bottom = 19.0 margin_bottom = 19.0
text = "At frame:" text = "At frame:"
[node name="AtFrameSpinbox" type="SpinBox" parent="VBoxContainer/HBoxContainer/NewLayerOptions"] [node name="AtFrameSpinbox" type="SpinBox" parent="VBoxContainer/HBoxContainer/NewLayerOptions"]
margin_left = 57.0 margin_left = 63.0
margin_right = 131.0 margin_right = 137.0
margin_bottom = 24.0 margin_bottom = 24.0
mouse_default_cursor_shape = 2 mouse_default_cursor_shape = 2
min_value = 1.0 min_value = 1.0
max_value = 1.0 max_value = 1.0
value = 1.0 value = 1.0
[node name="NewBrushOptions" type="HBoxContainer" parent="VBoxContainer/HBoxContainer"]
visible = false
margin_left = 155.0
margin_right = 324.0
margin_bottom = 20.0
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/NewBrushOptions"]
margin_top = 3.0
margin_right = 73.0
margin_bottom = 17.0
text = "Brush type:"
[node name="BrushTypeOption" type="OptionButton" parent="VBoxContainer/HBoxContainer/NewBrushOptions"]
margin_left = 77.0
margin_right = 169.0
margin_bottom = 20.0
mouse_default_cursor_shape = 2
text = "File brush"
items = [ "File brush", null, false, 0, null, "Project brush", null, false, 1, null, "Random brush", null, true, 2, null ]
selected = 0
[connection signal="about_to_show" from="." to="." method="_on_PreviewDialog_about_to_show"] [connection signal="about_to_show" from="." to="." method="_on_PreviewDialog_about_to_show"]
[connection signal="confirmed" from="." to="." method="_on_PreviewDialog_confirmed"] [connection signal="confirmed" from="." to="." method="_on_PreviewDialog_confirmed"]
[connection signal="popup_hide" from="." to="." method="_on_PreviewDialog_popup_hide"] [connection signal="popup_hide" from="." to="." method="_on_PreviewDialog_popup_hide"]