Skip to content

Commit

Permalink
Set default position of pip mode window
Browse files Browse the repository at this point in the history
  • Loading branch information
LionelJouin committed Jul 2, 2018
1 parent 89fbc35 commit 5eaa97c
Showing 1 changed file with 44 additions and 7 deletions.
51 changes: 44 additions & 7 deletions PiP-Tool/ViewModels/PiPModeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class PiPModeViewModel : ViewModelBase, ICloseable, IDisposable

public const int MinSize = 100;
public const float DefaultSizePercentage = 0.25f;
public const float DefaultPositionPercentage = 0.1f;
public const int TopBarHeight = 30;

public event EventHandler<EventArgs> RequestClose;
Expand Down Expand Up @@ -153,6 +154,8 @@ public Visibility TopBarVisibility
private IntPtr _targetHandle, _thumbHandle;
private SelectedWindow _selectedWindow;

private enum Position { TopLeft, TopRight, BottomLeft, BottomRight }

#endregion

/// <inheritdoc />
Expand Down Expand Up @@ -199,7 +202,8 @@ private void InitSelectedWindow(SelectedWindow selectedWindow)

_renderSizeEventDisabled = false;

SetDefaultSize();
SetSize(DefaultSizePercentage);
SetPosition(Position.BottomLeft);
SetAsForegroundWindow();

InitDwmThumbnail();
Expand Down Expand Up @@ -259,25 +263,58 @@ public void SetAsForegroundWindow()
}

/// <summary>
/// Set default size of this window
/// Set size of this window
/// </summary>
public void SetDefaultSize()
private void SetSize(float sizePercentage)
{
_renderSizeEventDisabled = true;
var resolution = Screen.PrimaryScreen.Bounds;
if (Height > resolution.Height * DefaultSizePercentage)
if (Height > resolution.Height * sizePercentage)
{
Height = (int)(resolution.Height * DefaultSizePercentage);
Height = (int)(resolution.Height * sizePercentage);
Width = Convert.ToInt32(Height * Ratio);
}
if (Width > resolution.Width * DefaultSizePercentage)
if (Width > resolution.Width * sizePercentage)
{
Width = (int)(resolution.Width * DefaultSizePercentage);
Width = (int)(resolution.Width * sizePercentage);
Height = Convert.ToInt32(Width * _selectedWindow.RatioHeightByWidth);
}
_renderSizeEventDisabled = false;
}

/// <summary>
/// Set position of this window
/// </summary>
private void SetPosition(Position position)
{
_renderSizeEventDisabled = true;
var resolution = Screen.PrimaryScreen.Bounds;
var top = 0;
var left = 0;
switch (position)
{
case Position.TopLeft:
top = (int) (resolution.Height * DefaultPositionPercentage);
left = (int)(resolution.Width * DefaultPositionPercentage);
break;
case Position.TopRight:
top = (int)(resolution.Height * DefaultPositionPercentage);
left = resolution.Width - Width - (int)(resolution.Width * DefaultPositionPercentage);
break;
case Position.BottomLeft:
top = resolution.Height - Height - (int)(resolution.Height * DefaultPositionPercentage);
left = (int)(resolution.Width * DefaultPositionPercentage);
break;
case Position.BottomRight:
top = resolution.Height - Height - (int)(resolution.Height * DefaultPositionPercentage);
left = resolution.Width - Width - (int)(resolution.Width * DefaultPositionPercentage);
break;
}
Top = top;
Left = left;
_renderSizeEventDisabled = false;
}

/// <summary>
/// Gets this window
/// </summary>
Expand Down

0 comments on commit 5eaa97c

Please sign in to comment.