Skip to content

Commit

Permalink
Working on 10.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry Nixon committed Nov 2, 2016
1 parent 00e9ee1 commit 815d3ac
Show file tree
Hide file tree
Showing 26 changed files with 552 additions and 148 deletions.
Binary file added .vs/Template10.sqlite
Binary file not shown.
114 changes: 114 additions & 0 deletions Template10 (Library)/Utils/InkUtils.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Windows.Graphics.Display;
using Windows.Graphics.Imaging;
using Windows.Storage;
using Windows.UI.Input.Inking;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Imaging;

namespace Template10.Utils
{
Expand Down Expand Up @@ -59,5 +63,115 @@ public static async Task<string> Recognize(this InkCanvas inkCanvas)
return string.Empty;
}
}

public class InkBitmapRenderer
{
public async Task<SoftwareBitmap> RenderAsync(IEnumerable<InkStroke> inkStrokes, double width, double height)
{
var dpi = DisplayInformation.GetForCurrentView().LogicalDpi;
try
{
var renderTarget = new CanvasRenderTarget(_canvasDevice, (float)width, (float)height, dpi); using (renderTarget)
{
using (var drawingSession = renderTarget.CreateDrawingSession())
{
drawingSession.DrawInk(inkStrokes);
}

return await SoftwareBitmap.CreateCopyFromSurfaceAsync(renderTarget);
}
}
catch (Exception e) when (_canvasDevice.IsDeviceLost(e.HResult))
{
_canvasDevice.RaiseDeviceLost();
}

return null;
}

private void HandleDeviceLost(CanvasDevice sender, object args)
{
if (sender == _canvasDevice)
{
RecreateDevice();
}
}

private void RecreateDevice()
{
_canvasDevice.DeviceLost -= HandleDeviceLost;

_canvasDevice = CanvasDevice.GetSharedDevice(_canvasDevice.ForceSoftwareRenderer); _canvasDevice.DeviceLost += HandleDeviceLost;
}
}

private async Task RenderBitmap(this InkCanvas inkCanvas)
{
var strokes = inkCanvas.InkPresenter.StrokeContainer.GetStrokes();

var renderer = new RenderTargetBitmap();

var renderedImage = await _inkBitmapRenderer.RenderAsync(
strokes,
inkCanvas.ActualWidth,
inkCanvas.ActualHeight);

var convertedImage = SoftwareBitmap
.Convert(renderedImage,
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Premultiplied);

if (renderedImage != null)
{
// Convert to a format appropriate for SoftwareBitmapSource.
var convertedImage = SoftwareBitmap.Convert(
renderedImage,
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Premultiplied
);
await InkImageSource.SetBitmapAsync(convertedImage);

var renderTargetBitmap = new RenderTargetBitmap();
var currentDpi = DisplayInformation.GetForCurrentView().LogicalDpi;

// Prepare for RenderTargetBitmap by hiding the InkCanvas and displaying the // rasterized strokes instead.
ImageInkCanvas.Visibility = Visibility.Collapsed;
InkImage.Visibility = Visibility.Visible;

await renderTargetBitmap.RenderAsync(InkingRoot);
var pixelData = await renderTargetBitmap.GetPixelsAsync();

// Restore the original layout now that we have created the RenderTargetBitmap image.
ImageInkCanvas.Visibility = Visibility.Visible;
InkImage.Visibility = Visibility.Collapsed;

// Create destination file for the new image
var destFolder = await SettingsService.GetStorageFolderForPhotoFile(ViewModel.CurrentPhoto.PhotoId);
var file = await destFolder.CreateFileAsync($"{Guid.NewGuid().ToString("D")}.png",
CreationCollisionOption.GenerateUniqueName);

using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);
encoder.SetPixelData(
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Ignore,
(uint)renderTargetBitmap.PixelWidth,
(uint)renderTargetBitmap.PixelHeight,
currentDpi,
currentDpi,
pixelData.ToArray()
);

await encoder.FlushAsync();
}

// Update the SightFile in the database
await ViewModel.UpdatePhotoImageUriAsync(file.GetUri());

// Erase all strokes.
ImageInkCanvas.InkPresenter.StrokeContainer.Clear();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface IService
{
}

public interface IInfrastructure<T> where T: IService
public interface IServiceHost<T> where T: IService
{
T Instance { get; set; }
}
Expand All @@ -21,12 +21,12 @@ namespace Template10
{
public static class Extensions
{
public static T GetInfrastructure<T>(this IInfrastructure<T> accessor) where T : IService
public static T GetService<T>(this IServiceHost<T> accessor) where T : IService
{
return accessor.Instance;
}

public static void SetInfrastructure<T>(this IInfrastructure<T> accessor, T value) where T : IService
public static void SetService<T>(this IServiceHost<T> accessor, T value) where T : IService
{
accessor.Instance = value;
}
Expand Down
2 changes: 1 addition & 1 deletion Template10.2.BCL/Template10.2.BCL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<Compile Include="IInfrastructure.cs" />
<Compile Include="IServiceConsumer.cs" />
<Compile Include="ObservableCollectionEx.cs" />
<Compile Include="ObservableDictionary.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
2 changes: 1 addition & 1 deletion Template10.2.BCL/project.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0"
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2"
},
"frameworks": {
"uap10.0": {}
Expand Down
2 changes: 1 addition & 1 deletion Template10.2.Core.Services/project.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0",
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2",
"Newtonsoft.Json": "9.0.1"
},
"frameworks": {
Expand Down
4 changes: 2 additions & 2 deletions Template10.2.Core/App/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

namespace Template10.App
{
public abstract partial class Bootstrapper : Application, IInfrastructure<ISuspensionService>
public abstract partial class Bootstrapper : Application, IServiceHost<ISuspensionService>
{
ISuspensionService IInfrastructure<ISuspensionService>.Instance { get; set; } = SuspensionService.Instance;
ISuspensionService IServiceHost<ISuspensionService>.Instance { get; set; } = SuspensionService.Instance;

public Bootstrapper()
{
Expand Down
2 changes: 1 addition & 1 deletion Template10.2.Core/App/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static partial class Settings
public static bool AutoExtendExecution { get; set; } = true;
public static bool AutoSuspend { get; set; } = true;
public static bool LogginEnabled { get; set; } = false;
public static TimeSpan RestoreExpires { get; set; } = TimeSpan.FromDays(3);
public static TimeSpan SuspensionStateExpires { get; set; } = TimeSpan.FromDays(3);

private static object _PageKeys;
public static Dictionary<T, Type> PageKeys<T>()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ public interface IFrameFacade
void ClearBackStack();

object Content { get; }

string GetNavigationState();

void SetNavigationState(string state);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ namespace Template10.Services.Navigation

internal interface IFrameFacadeInternal : IFrameFacade
{
string GetNavigationState();

void SetNavigationState(string state);

bool Navigate(Type page);

bool Navigate(Type page, object parameter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ namespace Template10.Services.Navigation
{
public interface INavigationService
{
event EventHandler Suspending;
event EventHandler Suspended;
event EventHandler Resuming;
event EventHandler Resumed;
event EventHandler<Type> Navigating;
event EventHandler<bool> Navigated;

string Id { get; }

Task SuspendAsync();
Expand All @@ -32,7 +39,7 @@ public interface INavigationService

object CurrentViewModel { get; }

CurrentNavigationMode CurrentNavigationMode { get; }
NavigationModes CurrentNavigationMode { get; }
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

namespace Template10.Services.Navigation
{
public interface INavigationStateService: IService
public interface INavigationStateService : IService
{
Task<string> LoadFromCacheAsync(string frameId);
Task<bool> SaveToCacheAsync(string frameId, string state);
Task<bool> LoadNavigationState(string id, IFrameFacade frame);

Task<bool> SaveNavigationState(string id, IFrameFacade frame);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System.Threading.Tasks;
using Windows.Foundation.Collections;

namespace Template10.Services.Navigation
{

public interface ISuspensionAware : INavigationAware
{
Task OnResumingAsync(ISuspensionState state);
Task OnSuspendingAsync(ISuspensionState state);
Task OnResumingAsync(IPropertySet state);
Task OnSuspendingAsync(IPropertySet state);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
using Windows.Storage;
using Template10.BCL;
using System.Threading.Tasks;
using Windows.UI.Xaml.Controls;

namespace Template10.Services.Navigation
{
public interface ISuspensionService: IService
{
Task<ISuspensionState> GetStateAsync(string frameId, Type type, int backStackDepth);
Task CallOnResumingAsync(String id, Page page, int backStackDepth);
Task CallOnSuspendingAsync(String id, Page page, int backStackDepth);
}
}

This file was deleted.

Loading

0 comments on commit 815d3ac

Please sign in to comment.