using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Shapes; using Avalonia.Markup.Xaml; using Avalonia.Media; using Avalonia.VisualTree; using System; using System.Runtime.InteropServices; using System.Threading.Tasks; /* MIT License Original work Copyright (c) 2020 Fichtelcoder Modified work Copyright 2022 Veloe Aetess Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. namespace VeloeMinecraftLauncher.Views.TitleBar { public partial class TitleBarWindow : UserControl { private Button minimizeButton; private Button maximizeButton; private Path maximizeIcon; private ToolTip maximizeToolTip; private Button closeButton; private Image windowIcon; private DockPanel titleBar; private DockPanel titleBarBackground; private TextBlock systemChromeTitle; private NativeMenuBar seamlessMenuBar; private NativeMenuBar defaultMenuBar; public static readonly StyledProperty IsSeamlessProperty = AvaloniaProperty.Register(nameof(IsSeamless)); public static readonly StyledProperty IsIconVisibleProperty = AvaloniaProperty.Register(nameof(IsIconVisible)); public static readonly StyledProperty IsMaximizeVisibleProperty = AvaloniaProperty.Register(nameof(IsMaximizeVisible)); public static readonly StyledProperty TitleProperty = AvaloniaProperty.Register(nameof(TitleText)); public bool IsSeamless { get { return GetValue(IsSeamlessProperty); } set { SetValue(IsSeamlessProperty, value); if (titleBarBackground != null && systemChromeTitle != null && seamlessMenuBar != null && defaultMenuBar != null) { titleBarBackground.IsVisible = IsSeamless ? false : true; systemChromeTitle.IsVisible = IsSeamless ? false : true; seamlessMenuBar.IsVisible = IsSeamless ? true : false; defaultMenuBar.IsVisible = IsSeamless ? false : true; if (IsSeamless == false) { //titleBar.Resources["SystemControlForegroundBaseHighBrush"] = new SolidColorBrush { Color = new Color(255, 0, 0, 0) }; } } } } public bool IsIconVisible { get { return GetValue(IsIconVisibleProperty); } set { SetValue(IsIconVisibleProperty, value); if (windowIcon != null ) { windowIcon.IsVisible = IsIconVisible ? true : false; //systemChromeTitle.IsVisible = IsIconVisible ? true : false; } } } public bool IsMaximizeVisible { get { return GetValue(IsIconVisibleProperty); } set { SetValue(IsIconVisibleProperty, value); if (maximizeButton != null && maximizeIcon != null && maximizeToolTip != null) { maximizeButton.IsVisible = IsIconVisible ? true : false; maximizeIcon.IsVisible = IsIconVisible ? true : false; maximizeToolTip.IsVisible = IsIconVisible ? true : false; } } } public string TitleText { get { if (systemChromeTitle != null) return systemChromeTitle.Text; return ""; } set { if (systemChromeTitle != null) systemChromeTitle.Text = value; } } public TitleBarWindow() { this.InitializeComponent(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) == false) { this.IsVisible = false; } else { minimizeButton = this.FindControl