initial commit
This commit is contained in:
+83
@@ -0,0 +1,83 @@
|
||||
using Godot;
|
||||
using ReEdit;
|
||||
using System;
|
||||
|
||||
public partial class Titlebar : PanelContainer
|
||||
{
|
||||
private bool _dragging = false;
|
||||
private Vector2I _dragOffset;
|
||||
private bool _isMaximized = false;
|
||||
|
||||
private Button minimizeButton;
|
||||
private Button maximizeButton;
|
||||
private Button closeButton;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
CustomMaximumSize = new Vector2(-1, -1);
|
||||
|
||||
minimizeButton = GetNode<Button>("HBoxContainer/Actions/Minimize");
|
||||
maximizeButton = GetNode<Button>("HBoxContainer/Actions/Maximize");
|
||||
closeButton = GetNode<Button>("HBoxContainer/Actions/Close");
|
||||
|
||||
minimizeButton.Text = char.ConvertFromUtf32(0xE921);
|
||||
maximizeButton.Text = char.ConvertFromUtf32(0xE922);
|
||||
closeButton.Text = char.ConvertFromUtf32(0xE8BB);
|
||||
|
||||
}
|
||||
|
||||
public override void _GuiInput(InputEvent @event)
|
||||
{
|
||||
if (@event is InputEventMouseButton mb && mb.ButtonIndex == MouseButton.Left && !_isMaximized)
|
||||
{
|
||||
_dragging = mb.Pressed;
|
||||
Vector2I screenMousePos = DisplayServer.MouseGetPosition();
|
||||
_dragOffset = screenMousePos - GetWindow().Position;
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (_dragging && !_isMaximized)
|
||||
{
|
||||
Vector2I screenMousePos = DisplayServer.MouseGetPosition();
|
||||
GetWindow().Position = screenMousePos - _dragOffset;
|
||||
}
|
||||
}
|
||||
|
||||
public void _OnMinimizePressed()
|
||||
{
|
||||
GetWindow().Mode = Window.ModeEnum.Minimized;
|
||||
}
|
||||
|
||||
public void _OnMaximizePressed()
|
||||
{
|
||||
Window window = GetWindow();
|
||||
|
||||
if (_isMaximized)
|
||||
{
|
||||
|
||||
window.Mode = Window.ModeEnum.Windowed;
|
||||
window.Size = new Vector2I(1152, 648);
|
||||
|
||||
Vector2I screenSize = DisplayServer.ScreenGetSize();
|
||||
window.Position = (screenSize - window.Size) / 2;
|
||||
maximizeButton.Text = char.ConvertFromUtf32(0xE922);
|
||||
|
||||
_isMaximized = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
window.Mode = Window.ModeEnum.Maximized;
|
||||
_isMaximized = true;
|
||||
maximizeButton.Text = char.ConvertFromUtf32(0xE923);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void _OnClosePressed()
|
||||
{
|
||||
GetWindow().GetTree().Quit();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user