Browse Source

- Raster Placement support!

- Aviability to Enable/Disable Raster and Snapline Placement from the Zoom Control (like in VS2012)
- Fix in Snapline Placement that you can also Position to 0!
pull/52/head
jkuehner 12 years ago
parent
commit
f34a5e8da8
  1. 39
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs
  2. 19
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.xaml
  3. 123
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RasterPlacementBehavior.cs
  4. 11
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs
  5. BIN
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Raster.png
  6. BIN
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Snapline.png
  7. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

39
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs

@ -16,7 +16,7 @@ using ICSharpCode.WpfDesign.Designer.Controls; @@ -16,7 +16,7 @@ using ICSharpCode.WpfDesign.Designer.Controls;
namespace ICSharpCode.WpfDesign.Designer
{
sealed class DesignPanel : Decorator, IDesignPanel
sealed class DesignPanel : Decorator, IDesignPanel, INotifyPropertyChanged
{
#region Hit Testing
/// <summary>
@ -182,6 +182,36 @@ namespace ICSharpCode.WpfDesign.Designer @@ -182,6 +182,36 @@ namespace ICSharpCode.WpfDesign.Designer
set { _adornerLayer.IsHitTestVisible = value; }
}
/// <summary>
/// Enables / Disables the Snapline Placement
/// </summary>
private bool _useSnaplinePlacement = true;
public bool UseSnaplinePlacement
{
get { return _useSnaplinePlacement; }
set { _useSnaplinePlacement = value; OnPropertyChanged("UseSnaplinePlacement"); }
}
/// <summary>
/// Enables / Disables the Raster Placement
/// </summary>
private bool _useRasterPlacement = false;
public bool UseRasterPlacement
{
get { return _useRasterPlacement; }
set { _useRasterPlacement = value; OnPropertyChanged("UseRasterPlacement"); }
}
/// <summary>
/// Sets the with of the Raster when using Raster Placement
/// </summary>
private int _rasterWidth = 5;
public int RasterWidth
{
get { return _rasterWidth; }
set { _rasterWidth = value; OnPropertyChanged("RasterWidth"); }
}
#endregion
#region Visual Child Management
@ -260,5 +290,12 @@ namespace ICSharpCode.WpfDesign.Designer @@ -260,5 +290,12 @@ namespace ICSharpCode.WpfDesign.Designer
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}

19
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.xaml

@ -3,9 +3,28 @@ @@ -3,9 +3,28 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Default="clr-namespace:ICSharpCode.WpfDesign.Designer"
xmlns:Controls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls"
xmlns:Widgets="http://icsharpcode.net/sharpdevelop/widgets"
DataContext="{x:Null}"
Background="#888">
<Controls:ZoomControl x:Name="uxZoom" AlwaysShowZoomButtons="True" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible">
<Controls:ZoomControl.AdditionalControls>
<StackPanel Orientation="Horizontal">
<Controls:EnumButton DataContext="{Binding ElementName=_designPanel}" Margin="0" MinWidth="16" Height="16" Width="16" IsChecked="{Binding ElementName=_designPanel, Path=UseRasterPlacement, Mode=TwoWay}" ToolTip="Use Raster Placement">
<Controls:EnumButton.ContextMenu>
<ContextMenu DataContext="{Binding PlacementTarget.DataContext,RelativeSource={RelativeSource Self}}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="RasterWidth:" />
<Widgets:NumericUpDown Width="40" Margin="5,0,0,0" Value="{Binding Path=RasterWidth, Mode=TwoWay}"/>
</StackPanel>
</ContextMenu>
</Controls:EnumButton.ContextMenu>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/Raster.png" Stretch="Uniform" />
</Controls:EnumButton>
<Controls:EnumButton Margin="0" MinWidth="16" Height="16" Width="16" IsChecked="{Binding ElementName=_designPanel, Path=UseSnaplinePlacement, Mode=TwoWay}" ToolTip="Use Snapline Placement">
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/Snapline.png" Stretch="Uniform" />
</Controls:EnumButton>
</StackPanel>
</Controls:ZoomControl.AdditionalControls>
<Default:DesignPanel x:Name="_designPanel">
<!-- Reset some inherited properties to the WPF defaults to avoid values from SharpDevelop applying to designed forms. -->
<Border x:Name="_sceneContainer" AllowDrop="False" UseLayoutRounding="False" TextOptions.TextFormattingMode="Ideal" />

123
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RasterPlacementBehavior.cs

@ -0,0 +1,123 @@ @@ -0,0 +1,123 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
public class RasterPlacementBehavior : DefaultPlacementBehavior
{
int raster = 5;
Canvas surface;
AdornerPanel adornerPanel;
private bool rasterDrawn = false;
public override void BeginPlacement(PlacementOperation operation)
{
base.BeginPlacement(operation);
raster = ((DesignPanel) ExtendedItem.Services.DesignPanel).RasterWidth;
CreateSurface(operation);
}
public override void EndPlacement(PlacementOperation operation)
{
base.EndPlacement(operation);
DeleteSurface();
}
public override void EnterContainer(PlacementOperation operation)
{
base.EnterContainer(operation);
CreateSurface(operation);
}
public override void LeaveContainer(PlacementOperation operation)
{
base.LeaveContainer(operation);
DeleteSurface();
}
void CreateSurface(PlacementOperation operation)
{
if (ExtendedItem.Services.GetService<IDesignPanel>() != null)
{
surface = new Canvas();
adornerPanel = new AdornerPanel();
adornerPanel.SetAdornedElement(ExtendedItem.View, ExtendedItem);
AdornerPanel.SetPlacement(surface, AdornerPlacement.FillContent);
adornerPanel.Children.Add(surface);
ExtendedItem.Services.DesignPanel.Adorners.Add(adornerPanel);
}
}
void DeleteSurface()
{
rasterDrawn = false;
if (surface != null)
{
ExtendedItem.Services.DesignPanel.Adorners.Remove(adornerPanel);
adornerPanel = null;
surface = null;
}
}
public override void BeforeSetPosition(PlacementOperation operation)
{
base.BeforeSetPosition(operation);
if (surface == null) return;
if (!((DesignPanel) ExtendedItem.Services.DesignPanel).UseRasterPlacement)
return;
if (Keyboard.IsKeyDown(Key.LeftCtrl))
{
surface.Children.Clear();
rasterDrawn = false;
return;
}
drawRaster();
var bounds = operation.PlacedItems[0].Bounds;
bounds.Y = ((int)bounds.Y/raster)*raster;
bounds.X = ((int)bounds.X/raster)*raster;
bounds.Width = Convert.ToInt32((bounds.Width/raster))*raster;
bounds.Height = Convert.ToInt32((bounds.Height/raster))*raster;
operation.PlacedItems[0].Bounds = bounds;
}
private void drawRaster()
{
if (!rasterDrawn)
{
rasterDrawn = true;
var w = ModelTools.GetWidth(ExtendedItem.View);
var h = ModelTools.GetHeight(ExtendedItem.View);
var dash = new DoubleCollection() {1, raster - 1};
for (int i = 0; i <= h; i += raster)
{
var line = new Line()
{
X1 = 0,
Y1 = i,
X2 = w,
Y2 = i,
StrokeThickness = 1,
Stroke = Brushes.Black,
StrokeDashArray = dash,
};
surface.Children.Add(line);
}
}
}
}
}

11
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs

@ -19,7 +19,7 @@ using System.Windows.Input; @@ -19,7 +19,7 @@ using System.Windows.Input;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
public class SnaplinePlacementBehavior : DefaultPlacementBehavior
public class SnaplinePlacementBehavior : RasterPlacementBehavior
{
AdornerPanel adornerPanel;
Canvas surface;
@ -59,6 +59,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -59,6 +59,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
base.BeforeSetPosition(operation);
if (surface == null) return;
if (!((DesignPanel)ExtendedItem.Services.DesignPanel).UseSnaplinePlacement)
return;
surface.Children.Clear();
if (Keyboard.IsKeyDown(Key.LeftCtrl)) return;
@ -167,6 +170,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -167,6 +170,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
var containerRect = new Rect(0, 0, ModelTools.GetWidth(ExtendedItem.View), ModelTools.GetHeight(ExtendedItem.View));
AddLines(containerRect, -Margin, false);
AddLines(containerRect, 0, false);
foreach (var item in ExtendedItem.ContentProperty.CollectionElements
.Except(operation.PlacedItems.Select(f => f.Item)))
{
@ -191,11 +196,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -191,11 +196,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (filter == null || filter.Value.Vertical == VerticalAlignment.Top)
h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Top - 1, Start = r.Left, End = r.Right });
if (filter == null || filter.Value.Vertical == VerticalAlignment.Bottom)
h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Bottom, Start = r.Left, End = r.Right });
h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Bottom - 1, Start = r.Left, End = r.Right });
if (filter == null || filter.Value.Horizontal == HorizontalAlignment.Left)
v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Left - 1, Start = r.Top, End = r.Bottom });
if (filter == null || filter.Value.Horizontal == HorizontalAlignment.Right)
v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Right, Start = r.Top, End = r.Bottom });
v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Right - 1, Start = r.Top, End = r.Bottom });
}
void AddBaseline(DesignItem item, Rect bounds, List<Snapline> list)

BIN
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Raster.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 B

BIN
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Snapline.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

@ -129,6 +129,7 @@ @@ -129,6 +129,7 @@
<Compile Include="Extensions\InPlaceEditorExtension.cs" />
<Compile Include="Extensions\MarginHandleExtension.cs" />
<Compile Include="Extensions\QuickOperationMenuExtension.cs" />
<Compile Include="Extensions\RasterPlacementBehavior.cs" />
<Compile Include="Extensions\SizeDisplayExtension.cs" />
<Compile Include="Extensions\SnaplinePlacementBehavior.cs">
<SubType>Code</SubType>
@ -331,4 +332,8 @@ @@ -331,4 +332,8 @@
<ItemGroup>
<CodeAnalysisDictionary Include="Configuration\CodeAnalysisDictionary.xml" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\Raster.png" />
<Resource Include="Images\Snapline.png" />
</ItemGroup>
</Project>
Loading…
Cancel
Save