Browse Source

better panel visibility system

Equbuxu 4 years ago
parent
commit
5ca911d855

+ 26 - 0
PixiEditor/Helpers/Converters/ThresholdVisibilityConverter.cs

@@ -0,0 +1,26 @@
+using System;
+using System.Globalization;
+using System.Windows;
+using System.Windows.Data;
+
+namespace PixiEditor.Helpers.Converters
+{
+    class ThresholdVisibilityConverter : IValueConverter
+    {
+        public double Threshold { get; set; } = 100;
+        public bool CheckIfLess { get; set; } = false;
+
+        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            if (CheckIfLess)
+                return (double)value < Threshold ? Visibility.Visible : Visibility.Hidden;
+            else
+                return (double)value >= Threshold ? Visibility.Visible : Visibility.Hidden;
+        }
+
+        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}

+ 0 - 34
PixiEditor/Views/ColorPanelController.cs

@@ -1,34 +0,0 @@
-using AvalonDock.Layout;
-using System.Windows;
-
-namespace PixiEditor.Views
-{
-    internal class ColorPanelController
-    {
-        private LayoutAnchorable colorPickerPanel;
-        private LayoutAnchorable colorSlidersPanel;
-        private LayoutAnchorable smallColorPickerPanel;
-
-        public ColorPanelController(LayoutAnchorable colorPickerPanel, LayoutAnchorable colorSlidersPanel, LayoutAnchorable smallColorPickerPanel)
-        {
-            this.colorPickerPanel = colorPickerPanel;
-            this.colorSlidersPanel = colorSlidersPanel;
-            this.smallColorPickerPanel = smallColorPickerPanel;
-        }
-
-        public void DeterminePanelsToDisplay()
-        {
-            if (SystemParameters.PrimaryScreenHeight < 1010)
-            {
-                colorPickerPanel.IsVisible = false;
-                colorSlidersPanel.IsVisible = true;
-                smallColorPickerPanel.IsVisible = true;
-            }
-            else
-            {
-                colorSlidersPanel.IsVisible = false;
-                smallColorPickerPanel.IsVisible = false;
-            }
-        }
-    }
-}

+ 1 - 12
PixiEditor/Views/MainWindow.xaml

@@ -248,23 +248,12 @@
                                     <LayoutAnchorable ContentId="colorPicker" Title="Color Picker" CanHide="False"
                                                              CanClose="False" CanAutoHide="False" x:Name="colorPickerPanel"
                                                              CanDockAsTabbedDocument="False" CanFloat="True">
-                                        <colorpicker:StandardColorPicker SelectedColor="{Binding ColorsSubViewModel.PrimaryColor, Mode=TwoWay}"
+                                        <usercontrols:SmallColorPicker SelectedColor="{Binding ColorsSubViewModel.PrimaryColor, Mode=TwoWay}"
                                                                          SecondaryColor="{Binding ColorsSubViewModel.SecondaryColor, Mode=TwoWay}" 
                                                                          Style="{StaticResource DefaultColorPickerStyle}" x:Name="mainColorPicker">
                                             <i:Interaction.Behaviors>
                                                 <behaviours:GlobalShortcutFocusBehavior/>
                                             </i:Interaction.Behaviors>
-                                        </colorpicker:StandardColorPicker>
-                                    </LayoutAnchorable>
-                                    <LayoutAnchorable ContentId="smallColorPicker" Title="Color Wheel" CanHide="False"
-                                                      CanClose="False" CanAutoHide="False" x:Name="smallColorPickerPanel"
-                                                      CanDockAsTabbedDocument="False" CanFloat="True">
-                                        <usercontrols:SmallColorPicker Style="{StaticResource DefaultColorPickerStyle}" 
-                                                                       ColorState="{Binding ElementName=mainColorPicker, Path=ColorState, Delay=10, Mode=TwoWay}"
-                                                                       SecondColorState="{Binding ElementName=mainColorPicker, Path=SecondColorState, Delay=10, Mode=TwoWay}">
-                                            <i:Interaction.Behaviors>
-                                                <behaviours:GlobalShortcutFocusBehavior/>
-                                            </i:Interaction.Behaviors>
                                         </usercontrols:SmallColorPicker>
                                     </LayoutAnchorable>
                                     <LayoutAnchorable ContentId="colorSliders" Title="Color Sliders" CanHide="False"

+ 0 - 4
PixiEditor/Views/MainWindow.xaml.cs

@@ -1,7 +1,6 @@
 using Microsoft.Extensions.DependencyInjection;
 using PixiEditor.Models.UserPreferences;
 using PixiEditor.ViewModels;
-using PixiEditor.Views;
 using System;
 using System.ComponentModel;
 using System.Windows;
@@ -30,9 +29,6 @@ namespace PixiEditor
             viewModel = (ViewModelMain)DataContext;
             viewModel.CloseAction = Close;
             Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
-
-            ColorPanelController controller = new ColorPanelController(colorPickerPanel, colorSlidersPanel, smallColorPickerPanel);
-            controller.DeterminePanelsToDisplay();
         }
 
         protected override void OnClosing(CancelEventArgs e)

+ 45 - 38
PixiEditor/Views/UserControls/SmallColorPicker.xaml

@@ -10,9 +10,8 @@
                                    xmlns:conv="clr-namespace:PixiEditor.Helpers.Converters"
                                    mc:Ignorable="d" 
                                    xmlns:colorpicker="clr-namespace:ColorPicker;assembly=ColorPicker"
-                                   d:DesignHeight="240" 
+                                   d:DesignHeight="380"
                                    d:DesignWidth="270"
-                                   MaxHeight="350"
                                    MaxWidth="400"
                                    x:Name="uc">
     <UserControl.Resources>
@@ -22,47 +21,55 @@
             </ResourceDictionary.MergedDictionaries>
             <conv:IntToPickerTypeConverter x:Key="IntToPickerTypeConverter"/>
             <conv:FloorConverter x:Key="FloorConverter"/>
+            <conv:ThresholdVisibilityConverter x:Key="ShowWhenBig" CheckIfLess="False" Threshold="380"/>
+            <conv:ThresholdVisibilityConverter x:Key="ShowWhenSmall" CheckIfLess="True" Threshold="380"/>
         </ResourceDictionary>
     </UserControl.Resources>
     <Grid>
-        <Grid.ColumnDefinitions>
-            <ColumnDefinition MaxWidth="80" Width="1*"/>
-            <ColumnDefinition Width="3*"/>
-        </Grid.ColumnDefinitions>
-        <Grid.RowDefinitions>
-            <RowDefinition Height="8*"/>
-            <RowDefinition Height="2*"/>
-            <RowDefinition Height="1.2*"/>
-            <RowDefinition Height="25"/>
-        </Grid.RowDefinitions>
-        <colorpicker:SquarePicker Grid.ColumnSpan="2" Grid.RowSpan="2" Margin="3"
-                                  ColorState="{Binding ColorState, Mode=TwoWay, ElementName=uc}"
-                                  PickerType="{Binding ElementName=colorSpaceComboBox, Path=SelectedIndex, Converter={StaticResource IntToPickerTypeConverter}}"/>
-        <colorpicker:ColorDisplay Grid.Row="1" Grid.RowSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="3,0,0,0"
-                                  ColorState="{Binding ColorState, Mode=TwoWay, ElementName=uc}" 
-                                  SecondColorState="{Binding SecondColorState, Mode=TwoWay, ElementName=uc}"/>
-        <ComboBox Grid.Row="1" Grid.RowSpan="2" Grid.Column="2" Width="50" Height="20" HorizontalAlignment="Right" 
-                  VerticalAlignment="Bottom" x:Name="colorSpaceComboBox" Margin="0,0,80,0">
-            <ComboBoxItem IsSelected="True">HSV</ComboBoxItem>
-            <ComboBoxItem>HSL</ComboBoxItem>
-        </ComboBox>
-        <colorpicker:HexColorTextBox Grid.Row="1" Grid.RowSpan="2" Grid.Column="2" Margin="0,0,3,0"
-                                     HorizontalAlignment="Right" VerticalAlignment="Bottom" 
-                                     ColorState="{Binding ColorState, Mode=TwoWay, ElementName=uc}"/>
-        <Grid Grid.Row="3" Grid.ColumnSpan="2">
+        <colorpicker:StandardColorPicker ColorState="{Binding ElementName=uc, Path=ColorState, Mode=TwoWay, Delay=10}"
+                                         SecondColorState="{Binding ElementName=uc, Path=SecondColorState, Mode=TwoWay, Delay=10}"
+                                         Visibility="{Binding ElementName=uc, Path=ActualHeight, Converter={StaticResource ShowWhenBig}}"
+                                         Style="{StaticResource DefaultColorPickerStyle}" x:Name="mainColorPicker" />
+        <Grid Visibility="{Binding ElementName=uc, Path=ActualHeight, Converter={StaticResource ShowWhenSmall}}">
             <Grid.ColumnDefinitions>
-                <ColumnDefinition Width="25"/>
-                <ColumnDefinition/>
-                <ColumnDefinition Width="50"/>
+                <ColumnDefinition MaxWidth="80" Width="1*"/>
+                <ColumnDefinition Width="3*"/>
             </Grid.ColumnDefinitions>
-            <Label VerticalAlignment="Center" Margin="3,0,0,0">A:</Label>
-            <colorpicker:AlphaSlider Margin="5,0" Grid.Column="1" VerticalAlignment="Center" ColorState="{Binding ColorState, Mode=TwoWay, ElementName=uc}"/>
-            <vws:NumberInput 
-                        Grid.Column="2" HorizontalAlignment="Right" Margin="5,0"
-                        Min="0" Max="255"
-                        Width="40" Height="20"
-                        VerticalAlignment="Center"
-                        Value="{Binding ElementName=uc, Path=Color.A, Mode=TwoWay, Delay=10, Converter={StaticResource FloorConverter}}" />
+            <Grid.RowDefinitions>
+                <RowDefinition Height="8*"/>
+                <RowDefinition Height="2*"/>
+                <RowDefinition Height="1.2*"/>
+                <RowDefinition Height="25"/>
+            </Grid.RowDefinitions>
+            <colorpicker:SquarePicker Grid.ColumnSpan="2" Grid.RowSpan="2" Margin="3"
+                                ColorState="{Binding ColorState, Mode=TwoWay, ElementName=uc}"
+                                PickerType="{Binding ElementName=colorSpaceComboBox, Path=SelectedIndex, Converter={StaticResource IntToPickerTypeConverter}}"/>
+            <colorpicker:ColorDisplay Grid.Row="1" Grid.RowSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="3,0,0,0"
+                                ColorState="{Binding ColorState, Mode=TwoWay, ElementName=uc}" 
+                                SecondColorState="{Binding SecondColorState, Mode=TwoWay, ElementName=uc}"/>
+            <ComboBox Grid.Row="1" Grid.RowSpan="2" Grid.Column="2" Width="50" Height="20" HorizontalAlignment="Right" 
+                VerticalAlignment="Bottom" x:Name="colorSpaceComboBox" Margin="0,0,80,0">
+                <ComboBoxItem IsSelected="True">HSV</ComboBoxItem>
+                <ComboBoxItem>HSL</ComboBoxItem>
+            </ComboBox>
+            <colorpicker:HexColorTextBox Grid.Row="1" Grid.RowSpan="2" Grid.Column="2" Margin="0,0,3,0"
+                                    HorizontalAlignment="Right" VerticalAlignment="Bottom" 
+                                    ColorState="{Binding ColorState, Mode=TwoWay, ElementName=uc}"/>
+            <Grid Grid.Row="3" Grid.ColumnSpan="2">
+                <Grid.ColumnDefinitions>
+                    <ColumnDefinition Width="25"/>
+                    <ColumnDefinition/>
+                    <ColumnDefinition Width="50"/>
+                </Grid.ColumnDefinitions>
+                <Label VerticalAlignment="Center" Margin="3,0,0,0">A:</Label>
+                <colorpicker:AlphaSlider Margin="5,0" Grid.Column="1" VerticalAlignment="Center" ColorState="{Binding ColorState, Mode=TwoWay, ElementName=uc}"/>
+                <vws:NumberInput 
+                    Grid.Column="2" HorizontalAlignment="Right" Margin="5,0"
+                    Min="0" Max="255"
+                    Width="40" Height="20"
+                    VerticalAlignment="Center"
+                    Value="{Binding ElementName=uc, Path=Color.A, Mode=TwoWay, Delay=10, Converter={StaticResource FloorConverter}}" />
+            </Grid>
         </Grid>
     </Grid>
 </colorpicker:DualPickerControlBase>