-
Notifications
You must be signed in to change notification settings - Fork 9
/
MainWindow.xaml
170 lines (170 loc) · 11.8 KB
/
MainWindow.xaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<Window x:Class="YoloMarkNet.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:YoloMarkNet"
mc:Ignorable="d"
Title="MainWindow" Height="600" Width="800">
<Window.DataContext>
<local:MainWindowViewModel />
</Window.DataContext>
<Grid x:Name="grid">
<Grid.Resources>
<local:DataContextProxy DataContext="{Binding}" x:Key="Proxy" />
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="85" />
<RowDefinition />
<RowDefinition Height="35" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border Grid.Row="0" Grid.ColumnSpan="2" BorderBrush="Black" BorderThickness="0,0,0,1">
<ScrollViewer VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding Images}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border>
<Border.Style>
<Style TargetType="Border">
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="BorderThickness" Value="1" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsSelected}" Value="True">
<Setter Property="BorderBrush" Value="Yellow" />
<Setter Property="BorderThickness" Value="2" />
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<Button Command="{Binding DataContext.SelectImageCommand,ElementName=grid}" CommandParameter="{Binding}">
<Image Source="{Binding Thumb}" Width="75" Height="75" Stretch="Uniform" StretchDirection="DownOnly" />
</Button>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Border>
<Border Grid.Row="1" Grid.Column="0" Grid.RowSpan="2" BorderBrush="Black" BorderThickness="0,0,0,1">
<ListBox ItemsSource="{Binding Classes}" SelectedItem="{Binding SelectedClass}">
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel>
<Border Margin="0,0,3,0" BorderBrush="Black" BorderThickness="1" Height="16" Width="16" Background="{Binding Color}" />
<TextBlock Text="{Binding ClassDescriptor}" VerticalAlignment="Center" />
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Border>
<Border Grid.Row="1" Grid.Column="1" BorderBrush="Black" BorderThickness="1,0,0,1" Background="Gray">
<Viewbox Stretch="Uniform" Cursor="Cross">
<Canvas Width="{Binding SelectedImageSource.Width}" Height="{Binding SelectedImageSource.Height}"
MouseMove="Control_MouseMove"
MouseLeftButtonDown="Control_MouseLeftButtonDown"
MouseLeftButtonUp="Control_MouseLeftButtonUp"
MouseLeave="Control_MouseLeave"
>
<ItemsControl ItemsSource="{Binding BoundingBoxes}">
<ItemsControl.Resources>
<Style TargetType="local:ResizeThumb">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border BorderBrush="Black" BorderThickness="1" Background="{Binding DataContext.Class.Color, RelativeSource={RelativeSource AncestorType=Border}}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ItemsControl.Resources>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border>
<Grid Tag="{Binding}">
<Grid.ContextMenu>
<ContextMenu DataContext="">
<MenuItem Command="{Binding DataContext.DeleteBoundingBoxCommand, Source={StaticResource Proxy}}"
CommandParameter="{Binding PlacementTarget.Tag, RelativeSource={RelativeSource AncestorType=ContextMenu}}">
<MenuItem.Header>
<TextBlock>
Delete <Run Text="{Binding PlacementTarget.Tag.Class.ClassDescriptor, RelativeSource={RelativeSource AncestorType=ContextMenu}, Mode=OneWay}" />
</TextBlock>
</MenuItem.Header>
</MenuItem>
</ContextMenu>
</Grid.ContextMenu>
<local:BoundingThumb IsHitTestVisible="True" Background="Transparent" Cursor="SizeAll"
DataContext="{Binding RelativeSource={RelativeSource AncestorType=ContentPresenter}}">
<local:BoundingThumb.Template>
<ControlTemplate>
<Rectangle Fill="{Binding DataContext.Class.Color, RelativeSource={RelativeSource AncestorType=Border}}" Opacity="0.3" />
</ControlTemplate>
</local:BoundingThumb.Template>
</local:BoundingThumb>
<local:ResizeThumb DataContext="{Binding RelativeSource={RelativeSource AncestorType=ContentPresenter}}" Height="3" Cursor="SizeNS" Margin="0 -4 0 0" VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
<local:ResizeThumb DataContext="{Binding RelativeSource={RelativeSource AncestorType=ContentPresenter}}" Width="3" Cursor="SizeWE" Margin="-4 0 0 0" VerticalAlignment="Stretch" HorizontalAlignment="Left"/>
<local:ResizeThumb DataContext="{Binding RelativeSource={RelativeSource AncestorType=ContentPresenter}}" Width="3" Cursor="SizeWE" Margin="0 0 -4 0" VerticalAlignment="Stretch" HorizontalAlignment="Right"/>
<local:ResizeThumb DataContext="{Binding RelativeSource={RelativeSource AncestorType=ContentPresenter}}" Height="3" Cursor="SizeNS" Margin="0 0 0 -4" VerticalAlignment="Bottom" HorizontalAlignment="Stretch"/>
<local:ResizeThumb DataContext="{Binding RelativeSource={RelativeSource AncestorType=ContentPresenter}}" Width="7" Height="7" Cursor="SizeNWSE" Margin="-6 -6 0 0" VerticalAlignment="Top" HorizontalAlignment="Left"/>
<local:ResizeThumb DataContext="{Binding RelativeSource={RelativeSource AncestorType=ContentPresenter}}" Width="7" Height="7" Cursor="SizeNESW" Margin="0 -6 -6 0" VerticalAlignment="Top" HorizontalAlignment="Right"/>
<local:ResizeThumb DataContext="{Binding RelativeSource={RelativeSource AncestorType=ContentPresenter}}" Width="7" Height="7" Cursor="SizeNESW" Margin="-6 0 0 -6" VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
<local:ResizeThumb DataContext="{Binding RelativeSource={RelativeSource AncestorType=ContentPresenter}}" Width="7" Height="7" Cursor="SizeNWSE" Margin="0 0 -6 -6" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
</Grid>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left" Value="{Binding X, Mode=TwoWay}" />
<Setter Property="Canvas.Top" Value="{Binding Y, Mode=TwoWay}" />
<Setter Property="Height" Value="{Binding Height, Mode=TwoWay}" />
<Setter Property="Width" Value="{Binding Width, Mode=TwoWay}" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
<Image Panel.ZIndex="-1" Name="img" Source="{Binding SelectedImageSource}" />
<Rectangle IsHitTestVisible="False" Fill="Yellow" Opacity="0.5" Canvas.Left="{Binding Ghost.X}" Canvas.Top="{Binding Ghost.Y}" Width="{Binding Ghost.Width}" Height="{Binding Ghost.Height}">
<Rectangle.Style>
<Style TargetType="Rectangle">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsMouseDown}" Value="True">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</Rectangle.Style>
</Rectangle>
</Canvas>
</Viewbox>
</Border>
<Border Grid.Row="2" Grid.Column="1">
<Button HorizontalAlignment="Right" Margin="5" Padding="10,0" Background="PaleGreen" Command="{Binding SaveCommand}">
<Button.Style>
<Style TargetType="Button">
<Setter Property="Content" Value="Next Image" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsLastImage}" Value="True">
<Setter Property="Content" Value="Save & Close" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</Border>
</Grid>
</Window>