fixed a bunch more

This commit is contained in:
Clint Rutkas
2019-12-12 14:34:25 -08:00
parent 4c88c9b029
commit 151a937c10
15 changed files with 180 additions and 173 deletions

View File

@@ -19,7 +19,7 @@ namespace FancyZonesEditor
public CanvasZone() public CanvasZone()
{ {
InitializeComponent(); InitializeComponent();
Canvas.SetZIndex(this, c_zIndex++); Panel.SetZIndex(this, _zIndex++);
} }
public CanvasLayoutModel Model; public CanvasLayoutModel Model;
@@ -66,9 +66,9 @@ namespace FancyZonesEditor
} }
else if (xDelta > 0) else if (xDelta > 0)
{ {
if ((rect.Width - (int)xDelta) < c_minZoneWidth) if ((rect.Width - (int)xDelta) < _minZoneWidth)
{ {
xDelta = rect.Width - c_minZoneWidth; xDelta = rect.Width - _minZoneWidth;
} }
} }
@@ -81,9 +81,9 @@ namespace FancyZonesEditor
} }
else if (yDelta > 0) else if (yDelta > 0)
{ {
if ((rect.Height - (int)yDelta) < c_minZoneHeight) if ((rect.Height - (int)yDelta) < _minZoneHeight)
{ {
yDelta = rect.Height - c_minZoneHeight; yDelta = rect.Height - _minZoneHeight;
} }
} }
@@ -107,9 +107,9 @@ namespace FancyZonesEditor
{ {
int newWidth = rect.Width + (int)xDelta; int newWidth = rect.Width + (int)xDelta;
if (newWidth < c_minZoneWidth) if (newWidth < _minZoneWidth)
{ {
newWidth = c_minZoneWidth; newWidth = _minZoneWidth;
} }
else if (newWidth > (_settings.WorkArea.Width - rect.X)) else if (newWidth > (_settings.WorkArea.Width - rect.X))
{ {
@@ -123,9 +123,9 @@ namespace FancyZonesEditor
{ {
int newHeight = rect.Height + (int)yDelta; int newHeight = rect.Height + (int)yDelta;
if (newHeight < c_minZoneHeight) if (newHeight < _minZoneHeight)
{ {
newHeight = c_minZoneHeight; newHeight = _minZoneHeight;
} }
else if (newHeight > (_settings.WorkArea.Height - rect.Y)) else if (newHeight > (_settings.WorkArea.Height - rect.Y))
{ {
@@ -138,13 +138,13 @@ namespace FancyZonesEditor
Model.Zones[ZoneIndex] = rect; Model.Zones[ZoneIndex] = rect;
} }
private static int c_zIndex = 0; private static int _zIndex = 0;
private static int c_minZoneWidth = 64; private static int _minZoneWidth = 64;
private static int c_minZoneHeight = 72; private static int _minZoneHeight = 72;
protected override void OnPreviewMouseDown(MouseButtonEventArgs e) protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
{ {
Canvas.SetZIndex(this, c_zIndex++); Panel.SetZIndex(this, _zIndex++);
base.OnPreviewMouseDown(e); base.OnPreviewMouseDown(e);
} }

View File

@@ -14,21 +14,21 @@ namespace FancyZonesEditor
/// </summary> /// </summary>
public partial class EditorOverlay : Window public partial class EditorOverlay : Window
{ {
public static EditorOverlay Current { get; set; }
public Int32Rect[] GetZoneRects() public Int32Rect[] GetZoneRects()
{ {
// TODO: the ideal here is that the ArrangeRects logic is entirely inside the model, so we don't have to walk the UIElement children to get the rect info // TODO: the ideal here is that the ArrangeRects logic is entirely inside the model, so we don't have to walk the UIElement children to get the rect info
Panel previewPanel = null; Panel previewPanel;
if (_editor != null) if (_editor != null)
{ {
GridEditor gridEditor = _editor as GridEditor; if (_editor is GridEditor gridEditor)
if (gridEditor != null)
{ {
previewPanel = gridEditor.PreviewPanel; previewPanel = gridEditor.PreviewPanel;
} }
else else
{ {
//CanvasEditor // CanvasEditor
previewPanel = ((CanvasEditor)_editor).Preview; previewPanel = ((CanvasEditor)_editor).Preview;
} }
} }
@@ -43,7 +43,7 @@ namespace FancyZonesEditor
int i = 0; int i = 0;
foreach (FrameworkElement child in previewPanel.Children) foreach (FrameworkElement child in previewPanel.Children)
{ {
Point topLeft = child.TransformToAncestor(previewPanel).Transform(new Point()); Point topLeft = child.TransformToAncestor(previewPanel).Transform(default(Point));
var right = topLeft.X + child.ActualWidth; var right = topLeft.X + child.ActualWidth;
var bottom = topLeft.Y + child.ActualHeight; var bottom = topLeft.Y + child.ActualHeight;
@@ -57,8 +57,6 @@ namespace FancyZonesEditor
return zones; return zones;
} }
public static EditorOverlay Current;
public EditorOverlay() public EditorOverlay()
{ {
InitializeComponent(); InitializeComponent();

View File

@@ -14,14 +14,14 @@ namespace FancyZonesEditor
protected void OnSaveApplyTemplate(object sender, RoutedEventArgs e) protected void OnSaveApplyTemplate(object sender, RoutedEventArgs e)
{ {
EditorOverlay mainEditor = EditorOverlay.Current; EditorOverlay mainEditor = EditorOverlay.Current;
LayoutModel model = mainEditor.DataContext as LayoutModel; var model = mainEditor.DataContext as LayoutModel;
if (model != null) if (model != null)
{ {
model.Persist(mainEditor.GetZoneRects()); model.Persist(mainEditor.GetZoneRects());
} }
_choosing = true; _choosing = true;
this.Close(); Close();
EditorOverlay.Current.Close(); EditorOverlay.Current.Close();
} }
@@ -36,7 +36,7 @@ namespace FancyZonesEditor
protected void OnCancel(object sender, RoutedEventArgs e) protected void OnCancel(object sender, RoutedEventArgs e)
{ {
_choosing = true; _choosing = true;
this.Close(); Close();
EditorOverlay.Current.ShowLayoutPicker(); EditorOverlay.Current.ShowLayoutPicker();
} }

View File

@@ -90,6 +90,7 @@
<DependentUpon>EditorOverlay.xaml</DependentUpon> <DependentUpon>EditorOverlay.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Converters\ModelToVisibilityConverter.xaml.cs" /> <Compile Include="Converters\ModelToVisibilityConverter.xaml.cs" />
<Compile Include="Native.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

@@ -1,5 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements. // Copyright (c) Microsoft Corporation
// The .NET Foundation 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.
// This file is used by Code Analysis to maintain SuppressMessage // This file is used by Code Analysis to maintain SuppressMessage

View File

@@ -343,8 +343,9 @@ namespace FancyZonesEditor
model.Columns++; model.Columns++;
} }
else // Horizontal else
{ {
// Horizontal
if (splitee.HorizontalSnapPoints != null) if (splitee.HorizontalSnapPoints != null)
{ {
offset += Canvas.GetTop(splitee); offset += Canvas.GetTop(splitee);
@@ -553,7 +554,7 @@ namespace FancyZonesEditor
return; return;
} }
Settings settings = ((App)(Application.Current)).ZoneSettings; Settings settings = ((App)Application.Current).ZoneSettings;
int spacing = settings.Spacing; int spacing = settings.Spacing;
int gutter = settings.Spacing; int gutter = settings.Spacing;
@@ -566,14 +567,14 @@ namespace FancyZonesEditor
double top = gutter; double top = gutter;
for (int row = 0; row < rows; row++) for (int row = 0; row < rows; row++)
{ {
double cellHeight = _rowInfo[row].SetExtent(top, totalHeight); double cellHeight = _rowInfo[row].Recalculate(top, totalHeight);
top += cellHeight + spacing; top += cellHeight + spacing;
} }
double left = gutter; double left = gutter;
for (int col = 0; col < cols; col++) for (int col = 0; col < cols; col++)
{ {
double cellWidth = _colInfo[col].SetExtent(left, totalWidth); double cellWidth = _colInfo[col].Recalculate(left, totalWidth);
left += cellWidth + spacing; left += cellWidth + spacing;
} }
@@ -861,7 +862,7 @@ namespace FancyZonesEditor
e.Handled = true; e.Handled = true;
} }
base.OnPreviewMouseMove(e); OnPreviewMouseMove(e);
} }
private void ClearSelection() private void ClearSelection()

View File

@@ -19,6 +19,25 @@ namespace FancyZonesEditor
{ {
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(GridZone), new PropertyMetadata(false, OnSelectionChanged)); public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(GridZone), new PropertyMetadata(false, OnSelectionChanged));
public event SplitEventHandler Split;
public event SplitEventHandler FullSplit;
public event MouseEventHandler MergeDrag;
public event MouseButtonEventHandler MergeComplete;
public double[] VerticalSnapPoints { get; set; }
public double[] HorizontalSnapPoints { get; set; }
private Rectangle _splitter;
private bool _switchOrientation = false;
private Point _lastPos = new Point(-1, -1);
private Point _mouseDownPos = new Point(-1, -1);
private bool _inMergeDrag = false;
private Orientation _splitOrientation;
private static void OnSelectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) private static void OnSelectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{ {
((GridZone)d).OnSelectionChanged(); ((GridZone)d).OnSelectionChanged();
@@ -35,15 +54,14 @@ namespace FancyZonesEditor
set { SetValue(IsSelectedProperty, value); } set { SetValue(IsSelectedProperty, value); }
} }
public double[] VerticalSnapPoints;
public double[] HorizontalSnapPoints;
public GridZone() public GridZone()
{ {
InitializeComponent(); InitializeComponent();
OnSelectionChanged(); OnSelectionChanged();
_splitter = new Rectangle(); _splitter = new Rectangle
_splitter.Fill = Brushes.DarkGray; {
Fill = Brushes.DarkGray,
};
Body.Children.Add(_splitter); Body.Children.Add(_splitter);
((App)Application.Current).ZoneSettings.PropertyChanged += ZoneSettings_PropertyChanged; ((App)Application.Current).ZoneSettings.PropertyChanged += ZoneSettings_PropertyChanged;
@@ -169,8 +187,9 @@ namespace FancyZonesEditor
} }
} }
} }
else // horizontal split else
{ {
// horizontal split
if (HorizontalSnapPoints != null) if (HorizontalSnapPoints != null)
{ {
int thickness = SplitterThickness; int thickness = SplitterThickness;
@@ -237,21 +256,6 @@ namespace FancyZonesEditor
base.OnMouseUp(e); base.OnMouseUp(e);
} }
public event SplitEventHandler Split;
public event SplitEventHandler FullSplit;
public event MouseEventHandler MergeDrag;
public event MouseButtonEventHandler MergeComplete;
private Rectangle _splitter;
private bool _switchOrientation = false;
private Point _lastPos = new Point(-1,-1);
private Point _mouseDownPos = new Point(-1,-1);
private bool _inMergeDrag = false;
private Orientation _splitOrientation;
private void DoMergeDrag(MouseEventArgs e) private void DoMergeDrag(MouseEventArgs e)
{ {
if (MergeDrag != null) if (MergeDrag != null)

View File

@@ -83,14 +83,13 @@ namespace FancyZonesEditor
Body.Children.Clear(); Body.Children.Clear();
GridLayoutModel gridModel = _model as GridLayoutModel; if (_model is GridLayoutModel gridModel)
if (gridModel != null)
{ {
RenderGridPreview(gridModel); RenderGridPreview(gridModel);
} }
else else
{ {
CanvasLayoutModel canvasModel = _model as CanvasLayoutModel; var canvasModel = _model as CanvasLayoutModel;
if (canvasModel != null) if (canvasModel != null)
{ {
RenderCanvasPreview(canvasModel); RenderCanvasPreview(canvasModel);
@@ -126,7 +125,7 @@ namespace FancyZonesEditor
{ {
for (int col = 0; col < grid.Columns; col++) for (int col = 0; col < grid.Columns; col++)
{ {
int childIndex = grid.CellChildMap[row,col]; int childIndex = grid.CellChildMap[row, col];
if (!visited.Contains(childIndex)) if (!visited.Contains(childIndex))
{ {
visited.Add(childIndex); visited.Add(childIndex);
@@ -135,7 +134,7 @@ namespace FancyZonesEditor
Grid.SetColumn(rect, col); Grid.SetColumn(rect, col);
int span = 1; int span = 1;
int walk = row + 1; int walk = row + 1;
while ((walk < grid.Rows) && grid.CellChildMap[walk,col] == childIndex) while ((walk < grid.Rows) && grid.CellChildMap[walk, col] == childIndex)
{ {
span++; span++;
walk++; walk++;

View File

@@ -23,7 +23,7 @@ namespace FancyZonesEditor
public static int MAX_ZONES = 40; public static int MAX_ZONES = 40;
private static string _defaultNamePrefix = "Custom Layout "; private static string _defaultNamePrefix = "Custom Layout ";
private bool _editing = false; private bool _editing = false;
private int _WrapPanelItemSize = 262; private int _wrapPanelItemSize = 262;
public MainWindow() public MainWindow()
{ {
@@ -31,8 +31,8 @@ namespace FancyZonesEditor
DataContext = _settings; DataContext = _settings;
if (_settings.WorkArea.Height < 900) if (_settings.WorkArea.Height < 900)
{ {
this.SizeToContent = SizeToContent.WidthAndHeight; SizeToContent = SizeToContent.WidthAndHeight;
this.WrapPanelItemSize = 180; WrapPanelItemSize = 180;
} }
} }
@@ -40,12 +40,12 @@ namespace FancyZonesEditor
{ {
get get
{ {
return _WrapPanelItemSize; return _wrapPanelItemSize;
} }
set set
{ {
_WrapPanelItemSize = value; _wrapPanelItemSize = value;
} }
} }
@@ -71,7 +71,7 @@ namespace FancyZonesEditor
{ {
WindowLayout window = new WindowLayout(); WindowLayout window = new WindowLayout();
window.Show(); window.Show();
this.Close(); Close();
} }
private void LayoutItem_Click(object sender, MouseButtonEventArgs e) private void LayoutItem_Click(object sender, MouseButtonEventArgs e)
@@ -81,30 +81,26 @@ namespace FancyZonesEditor
private void Select(LayoutModel newSelection) private void Select(LayoutModel newSelection)
{ {
LayoutModel currentSelection = EditorOverlay.Current.DataContext as LayoutModel; if (EditorOverlay.Current.DataContext is LayoutModel currentSelection)
if (currentSelection != null)
{ {
currentSelection.IsSelected = false; currentSelection.IsSelected = false;
} }
newSelection.IsSelected = true; newSelection.IsSelected = true;
EditorOverlay.Current.DataContext = newSelection; EditorOverlay.Current.DataContext = newSelection;
} }
private void EditLayout_Click(object sender, RoutedEventArgs e) private void EditLayout_Click(object sender, RoutedEventArgs e)
{ {
EditorOverlay mainEditor = EditorOverlay.Current; EditorOverlay mainEditor = EditorOverlay.Current;
LayoutModel model = mainEditor.DataContext as LayoutModel; if (!(mainEditor.DataContext is LayoutModel model))
if (model == null)
{ {
return; return;
} }
model.IsSelected = false; model.IsSelected = false;
_editing = true; _editing = true;
this.Close(); Close();
bool isPredefinedLayout = Settings.IsPredefinedLayout(model); bool isPredefinedLayout = Settings.IsPredefinedLayout(model);
@@ -124,7 +120,7 @@ namespace FancyZonesEditor
if (name.StartsWith(_defaultNamePrefix)) if (name.StartsWith(_defaultNamePrefix))
{ {
int i; int i;
if (Int32.TryParse(name.Substring(_defaultNamePrefix.Length), out i)) if (int.TryParse(name.Substring(_defaultNamePrefix.Length), out i))
{ {
if (maxCustomIndex < i) if (maxCustomIndex < i)
{ {
@@ -157,8 +153,7 @@ namespace FancyZonesEditor
private void Apply_Click(object sender, RoutedEventArgs e) private void Apply_Click(object sender, RoutedEventArgs e)
{ {
EditorOverlay mainEditor = EditorOverlay.Current; EditorOverlay mainEditor = EditorOverlay.Current;
LayoutModel model = mainEditor.DataContext as LayoutModel; if (mainEditor.DataContext is LayoutModel model)
if (model != null)
{ {
if (model is GridLayoutModel) if (model is GridLayoutModel)
{ {
@@ -169,7 +164,7 @@ namespace FancyZonesEditor
model.Apply((model as CanvasLayoutModel).Zones.ToArray()); model.Apply((model as CanvasLayoutModel).Zones.ToArray());
} }
this.Close(); Close();
} }
} }

View File

@@ -107,18 +107,18 @@ namespace FancyZonesEditor.Models
// Initialize this CanvasLayoutModel based on the given persistence data // Initialize this CanvasLayoutModel based on the given persistence data
// Skip version (2 bytes), id (2 bytes), and type (1 bytes) // Skip version (2 bytes), id (2 bytes), and type (1 bytes)
int i = 5; int i = 5;
_referenceWidth = data[i++] * 256 + data[i++]; _referenceWidth = (data[i++] * 256) + data[i++];
_referenceHeight = data[i++] * 256 + data[i++]; _referenceHeight = (data[i++] * 256) + data[i++];
int count = data[i++]; int count = data[i++];
while (count-- > 0) while (count-- > 0)
{ {
Zones.Add(new Int32Rect( Zones.Add(new Int32Rect(
data[i++] * 256 + data[i++], (data[i++] * 256) + data[i++],
data[i++] * 256 + data[i++], (data[i++] * 256) + data[i++],
data[i++] * 256 + data[i++], (data[i++] * 256) + data[i++],
data[i++] * 256 + data[i++])); (data[i++] * 256) + data[i++]));
} }
} }
@@ -127,11 +127,13 @@ namespace FancyZonesEditor.Models
// Clones the data from this CanvasLayoutModel to a new CanvasLayoutModel // Clones the data from this CanvasLayoutModel to a new CanvasLayoutModel
public override LayoutModel Clone() public override LayoutModel Clone()
{ {
CanvasLayoutModel layout = new CanvasLayoutModel(Name); CanvasLayoutModel layout = new CanvasLayoutModel(Name)
layout.ReferenceHeight = ReferenceHeight; {
layout.ReferenceWidth = ReferenceWidth; ReferenceHeight = ReferenceHeight,
ReferenceWidth = ReferenceWidth,
};
foreach(Int32Rect zone in Zones) foreach (Int32Rect zone in Zones)
{ {
layout.Zones.Add(zone); layout.Zones.Add(zone);
} }

View File

@@ -10,29 +10,7 @@ namespace FancyZonesEditor.Models
// Grid-styled Layout Model, which specifies rows, columns, percentage sizes, and row/column spans // Grid-styled Layout Model, which specifies rows, columns, percentage sizes, and row/column spans
public class GridLayoutModel : LayoutModel public class GridLayoutModel : LayoutModel
{ {
public GridLayoutModel() private static ushort _latestVersion = 0;
: base()
{
}
public GridLayoutModel(string name)
: base(name)
{
}
public GridLayoutModel(string name, ushort id)
: base(name, id)
{
}
public GridLayoutModel(ushort version, string name, ushort id, byte[] data)
: base(name, id)
{
if (version == c_latestVersion)
{
Reload(data);
}
}
// Rows - number of rows in the Grid // Rows - number of rows in the Grid
public int Rows public int Rows
@@ -90,6 +68,30 @@ namespace FancyZonesEditor.Models
// TODO: do I need FreeZones on the data model? - I think I do // TODO: do I need FreeZones on the data model? - I think I do
public IList<int> FreeZones { get; } = new List<int>(); public IList<int> FreeZones { get; } = new List<int>();
public GridLayoutModel()
: base()
{
}
public GridLayoutModel(string name)
: base(name)
{
}
public GridLayoutModel(string name, ushort id)
: base(name, id)
{
}
public GridLayoutModel(ushort version, string name, ushort id, byte[] data)
: base(name, id)
{
if (version == _latestVersion)
{
Reload(data);
}
}
public void Reload(byte[] data) public void Reload(byte[] data)
{ {
// Skip version (2 bytes), id (2 bytes), and type (1 bytes) // Skip version (2 bytes), id (2 bytes), and type (1 bytes)
@@ -207,8 +209,8 @@ namespace FancyZonesEditor.Models
int i = 0; int i = 0;
// Common persisted values between all layout types // Common persisted values between all layout types
data[i++] = (byte)(c_latestVersion / 256); data[i++] = (byte)(_latestVersion / 256);
data[i++] = (byte)(c_latestVersion % 256); data[i++] = (byte)(_latestVersion % 256);
data[i++] = 0; // LayoutModelType: 0 == GridLayoutModel data[i++] = 0; // LayoutModelType: 0 == GridLayoutModel
data[i++] = (byte)(Id / 256); data[i++] = (byte)(Id / 256);
data[i++] = (byte)(Id % 256); data[i++] = (byte)(Id % 256);
@@ -241,7 +243,5 @@ namespace FancyZonesEditor.Models
return data; return data;
} }
private static ushort c_latestVersion = 0;
} }
} }

View File

@@ -14,6 +14,9 @@ namespace FancyZonesEditor.Models
// Manages common properties and base persistence // Manages common properties and base persistence
public abstract class LayoutModel : INotifyPropertyChanged public abstract class LayoutModel : INotifyPropertyChanged
{ {
private static readonly string _registryPath = Settings.RegistryPath + "\\Layouts";
private static readonly string _fullRegistryPath = Settings.FullRegistryPath + "\\Layouts";
protected LayoutModel() protected LayoutModel()
{ {
} }
@@ -24,7 +27,7 @@ namespace FancyZonesEditor.Models
Name = name; Name = name;
} }
protected LayoutModel(string name, ushort id) protected LayoutModel(string name, ushort id)
: this(name) : this(name)
{ {
_id = id; _id = id;
@@ -58,7 +61,7 @@ namespace FancyZonesEditor.Models
{ {
if (_id == 0) if (_id == 0)
{ {
_id = ++s_maxId; _id = ++_maxId;
} }
return _id; return _id;
@@ -106,17 +109,17 @@ namespace FancyZonesEditor.Models
key.DeleteValue(Name); key.DeleteValue(Name);
} }
int i = s_customModels.IndexOf(this); int i = _customModels.IndexOf(this);
if (i != -1) if (i != -1)
{ {
s_customModels.RemoveAt(i); _customModels.RemoveAt(i);
} }
} }
// Loads all the Layouts persisted under the Layouts key in the registry // Loads all the Layouts persisted under the Layouts key in the registry
public static ObservableCollection<LayoutModel> LoadCustomModels() public static ObservableCollection<LayoutModel> LoadCustomModels()
{ {
s_customModels = new ObservableCollection<LayoutModel>(); _customModels = new ObservableCollection<LayoutModel>();
RegistryKey key = Registry.CurrentUser.OpenSubKey(_registryPath); RegistryKey key = Registry.CurrentUser.OpenSubKey(_registryPath);
if (key != null) if (key != null)
@@ -138,46 +141,28 @@ namespace FancyZonesEditor.Models
if (model != null) if (model != null)
{ {
if (s_maxId < id) if (_maxId < id)
{ {
s_maxId = id; _maxId = id;
} }
s_customModels.Add(model); _customModels.Add(model);
} }
} }
} }
return s_customModels; return _customModels;
} }
private static ObservableCollection<LayoutModel> s_customModels = null; private static ObservableCollection<LayoutModel> _customModels = null;
private static ushort s_maxId = 0; private static ushort _maxId = 0;
// Callbacks that the base LayoutModel makes to derived types // Callbacks that the base LayoutModel makes to derived types
protected abstract byte[] GetPersistData(); protected abstract byte[] GetPersistData();
public abstract LayoutModel Clone(); public abstract LayoutModel Clone();
// PInvokes to handshake with fancyzones backend
internal static class Native
{
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)]
public static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)]string lpFileName);
[DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
public static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
internal delegate int PersistZoneSet(
[MarshalAs(UnmanagedType.LPWStr)] string activeKey,
[MarshalAs(UnmanagedType.LPWStr)] string resolutionKey,
uint monitor,
ushort layoutId,
int zoneCount,
[MarshalAs(UnmanagedType.LPArray)] int[] zoneArray);
}
public void Persist(System.Windows.Int32Rect[] zones) public void Persist(System.Windows.Int32Rect[] zones)
{ {
// Persist the editor data // Persist the editor data
@@ -220,8 +205,5 @@ namespace FancyZonesEditor.Models
var persistZoneSet = Marshal.GetDelegateForFunctionPointer<Native.PersistZoneSet>(pfn); var persistZoneSet = Marshal.GetDelegateForFunctionPointer<Native.PersistZoneSet>(pfn);
persistZoneSet(Settings.UniqueKey, Settings.WorkAreaKey, Settings.Monitor, _id, zoneCount, zoneArray); persistZoneSet(Settings.UniqueKey, Settings.WorkAreaKey, Settings.Monitor, _id, zoneCount, zoneArray);
} }
private static readonly string _registryPath = Settings.RegistryPath + "\\Layouts";
private static readonly string _fullRegistryPath = Settings.FullRegistryPath + "\\Layouts";
} }
} }

View File

@@ -39,25 +39,25 @@ namespace FancyZonesEditor
ParseCommandLineArgs(); ParseCommandLineArgs();
// Initialize the five default layout models: Focus, Columns, Rows, Grid, and PriorityGrid // Initialize the five default layout models: Focus, Columns, Rows, Grid, and PriorityGrid
_defaultModels = new List<LayoutModel>(5); DefaultModels = new List<LayoutModel>(5);
_focusModel = new CanvasLayoutModel("Focus", _focusModelId, (int)_workArea.Width, (int)_workArea.Height); _focusModel = new CanvasLayoutModel("Focus", _focusModelId, (int)_workArea.Width, (int)_workArea.Height);
_defaultModels.Add(_focusModel); DefaultModels.Add(_focusModel);
_columnsModel = new GridLayoutModel("Columns", _columnsModelId); _columnsModel = new GridLayoutModel("Columns", _columnsModelId);
_columnsModel.Rows = 1; _columnsModel.Rows = 1;
_columnsModel.RowPercents = new int[1] { c_multiplier }; _columnsModel.RowPercents = new int[1] { _multiplier };
_defaultModels.Add(_columnsModel); DefaultModels.Add(_columnsModel);
_rowsModel = new GridLayoutModel("Rows", _rowsModelId); _rowsModel = new GridLayoutModel("Rows", _rowsModelId);
_rowsModel.Columns = 1; _rowsModel.Columns = 1;
_rowsModel.ColumnPercents = new int[1] { c_multiplier }; _rowsModel.ColumnPercents = new int[1] { _multiplier };
_defaultModels.Add(_rowsModel); DefaultModels.Add(_rowsModel);
_gridModel = new GridLayoutModel("Grid", _gridModelId); _gridModel = new GridLayoutModel("Grid", _gridModelId);
_defaultModels.Add(_gridModel); DefaultModels.Add(_gridModel);
_priorityGridModel = new GridLayoutModel("Priority Grid", _priorityGridModelId); _priorityGridModel = new GridLayoutModel("Priority Grid", _priorityGridModelId);
_defaultModels.Add(_priorityGridModel); DefaultModels.Add(_priorityGridModel);
_blankCustomModel = new CanvasLayoutModel("Create new custom", _blankCustomModelId, (int)_workArea.Width, (int)_workArea.Height); _blankCustomModel = new CanvasLayoutModel("Create new custom", _blankCustomModelId, (int)_workArea.Width, (int)_workArea.Height);
@@ -226,7 +226,7 @@ namespace FancyZonesEditor
{ {
_rowsModel.CellChildMap[i, 0] = i; _rowsModel.CellChildMap[i, 0] = i;
_columnsModel.CellChildMap[0, i] = i; _columnsModel.CellChildMap[0, i] = i;
_rowsModel.RowPercents[i] = c_multiplier / ZoneCount; // _columnsModel is sharing the same array _rowsModel.RowPercents[i] = _multiplier / ZoneCount; // _columnsModel is sharing the same array
} }
// Update the "Grid" Default Layout // Update the "Grid" Default Layout
@@ -258,12 +258,12 @@ namespace FancyZonesEditor
for (int row = 0; row < rows; row++) for (int row = 0; row < rows; row++)
{ {
_gridModel.RowPercents[row] = c_multiplier / rows; _gridModel.RowPercents[row] = _multiplier / rows;
} }
for (int col = 0; col < cols; col++) for (int col = 0; col < cols; col++)
{ {
_gridModel.ColumnPercents[col] = c_multiplier / cols; _gridModel.ColumnPercents[col] = _multiplier / cols;
} }
int index = 0; int index = 0;
@@ -297,10 +297,10 @@ namespace FancyZonesEditor
private void ParseCommandLineArgs() private void ParseCommandLineArgs()
{ {
_workArea = System.Windows.SystemParameters.WorkArea; _workArea = SystemParameters.WorkArea;
Monitor = 0; Monitor = 0;
_uniqueRegistryPath = FullRegistryPath; _uniqueRegistryPath = FullRegistryPath;
UniqueKey = ""; UniqueKey = string.Empty;
Dpi = 1; Dpi = 1;
string[] args = Environment.GetCommandLineArgs(); string[] args = Environment.GetCommandLineArgs();
@@ -345,10 +345,7 @@ namespace FancyZonesEditor
} }
} }
public IList<LayoutModel> DefaultModels public IList<LayoutModel> DefaultModels { get; }
{
get { return _defaultModels; }
}
public ObservableCollection<LayoutModel> CustomModels public ObservableCollection<LayoutModel> CustomModels
{ {
@@ -383,8 +380,6 @@ namespace FancyZonesEditor
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
} }
// storage for Default Layout Models
private IList<LayoutModel> _defaultModels;
private CanvasLayoutModel _focusModel; private CanvasLayoutModel _focusModel;
private GridLayoutModel _rowsModel; private GridLayoutModel _rowsModel;
private GridLayoutModel _columnsModel; private GridLayoutModel _columnsModel;
@@ -416,6 +411,6 @@ namespace FancyZonesEditor
new byte[] { 0, 0, 0, 0, 0, 3, 4, 13, 5, 13, 6, 13, 5, 9, 196, 9, 196, 9, 196, 9, 196, 0, 1, 2, 3, 4, 1, 5, 6, 7, 8, 9, 10 }, new byte[] { 0, 0, 0, 0, 0, 3, 4, 13, 5, 13, 6, 13, 5, 9, 196, 9, 196, 9, 196, 9, 196, 0, 1, 2, 3, 4, 1, 5, 6, 7, 8, 9, 10 },
}; };
private const int c_multiplier = 10000; private const int _multiplier = 10000;
} }
} }

View File

@@ -0,0 +1,27 @@
// 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.Runtime.InteropServices;
namespace FancyZonesEditor
{
// PInvokes to handshake with fancyzones backend
internal static class Native
{
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Ansi)]
public static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)]string lpFileName);
[DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
public static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
internal delegate int PersistZoneSet(
[MarshalAs(UnmanagedType.LPWStr)] string activeKey,
[MarshalAs(UnmanagedType.LPWStr)] string resolutionKey,
uint monitor,
ushort layoutId,
int zoneCount,
[MarshalAs(UnmanagedType.LPArray)] int[] zoneArray);
}
}

View File

@@ -6,6 +6,16 @@ namespace FancyZonesEditor
{ {
public class RowColInfo public class RowColInfo
{ {
private const int _multiplier = 10000;
public double Extent { get; set; }
public double Start { get; set; }
public double End { get; set; }
public int Percent { get; set; }
public RowColInfo(int percent) public RowColInfo(int percent)
{ {
Percent = percent; Percent = percent;
@@ -13,15 +23,13 @@ namespace FancyZonesEditor
public RowColInfo(int index, int count) public RowColInfo(int index, int count)
{ {
Percent = (c_multiplier / count) + ((index == 0) ? (c_multiplier % count) : 0); Percent = (_multiplier / count) + ((index == 0) ? (_multiplier % count) : 0);
} }
private const int c_multiplier = 10000; public double Recalculate(double start, double totalExtent)
public double SetExtent(double start, double totalExtent)
{ {
Start = start; Start = start;
Extent = totalExtent * Percent / c_multiplier; Extent = totalExtent * Percent / _multiplier;
End = Start + Extent; End = Start + Extent;
return Extent; return Extent;
} }
@@ -35,10 +43,5 @@ namespace FancyZonesEditor
info[1] = new RowColInfo(Percent - newPercent); info[1] = new RowColInfo(Percent - newPercent);
return info; return info;
} }
public int Percent;
public double Extent;
public double Start;
public double End;
} }
} }