Skip to content

Commit

Permalink
code cleanup and began new editorconfig setting integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyknight-me committed Sep 17, 2023
1 parent 23184bd commit b775987
Show file tree
Hide file tree
Showing 22 changed files with 89 additions and 119 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## Unreleased

### Changed
* Upgraded to .NET 7.

### Added
* Added option for full-screen
* Added extra options for transition speed
* Added option to stretch or centre full-screen display
* 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
Expand Down
33 changes: 16 additions & 17 deletions PhotoCollage.Common/CollageSettings.cs
Original file line number Diff line number Diff line change
@@ -1,21 +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 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.Centred;
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;
}
2 changes: 1 addition & 1 deletion PhotoCollage.Common/Enums/FullScreenMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
public enum FullScreenMode
{
Stretched,
Centred
Centered
}
12 changes: 9 additions & 3 deletions PhotoCollage.Common/Enums/FullScreenModeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
public static class FullScreenModeHelper
{
public const string Stretched = "Stretched";
public const string Centred = "Centred";
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", Stretched) },
{ FullScreenMode.Centred, new KeyValuePair<string, string> ("centred", Centred) }
{
FullScreenMode.Stretched,
new KeyValuePair<string, string>(Stretched.ToLower(), Stretched)
},
{
FullScreenMode.Centered,
new KeyValuePair<string, string> (Centered.ToLower(), Centered)
}
};
}
10 changes: 5 additions & 5 deletions PhotoCollage.Common/Enums/ScreensaverSpeedHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public static class ScreensaverSpeedHelper
public static IDictionary<ScreensaverSpeed, string> MakeDictionary()
=> new Dictionary<ScreensaverSpeed, string>
{
{ ScreensaverSpeed.SuperSlow, SuperSlow },
{ ScreensaverSpeed.ReallySlow, ReallySlow },
{ ScreensaverSpeed.Slow, Slow },
{ ScreensaverSpeed.Medium, Medium },
{ ScreensaverSpeed.Fast, Fast }
{ ScreensaverSpeed.SuperSlow, SuperSlow },
{ ScreensaverSpeed.ReallySlow, ReallySlow },
{ ScreensaverSpeed.Slow, Slow },
{ ScreensaverSpeed.Medium, Medium },
{ ScreensaverSpeed.Fast, Fast }
};
}
4 changes: 3 additions & 1 deletion PhotoCollageScreensaver/ApplicationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public ApplicationController()

public void StartScreensaver()
{
var collagePresenter = this.configuration.IsFullScreen ? this.collagePresenter ??= new CollagePresenterFullscreen(this, this.configuration) : this.collagePresenter ??= new CollagePresenterCollage(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
16 changes: 4 additions & 12 deletions PhotoCollageScreensaver/CollagePresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace PhotoCollageScreensaver;

public abstract class CollagePresenter: ICollagePresenter
public abstract class CollagePresenter
{
private readonly Random random;
protected readonly IPhotoRepository PhotoRepository;
Expand All @@ -25,10 +25,7 @@ public CollagePresenter(ApplicationController controllerToUse, CollageSettings c
this.DisplayViewIndex = -1;
}

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

public void StartAnimation()
{
Expand Down Expand Up @@ -76,15 +73,10 @@ public virtual void SetupWindow<T>(T window, Monitors.Screen screen) where T : W
window.Width = screen.Width;
window.Height = screen.Height;
window.Show();
window.IsPortrait = screen.Height > screen.Width;
this.Views.Add(window);
}

protected virtual void DisplayImageTimerTick(object sender, EventArgs e)
{
}
protected abstract void DisplayImageTimerTick(object sender, EventArgs e);

protected virtual void SetUserControlPosition(UIElement control, ICollageView view)
{
}
protected abstract void SetUserControlPosition(UIElement control, ICollageView view);
}
5 changes: 3 additions & 2 deletions PhotoCollageScreensaver/CollagePresenterCollage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

namespace PhotoCollageScreensaver;

public class CollagePresenterCollage: CollagePresenter, ICollagePresenter
public sealed class CollagePresenterCollage : CollagePresenter
{
private readonly ConcurrentQueue<CollageImage> imageQueue;

public CollagePresenterCollage(ApplicationController controllerToUse, CollageSettings configurationToUse) : base(controllerToUse, configurationToUse)
public CollagePresenterCollage(ApplicationController controllerToUse, CollageSettings configurationToUse)
: base(controllerToUse, configurationToUse)
{
this.imageQueue = new ConcurrentQueue<CollageImage>();
}
Expand Down
5 changes: 3 additions & 2 deletions PhotoCollageScreensaver/CollagePresenterFullscreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

namespace PhotoCollageScreensaver;

public class CollagePresenterFullscreen: CollagePresenter, ICollagePresenter
public sealed class CollagePresenterFullscreen : CollagePresenter
{
private readonly List<ConcurrentQueue<CollageImage>> imageQueues;
private readonly Queue<string> skippedPortraitImagePaths;
private readonly Queue<string> skippedLandscapeImagePaths;

public CollagePresenterFullscreen(ApplicationController controllerToUse, CollageSettings configurationToUse): base(controllerToUse, configurationToUse)
public CollagePresenterFullscreen(ApplicationController controllerToUse, CollageSettings configurationToUse)
: base(controllerToUse, configurationToUse)
{
this.imageQueues = new List<ConcurrentQueue<CollageImage>>();
this.skippedPortraitImagePaths = new Queue<string>();
Expand Down
15 changes: 7 additions & 8 deletions PhotoCollageScreensaver/EnumExtension.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System.Linq;

namespace PhotoCollageScreensaver
{
using System.Collections.Generic;
namespace PhotoCollageScreensaver;

using System.Collections.Generic;

public static class EnumExtension
{
public static IEnumerable<(T item, int index)> WithIndex<T>(this IEnumerable<T> self)
=> self.Select((item, index) => (item, index));
}
public static class EnumExtension
{
public static IEnumerable<(T item, int index)> WithIndex<T>(this IEnumerable<T> self)
=> self.Select((item, index) => (item, index));
}
20 changes: 0 additions & 20 deletions PhotoCollageScreensaver/ICollagePresenter.cs

This file was deleted.

6 changes: 0 additions & 6 deletions PhotoCollageScreensaver/IImagePositioner.cs

This file was deleted.

6 changes: 2 additions & 4 deletions PhotoCollageScreensaver/ImagePositioner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace PhotoCollageScreensaver;

internal abstract class ImagePositioner : IImagePositioner
internal abstract class ImagePositioner
{
protected readonly CollagePresenter Presenter;
protected readonly UIElement Control;
Expand All @@ -22,7 +22,5 @@ public ImagePositioner(CollagePresenter presenterToUse, UIElement controlToPosit
this.ViewportWidth = Convert.ToInt32(view.WindowActualWidth);
}

public virtual void Position()
{
}
public abstract void Position();
}
6 changes: 3 additions & 3 deletions PhotoCollageScreensaver/ImagePositionerCollage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

namespace PhotoCollageScreensaver;

internal class ImagePositionerCollage: ImagePositioner, IImagePositioner
internal sealed class ImagePositionerCollage : ImagePositioner
{
public ImagePositionerCollage(CollagePresenter presenterToUse, UIElement controlToPosition, ICollageView view) : base(presenterToUse, controlToPosition, view)
public ImagePositionerCollage(CollagePresenter presenterToUse, UIElement controlToPosition, ICollageView view)
: base(presenterToUse, controlToPosition, view)
{

}

public override void Position()
Expand Down
18 changes: 9 additions & 9 deletions PhotoCollageScreensaver/ImagePositionerFullscreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

namespace PhotoCollageScreensaver;

internal class ImagePositionerFullscreen: ImagePositioner, IImagePositioner
internal sealed class ImagePositionerFullscreen : ImagePositioner
{
public ImagePositionerFullscreen(CollagePresenter presenterToUse, UIElement controlToPosition, ICollageView view) : base(presenterToUse, controlToPosition, view)
public ImagePositionerFullscreen(CollagePresenter presenterToUse, UIElement controlToPosition, ICollageView view)
: base(presenterToUse, controlToPosition, view)
{

}

public override void Position()
Expand All @@ -21,16 +21,16 @@ public override void Position()
}
else
{
this.SetCentredPosition();
this.SetCenteredPosition();
}
}
}

private void SetCentredPosition()
private void SetCenteredPosition()
{
var centredHorizontal = (this.ViewportWidth - this.ControlWidth) / 2;
var centredVertical = (this.ViewportHeight - this.ControlHeight) / 2;
Canvas.SetLeft(this.Control, centredHorizontal);
Canvas.SetTop(this.Control, centredVertical);
var centeredHorizontal = (this.ViewportWidth - this.ControlWidth) / 2;
var centeredVertical = (this.ViewportHeight - this.ControlHeight) / 2;
Canvas.SetLeft(this.Control, centeredHorizontal);
Canvas.SetTop(this.Control, centeredVertical);
}
}
2 changes: 0 additions & 2 deletions PhotoCollageScreensaver/ImageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public BitmapSource GetImage()
: rawImage;

this.DpiScale = sourceImage.DpiX / 96;

this.MaximumSizeDiu = this.Configuration.MaximumSize / this.DpiScale; // default

return sourceImage;
}

Expand Down
7 changes: 4 additions & 3 deletions PhotoCollageScreensaver/ImageProcessorCollage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

namespace PhotoCollageScreensaver;

internal class ImageProcessorCollage: ImageProcessor, IImageProcessor
internal sealed class ImageProcessorCollage : ImageProcessor
{
public ImageProcessorCollage(string imagePathToUse, CollageSettings configurationToUse) : base(imagePathToUse, configurationToUse)
public ImageProcessorCollage(string imagePathToUse, CollageSettings configurationToUse)
: base(imagePathToUse, configurationToUse)
{
}

public override ImageSource GetScaledImage(ICollageView view, BitmapSource sourceImage=null)
public override ImageSource GetScaledImage(ICollageView view, BitmapSource sourceImage = null)
{
if (sourceImage == null)
{
Expand Down
18 changes: 8 additions & 10 deletions PhotoCollageScreensaver/ImageProcessorFullscreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,24 @@

namespace PhotoCollageScreensaver;

internal class ImageProcessorFullscreen: ImageProcessor, IImageProcessor
internal sealed class ImageProcessorFullscreen : ImageProcessor
{
public bool ImageIsRotatedPlusMinusNinetyDegrees { get; private set; }

private int rotationAngle;

public ImageProcessorFullscreen(string imagePathToUse, CollageSettings configurationToUse) : base(imagePathToUse, configurationToUse)
public ImageProcessorFullscreen(string imagePathToUse, CollageSettings configurationToUse)
: base(imagePathToUse, configurationToUse)
{
}

public bool ImageIsRotatedPlusMinusNinetyDegrees { get; private set; }

public new BitmapSource GetImage()
{
var sourceImage = base.GetImage();

if (this.Configuration.RotateBasedOnEXIF)
{
using (var image = Image.FromFile(this.ImagePath))
{
this.GetExifRotationData(image);
}
using var image = Image.FromFile(this.ImagePath);
this.GetExifRotationData(image);
}

return sourceImage;
Expand Down Expand Up @@ -94,7 +92,7 @@ private TransformedBitmap GetFullScreenScaledImage(BitmapSource original, IColla
{
var scaledHeight = view.WindowActualHeight / original.Height;
var scaledWidth = view.WindowActualWidth / original.Width;
if (this.Configuration.PhotoFullScreenMode == PhotoCollage.Common.Enums.FullScreenMode.Centred)
if (this.Configuration.PhotoFullScreenMode == PhotoCollage.Common.Enums.FullScreenMode.Centered)
{
scaledHeight = view.WindowActualHeight / original.Height;
scaledWidth = view.WindowActualWidth / original.Width;
Expand Down
7 changes: 5 additions & 2 deletions PhotoCollageScreensaver/UserControls/CollageImage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public partial class CollageImage : UserControl, IDisposable
{
private readonly string filePath;
private readonly CollagePresenter presenter;
public bool IsPortrait { get; private set; }
private readonly ICollageView view;

public CollageImage(string path, CollagePresenter presenterToUse, ICollageView view)
Expand All @@ -24,6 +23,8 @@ public CollageImage(string path, CollagePresenter presenterToUse, ICollageView v
this.Uid = Guid.NewGuid().ToString();
}

public bool IsPortrait { get; private set; }

public void FadeOutImage(Action<CollageImage> onCompletedAction)
{
try
Expand Down Expand Up @@ -112,7 +113,9 @@ private void RotateImageFrame()

private void LoadImage()
{
IImageProcessor processor = this.presenter.Configuration.IsFullScreen ? new ImageProcessorFullscreen(this.filePath, this.presenter.Configuration) : new ImageProcessorCollage(this.filePath, this.presenter.Configuration);
IImageProcessor processor = this.presenter.Configuration.IsFullScreen
? new ImageProcessorFullscreen(this.filePath, this.presenter.Configuration)
: new ImageProcessorCollage(this.filePath, this.presenter.Configuration);
this.MainImage.Source = processor.GetScaledImage(this.view);


Expand Down
Loading

0 comments on commit b775987

Please sign in to comment.