Procházet zdrojové kódy

Made reference layer on top when transforming

CPKreuz před 2 roky
rodič
revize
05a07a9a52

+ 40 - 0
src/PixiEditor/Helpers/Converters/BoolToValueConverter.cs

@@ -0,0 +1,40 @@
+using System.Globalization;
+
+namespace PixiEditor.Helpers.Converters;
+
+internal class BoolToValueConverter : MarkupConverter
+{
+    public object FalseValue { get; set; }
+    
+    public object TrueValue { get; set; }
+    
+    public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+    {
+        if (value is bool boolean && boolean)
+        {
+            return TrueValue;
+        }
+
+        return FalseValue;
+    }
+
+    public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+    {
+        if (value == FalseValue)
+        {
+            return false;
+        }
+
+        if (value == TrueValue)
+        {
+            return true;
+        }
+
+        if (targetType == typeof(bool?))
+        {
+            return null;
+        }
+
+        throw new ArgumentException("value was neither FalseValue nor TrueValue and targetType was not a nullable bool");
+    }
+}

+ 3 - 0
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/TransformReferenceLayerExecutor.cs

@@ -17,6 +17,7 @@ internal class TransformReferenceLayerExecutor : UpdateableChangeExecutor
 
         ShapeCorners corners = document.ReferenceLayerViewModel.ReferenceShapeBindable;
         document.TransformViewModel.ShowTransform(DocumentTransformMode.Scale_Rotate_Shear_NoPerspective, true, corners, true);
+        document.ReferenceLayerViewModel.IsTransforming = true;
         internals!.ActionAccumulator.AddActions(new TransformReferenceLayer_Action(corners));
         return ExecutionState.Success;
     }
@@ -36,6 +37,7 @@ internal class TransformReferenceLayerExecutor : UpdateableChangeExecutor
     {
         internals!.ActionAccumulator.AddFinishedActions(new EndTransformReferenceLayer_Action());
         document!.TransformViewModel.HideTransform();
+        document.ReferenceLayerViewModel.IsTransforming = false;
         onEnded!.Invoke(this);
     }
 
@@ -43,5 +45,6 @@ internal class TransformReferenceLayerExecutor : UpdateableChangeExecutor
     {
         internals!.ActionAccumulator.AddFinishedActions(new EndTransformReferenceLayer_Action());
         document!.TransformViewModel.HideTransform();
+        document.ReferenceLayerViewModel.IsTransforming = false;
     }
 }

+ 11 - 0
src/PixiEditor/ViewModels/SubViewModels/Document/ReferenceLayerViewModel.cs

@@ -53,6 +53,17 @@ internal class ReferenceLayerViewModel : INotifyPropertyChanged
         }
     }
 
+    private bool isTransforming;
+    public bool IsTransforming
+    {
+        get => isTransforming;
+        set
+        {
+            isTransforming = value;
+            RaisePropertyChanged(nameof(IsTransforming));
+        }
+    }
+
     public ReferenceLayerViewModel(DocumentViewModel doc, DocumentInternalParts internals)
     {
         this.doc = doc;

+ 56 - 52
src/PixiEditor/Views/UserControls/Viewport.xaml

@@ -148,7 +148,10 @@
                     </ImageBrush>
                 </Border.Background>
                 <Grid>
-                    <Canvas Visibility="{Binding Source={vm:ToolVM ColorPickerToolViewModel}, Path=PickFromReferenceLayer, Converter={converters:BoolToVisibilityConverter}}">
+                    <Canvas
+                        Visibility="{Binding Source={vm:ToolVM ColorPickerToolViewModel}, Path=PickFromReferenceLayer, Converter={converters:BoolToVisibilityConverter}}"
+                        ZIndex="{Binding Document.ReferenceLayerViewModel.IsTransforming, Converter={converters:BoolToIntConverter}}"
+                        Opacity="{Binding Document.ReferenceLayerViewModel.IsTransforming, Converter={converters:BoolToValueConverter FalseValue=1.0, TrueValue=0.75}}">
                         <Image
                             Focusable="False"
                             Width="{Binding Document.ReferenceLayerViewModel.ReferenceBitmap.Width}"
@@ -172,57 +175,58 @@
                         Source="{Binding TargetBitmap}"
                         Visibility="{Binding Source={vm:ToolVM ColorPickerToolViewModel}, Path=PickFromCanvas, Converter={converters:BoolToHiddenVisibilityConverter}}"
                         RenderOptions.BitmapScalingMode="{Binding Zoombox.Scale, Converter={converters:ScaleToBitmapScalingModeConverter}}"/>
-                    <symOverlay:SymmetryOverlay
-                        Focusable="False"
-                        IsHitTestVisible="{Binding ZoomMode, Converter={converters:ZoomModeToHitTestVisibleConverter}}"
-                        ZoomboxScale="{Binding Zoombox.Scale}"
-                        HorizontalAxisVisible="{Binding Document.HorizontalSymmetryAxisEnabledBindable}"
-                        VerticalAxisVisible="{Binding Document.VerticalSymmetryAxisEnabledBindable}"
-                        HorizontalAxisY="{Binding Document.HorizontalSymmetryAxisYBindable, Mode=OneWay}"
-                        VerticalAxisX="{Binding Document.VerticalSymmetryAxisXBindable, Mode=OneWay}"
-                        DragCommand="{cmds:Command PixiEditor.Document.DragSymmetry, UseProvided=True}"
-                        DragEndCommand="{cmds:Command PixiEditor.Document.EndDragSymmetry, UseProvided=True}" 
-                        DragStartCommand="{cmds:Command PixiEditor.Document.StartDragSymmetry, UseProvided=True}" />
-                    <overlays:SelectionOverlay
-                        Focusable="False"
-                        ShowFill="{Binding ToolsSubViewModel.ActiveTool, Source={vm:MainVM}, Converter={converters:IsSelectionToolConverter}}"
-                        Path="{Binding Document.SelectionPathBindable}"
-                        ZoomboxScale="{Binding Zoombox.Scale}" />
-                    <brushOverlay:BrushShapeOverlay
-                        Focusable="False"
-                        IsHitTestVisible="False"
-                        Visibility="{Binding Document.TransformViewModel.TransformActive, Converter={converters:InverseBoolToVisibilityConverter}}"
-                        ZoomboxScale="{Binding Zoombox.Scale}"
-                        MouseEventSource="{Binding Zoombox.Tag.BackgroundGrid, Mode=OneTime}"
-                        MouseReference="{Binding Zoombox.Tag.MainImage, Mode=OneTime}"
-                        BrushSize="{Binding ToolsSubViewModel.ActiveBasicToolbar.ToolSize, Source={vm:MainVM}}"
-                        BrushShape="{Binding ToolsSubViewModel.ActiveTool.BrushShape, Source={vm:MainVM}, FallbackValue={x:Static brushOverlay:BrushShape.Hidden}}"
-                        />
-                    <transformOverlay:TransformOverlay
-                        Focusable="False"
-                        Cursor="Arrow"
-                        IsHitTestVisible="{Binding ZoomMode, Converter={converters:ZoomModeToHitTestVisibleConverter}}"
-                        HorizontalAlignment="Stretch"
-                        VerticalAlignment="Stretch"
-                        Visibility="{Binding Document.TransformViewModel.TransformActive, Converter={converters:BoolToVisibilityConverter}}"
-                        ActionCompleted="{Binding Document.TransformViewModel.ActionCompletedCommand}"
-                        Corners="{Binding Document.TransformViewModel.Corners, Mode=TwoWay}"
-                        RequestedCorners="{Binding Document.TransformViewModel.RequestedCorners, Mode=TwoWay}"
-                        CornerFreedom="{Binding Document.TransformViewModel.CornerFreedom}"
-                        SideFreedom="{Binding Document.TransformViewModel.SideFreedom}"
-                        LockRotation="{Binding Document.TransformViewModel.LockRotation}"
-                        CoverWholeScreen="{Binding Document.TransformViewModel.CoverWholeScreen}"
-                        SnapToAngles="{Binding Document.TransformViewModel.SnapToAngles}"
-                        InternalState="{Binding Document.TransformViewModel.InternalState, Mode=TwoWay}"
-                        ZoomboxScale="{Binding Zoombox.Scale}"
-                        ZoomboxAngle="{Binding Zoombox.Angle}"/>
-                    <lineOverlay:LineToolOverlay
-                        Focusable="False"
-                        Visibility="{Binding Document.LineToolOverlayViewModel.IsEnabled, Converter={converters:BoolToVisibilityConverter}}"
-                        ActionCompleted="{Binding Document.LineToolOverlayViewModel.ActionCompletedCommand}"
-                        LineStart="{Binding Document.LineToolOverlayViewModel.LineStart, Mode=TwoWay}"
-                        LineEnd="{Binding Document.LineToolOverlayViewModel.LineEnd, Mode=TwoWay}"
-                        ZoomboxScale="{Binding Zoombox.Scale}"/>
+                    <Grid ZIndex="5">
+                        <symOverlay:SymmetryOverlay
+                            Focusable="False"
+                            IsHitTestVisible="{Binding ZoomMode, Converter={converters:ZoomModeToHitTestVisibleConverter}}"
+                            ZoomboxScale="{Binding Zoombox.Scale}"
+                            HorizontalAxisVisible="{Binding Document.HorizontalSymmetryAxisEnabledBindable}"
+                            VerticalAxisVisible="{Binding Document.VerticalSymmetryAxisEnabledBindable}"
+                            HorizontalAxisY="{Binding Document.HorizontalSymmetryAxisYBindable, Mode=OneWay}"
+                            VerticalAxisX="{Binding Document.VerticalSymmetryAxisXBindable, Mode=OneWay}"
+                            DragCommand="{cmds:Command PixiEditor.Document.DragSymmetry, UseProvided=True}"
+                            DragEndCommand="{cmds:Command PixiEditor.Document.EndDragSymmetry, UseProvided=True}"
+                            DragStartCommand="{cmds:Command PixiEditor.Document.StartDragSymmetry, UseProvided=True}" />
+                        <overlays:SelectionOverlay
+                            Focusable="False"
+                            ShowFill="{Binding ToolsSubViewModel.ActiveTool, Source={vm:MainVM}, Converter={converters:IsSelectionToolConverter}}"
+                            Path="{Binding Document.SelectionPathBindable}"
+                            ZoomboxScale="{Binding Zoombox.Scale}" />
+                        <brushOverlay:BrushShapeOverlay
+                            Focusable="False"
+                            IsHitTestVisible="False"
+                            Visibility="{Binding Document.TransformViewModel.TransformActive, Converter={converters:InverseBoolToVisibilityConverter}}"
+                            ZoomboxScale="{Binding Zoombox.Scale}"
+                            MouseEventSource="{Binding Zoombox.Tag.BackgroundGrid, Mode=OneTime}"
+                            MouseReference="{Binding Zoombox.Tag.MainImage, Mode=OneTime}"
+                            BrushSize="{Binding ToolsSubViewModel.ActiveBasicToolbar.ToolSize, Source={vm:MainVM}}"
+                            BrushShape="{Binding ToolsSubViewModel.ActiveTool.BrushShape, Source={vm:MainVM}, FallbackValue={x:Static brushOverlay:BrushShape.Hidden}}" />
+                        <transformOverlay:TransformOverlay
+                            Focusable="False"
+                            Cursor="Arrow"
+                            IsHitTestVisible="{Binding ZoomMode, Converter={converters:ZoomModeToHitTestVisibleConverter}}"
+                            HorizontalAlignment="Stretch"
+                            VerticalAlignment="Stretch"
+                            Visibility="{Binding Document.TransformViewModel.TransformActive, Converter={converters:BoolToVisibilityConverter}}"
+                            ActionCompleted="{Binding Document.TransformViewModel.ActionCompletedCommand}"
+                            Corners="{Binding Document.TransformViewModel.Corners, Mode=TwoWay}"
+                            RequestedCorners="{Binding Document.TransformViewModel.RequestedCorners, Mode=TwoWay}"
+                            CornerFreedom="{Binding Document.TransformViewModel.CornerFreedom}"
+                            SideFreedom="{Binding Document.TransformViewModel.SideFreedom}"
+                            LockRotation="{Binding Document.TransformViewModel.LockRotation}"
+                            CoverWholeScreen="{Binding Document.TransformViewModel.CoverWholeScreen}"
+                            SnapToAngles="{Binding Document.TransformViewModel.SnapToAngles}"
+                            InternalState="{Binding Document.TransformViewModel.InternalState, Mode=TwoWay}"
+                            ZoomboxScale="{Binding Zoombox.Scale}"
+                            ZoomboxAngle="{Binding Zoombox.Angle}" />
+                        <lineOverlay:LineToolOverlay
+                            Focusable="False"
+                            Visibility="{Binding Document.LineToolOverlayViewModel.IsEnabled, Converter={converters:BoolToVisibilityConverter}}"
+                            ActionCompleted="{Binding Document.LineToolOverlayViewModel.ActionCompletedCommand}"
+                            LineStart="{Binding Document.LineToolOverlayViewModel.LineStart, Mode=TwoWay}"
+                            LineEnd="{Binding Document.LineToolOverlayViewModel.LineEnd, Mode=TwoWay}"
+                            ZoomboxScale="{Binding Zoombox.Scale}" />
+                    </Grid>
                     <Grid IsHitTestVisible="False" 
                         ShowGridLines="True" Width="{Binding Document.Width}" Height="{Binding Document.Height}" Panel.ZIndex="10" 
                         Visibility="{Binding GridLinesVisible, Converter={converters:BoolToVisibilityConverter}, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Viewport}}">