Browse Source

Changed preview window and rounded more stuff

flabbet 4 năm trước cách đây
mục cha
commit
e8e047504a

+ 1 - 0
PixiEditor/App.xaml

@@ -15,6 +15,7 @@
                 <ResourceDictionary Source="Styles/DarkScrollBarStyle.xaml" />
                 <ResourceDictionary Source="Styles/ImageCheckBoxStyle.xaml" />
                 <ResourceDictionary Source="Styles/DarkCheckboxStyle.xaml" />
+                <ResourceDictionary Source="Styles/ListSwitchButtonStyle.xaml" />
                 <ResourceDictionary Source="Styles/LabelStyles.xaml" />
                 <ResourceDictionary Source="Styles/AvalonDock/DarkBrushes.xaml" />
                 <ResourceDictionary Source="Styles/AvalonDock/Themes/Menu/DarkBrushes.xaml" />

+ 48 - 0
PixiEditor/Helpers/Converters/FormattedColorConverter.cs

@@ -0,0 +1,48 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Data;
+using System.Windows.Markup;
+using System.Windows.Media;
+
+namespace PixiEditor.Helpers.Converters
+{
+    public class FormattedColorConverter : MarkupExtension, IMultiValueConverter
+    {
+        private static FormattedColorConverter converter;
+        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
+        {
+            if(values != null && values.Length > 1 && values[0] is Color color && values[1] is string format)
+            {
+                switch (format.ToLower())
+                {
+                    case "hex":
+                        return color.ToString();
+                    case "rgba":
+                        return $"({color.R}, {color.G}, {color.B}, {color.A})";
+                    default:
+                        break;
+                }
+            }
+
+            return "";
+        }
+
+        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
+        {
+            throw new NotImplementedException();
+        }
+
+        public override object ProvideValue(IServiceProvider serviceProvider)
+        {
+            if(converter == null)
+            {
+                converter = new FormattedColorConverter();
+            }
+            return converter;
+        }
+    }
+}

+ 28 - 0
PixiEditor/Styles/ListSwitchButtonStyle.xaml

@@ -0,0 +1,28 @@
+<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+                    xmlns:local="clr-namespace:PixiEditor.Views.UserControls">
+
+    <Style TargetType="{x:Type local:ListSwitchButton}" BasedOn="{StaticResource ResourceKey={x:Type Button}}" x:Name="btn">
+        <Setter Property="BorderBrush" Value="Black"/>
+        <Setter Property="BorderThickness" Value="1"/>
+        <Setter Property="FontSize" Value="12"/>
+        <Setter Property="Cursor" Value="Hand"/>
+        <Setter Property="Padding" Value="2, 0"/>
+        <Setter Property="Foreground" Value="White"/>
+        <Setter Property="Template">
+            <Setter.Value>
+                <ControlTemplate TargetType="{x:Type local:ListSwitchButton}">
+                    <Border
+                            CornerRadius="1"
+                        BorderBrush="{TemplateBinding BorderBrush}"
+                            Background="{Binding Path=ActiveItem.Background, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:ListSwitchButton}}}"
+                        BorderThickness="{TemplateBinding BorderThickness}">
+                        <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding Path=ActiveItem.Content, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:ListSwitchButton}}}"
+                                   FontSize="{TemplateBinding FontSize}" Padding="{TemplateBinding Padding}"/>
+                    </Border>
+                </ControlTemplate>
+            </Setter.Value>
+        </Setter>
+    </Style>
+
+</ResourceDictionary>

+ 11 - 1
PixiEditor/Views/MainWindow.xaml

@@ -207,6 +207,11 @@
             <Grid AllowDrop="True" Drop="MainWindow_Drop">
                 <DockingManager ActiveContent="{Binding BitmapManager.ActiveDocument, Mode=TwoWay}" 
                                            DocumentsSource="{Binding BitmapManager.Documents}">
+                    <DockingManager.Resources>
+                        <Style TargetType="Border">
+                            <Setter Property="CornerRadius" Value="0,5,5,0"/>
+                        </Style>
+                    </DockingManager.Resources>
                     <DockingManager.Theme>
                         <avalonDockTheme:PixiEditorDockTheme />
                     </DockingManager.Theme>
@@ -335,7 +340,7 @@
             <ItemsControl ItemsSource="{Binding ToolsSubViewModel.ToolSet}">
                 <ItemsControl.ItemTemplate>
                     <DataTemplate>
-                        <Button BorderBrush="White"
+                        <Button BorderBrush="White"                                
                                 BorderThickness="{Binding IsActive, Converter={StaticResource BoolToIntConverter}}"
                                 Style="{StaticResource ToolButtonStyle}"
                                 Command="{Binding Path=DataContext.ToolsSubViewModel.SelectToolCommand,
@@ -344,6 +349,11 @@
                             <Button.Background>
                                 <ImageBrush ImageSource="{Binding ImagePath}" Stretch="Uniform" />
                             </Button.Background>
+                                <Button.Resources>
+                                    <Style TargetType="Border">
+                                        <Setter Property="CornerRadius" Value="2.5"/>
+                                    </Style>
+                                </Button.Resources>
                         </Button>
                     </DataTemplate>
                 </ItemsControl.ItemTemplate>

+ 9 - 4
PixiEditor/Views/UserControls/ListSwitchButton.xaml.cs → PixiEditor/Views/UserControls/ListSwitchButton.cs

@@ -9,7 +9,7 @@ namespace PixiEditor.Views.UserControls
     /// <summary>
     /// Interaction logic for ListSwitchButton.xaml
     /// </summary>
-    public partial class ListSwitchButton : UserControl
+    public class ListSwitchButton : Button
     {
         public ObservableCollection<SwitchItem> Items
         {
@@ -41,15 +41,20 @@ namespace PixiEditor.Views.UserControls
 
         // Using a DependencyProperty as the backing store for ActiveItem.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty ActiveItemProperty =
-            DependencyProperty.Register("ActiveItem", typeof(SwitchItem), typeof(ListSwitchButton), new PropertyMetadata(new SwitchItem(Brushes.Transparent, null)));
+            DependencyProperty.Register("ActiveItem", typeof(SwitchItem), typeof(ListSwitchButton), new PropertyMetadata(new SwitchItem(Brushes.Transparent, "", null)));
 
 
+        static ListSwitchButton()
+        {
+            DefaultStyleKeyProperty.OverrideMetadata(typeof(ListSwitchButton), new FrameworkPropertyMetadata(typeof(ListSwitchButton)));
+        }
+
         public ListSwitchButton()
         {
-            InitializeComponent();
+            Click += ListSwitchButton_Click;
         }
 
-        private void Button_Click(object sender, RoutedEventArgs e)
+        private void ListSwitchButton_Click(object sender, RoutedEventArgs e)
         {
             if (!Items.Contains(ActiveItem))
             {

+ 0 - 17
PixiEditor/Views/UserControls/ListSwitchButton.xaml

@@ -1,17 +0,0 @@
-<UserControl x:Class="PixiEditor.Views.UserControls.ListSwitchButton"
-             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
-             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
-             mc:Ignorable="d" 
-             d:DesignHeight="30" d:DesignWidth="60" Name="switchButton">
-    <Button Style="{StaticResource BaseDarkButton}" Click="Button_Click" Background="{Binding ActiveItem.Background, ElementName=switchButton}">
-        <Button.Resources>
-            <Style TargetType="Border">
-                <Setter Property="CornerRadius" Value="1.5"/>
-                <Setter Property="BorderBrush" Value="Black"/>
-                <Setter Property="BorderThickness" Value="1"/>
-            </Style>
-        </Button.Resources>
-    </Button>
-</UserControl>

+ 17 - 6
PixiEditor/Views/UserControls/PreviewWindow.xaml

@@ -79,14 +79,25 @@
             <local:PrependTextBlock Prepend=" X: " Text="{Binding ColorCursorPosition.Left, ElementName=uc}"/>
             <local:PrependTextBlock Prepend=" Y: " Text="{Binding ColorCursorPosition.Top, ElementName=uc}"/>
 
-            <Grid Width="5"/>
+            <Grid Width="15"/>
 
-            <local:PrependTextBlock Prepend=" R: " Text="{Binding ColorCursorColor.R, ElementName=uc}"/>
-            <local:PrependTextBlock Prepend=" G: " Text="{Binding ColorCursorColor.G, ElementName=uc}"/>
-            <local:PrependTextBlock Prepend=" B: " Text="{Binding ColorCursorColor.B, ElementName=uc}"/>
-            <local:PrependTextBlock Prepend=" A: " Text="{Binding ColorCursorColor.A, ElementName=uc}"/>
+            <local:ListSwitchButton x:Name="formatButton" Height="20" Width="35" BorderThickness="1">
+                <local:ListSwitchButton.Items>
+                    <local:SwitchItemObservableCollection>
+                        <local:SwitchItem Content="RGBA" Background="{StaticResource AccentColor}" Value="RGBA"/>
+                        <local:SwitchItem Content="HEX" Background="{StaticResource AccentColor}" Value="HEX"/>
+                    </local:SwitchItemObservableCollection>
+                </local:ListSwitchButton.Items>
+            </local:ListSwitchButton>
 
-            <local:PrependTextBlock Prepend="  (" Text="{Binding ColorCursorColor, ElementName=uc, FallbackValue=#00000000}" Append=")"/>
+            <TextBlock VerticalAlignment="Center" Margin="10, 0, 0, 0">
+                <TextBlock.Text>
+                    <MultiBinding Converter="{converters:FormattedColorConverter}">
+                        <Binding Path="ColorCursorColor" ElementName="uc"/>
+                        <Binding Path="ActiveItem.Value" ElementName="formatButton"/>
+                    </MultiBinding>
+                </TextBlock.Text>
+            </TextBlock>
         </StackPanel>
         <Grid Grid.Row="2" HorizontalAlignment="Right" Margin="5,0,5,0" Width="25" Height="20" RenderOptions.BitmapScalingMode="{Binding ElementName=backgroundButton, Path=ActiveItem.ScalingMode}">
             <local:ListSwitchButton x:Name="backgroundButton" ToolTip="Preview background">

+ 3 - 1
PixiEditor/Views/UserControls/SwitchItem.cs

@@ -4,16 +4,18 @@ namespace PixiEditor.Views.UserControls
 {
     public class SwitchItem
     {
+        public string Content { get; set; } = "";
         public Brush Background { get; set; }
         public object Value { get; set; }
 
         public BitmapScalingMode ScalingMode { get; set; } = BitmapScalingMode.HighQuality;
 
-        public SwitchItem(Brush background, object value, BitmapScalingMode scalingMode = BitmapScalingMode.HighQuality)
+        public SwitchItem(Brush background, object value, string content, BitmapScalingMode scalingMode = BitmapScalingMode.HighQuality)
         {
             Background = background;
             Value = value;
             ScalingMode = scalingMode;
+            Content = content;
         }
         public SwitchItem()
         {