Skip to content

Commit

Permalink
somewhat fix transparency for floating window (#1116)
Browse files Browse the repository at this point in the history
* somewhat fix transparency

* some formatting
  • Loading branch information
Variable-ind authored Oct 17, 2024
1 parent a64f5f3 commit 2cb29ab
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
16 changes: 12 additions & 4 deletions src/UI/Dialogs/WindowOpacityDialog.gd
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
extends AcceptDialog

var main_canvas := Global.control.find_child("Main Canvas", true, false)

@onready var slider := $VBoxContainer/ValueSlider as ValueSlider
@onready var fullscreen_warning := $VBoxContainer/FullscreenWarning as Label
@onready var main_canvas := Global.control.find_child("Main Canvas") as Control


func _ready() -> void:
if main_canvas is FloatingWindow: ## If it's shifted to a window then get the content
main_canvas = main_canvas.window_content
await get_tree().process_frame
Global.control.main_ui.sort_children.connect(_recalculate_opacity)


func _on_WindowOpacityDialog_about_to_show() -> void:
get_tree().root.transparent = true
get_tree().root.transparent_bg = true
var canvas_window = main_canvas.get_window()
canvas_window.transparent = true
canvas_window.transparent_bg = true
slider.editable = not is_fullscreen()
fullscreen_warning.visible = not slider.editable

Expand All @@ -31,7 +35,11 @@ func set_window_opacity(value: float) -> void:
if container is TabContainer:
var center := container.get_rect().get_center()
if main_canvas.get_rect().has_point(center):
container.self_modulate.a = value
if main_canvas.get_window() != get_tree().root:
## In case we converted to window while trransparency was active
container.self_modulate.a = 1.0
else:
container.self_modulate.a = value
Global.transparent_checker.update_transparency(value)


Expand Down
22 changes: 19 additions & 3 deletions src/UI/UI.gd
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
extends Panel

var shader_disabled := false
var transparency_material: ShaderMaterial

@onready var main_canvas_container := find_child("Main Canvas") as Container


func _ready() -> void:
transparency_material = material
main_canvas_container.property_list_changed.connect(_re_configure_shader)
update_transparent_shader()


func _re_configure_shader():
await get_tree().process_frame
if get_window() != main_canvas_container.get_window():
material = null
shader_disabled = true
else:
if shader_disabled:
material = transparency_material
shader_disabled = false


func _on_main_canvas_item_rect_changed() -> void:
update_transparent_shader()

Expand All @@ -20,6 +36,6 @@ func update_transparent_shader() -> void:
return
# Works independently of the transparency feature
var canvas_size: Vector2 = (main_canvas_container.size - Vector2.DOWN * 2) * Global.shrink
material.set_shader_parameter("screen_resolution", get_viewport().size)
material.set_shader_parameter("position", main_canvas_container.global_position * Global.shrink)
material.set_shader_parameter("size", canvas_size)
transparency_material.set_shader_parameter("screen_resolution", get_viewport().size)
transparency_material.set_shader_parameter("position", main_canvas_container.global_position * Global.shrink)
transparency_material.set_shader_parameter("size", canvas_size)

0 comments on commit 2cb29ab

Please sign in to comment.