Skip to content

Commit

Permalink
the grid will now be displayed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Venomalia committed Aug 10, 2021
1 parent 2b979f3 commit a5036d1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
5 changes: 3 additions & 2 deletions Controls/PanZoom.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<UserControl.Resources>
<converters:ScaleFactorToPercentageValueConverter x:Key="ScaleFactorToPercentageValueConverter"/>
<converters:PathToImageValueConverter x:Key="PathToImageValueConverter"/>
<converters:CanvasGridToViewport x:Key="CanvasGridToViewport"/>
<BooleanToVisibilityConverter x:Key="BoolToVis" />
<ContextMenu x:Key="ItemContextMenu">
<MenuItem Header="Delete" Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type controls:PanZoom}},
Expand Down Expand Up @@ -129,7 +130,7 @@
<Grid>
<Grid VerticalAlignment="Top" HorizontalAlignment="Left">
<Grid.Background>
<DrawingBrush TileMode="Tile" Viewport="0,0,2,2"
<DrawingBrush x:Name="Canvas" TileMode="Tile" Viewport="{Binding InputPack.SelectedRegionBrush.Grid, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource CanvasGridToViewport}}"
ViewportUnits="Absolute">
<DrawingBrush.Drawing>
<DrawingGroup>
Expand Down Expand Up @@ -173,7 +174,7 @@
</Border>
</Grid>
<Grid VerticalAlignment="Center" HorizontalAlignment="Center" Visibility="{Binding InputPack.IsEditingTextureHelpAvailable, Converter={StaticResource BoolToVis}}">
<TextBlock TextWrapping="Wrap" Text="Click the 'Add Texture' buton on the left to get started. Once added, double click on a texture to begin placing emulated regions." />
<TextBlock TextWrapping="Wrap" Text="Click the 'Add Texture' buton on the left to get started. Once added, double click on a texture to begin placing emulated regions." />
</Grid>
</Grid>
</UserControl>
8 changes: 4 additions & 4 deletions Data/CanvasGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public double X {
value = 0;
_x = value;

RectRegion.Grid = this;
OnPropertyChanged(nameof(CanvasGrid));
OnPropertyChanged(nameof(X));
}
}
Expand All @@ -50,7 +50,7 @@ public double Y {
value = 0;
_y = value;

RectRegion.Grid = this;
OnPropertyChanged(nameof(CanvasGrid));
OnPropertyChanged(nameof(Y));
}
}
Expand All @@ -72,7 +72,7 @@ public double Width

if (X >= value) X = value - 1;

RectRegion.Grid = this;
OnPropertyChanged(nameof(CanvasGrid));
OnPropertyChanged(nameof(Width));
}
}
Expand All @@ -94,7 +94,7 @@ public double Height

if (Y >= value) Y = value - 1;

RectRegion.Grid = this;
OnPropertyChanged(nameof(CanvasGrid));
OnPropertyChanged(nameof(Height));
}
}
Expand Down
18 changes: 16 additions & 2 deletions Data/RegionBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,31 @@ public bool Subpixel
/// <summary>
/// Canvas grid.
/// </summary>
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
}
}
28 changes: 28 additions & 0 deletions ValueConverters/CanvasGridToViewport.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

0 comments on commit a5036d1

Please sign in to comment.