From a5036d12300cb4f6831255987da3d3800731f804 Mon Sep 17 00:00:00 2001 From: Venomalia Date: Tue, 10 Aug 2021 10:45:21 +0200 Subject: [PATCH] the grid will now be displayed. --- Controls/PanZoom.xaml | 5 +++-- Data/CanvasGrid.cs | 8 +++---- Data/RegionBrush.cs | 18 ++++++++++++++-- ValueConverters/CanvasGridToViewport.cs | 28 +++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 ValueConverters/CanvasGridToViewport.cs diff --git a/Controls/PanZoom.xaml b/Controls/PanZoom.xaml index ad47db7..39b9174 100644 --- a/Controls/PanZoom.xaml +++ b/Controls/PanZoom.xaml @@ -11,6 +11,7 @@ + - @@ -173,7 +174,7 @@ - + diff --git a/Data/CanvasGrid.cs b/Data/CanvasGrid.cs index e269231..19ec705 100644 --- a/Data/CanvasGrid.cs +++ b/Data/CanvasGrid.cs @@ -29,7 +29,7 @@ public double X { value = 0; _x = value; - RectRegion.Grid = this; + OnPropertyChanged(nameof(CanvasGrid)); OnPropertyChanged(nameof(X)); } } @@ -50,7 +50,7 @@ public double Y { value = 0; _y = value; - RectRegion.Grid = this; + OnPropertyChanged(nameof(CanvasGrid)); OnPropertyChanged(nameof(Y)); } } @@ -72,7 +72,7 @@ public double Width if (X >= value) X = value - 1; - RectRegion.Grid = this; + OnPropertyChanged(nameof(CanvasGrid)); OnPropertyChanged(nameof(Width)); } } @@ -94,7 +94,7 @@ public double Height if (Y >= value) Y = value - 1; - RectRegion.Grid = this; + OnPropertyChanged(nameof(CanvasGrid)); OnPropertyChanged(nameof(Height)); } } diff --git a/Data/RegionBrush.cs b/Data/RegionBrush.cs index 102b880..b3ebcee 100644 --- a/Data/RegionBrush.cs +++ b/Data/RegionBrush.cs @@ -68,17 +68,31 @@ public bool Subpixel /// /// Canvas grid. /// - private CanvasGrid _grid = new CanvasGrid(0,0,1,1); + private CanvasGrid _grid; public CanvasGrid Grid { - get { return _grid; } + get + { + if (_grid == null) + Grid = new CanvasGrid(0, 0, 1, 1); + return _grid; + } set { _grid = value; + _grid.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(UpdateCanvasGrid); OnPropertyChanged(nameof(Grid)); } } + private void UpdateCanvasGrid(object sender, System.ComponentModel.PropertyChangedEventArgs e) + { + if (e.PropertyName == nameof(CanvasGrid)) + { + OnPropertyChanged(nameof(Grid)); + RectRegion.Grid = _grid; + } + } #endregion } } diff --git a/ValueConverters/CanvasGridToViewport.cs b/ValueConverters/CanvasGridToViewport.cs new file mode 100644 index 0000000..639cb01 --- /dev/null +++ b/ValueConverters/CanvasGridToViewport.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using System.Windows; +using System.Windows.Data; + +namespace DolphinDynamicInputTextureCreator.ValueConverters +{ + class CanvasGridToViewport : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var Rect = (Rect)(Data.CanvasGrid)value; + Rect.Width *= 2; + Rect.Height *= 2; + return (Rect)Rect; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + var Rect = (Rect)value; + Rect.Width *= 0.5; + Rect.Height *= 0.5; + return (Rect)Rect; + } + } +}