Skip to content

Commit 0285860

Browse files
authored
Merge pull request #45 from Venomalia/V2-B
V2 Part B
2 parents 190082d + 2578621 commit 0285860

18 files changed

Lines changed: 658 additions & 150 deletions

App.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<ResourceDictionary Source="resources\icongeometry.xaml"/>
1010
<ResourceDictionary Source="resources\icons.xaml"/>
1111
<ResourceDictionary Source="resources\buttonstyles.xaml"/>
12+
<ResourceDictionary Source="resources\InputRegionRectStyles.xaml"/>
1213
</ResourceDictionary.MergedDictionaries>
1314
</ResourceDictionary>
1415
</Application.Resources>

Controls/PanZoom.xaml

Lines changed: 47 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<UserControl x:Class="DolphinDynamicInputTextureCreator.Controls.PanZoom"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
34
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:data="clr-namespace:DolphinDynamicInputTexture.Data;assembly=DolphinDynamicInputTexture"
77
xmlns:controls="clr-namespace:DolphinDynamicInputTextureCreator.Controls"
88
xmlns:converters="clr-namespace:DolphinDynamicInputTextureCreator.ValueConverters"
9-
mc:Ignorable="d"
9+
mc:Ignorable="d"
1010
d:DesignHeight="450" d:DesignWidth="800">
1111
<UserControl.Resources>
12-
<converters:ScaleFactorToPercentageValueConverter x:Key="ScaleFactorToPercentageValueConverter"/>
13-
<converters:PathToImageValueConverter x:Key="PathToImageValueConverter"/>
12+
<converters:ScaleFactorToPercentageValueConverter x:Key="ScaleFactorToPercentageValueConverter" />
13+
<converters:PathToImageValueConverter x:Key="PathToImageValueConverter" />
1414
<BooleanToVisibilityConverter x:Key="BoolToVis" />
1515
<converters:ConverterCombinationConverter x:Key="InvertBoolToVis">
1616
<converters:InvertBoolConverter />
@@ -23,117 +23,51 @@
2323
<MenuItem Header="Delete" Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type controls:PanZoom}},
2424
Path=DataContext.InputPack.DeleteRegionCommand}" CommandParameter="{Binding}" Icon="{StaticResource Icon.Delete}" />
2525
</ContextMenu>
26-
<DataTemplate DataType="{x:Type data:InputRegion}">
27-
<Grid>
28-
<Grid.Background>
29-
<SolidColorBrush Color="{Binding RelativeSource={RelativeSource AncestorType={x:Type controls:PanZoom}},
30-
Path=DataContext.InputPack.SelectedRegionBrush.UseDarkBackground, NotifyOnTargetUpdated=True,
31-
Converter={StaticResource BoolToResizerColorBrushConverter}}" Opacity="0.25" />
32-
</Grid.Background>
33-
<Grid.RowDefinitions>
34-
<RowDefinition Height="8*"/>
35-
<RowDefinition Height="*"/>
36-
</Grid.RowDefinitions>
37-
<Path Grid.RowSpan="2" x:Name="Path" StrokeThickness="2" Stroke="Black"
38-
Stretch="Fill">
39-
<Path.Data>
40-
<RectangleGeometry Rect="0,0,10,10"/>
41-
</Path.Data>
42-
</Path>
43-
<Viewbox Grid.Row="0">
44-
<StackPanel>
45-
<Label Content="{Binding Device.Name, Mode=OneWay}" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White" FontWeight="Bold">
46-
<Label.Effect>
47-
<DropShadowEffect ShadowDepth="0" BlurRadius="4" Color="Black"/>
48-
</Label.Effect>
49-
</Label>
50-
<Label Content="{Binding Key.Name, Mode=OneWay}" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White" FontWeight="Bold">
51-
<Label.Effect>
52-
<DropShadowEffect ShadowDepth="0" BlurRadius="4" Color="Black"/>
53-
</Label.Effect>
54-
</Label>
55-
<Label Content="{Binding Tag.Name, Mode=OneWay}" FontSize="8" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Plum" >
56-
<Label.Effect>
57-
<DropShadowEffect ShadowDepth="0" BlurRadius="2" Color="Black"/>
58-
</Label.Effect>
59-
</Label>
60-
</StackPanel>
61-
</Viewbox>
62-
<Viewbox Grid.Row="1" >
63-
<StackPanel Orientation="Horizontal" Margin="1,0">
64-
<Label Content="{Binding RegionRect.X, Mode=OneWay}" ContentStringFormat="0.#" Foreground="White" Padding="0" >
65-
<Label.Effect>
66-
<DropShadowEffect ShadowDepth="0" BlurRadius="2" Color="Black"/>
67-
</Label.Effect>
68-
</Label>
69-
<Label Content="{Binding RegionRect.Y, Mode=OneWay}" ContentStringFormat="0.#" Foreground="White" Padding="6,0" >
70-
<Label.Effect>
71-
<DropShadowEffect ShadowDepth="0" BlurRadius="2" Color="Black"/>
72-
</Label.Effect>
73-
</Label>
74-
<Label Content="{Binding RegionRect.Width, Mode=OneWay}" ContentStringFormat="0.#" Foreground="White" Padding="0">
75-
<Label.Effect>
76-
<DropShadowEffect ShadowDepth="0" BlurRadius="2" Color="Black"/>
77-
</Label.Effect>
78-
</Label>
79-
<Label Content="x" Foreground="White" Padding="1,0">
80-
<Label.Effect>
81-
<DropShadowEffect ShadowDepth="0" BlurRadius="2" Color="Black"/>
82-
</Label.Effect>
83-
</Label>
84-
<Label Content="{Binding RegionRect.Height, Mode=OneWay}" ContentStringFormat="0.#" Foreground="White" Padding="0">
85-
<Label.Effect>
86-
<DropShadowEffect ShadowDepth="0" BlurRadius="2" Color="Black"/>
87-
</Label.Effect>
88-
</Label>
89-
</StackPanel>
90-
</Viewbox>
91-
<controls:Resizer Grid.RowSpan="2" Visibility="Collapsed"
92-
X="{Binding RegionRect.ScaledX}" Y="{Binding RegionRect.ScaledY}"
93-
ItemWidth="{Binding RegionRect.ScaledWidth}"
94-
ItemHeight="{Binding RegionRect.ScaledHeight}"
95-
x:Name="Resizer"/>
96-
</Grid>
97-
<DataTemplate.Triggers>
98-
<DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ListBoxItem}}" Value="True">
99-
<Setter TargetName="Resizer" Property="Visibility" Value="Visible"/>
100-
</DataTrigger>
101-
</DataTemplate.Triggers>
102-
</DataTemplate>
26+
<ContextMenu x:Key="ItemSubContextMenu">
27+
<MenuItem Header="Auto SubRegions" Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type controls:PanZoom}},
28+
Path=DataContext.InputPack.AutoSubRegionCommand}" CommandParameter="{Binding}" Icon="" />
29+
</ContextMenu>
10330

104-
<Style TargetType="ListBox" x:Key="RectRegionListBoxStyle">
105-
<Setter Property="ItemContainerStyle" Value="{DynamicResource RectRegionItemStyle}"/>
106-
<Setter Property="ItemsPanel">
107-
<Setter.Value>
108-
<ItemsPanelTemplate>
109-
<Canvas HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
110-
</ItemsPanelTemplate>
111-
</Setter.Value>
112-
</Setter>
113-
<Setter Property="Template">
114-
<Setter.Value>
115-
<ControlTemplate>
116-
<ItemsPresenter/>
117-
</ControlTemplate>
118-
</Setter.Value>
119-
</Setter>
120-
</Style>
121-
12231
<Style TargetType="ListBoxItem" x:Key="RectRegionItemStyle">
12332
<Setter Property="ContextMenu" Value="{StaticResource ItemContextMenu}" />
124-
<Setter Property="Canvas.Left" Value="{Binding RegionRect.ScaledX}"/>
125-
<Setter Property="Canvas.Top" Value="{Binding RegionRect.ScaledY}"/>
126-
<Setter Property="Height" Value="{Binding RegionRect.ScaledHeight}"/>
127-
<Setter Property="Width" Value="{Binding RegionRect.ScaledWidth}"/>
33+
<Setter Property="Canvas.Left" Value="{Binding RegionRect.ScaledX}" />
34+
<Setter Property="Canvas.Top" Value="{Binding RegionRect.ScaledY}" />
35+
<Setter Property="Height" Value="{Binding RegionRect.ScaledHeight}" />
36+
<Setter Property="Width" Value="{Binding RegionRect.ScaledWidth}" />
37+
<Setter Property="ContentTemplate" Value="{StaticResource RegionTemplate}"/>
12838
<Setter Property="Template">
12939
<Setter.Value>
13040
<ControlTemplate TargetType="ListBoxItem">
131-
<ContentPresenter ContentSource="Content"/>
41+
<Grid MouseDown="GridRegion_MouseDown">
42+
<Grid.Background>
43+
<SolidColorBrush Color="{Binding RelativeSource={RelativeSource AncestorType={x:Type controls:PanZoom}},
44+
Path=DataContext.InputPack.SelectedRegionBrush.UseDarkBackground, NotifyOnTargetUpdated=True, Converter={StaticResource BoolToResizerColorBrushConverter}}" Opacity="0.25" />
45+
</Grid.Background>
46+
<Border BorderBrush="Black" BorderThickness="2"/>
47+
<ContentPresenter ContentSource="Content" />
48+
</Grid>
13249
</ControlTemplate>
13350
</Setter.Value>
13451
</Setter>
13552
</Style>
13653

54+
<Style TargetType="ListBoxItem" x:Key="MainRectRegionItemStyle" BasedOn="{StaticResource RectRegionItemStyle}">
55+
<Style.Triggers>
56+
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type controls:PanZoom}}, Path=DataContext.InputPack.SelectedRegionBrush.EditSubRegions, NotifyOnTargetUpdated=True}" Value="true">
57+
<DataTrigger.Setters>
58+
<Setter Property="ContentTemplate">
59+
<Setter.Value>
60+
<DataTemplate DataType="{x:Type data:InputRegion}">
61+
<ListBox ItemsSource="{Binding SubEntries}" SelectedValue="{Binding RegionRect.Pack.SelectedRegion, NotifyOnTargetUpdated=True}" Style="{StaticResource RectRegionListBoxStyle}" />
62+
</DataTemplate>
63+
</Setter.Value>
64+
</Setter>
65+
<Setter Property="ContextMenu" Value="{StaticResource ItemSubContextMenu}"/>
66+
</DataTrigger.Setters>
67+
</DataTrigger>
68+
</Style.Triggers>
69+
</Style>
70+
13771
</UserControl.Resources>
13872
<Grid>
13973
<Grid Visibility="{Binding InputPack.Textures.ValidSelection, Converter={StaticResource BoolToVis}}">
@@ -144,28 +78,27 @@ Converter={StaticResource BoolToResizerColorBrushConverter}}" Opacity="0.25" />
14478
<Grid VerticalAlignment="Center" HorizontalAlignment="Center">
14579
<Grid>
14680
<Grid.Background>
147-
<DrawingBrush TileMode="Tile" Viewport="0,0,2,2"
81+
<DrawingBrush TileMode="Tile" Viewport="0,0,2,2"
14882
ViewportUnits="Absolute">
14983
<DrawingBrush.Drawing>
15084
<DrawingGroup>
151-
<GeometryDrawing Brush="{Binding InputPack.SelectedRegionBrush.UseDarkBackground, Converter={StaticResource BoolToMainColorBrushConverter}}" Geometry="M0,0 L0,0 0,10 10,10 10,0 Z"/>
152-
<GeometryDrawing Brush="{Binding InputPack.SelectedRegionBrush.UseDarkBackground, Converter={StaticResource BoolToSecondaryColorBrushConverter}}" Geometry="M0,0 L0,0 0,5, 10,5 10,10 5,10 5,0 Z"/>
85+
<GeometryDrawing Brush="{Binding InputPack.SelectedRegionBrush.UseDarkBackground, Converter={StaticResource BoolToMainColorBrushConverter}}" Geometry="M0,0 L0,0 0,10 10,10 10,0 Z" />
86+
<GeometryDrawing Brush="{Binding InputPack.SelectedRegionBrush.UseDarkBackground, Converter={StaticResource BoolToSecondaryColorBrushConverter}}" Geometry="M0,0 L0,0 0,5, 10,5 10,10 5,10 5,0 Z" />
15387
</DrawingGroup>
15488
</DrawingBrush.Drawing>
15589
</DrawingBrush>
15690
</Grid.Background>
15791
<Grid.LayoutTransform>
15892
<TransformGroup>
159-
<ScaleTransform ScaleX="{Binding InputPack.ScaleFactor}" ScaleY="{Binding InputPack.ScaleFactor}"/>
93+
<ScaleTransform ScaleX="{Binding InputPack.ScaleFactor}" ScaleY="{Binding InputPack.ScaleFactor}" />
16094
</TransformGroup>
16195
</Grid.LayoutTransform>
16296
<Image Source="{Binding InputPack.Textures.Selected.TexturePath, Converter={StaticResource PathToImageValueConverter}}" Width="{Binding InputPack.Textures.Selected.ImageWidth}" Height="{Binding InputPack.Textures.Selected.ImageHeight}" Stretch="Fill" x:Name="Img" RenderOptions.BitmapScalingMode="NearestNeighbor"
16397
VerticalAlignment="Top" HorizontalAlignment="Left" UseLayoutRounding="True" SnapsToDevicePixels="True">
16498
</Image>
16599
</Grid>
166100

167-
<ListBox x:Name="lb" ItemsSource="{Binding InputPack.Textures.Selected.Regions}" SelectedItem="{Binding InputPack.SelectedRegion, NotifyOnTargetUpdated=True}" Style="{StaticResource RectRegionListBoxStyle}"/>
168-
101+
<ListBox x:Name="lb" ItemsSource="{Binding InputPack.Textures.Selected.Regions}" SelectedValue="{Binding InputPack.SelectedRegion, NotifyOnTargetUpdated=True}" Style="{StaticResource RectRegionListBoxStyle}" ItemContainerStyle="{DynamicResource MainRectRegionItemStyle}"/>
169102
</Grid>
170103
</Grid>
171104
</ScrollViewer>
@@ -184,10 +117,10 @@ Converter={StaticResource BoolToResizerColorBrushConverter}}" Opacity="0.25" />
184117
</Border>
185118
</Grid>
186119
<Grid VerticalAlignment="Center" HorizontalAlignment="Center" Visibility="{Binding InputPack.Textures.ValidSelection, Converter={StaticResource InvertBoolToVis}}">
187-
<TextBlock FontSize="24" TextWrapping="Wrap" TextAlignment="Center" LineHeight="50" >
188-
Click the <Bold>'Add Texture(s)'</Bold> buton on the left to get started. <LineBreak/>
120+
<TextBlock FontSize="24" TextWrapping="Wrap" TextAlignment="Center" LineHeight="50">
121+
Click the <Bold>'Add Texture(s)'</Bold> buton on the left to get started. <LineBreak />
189122
Once added, <Italic>double click</Italic> on a texture to begin placing emulated regions.
190123
</TextBlock>
191124
</Grid>
192125
</Grid>
193-
</UserControl>
126+
</UserControl>

Controls/PanZoom.xaml.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,23 @@ private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
3232
ViewModel.StartPanning(e.GetPosition(Img));
3333
}
3434

35-
if (e.LeftButton == MouseButtonState.Pressed)
35+
if (!ViewModel.InputPack.SelectedRegionBrush.EditSubRegions)
36+
{
37+
if (e.LeftButton == MouseButtonState.Pressed)
38+
{
39+
ViewModel.StartCreatingRegion(e.GetPosition(Img));
40+
}
41+
}
42+
}
43+
44+
private void GridRegion_MouseDown(object sender, MouseButtonEventArgs e)
45+
{
46+
if (ViewModel.InputPack.SelectedRegionBrush.EditSubRegions)
3647
{
37-
ViewModel.StartCreatingRegion(e.GetPosition(Img));
48+
if (e.LeftButton == MouseButtonState.Pressed)
49+
{
50+
ViewModel.StartCreatingSubRegion(e.GetPosition(Img));
51+
}
3852
}
3953
}
4054

DolphinDynamicInputTexture/Data/DynamicInputPack.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,9 @@ private InputRegion ReadV2InputRegion(JsonReader reader, EmulatedDevice emulated
606606
case "sub_entries":
607607
while (reader.Read() && reader.TokenType != JsonToken.EndArray)
608608
{
609-
Region.SubEntries.Add(ReadV2InputRegion(reader, emulatedDevice, texture));
609+
InputRegion subentry = ReadV2InputRegion(reader, emulatedDevice, texture);
610+
subentry.RegionRect = new InputSubRegionRect(subentry.RegionRect);
611+
Region.SubEntries.Add(subentry);
610612
}
611613
break;
612614
}

DolphinDynamicInputTexture/Data/DynamicInputTexture.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,8 @@ public ObservableCollection<InputRegion> Regions
9595
{
9696
foreach (InputRegion Region in value)
9797
{
98+
Region.OwnedRegion = null;
9899
Region.RegionRect.OwnedTexture = this;
99-
foreach (InputRegion SubEntrie in Region.SubEntries)
100-
{
101-
SubEntrie.RegionRect.OwnedTexture = this;
102-
}
103100
}
104101
}
105102
_regions = value;
@@ -118,10 +115,11 @@ private void OnCollectionOfRegionsChanged(object sender, NotifyCollectionChanged
118115
{
119116
foreach (InputRegion Region in e.NewItems)
120117
{
118+
Region.OwnedRegion = null;
121119
Region.RegionRect.OwnedTexture = this;
122-
foreach (InputRegion SubEntrie in Region.SubEntries)
120+
foreach (InputRegion subentry in Region.SubEntries)
123121
{
124-
SubEntrie.RegionRect.OwnedTexture = this;
122+
subentry.RegionRect.OwnedTexture = this;
125123
}
126124
}
127125
}

0 commit comments

Comments
 (0)