Skip to content

macOS: Transparent title bar #946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions material_maker/icons/down.tres
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[gd_resource type="AtlasTexture" load_steps=2 format=3]
[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://br47pe0yf0gbl"]

[ext_resource type="Texture2D" path="res://material_maker/icons/icons.tres" id="1"]
[ext_resource type="Texture2D" uid="uid://c0j4px4n72di5" path="res://material_maker/icons/icons.tres" id="1"]

[resource]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 32, 48, 16, 16 )
atlas = ExtResource("1")
region = Rect2(32, 48, 16, 16)
7 changes: 6 additions & 1 deletion material_maker/main_window.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var current_tab = null
var updating : bool = false
var need_update : bool = false


# The resolution scale to use for 3D previews.
# Values above 1.0 enable supersampling. This has a significant performance cost
# but greatly improves texture rendering quality, especially when using
Expand Down Expand Up @@ -111,10 +112,14 @@ const MENU : Array[Dictionary] = [
{ menu="Help/About", command="about" }
]


func _enter_tree() -> void:
mm_globals.main_window = self

if OS.get_name() == "macOS":
get_window().extend_to_title = true
$VBoxContainer/TitleBar.visible = true
$VBoxContainer/TitleBar.process_mode = Node.PROCESS_MODE_INHERIT

func _ready() -> void:
get_window().borderless = false
get_window().transparent = false
Expand Down
22 changes: 21 additions & 1 deletion material_maker/main_window.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[gd_scene load_steps=21 format=3 uid="uid://cgfeik04a5qqs"]
[gd_scene load_steps=22 format=3 uid="uid://cgfeik04a5qqs"]

[ext_resource type="Script" uid="uid://cbfcjtm6e4t8h" path="res://material_maker/main_window.gd" id="1"]
[ext_resource type="Theme" uid="uid://b628lwfk6ig2c" path="res://material_maker/theme/default.tres" id="1_2qcba"]
[ext_resource type="Script" uid="uid://csdtiyrrw4pxg" path="res://material_maker/main_window_layout.gd" id="2"]
[ext_resource type="Script" uid="uid://vqcg44elblx8" path="res://material_maker/title_bar.gd" id="5_jxedr"]
[ext_resource type="PackedScene" uid="uid://eiq3i53x72m2" path="res://addons/flexible_layout/flexible_layout.tscn" id="6_ygla4"]
[ext_resource type="PackedScene" uid="uid://clw8sb0p8webl" path="res://material_maker/windows/add_node_popup/add_node_popup.tscn" id="7"]
[ext_resource type="PackedScene" uid="uid://bnqq3vhwmudkw" path="res://material_maker/projects_panel.tscn" id="7_ih0ps"]
Expand Down Expand Up @@ -145,6 +146,24 @@ layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="TitleBar" type="Control" parent="VBoxContainer"]
process_mode = 4
custom_minimum_size = Vector2(0, 20)
layout_mode = 2
mouse_filter = 1
mouse_force_pass_scroll_events = false
script = ExtResource("5_jxedr")

[node name="TitleBarLabel" type="Label" parent="VBoxContainer/TitleBar"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -20.0
offset_right = 20.0
offset_bottom = 19.0
grow_horizontal = 2

[node name="TopBar" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2

Expand Down Expand Up @@ -283,6 +302,7 @@ script = ExtResource("9")
[node name="AddNodePopup" parent="." instance=ExtResource("7")]
visible = false

[connection signal="ready" from="VBoxContainer/TitleBar/TitleBarLabel" to="VBoxContainer/TitleBar" method="_on_title_bar_label_ready"]
[connection signal="layout_changed" from="VBoxContainer/Layout/FlexibleLayout" to="." method="update_menus"]
[connection signal="gui_input" from="VBoxContainer/ConsoleResizer" to="VBoxContainer/Console" method="_on_console_resizer_gui_input"]
[connection signal="gui_input" from="VBoxContainer/ConsoleResizer/ResizerBar" to="VBoxContainer/Console" method="_on_console_resizer_gui_input"]
Expand Down
2 changes: 1 addition & 1 deletion material_maker/nodes/node_button.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://nhbn35rfn2m5"]

[ext_resource type="Script" path="res://material_maker/nodes/node_button.gd" id="1_f00x4"]
[ext_resource type="Script" uid="uid://dgy0cxsasek5u" path="res://material_maker/nodes/node_button.gd" id="1_f00x4"]

[node name="NodeButton" type="TextureButton"]
anchors_preset = 15
Expand Down
54 changes: 54 additions & 0 deletions material_maker/title_bar.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
extends Control

var moving : bool
var click_pos : Vector2i

var title_bar_font = preload("res://material_maker/theme/font_rubik/Rubik-416.ttf")

func _gui_input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
if moving:
if (event.button_mask & MOUSE_BUTTON_MASK_LEFT) != 0:
var window : Window = get_parent().get_window()
if window:
window.position = (
DisplayServer.mouse_get_position() - click_pos)
else:
moving = false

if event is InputEventMouseButton:
if get_rect().has_point(event.position):
var window : Window = get_parent().get_window()
if window:
if event.button_index == MOUSE_BUTTON_LEFT:
if event.is_pressed():
click_pos = DisplayServer.mouse_get_position() - window.position
moving = true
else:
moving = false
if (event.button_index == MOUSE_BUTTON_LEFT
and event.double_click
and event.is_pressed()):
if DisplayServer.window_maximize_on_title_dbl_click():
if window.mode == Window.MODE_WINDOWED:
window.mode = Window.MODE_MAXIMIZED
elif window.mode == Window.MODE_MAXIMIZED:
window.mode = Window.MODE_WINDOWED
elif DisplayServer.window_minimize_on_title_dbl_click():
window.mode = Window.MODE_MINIMIZED
moving = false


func _on_title_bar_label_ready() -> void:
var tween = get_tree().create_tween()
modulate = Color.TRANSPARENT
tween.tween_property(
self,"modulate", Color.LIGHT_GRAY, 0.5).set_trans(Tween.TRANS_CUBIC).set_delay(0.15)

var version = ProjectSettings.get_setting("application/config/actual_release")
var app_name = ProjectSettings.get_setting("application/config/name")
var title_bar_label_text = "%s v%s" % [ app_name, version ]

$TitleBarLabel.add_theme_font_override("font", title_bar_font)
$TitleBarLabel.add_theme_font_size_override("font_size", 14)
$TitleBarLabel.text = title_bar_label_text
1 change: 1 addition & 0 deletions material_maker/title_bar.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://vqcg44elblx8