Skip to content

Commit

Permalink
Merge pull request #40 from jeremyknight-me/full-screen-mode
Browse files Browse the repository at this point in the history
Full screen mode thanks to @LoganRupe
  • Loading branch information
jeremyknight-me authored Sep 17, 2023
2 parents ae081ed + 11982d5 commit 18aec3e
Show file tree
Hide file tree
Showing 29 changed files with 832 additions and 277 deletions.
8 changes: 4 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ insert_final_newline = true
trim_trailing_whitespace = true

[*.{cs,vb}]
# Organize usings
# Organize usings and namespaces
dotnet_sort_system_directives_first = true
csharp_style_namespace_declarations = file_scoped:suggestion

# this. and me. preferences
dotnet_style_qualification_for_event = true:warning
Expand Down Expand Up @@ -140,7 +141,7 @@ csharp_new_line_before_open_brace = all
csharp_new_line_between_query_expression_clauses = true

# Wrapping preferences
csharp_preserve_single_line_blocks = false
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = false

# Space preferences
Expand All @@ -165,5 +166,4 @@ csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = none
csharp_space_between_square_brackets = false
csharp_style_namespace_declarations=block_scoped:suggestion
csharp_space_between_square_brackets = false
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## Unreleased

_There are currently no unreleased changes._
### Changed
* Upgraded to .NET 7.

### Added
* Added option for full-screen
* Added extra options for transition speed
* Added option to stretch or center full-screen display
* Added option to fix rotation based on EXIF metadata for full-screen display

## [Version 4.0.0](../../releases/tag/v4) - 09 November 2021
### Changed
Expand Down
30 changes: 16 additions & 14 deletions PhotoCollage.Common/CollageSettings.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
using PhotoCollage.Common.Enums;

namespace PhotoCollage.Common
namespace PhotoCollage.Common;

public class CollageSettings
{
public class CollageSettings
{
public string Directory { get; set; } = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
public bool IsGrayscale { get; set; } = false;
public bool IsRandom { get; set; } = true;
public int MaximumRotation { get; set; } = 15;
public int MaximumSize { get; set; } = 500;
public int NumberOfPhotos { get; set; } = 10;
public double Opacity { get; set; } = 1.0;
public BorderType PhotoBorderType { get; set; } = BorderType.Border;
public ScreensaverSpeed Speed { get; set; } = ScreensaverSpeed.Medium;
public bool UseVerboseLogging { get; set; } = false;
}
public string Directory { get; set; } = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
public bool IsGrayscale { get; set; } = false;
public bool IsRandom { get; set; } = true;
public int MaximumRotation { get; set; } = 15;
public int MaximumSize { get; set; } = 500;
public bool IsFullScreen { get; set; } = false;
public bool RotateBasedOnEXIF { get; set; } = false;
public int NumberOfPhotos { get; set; } = 10;
public double Opacity { get; set; } = 1.0;
public BorderType PhotoBorderType { get; set; } = BorderType.Border;
public ScreensaverSpeed Speed { get; set; } = ScreensaverSpeed.Medium;
public FullScreenMode PhotoFullScreenMode { get; set; } = FullScreenMode.Centered;
public bool UseVerboseLogging { get; set; } = false;
}
7 changes: 7 additions & 0 deletions PhotoCollage.Common/Enums/FullScreenMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace PhotoCollage.Common.Enums;

public enum FullScreenMode
{
Stretched,
Centered
}
20 changes: 20 additions & 0 deletions PhotoCollage.Common/Enums/FullScreenModeHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace PhotoCollage.Common.Enums;

public static class FullScreenModeHelper
{
public const string Stretched = "Stretched";
public const string Centered = "Centered";

public static IDictionary<FullScreenMode, KeyValuePair<string, string>> MakeDictionary()
=> new Dictionary<FullScreenMode, KeyValuePair<string, string>>
{
{
FullScreenMode.Stretched,
new KeyValuePair<string, string>(Stretched.ToLower(), Stretched)
},
{
FullScreenMode.Centered,
new KeyValuePair<string, string> (Centered.ToLower(), Centered)
}
};
}
2 changes: 2 additions & 0 deletions PhotoCollage.Common/Enums/ScreensaverSpeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

public enum ScreensaverSpeed
{
SuperSlow = 20,
ReallySlow = 10,
Slow = 6,
Medium = 4,
Fast = 2
Expand Down
10 changes: 7 additions & 3 deletions PhotoCollage.Common/Enums/ScreensaverSpeedHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

public static class ScreensaverSpeedHelper
{
public const string SuperSlow = "Super Slow";
public const string ReallySlow = "Really Slow";
public const string Slow = "Slow";
public const string Medium = "Medium";
public const string Fast = "Fast";

public static IDictionary<ScreensaverSpeed, string> MakeDictionary()
=> new Dictionary<ScreensaverSpeed, string>
{
{ ScreensaverSpeed.Slow, Slow },
{ ScreensaverSpeed.Medium, Medium },
{ ScreensaverSpeed.Fast, Fast }
{ ScreensaverSpeed.SuperSlow, SuperSlow },
{ ScreensaverSpeed.ReallySlow, ReallySlow },
{ ScreensaverSpeed.Slow, Slow },
{ ScreensaverSpeed.Medium, Medium },
{ ScreensaverSpeed.Fast, Fast }
};
}
9 changes: 5 additions & 4 deletions PhotoCollageScreensaver/ApplicationController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using PhotoCollageScreensaver.Logging;
using System.IO;
using PhotoCollageScreensaver.Data;
using PhotoCollageScreensaver.Logging;
using PhotoCollageScreensaver.ViewModels;
using PhotoCollageScreensaver.Views;
using System.IO;
using PhotoCollage.Common;

namespace PhotoCollageScreensaver;

Expand All @@ -26,7 +25,9 @@ public ApplicationController()

public void StartScreensaver()
{
var collagePresenter = this.collagePresenter ??= new CollagePresenter(this, this.configuration);
var collagePresenter = this.configuration.IsFullScreen
? this.collagePresenter ??= new CollagePresenterFullscreen(this, this.configuration)
: this.collagePresenter ??= new CollagePresenterCollage(this, this.configuration);
foreach (var screen in Monitors.Monitor.GetScreens())
{
var collageWindow = new CollageWindow(this);
Expand Down
119 changes: 22 additions & 97 deletions PhotoCollageScreensaver/CollagePresenter.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,39 @@
using PhotoCollage.Common;
using PhotoCollage.Common.Data;
using PhotoCollageScreensaver.UserControls;
using PhotoCollageScreensaver.Views;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading;
using System.Windows.Media;
using System.Windows.Threading;
using PhotoCollage.Common.Data;
using PhotoCollageScreensaver.Views;

namespace PhotoCollageScreensaver;

public sealed class CollagePresenter
public abstract class CollagePresenter
{
private readonly Random random;
private readonly List<ICollageView> views;
private readonly IPhotoRepository photoRepository;
private readonly ConcurrentQueue<CollageImage> imageQueue;
private readonly ApplicationController controller;
private int displayViewIndex;
protected readonly IPhotoRepository PhotoRepository;
protected readonly ApplicationController Controller;
protected int DisplayViewIndex;
protected readonly List<ICollageView> Views;

public CollagePresenter(ApplicationController controllerToUse, CollageSettings configurationToUse)
{
this.random = new Random();
this.views = new List<ICollageView>();
this.imageQueue = new ConcurrentQueue<CollageImage>();
this.controller = controllerToUse;
this.Views = new List<ICollageView>();
this.Controller = controllerToUse;
this.Configuration = configurationToUse;
this.photoRepository = new PhotoRepositoryFactory(this.Configuration).Make();
this.displayViewIndex = -1;
this.PhotoRepository = new PhotoRepositoryFactory(this.Configuration).Make();
this.DisplayViewIndex = -1;
}

public CollageSettings Configuration
{
get;
}
public CollageSettings Configuration { get; }

public void StartAnimation()
{
try
{
if (!this.photoRepository.HasPhotos)
if (!this.PhotoRepository.HasPhotos)
{
this.controller.DisplayErrorMessage("Folder does not contain any supported photos.");
this.controller.Shutdown();
this.Controller.DisplayErrorMessage("Folder does not contain any supported photos.");
this.Controller.Shutdown();
}

this.DisplayImageTimerTick(null, null);
Expand All @@ -53,7 +45,7 @@ public void StartAnimation()
}
catch (Exception ex)
{
this.controller.HandleError(ex);
this.Controller.HandleError(ex);
}
}

Expand All @@ -65,9 +57,9 @@ public int GetRandomNumber(int min, int max)
return value;
}

public void HandleError(Exception ex, bool showMessage = false) => this.controller.HandleError(ex, showMessage);
public void HandleError(Exception ex, bool showMessage = false) => this.Controller.HandleError(ex, showMessage);

public void SetupWindow<T>(T window, Monitors.Screen screen) where T : Window, ICollageView
public virtual void SetupWindow<T>(T window, Monitors.Screen screen) where T : Window, ICollageView
{
var backgroundBrush = new SolidColorBrush
{
Expand All @@ -80,77 +72,10 @@ public void SetupWindow<T>(T window, Monitors.Screen screen) where T : Window, I
window.Width = screen.Width;
window.Height = screen.Height;
window.Show();
this.views.Add(window);
}

private void DisplayImageTimerTick(object sender, EventArgs e)
{
try
{
var path = this.photoRepository.GetNextPhotoFilePath();
var view = this.GetNextDisplayView();
var control = new CollageImage(path, this);
view.ImageCanvas.Children.Add(control);
this.imageQueue.Enqueue(control);

if (this.imageQueue.Count > this.Configuration.NumberOfPhotos)
{
this.RemoveImageFromQueue();
}

this.SetUserControlPosition(control, view);
}
catch (Exception ex)
{
this.controller.HandleError(ex);
this.controller.Shutdown();
}
}

private ICollageView GetNextDisplayView()
{
var nextIndex = this.displayViewIndex + 1;
if (nextIndex >= this.views.Count)
{
nextIndex = 0;
}

this.displayViewIndex = nextIndex;
return this.views[nextIndex];
this.Views.Add(window);
}

private void RemoveImageFromQueue()
{
if (this.imageQueue.TryDequeue(out var control))
{
Action<CollageImage> action = this.RemoveImageFromPanel;
control.FadeOutImage(action);
}
}
protected abstract void DisplayImageTimerTick(object sender, EventArgs e);

private void RemoveImageFromPanel(CollageImage control)
{
try
{
foreach (var view in this.views)
{
if (view.ImageCanvas.Children.Contains(control))
{
view.ImageCanvas.Children.Remove(control);
control.Dispose();
break;
}
}
}
catch (Exception ex)
{
this.controller.HandleError(ex);
}
}

private void SetUserControlPosition(UIElement control, ICollageView view)
{
var positioner = new ImagePositioner(this, control, view);
positioner.Position();
}
protected abstract void SetUserControlPosition(UIElement control, ICollageView view);
}
Loading

0 comments on commit 18aec3e

Please sign in to comment.