mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-31 07:29:49 +00:00
Added a clipboard pattern button
It starts empty and gets updated every time the user copies something.
This commit is contained in:
parent
3213638ba1
commit
af86856dc6
|
@ -37,11 +37,11 @@ func _on_FillWithOptions_item_selected(index: int) -> void:
|
|||
save_config()
|
||||
|
||||
|
||||
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)))
|
||||
func _on_PatternType_pressed() -> void:
|
||||
var popup: Popup = Global.patterns_popup
|
||||
if !popup.is_connected("pattern_selected", self, "_on_Pattern_selected"):
|
||||
popup.connect("pattern_selected", self, "_on_Pattern_selected", [], CONNECT_ONESHOT)
|
||||
popup.popup(Rect2($FillPattern/Type.rect_global_position, Vector2(226, 72)))
|
||||
|
||||
|
||||
func _on_Pattern_selected(pattern: Patterns.Pattern) -> void:
|
||||
|
@ -101,7 +101,8 @@ func update_pattern() -> void:
|
|||
else:
|
||||
_pattern = Global.patterns_popup.default_pattern
|
||||
var tex := ImageTexture.new()
|
||||
tex.create_from_image(_pattern.image, 0)
|
||||
if !_pattern.image.is_empty():
|
||||
tex.create_from_image(_pattern.image, 0)
|
||||
$FillPattern/Type/Texture.texture = tex
|
||||
var size := _pattern.image.get_size()
|
||||
$FillPattern/XOffset/OffsetX.max_value = size.x - 1
|
||||
|
@ -232,8 +233,10 @@ func _set_pixel(image: Image, x: int, y: int, color: Color) -> void:
|
|||
if _fill_with == 0 or _pattern == null:
|
||||
image.set_pixel(x, y, color)
|
||||
else:
|
||||
_pattern.image.lock()
|
||||
var size := _pattern.image.get_size()
|
||||
if size.x == 0 or size.y == 0:
|
||||
return
|
||||
_pattern.image.lock()
|
||||
var px := int(x + _offset_x) % int(size.x)
|
||||
var py := int(y + _offset_y) % int(size.y)
|
||||
var pc := _pattern.image.get_pixel(px, py)
|
||||
|
|
|
@ -672,6 +672,14 @@ func copy() -> void:
|
|||
clipboard.big_bounding_rectangle = big_bounding_rectangle
|
||||
clipboard.selection_offset = project.selection_offset
|
||||
|
||||
if !to_copy.is_empty():
|
||||
var pattern: Patterns.Pattern = Global.patterns_popup.get_pattern(0)
|
||||
pattern.image = to_copy
|
||||
var tex := ImageTexture.new()
|
||||
tex.create_from_image(to_copy, 0)
|
||||
var container = Global.patterns_popup.get_node("ScrollContainer/PatternContainer")
|
||||
container.get_child(0).get_child(0).texture = tex
|
||||
|
||||
|
||||
func paste() -> void:
|
||||
if clipboard.image.is_empty():
|
||||
|
|
|
@ -11,25 +11,30 @@ class Pattern:
|
|||
var index: int
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
add(Image.new(), "Clipboard")
|
||||
|
||||
|
||||
func select_pattern(pattern: Pattern) -> void:
|
||||
emit_signal("pattern_selected", pattern)
|
||||
hide()
|
||||
|
||||
|
||||
static func create_button(image: Image) -> Node:
|
||||
func create_button(image: Image) -> Node:
|
||||
var button: BaseButton = preload("res://src/UI/PatternButton.tscn").instance()
|
||||
var tex := ImageTexture.new()
|
||||
tex.create_from_image(image, 0)
|
||||
if !image.is_empty():
|
||||
tex.create_from_image(image, 0)
|
||||
button.get_child(0).texture = tex
|
||||
button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
return button
|
||||
|
||||
|
||||
static func add(image: Image, hint := "") -> void:
|
||||
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 = get_node("ScrollContainer/PatternContainer")
|
||||
container.add_child(button)
|
||||
button.pattern.index = button.get_index()
|
||||
|
||||
|
|
Loading…
Reference in a new issue