Created
August 31, 2024 09:47
-
-
Save Aqueuse/919a1d08bce93d934491feba19b4dc57 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Avalonia.Controls; | |
using Avalonia.Media.Imaging; | |
using Avalonia.Threading; | |
using Avalonia.VisualTree; | |
using NekoDot.Core; | |
namespace NekoDot.Views; | |
public partial class MainWindow : Window { | |
private Image? petImage; | |
private const int GWL_EXSTYLE = -20; | |
private const uint WS_EX_TOOLWINDOW = 0x00000080; | |
public MainWindow() { | |
Loaded += SearchImage; | |
InitializeComponent(); | |
ShowInTaskbar = false; | |
WindowStartupLocation = WindowStartupLocation.Manual; | |
var visualRoot = this.GetVisualRoot() as TopLevel; | |
if (visualRoot != null && visualRoot.TryGetPlatformHandle() is { } platformHandle) { | |
var hwnd = platformHandle.Handle; | |
NativeMethods.SetWindowLong(hwnd, GWL_EXSTYLE, | |
(uint)NativeMethods.GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_TOOLWINDOW); | |
} | |
} | |
private void SearchImage(Object? o, EventArgs eventArgs) { | |
petImage = this.FindControl<Image>("pet"); | |
} | |
private void SetSprite(Bitmap bitmap) { | |
petImage.Source = bitmap; | |
} | |
public void SetPetSprite(Bitmap bitmap) { | |
Dispatcher.UIThread.Invoke(() => SetSprite(bitmap)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment