Skip to content

Commit

Permalink
Merge pull request #7 from emiliano84/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Emiliano84 authored May 5, 2020
2 parents d79797b + c7123e2 commit 57c80ea
Show file tree
Hide file tree
Showing 31 changed files with 1,216 additions and 808 deletions.
13 changes: 5 additions & 8 deletions Yugen.Mosaic.Uwp/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ namespace Yugen.Mosaic.Uwp
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
sealed partial class App : Application
public sealed partial class App : Application
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
InitializeComponent();
Suspending += OnSuspending;

AppCenter.Start("7df4b441-69ae-49c5-b27d-5a532f33b554",
typeof(Analytics), typeof(Crashes));
Expand Down Expand Up @@ -76,10 +76,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
/// </summary>
/// <param name="sender">The Frame which failed navigation</param>
/// <param name="e">Details about the navigation failure</param>
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
}
private void OnNavigationFailed(object sender, NavigationFailedEventArgs e) => throw new Exception("Failed to load Page " + e.SourcePageType.FullName);

/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
Expand All @@ -90,7 +87,7 @@ void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
/// <param name="e">Details about the suspend request.</param>
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
SuspendingDeferral deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
deferral.Complete();
}
Expand Down
27 changes: 12 additions & 15 deletions Yugen.Mosaic.Uwp/Controls/AlignmentGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,44 +60,44 @@ private static void OnPropertyChanged(DependencyObject dependencyObject, Depende
/// </summary>
public Brush LineBrush
{
get { return (Brush)GetValue(LineBrushProperty); }
set { SetValue(LineBrushProperty, value); }
get => (Brush)GetValue(LineBrushProperty);
set => SetValue(LineBrushProperty, value);
}

/// <summary>
/// Gets or sets the step to use horizontally.
/// </summary>
public double HorizontalStep
{
get { return (double)GetValue(HorizontalStepProperty); }
set { SetValue(HorizontalStepProperty, value); }
get => (double)GetValue(HorizontalStepProperty);
set => SetValue(HorizontalStepProperty, value);
}

/// <summary>
/// Gets or sets the step to use horizontally.
/// </summary>
public double VerticalStep
{
get { return (double)GetValue(VerticalStepProperty); }
set { SetValue(VerticalStepProperty, value); }
get => (double)GetValue(VerticalStepProperty);
set => SetValue(VerticalStepProperty, value);
}

/// <summary>
/// Get or set the container width.
/// </summary>
public double ContainerWidth
{
get { return (double)GetValue(ContainerWidthProperty); }
set { SetValue(ContainerWidthProperty, value); }
get => (double)GetValue(ContainerWidthProperty);
set => SetValue(ContainerWidthProperty, value);
}

/// <summary>
/// Get or set the container height.
/// </summary>
public double ContainerHeight
{
get { return (double)GetValue(ContainerHeightProperty); }
set { SetValue(ContainerHeightProperty, value); }
get => (double)GetValue(ContainerHeightProperty);
set => SetValue(ContainerHeightProperty, value);
}

/// <summary>
Expand All @@ -121,7 +121,7 @@ private void Rebuild()
containerCanvas.Children.Clear();
var horizontalStep = HorizontalStep;
var verticalStep = VerticalStep;
var brush = LineBrush ?? (Brush)Application.Current.Resources["ApplicationForegroundThemeBrush"];
Brush brush = LineBrush ?? (Brush)Application.Current.Resources["ApplicationForegroundThemeBrush"];

if (horizontalStep > 0)
{
Expand Down Expand Up @@ -156,9 +156,6 @@ private void Rebuild()
}
}

private void AlignmentGrid_SizeChanged(object sender, SizeChangedEventArgs e)
{
Rebuild();
}
private void AlignmentGrid_SizeChanged(object sender, SizeChangedEventArgs e) => Rebuild();
}
}
14 changes: 4 additions & 10 deletions Yugen.Mosaic.Uwp/Extensions/SettingsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,12 @@ public static void Write<T>(string key, T value)
LocalSettings.Values[key] = valueString;
}

public static async Task<T> ReadAsync<T>(string key)
{
return LocalSettings.Values.TryGetValue(key, out object value)
? await JsonProvider.ToObjectAsync<T>((string) value)
public static async Task<T> ReadAsync<T>(string key) => LocalSettings.Values.TryGetValue(key, out var value)
? await JsonProvider.ToObjectAsync<T>((string)value)
: default;
}

public static T Read<T>(string key)
{
return LocalSettings.Values.TryGetValue(key, out object value)
? JsonConvert.DeserializeObject<T>((string) value)
public static T Read<T>(string key) => LocalSettings.Values.TryGetValue(key, out var value)
? JsonConvert.DeserializeObject<T>((string)value)
: default;
}
}
}
53 changes: 53 additions & 0 deletions Yugen.Mosaic.Uwp/Helpers/ColorHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using System;
using System.Threading.Tasks;

namespace Yugen.Mosaic.Uwp.Helpers
{
public static class ColorHelper
{
public static Rgba32 GetAverageColor(Image<Rgba32> source, int x, int y, Size tileSize) => GetAverageColor(source, x * tileSize.Width, y * tileSize.Height,
tileSize.Width, tileSize.Height, x * tileSize.Width + tileSize.Width, y * tileSize.Height + tileSize.Height);

public static Rgba32 GetAverageColor(Image<Rgba32> source) => GetAverageColor(source, 0, 0, source.Width, source.Height, source.Width, source.Height);

private static Rgba32 GetAverageColor(Image<Rgba32> source, int startX, int startY, int width, int height, int endX, int endY)
{
long aR = 0;
long aG = 0;
long aB = 0;

Parallel.For(startY, endY, h =>
{
Span<Rgba32> rowSpan = source.GetPixelRowSpan(h);

for (var w = startX; w < endX; w++)
{
var pixel = new Rgba32();
rowSpan[w].ToRgba32(ref pixel);

aR += pixel.R;
aG += pixel.G;
aB += pixel.B;
}
});

aR /= width * height;
aG /= width * height;
aB /= width * height;

return new Rgba32(Convert.ToByte(aR), Convert.ToByte(aG), Convert.ToByte(aB));
}


public static int GetDifference(Rgba32 source, Rgba32 target)
{
var dR = Math.Abs(source.R - target.R);
var dG = Math.Abs(source.G - target.G);
var dB = Math.Abs(source.B - target.B);
var diff = Math.Max(dR, dG);
return Math.Max(diff, dB);
}
}
}
88 changes: 25 additions & 63 deletions Yugen.Mosaic.Uwp/Helpers/OnboardingHelper.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,9 @@
using Windows.UI.Xaml;
using Yugen.Mosaic.Uwp.Extensions;
using Yugen.Mosaic.Uwp.Models;

namespace Yugen.Mosaic.Uwp.Helpers
{
public enum OnboardingStage
{
MasterImage,
AddTiles,
TileProperties,
MosaicType,
OutputProperties,
Generate,
Save
}

public class OnboardingElement
{
public string Title { get; set; }

public string Subtitle { get; set; }

public FrameworkElement Target { get; set; }

public OnboardingStage Stage { get; set; }

public OnboardingElement(string title, string subtitle, FrameworkElement target, OnboardingStage stage)
{
Title = title;
Subtitle = subtitle;
Target = target;
Stage = stage;
}
}

public static class OnboardingHelper
{
Expand All @@ -46,49 +18,39 @@ public static bool IsDisabled
private static int _step;
private static OnboardingElement[] _onboardingElements;

public static void Init(FrameworkElement[] frameworkElements)
{
var masterImageDescription = "Choose what image you want to use as the Matrix of the mosaic. " +
"Yugen Mosaic will create a mosaic as close as possible to the main image.";

var addTilesDescription = "Add a list of Tile Images, Yugen Mosaic will use as tiles to build your mosaic";

var tilesPropertiesDescription = "After you created the Tile Images List, it is necessary to set all the parameters of the mosaic." +
"Here you can set the size of every single tile";

var mosaicTypeDescription = "Choose the tpe of mosaic.";

var outputDescription = "Choose the size of the mosaic.";

var generateDescription = "Create the mosaic.";

var saveDescription = "The last step is to save the mosaic.";

_onboardingElements = new OnboardingElement[]
public static void Init(FrameworkElement[] frameworkElements) => _onboardingElements = new OnboardingElement[]
{
new OnboardingElement("Select the Main Image", masterImageDescription,
frameworkElements[0], OnboardingStage.MasterImage),
new OnboardingElement("Create a Tile Images List", addTilesDescription,
frameworkElements[1], OnboardingStage.AddTiles),
new OnboardingElement("TileProperties", tilesPropertiesDescription,
frameworkElements[2], OnboardingStage.TileProperties),
new OnboardingElement("MosaicType", mosaicTypeDescription,
frameworkElements[3], OnboardingStage.MosaicType),
new OnboardingElement("Set the parameters of the Mosaic", outputDescription,
frameworkElements[4], OnboardingStage.OutputProperties),
new OnboardingElement("Create the Mosaic", generateDescription,
frameworkElements[5], OnboardingStage.Generate),
new OnboardingElement("Save the Mosaic", saveDescription,
frameworkElements[6], OnboardingStage.Save),
new OnboardingElement(
frameworkElements[0],
OnboardingStage.MasterImage),
new OnboardingElement(
frameworkElements[1],
OnboardingStage.AddTiles),
new OnboardingElement(
frameworkElements[2],
OnboardingStage.TileProperties),
new OnboardingElement(
frameworkElements[3],
OnboardingStage.MosaicType),
new OnboardingElement(
frameworkElements[4],
OnboardingStage.OutputProperties),
new OnboardingElement(
frameworkElements[5],
OnboardingStage.Generate),
new OnboardingElement(
frameworkElements[6],
OnboardingStage.Save),
};
}

public static OnboardingElement ShowTeachingTip()
{
OnboardingElement onboardingElement = null;

if (_step < 0 || IsDisabled)
{
return onboardingElement;
}

if (_step < _onboardingElements.Length)
{
Expand Down
2 changes: 1 addition & 1 deletion Yugen.Mosaic.Uwp/Helpers/RatioHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class RatioHelper
public static Tuple<int, int> Convert(int width, int height, int newHeight, int newWidth)
{
//calculate the ratio
double ratio = (double)width / (double)height;
var ratio = (double)width / (double)height;

//set height of image to boxHeight and check if resulting width is less than boxWidth,
//else set width of image to boxWidth and calculate new height
Expand Down
11 changes: 11 additions & 0 deletions Yugen.Mosaic.Uwp/Helpers/ResourceHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Windows.ApplicationModel.Resources;

namespace Yugen.Mosaic.Uwp.Helpers
{
public static class ResourceHelper
{
private static readonly ResourceLoader _resourceLoader = _resourceLoader ?? new ResourceLoader();

public static string GetText(string key) => _resourceLoader.GetString(key);
}
}
18 changes: 18 additions & 0 deletions Yugen.Mosaic.Uwp/Interfaces/IMosaicService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using System.IO;
using Windows.Storage.Streams;

namespace Yugen.Mosaic.Uwp.Interfaces
{
public interface IMosaicService
{
Image<Rgba32> AddMasterImage(Stream stream);
Image<Rgba32> AddTileImage(string name, Stream stream);
Image<Rgba32> GenerateMosaic(Size outputSize, Size tileSize, int mosaicType);
Image<Rgba32> GetResizedImage(Image<Rgba32> image, int size);
InMemoryRandomAccessStream GetStream(Image<Rgba32> image);
void RemoveTileImage(string name);
void Reset();
}
}
7 changes: 7 additions & 0 deletions Yugen.Mosaic.Uwp/Interfaces/ISearchAndReplaceService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Yugen.Mosaic.Uwp.Interfaces
{
public interface ISearchAndReplaceService
{
void SearchAndReplace();
}
}
4 changes: 2 additions & 2 deletions Yugen.Mosaic.Uwp/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public sealed partial class MainPage : Page

public MainPage()
{
this.InitializeComponent();
InitializeComponent();
ExtendToTitleBar();
}

private void ExtendToTitleBar()
{
var coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
CoreApplicationViewTitleBar coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
coreTitleBar.ExtendViewIntoTitleBar = true;
}

Expand Down
Loading

0 comments on commit 57c80ea

Please sign in to comment.