Browse Source

- Fix Context Menu's when Transforms are used

- Snap Path Point Thumbs
pull/633/head
jogibear9988 11 years ago
parent
commit
26dedf8ae0
  1. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml
  2. 17
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs
  3. 14
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/PointThumb.cs
  4. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs
  5. 21
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs
  6. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs
  7. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/QuickOperationMenuExtension.cs
  8. 25
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RasterPlacementBehavior.cs
  9. 107
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs
  10. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/RootItemBehavior.cs
  11. 19
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs
  12. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementBehavior.cs

6
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml

@ -81,14 +81,15 @@ @@ -81,14 +81,15 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:PointThumb}">
<Grid>
<Grid Width="7" Height="7" Margin="-3.5,-3.5,0,0" HorizontalAlignment="Left" VerticalAlignment="Top">
<Line HorizontalAlignment="Left" VerticalAlignment="Top" Stroke="{TemplateBinding Foreground}" StrokeThickness="1" StrokeDashArray="2 2" X1="3.5" Y1="3.5" X2="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=RelativeToPoint.X}" Y2="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=RelativeToPoint.Y}" Visibility="{Binding Path=RelativeToPoint, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static Converters:CollapsedWhenNull.Instance}}" />
<Grid RenderTransform="{TemplateBinding InnerRenderTransform}">
<Grid.Resources>
<Style TargetType="MenuItem">
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Center" />
</Style>
</Grid.Resources>
<Line HorizontalAlignment="Left" VerticalAlignment="Top" Stroke="{TemplateBinding Foreground}" StrokeThickness="1" StrokeDashArray="2 2" X1="3.5" Y1="3.5" X2="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=RelativeToPoint.X}" Y2="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=RelativeToPoint.Y}" Visibility="{Binding Path=RelativeToPoint, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static Converters:CollapsedWhenNull.Instance}}" />
<Rectangle HorizontalAlignment="Left" VerticalAlignment="Top" Width="7" Height="7" Name="thumbRectangle" SnapsToDevicePixels="True" Stroke="{TemplateBinding Foreground}" Fill="White" RadiusX="1.414" RadiusY="1.414" />
<Ellipse HorizontalAlignment="Left" VerticalAlignment="Top" Width="7" Height="7" Name="thumbElipse" Stroke="{TemplateBinding Foreground}" SnapsToDevicePixels="True" Fill="White" Visibility="Collapsed" />
<Menu Height="15" HorizontalAlignment="Left" Margin="0,-19,-19,0" VerticalAlignment="Top" Width="15" BorderThickness="0" Background="Transparent" Visibility="{Binding Path=OperationMenu, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static Converters:CollapsedWhenNull.Instance}}" >
@ -99,6 +100,7 @@ @@ -99,6 +100,7 @@
</MenuItem>
</Menu>
</Grid>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsPrimarySelection" Value="False">
<Setter TargetName="thumbRectangle" Property="Stroke" Value="White" />

17
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs

@ -39,12 +39,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -39,12 +39,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
}
public QuickOperationMenu()
{
scaleTransform = new ScaleTransform(1.0, 1.0);
this.LayoutTransform = scaleTransform;
}
private ScaleTransform scaleTransform;
{ }
private MenuItem _mainHeader;
@ -96,16 +91,6 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -96,16 +91,6 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
if (mainHeader != null) {
_mainHeader = mainHeader;
}
var surface = this.TryFindParent<DesignSurface>();
if (surface != null && surface.ZoomControl != null)
{
var bnd = new Binding("CurrentZoom") { Source = surface.ZoomControl };
bnd.Converter = InvertedZoomConverter.Instance;
BindingOperations.SetBinding(scaleTransform, ScaleTransform.ScaleXProperty, bnd);
BindingOperations.SetBinding(scaleTransform, ScaleTransform.ScaleYProperty, bnd);
}
}
/// <summary>

14
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/PointThumb.cs

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE.
using System.Windows;
using System.Windows.Media;
using ICSharpCode.WpfDesign.Adorners;
using System.Windows.Data;
@ -27,6 +28,16 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -27,6 +28,16 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
/// </summary>
public class PointThumb : DesignerThumb
{
public Transform InnerRenderTransform
{
get { return (Transform)GetValue(InnerRenderTransformProperty); }
set { SetValue(InnerRenderTransformProperty, value); }
}
// Using a DependencyProperty as the backing store for InnerRenderTransform. This enables animation, styling, binding, etc...
public static readonly DependencyProperty InnerRenderTransformProperty =
DependencyProperty.Register("InnerRenderTransform", typeof(Transform), typeof(PointThumb), new PropertyMetadata(null));
public bool IsEllipse
{
get { return (bool)GetValue(IsEllipseProperty); }
@ -97,8 +108,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -97,8 +108,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize)
{
double thumbsize = 7;
adorner.Arrange(new Rect(p.X - thumbsize / 2, p.Y - thumbsize / 2, adornedElementSize.Width, adornedElementSize.Height));
adorner.Arrange(new Rect(p.X, p.Y, adornedElementSize.Width, adornedElementSize.Height));
}
}
}

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs

@ -175,5 +175,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -175,5 +175,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
}
}
public virtual Point PlacePoint(Point point)
{
return point;
}
}
}

21
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs

@ -129,17 +129,15 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -129,17 +129,15 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
protected class RelativeToPointConverter : IValueConverter
{
PathPoint pathPoint;
Shape shape;
public RelativeToPointConverter(PathPoint pathPoint/*, Shape shape*/)
public RelativeToPointConverter(PathPoint pathPoint)
{
this.pathPoint = pathPoint;
//this.shape = shape;
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var pt = (Point)value;
return pt - new Vector(pathPoint.TranslatedPoint.X - 3.5, pathPoint.TranslatedPoint.Y - 3.5);
return pt - new Vector(pathPoint.TranslatedPoint.X, pathPoint.TranslatedPoint.Y);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
@ -209,6 +207,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -209,6 +207,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
var designerThumb = new PathThumb(index, pathpoint) {Cursor = cursor};
designerThumb.OperationMenu = BuildMenu(pathpoint);
designerThumb.InnerRenderTransform = ((Transform)transform.Inverse);
if (pathpoint.TargetPathPoint != null) {
designerThumb.IsEllipse = true;
designerThumb.Foreground = Brushes.Blue;
@ -243,8 +243,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -243,8 +243,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
var point = senderThumb.PathPoint.Point;
if (pathSegment is PolyLineSegment)
{
if (pathSegment is PolyLineSegment) {
var poly = pathSegment as PolyLineSegment;
var lst = poly.Points.Take(senderThumb.PathPoint.PolyLineIndex);
var lst2 = poly.Points.Skip(senderThumb.PathPoint.PolyLineIndex + 1);
@ -259,6 +258,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -259,6 +258,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
p2.Points.AddRange(lst2);
pathFigure.Segments.Insert(idx+2, p2);
idx++;
} else if (pathSegment is PolyBezierSegment) {
//TODO
} else if (pathSegment is PolyQuadraticBezierSegment) {
//TODO
}
pathFigure.Segments.RemoveAt(idx);
@ -566,6 +569,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -566,6 +569,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
List<PathPoint> MovePoints(List<PathPoint> pc, double displacementX, double displacementY)
{
var relativeTo = new Vector(operation.PlacedItems[0].Bounds.TopLeft.X, operation.PlacedItems[0].Bounds.TopLeft.Y);
//iterate all selected points
foreach (int i in _selectedThumbs.Keys) {
Point p = pc[i].TranslatedPoint;
@ -576,6 +581,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -576,6 +581,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
p.X = x;
p.Y = y;
p = operation.CurrentContainerBehavior.PlacePoint(p + relativeTo) - relativeTo;
pc[i].TranslatedPoint = p;
}
return pc;

3
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs

@ -47,7 +47,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -47,7 +47,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize)
{
Point p = new Point(0, 0);
double thumbsize = 7;
double distance = 0;
if (shape is Line)
{
@ -76,7 +75,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -76,7 +75,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
var transform = shape.RenderedGeometry.Transform;
p = transform.Transform(p);
adorner.Arrange(new Rect(p.X - thumbsize / 2, p.Y - thumbsize / 2, thumbsize, thumbsize)); //thumbsize, thumbsize)));
adorner.Arrange(new Rect(p.X - 3.5, p.Y - 3.5, 7, 7));
}
}
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/QuickOperationMenuExtension.cs

@ -20,6 +20,7 @@ using System; @@ -20,6 +20,7 @@ using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using ICSharpCode.SharpDevelop.Widgets;
using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Extensions;
@ -43,6 +44,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -43,6 +44,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
base.OnInitialized();
_menu = new QuickOperationMenu();
_menu.Loaded += OnMenuLoaded;
_menu.RenderTransform = ((Transform)this.ExtendedItem.GetCompleteAppliedTransformationToView().Inverse);
var placement = new RelativePlacement(HorizontalAlignment.Right, VerticalAlignment.Top) {XOffset = 7, YOffset = 3.5};
this.AddAdorners(placement, _menu);

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

@ -23,6 +23,7 @@ using System.Windows.Media; @@ -23,6 +23,7 @@ using System.Windows.Media;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls;
using System.Windows;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
@ -112,6 +113,30 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -112,6 +113,30 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
operation.PlacedItems[0].Bounds = bounds;
}
public override Point PlacePoint(Point point)
{
if (surface == null)
return base.PlacePoint(point);
DesignPanel designPanel = ExtendedItem.Services.DesignPanel as DesignPanel;
if (designPanel == null || !designPanel.UseRasterPlacement)
return base.PlacePoint(point);
if (Keyboard.IsKeyDown(Key.LeftCtrl))
{
surface.Children.Clear();
rasterDrawn = false;
return base.PlacePoint(point);
}
drawRaster();
point.Y = ((int)point.Y / raster) * raster;
point.X = ((int)point.X / raster) * raster;
return point;
}
private void drawRaster()
{
if (!rasterDrawn)

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

@ -78,6 +78,57 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -78,6 +78,57 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
DeleteSurface();
}
public override Point PlacePoint(Point point)
{
if (surface == null)
return base.PlacePoint(point);
DesignPanel designPanel = ExtendedItem.Services.DesignPanel as DesignPanel;
if (designPanel == null || !designPanel.UseSnaplinePlacement)
return base.PlacePoint(point); ;
surface.Children.Clear();
if (Keyboard.IsKeyDown(Key.LeftCtrl))
return base.PlacePoint(point); ;
Rect bounds = new Rect(point.X, point.Y, 0, 0);
var horizontalInput = new List<Snapline>();
var verticalInput = new List<Snapline>();
AddLines(bounds, 0, false, horizontalInput, verticalInput, null);
if (baseline.HasValue)
{
var textOffset = bounds.Top + baseline.Value;
horizontalInput.Add(new Snapline() { Group = 1, Offset = textOffset, Start = bounds.Left, End = bounds.Right });
}
List<Snapline> drawLines;
double delta;
if (Snap(horizontalInput, horizontalMap, Accuracy, out drawLines, out delta))
{
foreach (var d in drawLines)
{
DrawLine(d.Start, d.Offset + d.DrawOffset, d.End, d.Offset + d.DrawOffset);
}
point.Y += delta;
}
if (Snap(verticalInput, verticalMap, Accuracy, out drawLines, out delta))
{
foreach (var d in drawLines)
{
DrawLine(d.Offset + d.DrawOffset, d.Start, d.Offset + d.DrawOffset, d.End);
}
point.X += delta;
}
return point;
}
public override void BeforeSetPosition(PlacementOperation operation)
{
base.BeforeSetPosition(operation);
@ -99,11 +150,15 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -99,11 +150,15 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
var verticalInput = new List<Snapline>();
var info = operation.PlacedItems[0];
if (operation.Type == PlacementType.Resize) {
if (operation.Type == PlacementType.Resize)
{
AddLines(bounds, 0, false, horizontalInput, verticalInput, info.ResizeThumbAlignment);
} else {
}
else
{
AddLines(bounds, 0, false, horizontalInput, verticalInput, null);
if (baseline.HasValue) {
if (baseline.HasValue)
{
var textOffset = bounds.Top + baseline.Value;
horizontalInput.Add(new Snapline() { Group = 1, Offset = textOffset, Start = bounds.Left, End = bounds.Right });
}
@ -121,48 +176,66 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -121,48 +176,66 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
List<Snapline> drawLines;
double delta;
if (Snap(horizontalInput, horizontalMap, Accuracy, out drawLines, out delta)) {
if (Snap(horizontalInput, horizontalMap, Accuracy, out drawLines, out delta))
{
if (operation.Type == PlacementType.Resize) {
if (info.ResizeThumbAlignment != null && info.ResizeThumbAlignment.Value.Vertical == VerticalAlignment.Top) {
if (operation.Type == PlacementType.Resize)
{
if (info.ResizeThumbAlignment != null && info.ResizeThumbAlignment.Value.Vertical == VerticalAlignment.Top)
{
bounds.Y += delta;
bounds.Height = Math.Max(0, bounds.Height - delta);
} else {
}
else
{
bounds.Height = Math.Max(0, bounds.Height + delta);
}
info.Bounds = bounds;
} else {
foreach (var item in operation.PlacedItems) {
}
else
{
foreach (var item in operation.PlacedItems)
{
var r = item.Bounds;
r.Y += delta;
item.Bounds = r;
}
}
foreach (var d in drawLines) {
foreach (var d in drawLines)
{
DrawLine(d.Start, d.Offset + d.DrawOffset, d.End, d.Offset + d.DrawOffset);
}
}
if (Snap(verticalInput, verticalMap, Accuracy, out drawLines, out delta)) {
if (Snap(verticalInput, verticalMap, Accuracy, out drawLines, out delta))
{
if (operation.Type == PlacementType.Resize) {
if (info.ResizeThumbAlignment != null && info.ResizeThumbAlignment.Value.Horizontal == HorizontalAlignment.Left) {
if (operation.Type == PlacementType.Resize)
{
if (info.ResizeThumbAlignment != null && info.ResizeThumbAlignment.Value.Horizontal == HorizontalAlignment.Left)
{
bounds.X += delta;
bounds.Width = Math.Max(0, bounds.Width - delta);
} else {
}
else
{
bounds.Width = Math.Max(0, bounds.Width + delta);
}
info.Bounds = bounds;
} else {
foreach (var item in operation.PlacedItems) {
}
else
{
foreach (var item in operation.PlacedItems)
{
var r = item.Bounds;
r.X += delta;
item.Bounds = r;
}
}
foreach (var d in drawLines) {
foreach (var d in drawLines)
{
DrawLine(d.Offset + d.DrawOffset, d.Start, d.Offset + d.DrawOffset, d.End);
}
}

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/RootItemBehavior.cs

@ -94,5 +94,10 @@ namespace ICSharpCode.WpfDesign.Designer @@ -94,5 +94,10 @@ namespace ICSharpCode.WpfDesign.Designer
{
throw new NotImplementedException();
}
public Point PlacePoint(Point point)
{
return point;
}
}
}

19
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs

@ -298,23 +298,20 @@ namespace ICSharpCode.WpfDesign @@ -298,23 +298,20 @@ namespace ICSharpCode.WpfDesign
public Transform GetCompleteAppliedTransformationToView()
{
var retVal = new TransformGroup();
var fe = this.View as FrameworkElement;
while (fe != null) {
if (fe.LayoutTransform != null)
var v = this.View as Visual;
while (v != null) {
var fe = v as FrameworkElement;
if (fe != null && fe.LayoutTransform != null)
retVal.Children.Add(fe.LayoutTransform);
if (fe.RenderTransform != null)
if (fe != null && fe.RenderTransform != null)
retVal.Children.Add(fe.RenderTransform);
if (fe is Viewbox)
{
var scaleX = fe.ActualWidth / ((FrameworkElement)((Viewbox)fe).Child).ActualWidth;
var scaleY = fe.ActualHeight / ((FrameworkElement)((Viewbox)fe).Child).ActualHeight;
retVal.Children.Add(new ScaleTransform(){ScaleX = scaleX, ScaleY = scaleY});
if (v is ContainerVisual && ((ContainerVisual)v).Transform != null) {
retVal.Children.Add(((ContainerVisual)v).Transform);
}
fe = fe.TryFindParent<FrameworkElement>(true);
v = v.TryFindParent<Visual>(true);
}
return retVal;
}
}
}

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementBehavior.cs

@ -78,6 +78,11 @@ namespace ICSharpCode.WpfDesign @@ -78,6 +78,11 @@ namespace ICSharpCode.WpfDesign
/// Let the placed children enter this container.
/// </summary>
void EnterContainer(PlacementOperation operation);
/// <summary>
/// Place Point.
/// </summary>
Point PlacePoint(Point point);
}
/// <summary>

Loading…
Cancel
Save