Ver Fonte

Formatting

Equbuxu há 4 anos atrás
pai
commit
51752aa861

+ 12 - 12
PixiEditor/Views/UserControls/DrawingViewPort.xaml

@@ -22,19 +22,19 @@
                           MiddleMouseClickedCommand="{Binding MiddleMouseClickedCommand, ElementName=uc}" 
                           MiddleMouseClickedCommandParameter="{x:Type tools:MoveViewportTool}"
                           ViewportPosition="{Binding ViewportPosition, ElementName=uc, Mode=TwoWay}">
-            <i:Interaction.Triggers>
-                <i:EventTrigger EventName="MouseMove">
-                    <i:InvokeCommandAction Command="{Binding MouseMoveCommand, ElementName=uc}" />
-                </i:EventTrigger>
-                <i:EventTrigger EventName="MouseDown">
-                    <i:InvokeCommandAction Command="{Binding MouseDownCommand, ElementName=uc}"/>
-                </i:EventTrigger>
-            </i:Interaction.Triggers>
-            <i:Interaction.Behaviors>
-                <behaviors:MouseBehavior RelativeTo="{Binding ElementName=DrawingPanel, Path=Item}"
+        <i:Interaction.Triggers>
+            <i:EventTrigger EventName="MouseMove">
+                <i:InvokeCommandAction Command="{Binding MouseMoveCommand, ElementName=uc}" />
+            </i:EventTrigger>
+            <i:EventTrigger EventName="MouseDown">
+                <i:InvokeCommandAction Command="{Binding MouseDownCommand, ElementName=uc}"/>
+            </i:EventTrigger>
+        </i:Interaction.Triggers>
+        <i:Interaction.Behaviors>
+            <behaviors:MouseBehavior RelativeTo="{Binding ElementName=DrawingPanel, Path=Item}"
                                                   MouseX="{Binding MouseXOnCanvas, Mode=TwoWay, ElementName=uc}"
                                                   MouseY="{Binding MouseYOnCanvas, Mode=TwoWay, ElementName=uc}" />
-            </i:Interaction.Behaviors>
+        </i:Interaction.Behaviors>
         <vws:MainDrawingPanel.Item>
             <Canvas Width="{Binding Width}"
                                 Height="{Binding Height}" VerticalAlignment="Center"
@@ -114,5 +114,5 @@
                 </Grid>
             </Canvas>
         </vws:MainDrawingPanel.Item>
-        </vws:MainDrawingPanel>
+    </vws:MainDrawingPanel>
 </UserControl>

+ 46 - 55
PixiEditor/Views/UserControls/DrawingViewPort.xaml.cs

@@ -14,94 +14,85 @@ 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)));
+
+        public static readonly DependencyProperty MouseMoveCommandProperty =
+            DependencyProperty.Register("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)));
+
+        public static readonly DependencyProperty MouseXOnCanvasProperty =
+            DependencyProperty.Register("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));
+
+        public static readonly DependencyProperty GridLinesVisibleProperty =
+            DependencyProperty.Register("GridLinesVisible", typeof(bool), typeof(DrawingViewPort), new PropertyMetadata(false));
+
         public float ZoomPercentage
         {
-            get { return (float)GetValue(ZoomPercentageProperty); }
-            set { SetValue(ZoomPercentageProperty, value); }
+            get => (float)GetValue(ZoomPercentageProperty);
+            set => SetValue(ZoomPercentageProperty, value);
         }
 
-        // Using a DependencyProperty as the backing store for ZoomPercentage.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty ZoomPercentageProperty =
-            DependencyProperty.Register("ZoomPercentage", typeof(float), typeof(DrawingViewPort), new PropertyMetadata(100f));
-
         public bool RecenterZoombox
         {
-            get { return (bool)GetValue(RecenterZoomboxProperty); }
-            set { SetValue(RecenterZoomboxProperty, value); }
+            get => (bool)GetValue(RecenterZoomboxProperty);
+            set => SetValue(RecenterZoomboxProperty, value);
         }
 
-        // Using a DependencyProperty as the backing store for RecenterZoombox.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty RecenterZoomboxProperty =
-            DependencyProperty.Register("RecenterZoombox", typeof(bool), typeof(DrawingViewPort), new PropertyMetadata(false));
-
         public ICommand MiddleMouseClickedCommand
         {
-            get { return (ICommand)GetValue(MiddleMouseClickedCommandProperty); }
-            set { SetValue(MiddleMouseClickedCommandProperty, value); }
+            get => (ICommand)GetValue(MiddleMouseClickedCommandProperty);
+            set => SetValue(MiddleMouseClickedCommandProperty, value);
         }
 
-        // Using a DependencyProperty as the backing store for MiddleMouseClickedCommand.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty MiddleMouseClickedCommandProperty =
-            DependencyProperty.Register("MiddleMouseClickedCommand", typeof(ICommand), typeof(DrawingViewPort), new PropertyMetadata(default(ICommand)));
-
         public Point ViewportPosition
         {
-            get { return (Point)GetValue(ViewportPositionProperty); }
-            set { SetValue(ViewportPositionProperty, value); }
+            get => (Point)GetValue(ViewportPositionProperty);
+            set => SetValue(ViewportPositionProperty, value);
         }
 
-        // Using a DependencyProperty as the backing store for ViewportPosition.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty ViewportPositionProperty =
-            DependencyProperty.Register("ViewportPosition", typeof(Point), typeof(DrawingViewPort), new PropertyMetadata(default(Point)));
-
         public ICommand MouseMoveCommand
         {
-            get { return (ICommand)GetValue(MouseMoveCommandProperty); }
-            set { SetValue(MouseMoveCommandProperty, value); }
+            get => (ICommand)GetValue(MouseMoveCommandProperty);
+            set => SetValue(MouseMoveCommandProperty, value);
         }
 
-        // Using a DependencyProperty as the backing store for MouseMoveCommand.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty MouseMoveCommandProperty =
-            DependencyProperty.Register("MouseMoveCommand", typeof(ICommand), typeof(DrawingViewPort), new PropertyMetadata(default(ICommand)));
-
         public ICommand MouseDownCommand
         {
-            get { return (ICommand)GetValue(MouseDownCommandProperty); }
-            set { SetValue(MouseDownCommandProperty, value); }
+            get => (ICommand)GetValue(MouseDownCommandProperty);
+            set => SetValue(MouseDownCommandProperty, value);
         }
 
-        // Using a DependencyProperty as the backing store for MouseDownCommand.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty MouseDownCommandProperty =
-            DependencyProperty.Register("MouseDownCommand", typeof(ICommand), typeof(DrawingViewPort), new PropertyMetadata(default(ICommand)));
-
         public double MouseXOnCanvas
         {
-            get { return (double)GetValue(MouseXOnCanvasProperty); }
-            set { SetValue(MouseXOnCanvasProperty, value); }
+            get => (double)GetValue(MouseXOnCanvasProperty);
+            set => SetValue(MouseXOnCanvasProperty, value);
         }
 
-        // Using a DependencyProperty as the backing store for MouseXOnCanvas.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty MouseXOnCanvasProperty =
-            DependencyProperty.Register("MouseXOnCanvas", typeof(double), typeof(DrawingViewPort), new PropertyMetadata(0.0));
-
         public double MouseYOnCanvas
         {
-            get { return (double)GetValue(MouseYOnCanvasProperty); }
-            set { SetValue(MouseYOnCanvasProperty, value); }
+            get => (double)GetValue(MouseYOnCanvasProperty);
+            set => SetValue(MouseYOnCanvasProperty, value);
         }
 
-        // Using a DependencyProperty as the backing store for MouseXOnCanvas.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty MouseYOnCanvasProperty =
-            DependencyProperty.Register("MouseYOnCanvas", typeof(double), typeof(DrawingViewPort), new PropertyMetadata(0.0));
-
         public bool GridLinesVisible
         {
-            get { return (bool)GetValue(GridLinesVisibleProperty); }
-            set { SetValue(GridLinesVisibleProperty, value); }
+            get => (bool)GetValue(GridLinesVisibleProperty);
+            set => SetValue(GridLinesVisibleProperty, value);
         }
-
-        // Using a DependencyProperty as the backing store for GridLinesVisible.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty GridLinesVisibleProperty =
-            DependencyProperty.Register("GridLinesVisible", typeof(bool), typeof(DrawingViewPort), new PropertyMetadata(false));
     }
-}
+}

+ 63 - 91
PixiEditor/Views/UserControls/MainDrawingPanel.xaml.cs

@@ -9,70 +9,45 @@ using Xceed.Wpf.Toolkit.Zoombox;
 
 namespace PixiEditor.Views
 {
-    /// <summary>
-    ///     Interaction logic for MainDrawingPanel.xaml
-    /// </summary>
     public partial class MainDrawingPanel : UserControl
     {
-        // Using a DependencyProperty as the backing store for Center.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty CenterProperty =
-            DependencyProperty.Register("Center", typeof(bool), typeof(MainDrawingPanel),
+            DependencyProperty.Register(nameof(Center), typeof(bool), typeof(MainDrawingPanel),
                 new PropertyMetadata(true, OnCenterChanged));
 
-        // Using a DependencyProperty as the backing store for MouseX.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty MouseXProperty =
-            DependencyProperty.Register("MouseX", typeof(double), typeof(MainDrawingPanel), new PropertyMetadata(null));
+            DependencyProperty.Register(nameof(MouseX), typeof(double), typeof(MainDrawingPanel), new PropertyMetadata(null));
 
-        // Using a DependencyProperty as the backing store for MouseX.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty MouseYProperty =
-            DependencyProperty.Register("MouseY", typeof(double), typeof(MainDrawingPanel), new PropertyMetadata(null));
+            DependencyProperty.Register(nameof(MouseY), typeof(double), typeof(MainDrawingPanel), new PropertyMetadata(null));
 
-        // Using a DependencyProperty as the backing store for MouseMoveCommand.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty MouseMoveCommandProperty =
-            DependencyProperty.Register("MouseMoveCommand", typeof(ICommand), typeof(MainDrawingPanel),
+            DependencyProperty.Register(nameof(MouseMoveCommand), typeof(ICommand), typeof(MainDrawingPanel),
                 new PropertyMetadata(null));
 
-        // Using a DependencyProperty as the backing store for CenterOnStart.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty CenterOnStartProperty =
-            DependencyProperty.Register("CenterOnStart", typeof(bool), typeof(MainDrawingPanel),
+            DependencyProperty.Register(nameof(CenterOnStart), typeof(bool), typeof(MainDrawingPanel),
                 new PropertyMetadata(false));
 
-        // Using a DependencyProperty as the backing store for Item.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty ItemProperty =
-            DependencyProperty.Register("Item", typeof(object), typeof(MainDrawingPanel), new PropertyMetadata(default(FrameworkElement)));
+            DependencyProperty.Register(nameof(Item), typeof(object), typeof(MainDrawingPanel), new PropertyMetadata(default(FrameworkElement)));
 
-        // Using a DependencyProperty as the backing store for Item.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty IsUsingZoomToolProperty =
-            DependencyProperty.Register("IsUsingZoomTool", typeof(bool), typeof(MainDrawingPanel), new PropertyMetadata(false));
+            DependencyProperty.Register(nameof(IsUsingZoomTool), typeof(bool), typeof(MainDrawingPanel), new PropertyMetadata(false));
 
-
-        public double ZoomPercentage
-        {
-            get { return (double)GetValue(ZoomPercentageProperty); }
-            set { SetValue(ZoomPercentageProperty, value); }
-        }
-
-        // Using a DependencyProperty as the backing store for ZoomPercentage.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty ZoomPercentageProperty =
-            DependencyProperty.Register("ZoomPercentage", typeof(double), typeof(MainDrawingPanel), new PropertyMetadata(0.0, ZoomPercentegeChanged));
-
+            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 Point ViewportPosition
-        {
-            get { return (Point)GetValue(ViewportPositionProperty); }
-            set { SetValue(ViewportPositionProperty, value); }
-        }
+        public static readonly DependencyProperty MiddleMouseClickedCommandProperty =
+            DependencyProperty.Register(nameof(MiddleMouseClickedCommand), typeof(ICommand), typeof(MainDrawingPanel), new PropertyMetadata(default(ICommand)));
 
-        // Using a DependencyProperty as the backing store for ViewportPosition.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty ViewportPositionProperty =
-            DependencyProperty.Register(
-                "ViewportPosition",
-                typeof(Point),
-                typeof(MainDrawingPanel),
-                new PropertyMetadata(
-                    default(Point),
-                    ViewportPosCallback));
+        public static readonly DependencyProperty MiddleMouseClickedCommandParameterProperty =
+            DependencyProperty.Register(nameof(MiddleMouseClickedCommandParameter), typeof(object), typeof(MainDrawingPanel), new PropertyMetadata(default(object)));
 
         public bool Center
         {
@@ -116,30 +91,38 @@ namespace PixiEditor.Views
             set => SetValue(IsUsingZoomToolProperty, value);
         }
 
-        public ICommand MiddleMouseClickedCommand
+        public double ZoomPercentage
         {
-            get { return (ICommand)GetValue(MiddleMouseClickedCommandProperty); }
-            set { SetValue(MiddleMouseClickedCommandProperty, value); }
+            get => (double)GetValue(ZoomPercentageProperty);
+            set => SetValue(ZoomPercentageProperty, value);
         }
 
-        // Using a DependencyProperty as the backing store for MiddleMouseClickedCommand.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty MiddleMouseClickedCommandProperty =
-            DependencyProperty.Register("MiddleMouseClickedCommand", typeof(ICommand), typeof(MainDrawingPanel), new PropertyMetadata(default(ICommand)));
+        public Point ViewportPosition
+        {
+            get => (Point)GetValue(ViewportPositionProperty);
+            set => SetValue(ViewportPositionProperty, value);
+        }
+
+        public ICommand MiddleMouseClickedCommand
+        {
+            get => (ICommand)GetValue(MiddleMouseClickedCommandProperty);
+            set => SetValue(MiddleMouseClickedCommandProperty, value);
+        }
 
         public object MiddleMouseClickedCommandParameter
         {
-            get { return (object)GetValue(MiddleMouseClickedCommandParameterProperty); }
-            set { SetValue(MiddleMouseClickedCommandParameterProperty, value); }
+            get => GetValue(MiddleMouseClickedCommandParameterProperty);
+            set => SetValue(MiddleMouseClickedCommandParameterProperty, value);
         }
 
-        // Using a DependencyProperty as the backing store for MiddleMouseClickedCommandParameter.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty MiddleMouseClickedCommandParameterProperty =
-            DependencyProperty.Register(
-                "MiddleMouseClickedCommandParameter",
-                typeof(object),
-                typeof(MainDrawingPanel),
-                new PropertyMetadata(
-                    default(object)));
+        public double ClickScale;
+        public Point ClickPosition;
+
+        public MainDrawingPanel()
+        {
+            InitializeComponent();
+            Zoombox.ZoomToSelectionModifiers = new KeyModifierCollection() { KeyModifier.RightAlt };
+        }
 
         private static void ZoomPercentegeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
         {
@@ -152,15 +135,6 @@ namespace PixiEditor.Views
             panel.Zoombox.ZoomTo(panel.ClickScale * ((double)e.NewValue / 100.0));
         }
 
-        public double ClickScale;
-        public Point ClickPosition;
-
-        public MainDrawingPanel()
-        {
-            InitializeComponent();
-            Zoombox.ZoomToSelectionModifiers = new KeyModifierCollection() { KeyModifier.RightAlt };
-        }
-
         private static void ViewportPosCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
         {
             MainDrawingPanel panel = (MainDrawingPanel)d;
@@ -186,19 +160,6 @@ namespace PixiEditor.Views
             panel.Zoombox.FitToBounds();
         }
 
-        private void Zoombox_CurrentViewChanged(object sender, ZoomboxViewChangedEventArgs e)
-        {
-            Zoombox.MinScale = 32 / ((FrameworkElement)Item).Width;
-        }
-
-        private void Zoombox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
-        {
-            if (ZoomPercentage == 100)
-            {
-                SetClickValues();
-            }
-        }
-
         private void SetClickValues()
         {
             if (!IsUsingZoomTool)
@@ -217,6 +178,18 @@ namespace PixiEditor.Views
             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)
+        {
+            ((IInputElement)sender).ReleaseMouseCapture();
+        }
 
         private void Zoombox_Loaded(object sender, RoutedEventArgs e)
         {
@@ -233,25 +206,24 @@ namespace PixiEditor.Views
             SetZoomOrigin();
         }
 
-        private void MainDrawingPanel_PreviewMouseDown(object sender, MouseButtonEventArgs e)
+        private void Zoombox_MouseDown(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();
+            if (e.MiddleButton == MouseButtonState.Pressed &&
+                MiddleMouseClickedCommand.CanExecute(MiddleMouseClickedCommandParameter))
+            {
+                MiddleMouseClickedCommand.Execute(MiddleMouseClickedCommandParameter);
+            }
         }
-
-        private void MainDrawingPanel_PreviewMouseUp(object sender, MouseButtonEventArgs e)
+        private void Zoombox_CurrentViewChanged(object sender, ZoomboxViewChangedEventArgs e)
         {
-            ((IInputElement)sender).ReleaseMouseCapture();
+            Zoombox.MinScale = 32 / ((FrameworkElement)Item).Width;
         }
 
-        private void Zoombox_MouseDown(object sender, MouseButtonEventArgs e)
+        private void Zoombox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
         {
-            if (e.MiddleButton == MouseButtonState.Pressed &&
-                MiddleMouseClickedCommand.CanExecute(MiddleMouseClickedCommandParameter))
+            if (ZoomPercentage == 100)
             {
-                MiddleMouseClickedCommand.Execute(MiddleMouseClickedCommandParameter);
+                SetClickValues();
             }
         }
     }