diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2019-12-15 22:30:38 +0100 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2019-12-15 22:30:38 +0100 |
| commit | 0f98b398520a3f5cc6a299e7fd3b8fab494480d7 (patch) | |
| tree | a1c0ab173723c47adf23d7dc5c1894185052cc39 | |
| download | avalar-0f98b398520a3f5cc6a299e7fd3b8fab494480d7.tar.gz avalar-0f98b398520a3f5cc6a299e7fd3b8fab494480d7.tar.bz2 avalar-0f98b398520a3f5cc6a299e7fd3b8fab494480d7.zip | |
Initial commit, skeleton project.
| -rw-r--r-- | .gitignore | 337 | ||||
| -rw-r--r-- | App.xaml | 8 | ||||
| -rw-r--r-- | App.xaml.cs | 13 | ||||
| -rw-r--r-- | Avalar.csproj | 44 | ||||
| -rw-r--r-- | MainWindow.xaml | 18 | ||||
| -rw-r--r-- | MainWindow.xaml.cs | 32 | ||||
| -rw-r--r-- | Program.cs | 31 | ||||
| -rw-r--r-- | ViewModels/Image/ImageLoadedViewModel.cs | 23 | ||||
| -rw-r--r-- | ViewModels/Image/ImageNotLoadedViewModel.cs | 15 | ||||
| -rw-r--r-- | ViewModels/Image/ImageViewModel.cs | 38 | ||||
| -rw-r--r-- | ViewModels/Settings/SettingsViewModel.cs | 7 | ||||
| -rw-r--r-- | Views/AvalarViewService.cs | 32 | ||||
| -rw-r--r-- | Views/IAvalarViewService.cs | 9 | ||||
| -rw-r--r-- | Views/Image/ImageControl.xaml | 16 | ||||
| -rw-r--r-- | Views/Image/ImageControl.xaml.cs | 100 | ||||
| -rw-r--r-- | Views/Image/ImagePanel.xaml | 26 | ||||
| -rw-r--r-- | Views/Image/ImagePanel.xaml.cs | 19 | ||||
| -rw-r--r-- | Views/Settings/Settings.xaml | 9 | ||||
| -rw-r--r-- | Views/Settings/Settings.xaml.cs | 18 | ||||
| -rw-r--r-- | avalar.sln | 25 | ||||
| -rw-r--r-- | nuget.config | 6 |
21 files changed, 826 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dbe7c8f --- /dev/null +++ b/.gitignore @@ -0,0 +1,337 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +## Visual Studio Code specific files and folder +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.jsons + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ +**/Properties/launchSettings.json + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ diff --git a/App.xaml b/App.xaml new file mode 100644 index 0000000..f847937 --- /dev/null +++ b/App.xaml @@ -0,0 +1,8 @@ +<Application xmlns="https://github.com/avaloniaui" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + x:Class="Avalar.App"> + <Application.Styles> + <StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml"/> + <StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml"/> + </Application.Styles> +</Application> diff --git a/App.xaml.cs b/App.xaml.cs new file mode 100644 index 0000000..0d3a9b5 --- /dev/null +++ b/App.xaml.cs @@ -0,0 +1,13 @@ +using Avalonia; +using Avalonia.Markup.Xaml; + +namespace Avalar +{ + public class App : Application + { + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + } +}
\ No newline at end of file diff --git a/Avalar.csproj b/Avalar.csproj new file mode 100644 index 0000000..93ac3a3 --- /dev/null +++ b/Avalar.csproj @@ -0,0 +1,44 @@ +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <OutputType>WinExe</OutputType> + <TargetFramework>netcoreapp3.0</TargetFramework> + <AllowUnsafeBlocks>false</AllowUnsafeBlocks> + </PropertyGroup> + <ItemGroup> + <Compile Update="**\*.xaml.cs"> + <DependentUpon>%(Filename)</DependentUpon> + </Compile> + <AvaloniaResource Include="**\*.xaml"> + <SubType>Designer</SubType> + </AvaloniaResource> + </ItemGroup> + <ItemGroup> + <AvaloniaResource Remove="Views\Image\ImageControl.xaml" /> + <AvaloniaResource Remove="Views\Image\ImagePanel.xaml" /> + </ItemGroup> + <ItemGroup> + <None Remove="Views\Image\ImageControl.xaml" /> + <None Remove="Views\Image\ImagePanel.xaml" /> + </ItemGroup> + <ItemGroup> + <PackageReference Include="Avalonia" Version="0.9.0" /> + <PackageReference Include="Avalonia.Desktop" Version="0.9.0" /> + <PackageReference Include="Avalonia.ReactiveUI" Version="0.9.0" /> + <PackageReference Include="Avalonia.Xaml.Behaviors" Version="0.9.0" /> + </ItemGroup> + <ItemGroup> + <EmbeddedResource Include="Views\Image\ImageControl.xaml"> + <Generator>MSBuild:Compile</Generator> + </EmbeddedResource> + </ItemGroup> + <ItemGroup> + <EmbeddedResource Include="Views\Image\ImagePanel.xaml"> + <Generator>MSBuild:Compile</Generator> + </EmbeddedResource> + </ItemGroup> + <ItemGroup> + <Compile Update="Views\Image\ImageControl.xaml.cs"> + <DependentUpon>ImageControl.xaml</DependentUpon> + </Compile> + </ItemGroup> +</Project> diff --git a/MainWindow.xaml b/MainWindow.xaml new file mode 100644 index 0000000..b4a5565 --- /dev/null +++ b/MainWindow.xaml @@ -0,0 +1,18 @@ +<Window xmlns="https://github.com/avaloniaui" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:image="clr-namespace:Avalar.Views.Image" + xmlns:settings="clr-namespace:Avalar.Views.Settings" + mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + x:Class="Avalar.MainWindow" + Title="Avalar"> + <Grid Margin="5"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="*"/> + <ColumnDefinition Width="Auto"/> + </Grid.ColumnDefinitions> + <image:ImagePanel DataContext="{Binding ImageVm}" Grid.Column="0"/> + <settings:Settings DataContext="{Binding SettingsVm}" Grid.Column="1"/> + </Grid> +</Window> diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs new file mode 100644 index 0000000..154ee31 --- /dev/null +++ b/MainWindow.xaml.cs @@ -0,0 +1,32 @@ +using Avalar.Viewmodels.Image; +using Avalar.ViewModels.Settings; +using Avalar.Views; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace Avalar +{ + public class MainWindow : Window + { + private ImageViewModel ImageVm { get; } + private SettingsViewModel SettingsVm { get; } + + private IAvalarViewService ViewService { get; } + public MainWindow() + { + InitializeComponent(); + + ViewService = new AvalarViewService(this); + + ImageVm = new ImageViewModel(ViewService); + SettingsVm = new SettingsViewModel(); + + DataContext = this; + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + } +}
\ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..915f344 --- /dev/null +++ b/Program.cs @@ -0,0 +1,31 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Logging.Serilog; +using Avalonia.ReactiveUI; + +namespace Avalar +{ + 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. + public static void Main(string[] args) => BuildAvaloniaApp().Start(AppMain, args); + + // Avalonia configuration, don't remove; also used by visual designer. + public static AppBuilder BuildAvaloniaApp() + { + return AppBuilder.Configure<App>() + .UseReactiveUI() + .UsePlatformDetect() + .LogToDebug(); + } + + // Your application's entry point. Here you can initialize your MVVM framework, DI + // container, etc. + private static void AppMain(Application app, string[] args) + { + app.Run(new MainWindow()); + } + } +} diff --git a/ViewModels/Image/ImageLoadedViewModel.cs b/ViewModels/Image/ImageLoadedViewModel.cs new file mode 100644 index 0000000..f9e322c --- /dev/null +++ b/ViewModels/Image/ImageLoadedViewModel.cs @@ -0,0 +1,23 @@ +using Avalonia.Media.Imaging; +using ReactiveUI; + +namespace Avalar.ViewModels.Image +{ + public class ImageLoadedViewModel : ReactiveObject + { + public ImageLoadedViewModel(IBitmap bitmap) + { + Bitmap = bitmap; + } + + private IBitmap m_Bitmap; + public IBitmap Bitmap + { + get => m_Bitmap; + set + { + this.RaiseAndSetIfChanged(ref m_Bitmap, value); + } + } + } +} diff --git a/ViewModels/Image/ImageNotLoadedViewModel.cs b/ViewModels/Image/ImageNotLoadedViewModel.cs new file mode 100644 index 0000000..bf7b65e --- /dev/null +++ b/ViewModels/Image/ImageNotLoadedViewModel.cs @@ -0,0 +1,15 @@ +using ReactiveUI; +using System.Reactive; + +namespace Avalar.ViewModels.Image +{ + public class ImageNotLoadedViewModel : ReactiveObject + { + public ImageNotLoadedViewModel(ReactiveCommand<Unit, Unit> openFileCommand) + { + OpenFileCommand = openFileCommand; + } + + public ReactiveCommand<Unit, Unit> OpenFileCommand { get; } + } +} diff --git a/ViewModels/Image/ImageViewModel.cs b/ViewModels/Image/ImageViewModel.cs new file mode 100644 index 0000000..030a95b --- /dev/null +++ b/ViewModels/Image/ImageViewModel.cs @@ -0,0 +1,38 @@ + +using Avalar.ViewModels.Image; +using Avalar.Views; +using Avalonia.Media.Imaging; +using ReactiveUI; +using System.Linq; + +namespace Avalar.Viewmodels.Image +{ + public class ImageViewModel : ReactiveObject + { + public ImageViewModel(IAvalarViewService viewService) + { + ViewService = viewService; + ChildViewModel = new ImageNotLoadedViewModel(ReactiveCommand.Create(OpenFile)); + } + + private IAvalarViewService ViewService { get; } + + private object m_ChildViewModel; + + public object ChildViewModel + { + get => m_ChildViewModel; + set { + this.RaiseAndSetIfChanged(ref m_ChildViewModel, value); + } + } + + public async void OpenFile() + { + var result = await ViewService.ShowOpenImageFileDialog(); + if (result.Length != 1) return; + + ChildViewModel = new ImageLoadedViewModel(new Bitmap(result.First())); + } + } +} diff --git a/ViewModels/Settings/SettingsViewModel.cs b/ViewModels/Settings/SettingsViewModel.cs new file mode 100644 index 0000000..b9f076b --- /dev/null +++ b/ViewModels/Settings/SettingsViewModel.cs @@ -0,0 +1,7 @@ + +namespace Avalar.ViewModels.Settings +{ + class SettingsViewModel + { + } +} diff --git a/Views/AvalarViewService.cs b/Views/AvalarViewService.cs new file mode 100644 index 0000000..994f88b --- /dev/null +++ b/Views/AvalarViewService.cs @@ -0,0 +1,32 @@ +using Avalonia.Controls; +using System.Threading.Tasks; + +namespace Avalar.Views +{ + class AvalarViewService : IAvalarViewService + { + private Window m_Window; + + public AvalarViewService(Window window) + { + m_Window = window; + } + + public async Task<string[]> ShowOpenImageFileDialog() + { + var openFileDialog = new OpenFileDialog(); + + openFileDialog.AllowMultiple = false; + + var filter = new FileDialogFilter(); + filter.Extensions.Add("png"); + filter.Name = "png"; + openFileDialog.Filters.Add(filter); + + openFileDialog.Title = "Open Image"; + + var result = await openFileDialog.ShowAsync(m_Window); + return result; + } + } +} diff --git a/Views/IAvalarViewService.cs b/Views/IAvalarViewService.cs new file mode 100644 index 0000000..cb0c896 --- /dev/null +++ b/Views/IAvalarViewService.cs @@ -0,0 +1,9 @@ +using System.Threading.Tasks; + +namespace Avalar.Views +{ + public interface IAvalarViewService + { + Task<string[]> ShowOpenImageFileDialog(); + } +}
\ No newline at end of file diff --git a/Views/Image/ImageControl.xaml b/Views/Image/ImageControl.xaml new file mode 100644 index 0000000..c1c176e --- /dev/null +++ b/Views/Image/ImageControl.xaml @@ -0,0 +1,16 @@ +<UserControl xmlns="https://github.com/avaloniaui" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + x:Class="Avalar.Views.Image.ImageControl"> + <UserControl.Resources> + <ImageBrush x:Key="ImageBrush" Source="{Binding Bitmap}" Stretch="Uniform"/> + </UserControl.Resources> + <Grid> + <Canvas Name="ImageCanvas" + HorizontalAlignment="Stretch" VerticalAlignment="Stretch" + Background="{StaticResource ImageBrush}" + PointerWheelChanged="OnPointerWheelChanged"/> + </Grid> +</UserControl> diff --git a/Views/Image/ImageControl.xaml.cs b/Views/Image/ImageControl.xaml.cs new file mode 100644 index 0000000..2189bb0 --- /dev/null +++ b/Views/Image/ImageControl.xaml.cs @@ -0,0 +1,100 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Input; +using Avalonia.Markup.Xaml; +using Avalonia.Media; +using System; + +namespace Avalar.Views.Image +{ + public class ImageControl : UserControl + { + private const double ZoomTick = 0.1; + private double CurrentZoom { get; set; } = 1.0; + + private double InvCurrentZoom => 1 / CurrentZoom; + + private ImageBrush Image { get; } + + private Canvas ImageCanvas { get; } + public ImageControl() + { + InitializeComponent(); + + Image = this.FindResource("ImageBrush") as ImageBrush ?? throw new System.ArgumentException("ImageBrush"); + ImageCanvas = this.FindControl<Canvas>("ImageCanvas"); + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + + private Point MousePointerInImageSpace(Point mouseCoordinates) + { + var imageSize = Image.Source.Size; + var canvasSize = new Size(ImageCanvas.Bounds.Width, ImageCanvas.Bounds.Height); + + double focalPointX; + double focalPointY; + + if (canvasSize.AspectRatio > imageSize.AspectRatio) + { + focalPointY = mouseCoordinates.Y / canvasSize.Height; + + var halfUnusedX = (canvasSize.AspectRatio - imageSize.AspectRatio) * canvasSize.Width / 2; + var clampedX = Math.Clamp(mouseCoordinates.X - halfUnusedX, 0, imageSize.Width); + + focalPointX = clampedX / imageSize.Width; + } + else + { + focalPointX = mouseCoordinates.X / canvasSize.Width; + + var halfUnusedY = 1 / (canvasSize.AspectRatio - imageSize.AspectRatio) * canvasSize.Height / 2; + var clampedY = Math.Clamp(mouseCoordinates.Y - halfUnusedY, 0, imageSize.Height); + + focalPointY = clampedY / imageSize.Height; + } + + return new Point(focalPointX, focalPointY); + } + + private Point TransformToSourceRectSpace(Point from) + { + var sourceRectPosition = Image.SourceRect.Rect.Position; + var sourceRectSize = Image.SourceRect.Rect.Size; + return new Point( + from.X * sourceRectSize.Width + sourceRectPosition.X, + from.Y * sourceRectSize.Height + sourceRectPosition.Y + ); + } + + public void OnPointerWheelChanged(object sender, PointerWheelEventArgs e) + { + var invOldZoom = InvCurrentZoom; + var zoomFactor = e.Delta.Y * ZoomTick + 1.0; + CurrentZoom = Math.Clamp(CurrentZoom * zoomFactor, 1, double.PositiveInfinity); + + var sourceRect = Image.SourceRect.Rect; + + var canvasMouseCoordinates = e.GetPosition(ImageCanvas); + + var currentCenter = sourceRect.Center; + var desiredCenterInImageCoords = MousePointerInImageSpace(canvasMouseCoordinates); + if(e.Delta.Y < 0) + { + desiredCenterInImageCoords = new Point(1 - desiredCenterInImageCoords.X, 1 - desiredCenterInImageCoords.Y); + } + var desiredCenter = TransformToSourceRectSpace(desiredCenterInImageCoords); + + var maxTravelDistance = Math.Abs(invOldZoom - InvCurrentZoom); + + var newCenterX = Math.Clamp(desiredCenter.X, currentCenter.X - maxTravelDistance, currentCenter.X + maxTravelDistance); + var newCenterY = Math.Clamp(desiredCenter.Y, currentCenter.Y - maxTravelDistance, currentCenter.Y + maxTravelDistance); + + var sourceRectNewTopLeft = new Point(newCenterX - InvCurrentZoom / 2, newCenterY - InvCurrentZoom / 2); + Image.SourceRect = new RelativeRect(sourceRectNewTopLeft, new Size(InvCurrentZoom, InvCurrentZoom), RelativeUnit.Relative); + } + } +} diff --git a/Views/Image/ImagePanel.xaml b/Views/Image/ImagePanel.xaml new file mode 100644 index 0000000..f54458d --- /dev/null +++ b/Views/Image/ImagePanel.xaml @@ -0,0 +1,26 @@ +<UserControl xmlns="https://github.com/avaloniaui" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:vms="clr-namespace:Avalar.ViewModels.Image" + xmlns:local="clr-namespace:Avalar.Views.Image" + mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + x:Class="Avalar.Views.Image.ImagePanel"> + <Border Margin="5"> + <ContentControl Content="{Binding ChildViewModel}"> + <ContentControl.DataTemplates> + <DataTemplate DataType="{x:Type vms:ImageLoadedViewModel}"> + <local:ImageControl/> + </DataTemplate> + <DataTemplate DataType="{x:Type vms:ImageNotLoadedViewModel}"> + <Button Command="{Binding OpenFileCommand}"> + <ItemsControl> + <TextBlock Text="No image loaded"/> + <TextBlock Text="Click here or drag an image over this area to load."/> + </ItemsControl> + </Button> + </DataTemplate> + </ContentControl.DataTemplates> + </ContentControl> + </Border> +</UserControl> diff --git a/Views/Image/ImagePanel.xaml.cs b/Views/Image/ImagePanel.xaml.cs new file mode 100644 index 0000000..bc18611 --- /dev/null +++ b/Views/Image/ImagePanel.xaml.cs @@ -0,0 +1,19 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace Avalar.Views.Image +{ + public class ImagePanel : UserControl + { + public ImagePanel() + { + this.InitializeComponent(); + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + } +} diff --git a/Views/Settings/Settings.xaml b/Views/Settings/Settings.xaml new file mode 100644 index 0000000..dfc8602 --- /dev/null +++ b/Views/Settings/Settings.xaml @@ -0,0 +1,9 @@ +<UserControl xmlns="https://github.com/avaloniaui" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" + x:Class="Avalar.Views.Settings.Settings" + MinWidth="400"> + Welcome to Avalonia! +</UserControl> diff --git a/Views/Settings/Settings.xaml.cs b/Views/Settings/Settings.xaml.cs new file mode 100644 index 0000000..4504460 --- /dev/null +++ b/Views/Settings/Settings.xaml.cs @@ -0,0 +1,18 @@ +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace Avalar.Views.Settings +{ + public class Settings : UserControl + { + public Settings() + { + InitializeComponent(); + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + } +}
\ No newline at end of file diff --git a/avalar.sln b/avalar.sln new file mode 100644 index 0000000..6a22056 --- /dev/null +++ b/avalar.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29519.181 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalar", "Avalar.csproj", "{EE5881DC-0C8F-42B1-A8EA-9CAA5840D72D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EE5881DC-0C8F-42B1-A8EA-9CAA5840D72D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EE5881DC-0C8F-42B1-A8EA-9CAA5840D72D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EE5881DC-0C8F-42B1-A8EA-9CAA5840D72D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EE5881DC-0C8F-42B1-A8EA-9CAA5840D72D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {24ED781A-FAE3-4ED5-9F7F-7D923A794C5C} + EndGlobalSection +EndGlobal diff --git a/nuget.config b/nuget.config new file mode 100644 index 0000000..7c07e22 --- /dev/null +++ b/nuget.config @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<configuration> + <packageSources> + <add key="AvaloniaCI" value="https://www.myget.org/F/avalonia-ci/api/v2" /> + </packageSources> +</configuration>
\ No newline at end of file |
