Browse Source

Create mask button

Equbuxu 2 years ago
parent
commit
cc45fdc472

BIN
src/PixiEditor/Images/Create-mask.png


+ 87 - 0
src/PixiEditor/Images/Create-mask.svg

@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   width="24"
+   height="24"
+   viewBox="0 0 6.3499999 6.3500002"
+   version="1.1"
+   id="svg5"
+   inkscape:version="1.2.1 (9c6d41e410, 2022-07-14)"
+   sodipodi:docname="Create-mask.svg"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:svg="http://www.w3.org/2000/svg">
+  <sodipodi:namedview
+     id="namedview7"
+     pagecolor="#000000"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageshadow="2"
+     inkscape:pageopacity="0"
+     inkscape:pagecheckerboard="false"
+     inkscape:document-units="px"
+     showgrid="true"
+     units="px"
+     width="24px"
+     inkscape:snap-bbox="true"
+     inkscape:zoom="11.313709"
+     inkscape:cx="12.948893"
+     inkscape:cy="15.954097"
+     inkscape:window-width="1920"
+     inkscape:window-height="1009"
+     inkscape:window-x="1272"
+     inkscape:window-y="-8"
+     inkscape:window-maximized="1"
+     inkscape:current-layer="layer1"
+     inkscape:showpageshadow="2"
+     inkscape:deskcolor="#000000">
+    <inkscape:grid
+       type="xygrid"
+       id="grid1308"
+       spacingx="0.13229167"
+       spacingy="0.13229167"
+       empspacing="4"
+       visible="false"
+       enabled="true" />
+  </sodipodi:namedview>
+  <defs
+     id="defs2" />
+  <g
+     inkscape:label="Слой 1"
+     inkscape:groupmode="layer"
+     id="layer1">
+    <circle
+       style="display:none;opacity:1;fill:#ffffff;stroke:none;stroke-width:0.264583"
+       id="path3065"
+       cx="3.1750002"
+       cy="2.3812501"
+       r="2.1166668" />
+    <rect
+       style="display:none;opacity:1;fill:#ffffff;stroke:none;stroke-width:0.264583"
+       id="rect3169"
+       width="4.2333336"
+       height="0.92604166"
+       x="1.0583332"
+       y="2.3812501" />
+    <path
+       id="path3295"
+       style="display:none;opacity:1;fill:#333333;stroke:none;stroke-width:0.288637"
+       d="m 3.1750001,0.79375002 a 1.5875,1.5875 0 0 1 1.5875,1.58750008 V 2.9104167 H 1.5875 V 2.3812501 A 1.5875,1.5875 0 0 1 3.1750001,0.79375002 Z" />
+    <rect
+       style="fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.554366;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:0.554366, 1.10873"
+       id="rect359"
+       width="5.8208332"
+       height="5.8208332"
+       x="0.26458335"
+       y="0.26458335"
+       ry="1.3229166" />
+    <circle
+       style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.551216;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:0.551216, 1.10242"
+       id="path1170"
+       cx="3.175"
+       cy="3.175"
+       r="1.6536459" />
+  </g>
+</svg>

+ 2 - 0
src/PixiEditor/PixiEditor.csproj

@@ -343,6 +343,8 @@
 		<Resource Include="Images\SocialMedia\Avatars\Equbuxu.png" />
 		<None Remove="Images\SocialMedia\Avatars\CPK.png" />
 		<Resource Include="Images\SocialMedia\Avatars\CPK.png" />
+		<None Remove="Images\Create-mask.png" />
+		<Resource Include="Images\Create-mask.png" />
 	</ItemGroup>
 	<ItemGroup>
 		<None Include="..\LICENSE">

+ 1 - 1
src/PixiEditor/ViewModels/SubViewModels/Main/LayersViewModel.cs

@@ -201,7 +201,7 @@ internal class LayersViewModel : SubViewModel<ViewModelMain>
     public bool ActiveMemberHasMask() => Owner.DocumentManagerSubViewModel.ActiveDocument?.SelectedStructureMember?.HasMaskBindable ?? false;
 
     [Evaluator.CanExecute("PixiEditor.Layer.ActiveLayerHasNoMask")]
-    public bool ActiveLayerHasNoMask() => !ActiveMemberHasMask();
+    public bool ActiveLayerHasNoMask() => !Owner.DocumentManagerSubViewModel.ActiveDocument?.SelectedStructureMember?.HasMaskBindable ?? false;
 
     [Command.Basic("PixiEditor.Layer.CreateMask", "Create mask", "Create mask", CanExecute = "PixiEditor.Layer.ActiveLayerHasNoMask")]
     public void CreateMask()

+ 4 - 2
src/PixiEditor/ViewModels/ViewModelMain.cs

@@ -247,7 +247,9 @@ internal class ViewModelMain : ViewModelBase
 
         if (result != ConfirmationType.Canceled)
         {
-            DocumentManagerSubViewModel.Documents.Remove(document);
+            if (!DocumentManagerSubViewModel.Documents.Remove(document))
+                throw new InvalidOperationException("Trying to close a document that's not in the documents collection. Likely, the document wasn't added there after creation by mistake.");
+            
             if (DocumentManagerSubViewModel.ActiveDocument == document)
             {
                 if (DocumentManagerSubViewModel.Documents.Count > 0)
@@ -258,7 +260,7 @@ internal class ViewModelMain : ViewModelBase
 
             // TODO: this thing should actually dispose the document to free up ram
             // We need the UI to be able to handle disposed documents
-            // Like, the viewports should show nothing, the commands shouldn't work, etc. At least nothing should crash or behave unexpectidly
+            // Like, the viewports should show nothing, the commands shouldn't work, etc. At least nothing should crash or behave unexpectedly
             // Mostly we only care about this because avalondock doesn't remove the UI elements of closed viewports (at least not right away)
             // So they remain alive and keep "showing" the now disposed DocumentViewModel
             // And since they reference the DocumentViewModel it doesn't get collected by GC

+ 10 - 0
src/PixiEditor/Views/UserControls/Layers/LayersManager.xaml

@@ -62,6 +62,16 @@
                         <ImageBrush ImageSource="/Images/Merge-downwards.png"/>
                     </Button.Background>
                 </Button>
+                <Button 
+                    Height="24" Width="24" ToolTip="Create mask" Cursor="Hand"
+                    DockPanel.Dock="Right"
+                    HorizontalAlignment="Stretch" Margin="5,0,0,0"
+                    Style="{StaticResource ToolButtonStyle}"
+                    Command="{commands:Command PixiEditor.Layer.CreateMask}">
+                    <Button.Background>
+                        <ImageBrush ImageSource="/Images/Create-mask.png"/>
+                    </Button.Background>
+                </Button>
                 <Button 
                     Height="24" Width="24" ToolTip="Lock transparency" Cursor="Hand"
                     DockPanel.Dock="Right"