mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
somewhat fix transparency for floating window (#1116)
* somewhat fix transparency * some formatting
This commit is contained in:
parent
a64f5f3429
commit
2cb29ab274
|
@ -1,18 +1,22 @@
|
||||||
extends AcceptDialog
|
extends AcceptDialog
|
||||||
|
|
||||||
|
var main_canvas := Global.control.find_child("Main Canvas", true, false)
|
||||||
|
|
||||||
@onready var slider := $VBoxContainer/ValueSlider as ValueSlider
|
@onready var slider := $VBoxContainer/ValueSlider as ValueSlider
|
||||||
@onready var fullscreen_warning := $VBoxContainer/FullscreenWarning as Label
|
@onready var fullscreen_warning := $VBoxContainer/FullscreenWarning as Label
|
||||||
@onready var main_canvas := Global.control.find_child("Main Canvas") as Control
|
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
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
|
await get_tree().process_frame
|
||||||
Global.control.main_ui.sort_children.connect(_recalculate_opacity)
|
Global.control.main_ui.sort_children.connect(_recalculate_opacity)
|
||||||
|
|
||||||
|
|
||||||
func _on_WindowOpacityDialog_about_to_show() -> void:
|
func _on_WindowOpacityDialog_about_to_show() -> void:
|
||||||
get_tree().root.transparent = true
|
var canvas_window = main_canvas.get_window()
|
||||||
get_tree().root.transparent_bg = true
|
canvas_window.transparent = true
|
||||||
|
canvas_window.transparent_bg = true
|
||||||
slider.editable = not is_fullscreen()
|
slider.editable = not is_fullscreen()
|
||||||
fullscreen_warning.visible = not slider.editable
|
fullscreen_warning.visible = not slider.editable
|
||||||
|
|
||||||
|
@ -31,6 +35,10 @@ func set_window_opacity(value: float) -> void:
|
||||||
if container is TabContainer:
|
if container is TabContainer:
|
||||||
var center := container.get_rect().get_center()
|
var center := container.get_rect().get_center()
|
||||||
if main_canvas.get_rect().has_point(center):
|
if main_canvas.get_rect().has_point(center):
|
||||||
|
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
|
container.self_modulate.a = value
|
||||||
Global.transparent_checker.update_transparency(value)
|
Global.transparent_checker.update_transparency(value)
|
||||||
|
|
||||||
|
|
22
src/UI/UI.gd
22
src/UI/UI.gd
|
@ -1,12 +1,28 @@
|
||||||
extends Panel
|
extends Panel
|
||||||
|
|
||||||
|
var shader_disabled := false
|
||||||
|
var transparency_material: ShaderMaterial
|
||||||
|
|
||||||
@onready var main_canvas_container := find_child("Main Canvas") as Container
|
@onready var main_canvas_container := find_child("Main Canvas") as Container
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
transparency_material = material
|
||||||
|
main_canvas_container.property_list_changed.connect(_re_configure_shader)
|
||||||
update_transparent_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:
|
func _on_main_canvas_item_rect_changed() -> void:
|
||||||
update_transparent_shader()
|
update_transparent_shader()
|
||||||
|
|
||||||
|
@ -20,6 +36,6 @@ func update_transparent_shader() -> void:
|
||||||
return
|
return
|
||||||
# Works independently of the transparency feature
|
# Works independently of the transparency feature
|
||||||
var canvas_size: Vector2 = (main_canvas_container.size - Vector2.DOWN * 2) * Global.shrink
|
var canvas_size: Vector2 = (main_canvas_container.size - Vector2.DOWN * 2) * Global.shrink
|
||||||
material.set_shader_parameter("screen_resolution", get_viewport().size)
|
transparency_material.set_shader_parameter("screen_resolution", get_viewport().size)
|
||||||
material.set_shader_parameter("position", main_canvas_container.global_position * Global.shrink)
|
transparency_material.set_shader_parameter("position", main_canvas_container.global_position * Global.shrink)
|
||||||
material.set_shader_parameter("size", canvas_size)
|
transparency_material.set_shader_parameter("size", canvas_size)
|
||||||
|
|
Loading…
Reference in a new issue