Skip to content

Commit

Permalink
Update for multi monitor support for different screen resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Jun 16, 2019
1 parent 0e4d969 commit f2d063f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
25 changes: 19 additions & 6 deletions PicView/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ private void MainWindow_ContentRendered(object sender, EventArgs e)
MouseMove += MainWindow_MouseMove;
MouseLeave += MainWindow_MouseLeave;

Microsoft.Win32.SystemEvents.DisplaySettingsChanged += (x, y) => Pic(FolderIndex);

#endregion Add events

// Add Timers
Expand Down Expand Up @@ -840,6 +842,7 @@ private void Move(object sender, MouseButtonEventArgs e)
}
}


/// <summary>
/// Function made to restore and drag window from maximized windowstate
/// </summary>
Expand Down Expand Up @@ -2430,7 +2433,6 @@ private void Zoom_img_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
}

/// <summary>
/// Occurs when the users clicks on the img control
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
Expand Down Expand Up @@ -2682,17 +2684,28 @@ private void ZoomFit(double width, double height)
double maxWidth, maxHeight;
var interfaceHeight = 93; // TopBar + LowerBar height

var currentMonitor = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(Application.Current.MainWindow).Handle);

//find out if our app is being scaled by the monitor
PresentationSource source = PresentationSource.FromVisual(Application.Current.MainWindow);
double dpiScaling = (source != null && source.CompositionTarget != null ? source.CompositionTarget.TransformFromDevice.M11 : 1);

//get the available area of the monitor
System.Drawing.Rectangle workArea = currentMonitor.WorkingArea;
var workAreaWidth = (int)Math.Floor(workArea.Width * dpiScaling);
var workAreaHeight = (int)Math.Floor(workArea.Height * dpiScaling);

if (windowstyle)
{
// Get max width and height, based on user's screen
maxWidth = Math.Min(SystemParameters.PrimaryScreenWidth - ComfySpace, width);
maxHeight = Math.Min((SystemParameters.FullPrimaryScreenHeight - interfaceHeight), height);
maxWidth = Math.Min(workAreaWidth - ComfySpace, width);
maxHeight = Math.Min((workAreaHeight - interfaceHeight), height);
}
else
{
// Get max width and height, based on window size
maxWidth = Math.Min(Width, width);
maxHeight = Math.Min(Height - interfaceHeight, height);
maxWidth = Math.Min(workAreaWidth, width);
maxHeight = Math.Min(workAreaHeight - interfaceHeight, height);
}

AspectRatio = Math.Min((maxWidth / width), (maxHeight / height));
Expand Down Expand Up @@ -2735,7 +2748,7 @@ private void ZoomFit(double width, double height)
}
else
{
if (Width - interfaceSize < interfaceSize)
if (workAreaWidth - interfaceSize < interfaceSize)
Bar.MaxWidth = interfaceSize;
else
Bar.MaxWidth = Width - interfaceSize;
Expand Down
9 changes: 5 additions & 4 deletions PicView/PicVIew.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<Reference Include="Magick.NET-Q16-HDRI-x64, Version=7.11.0.0, Culture=neutral, PublicKeyToken=2004825badfa91ec, processorArchitecture=AMD64">
<HintPath>..\packages\Magick.NET-Q16-HDRI-x64.7.11.0\lib\net40\Magick.NET-Q16-HDRI-x64.dll</HintPath>
<Reference Include="Magick.NET-Q16-HDRI-x64, Version=7.13.1.0, Culture=neutral, PublicKeyToken=2004825badfa91ec, processorArchitecture=AMD64">
<HintPath>..\packages\Magick.NET-Q16-HDRI-x64.7.13.1\lib\net40\Magick.NET-Q16-HDRI-x64.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.VisualBasic" />
Expand Down Expand Up @@ -128,6 +128,7 @@
</ApplicationDefinition>
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="lib\ArchiveExtraction.cs" />
<Compile Include="lib\CheckScreenChanged.cs" />
<Compile Include="lib\FileAssociation.cs" />
<Compile Include="lib\FileFunctions.cs" />
<Compile Include="lib\NativeMethods.cs" />
Expand Down Expand Up @@ -415,12 +416,12 @@
</FileAssociation>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Magick.NET-Q16-HDRI-x64.7.11.0\build\net40\Magick.NET-Q16-HDRI-x64.targets" Condition="Exists('..\packages\Magick.NET-Q16-HDRI-x64.7.11.0\build\net40\Magick.NET-Q16-HDRI-x64.targets')" />
<Import Project="..\packages\Magick.NET-Q16-HDRI-x64.7.13.1\build\net40\Magick.NET-Q16-HDRI-x64.targets" Condition="Exists('..\packages\Magick.NET-Q16-HDRI-x64.7.13.1\build\net40\Magick.NET-Q16-HDRI-x64.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Magick.NET-Q16-HDRI-x64.7.11.0\build\net40\Magick.NET-Q16-HDRI-x64.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Magick.NET-Q16-HDRI-x64.7.11.0\build\net40\Magick.NET-Q16-HDRI-x64.targets'))" />
<Error Condition="!Exists('..\packages\Magick.NET-Q16-HDRI-x64.7.13.1\build\net40\Magick.NET-Q16-HDRI-x64.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Magick.NET-Q16-HDRI-x64.7.13.1\build\net40\Magick.NET-Q16-HDRI-x64.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
12 changes: 12 additions & 0 deletions PicView/lib/CheckScreenChanged.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PicView.lib
{
class CheckScreenChanged
{
}
}
2 changes: 1 addition & 1 deletion PicView/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Magick.NET-Q16-HDRI-x64" version="7.11.0" targetFramework="net472" />
<package id="Magick.NET-Q16-HDRI-x64" version="7.13.1" targetFramework="net472" />
<package id="XamlAnimatedGif" version="1.2.1" targetFramework="net472" />
</packages>

0 comments on commit f2d063f

Please sign in to comment.