Skip to content

Commit e441c01

Browse files
committed
Added shapes
1 parent fc39a0c commit e441c01

File tree

5 files changed

+149
-51
lines changed

5 files changed

+149
-51
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace OpenBoardAnim.Library.Repositories
9+
{
10+
public class ShapeRepository
11+
{
12+
public List<GraphicEntity> GetAllShapess()
13+
{
14+
List<GraphicEntity> shapes = [];
15+
shapes.Add(new GraphicEntity
16+
{
17+
Name = "Rectangle",
18+
SVGText = " <svg width=\"200\" height=\"100\" xmlns=\"http://www.w3.org/2000/svg\">\r\n <rect width=\"200\" height=\"100\" style=\"stroke:black;stroke-width:3;fill-opacity:0;stroke-opacity:1\"/>\r\n</svg> "
19+
});
20+
shapes.Add(new GraphicEntity
21+
{
22+
Name = "Rectangle-rounded",
23+
SVGText = " <svg width=\"200\" height=\"100\" xmlns=\"http://www.w3.org/2000/svg\">\r\n <rect width=\"200\" height=\"100\" rx=\"20\" ry=\"20\" style=\"stroke:black;stroke-width:3;fill-opacity:0;stroke-opacity:1\"/>\r\n</svg> "
24+
});
25+
shapes.Add(new GraphicEntity
26+
{
27+
Name = "Square",
28+
SVGText = " <svg width=\"200\" height=\"200\" xmlns=\"http://www.w3.org/2000/svg\">\r\n <rect width=\"200\" height=\"200\" style=\"stroke:black;stroke-width:3;fill-opacity:0;stroke-opacity:1\"/>\r\n</svg> "
29+
});
30+
shapes.Add(new GraphicEntity
31+
{
32+
Name = "Square-rounded",
33+
SVGText = " <svg width=\"200\" height=\"200\" xmlns=\"http://www.w3.org/2000/svg\">\r\n <rect width=\"200\" height=\"200\" rx=\"20\" ry=\"20\" style=\"stroke:black;stroke-width:3;fill-opacity:0;stroke-opacity:1\"/>\r\n</svg> "
34+
});
35+
shapes.Add(new GraphicEntity
36+
{
37+
Name = "Circle",
38+
SVGText = " <svg height=\"100\" width=\"100\" xmlns=\"http://www.w3.org/2000/svg\">\r\n <circle r=\"45\" cx=\"50\" cy=\"50\" fill=\"none\" stroke=\"black\" stroke-width=\"3\" opacity=\"1\" />\r\n</svg> "
39+
});
40+
shapes.Add(new GraphicEntity
41+
{
42+
Name = "Ellipse-Vertical",
43+
SVGText = "<svg height=\"500\" width=\"140\" xmlns=\"http://www.w3.org/2000/svg\">\r\n <ellipse rx=\"50\" ry=\"100\" cx=\"80\" cy=\"120\"\r\n style=\"fill:none;stroke:black;stroke-width:3\" />\r\n</svg> "
44+
});
45+
shapes.Add(new GraphicEntity
46+
{
47+
Name = "Line-Horizontal",
48+
SVGText = "<svg height=\"25\" width=\"300\" xmlns=\"http://www.w3.org/2000/svg\">\r\n <line x1=\"0\" y1=\"10\" x2=\"250\" y2=\"10\" style=\"stroke:black;stroke-width:3\" />\r\n</svg>"
49+
});
50+
shapes.Add(new GraphicEntity
51+
{
52+
Name = "Triangle",
53+
SVGText = " <svg height=\"210\" width=\"210\" xmlns=\"http://www.w3.org/2000/svg\">\r\n <polygon points=\"100,0 200,200 0,200\" style=\"fill:none;stroke:black;stroke-width:3\" />\r\n</svg> "
54+
});
55+
shapes.Add(new GraphicEntity
56+
{
57+
Name = "Speech-Bubble",
58+
SVGText = "<svg fill=\"#000000\" width=\"100px\" height=\"100px\" viewBox=\"0 0 32 32\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\r\n <path d=\"M16 4c7.72 0 14 4.486 14 10s-6.28 10-14 10l-0.829 0.003c-0.55 0-0.909-0.015-1.471-0.099l-1.12-0.16-0.719 0.87c-0.331 0.399-2.017 1.785-3.878 2.677 0.378-1.001 0.657-2.094 0.683-3.175l0.010-0.059v-1.395l-1.090-0.556c-3.55-1.816-5.585-4.77-5.585-8.106 0-5.514 6.28-10 14-10zM16 2c-8.838 0-16 5.373-16 12 0 4.127 2.446 7.724 6.675 9.886 0 0.026-0.008 0.044-0.008 0.073 0 1.793-1.005 3.765-1.594 4.779h0.002c-0.046 0.109-0.074 0.229-0.074 0.357 0 0.503 0.405 0.906 0.907 0.906 0.075 0 0.196-0.015 0.239-0.015 0.011 0 0.016 0 0.016 0.003 3.125-0.511 6.561-3.271 7.245-4.104 0.703 0.105 1.177 0.12 1.765 0.12 0.248 0 0.515-0.003 0.829-0.003 8.836 0 16-5.372 16-12 0-6.627-7.164-12-16-12z\"></path>\r\n</svg>"
59+
});
60+
shapes.Add(new GraphicEntity
61+
{
62+
Name = "Thought-Bubble",
63+
SVGText = "<svg width=\"100px\" height=\"100px\" viewBox=\"0 0 128 128\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" aria-hidden=\"true\" role=\"img\" class=\"iconify iconify--noto\" preserveAspectRatio=\"xMidYMid meet\"><path d=\"M120.44 51.23a29.87 29.87 0 0 0 2.96-13.02c0-16.6-13.45-30.05-30.05-30.05c-3.89 0-7.61.75-11.03 2.1C77.95 6.45 72.22 4.1 66 4.1c-7.6 0-14.4 3.4-18.9 8.7c-3.5-1.9-7.5-3-11.7-3c-13.4.1-24.3 10.9-24.3 24.3c0 5 1.5 9.7 4.2 13.6c-5 4-8.5 9.9-9.2 16.8C4.8 77.9 14.7 90 28.3 91.3c3.2.3 6.2 0 9.1-.8c1.1 10.7 10.1 19 21.1 19c7 0 13.2-3.4 17-8.6c3.6 2.8 8.1 4.6 13.1 4.6c11 0 20.1-8.5 20.9-19.2C118 82.4 124 73.8 124 63.8c0-4.59-1.33-8.92-3.56-12.57z\" fill=\"#ffffff\" stroke=\"#000000\" stroke-width=\"6\" stroke-miterlimit=\"10\"></path><path d=\"M24.3 97.3c-4.5-.5-8.5 2.8-9 7.3s2.8 8.5 7.3 8.9c4.5.5 8.5-2.8 9-7.3s-2.8-8.5-7.3-8.9z\" fill=\"#ffffff\" stroke=\"#000000\" stroke-width=\"4.5\" stroke-miterlimit=\"10\"></path><path d=\"M9 114.3c-3-.3-5.7 1.9-6 4.9s1.9 5.6 4.9 5.9s5.7-1.9 6-4.9c.3-2.9-1.9-5.6-4.9-5.9z\" fill=\"#ffffff\" stroke=\"#000000\" stroke-width=\"3\" stroke-miterlimit=\"10\"></path></svg>"
64+
});
65+
return shapes;
66+
}
67+
}
68+
}

OpenBoardAnim/App.xaml.cs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public App()
2020
{
2121
IServiceCollection services = new ServiceCollection();
2222
services.AddSingleton<DataContext>();
23+
services.AddSingleton<ShapeRepository>();
2324
services.AddSingleton<GraphicRepository>();
2425
services.AddSingleton<SceneRepository>();
2526
services.AddSingleton<ProjectRepository>();

OpenBoardAnim/Services/CacheService.cs

+23-13
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,34 @@ public class CacheService
1616
private readonly GraphicRepository _gRepo;
1717
private readonly SceneRepository _sRepo;
1818
private readonly ProjectRepository _pRepo;
19+
private readonly ShapeRepository _shRepo;
1920
private List<GraphicEntity> _graphicEntities;
2021
private List<SceneEntity> _sceneEntities;
2122
public BindingList<RecentProjectModel> RecentProjects { get; set; }
2223
public ProjectDetails CurrentProject { get; set; }
2324
public BindingList<DrawingModel> LoadedGraphics { get; set; }
25+
public BindingList<DrawingModel> AllShapes { get; set; }
2426
public BindingList<SceneModel> LoadedScenes { get; set; }
2527

26-
public CacheService(GraphicRepository gRepo, SceneRepository sRepo, ProjectRepository pRepo)
28+
public CacheService(GraphicRepository gRepo, SceneRepository sRepo, ProjectRepository pRepo, ShapeRepository shRepo)
2729
{
2830
_gRepo = gRepo;
2931
_sRepo = sRepo;
3032
_pRepo = pRepo;
33+
_shRepo = shRepo;
3134
LoadRecentProjects();
3235
LoadGraphics();
3336
LoadScenes();
37+
LoadShapes();
3438
}
39+
40+
private void LoadShapes()
41+
{
42+
List<GraphicEntity> shapeEntities = _shRepo.GetAllShapess();
43+
List<DrawingModel> drawingModels = shapeEntities.Select(GetModelFromGrpahicEntity).ToList();
44+
AllShapes = new BindingList<DrawingModel>(drawingModels);
45+
}
46+
3547
public ProjectDetails LoadProjectFromFile(RecentProjectModel model)
3648
{
3749
string json = File.ReadAllText(model.FilePath);
@@ -85,27 +97,25 @@ private void LoadScenes()
8597
private void LoadGraphics()
8698
{
8799
_graphicEntities = _gRepo.GetAllGraphics();
88-
List<DrawingModel> graphics = _graphicEntities.Select(e =>
89-
new DrawingModel
100+
List<DrawingModel> graphics = _graphicEntities.Select(GetModelFromGrpahicEntity).ToList();
101+
LoadedGraphics = new BindingList<DrawingModel>(graphics);
102+
}
103+
104+
private static DrawingModel GetModelFromGrpahicEntity(GraphicEntity e)
105+
{
106+
return new DrawingModel
90107
{
91108
ID = e.GraphicID,
92109
Name = e.Name,
93110
SVGText = e.SVGText,
94111
ImgDrawingGroup = GeometryHelper.GetPathGeometryFromSVG(e.SVGText)
95-
}).ToList();
96-
LoadedGraphics = new BindingList<DrawingModel>(graphics);
112+
};
97113
}
114+
98115
public List<DrawingModel> GetGraphics(string searchText,int offsetID)
99116
{
100117
_graphicEntities = _gRepo.GetAllGraphics(searchText, offsetID);
101-
List<DrawingModel> graphics = _graphicEntities.Select(e =>
102-
new DrawingModel
103-
{
104-
ID = e.GraphicID,
105-
Name = e.Name,
106-
SVGText = e.SVGText,
107-
ImgDrawingGroup = GeometryHelper.GetPathGeometryFromSVG(e.SVGText)
108-
}).ToList();
118+
List<DrawingModel> graphics = _graphicEntities.Select(GetModelFromGrpahicEntity).ToList();
109119
return graphics;
110120
}
111121
public async Task SaveNewGraphics(string[] paths)

OpenBoardAnim/ViewModels/EditorLibraryViewModel.cs

+16
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@ public EditorLibraryViewModel(IPubSubService pubSub, CacheService cache)
2828
_pubSub = pubSub;
2929
_cache = cache;
3030
Graphics = cache.LoadedGraphics;
31+
Shapes = cache.AllShapes;
3132
foreach (var graphic in Graphics)
3233
{
3334
graphic.AddGraphic = AddGraphicHandler;
3435
}
36+
foreach (var shape in Shapes)
37+
{
38+
shape.AddGraphic = AddGraphicHandler;
39+
}
3540
Scenes = cache.LoadedScenes;
3641
foreach (var scene in Scenes)
3742
{
@@ -176,6 +181,17 @@ public BindingList<DrawingModel> Graphics
176181
OnPropertyChanged();
177182
}
178183
}
184+
private BindingList<DrawingModel> _shapes;
185+
186+
public BindingList<DrawingModel> Shapes
187+
{
188+
get { return _shapes; }
189+
set
190+
{
191+
_shapes = value;
192+
OnPropertyChanged();
193+
}
194+
}
179195
private void AddGraphicHandler(DrawingModel model)
180196
{
181197
_pubSub.Publish(SubTopic.GraphicAdded, model.Clone());

OpenBoardAnim/Views/EditorLibraryView.xaml

+41-38
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,7 @@
1717
</Grid.RowDefinitions>
1818
<hc:TabControl Grid.Row="1" IsAnimationEnabled="True" IsDraggable="True" IsTabFillEnabled="True" TabItemWidth="20">
1919
<hc:TabItem Header="{materialDesign:PackIcon imageFrame}" ToolTip="Scenes" ScrollViewer.VerticalScrollBarVisibility="Visible">
20-
<hc:CoverView Background="DarkGray" ItemWidth="100" ItemHeight="100" ItemContentHeight="20"
21-
ScrollViewer.VerticalScrollBarVisibility="Visible" ItemsSource="{Binding Scenes}">
22-
<hc:CoverView.ItemHeaderTemplate>
23-
<DataTemplate>
24-
<svgc:SvgBitmap UriSource="{Binding ImgPath}"/>
25-
</DataTemplate>
26-
</hc:CoverView.ItemHeaderTemplate>
27-
<hc:CoverView.ItemTemplate>
28-
<DataTemplate>
29-
<WrapPanel Background="Green">
30-
<TextBlock HorizontalAlignment="Stretch" Text="{Binding Name}"/>
31-
<Button Margin="2" Style="{StaticResource ButtonPrimary}" Command="{Binding ReplaceSceneCommand}">Replace Scene</Button>
32-
</WrapPanel>
33-
</DataTemplate>
34-
</hc:CoverView.ItemTemplate>
35-
</hc:CoverView>
20+
<TextBlock Text="Under&#x0a;construction" TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30"/>
3621
</hc:TabItem>
3722
<hc:TabItem IsSelected="True" Header="{materialDesign:PackIcon AccountGroup}" ToolTip="Graphics">
3823
<Grid>
@@ -56,33 +41,51 @@
5641
<RowDefinition Height="*"/>
5742
<RowDefinition Height="auto"/>
5843
</Grid.RowDefinitions>
59-
<ListBox ScrollViewer.VerticalScrollBarVisibility="Visible" ItemsSource="{Binding Graphics}" SelectedItem="{Binding SelectedScene}">
60-
<ListBox.ItemsPanel>
61-
<ItemsPanelTemplate>
62-
<WrapPanel/>
63-
</ItemsPanelTemplate>
64-
</ListBox.ItemsPanel>
65-
<ListBox.ItemTemplate>
66-
<DataTemplate>
67-
<StackPanel ToolTip="{Binding Name}" Margin="5" Orientation="Vertical">
68-
<Image Height="115" Width="115">
69-
<Image.Source>
70-
<DrawingImage Drawing="{Binding ImgDrawingGroup}"/>
71-
</Image.Source>
72-
</Image>
73-
<Button Margin="0 10 0 0" Style="{StaticResource ButtonPrimary}" Command="{Binding AddGraphicCommand}">Add</Button>
74-
</StackPanel>
75-
</DataTemplate>
76-
</ListBox.ItemTemplate>
77-
</ListBox>
44+
<ListBox ScrollViewer.VerticalScrollBarVisibility="Visible" ItemsSource="{Binding Graphics}" SelectedItem="{Binding SelectedGraphic}">
45+
<ListBox.ItemsPanel>
46+
<ItemsPanelTemplate>
47+
<WrapPanel/>
48+
</ItemsPanelTemplate>
49+
</ListBox.ItemsPanel>
50+
<ListBox.ItemTemplate>
51+
<DataTemplate>
52+
<StackPanel ToolTip="{Binding Name}" Margin="5" Orientation="Vertical">
53+
<Image Height="115" Width="115">
54+
<Image.Source>
55+
<DrawingImage Drawing="{Binding ImgDrawingGroup}"/>
56+
</Image.Source>
57+
</Image>
58+
<Button Margin="0 10 0 0" Style="{StaticResource ButtonPrimary}" Command="{Binding AddGraphicCommand}">Add</Button>
59+
</StackPanel>
60+
</DataTemplate>
61+
</ListBox.ItemTemplate>
62+
</ListBox>
7863
<Button Grid.Row="1" Command="{Binding LoadMoreGraphicsCommand}">Load More..</Button>
7964
</Grid>
8065
</ScrollViewer>
8166

8267
</Grid>
8368
</hc:TabItem>
8469
<hc:TabItem Header="{materialDesign:PackIcon shape}" ToolTip="Shapes">
85-
<WrapPanel Background="#FF3F4EE8"/>
70+
<ListBox ScrollViewer.VerticalScrollBarVisibility="Visible" ItemsSource="{Binding Shapes}" SelectedItem="{Binding SelectedShape}">
71+
<ListBox.ItemsPanel>
72+
<ItemsPanelTemplate>
73+
<WrapPanel/>
74+
</ItemsPanelTemplate>
75+
</ListBox.ItemsPanel>
76+
<ListBox.ItemTemplate>
77+
<DataTemplate>
78+
<StackPanel ToolTip="{Binding Name}" Margin="5" Orientation="Vertical">
79+
<Image Height="115" Width="115">
80+
<Image.Source>
81+
<DrawingImage Drawing="{Binding ImgDrawingGroup}"/>
82+
</Image.Source>
83+
</Image>
84+
<Button Margin="0 10 0 0" Style="{StaticResource ButtonPrimary}" Command="{Binding AddGraphicCommand}">Add</Button>
85+
</StackPanel>
86+
</DataTemplate>
87+
</ListBox.ItemTemplate>
88+
</ListBox>
8689
</hc:TabItem>
8790
<hc:TabItem Header="{materialDesign:PackIcon FormatLetterCase}" ToolTip="Text">
8891
<Grid>
@@ -123,10 +126,10 @@
123126
</Grid>
124127
</hc:TabItem>
125128
<hc:TabItem Header="{materialDesign:PackIcon music}" ToolTip="Audio">
126-
<WrapPanel Background="#FFB23FE8"/>
129+
<TextBlock Text="Under&#x0a;construction" TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30"/>
127130
</hc:TabItem>
128131
<hc:TabItem Header="{materialDesign:PackIcon CloudUpload}">
129-
<WrapPanel Background="#FF3FE8E8"/>
132+
<TextBlock Text="Under&#x0a;construction" TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30"/>
130133
</hc:TabItem>
131134
</hc:TabControl>
132135
</Grid>

0 commit comments

Comments
 (0)