-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1958 from IbraheemOsama/InfiniteCanvas
Infinite canvas
- Loading branch information
Showing
38 changed files
with
2,604 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InfiniteCanvas/InfiniteCanvas.bind
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d"> | ||
|
||
<Grid> | ||
<controls:InfiniteCanvas Name="canvas" IsToolbarVisible="@[IsToolbarVisible:Bool:True]"/> | ||
</Grid> | ||
</Page> |
Binary file added
BIN
+4.02 KB
Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InfiniteCanvas/InfiniteCanvas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions
8
Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InfiniteCanvas/InfiniteCanvasPage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Page x:Class="Microsoft.Toolkit.Uwp.SampleApp.SamplePages.InfiniteCanvasPage" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="using:Microsoft.Toolkit.Uwp.SampleApp.SamplePages" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" /> |
97 changes: 97 additions & 0 deletions
97
Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InfiniteCanvas/InfiniteCanvasPage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// ****************************************************************** | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// This code is licensed under the MIT License (MIT). | ||
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH | ||
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE. | ||
// ****************************************************************** | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Windows.Storage; | ||
using Windows.UI.Popups; | ||
using Microsoft.Toolkit.Uwp.Helpers; | ||
using Microsoft.Toolkit.Uwp.UI.Controls; | ||
using Microsoft.Toolkit.Uwp.UI.Extensions; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Navigation; | ||
|
||
namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages | ||
{ | ||
/// <summary> | ||
/// InfinteCanvas sample page. | ||
/// </summary> | ||
public sealed partial class InfiniteCanvasPage : Page, IXamlRenderListener | ||
{ | ||
private InfiniteCanvas _infiniteCanvas; | ||
|
||
public InfiniteCanvasPage() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
public void OnXamlRendered(FrameworkElement control) | ||
{ | ||
_infiniteCanvas = control.FindChildByName("canvas") as InfiniteCanvas; | ||
} | ||
|
||
protected override void OnNavigatedTo(NavigationEventArgs e) | ||
{ | ||
base.OnNavigatedTo(e); | ||
|
||
Shell.Current.RegisterNewCommand("Export & Save", async (sender, args) => | ||
{ | ||
if (_infiniteCanvas != null) | ||
{ | ||
var savePicker = new Windows.Storage.Pickers.FileSavePicker | ||
{ | ||
SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary | ||
}; | ||
savePicker.FileTypeChoices.Add("application/json", new List<string> { ".json" }); | ||
savePicker.SuggestedFileName = "Infinite Canvas Export"; | ||
|
||
StorageFile file = await savePicker.PickSaveFileAsync(); | ||
if (file != null) | ||
{ | ||
var json = _infiniteCanvas.ExportAsJson(); | ||
CachedFileManager.DeferUpdates(file); | ||
await FileIO.WriteTextAsync(file, json); | ||
} | ||
} | ||
}); | ||
|
||
Shell.Current.RegisterNewCommand("Import and Load", async (sender, args) => | ||
{ | ||
if (_infiniteCanvas != null) | ||
{ | ||
var picker = new Windows.Storage.Pickers.FileOpenPicker | ||
{ | ||
ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail, | ||
SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary | ||
}; | ||
picker.FileTypeFilter.Add(".json"); | ||
var file = await picker.PickSingleFileAsync(); | ||
|
||
if (file != null) | ||
{ | ||
try | ||
{ | ||
var json = await FileIO.ReadTextAsync(file); | ||
_infiniteCanvas.ImportFromJson(json); | ||
} | ||
catch | ||
{ | ||
var dialog = new MessageDialog("Invalid File"); | ||
await dialog.ShowAsync(); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
Microsoft.Toolkit.Uwp.UI.Controls/InfiniteCanvas/Commands/IInfiniteCanvasCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// ****************************************************************** | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// This code is licensed under the MIT License (MIT). | ||
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH | ||
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE. | ||
// ****************************************************************** | ||
|
||
namespace Microsoft.Toolkit.Uwp.UI.Controls | ||
{ | ||
internal interface IInfiniteCanvasCommand | ||
{ | ||
void Execute(); | ||
|
||
void Undo(); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
Microsoft.Toolkit.Uwp.UI.Controls/InfiniteCanvas/Commands/InfiniteCanvasClearAllCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// ****************************************************************** | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// This code is licensed under the MIT License (MIT). | ||
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH | ||
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE. | ||
// ****************************************************************** | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.Toolkit.Uwp.UI.Controls | ||
{ | ||
internal class InfiniteCanvasClearAllCommand : IInfiniteCanvasCommand | ||
{ | ||
private readonly List<IDrawable> _drawableList; | ||
private IDrawable[] _storeList; | ||
|
||
public InfiniteCanvasClearAllCommand(List<IDrawable> drawableList) | ||
{ | ||
_drawableList = drawableList; | ||
} | ||
|
||
public void Execute() | ||
{ | ||
_storeList = new IDrawable[_drawableList.Count]; | ||
for (int i = 0; i < _drawableList.Count; i++) | ||
{ | ||
_storeList[i] = _drawableList[i]; | ||
} | ||
|
||
_drawableList.Clear(); | ||
} | ||
|
||
public void Undo() | ||
{ | ||
foreach (var drawable in _storeList) | ||
{ | ||
_drawableList.Add(drawable); | ||
} | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
Microsoft.Toolkit.Uwp.UI.Controls/InfiniteCanvas/Commands/InfiniteCanvasCreateInkCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// ****************************************************************** | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// This code is licensed under the MIT License (MIT). | ||
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH | ||
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE. | ||
// ****************************************************************** | ||
|
||
using System.Collections.Generic; | ||
using Windows.UI.Input.Inking; | ||
|
||
namespace Microsoft.Toolkit.Uwp.UI.Controls | ||
{ | ||
internal class InfiniteCanvasCreateInkCommand : IInfiniteCanvasCommand | ||
{ | ||
private readonly List<IDrawable> _drawableList; | ||
private readonly InkDrawable _drawable; | ||
|
||
public InfiniteCanvasCreateInkCommand(List<IDrawable> drawableList, IReadOnlyList<InkStroke> strokes) | ||
{ | ||
_drawable = new InkDrawable(strokes); | ||
_drawableList = drawableList; | ||
} | ||
|
||
public void Execute() | ||
{ | ||
_drawableList.Add(_drawable); | ||
} | ||
|
||
public void Undo() | ||
{ | ||
_drawableList.Remove(_drawable); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...oft.Toolkit.Uwp.UI.Controls/InfiniteCanvas/Commands/InfiniteCanvasCreateTextBoxCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// ****************************************************************** | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// This code is licensed under the MIT License (MIT). | ||
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH | ||
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE. | ||
// ****************************************************************** | ||
|
||
using System.Collections.Generic; | ||
using Windows.UI; | ||
|
||
namespace Microsoft.Toolkit.Uwp.UI.Controls | ||
{ | ||
internal class InfiniteCanvasCreateTextBoxCommand : IInfiniteCanvasCommand | ||
{ | ||
private readonly List<IDrawable> _drawableList; | ||
private readonly TextDrawable _drawable; | ||
|
||
public InfiniteCanvasCreateTextBoxCommand(List<IDrawable> drawableList, double x, double y, double width, double height, int textFontSize, string text, Color color, bool isBold, bool isItalic) | ||
{ | ||
_drawable = new TextDrawable( | ||
x, | ||
y, | ||
width, | ||
height, | ||
textFontSize, | ||
text, | ||
color, | ||
isBold, | ||
isItalic); | ||
_drawableList = drawableList; | ||
} | ||
|
||
public void Execute() | ||
{ | ||
_drawableList.Add(_drawable); | ||
} | ||
|
||
public void Undo() | ||
{ | ||
_drawableList.Remove(_drawable); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
Microsoft.Toolkit.Uwp.UI.Controls/InfiniteCanvas/Commands/InfiniteCanvasEraseInkCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// ****************************************************************** | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// This code is licensed under the MIT License (MIT). | ||
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH | ||
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE. | ||
// ****************************************************************** | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.Toolkit.Uwp.UI.Controls | ||
{ | ||
internal class InfiniteCanvasEraseInkCommand : IInfiniteCanvasCommand | ||
{ | ||
private readonly List<IDrawable> _drawableList; | ||
private readonly IDrawable _drawable; | ||
|
||
public InfiniteCanvasEraseInkCommand(List<IDrawable> drawableList, IDrawable drawable) | ||
{ | ||
_drawable = drawable; | ||
_drawableList = drawableList; | ||
} | ||
|
||
public void Execute() | ||
{ | ||
_drawableList.Remove(_drawable); | ||
} | ||
|
||
public void Undo() | ||
{ | ||
_drawableList.Add(_drawable); | ||
} | ||
} | ||
} |
Oops, something went wrong.