|
@@ -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();
|
|
|
}
|
|
|
}
|
|
|
}
|