project created

This commit is contained in:
Timerix 2024-09-05 12:20:33 +05:00
commit 29ec6e9fff
12 changed files with 221 additions and 0 deletions

22
.gitignore vendored Normal file
View File

@ -0,0 +1,22 @@
# Build results
[Bb]in/
.bin/
[Dd]ebug/
[Rr]elease/
[Rr]eleases/
[Oo]bj/
[Oo]ut/
[Ll]og/
[Ll]ogs/
[Pp]ublish/
# IDE files
.vs/
.vscode/
.vshistory/
.idea/
.editorconfig
*.user
#backups
.old*/

10
App.axaml Normal file
View File

@ -0,0 +1,10 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Slimak.App"
RequestedThemeVariant="Dark">
<Application.Styles>
<SimpleTheme />
</Application.Styles>
</Application>

23
App.axaml.cs Normal file
View File

@ -0,0 +1,23 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
namespace Slimak;
public partial class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow();
}
base.OnFrameworkInitializationCompleted();
}
}

22
MainWindow.axaml Normal file
View File

@ -0,0 +1,22 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:gif="clr-namespace:Avalonia.Gif;assembly=Avalonia.Gif"
x:Class="Slimak.MainWindow"
Title="Slimak"
Name="w"
Width="400" Height="300"
MinWidth="400" MinHeight="300"
WindowStartupLocation="CenterScreen">
<Grid Background="Black"
PointerPressed="InputElement_OnPointerOver"
DragDrop.AllowDrop="True">
<Image
Stretch="Fill"
Source="avares://Slimak/resources/Slimak.png"
IsVisible="{Binding !#w.IsEating}" />
<gif:GifImage
Stretch="Fill"
SourceUri="avares://Slimak/resources/Slimak_eating.gif"
IsVisible="{Binding #w.IsEating}"/>
</Grid>
</Window>

65
MainWindow.axaml.cs Normal file
View File

@ -0,0 +1,65 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Data;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Platform;
using Avalonia.Platform.Storage;
namespace Slimak;
public partial class MainWindow : Window
{
public static readonly StyledProperty<bool> IsEatingProperty =
AvaloniaProperty.Register<MainWindow, bool>(nameof(IsEating),
defaultBindingMode: BindingMode.TwoWay, defaultValue: false);
public bool IsEating
{
get => GetValue(IsEatingProperty);
set => SetValue(IsEatingProperty, value);
}
public MainWindow()
{
InitializeComponent();
AddHandler(DragDrop.DropEvent, Drop);
}
protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);
using var res = AssetLoader.Open(new Uri("avares://Slimak/resources/Salata.png"));
using var file = File.OpenWrite("Salata.png");
res.CopyTo(file);
}
private void InputElement_OnPointerOver(object? sender, PointerPressedEventArgs e)
{
if (IsEating)
{
IsEating = false;
Console.WriteLine("Stopped eating");
}
}
private void Drop(object? sender, DragEventArgs e)
{
if(IsEating)
return;
Console.WriteLine("Drag and Drop");
var data = e.Data;
var draggedFiles = data.GetFiles();
var storageItems = (draggedFiles ?? Array.Empty<IStorageItem>()).ToArray();
Console.WriteLine($"files: {storageItems.Select(f => f.Name).Aggregate((a, b) => a + " " + b + " ")}");
if(draggedFiles != null && storageItems.Any(st => st.Name.ToLower().Contains("salata")))
{
IsEating = true;
Console.WriteLine("Started eating");
}
}
}

20
Program.cs Normal file
View File

@ -0,0 +1,20 @@
using Avalonia;
using System;
namespace Slimak;
class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace();
}

25
Slimak.csproj Normal file
View File

@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.1.3"/>
<PackageReference Include="Avalonia.Desktop" Version="11.1.3"/>
<PackageReference Include="Avalonia.Themes.Simple" Version="11.1.3"/>
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.3"/>
<PackageReference Include="AvaloniaGif-Unofficial" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
<AvaloniaResource Include="resources\**"/>
</ItemGroup>
</Project>

16
Slimak.sln Normal file
View File

@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Slimak", "Slimak.csproj", "{9E0B960E-6E69-4497-9D1F-2F25601F258F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9E0B960E-6E69-4497-9D1F-2F25601F258F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9E0B960E-6E69-4497-9D1F-2F25601F258F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9E0B960E-6E69-4497-9D1F-2F25601F258F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9E0B960E-6E69-4497-9D1F-2F25601F258F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

18
app.manifest Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<!-- This manifest is used on Windows only.
Don't remove it as it might cause problems with window transparency and embedded controls.
For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
<assemblyIdentity version="1.0.0.0" name="Slimak.Desktop"/>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on
and is designed to work with. Uncomment the appropriate elements
and Windows will automatically select the most compatible environment. -->
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
</assembly>

BIN
resources/Salata.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

BIN
resources/Slimak.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
resources/Slimak_eating.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB