Browse Source

Code Cleanup -> Line and Polyline Handlers

pull/637/head
jkuehner 11 years ago
parent
commit
e5da9a8282
  1. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs
  2. 7
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs
  3. 20
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs
  4. 37
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs
  5. 11
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs

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

@ -300,6 +300,11 @@ namespace ICSharpCode.WpfDesign.Designer @@ -300,6 +300,11 @@ namespace ICSharpCode.WpfDesign.Designer
Metadata.AddDefaultPropertyValue(typeof(Line), Line.StrokeThicknessProperty, 2d);
Metadata.AddDefaultPropertyValue(typeof(Line), Line.StretchProperty, Stretch.None);
Metadata.AddDefaultPropertyValue(typeof(Polyline), Polyline.PointsProperty, new PointCollection() { new Point(0, 0), new Point(20, 20) });
Metadata.AddDefaultPropertyValue(typeof(Polyline), Polyline.StrokeProperty, Brushes.Black);
Metadata.AddDefaultPropertyValue(typeof(Polyline), Polyline.StrokeThicknessProperty, 2d);
Metadata.AddDefaultPropertyValue(typeof(Polyline), Polyline.StretchProperty, Stretch.None);
Metadata.AddDefaultPropertyValue(typeof(Rectangle), Rectangle.FillProperty, Brushes.Transparent);
Metadata.AddDefaultPropertyValue(typeof(Rectangle), Rectangle.StrokeProperty, Brushes.Black);
Metadata.AddDefaultPropertyValue(typeof(Rectangle), Rectangle.StrokeThicknessProperty, 2d);

7
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs

@ -150,11 +150,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -150,11 +150,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
protected void SetSurfaceInfo(int x, int y, string s)
{
if (_text == null)
{
_text = new TextBlock();
if (_text == null) {
_text = new TextBlock(){ FontSize = 8, FontStyle = FontStyles.Italic };
_surface.Children.Add(_text);
}
AdornerPanel ap = _surface.Parent as AdornerPanel;
_surface.Width = ap.Width;
@ -163,7 +163,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -163,7 +163,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
_text.Text = s;
Canvas.SetLeft(_text, x);
Canvas.SetTop(_text, y);
}
protected void HideSizeAndShowHandles()

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

@ -91,7 +91,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -91,7 +91,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
}
SetSurfaceInfo(0, 0, Math.Round((180 / Math.PI) * Math.Atan2(y, x), 0).ToString());
SetSurfaceInfo(0, 3, Math.Round((180 / Math.PI) * Math.Atan2(y, x), 0).ToString());
return new Bounds { X = Math.Round(x, 1), Y = Math.Round(y, 1), Left = Math.Round(left, 1), Top = Math.Round(top, 1) };
}
@ -130,16 +130,15 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -130,16 +130,15 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
double dx = 0;
double dy = 0;
if (zoom != null)
{
if (zoom != null) {
dx = drag.Delta.X * (1 / zoom.CurrentZoom);
dy = drag.Delta.Y * (1 / zoom.CurrentZoom);
}
double top, left, x, y, xtop, xleft;
if (alignment == PlacementAlignment.TopLeft)
{
if (alignment == PlacementAlignment.TopLeft) {
//normal values
x = CurrentX2 - dx;
y = CurrentY2 - dy;
@ -150,14 +149,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -150,14 +149,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
xtop = CurrentTop + CurrentY2;
xleft = CurrentLeft + CurrentX2;
}
else
{
} else {
x = CurrentX2 + dx;
y = CurrentY2 + dy;
top = xtop = CurrentTop;
left = xleft = CurrentLeft;
}
Bounds position = CalculateDrawing(x, y, left, top, xleft, xtop);
ExtendedItem.Properties.GetProperty(Line.X1Property).SetValue(0);
@ -165,8 +163,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -165,8 +163,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
ExtendedItem.Properties.GetProperty(Line.X2Property).SetValue(position.X);
ExtendedItem.Properties.GetProperty(Line.Y2Property).SetValue(position.Y);
if (operation != null)
{
if (operation != null) {
var result = info.OriginalBounds;
result.X = position.Left;
result.Y = position.Top;
@ -177,6 +174,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -177,6 +174,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
operation.CurrentContainerBehavior.BeforeSetPosition(operation);
operation.CurrentContainerBehavior.SetPosition(info);
}
(drag.Target as ResizeThumb).InvalidateArrange();
ResetWidthHeightProperties();
}

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

@ -33,6 +33,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -33,6 +33,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
{
get; set;
}
public PointTrackerPlacementSupport(Shape s, PlacementAlignment align, int index)
{
shape = s;
@ -40,51 +41,32 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -40,51 +41,32 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
Index = index;
}
public PointTrackerPlacementSupport(Shape s, PlacementAlignment align)
{
shape = s;
alignment = align;
Index = -1;
}
/// <summary>
/// Arranges the adorner element on the specified adorner panel.
/// </summary>
public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize)
{
Point p = new Point(0, 0);
double thumbsize = 7;
double distance = 0;// thumbsize / 2;
double thumbsize = 7;
double distance = 0;
if (shape as Line != null)
{
Line s = shape as Line;
double x, y;
//will give you the angle of the line if more than 180 degrees it becomes negative from
Double theta = (180 / Math.PI) * Math.Atan2(s.Y2 - s.Y1, s.X2 - s.X1);
//this will give you the x offset from the line x point in parts of half the size of the thumb
double dx = Math.Cos(theta * (Math.PI / 180)) * distance;
//this will give you the y offset from the line y point in parts of half the size of the thumb
double dy = Math.Sin(theta * (Math.PI / 180)) * distance;
if (alignment == PlacementAlignment.BottomRight)
{
//x offset is linear
x = s.X2 - Math.Abs(theta) / (180 / thumbsize) + dx;
//y offset is angular
y = s.Y2 - ((.5 - Math.Sin(theta * (Math.PI / 180)) * .5) * thumbsize) + dy;
x = s.X2;
y = s.Y2;
}
else
{
x = s.X1 - ((180 - Math.Abs(theta)) / (180 / thumbsize)) - dx;
y = s.Y1 - ((.5 - Math.Sin(theta * (Math.PI / 180) + Math.PI) * .5) * thumbsize) - dy;
x = s.X1;
y = s.Y1;
}
p = new Point(x, y);
}
Polygon pg = shape as Polygon;
Polyline pl = shape as Polyline;
if (pg != null || pl != null)
@ -92,10 +74,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -92,10 +74,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (Index > 0)
{
p = pl != null ? pl.Points[Index] : pg.Points[Index];
}
}
adorner.Arrange(new Rect(p, new Size(thumbsize, thumbsize)));
adorner.Arrange(new Rect(p.X - thumbsize / 2, p.Y - thumbsize / 2, thumbsize, thumbsize)); //thumbsize, thumbsize)));
}

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

@ -303,8 +303,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -303,8 +303,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
ChangeOperation(points);
(drag.Target as ResizeThumb).InvalidateArrange();
}
protected void drag_Completed(DragListener drag)
@ -332,15 +330,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -332,15 +330,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
PointCollection points = GetPointCollection();
if (ExtendedItem.Properties[Shape.StrokeProperty].ValueOnInstance == null)
{
ExtendedItem.Properties[Shape.StrokeProperty].SetValue(Colors.Black);
ExtendedItem.Properties[Shape.StrokeThicknessProperty].SetValue(2d);
ExtendedItem.Properties[Shape.StretchProperty].SetValue(Stretch.None);
points.AddRange(new List<Point> { new Point(0, 0), new Point(20, 20) });
ExtendedItem.Properties.GetProperty(ExtendedItem.View as Polyline != null ? Polyline.PointsProperty : Polygon.PointsProperty).SetValue(points);
}
resizeThumbs = new List<ResizeThumb>();
for (int i = 1; i < points.Count; i++)
{

Loading…
Cancel
Save