Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions FlyleafLib/Engine/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,16 @@ public ThreadPriority
/// </summary>
public Usage Usage { get; set; } = Usage.AVS;

/// <summary>
/// Restrict panning of the video outside of half the video width or height
/// </summary>
public bool RestrictPanning { get; set; } = false;

/// <summary>
/// Reset pan and zoom level when zooming out to less than 100%
/// </summary>
public bool ResetPanOnZoomedOut { get; set; } = false;

// Offsets
public long AudioDelayOffset { get; set; } = 100 * 10000;
public long AudioDelayOffset2 { get; set; } = 1000 * 10000;
Expand Down
37 changes: 36 additions & 1 deletion FlyleafLib/MediaFramework/MediaRenderer/Renderer.SwapChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,43 @@ public void SetViewport(bool refresh = true)
yZoomPixels = newHeight - (ControlHeight - SideYPixels);
}

if (Config.Player.RestrictPanning)
{
// Don't let the user pan or zoom outside of half the video's height
int newY = (int)(y - yZoomPixels * (float)zoomCenter.Y);
int bottom = newHeight + newY;
if (newY > ControlHeight / 2d)
{
y = (int)((ControlHeight / 2d) + yZoomPixels * (float)zoomCenter.Y);
panYOffset = y - SideYPixels / 2;
}
else if (bottom < ControlHeight / 2d)
{
int newBottom = (int)(ControlHeight / 2d);
int newNewY = newBottom - newHeight;
y = (int)(newNewY + yZoomPixels * (float)zoomCenter.Y);
panYOffset = y - SideYPixels / 2;
}

// Don't let the user pan or zoom outside of half the video's width
int newX = (int)(x - xZoomPixels * (float)zoomCenter.X);
int right = newWidth + newX;
if (newX > ControlWidth / 2d)
{
x = (int)((ControlWidth / 2d) + xZoomPixels * (float)zoomCenter.X);
panXOffset = x - SideXPixels / 2;
}
else if (right < ControlWidth / 2d)
{
int newRight = (int)(ControlWidth / 2d);
int newNewX = newRight - newWidth;
x = (int)(newNewX + xZoomPixels * (float)zoomCenter.X);
panXOffset = x - SideXPixels / 2;
}
}

GetViewport = new(x - xZoomPixels * (float)zoomCenter.X, y - yZoomPixels * (float)zoomCenter.Y, newWidth, newHeight);
ViewportChanged?.Invoke(this, new());
ViewportChanged?.Invoke(this, EventArgs.Empty);

if (videoProcessor == VideoProcessors.D3D11)
{
Expand Down
31 changes: 31 additions & 0 deletions FlyleafLib/MediaFramework/MediaRenderer/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ public void SetZoom(double zoom, bool refresh = true)
{
lock(lockDevice)
{
if (Config.Player.ResetPanOnZoomedOut)
{
if (zoom < 1)
{
ResetPanAndZoom(refresh);
return;
}
}

this.zoom = zoom;

if (Disposed)
Expand Down Expand Up @@ -151,6 +160,15 @@ public void SetZoomAndCenter(double zoom, Point p, bool refresh = true)
{
lock(lockDevice)
{
if (Config.Player.ResetPanOnZoomedOut)
{
if (zoom < 1)
{
ResetPanAndZoom(refresh);
return;
}
}

this.zoom = zoom;
zoomCenter = p;

Expand Down Expand Up @@ -179,6 +197,19 @@ public void SetPanAll(int panX, int panY, uint rotation, double zoom, Point p, b
}
}

private void ResetPanAndZoom(bool refresh = true)
{
panXOffset = panYOffset = 0;
zoom = 1;
zoomCenter = ZoomCenterPoint;

if (Disposed)
return;

if (refresh)
SetViewport();
}

public int UniqueId { get; private set; }
public bool HasFLFilters { get; private set; }
public VideoFrame LastFrame { get; set; }
Expand Down