Skip to content

Commit

Permalink
Added ability to Overlay Reference Image
Browse files Browse the repository at this point in the history
  • Loading branch information
Qainguin committed Apr 27, 2024
1 parent fb2f7e1 commit 7797e2b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
18 changes: 16 additions & 2 deletions src/ui_parts/display.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ const NumberField = preload("res://src/ui_elements/number_field.tscn")
@onready var panel_container: PanelContainer = $PanelContainer
@onready var viewport_panel: PanelContainer = $ViewportPanel

var reference_overlay = false

func _ready() -> void:
reference_texture.hide()
update_snap_config()
view_settings_updated.emit(grid_visuals.visible, controls.visible,
viewport.display_texture.rasterized)
Expand Down Expand Up @@ -103,7 +106,8 @@ func _on_visuals_button_pressed() -> void:
func _on_reference_pressed() -> void:
var btn_arr: Array[Button] = [
Utils.create_btn(tr("Select Image"), open_reference_file, false, load("res://visual/icons/Reference.svg")),
Utils.create_checkbox(tr("Show Reference Image"), toggle_reference_visuals, reference_texture.visible)
Utils.create_checkbox(tr("Show Reference Image"), toggle_reference_visuals, reference_texture.visible),
Utils.create_checkbox(tr("Overlay Reference Image"), toggle_reference_overlay, reference_overlay)
]

var reference_popup := ContextPopup.new()
Expand Down Expand Up @@ -156,6 +160,13 @@ func open_reference_file() -> void:
DisplayServer.file_dialog_show("Import a .png file", Utils.get_last_dir(), "", false,
DisplayServer.FILE_DIALOG_MODE_OPEN_FILE, ["*.png"], native_reference_import)

func toggle_reference_overlay() -> void:
reference_overlay = not reference_overlay
if reference_overlay:
viewport.move_child(reference_texture, 2)
else:
viewport.move_child(reference_texture, 0)

func toggle_reference_visuals() -> void:
reference_texture.visible = not reference_texture.visible

Expand All @@ -181,9 +192,12 @@ func toggle_snap() -> void:
func set_snap_amount(snap_value: float) -> void:
snapper.set_value(snap_value)


func native_reference_import(has_selected: bool, files: PackedStringArray, _filter_idx: int) -> void:
if has_selected:
reference_texture.texture = load(files[0])
if files[0].ends_with(".png"):
reference_texture.texture = load(files[0])
reference_texture.visible = true

func _on_snap_button_toggled(toggled_on: bool) -> void:
GlobalSettings.modify_save_data("snap",
Expand Down
10 changes: 5 additions & 5 deletions src/ui_parts/display.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,24 @@ theme_type_variation = &"IconButton"
icon = ExtResource("3_0w618")
icon_alignment = 1

[node name="Visuals" type="Button" parent="PanelContainer/HBoxContainer/LeftMenu"]
[node name="Reference" type="Button" parent="PanelContainer/HBoxContainer/LeftMenu"]
layout_mode = 2
size_flags_horizontal = 2
tooltip_text = "Visuals"
focus_mode = 0
mouse_default_cursor_shape = 2
theme_type_variation = &"IconButton"
icon = ExtResource("4_n3qjt")
icon = ExtResource("5_qufah")
icon_alignment = 1

[node name="Reference" type="Button" parent="PanelContainer/HBoxContainer/LeftMenu"]
[node name="Visuals" type="Button" parent="PanelContainer/HBoxContainer/LeftMenu"]
layout_mode = 2
size_flags_horizontal = 2
tooltip_text = "Visuals"
focus_mode = 0
mouse_default_cursor_shape = 2
theme_type_variation = &"IconButton"
icon = ExtResource("5_qufah")
icon = ExtResource("4_n3qjt")
icon_alignment = 1

[node name="Snapping" type="HBoxContainer" parent="PanelContainer/HBoxContainer/LeftMenu"]
Expand Down Expand Up @@ -181,8 +181,8 @@ script = ExtResource("15_hevpa")

[connection signal="pressed" from="PanelContainer/HBoxContainer/LeftMenu/MoreOptions" to="." method="_on_more_options_pressed"]
[connection signal="pressed" from="PanelContainer/HBoxContainer/LeftMenu/Settings" to="." method="_on_settings_pressed"]
[connection signal="pressed" from="PanelContainer/HBoxContainer/LeftMenu/Visuals" to="." method="_on_visuals_button_pressed"]
[connection signal="pressed" from="PanelContainer/HBoxContainer/LeftMenu/Reference" to="." method="_on_reference_pressed"]
[connection signal="pressed" from="PanelContainer/HBoxContainer/LeftMenu/Visuals" to="." method="_on_visuals_button_pressed"]
[connection signal="toggled" from="PanelContainer/HBoxContainer/LeftMenu/Snapping/SnapButton" to="." method="_on_snap_button_toggled"]
[connection signal="value_changed" from="PanelContainer/HBoxContainer/LeftMenu/Snapping/SnapNumberEdit" to="." method="_on_snap_number_edit_value_changed"]
[connection signal="zoom_changed" from="PanelContainer/HBoxContainer/ZoomMenu" to="ViewportPanel/ViewportContainer/Viewport" method="_on_zoom_changed"]
Expand Down

0 comments on commit 7797e2b

Please sign in to comment.