Pārlūkot izejas kodu

Delete some code

Equbuxu 4 gadi atpakaļ
vecāks
revīzija
ba8d0385de

+ 9 - 58
PixiEditor/Models/DataHolders/Document/Document.cs

@@ -1,25 +1,19 @@
-using System;
+using PixiEditor.Helpers;
+using PixiEditor.Models.Controllers;
+using PixiEditor.Models.Enums;
+using PixiEditor.Models.Layers;
+using PixiEditor.Models.Position;
+using PixiEditor.Models.Undo;
+using PixiEditor.ViewModels;
+using System;
 using System.Buffers;
-using System.Collections;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Diagnostics;
 using System.IO;
 using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using PixiEditor.Helpers;
-using PixiEditor.Models.Controllers;
-using PixiEditor.Models.Enums;
-using PixiEditor.Models.ImageManipulation;
-using PixiEditor.Models.IO;
-using PixiEditor.Models.Layers;
-using PixiEditor.Models.Position;
-using PixiEditor.Models.Undo;
-using PixiEditor.ViewModels;
 
 namespace PixiEditor.Models.DataHolders
 {
@@ -103,51 +97,8 @@ namespace PixiEditor.Models.DataHolders
             }
         }
 
-        private double zoomPercentage = 100;
-
-        public double ZoomPercentage
-        {
-            get => zoomPercentage;
-            set
-            {
-                zoomPercentage = value;
-                RaisePropertyChanged(nameof(ZoomPercentage));
-            }
-        }
-
-        private Point viewPortPosition;
-
-        public Point ViewportPosition
-        {
-            get => viewPortPosition;
-            set
-            {
-                viewPortPosition = value;
-                RaisePropertyChanged(nameof(ViewportPosition));
-            }
-        }
-
-        private bool recenterZoombox = true;
-
-        public bool RecenterZoombox
-        {
-            get => recenterZoombox;
-            set
-            {
-                recenterZoombox = value;
-                RaisePropertyChanged(nameof(RecenterZoombox));
-            }
-        }
-
         public UndoManager UndoManager { get; set; }
 
-        public void CenterViewport()
-        {
-            RecenterZoombox = false; // It's a trick to trigger change in UserControl
-            RecenterZoombox = true;
-            ViewportPosition = default;
-            ZoomPercentage = default;
-        }
 
         public ObservableCollection<Color> Swatches { get; set; } = new ObservableCollection<Color>();
 
@@ -316,4 +267,4 @@ namespace PixiEditor.Models.DataHolders
                 new Coordinates(biggestX, biggestY));
         }
     }
-}
+}

+ 4 - 26
PixiEditor/Models/Tools/Tools/MoveViewportTool.cs

@@ -1,14 +1,11 @@
-using System.Drawing;
-using System.Windows.Input;
-using PixiEditor.Models.Position;
+using PixiEditor.Models.Position;
 using PixiEditor.ViewModels;
+using System.Windows.Input;
 
 namespace PixiEditor.Models.Tools.Tools
 {
     public class MoveViewportTool : ReadonlyTool
-    {
-        private Point clickPoint;
-
+    {
         public MoveViewportTool()
         {
             HideHighlight = true;
@@ -16,25 +13,6 @@ namespace PixiEditor.Models.Tools.Tools
             ActionDisplay = "Click and move to pan viewport.";
             Tooltip = "Move viewport. (H)";
         }
-
-        public override void OnMouseDown(MouseEventArgs e)
-        {
-            if (e.LeftButton == MouseButtonState.Pressed || e.MiddleButton == MouseButtonState.Pressed)
-            {
-                clickPoint = MousePositionConverter.GetCursorPosition();
-            }
-        }
-
-        public override void OnMouseMove(MouseEventArgs e)
-        {
-            if (e.LeftButton == MouseButtonState.Pressed || e.MiddleButton == MouseButtonState.Pressed)
-            {
-                var point = MousePositionConverter.GetCursorPosition();
-                ViewModelMain.Current.BitmapManager.ActiveDocument.ViewportPosition = new System.Windows.Point(
-                    point.X - clickPoint.X,
-                    point.Y - clickPoint.Y);
-            }
-        }
 
         public override void OnMouseUp(MouseEventArgs e)
         {
@@ -48,4 +26,4 @@ namespace PixiEditor.Models.Tools.Tools
         {
         }
     }
-}
+}

+ 2 - 52
PixiEditor/Models/Tools/Tools/ZoomTool.cs

@@ -1,27 +1,16 @@
-using System;
-using System.Windows;
+using PixiEditor.Models.Position;
 using System.Windows.Input;
-using PixiEditor.Models.Position;
-using PixiEditor.ViewModels;
 
 namespace PixiEditor.Models.Tools.Tools
 {
     public class ZoomTool : ReadonlyTool
     {
-        public const float ZoomSensitivityMultiplier = 30f;
-
-        private double startingX;
-
-        private double workAreaWidth = SystemParameters.WorkArea.Width;
-        private double pixelsPerZoomMultiplier;
-
         public ZoomTool()
         {
             HideHighlight = true;
             CanStartOutsideCanvas = true;
             ActionDisplay = "Click and move to zoom. Click to zoom in, hold alt and click to zoom out.";
             Tooltip = "Zooms viewport (Z). Click to zoom in, hold alt and click to zoom out.";
-            pixelsPerZoomMultiplier = workAreaWidth / ZoomSensitivityMultiplier;
         }
 
         public override void OnKeyDown(KeyEventArgs e)
@@ -38,49 +27,10 @@ namespace PixiEditor.Models.Tools.Tools
             {
                 ActionDisplay = "Click and move to zoom. Click to zoom in, hold alt and click to zoom out.";
             }
-        }
-
-        public override void OnRecordingLeftMouseDown(MouseEventArgs e)
-        {
-            startingX = MousePositionConverter.GetCursorPosition().X;
-            ViewModelMain.Current.BitmapManager.ActiveDocument.ZoomPercentage = 100; // This resest the value, so callback in MainDrawingPanel can fire again later
-        }
-
-        public override void OnMouseMove(MouseEventArgs e)
-        {
-            if (e.LeftButton == MouseButtonState.Pressed)
-            {
-                double xPos = MousePositionConverter.GetCursorPosition().X;
-
-                double rawPercentDifference = (xPos - startingX) / pixelsPerZoomMultiplier; // negative - zoom out, positive - zoom in, linear
-                double finalPercentDifference = Math.Pow(2, rawPercentDifference) * 100.0; // less than 100 - zoom out, greater than 100 - zoom in
-                Zoom(finalPercentDifference);
-            }
-        }
-
-        public override void OnStoppedRecordingMouseUp(MouseEventArgs e)
-        {
-            if (e.LeftButton == MouseButtonState.Released && e.RightButton == MouseButtonState.Released &&
-                startingX == MousePositionConverter.GetCursorPosition().X)
-            {
-                if (Keyboard.Modifiers.HasFlag(ModifierKeys.Alt))
-                {
-                    Zoom(85);
-                }
-                else
-                {
-                    Zoom(115);
-                }
-            }
-        }
-
-        public void Zoom(double percentage)
-        {
-            ViewModelMain.Current.BitmapManager.ActiveDocument.ZoomPercentage = percentage;
         }
 
         public override void Use(Coordinates[] pixels)
         {
         }
     }
-}
+}

+ 2 - 6
PixiEditor/ViewModels/SubViewModels/Main/ViewportViewModel.cs

@@ -1,6 +1,4 @@
-using System;
-using System.Windows;
-using PixiEditor.Helpers;
+using PixiEditor.Helpers;
 
 namespace PixiEditor.ViewModels.SubViewModels.Main
 {
@@ -37,8 +35,6 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
         private void ZoomViewport(object parameter)
         {
             double zoom = (int)parameter;
-            Owner.BitmapManager.ActiveDocument.ZoomPercentage = zoom;
-            Owner.BitmapManager.ActiveDocument.ZoomPercentage = 100;
         }
     }
-}
+}

+ 1 - 4
PixiEditor/ViewModels/ViewModelMain.cs

@@ -227,8 +227,6 @@ namespace PixiEditor.ViewModels
             {
                 document.PreviewLayer = null;
             }
-
-            BitmapManager.ActiveDocument?.CenterViewport();
         }
 
         public bool DocumentIsNotNull(object property)
@@ -334,7 +332,6 @@ namespace PixiEditor.ViewModels
         private void ActiveDocument_DocumentSizeChanged(object sender, DocumentSizeChangedEventArgs e)
         {
             BitmapManager.ActiveDocument.ActiveSelection = new Selection(Array.Empty<Coordinates>());
-            BitmapManager.ActiveDocument.CenterViewport();
             BitmapManager.ActiveDocument.ChangesSaved = false;
         }
 
@@ -355,4 +352,4 @@ namespace PixiEditor.ViewModels
             }
         }
     }
-}
+}

+ 0 - 3
PixiEditor/Views/MainWindow.xaml

@@ -227,12 +227,9 @@
                             <ui:DocumentsTemplateSelector.DocumentsViewTemplate>
                                 <DataTemplate DataType="{x:Type dataHolders:Document}">
                                     <usercontrols:DrawingViewPort
-                                        ZoomPercentage="{Binding ZoomPercentage}"
-                                        RecenterZoombox="{Binding RecenterZoombox}"
                                         GridLinesVisible="{Binding XamlAccesibleViewModel.ViewportSubViewModel.GridLinesEnabled}"
                                         Cursor="{Binding XamlAccesibleViewModel.ToolsSubViewModel.ToolCursor}"
                                         MiddleMouseClickedCommand="{Binding XamlAccesibleViewModel.ToolsSubViewModel.SelectToolCommand}"
-                                        ViewportPosition="{Binding ViewportPosition}"
                                         MouseMoveCommand="{Binding XamlAccesibleViewModel.IoSubViewModel.MouseMoveCommand}"
                                         MouseDownCommand="{Binding XamlAccesibleViewModel.IoSubViewModel.MouseDownCommand}"
                                         MouseXOnCanvas="{Binding MouseXOnCanvas, Mode=TwoWay}"

+ 2 - 6
PixiEditor/Views/UserControls/DrawingViewPort.xaml

@@ -15,13 +15,9 @@
         <BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter" />
         <converters:IntToViewportRectConverter x:Key="IntToViewportRectConverter" />
     </UserControl.Resources>
-    <vws:MainDrawingPanel ZoomPercentage="{Binding ZoomPercentage, Mode=TwoWay, ElementName=uc}"
-                          Center="{Binding RecenterZoombox, Mode=TwoWay, ElementName=uc}" 
-                          x:Name="DrawingPanel"
-                          CenterOnStart="True" Cursor="{Binding Cursor, ElementName=uc}" 
+    <vws:MainDrawingPanel x:Name="DrawingPanel"
                           MiddleMouseClickedCommand="{Binding MiddleMouseClickedCommand, ElementName=uc}" 
-                          MiddleMouseClickedCommandParameter="{x:Type tools:MoveViewportTool}"
-                          ViewportPosition="{Binding ViewportPosition, ElementName=uc, Mode=TwoWay}">
+                          MiddleMouseClickedCommandParameter="{x:Type tools:MoveViewportTool}">
         <i:Interaction.Triggers>
             <i:EventTrigger EventName="MouseMove">
                 <i:InvokeCommandAction Command="{Binding MouseMoveCommand, ElementName=uc}" />

+ 6 - 33
PixiEditor/Views/UserControls/DrawingViewPort.xaml.cs

@@ -14,44 +14,23 @@ namespace PixiEditor.Views.UserControls
             InitializeComponent();
         }
 
-        public static readonly DependencyProperty ZoomPercentageProperty =
-            DependencyProperty.Register("ZoomPercentage", typeof(float), typeof(DrawingViewPort), new PropertyMetadata(100f));
-
-        public static readonly DependencyProperty RecenterZoomboxProperty =
-            DependencyProperty.Register("RecenterZoombox", typeof(bool), typeof(DrawingViewPort), new PropertyMetadata(false));
-
         public static readonly DependencyProperty MiddleMouseClickedCommandProperty =
-            DependencyProperty.Register("MiddleMouseClickedCommand", typeof(ICommand), typeof(DrawingViewPort), new PropertyMetadata(default(ICommand)));
-
-        public static readonly DependencyProperty ViewportPositionProperty =
-            DependencyProperty.Register("ViewportPosition", typeof(Point), typeof(DrawingViewPort), new PropertyMetadata(default(Point)));
+            DependencyProperty.Register(nameof(MiddleMouseClickedCommand), typeof(ICommand), typeof(DrawingViewPort), new PropertyMetadata(default(ICommand)));
 
         public static readonly DependencyProperty MouseMoveCommandProperty =
-            DependencyProperty.Register("MouseMoveCommand", typeof(ICommand), typeof(DrawingViewPort), new PropertyMetadata(default(ICommand)));
+            DependencyProperty.Register(nameof(MouseMoveCommand), typeof(ICommand), typeof(DrawingViewPort), new PropertyMetadata(default(ICommand)));
 
         public static readonly DependencyProperty MouseDownCommandProperty =
-            DependencyProperty.Register("MouseDownCommand", typeof(ICommand), typeof(DrawingViewPort), new PropertyMetadata(default(ICommand)));
+            DependencyProperty.Register(nameof(MouseDownCommand), typeof(ICommand), typeof(DrawingViewPort), new PropertyMetadata(default(ICommand)));
 
         public static readonly DependencyProperty MouseXOnCanvasProperty =
-            DependencyProperty.Register("MouseXOnCanvas", typeof(double), typeof(DrawingViewPort), new PropertyMetadata(0.0));
+            DependencyProperty.Register(nameof(MouseXOnCanvas), typeof(double), typeof(DrawingViewPort), new PropertyMetadata(0.0));
 
         public static readonly DependencyProperty MouseYOnCanvasProperty =
-            DependencyProperty.Register("MouseYOnCanvas", typeof(double), typeof(DrawingViewPort), new PropertyMetadata(0.0));
+            DependencyProperty.Register(nameof(MouseYOnCanvas), typeof(double), typeof(DrawingViewPort), new PropertyMetadata(0.0));
 
         public static readonly DependencyProperty GridLinesVisibleProperty =
-            DependencyProperty.Register("GridLinesVisible", typeof(bool), typeof(DrawingViewPort), new PropertyMetadata(false));
-
-        public float ZoomPercentage
-        {
-            get => (float)GetValue(ZoomPercentageProperty);
-            set => SetValue(ZoomPercentageProperty, value);
-        }
-
-        public bool RecenterZoombox
-        {
-            get => (bool)GetValue(RecenterZoomboxProperty);
-            set => SetValue(RecenterZoomboxProperty, value);
-        }
+            DependencyProperty.Register(nameof(GridLinesVisible), typeof(bool), typeof(DrawingViewPort), new PropertyMetadata(false));
 
         public ICommand MiddleMouseClickedCommand
         {
@@ -59,12 +38,6 @@ namespace PixiEditor.Views.UserControls
             set => SetValue(MiddleMouseClickedCommandProperty, value);
         }
 
-        public Point ViewportPosition
-        {
-            get => (Point)GetValue(ViewportPositionProperty);
-            set => SetValue(ViewportPositionProperty, value);
-        }
-
         public ICommand MouseMoveCommand
         {
             get => (ICommand)GetValue(MouseMoveCommandProperty);

+ 4 - 5
PixiEditor/Views/UserControls/MainDrawingPanel.xaml

@@ -9,18 +9,17 @@
              xmlns:helpers="clr-namespace:PixiEditor.Helpers"
              xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
              mc:Ignorable="d" PreviewMouseDown="MainDrawingPanel_PreviewMouseDown" PreviewMouseUp="MainDrawingPanel_PreviewMouseUp"
-             d:DesignHeight="450" d:DesignWidth="800" x:Name="mainDrawingPanel" PreviewMouseWheel="Zoombox_MouseWheel">
+             d:DesignHeight="450" d:DesignWidth="800" x:Name="mainDrawingPanel">
     <Grid>
-        <userc:ZoomBox/>
-        <xctk:Zoombox PreviewMouseDown="Zoombox_PreviewMouseDown" Cursor="{Binding Cursor}" Name="Zoombox" KeepContentInBounds="False" Visibility="Hidden"
-                  Loaded="Zoombox_Loaded" IsAnimated="False" MouseDown="Zoombox_MouseDown"
+        <userc:ZoomBox AdditionalContent="{Binding Item, ElementName=mainDrawingPanel}" />
+        <xctk:Zoombox Cursor="{Binding Cursor}" Name="Zoombox" KeepContentInBounds="False" Visibility="Hidden"
+                  IsAnimated="False" MouseDown="Zoombox_MouseDown"
                   CurrentViewChanged="Zoombox_CurrentViewChanged" DragModifiers="Blocked" ZoomModifiers="None">
             <i:Interaction.Triggers>
                 <i:EventTrigger EventName="MouseMove">
                     <i:InvokeCommandAction Command="{Binding MouseMoveCommand, ElementName=mainDrawingPanel, Mode=OneWay}" />
                 </i:EventTrigger>
             </i:Interaction.Triggers>
-            <ContentPresenter Content="{Binding Item, ElementName=mainDrawingPanel}" />
         </xctk:Zoombox>
     </Grid>
 </UserControl>

+ 0 - 120
PixiEditor/Views/UserControls/MainDrawingPanel.xaml.cs

@@ -1,6 +1,5 @@
 using PixiEditor.Models.Tools.Tools;
 using PixiEditor.ViewModels;
-using System;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
@@ -11,10 +10,6 @@ namespace PixiEditor.Views
 {
     public partial class MainDrawingPanel : UserControl
     {
-        public static readonly DependencyProperty CenterProperty =
-            DependencyProperty.Register(nameof(Center), typeof(bool), typeof(MainDrawingPanel),
-                new PropertyMetadata(true, OnCenterChanged));
-
         public static readonly DependencyProperty MouseXProperty =
             DependencyProperty.Register(nameof(MouseX), typeof(double), typeof(MainDrawingPanel), new PropertyMetadata(null));
 
@@ -25,36 +20,18 @@ namespace PixiEditor.Views
             DependencyProperty.Register(nameof(MouseMoveCommand), typeof(ICommand), typeof(MainDrawingPanel),
                 new PropertyMetadata(null));
 
-        public static readonly DependencyProperty CenterOnStartProperty =
-            DependencyProperty.Register(nameof(CenterOnStart), typeof(bool), typeof(MainDrawingPanel),
-                new PropertyMetadata(false));
-
         public static readonly DependencyProperty ItemProperty =
             DependencyProperty.Register(nameof(Item), typeof(object), typeof(MainDrawingPanel), new PropertyMetadata(default(FrameworkElement)));
 
         public static readonly DependencyProperty IsUsingZoomToolProperty =
             DependencyProperty.Register(nameof(IsUsingZoomTool), typeof(bool), typeof(MainDrawingPanel), new PropertyMetadata(false));
 
-        public static readonly DependencyProperty ZoomPercentageProperty =
-            DependencyProperty.Register(nameof(ZoomPercentage), typeof(double), typeof(MainDrawingPanel),
-                new PropertyMetadata(0.0, ZoomPercentegeChanged));
-
-        public static readonly DependencyProperty ViewportPositionProperty =
-            DependencyProperty.Register(nameof(ViewportPosition), typeof(Point), typeof(MainDrawingPanel),
-                new PropertyMetadata(default(Point), ViewportPosCallback));
-
         public static readonly DependencyProperty MiddleMouseClickedCommandProperty =
             DependencyProperty.Register(nameof(MiddleMouseClickedCommand), typeof(ICommand), typeof(MainDrawingPanel), new PropertyMetadata(default(ICommand)));
 
         public static readonly DependencyProperty MiddleMouseClickedCommandParameterProperty =
             DependencyProperty.Register(nameof(MiddleMouseClickedCommandParameter), typeof(object), typeof(MainDrawingPanel), new PropertyMetadata(default(object)));
 
-        public bool Center
-        {
-            get => (bool)GetValue(CenterProperty);
-            set => SetValue(CenterProperty, value);
-        }
-
         public double MouseX
         {
             get => (double)GetValue(MouseXProperty);
@@ -73,12 +50,6 @@ namespace PixiEditor.Views
             set => SetValue(MouseMoveCommandProperty, value);
         }
 
-        public bool CenterOnStart
-        {
-            get => (bool)GetValue(CenterOnStartProperty);
-            set => SetValue(CenterOnStartProperty, value);
-        }
-
         public object Item
         {
             get => GetValue(ItemProperty);
@@ -91,18 +62,6 @@ namespace PixiEditor.Views
             set => SetValue(IsUsingZoomToolProperty, value);
         }
 
-        public double ZoomPercentage
-        {
-            get => (double)GetValue(ZoomPercentageProperty);
-            set => SetValue(ZoomPercentageProperty, value);
-        }
-
-        public Point ViewportPosition
-        {
-            get => (Point)GetValue(ViewportPositionProperty);
-            set => SetValue(ViewportPositionProperty, value);
-        }
-
         public ICommand MiddleMouseClickedCommand
         {
             get => (ICommand)GetValue(MiddleMouseClickedCommandProperty);
@@ -115,7 +74,6 @@ namespace PixiEditor.Views
             set => SetValue(MiddleMouseClickedCommandParameterProperty, value);
         }
 
-        public double ClickScale;
         public Point ClickPosition;
 
         public MainDrawingPanel()
@@ -124,66 +82,11 @@ namespace PixiEditor.Views
             Zoombox.ZoomToSelectionModifiers = new KeyModifierCollection() { KeyModifier.RightAlt };
         }
 
-        private static void ZoomPercentegeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
-        {
-            MainDrawingPanel panel = (MainDrawingPanel)d;
-            double percentage = (double)e.NewValue;
-            if (percentage == 100)
-            {
-                panel.SetClickValues();
-            }
-            panel.Zoombox.ZoomTo(panel.ClickScale * ((double)e.NewValue / 100.0));
-        }
-
-        private static void ViewportPosCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
-        {
-            MainDrawingPanel panel = (MainDrawingPanel)d;
-            if (PresentationSource.FromVisual(panel.Zoombox) == null)
-            {
-                panel.Zoombox.Position = default;
-                return;
-            }
-            TranslateZoombox(panel, (Point)e.NewValue);
-        }
-
-        private static void TranslateZoombox(MainDrawingPanel panel, Point vector)
-        {
-            var newPos = new Point(
-                panel.ClickPosition.X + vector.X,
-                panel.ClickPosition.Y + vector.Y);
-            panel.Zoombox.Position = newPos;
-        }
-
-        private static void OnCenterChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
-        {
-            MainDrawingPanel panel = (MainDrawingPanel)d;
-            panel.Zoombox.FitToBounds();
-        }
-
-        private void SetClickValues()
-        {
-            if (!IsUsingZoomTool)
-            {
-                return;
-            }
-
-            ClickScale = Zoombox.Scale;
-            SetZoomOrigin();
-        }
-
-        private void SetZoomOrigin()
-        {
-            var item = (FrameworkElement)Item;
-            if (item == null) return;
-            var mousePos = Mouse.GetPosition(item);
-            Zoombox.ZoomOrigin = new Point(Math.Clamp(mousePos.X / item.Width, 0, 1), Math.Clamp(mousePos.Y / item.Height, 0, 1));
-        }
         private void MainDrawingPanel_PreviewMouseDown(object sender, MouseButtonEventArgs e)
         {
             IsUsingZoomTool = ViewModelMain.Current.BitmapManager.SelectedTool is ZoomTool;
             Mouse.Capture((IInputElement)sender, CaptureMode.SubTree);
             ClickPosition = ((FrameworkElement)Item).TranslatePoint(new Point(0, 0), Zoombox);
-            SetClickValues();
         }
 
         private void MainDrawingPanel_PreviewMouseUp(object sender, MouseButtonEventArgs e)
@@ -191,21 +94,6 @@ namespace PixiEditor.Views
             ((IInputElement)sender).ReleaseMouseCapture();
         }
 
-        private void Zoombox_Loaded(object sender, RoutedEventArgs e)
-        {
-            if (CenterOnStart)
-            {
-                ((Zoombox)sender).FitToBounds();
-            }
-
-            ClickScale = Zoombox.Scale;
-        }
-
-        private void Zoombox_MouseWheel(object sender, MouseWheelEventArgs e)
-        {
-            SetZoomOrigin();
-        }
-
         private void Zoombox_MouseDown(object sender, MouseButtonEventArgs e)
         {
             if (e.MiddleButton == MouseButtonState.Pressed &&
@@ -218,13 +106,5 @@ namespace PixiEditor.Views
         {
             Zoombox.MinScale = 32 / ((FrameworkElement)Item).Width;
         }
-
-        private void Zoombox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
-        {
-            if (ZoomPercentage == 100)
-            {
-                SetClickValues();
-            }
-        }
     }
 }

+ 9 - 10
PixiEditor/Views/UserControls/ZoomBox.xaml

@@ -1,19 +1,18 @@
 <ContentControl x:Class="PixiEditor.Views.UserControls.ZoomBox"
-             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
-             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
-             xmlns:local="clr-namespace:PixiEditor.Views.UserControls"
-             mc:Ignorable="d" 
-             d:DesignHeight="450" d:DesignWidth="800">
+                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+                xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+                xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+                xmlns:local="clr-namespace:PixiEditor.Views.UserControls"
+                mc:Ignorable="d" 
+                x:Name="uc"
+                d:DesignHeight="450" d:DesignWidth="800">
     <Canvas MouseDown="OnMouseDown" MouseUp="OnMouseUp" MouseMove="OnMouseMove" MouseWheel="OnScroll" x:Name="mainCanvas" Background="Transparent">
         <Grid x:Name="mainGrid">
             <Grid.LayoutTransform>
                 <ScaleTransform x:Name="scaleTransform"/>
             </Grid.LayoutTransform>
-            <Border Background="White" BorderThickness="2" BorderBrush="Aquamarine" Width="200" Height="100">
-                <TextBlock>Test!</TextBlock>
-            </Border>
+            <ContentPresenter Content="{Binding AdditionalContent, ElementName=uc}"/>
         </Grid>
     </Canvas>
 </ContentControl>

+ 31 - 6
PixiEditor/Views/UserControls/ZoomBox.xaml.cs

@@ -2,14 +2,16 @@
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
+using System.Windows.Markup;
 
 namespace PixiEditor.Views.UserControls
 {
+    [ContentProperty(nameof(AdditionalContent))]
     public partial class ZoomBox : ContentControl
     {
         public enum Mode
         {
-            Normal, Move, Zoom
+            Normal, MoveTool, ZoomTool
         }
 
         private interface IDragOperation
@@ -91,6 +93,24 @@ namespace PixiEditor.Views.UserControls
             }
         }
 
+        public static readonly DependencyProperty AdditionalContentProperty =
+            DependencyProperty.Register(nameof(AdditionalContent), typeof(object), typeof(ZoomBox),
+              new PropertyMetadata(null));
+
+        public static readonly DependencyProperty ZoomModeProperty =
+            DependencyProperty.Register(nameof(ZoomMode), typeof(Mode), typeof(ZoomBox),
+              new PropertyMetadata(Mode.Normal, ZoomModeChanged));
+        public object AdditionalContent
+        {
+            get => GetValue(AdditionalContentProperty);
+            set => SetValue(AdditionalContentProperty, value);
+        }
+        public Mode ZoomMode
+        {
+            get => (Mode)GetValue(ZoomModeProperty);
+            set => SetValue(ZoomModeProperty, value);
+        }
+
         private Point spaceOriginPos;
         private Point SpaceOriginPos
         {
@@ -116,14 +136,19 @@ namespace PixiEditor.Views.UserControls
             }
         }
         private double Zoom => Math.Pow(1.1, zoomPower);
-        private Mode mode;
 
         private IDragOperation activeDragOperation = null;
 
+        private static void ZoomModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+        {
+            ZoomBox sender = (ZoomBox)d;
+            sender.activeDragOperation?.Terminate();
+            sender.activeDragOperation = null;
+        }
+
         public ZoomBox()
         {
             InitializeComponent();
-            mode = Mode.Zoom;
         }
 
         private Point ToScreenSpace(Point p)
@@ -146,14 +171,14 @@ namespace PixiEditor.Views.UserControls
 
         private void OnMouseDown(object sender, MouseButtonEventArgs e)
         {
-            if (mode == Mode.Normal)
+            if (ZoomMode == Mode.Normal)
                 return;
 
             activeDragOperation?.Terminate();
 
-            if (mode == Mode.Move)
+            if (ZoomMode == Mode.MoveTool)
                 activeDragOperation = new MoveDragOperation(this);
-            else if (mode == Mode.Zoom)
+            else if (ZoomMode == Mode.ZoomTool)
                 activeDragOperation = new ZoomDragOperation(this);
 
             activeDragOperation.Start(e);