Browse Source

Merge branch 'DrawLineOnCanvas' of https://github.com/jogibear9988/SharpDevelop into DrawLineOnCanvas

Conflicts:
	src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml
pull/633/head
jkuehner 11 years ago
parent
commit
7306b61777
  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. 15
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPathExtension.cs
  6. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs
  7. 25
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs
  8. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs
  9. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/QuickOperationMenuExtension.cs
  10. 25
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RasterPlacementBehavior.cs
  11. 107
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs
  12. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/RootItemBehavior.cs
  13. 19
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs
  14. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementBehavior.cs

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

@ -81,14 +81,15 @@
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:PointThumb}"> <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> <Grid.Resources>
<Style TargetType="MenuItem"> <Style TargetType="MenuItem">
<Setter Property="HorizontalContentAlignment" Value="Left" /> <Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="VerticalContentAlignment" Value="Center" />
</Style> </Style>
</Grid.Resources> </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" /> <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" /> <Ellipse HorizontalAlignment="Left" VerticalAlignment="Top" Width="7" Height="7" Name="thumbElipse" Stroke="{TemplateBinding Foreground}" SnapsToDevicePixels="True" Fill="White" Visibility="Collapsed" />
<Menu Foreground="Black" 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}}" > <Menu Foreground="Black" 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 @@
</MenuItem> </MenuItem>
</Menu> </Menu>
</Grid> </Grid>
</Grid>
<ControlTemplate.Triggers> <ControlTemplate.Triggers>
<Trigger Property="IsPrimarySelection" Value="False"> <Trigger Property="IsPrimarySelection" Value="False">
<Setter TargetName="thumbRectangle" Property="Stroke" Value="White" /> <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
} }
public QuickOperationMenu() public QuickOperationMenu()
{ { }
scaleTransform = new ScaleTransform(1.0, 1.0);
this.LayoutTransform = scaleTransform;
}
private ScaleTransform scaleTransform;
private MenuItem _mainHeader; private MenuItem _mainHeader;
@ -96,16 +91,6 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
if (mainHeader != null) { if (mainHeader != null) {
_mainHeader = mainHeader; _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> /// <summary>

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

@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System.Windows; using System.Windows;
using System.Windows.Media;
using ICSharpCode.WpfDesign.Adorners; using ICSharpCode.WpfDesign.Adorners;
using System.Windows.Data; using System.Windows.Data;
@ -27,6 +28,16 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
/// </summary> /// </summary>
public class PointThumb : DesignerThumb 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 public bool IsEllipse
{ {
get { return (bool)GetValue(IsEllipseProperty); } get { return (bool)GetValue(IsEllipseProperty); }
@ -97,8 +108,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize) public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize)
{ {
double thumbsize = 7; adorner.Arrange(new Rect(p.X, p.Y, adornedElementSize.Width, adornedElementSize.Height));
adorner.Arrange(new Rect(p.X - thumbsize / 2, p.Y - thumbsize / 2, adornedElementSize.Width, adornedElementSize.Height));
} }
} }
} }

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

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

15
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPathExtension.cs

@ -76,7 +76,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
//geometryDesignItem.Properties[PathGeometry.FiguresProperty].CollectionElements.Add(figureDesignItem); //geometryDesignItem.Properties[PathGeometry.FiguresProperty].CollectionElements.Add(figureDesignItem);
figureDesignItem.Properties[PathFigure.StartPointProperty].SetValue(new Point(0,0)); figureDesignItem.Properties[PathFigure.StartPointProperty].SetValue(new Point(0,0));
new DrawPathMouseGesture(figure, createdItem, clickedOn.View, changeGroup).Start(panel, (MouseButtonEventArgs) e); new DrawPathMouseGesture(figure, createdItem, clickedOn.View, changeGroup, this.ExtendedItem.GetCompleteAppliedTransformationToView()).Start(panel, (MouseButtonEventArgs) e);
} }
#endregion #endregion
@ -88,13 +88,16 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
private Point sP; private Point sP;
private PathFigure figure; private PathFigure figure;
private DesignItem geometry; private DesignItem geometry;
private Matrix matrix;
public DrawPathMouseGesture(PathFigure figure, DesignItem newLine, IInputElement relativeTo, ChangeGroup changeGroup) public DrawPathMouseGesture(PathFigure figure, DesignItem newLine, IInputElement relativeTo, ChangeGroup changeGroup, Transform transform)
{ {
this.newLine = newLine; this.newLine = newLine;
this.positionRelativeTo = relativeTo; this.positionRelativeTo = relativeTo;
this.changeGroup = changeGroup; this.changeGroup = changeGroup;
this.figure = figure; this.figure = figure;
this.matrix = transform.Value;
matrix.Invert();
sP = Mouse.GetPosition(null); sP = Mouse.GetPosition(null);
@ -109,8 +112,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
protected override void OnMouseMove(object sender, MouseEventArgs e) protected override void OnMouseMove(object sender, MouseEventArgs e)
{ {
var delta = e.GetPosition(null) - sP; var delta = matrix.Transform(e.GetPosition(null) - sP);
var point = new Point(delta.X, delta.Y); var point = new Point(Math.Round(delta.X, 0), Math.Round(delta.Y, 0));
var segment = figure.Segments.LastOrDefault() as LineSegment; var segment = figure.Segments.LastOrDefault() as LineSegment;
if (Mouse.LeftButton == MouseButtonState.Pressed) if (Mouse.LeftButton == MouseButtonState.Pressed)
@ -128,8 +131,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
protected override void OnMouseUp(object sender, MouseButtonEventArgs e) protected override void OnMouseUp(object sender, MouseButtonEventArgs e)
{ {
var delta = e.GetPosition(null) - sP; var delta = matrix.Transform(e.GetPosition(null) - sP);
var point = new Point(delta.X, delta.Y); var point = new Point(Math.Round(delta.X, 0), Math.Round(delta.Y,0));
figure.Segments.Add(new LineSegment(point, false)); figure.Segments.Add(new LineSegment(point, false));
geometry.Properties[PathGeometry.FiguresProperty].SetValue(figure.ToString()); geometry.Properties[PathGeometry.FiguresProperty].SetValue(figure.ToString());

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

@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Windows;
using ICSharpCode.WpfDesign.Extensions; using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.Adorners; using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls; using ICSharpCode.WpfDesign.Designer.Controls;
@ -173,6 +174,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
info.Bounds = result.Round(); info.Bounds = result.Round();
operation.CurrentContainerBehavior.BeforeSetPosition(operation); operation.CurrentContainerBehavior.BeforeSetPosition(operation);
operation.CurrentContainerBehavior.SetPosition(info); operation.CurrentContainerBehavior.SetPosition(info);
// var p = operation.CurrentContainerBehavior.PlacePoint(new Point(position.X, position.Y));
// ExtendedItem.Properties.GetProperty(Line.X2Property).SetValue(p.X);
// ExtendedItem.Properties.GetProperty(Line.Y2Property).SetValue(p.Y);
} }
(drag.Target as DesignerThumb).InvalidateArrange(); (drag.Target as DesignerThumb).InvalidateArrange();

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

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

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

@ -47,7 +47,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize) public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize)
{ {
Point p = new Point(0, 0); Point p = new Point(0, 0);
double thumbsize = 7;
double distance = 0; double distance = 0;
if (shape is Line) if (shape is Line)
{ {
@ -76,7 +75,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
var transform = shape.RenderedGeometry.Transform; var transform = shape.RenderedGeometry.Transform;
p = transform.Transform(p); 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;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media;
using ICSharpCode.SharpDevelop.Widgets; using ICSharpCode.SharpDevelop.Widgets;
using ICSharpCode.WpfDesign.Designer.Controls; using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Extensions; using ICSharpCode.WpfDesign.Extensions;
@ -43,6 +44,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
base.OnInitialized(); base.OnInitialized();
_menu = new QuickOperationMenu(); _menu = new QuickOperationMenu();
_menu.Loaded += OnMenuLoaded; _menu.Loaded += OnMenuLoaded;
_menu.RenderTransform = ((Transform)this.ExtendedItem.GetCompleteAppliedTransformationToView().Inverse);
var placement = new RelativePlacement(HorizontalAlignment.Right, VerticalAlignment.Top) {XOffset = 7, YOffset = 3.5}; var placement = new RelativePlacement(HorizontalAlignment.Right, VerticalAlignment.Top) {XOffset = 7, YOffset = 3.5};
this.AddAdorners(placement, _menu); this.AddAdorners(placement, _menu);

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

@ -23,6 +23,7 @@ using System.Windows.Media;
using System.Windows.Shapes; using System.Windows.Shapes;
using ICSharpCode.WpfDesign.Adorners; using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls; using ICSharpCode.WpfDesign.Designer.Controls;
using System.Windows;
namespace ICSharpCode.WpfDesign.Designer.Extensions namespace ICSharpCode.WpfDesign.Designer.Extensions
{ {
@ -112,6 +113,30 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
operation.PlacedItems[0].Bounds = bounds; 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() private void drawRaster()
{ {
if (!rasterDrawn) if (!rasterDrawn)

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

@ -78,6 +78,57 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
DeleteSurface(); 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) public override void BeforeSetPosition(PlacementOperation operation)
{ {
base.BeforeSetPosition(operation); base.BeforeSetPosition(operation);
@ -99,11 +150,15 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
var verticalInput = new List<Snapline>(); var verticalInput = new List<Snapline>();
var info = operation.PlacedItems[0]; var info = operation.PlacedItems[0];
if (operation.Type == PlacementType.Resize) { if (operation.Type == PlacementType.Resize)
{
AddLines(bounds, 0, false, horizontalInput, verticalInput, info.ResizeThumbAlignment); AddLines(bounds, 0, false, horizontalInput, verticalInput, info.ResizeThumbAlignment);
} else { }
else
{
AddLines(bounds, 0, false, horizontalInput, verticalInput, null); AddLines(bounds, 0, false, horizontalInput, verticalInput, null);
if (baseline.HasValue) { if (baseline.HasValue)
{
var textOffset = bounds.Top + baseline.Value; var textOffset = bounds.Top + baseline.Value;
horizontalInput.Add(new Snapline() { Group = 1, Offset = textOffset, Start = bounds.Left, End = bounds.Right }); horizontalInput.Add(new Snapline() { Group = 1, Offset = textOffset, Start = bounds.Left, End = bounds.Right });
} }
@ -121,48 +176,66 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
List<Snapline> drawLines; List<Snapline> drawLines;
double delta; 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 (operation.Type == PlacementType.Resize)
if (info.ResizeThumbAlignment != null && info.ResizeThumbAlignment.Value.Vertical == VerticalAlignment.Top) { {
if (info.ResizeThumbAlignment != null && info.ResizeThumbAlignment.Value.Vertical == VerticalAlignment.Top)
{
bounds.Y += delta; bounds.Y += delta;
bounds.Height = Math.Max(0, bounds.Height - delta); bounds.Height = Math.Max(0, bounds.Height - delta);
} else { }
else
{
bounds.Height = Math.Max(0, bounds.Height + delta); bounds.Height = Math.Max(0, bounds.Height + delta);
} }
info.Bounds = bounds; info.Bounds = bounds;
} else { }
foreach (var item in operation.PlacedItems) { else
{
foreach (var item in operation.PlacedItems)
{
var r = item.Bounds; var r = item.Bounds;
r.Y += delta; r.Y += delta;
item.Bounds = r; 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); 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 (operation.Type == PlacementType.Resize)
if (info.ResizeThumbAlignment != null && info.ResizeThumbAlignment.Value.Horizontal == HorizontalAlignment.Left) { {
if (info.ResizeThumbAlignment != null && info.ResizeThumbAlignment.Value.Horizontal == HorizontalAlignment.Left)
{
bounds.X += delta; bounds.X += delta;
bounds.Width = Math.Max(0, bounds.Width - delta); bounds.Width = Math.Max(0, bounds.Width - delta);
} else { }
else
{
bounds.Width = Math.Max(0, bounds.Width + delta); bounds.Width = Math.Max(0, bounds.Width + delta);
} }
info.Bounds = bounds; info.Bounds = bounds;
} else { }
foreach (var item in operation.PlacedItems) { else
{
foreach (var item in operation.PlacedItems)
{
var r = item.Bounds; var r = item.Bounds;
r.X += delta; r.X += delta;
item.Bounds = r; 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); 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
{ {
throw new NotImplementedException(); 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
public Transform GetCompleteAppliedTransformationToView() public Transform GetCompleteAppliedTransformationToView()
{ {
var retVal = new TransformGroup(); var retVal = new TransformGroup();
var fe = this.View as FrameworkElement; var v = this.View as Visual;
while (fe != null) { while (v != null) {
if (fe.LayoutTransform != null) var fe = v as FrameworkElement;
if (fe != null && fe.LayoutTransform != null)
retVal.Children.Add(fe.LayoutTransform); retVal.Children.Add(fe.LayoutTransform);
if (fe.RenderTransform != null) if (fe != null && fe.RenderTransform != null)
retVal.Children.Add(fe.RenderTransform); retVal.Children.Add(fe.RenderTransform);
if (fe is Viewbox) if (v is ContainerVisual && ((ContainerVisual)v).Transform != null) {
{ retVal.Children.Add(((ContainerVisual)v).Transform);
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});
} }
fe = fe.TryFindParent<FrameworkElement>(true); v = v.TryFindParent<Visual>(true);
} }
return retVal; return retVal;
} }
} }
} }

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

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

Loading…
Cancel
Save