Explorar o código

Zoom tool WIP, fixed editable text box editing: shortcuts, and selection

flabbet %!s(int64=5) %!d(string=hai) anos
pai
achega
9215a92699

BIN=BIN
PixiEditor/Images/ZoomImage.png


+ 2 - 2
PixiEditor/Models/Controllers/BitmapManager.cs

@@ -160,13 +160,13 @@ namespace PixiEditor.Models.Controllers
 
         private void MouseController_StartedRecordingChanges(object sender, EventArgs e)
         {
-            SelectedTool.OnMouseDown();
+            SelectedTool.OnMouseDown(new MouseEventArgs(Mouse.PrimaryDevice, (int)DateTimeOffset.UtcNow.ToUnixTimeSeconds()));
             PreviewLayer = null;
         }
 
         private void MouseController_StoppedRecordingChanges(object sender, EventArgs e)
         {
-            SelectedTool.OnMouseUp();
+            SelectedTool.OnMouseUp(new MouseEventArgs(Mouse.PrimaryDevice, (int)DateTimeOffset.UtcNow.ToUnixTimeSeconds()));
             if (IsOperationTool(SelectedTool) && ((BitmapOperationTool) SelectedTool).RequiresPreviewLayer)
                 BitmapOperations.StopAction();
         }

+ 2 - 2
PixiEditor/Models/Tools/Tool.cs

@@ -28,11 +28,11 @@ namespace PixiEditor.Models.Tools
 
         private bool _isActive;
 
-        public virtual void OnMouseDown()
+        public virtual void OnMouseDown(MouseEventArgs e)
         {
         }
 
-        public virtual void OnMouseUp()
+        public virtual void OnMouseUp(MouseEventArgs e)
         {
         }
 

+ 2 - 1
PixiEditor/Models/Tools/ToolType.cs

@@ -12,6 +12,7 @@
         Rectangle,
         Eraser,
         Brightness,
-        ColorPicker
+        ColorPicker,
+        Zoom
     }
 }

+ 1 - 2
PixiEditor/Models/Tools/Tools/BrightnessTool.cs

@@ -28,9 +28,8 @@ namespace PixiEditor.Models.Tools.Tools
             Toolbar = new BrightnessToolToolbar(CorrectionFactor);
         }
 
-        public override void OnMouseDown()
+        public override void OnMouseDown(MouseEventArgs e)
         {
-            base.OnMouseDown();
             _pixelsVisited.Clear();
         }
 

+ 1 - 1
PixiEditor/Models/Tools/Tools/MoveTool.cs

@@ -62,7 +62,7 @@ namespace PixiEditor.Models.Tools.Tools
             }
         }
 
-        public override void OnMouseUp() //This adds undo if there is no selection, reason why this isn't in AfterUndoAdded,
+        public override void OnMouseUp(MouseEventArgs e) //This adds undo if there is no selection, reason why this isn't in AfterUndoAdded,
         {   //is because it doesn't fire if no pixel changes were made.
             if (_currentSelection != null && _currentSelection.Length == 0)
             {

+ 3 - 2
PixiEditor/Models/Tools/Tools/SelectTool.cs

@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Windows.Controls;
+using System.Windows.Input;
 using PixiEditor.Models.Controllers;
 using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.Enums;
@@ -24,7 +25,7 @@ namespace PixiEditor.Models.Tools.Tools
             Toolbar = new SelectToolToolbar();
         }
 
-        public override void OnMouseDown()
+        public override void OnMouseDown(MouseEventArgs e)
         {
             Enum.TryParse((Toolbar.GetSetting("Mode").Value as ComboBoxItem)?.Content as string, out SelectionType);
 
@@ -34,7 +35,7 @@ namespace PixiEditor.Models.Tools.Tools
                 _oldSelection = ViewModelMain.Current.ActiveSelection;
         }
 
-        public override void OnMouseUp()
+        public override void OnMouseUp(MouseEventArgs e)
         {
             UndoManager.AddUndoChange(new Change("ActiveSelection", _oldSelection,
                 ViewModelMain.Current.ActiveSelection, "Select pixels"));

+ 51 - 0
PixiEditor/Models/Tools/Tools/ZoomTool.cs

@@ -0,0 +1,51 @@
+using PixiEditor.Models.Position;
+using PixiEditor.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Windows.Input;
+
+namespace PixiEditor.Models.Tools.Tools
+{
+    public class ZoomTool : ReadonlyTool
+    {
+        public override ToolType ToolType => ToolType.Zoom;
+        private double _startingX;
+
+        public ZoomTool()
+        {
+            HideHighlight = true;
+        }
+
+        public override void OnMouseDown(MouseEventArgs e)
+        {
+            _startingX = MousePositionConverter.GetCursorPosition().X;
+            ViewModelMain.Current.ZoomPercentage = 100; //This resest the value, so callback in MainDrawingPanel can fire again later
+        }
+
+        public override void OnMouseUp(MouseEventArgs e)
+        {
+            if (e.LeftButton == MouseButtonState.Released && e.RightButton == MouseButtonState.Released && 
+                _startingX == MousePositionConverter.GetCursorPosition().X)
+            {
+                double zoomModifier;
+                if (Keyboard.Modifiers.HasFlag(ModifierKeys.Alt))
+                {
+                    zoomModifier =  85;
+                }
+                else
+                {
+                    zoomModifier = 115;
+                }
+                ViewModelMain.Current.ZoomPercentage = zoomModifier;
+            }
+        }
+
+        public override void Use(Coordinates[] pixels)
+        {
+            double xPos = MousePositionConverter.GetCursorPosition().X;
+
+            ViewModelMain.Current.ZoomPercentage = 100 + ((xPos - _startingX) / 5.0);
+        }
+    }
+}

+ 2 - 0
PixiEditor/PixiEditor.csproj

@@ -31,6 +31,7 @@
     <None Remove="Images\MoveImage.png" />
     <None Remove="Images\PixiEditorLogo.png" />
     <None Remove="Images\SelectImage.png" />
+    <None Remove="Images\ZoomImage.png" />
     <None Include="..\icon.ico">
       <Pack>True</Pack>
       <PackagePath></PackagePath>
@@ -69,6 +70,7 @@
     <Resource Include="Images\RectangleImage.png" />
     <Resource Include="Images\SelectImage.png" />
     <Resource Include="Images\transparentbg.png" />
+    <Resource Include="Images\ZoomImage.png" />
   </ItemGroup>
   <ItemGroup>
     <None Include="..\LICENSE">

+ 16 - 2
PixiEditor/ViewModels/ViewModelMain.cs

@@ -164,6 +164,19 @@ namespace PixiEditor.ViewModels
             }
         }
 
+        private double _zoomPercentage = 100;
+
+        public double ZoomPercentage
+        {
+            get { return _zoomPercentage; }
+            set 
+            {
+                _zoomPercentage = value;
+                RaisePropertyChanged(nameof(ZoomPercentage));
+            }
+        }
+
+
         public BitmapManager BitmapManager { get; set; }
         public PixelChangesController ChangesController { get; set; }
 
@@ -226,7 +239,8 @@ namespace PixiEditor.ViewModels
             ToolSet = new ObservableCollection<Tool>
             {
                 new MoveTool(), new PenTool(), new SelectTool(), new FloodFill(), new LineTool(),
-                new CircleTool(), new RectangleTool(), new EraserTool(), new ColorPickerTool(), new BrightnessTool()
+                new CircleTool(), new RectangleTool(), new EraserTool(), new ColorPickerTool(), new BrightnessTool(), 
+                new ZoomTool()
             };
             ShortcutController = new ShortcutController
             {
@@ -497,8 +511,8 @@ namespace PixiEditor.ViewModels
             {
                 _restoreToolOnKeyUp = false;
                 SetActiveTool(_lastActionTool);
+                ShortcutController.BlockShortcutExecution = false;
             }
-            ShortcutController.BlockShortcutExecution = false;
         }
 
         public void KeyDown(object parameter)

+ 2 - 0
PixiEditor/Views/EditableTextBlock.xaml.cs

@@ -66,6 +66,8 @@ namespace PixiEditor.Views
             ShortcutController.BlockShortcutExecution = true;
             TextBlockVisibility = Visibility.Hidden;
             IsEditing = true;
+            textBox.Focus();
+            textBox.SelectAll();
         }
 
         private void DisableEditing()

+ 29 - 1
PixiEditor/Views/MainDrawingPanel.xaml.cs

@@ -1,6 +1,8 @@
-using System.Windows;
+using System;
+using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
+using Xceed.Wpf.Toolkit.Core.Input;
 using Xceed.Wpf.Toolkit.Zoombox;
 
 namespace PixiEditor.Views
@@ -37,11 +39,37 @@ namespace PixiEditor.Views
         public static readonly DependencyProperty ItemProperty =
             DependencyProperty.Register("Item", typeof(object), typeof(MainDrawingPanel), new PropertyMetadata(0));
 
+
+
+        public double ZoomPercentage
+        {
+            get { return (double)GetValue(ZoomPrecentageProperty); }
+            set { SetValue(ZoomPrecentageProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for ZoomPrecentage.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty ZoomPrecentageProperty =
+            DependencyProperty.Register("ZoomPercentage", typeof(double), typeof(MainDrawingPanel), new PropertyMetadata(0.0, ZoomPercentegeChanged));
+
+        private static void ZoomPercentegeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+        {
+            MainDrawingPanel panel = (MainDrawingPanel)d;
+            panel.Zoombox.ZoomTo(panel.ClickScale * ((double)e.NewValue / 100.0));
+        }
+
+        public double ClickScale;
+
         public MainDrawingPanel()
         {
             InitializeComponent();
+            Zoombox.ZoomToSelectionModifiers = new KeyModifierCollection() { KeyModifier.RightAlt };
+            Zoombox.PreviewMouseDown += Zoombox_MouseDown;
         }
 
+        private void Zoombox_MouseDown(object sender, MouseButtonEventArgs e)
+        {
+            ClickScale = Zoombox.Scale;
+        }
 
         public bool Center
         {

+ 1 - 1
PixiEditor/Views/MainWindow.xaml

@@ -160,7 +160,7 @@
         </StackPanel>
         <Grid Grid.Column="1" Grid.Row="2" Background="#303030" Margin="0,7,5,0">
             <Grid>
-                <vws:MainDrawingPanel Center="{Binding RecenterZoombox, Mode=TwoWay}" x:Name="DrawingPanel"
+                <vws:MainDrawingPanel ZoomPercentage="{Binding ZoomPercentage, Mode=TwoWay}" Center="{Binding RecenterZoombox, Mode=TwoWay}" x:Name="DrawingPanel"
                                       CenterOnStart="True" Cursor="{Binding ToolCursor}">
                     <i:Interaction.Triggers>
                         <i:EventTrigger EventName="MouseMove">