Skip to content

Commit 2578621

Browse files
committed
allows to change the order of subregions.
1 parent e08fd49 commit 2578621

6 files changed

Lines changed: 60 additions & 6 deletions

File tree

DolphinDynamicInputTexture/Data/InputRegion.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ public ObservableCollection<InputRegion> SubEntries
132132
}
133133
private ObservableCollection<InputRegion> _sub_entries;
134134

135-
136135
public InputRegion OwnedRegion
137136
{
138137
get => _main_region;
@@ -148,15 +147,38 @@ internal set
148147
}
149148
}
150149
OnPropertyChanged(nameof(OwnedRegion));
150+
OnPropertyChanged(nameof(SubIndex));
151151
}
152152
}
153153
private InputRegion _main_region;
154154

155+
public int SubIndex
156+
{
157+
get
158+
{
159+
if (OwnedRegion == null) return -1;
160+
return OwnedRegion.SubEntries.IndexOf(this);
161+
}
162+
set
163+
{
164+
if (value != SubIndex)
165+
{
166+
OwnedRegion.SubEntries.Move(SubIndex, value);
167+
}
168+
OnPropertyChanged(nameof(SubIndex));
169+
}
170+
}
171+
155172
/// <summary>
156173
/// connects all sub regions with this regions.
157174
/// </summary>
158175
private void OnCollectionOfSubEntriesChanged(object sender, NotifyCollectionChangedEventArgs e)
159176
{
177+
if (e.Action == NotifyCollectionChangedAction.Move)
178+
{
179+
SubEntries[e.OldStartingIndex].SubIndex = e.OldStartingIndex;
180+
return;
181+
}
160182

161183
if (e.OldItems != null)
162184
{

MainWindow.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@
199199

200200
<Button Margin="2,0" Width="20" Height="20" Content="{StaticResource Icon.RemoveRegion}" VerticalAlignment="Center" Command="{Binding DeleteSelectedRegionCommand}" ToolTip="Delete Region"/>
201201

202+
<Button Margin="2,0" Width="20" Height="20" Content="{StaticResource Icon.ArrowDown}" VerticalAlignment="Center" Command="{Binding MoveDownSelectedRegionCommand}" ToolTip="Move layer down" Visibility="{Binding SelectedRegionBrush.EditSubRegions, Converter={StaticResource BooleanToVisibilityConverter}}"/>
203+
<Button Margin="2,0" Width="20" Height="20" Content="{StaticResource Icon.ArrowUp}" VerticalAlignment="Center" Command="{Binding MoveUpSelectedRegionCommand}" ToolTip="Move layer up" Visibility="{Binding SelectedRegionBrush.EditSubRegions, Converter={StaticResource BooleanToVisibilityConverter}}"/>
204+
202205
<Border BorderBrush="Gray" BorderThickness="0.3" Margin="2 0"/>
203206

204207
<ToggleButton Margin="2 0" Height="20" IsChecked="{Binding SelectedRegionBrush.UseDarkBackground}" >

Resources/IconGeometry.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
<PathGeometry x:Key="Geometry.RegionOverlay" Figures="M19 13V11H21V13H19M21 9V7H19V9H21M21 3H19V5H21V3M17 15H19V13H17V15M21 17V15H19V17H21M13 17V15H15V13H13V11H15V9H13V7H15V5H13V3H3V21H13V19H15V17H13M15 21H17V19H15V21M17 3H15V5H17V3M17 11H19V9H17V11M15 17H17V15H15V17M17 19H19V17H17V19M21 21V19H19V21H21M15 9H17V7H15V9M15 13H17V11H15V13M17 5V7H19V5H17Z"/>
3535
<PathGeometry x:Key="Geometry.SelectRegion" Figures="M4,3H5V5H3V4A1,1 0 0,1 4,3M20,3A1,1 0 0,1 21,4V5H19V3H20M15,5V3H17V5H15M11,5V3H13V5H11M7,5V3H9V5H7M21,20A1,1 0 0,1 20,21H19V19H21V20M15,21V19H17V21H15M11,21V19H13V21H11M7,21V19H9V21H7M4,21A1,1 0 0,1 3,20V19H5V21H4M3,15H5V17H3V15M21,15V17H19V15H21M3,11H5V13H3V11M21,11V13H19V11H21M3,7H5V9H3V7M21,7V9H19V7H21Z"/>
3636
<PathGeometry x:Key="Geometry.SelectSubRegion" Figures="M9,9H15V15H9M7,17H17V7H7M15,5H17V3H15M15,21H17V19H15M19,17H21V15H19M19,9H21V7H19M19,21A2,2 0 0,0 21,19H19M19,13H21V11H19M11,21H13V19H11M9,3H7V5H9M3,17H5V15H3M5,21V19H3A2,2 0 0,0 5,21M19,3V5H21A2,2 0 0,0 19,3M13,3H11V5H13M3,9H5V7H3M7,21H9V19H7M3,13H5V11H3M3,5H5V3A2,2 0 0,0 3,5Z"/>
37+
<PathGeometry x:Key="Geometry.ArrowUp" Figures="M13,20H11V8L5.5,13.5L4.08,12.08L12,4.16L19.92,12.08L18.5,13.5L13,8V20Z"/>
38+
<PathGeometry x:Key="Geometry.ArrowDown" Figures="M11,4H13V16L18.5,10.5L19.92,11.92L12,19.84L4.08,11.92L5.5,10.5L11,16V4Z"/>
3739
<!--#endregion-->
3840

3941
<!--#region other-->

Resources/Icons.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
<Path x:Key="Icon.NoTag" Fill="Gray" Data="{StaticResource Geometry.NoTag}"/>
5454
<Path x:Key="Icon.SelectRegion" Fill="Gray" Data="{StaticResource Geometry.SelectRegion}"/>
5555
<Path x:Key="Icon.SelectSubRegion" Fill="Gray" Data="{StaticResource Geometry.SelectSubRegion}"/>
56+
<Path x:Key="Icon.ArrowUp" Fill="Gray" Data="{StaticResource Geometry.ArrowUp}"/>
57+
<Path x:Key="Icon.ArrowDown" Fill="Gray" Data="{StaticResource Geometry.ArrowDown}"/>
5658
<!--#endregion-->
5759

5860
<!--#region other-->

Resources/InputRegionRectStyles.xaml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,32 @@
8181
<DataTemplate x:Key="RegionTemplate" DataType="{x:Type data:InputRegion}">
8282
<Grid>
8383
<Grid.RowDefinitions>
84-
<RowDefinition Height="4*" />
85-
<RowDefinition Height="*" />
84+
<RowDefinition Height="1.5*" />
85+
<RowDefinition Height="8*" />
86+
<RowDefinition Height="2*" />
8687
</Grid.RowDefinitions>
8788

8889
<ListBox x:Name="l" ItemsSource="{Binding SubEntries}" Style="{DynamicResource RectRegionListBoxStyle}" ItemContainerStyle="{DynamicResource RectRegionSubItemStyle}" />
8990

90-
<Viewbox Grid.Row="0">
91+
<Viewbox Grid.Row="0" HorizontalAlignment="Left">
92+
<Label Content="{Binding SubIndex, Mode=OneWay}" VerticalAlignment="Top" HorizontalAlignment="Left" Foreground="White" FontWeight="Bold">
93+
<Label.ContentTemplate>
94+
<DataTemplate>
95+
<TextBlock Name="int" Text="{Binding}" Foreground="White" HorizontalAlignment="Center" />
96+
<DataTemplate.Triggers>
97+
<DataTrigger Binding="{Binding}" Value="-1">
98+
<Setter TargetName="int" Property="Visibility" Value="Collapsed" />
99+
</DataTrigger>
100+
</DataTemplate.Triggers>
101+
</DataTemplate>
102+
</Label.ContentTemplate>
103+
<Label.Effect>
104+
<DropShadowEffect ShadowDepth="1" BlurRadius="3" Color="Black" />
105+
</Label.Effect>
106+
</Label>
107+
</Viewbox>
108+
109+
<Viewbox Grid.Row="0" Grid.RowSpan="2">
91110
<StackPanel>
92111
<Label Content="{Binding Device.Name, Mode=OneWay}" VerticalAlignment="Top" HorizontalAlignment="Center" Foreground="White" FontWeight="Bold">
93112
<Label.Effect>
@@ -103,15 +122,15 @@
103122
</StackPanel>
104123
</Viewbox>
105124

106-
<Viewbox Grid.Row="1" VerticalAlignment="Bottom">
125+
<Viewbox Grid.Row="2" VerticalAlignment="Bottom">
107126
<Label Content="{Binding RegionRect}" Foreground="White" Padding="0" ContentTemplate="{StaticResource ResourceKey=RectRegionCoordinates}">
108127
<Label.Effect>
109128
<DropShadowEffect ShadowDepth="1.5" BlurRadius="2" Color="Black" />
110129
</Label.Effect>
111130
</Label>
112131
</Viewbox>
113132

114-
<controls:Resizer Grid.RowSpan="2" x:Name="Resizer" Visibility="Collapsed"
133+
<controls:Resizer Grid.RowSpan="3" x:Name="Resizer" Visibility="Collapsed"
115134
X="{Binding RegionRect.ScaledX}" Y="{Binding RegionRect.ScaledY}"
116135
ItemWidth="{Binding RegionRect.ScaledWidth}" ItemHeight="{Binding RegionRect.ScaledHeight}" />
117136
</Grid>

ViewModels/DynamicInputPackViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ public void AutoSubRegion(InputRegion region)
225225
[JsonIgnore]
226226
public ICommand UpdateSelectedRegionCommand => new RelayCommand(x => SelectedRegionBrush.UpdateRegion(SelectedRegion),x => IsRegionSelected & SelectedRegionBrush.IsValid());
227227

228+
[JsonIgnore]
229+
public ICommand MoveUpSelectedRegionCommand => new RelayCommand(x => SelectedRegion.SubIndex += 1, x => IsRegionSelected && SelectedRegion.OwnedRegion != null && SelectedRegion.SubIndex < SelectedRegion.OwnedRegion.SubEntries.Count - 1);
230+
231+
[JsonIgnore]
232+
public ICommand MoveDownSelectedRegionCommand => new RelayCommand(x => SelectedRegion.SubIndex -= 1, x => IsRegionSelected && SelectedRegion.OwnedRegion != null && SelectedRegion.SubIndex > 0);
233+
228234
public IList<InputRegion> GetRegionList(InputRegion region)
229235
{
230236
if (region.OwnedRegion != null)

0 commit comments

Comments
 (0)