ImageEditor.axaml 12 KB

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