ImageEditor.axaml 11 KB

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