/// <summary> /// Load a storage container for the currently selected storage file /// </summary> [NotNull] private async Task <IStorageContainer> LoadTileStore([NotNull] string path) { var directoryName = Path.GetDirectoryName(path); if (string.IsNullOrWhiteSpace(directoryName)) { throw new Exception("Path directory is invalid"); } var folder = await StorageFolder.GetFolderFromPathAsync(directoryName).NotNull(); if (folder == null) { throw new Exception("Path to Slick file is not available"); } var fileName = Path.GetFileName(path); if (string.IsNullOrWhiteSpace(fileName)) { throw new Exception("Path file name is invalid"); } var file = await folder.CreateFileAsync(fileName, CreationCollisionOption.OpenIfExists).NotNull(); if (file == null || !file.IsAvailable) { throw new Exception("Failed to load Slick file"); } if (_tileStore != null) { _tileStore.Dispose(); _tileStore = null; } var accessStream = await file.OpenAsync(FileAccessMode.ReadWrite).NotNull(); var wrapper = new StreamWrapper(accessStream); var store = LoadStorageFile(wrapper); if (_tileCanvas != null) { pinsView?.SetConnections(_tileCanvas, store); ImageImportFloater?.SetCanvasTarget(_tileCanvas); TextFloater?.SetCanvasTarget(_tileCanvas); } return(store); }
/// <summary> /// Start the canvas up with the default document /// </summary> private void Page_Loaded(object sender, RoutedEventArgs e) { // Set up pen/mouse/touch input var ip = baseInkCanvas?.InkPresenter; if (ip == null) { throw new Exception("Base ink presenter is missing"); } if (paletteView == null) { throw new Exception("Palette object is missing"); } if (pinsView == null) { throw new Exception("Palette object is missing"); } ip.ActivateCustomDrying(); if (ip.UnprocessedInput == null || ip.InputProcessingConfiguration == null || ip.InputConfiguration == null) { throw new Exception("Ink Presenter is malformed"); } // These to get all the drawing and input directly ip.UnprocessedInput.PointerMoved += UnprocessedInput_PointerMoved; ip.UnprocessedInput.PointerPressed += UnprocessedInput_PointerPressed; ip.UnprocessedInput.PointerReleased += UnprocessedInput_PointerReleased; ip.InputProcessingConfiguration.Mode = InkInputProcessingMode.None; ip.InputProcessingConfiguration.RightDragAction = InkInputRightDragAction.AllowProcessing; ip.InputConfiguration.IsEraserInputEnabled = true; ip.InputConfiguration.IsPrimaryBarrelButtonInputEnabled = true; ip.InputDeviceTypes = CoreInputDeviceTypes.Mouse /*| CoreInputDeviceTypes.Touch*/ | CoreInputDeviceTypes.Pen; ip.IsInputEnabled = true; paletteView.Opacity = 0.0; // 1.0 is 100%, 0.0 is 0% pinsView.Opacity = 0.0; // 1.0 is 100%, 0.0 is 0% var defaultFile = Path.Combine(ApplicationData.Current?.RoamingFolder?.Path, "default.slick"); if (defaultFile == null) { throw new Exception("Failed to pick an initial page path"); } _tileStore = Sync.Run(() => LoadTileStore(defaultFile)); if (_tileStore == null) { throw new Exception("Failed to load initial page"); } if (renderLayer == null) { throw new Exception("Invalid page structure (1)"); } _tileCanvas = new TileCanvas(renderLayer, _tileStore); pinsView?.SetConnections(_tileCanvas, _tileStore); ImageImportFloater?.SetCanvasTarget(_tileCanvas); TextFloater?.SetCanvasTarget(_tileCanvas); _wetInk = new WetInkCanvas(wetInkCanvas ?? throw new Exception("Invalid page structure (2)")); _tileCanvas?.Invalidate(); SetTitleBarString(Path.GetFileNameWithoutExtension(defaultFile)); }