Browse Source

Add coordinates display on the bottom right

Equbuxu 3 years ago
parent
commit
11f49348bf

+ 6 - 4
src/PixiEditor/Models/DocumentModels/ActionAccumulator.cs

@@ -92,19 +92,20 @@ internal class ActionAccumulator
             // Somehow this all works
             // Somehow this all works
             // Also, there is a bug report for this on github https://github.com/dotnet/wpf/issues/5816
             // Also, there is a bug report for this on github https://github.com/dotnet/wpf/issues/5816
 
 
+            // update the contents of the bitmaps
             var affectedChunks = new AffectedChunkGatherer(helpers.Tracker, changes);
             var affectedChunks = new AffectedChunkGatherer(helpers.Tracker, changes);
             bool refreshDelayed = toExecute.Any(static action => action is ChangeBoundary_Action or Redo_Action or Undo_Action);
             bool refreshDelayed = toExecute.Any(static action => action is ChangeBoundary_Action or Redo_Action or Undo_Action);
             var renderResult = await renderer.UpdateGatheredChunks(affectedChunks, refreshDelayed);
             var renderResult = await renderer.UpdateGatheredChunks(affectedChunks, refreshDelayed);
             
             
-            // lock bitmaps that need to be updated
+            // lock bitmaps
             foreach (var (_, bitmap) in document.Bitmaps)
             foreach (var (_, bitmap) in document.Bitmaps)
             {
             {
                 bitmap.Lock();
                 bitmap.Lock();
             }
             }
-
-            // update bitmaps
             if (refreshDelayed)
             if (refreshDelayed)
                 LockPreviewBitmaps(document.StructureRoot);
                 LockPreviewBitmaps(document.StructureRoot);
+
+            // add dirty rectangles
             AddDirtyRects(renderResult);
             AddDirtyRects(renderResult);
 
 
             // unlock bitmaps
             // unlock bitmaps
@@ -118,7 +119,8 @@ internal class ActionAccumulator
             // force refresh viewports for better responsiveness
             // force refresh viewports for better responsiveness
             foreach (var (_, value) in helpers.State.Viewports)
             foreach (var (_, value) in helpers.State.Viewports)
             {
             {
-                value.InvalidateVisual();
+                if (!value.Delayed)
+                    value.InvalidateVisual();
             }
             }
         }
         }
 
 

+ 13 - 1
src/PixiEditor/ViewModels/SubViewModels/Document/DocumentViewModel.cs

@@ -90,12 +90,20 @@ internal class DocumentViewModel : NotifyableObject
         }
         }
     }
     }
 
 
+    private string coordinatesString;
+    public string CoordinatesString
+    {
+        get => coordinatesString;
+        set => SetProperty(ref coordinatesString, value);
+    }
+
     public SKPath SelectionPathBindable => selectionPath;
     public SKPath SelectionPathBindable => selectionPath;
     public DocumentTransformViewModel TransformViewModel { get; }
     public DocumentTransformViewModel TransformViewModel { get; }
 
 
     public ExecutionTrigger<VecI> CenterViewportTrigger { get; } = new ExecutionTrigger<VecI>();
     public ExecutionTrigger<VecI> CenterViewportTrigger { get; } = new ExecutionTrigger<VecI>();
     public ExecutionTrigger<double> ZoomViewportTrigger { get; } = new ExecutionTrigger<double>();
     public ExecutionTrigger<double> ZoomViewportTrigger { get; } = new ExecutionTrigger<double>();
 
 
+
     private DocumentHelpers Helpers { get; }
     private DocumentHelpers Helpers { get; }
 
 
     private int verticalSymmetryAxisX;
     private int verticalSymmetryAxisX;
@@ -300,7 +308,11 @@ internal class DocumentViewModel : NotifyableObject
     public void OnKeyUp(Key args) => Helpers.ChangeController.OnKeyUp(args);
     public void OnKeyUp(Key args) => Helpers.ChangeController.OnKeyUp(args);
 
 
     public void OnCanvasLeftMouseButtonDown(VecD pos) => Helpers.ChangeController.OnLeftMouseButtonDown(pos);
     public void OnCanvasLeftMouseButtonDown(VecD pos) => Helpers.ChangeController.OnLeftMouseButtonDown(pos);
-    public void OnCanvasMouseMove(VecD newPos) => Helpers.ChangeController.OnMouseMove(newPos);
+    public void OnCanvasMouseMove(VecD newPos)
+    {
+        CoordinatesString = $"X: {(int)newPos.X} Y: {(int)newPos.Y}";
+        Helpers.ChangeController.OnMouseMove(newPos);
+    }
     public void OnCanvasLeftMouseButtonUp() => Helpers.ChangeController.OnLeftMouseButtonUp();
     public void OnCanvasLeftMouseButtonUp() => Helpers.ChangeController.OnLeftMouseButtonUp();
 
 
     public void OnOpacitySliderDragStarted() => Helpers.ChangeController.OnOpacitySliderDragStarted();
     public void OnOpacitySliderDragStarted() => Helpers.ChangeController.OnOpacitySliderDragStarted();

+ 1 - 15
src/PixiEditor/Views/MainWindow.xaml

@@ -762,23 +762,9 @@
                         HorizontalAlignment="Right"
                         HorizontalAlignment="Right"
                         VerticalAlignment="Center">
                         VerticalAlignment="Center">
                         <TextBlock
                         <TextBlock
-                            Text="X:"
+                            Text="{Binding ElementName=mainWindow, Path=DataContext.DocumentManagerSubViewModel.ActiveDocument.CoordinatesString}"
                             Foreground="White"
                             Foreground="White"
                             FontSize="16" />
                             FontSize="16" />
-                        <!--<TextBlock
-                            Margin="4,0,10,0"
-                            Text="{Binding BitmapManager.ActiveDocument.MouseXOnCanvas, Converter={converters:DoubleToIntConverter}}"
-                            Foreground="White"
-                            FontSize="16" />-->
-                        <TextBlock
-                            Text="Y:"
-                            Foreground="White"
-                            FontSize="16" />
-                        <!--<TextBlock
-                            Margin="4,0,10,0"
-                            Text="{Binding BitmapManager.ActiveDocument.MouseYOnCanvas, Converter={converters:DoubleToIntConverter}}"
-                            Foreground="White"
-                            FontSize="16" />-->
                     </StackPanel>
                     </StackPanel>
                 </DockPanel>
                 </DockPanel>
                 <StackPanel
                 <StackPanel

+ 1 - 1
src/PixiEditor/Views/UserControls/Viewport.xaml

@@ -103,7 +103,7 @@
                         </Grid.Resources>
                         </Grid.Resources>
                         <Rectangle Focusable="False" Visibility="{Binding Zoombox.Scale, Converter={StaticResource ThresholdVisibilityConverter}}">
                         <Rectangle Focusable="False" Visibility="{Binding Zoombox.Scale, Converter={StaticResource ThresholdVisibilityConverter}}">
                             <Rectangle.Fill>
                             <Rectangle.Fill>
-                                <VisualBrush Viewport="{Binding Document.Height, Converter={converters:IntToViewportRectConverter}, ConverterParameter=vertical}" ViewboxUnits="Absolute" TileMode="Tile" >
+                                <VisualBrush Viewport="{Binding Document.Width, Converter={converters:IntToViewportRectConverter}, ConverterParameter=vertical}" ViewboxUnits="Absolute" TileMode="Tile" >
                                     <VisualBrush.Visual>
                                     <VisualBrush.Visual>
                                         <Line X1="0" Y1="0" X2="0" Y2="1" Stroke="#88888888" StrokeThickness="{Binding Zoombox.Scale, Converter={converters:ReciprocalConverter}}"/>
                                         <Line X1="0" Y1="0" X2="0" Y2="1" Stroke="#88888888" StrokeThickness="{Binding Zoombox.Scale, Converter={converters:ReciprocalConverter}}"/>
                                     </VisualBrush.Visual>
                                     </VisualBrush.Visual>