ImageEditor.axaml 12 KB

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