Skip to content

Commit

Permalink
Started reference image support
Browse files Browse the repository at this point in the history
  • Loading branch information
Qainguin committed Apr 27, 2024
1 parent 8b8b779 commit 02c470f
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 2 deletions.
Binary file added chrome-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions chrome-icon.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bat6836ih43p3"
path="res://.godot/imported/chrome-icon.png-ac67218f07be1f136252829ef90d6dbe.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://chrome-icon.png"
dest_files=["res://.godot/imported/chrome-icon.png-ac67218f07be1f136252829ef90d6dbe.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
24 changes: 23 additions & 1 deletion src/ui_parts/display.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ const NumberField = preload("res://src/ui_elements/number_field.tscn")
@onready var viewport: SubViewport = $ViewportPanel/ViewportContainer/Viewport
@onready var controls: Control = %Checkerboard/Controls
@onready var grid_visuals: Control = %Camera
@onready var reference_texture : TextureRect = %ReferenceTexture
@onready var visuals_button: Button = %LeftMenu/Visuals
@onready var more_button: Button = %LeftMenu/MoreOptions
@onready var reference_button : Button = %LeftMenu/Reference
@onready var snapper: NumberEditType = %LeftMenu/Snapping/SnapNumberEdit
@onready var snap_button: BetterToggleButtonType = %LeftMenu/Snapping/SnapButton
@onready var panel_container: PanelContainer = $PanelContainer
@onready var viewport_panel: PanelContainer = $ViewportPanel


func _ready() -> void:
update_snap_config()
view_settings_updated.emit(grid_visuals.visible, controls.visible,
Expand Down Expand Up @@ -99,6 +100,17 @@ func _on_visuals_button_pressed() -> void:
HandlerGUI.popup_under_rect_center(visuals_popup, visuals_button.get_global_rect(),
get_viewport())

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)
]

var reference_popup := ContextPopup.new()
reference_popup.setup(btn_arr, true)
HandlerGUI.popup_under_rect_center(reference_popup, reference_button.get_global_rect(), get_viewport())


func _on_more_options_pressed() -> void:
var about_btn := Utils.create_btn(tr("About…"), open_about, false,
load("res://visual/icon.svg"))
Expand Down Expand Up @@ -139,6 +151,13 @@ func open_update_checker() -> void:
var update_menu_instance := update_menu.instantiate()
HandlerGUI.add_overlay(update_menu_instance)

func open_reference_file() -> void:
# TODO: Add GodSVG file dialog and web.
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_visuals() -> void:
reference_texture.visible = not reference_texture.visible

func toggle_grid_visuals() -> void:
grid_visuals.visible = not grid_visuals.visible
Expand All @@ -162,6 +181,9 @@ 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])

func _on_snap_button_toggled(toggled_on: bool) -> void:
GlobalSettings.modify_save_data("snap",
Expand Down
23 changes: 22 additions & 1 deletion src/ui_parts/display.tscn
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
[gd_scene load_steps=17 format=3 uid="uid://bvrncl7e6yn5b"]
[gd_scene load_steps=19 format=3 uid="uid://bvrncl7e6yn5b"]

[ext_resource type="Script" path="res://src/ui_parts/display.gd" id="1_oib5g"]
[ext_resource type="Texture2D" uid="uid://ccbta5q43jobk" path="res://visual/icons/More.svg" id="2_3wliq"]
[ext_resource type="Texture2D" uid="uid://ckkkgof1hcbld" path="res://visual/icons/Gear.svg" id="3_0w618"]
[ext_resource type="Texture2D" uid="uid://kkxyv1gyrjgj" path="res://visual/icons/Visuals.svg" id="4_n3qjt"]
[ext_resource type="Texture2D" uid="uid://buire51l0mifg" path="res://visual/icons/Snap.svg" id="5_1k2cq"]
[ext_resource type="Texture2D" uid="uid://bvoetuaifdv8i" path="res://visual/icons/Reference.svg" id="5_qufah"]
[ext_resource type="Script" path="res://src/ui_elements/BetterToggleButton.gd" id="6_3v3ve"]
[ext_resource type="PackedScene" uid="uid://dad7fkhmsooc6" path="res://src/ui_elements/number_edit.tscn" id="7_wrrfr"]
[ext_resource type="PackedScene" uid="uid://oltvrf01xrxl" path="res://src/ui_parts/zoom_menu.tscn" id="8_xtdmn"]
[ext_resource type="Script" path="res://src/ui_parts/viewport.gd" id="9_4xrk7"]
[ext_resource type="Texture2D" uid="uid://bat6836ih43p3" path="res://chrome-icon.png" id="10_cd25l"]
[ext_resource type="Shader" path="res://src/shaders/zoom_shader.gdshader" id="10_x7ybk"]
[ext_resource type="Texture2D" uid="uid://c68og6bsqt0lb" path="res://visual/icons/backgrounds/Checkerboard.svg" id="11_1bm1s"]
[ext_resource type="Script" path="res://src/ui_parts/display_texture.gd" id="12_qi23s"]
Expand Down Expand Up @@ -76,6 +78,16 @@ theme_type_variation = &"IconButton"
icon = ExtResource("4_n3qjt")
icon_alignment = 1

[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("5_qufah")
icon_alignment = 1

[node name="Snapping" type="HBoxContainer" parent="PanelContainer/HBoxContainer/LeftMenu"]
layout_mode = 2
theme_override_constants/separation = 0
Expand Down Expand Up @@ -125,6 +137,14 @@ size_2d_override_stretch = true
render_target_update_mode = 4
script = ExtResource("9_4xrk7")

[node name="ReferenceTexture" type="TextureRect" parent="ViewportPanel/ViewportContainer/Viewport"]
unique_name_in_owner = true
offset_right = 40.0
offset_bottom = 40.0
texture = ExtResource("10_cd25l")
expand_mode = 1
stretch_mode = 4

[node name="Checkerboard" type="TextureRect" parent="ViewportPanel/ViewportContainer/Viewport"]
unique_name_in_owner = true
texture_filter = 1
Expand Down Expand Up @@ -164,6 +184,7 @@ 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="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
2 changes: 2 additions & 0 deletions src/ui_parts/viewport.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var _zoom_to: Vector2
@onready var view: Control = %Camera
@onready var controls: Control = %Checkerboard/Controls
@onready var display_texture: TextureRect = %Checkerboard/DisplayTexture
@onready var reference_texture : TextureRect = $ReferenceTexture
@onready var zoom_menu: ZoomMenuType = %ZoomMenu


Expand Down Expand Up @@ -42,6 +43,7 @@ func set_view(new_position: Vector2) -> void:
func resize() -> void:
if SVG.root_tag.get_size().is_finite():
display.size = SVG.root_tag.get_size()
reference_texture.size = SVG.root_tag.get_size()
zoom_menu.zoom_reset()

func center_frame() -> void:
Expand Down
1 change: 1 addition & 0 deletions visual/icons/Reference.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions visual/icons/Reference.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bvoetuaifdv8i"
path="res://.godot/imported/Reference.svg-28e3f2638dc2f67db7899c414706e462.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://visual/icons/Reference.svg"
dest_files=["res://.godot/imported/Reference.svg-28e3f2638dc2f67db7899c414706e462.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

0 comments on commit 02c470f

Please sign in to comment.