ImageEditor.axaml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <UserControl xmlns="https://github.com/avaloniaui"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  4. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  5. xmlns:components="using:InABox.Avalonia.Components"
  6. xmlns:converters="using:InABox.Avalonia.Converters"
  7. xmlns:system="using:System"
  8. mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
  9. x:Class="InABox.Avalonia.Components.ImageEditor">
  10. <UserControl.Styles>
  11. <Style Selector="Button">
  12. <Setter Property="Background"
  13. Value="Transparent"/>
  14. <Setter Property="ClipToBounds"
  15. Value="False"/>
  16. </Style>
  17. <Style Selector="Button:flyout-open /template/ ContentPresenter">
  18. <Setter Property="BoxShadow"
  19. Value="0 0 10 DarkGray"/>
  20. </Style>
  21. <Style Selector="Button.active /template/ ContentPresenter">
  22. <Setter Property="BoxShadow"
  23. Value="0 0 10 DarkGray"/>
  24. </Style>
  25. <Style Selector="Button:disabled">
  26. <Setter Property="Foreground"
  27. Value="#909090"/>
  28. </Style>
  29. <Style Selector="Button:disabled /template/ ContentPresenter">
  30. <Setter Property="Background"
  31. Value="Transparent"/>
  32. </Style>
  33. <Style Selector="Button:pointerover /template/ ContentPresenter#PART_ContentPresenter">
  34. <Setter Property="BorderBrush" Value="{Binding $parent[Button].BorderBrush}" />
  35. <Setter Property="BorderThickness" Value="{Binding $parent[Button].BorderThickness}" />
  36. <Setter Property="Background" Value="{Binding $parent[Button].Background}" />
  37. <Setter Property="Foreground" Value="{Binding $parent[Button].Foreground}" />
  38. </Style>
  39. <Style Selector="FlyoutPresenter">
  40. <Setter Property="Padding" Value="5"/>
  41. <Setter Property="Background" Value="Transparent"/>
  42. <Setter Property="BorderThickness" Value="0"/>
  43. <Setter Property="CornerRadius" Value="0"/>
  44. <Setter Property="ClipToBounds" Value="False"/>
  45. </Style>
  46. <Style Selector="FlyoutPresenter > Border">
  47. <Setter Property="Padding" Value="{StaticResource PrsControlSpacing}"/>
  48. <Setter Property="BorderBrush" Value="Black"/>
  49. <Setter Property="BorderThickness" Value="0"/>
  50. <Setter Property="Background" Value="White"/>
  51. <Setter Property="BoxShadow" Value="0 0 10 Gray"/>
  52. </Style>
  53. <Style Selector="Rectangle.Separator">
  54. <Setter Property="Fill" Value="Gray"/>
  55. <Setter Property="Width" Value="1"/>
  56. <Setter Property="VerticalAlignment" Value="Stretch"/>
  57. <Setter Property="Margin" Value="0,10"/>
  58. </Style>
  59. </UserControl.Styles>
  60. <UserControl.Resources>
  61. <converters:DoubleCalculator x:Key="Add1Calculator" Constants="1.0" Type="Sum"/>
  62. </UserControl.Resources>
  63. <Border CornerRadius="{Binding $parent[components:ImageEditor].CornerRadius}" ClipToBounds="True">
  64. <Grid>
  65. <Grid.RowDefinitions>
  66. <RowDefinition Height="Auto"/>
  67. <RowDefinition Height="*"/>
  68. <RowDefinition Height="Auto"/>
  69. </Grid.RowDefinitions>
  70. <Canvas Name="OuterCanvas" Grid.Row="1" Background="White">
  71. <Canvas.Styles>
  72. <Style Selector="Thumb">
  73. <Setter Property="Template">
  74. <ControlTemplate>
  75. <Border Background="LightGray"
  76. BorderBrush="Black"
  77. BorderThickness="1"/>
  78. </ControlTemplate>
  79. </Setter>
  80. </Style>
  81. </Canvas.Styles>
  82. <Border Name="ImageBorder" Background="White"
  83. BoxShadow="0 0 10 Gray">
  84. <Grid>
  85. <Image Name="Image" Source="{Binding $parent[components:ImageEditor].Source}"/>
  86. <Canvas Name="Canvas"
  87. Background="Transparent"
  88. PointerPressed="Canvas_PointerPressed"
  89. PointerMoved="Canvas_PointerMoved"
  90. PointerReleased="Canvas_PointerReleased"
  91. ClipToBounds="True"/>
  92. </Grid>
  93. </Border>
  94. </Canvas>
  95. <Border Grid.Row="0"
  96. BoxShadow="0 0 10 Gray"
  97. IsVisible="{Binding $parent[components:ImageEditor].ShowButtons}">
  98. <Border ClipToBounds="True"
  99. Background="White">
  100. <Grid>
  101. <Grid.ColumnDefinitions>
  102. <ColumnDefinition Width="*"/>
  103. <ColumnDefinition Width="Auto"/>
  104. <ColumnDefinition Width="*"/>
  105. </Grid.ColumnDefinitions>
  106. <ItemsControl Grid.Column="1" ItemsSource="{Binding $parent[components:ImageEditor].ModeButtons}">
  107. <ItemsControl.ItemTemplate>
  108. <DataTemplate DataType="components:ImageEditorModeButton">
  109. <Button Classes.active="{Binding Active}"
  110. Width="40" Height="40" Margin="10"
  111. CommandParameter="{Binding Mode}"
  112. Command="{Binding $parent[components:ImageEditor].SetModeCommand}"
  113. Content="{Binding Content}"/>
  114. </DataTemplate>
  115. </ItemsControl.ItemTemplate>
  116. <ItemsControl.ItemsPanel>
  117. <ItemsPanelTemplate>
  118. <UniformGrid Margin="-10" Rows="1"/>
  119. </ItemsPanelTemplate>
  120. </ItemsControl.ItemsPanel>
  121. </ItemsControl>
  122. </Grid>
  123. </Border>
  124. </Border>
  125. <Border Grid.Row="2"
  126. BoxShadow="0 0 10 Gray"
  127. IsVisible="{Binding $parent[components:ImageEditor].ShowButtons}">
  128. <Border ClipToBounds="True"
  129. Background="White">
  130. <Grid>
  131. <Grid.ColumnDefinitions>
  132. <ColumnDefinition Width="*"/>
  133. <ColumnDefinition Width="Auto"/>
  134. <ColumnDefinition Width="*"/>
  135. </Grid.ColumnDefinitions>
  136. <StackPanel Grid.Column="1" Margin="-10"
  137. Orientation="Horizontal">
  138. <Button Name="LineThicknessButton" Width="40" Height="40"
  139. Margin="10">
  140. <Canvas Width="25" Height="21"
  141. HorizontalAlignment="Center" VerticalAlignment="Center">
  142. <Line StrokeThickness="0.5"
  143. Stroke="Black"
  144. StartPoint="0,0"
  145. EndPoint="25,0"/>
  146. <Line StrokeThickness="1"
  147. Stroke="Black"
  148. StartPoint="0,3"
  149. EndPoint="25,3"/>
  150. <Line StrokeThickness="2"
  151. Stroke="Black"
  152. StartPoint="0,7"
  153. EndPoint="25,7"/>
  154. <Line StrokeThickness="3"
  155. Stroke="Black"
  156. StartPoint="0,12.5"
  157. EndPoint="25,12.5"/>
  158. <Line StrokeThickness="5"
  159. Stroke="Black"
  160. StartPoint="0,19.5"
  161. EndPoint="25,19.5"/>
  162. </Canvas>
  163. <Button.Flyout>
  164. <Flyout Placement="Top" VerticalOffset="0">
  165. <Border>
  166. <Grid>
  167. <Grid.RowDefinitions>
  168. <RowDefinition Height="20"/>
  169. <RowDefinition Height="Auto"/>
  170. </Grid.RowDefinitions>
  171. <Line Grid.Row="0"
  172. Margin="20"
  173. StartPoint="0,0"
  174. EndPoint="150,0"
  175. StrokeLineCap="Round"
  176. Stroke="Black">
  177. <Line.StrokeThickness>
  178. <MultiBinding Converter="{StaticResource Add1Calculator}">
  179. <Binding Path="$parent[components:ImageEditor].LineThickness"/>
  180. </MultiBinding>
  181. </Line.StrokeThickness>
  182. </Line>
  183. <Line Grid.Row="0"
  184. Margin="20"
  185. StartPoint="0,0"
  186. EndPoint="150,0"
  187. StrokeThickness="{Binding $parent[components:ImageEditor].LineThickness}"
  188. StrokeLineCap="Round"
  189. Stroke="{Binding $parent[components:ImageEditor].PrimaryBrush}"/>
  190. <Slider Value="{Binding $parent[components:ImageEditor].LineThickness}"
  191. Grid.Row="1"
  192. Minimum="1.0"
  193. Maximum="30.0"
  194. Width="150"/>
  195. </Grid>
  196. </Border>
  197. </Flyout>
  198. </Button.Flyout>
  199. </Button>
  200. <Button Name="PrimaryColour" Width="40" Height="40"
  201. Margin="10">
  202. <Ellipse Width="25" Height="25"
  203. Margin="10"
  204. HorizontalAlignment="Center" VerticalAlignment="Center"
  205. Fill="{Binding $parent[components:ImageEditor].PrimaryBrush,Converter={x:Static components:ImageEditorTransparentImageBrushConverter.Instance}}"
  206. Stroke="Black" StrokeThickness="1"/>
  207. <Button.Flyout>
  208. <Flyout Placement="Top" VerticalOffset="0">
  209. <Border>
  210. <ColorView Color="{Binding $parent[components:ImageEditor].PrimaryBrush,Converter={x:Static converters:BrushToColorConverter.Instance}}"/>
  211. </Border>
  212. </Flyout>
  213. </Button.Flyout>
  214. </Button>
  215. <Button Name="SecondaryColour" Width="40" Height="40"
  216. Margin="10">
  217. <Ellipse Width="25" Height="25"
  218. Margin="10"
  219. HorizontalAlignment="Center" VerticalAlignment="Center"
  220. Fill="{Binding $parent[components:ImageEditor].SecondaryBrush,Converter={x:Static components:ImageEditorTransparentImageBrushConverter.Instance}}"
  221. Stroke="Black" StrokeThickness="1"/>
  222. <Button.Flyout>
  223. <Flyout Placement="Top" VerticalOffset="0">
  224. <Border>
  225. <ColorView Color="{Binding $parent[components:ImageEditor].SecondaryBrush,Converter={x:Static converters:BrushToColorConverter.Instance}}"/>
  226. </Border>
  227. </Flyout>
  228. </Button.Flyout>
  229. </Button>
  230. <Rectangle Classes="Separator"/>
  231. <Button Name="UndoButton" Width="40" Height="40"
  232. Margin="10"
  233. Command="{Binding $parent[components:ImageEditor].UndoCommand}"
  234. IsEnabled="False">
  235. <Canvas Width="25" Height="25">
  236. <Path Stroke="{Binding $parent[Button].Foreground}" StrokeThickness="2">
  237. <Path.Data>
  238. <PathGeometry>
  239. <PathFigure StartPoint="4,9" IsClosed="False">
  240. <LineSegment Point="10,3"/>
  241. <ArcSegment Point="18,17" Size="8,8"/>
  242. <LineSegment Point="11,24"/>
  243. </PathFigure>
  244. </PathGeometry>
  245. </Path.Data>
  246. </Path>
  247. <Line StartPoint="4,10" EndPoint="13,10"
  248. Stroke="{Binding $parent[Button].Foreground}" StrokeThickness="2"
  249. StrokeLineCap="Round"/>
  250. <Line StartPoint="3,10" EndPoint="3,1"
  251. Stroke="{Binding $parent[Button].Foreground}" StrokeThickness="2"
  252. StrokeLineCap="Round"/>
  253. </Canvas>
  254. </Button>
  255. <Button Name="RedoButton" Width="40" Height="40"
  256. Margin="10"
  257. Command="{Binding $parent[components:ImageEditor].RedoCommand}"
  258. IsEnabled="False">
  259. <Canvas Width="25" Height="25">
  260. <Path Stroke="{Binding $parent[Button].Foreground}" StrokeThickness="2">
  261. <Path.Data>
  262. <PathGeometry>
  263. <PathFigure StartPoint="21,9" IsClosed="False">
  264. <LineSegment Point="15,3"/>
  265. <ArcSegment Point="7,17" Size="8,8" SweepDirection="CounterClockwise"/>
  266. <LineSegment Point="14,24"/>
  267. </PathFigure>
  268. </PathGeometry>
  269. </Path.Data>
  270. </Path>
  271. <Line StartPoint="21,10" EndPoint="12,10"
  272. Stroke="{Binding $parent[Button].Foreground}" StrokeThickness="2"
  273. StrokeLineCap="Round"/>
  274. <Line StartPoint="22,10" EndPoint="22,1"
  275. Stroke="{Binding $parent[Button].Foreground}" StrokeThickness="2"
  276. StrokeLineCap="Round"/>
  277. </Canvas>
  278. </Button>
  279. </StackPanel>
  280. </Grid>
  281. </Border>
  282. </Border>
  283. </Grid>
  284. </Border>
  285. </UserControl>