ImageEditor.axaml 12 KB

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