moving converters, fixing spacing issues

This commit is contained in:
Clint Rutkas 2019-12-12 13:51:58 -08:00
parent a187456ac3
commit 24664cc859
14 changed files with 93 additions and 85 deletions

View File

@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Windows.Data;
using System.Windows.Media;
namespace FancyZonesEditor.Converters
{
public class BooleanToBrushConverter : IValueConverter
{
private static Brush _selectedBrush = new SolidColorBrush(Color.FromRgb(0x00, 0x78, 0xD7));
private static Brush _normalBrush = new SolidColorBrush(Color.FromRgb(0xF2, 0xF2, 0xF2));
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return ((bool)value) ? _selectedBrush : _normalBrush;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value == _selectedBrush;
}
}
}

View File

@ -0,0 +1,32 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Windows.Data;
namespace FancyZonesEditor.Converters
{
public class BooleanToIntConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is bool)
{
return (bool)value == true ? 1 : 0;
}
return 0;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is int)
{
return (int)value == 1;
}
return false;
}
}
}

View File

@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Windows;
using System.Windows.Data;
using FancyZonesEditor.Models;
namespace FancyZonesEditor.Converters
{
public class ModelToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return Settings.IsPredefinedLayout((LayoutModel)value) ? Visibility.Collapsed : Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}

View File

@ -2,22 +2,10 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using FancyZonesEditor.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Security.RightsManagement;
using System.Text;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using FancyZonesEditor.Models;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace FancyZonesEditor namespace FancyZonesEditor
{ {
@ -70,6 +58,7 @@ namespace FancyZonesEditor
} }
public static EditorOverlay Current; public static EditorOverlay Current;
public EditorOverlay() public EditorOverlay()
{ {
InitializeComponent(); InitializeComponent();

View File

@ -66,6 +66,8 @@
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</ApplicationDefinition> </ApplicationDefinition>
<Compile Include="Converters\BooleanToBrushConverter.xaml.cs" />
<Compile Include="Converters\BooleanToIntConverter.xaml.cs" />
<Compile Include="CanvasEditor.xaml.cs"> <Compile Include="CanvasEditor.xaml.cs">
<DependentUpon>CanvasEditor.xaml</DependentUpon> <DependentUpon>CanvasEditor.xaml</DependentUpon>
</Compile> </Compile>
@ -87,6 +89,7 @@
<Compile Include="EditorOverlay.xaml.cs"> <Compile Include="EditorOverlay.xaml.cs">
<DependentUpon>EditorOverlay.xaml</DependentUpon> <DependentUpon>EditorOverlay.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Converters\ModelToVisibilityConverter.xaml.cs" />
<Compile Include="RowColInfo.cs" /> <Compile Include="RowColInfo.cs" />
<Compile Include="GridEditorWindow.xaml.cs"> <Compile Include="GridEditorWindow.xaml.cs">
<DependentUpon>GridEditorWindow.xaml</DependentUpon> <DependentUpon>GridEditorWindow.xaml</DependentUpon>

View File

@ -212,7 +212,6 @@ namespace FancyZonesEditor
break; break;
} }
} }
} }
private void OnSplit(object o, SplitEventArgs e) private void OnSplit(object o, SplitEventArgs e)
@ -246,12 +245,10 @@ namespace FancyZonesEditor
} }
} }
int newChildIndex = AddZone(); int newChildIndex = AddZone();
double offset = e.Offset; double offset = e.Offset;
if (e.Orientation == Orientation.Vertical) if (e.Orientation == Orientation.Vertical)
{ {
if (splitee.VerticalSnapPoints != null) if (splitee.VerticalSnapPoints != null)
@ -385,7 +382,6 @@ namespace FancyZonesEditor
} }
offset -= _rowInfo[foundRow].Start; offset -= _rowInfo[foundRow].Start;
} }
AddDragHandle(Orientation.Horizontal, rows - 1); AddDragHandle(Orientation.Horizontal, rows - 1);
@ -919,7 +915,6 @@ namespace FancyZonesEditor
return returnSize; return returnSize;
} }
Point _mouseDownPos = new Point(-1, -1);
private RowColInfo[] _rowInfo; private RowColInfo[] _rowInfo;
private RowColInfo[] _colInfo; private RowColInfo[] _colInfo;
@ -927,8 +922,5 @@ namespace FancyZonesEditor
private int _endRow = -1; private int _endRow = -1;
private int _startCol = -1; private int _startCol = -1;
private int _endCol = -1; private int _endCol = -1;
private const int c_multiplier = 10000;
} }
} }

View File

@ -26,6 +26,7 @@ namespace FancyZonesEditor
{ {
return _orientation; return _orientation;
} }
set set
{ {
_orientation = value; _orientation = value;

View File

@ -35,12 +35,9 @@ namespace FancyZonesEditor
set { SetValue(IsSelectedProperty, value); } set { SetValue(IsSelectedProperty, value); }
} }
public double[] VerticalSnapPoints; public double[] VerticalSnapPoints;
public double[] HorizontalSnapPoints; public double[] HorizontalSnapPoints;
public GridZone() public GridZone()
{ {
InitializeComponent(); InitializeComponent();

View File

@ -17,6 +17,7 @@ namespace FancyZonesEditor
public partial class LayoutPreview : UserControl public partial class LayoutPreview : UserControl
{ {
public static readonly DependencyProperty IsActualSizeProperty = DependencyProperty.Register("IsActualSize", typeof(bool), typeof(LayoutPreview), new PropertyMetadata(false)); public static readonly DependencyProperty IsActualSizeProperty = DependencyProperty.Register("IsActualSize", typeof(bool), typeof(LayoutPreview), new PropertyMetadata(false));
public LayoutPreview() public LayoutPreview()
{ {
InitializeComponent(); InitializeComponent();

View File

@ -6,6 +6,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:local="clr-namespace:FancyZonesEditor" xmlns:local="clr-namespace:FancyZonesEditor"
xmlns:Converters="clr-namespace:FancyZonesEditor.Converters"
mc:Ignorable="d" mc:Ignorable="d"
Title="" Title=""
Width="810" Width="810"
@ -16,9 +17,9 @@
Initialized="InitializedEventHandler" Initialized="InitializedEventHandler"
Closed="OnClosed"> Closed="OnClosed">
<Window.Resources> <Window.Resources>
<local:BooleanToBrushConverter x:Key="BooleanToBrushConverter" /> <Converters:BooleanToBrushConverter x:Key="BooleanToBrushConverter" />
<local:ModelToVisibilityConverter x:Key="ModelToVisibilityConverter" /> <Converters:ModelToVisibilityConverter x:Key="ModelToVisibilityConverter" />
<local:BooleanToIntConverter x:Key="BooleanToIntConverter" /> <Converters:BooleanToIntConverter x:Key="BooleanToIntConverter" />
<Style x:Key="titleText" TargetType="TextBlock"> <Style x:Key="titleText" TargetType="TextBlock">
<Setter Property="FontFamily" Value="Segoe UI" /> <Setter Property="FontFamily" Value="Segoe UI" />

View File

@ -209,57 +209,4 @@ namespace FancyZonesEditor
model.Delete(); model.Delete();
} }
} }
public class BooleanToBrushConverter : IValueConverter
{
private static Brush c_selectedBrush = new SolidColorBrush(Color.FromRgb(0x00, 0x78, 0xD7));
private static Brush c_normalBrush = new SolidColorBrush(Color.FromRgb(0xF2, 0xF2, 0xF2));
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return ((bool)value) ? c_selectedBrush : c_normalBrush;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value == c_selectedBrush;
}
}
public class ModelToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return Settings.IsPredefinedLayout((LayoutModel)value) ? Visibility.Collapsed : Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
public class BooleanToIntConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is bool)
{
return (bool)value == true ? 1 : 0;
}
return 0;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is int)
{
return (int)value == 1;
}
return false;
}
}
} }

View File

@ -155,7 +155,6 @@ namespace FancyZonesEditor.Models
data[i++] = (byte)(Id % 256); data[i++] = (byte)(Id % 256);
// End common // End common
data[i++] = (byte)(_referenceWidth / 256); data[i++] = (byte)(_referenceWidth / 256);
data[i++] = (byte)(_referenceWidth % 256); data[i++] = (byte)(_referenceWidth % 256);
data[i++] = (byte)(_referenceHeight / 256); data[i++] = (byte)(_referenceHeight / 256);

View File

@ -214,7 +214,6 @@ namespace FancyZonesEditor.Models
data[i++] = (byte)(Id % 256); data[i++] = (byte)(Id % 256);
// End common // End common
data[i++] = (byte)Rows; data[i++] = (byte)Rows;
data[i++] = (byte)Columns; data[i++] = (byte)Columns;

View File

@ -276,7 +276,6 @@ namespace FancyZonesEditor
{ {
index--; index--;
} }
} }
} }
@ -313,7 +312,6 @@ namespace FancyZonesEditor
// 4 = X_Y_Width_Height in a dpi-scaled-but-unaware coords (where EditorOverlay shows up) // 4 = X_Y_Width_Height in a dpi-scaled-but-unaware coords (where EditorOverlay shows up)
// 5 = resolution key (passed back to engine to persist data) // 5 = resolution key (passed back to engine to persist data)
// 6 = monitor DPI (float) // 6 = monitor DPI (float)
UniqueKey = args[1]; UniqueKey = args[1];
_uniqueRegistryPath += "\\" + UniqueKey; _uniqueRegistryPath += "\\" + UniqueKey;
@ -347,7 +345,6 @@ namespace FancyZonesEditor
} }
} }
public IList<LayoutModel> DefaultModels public IList<LayoutModel> DefaultModels
{ {
get { return _defaultModels; } get { return _defaultModels; }