Browse Source

Merge pull request #659 from gumme/WpfDesignerPublicShapeExtensions

pull/676/head
Andreas Weizel 11 years ago
parent
commit
5f965cb9a4
  1. 8
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs
  2. 12
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs
  3. 24
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs
  4. 38
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs

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

@ -25,19 +25,11 @@ using ICSharpCode.WpfDesign;
using ICSharpCode.WpfDesign.Adorners; using ICSharpCode.WpfDesign.Adorners;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System;
using System.Collections; using System.Collections;
using System.ComponentModel; using System.ComponentModel;
namespace ICSharpCode.WpfDesign.Designer.Extensions namespace ICSharpCode.WpfDesign.Designer.Extensions
{ {
/// <summary>
/// Description of LineExtensionBase.
/// </summary>
class Bounds
{
public double X, Y, Left, Top;
}
/// <summary> /// <summary>
/// base class for the Line, Polyline and Polygon extension classes /// base class for the Line, Polyline and Polygon extension classes
/// </summary> /// </summary>

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

@ -32,8 +32,16 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
/// Description of LineHandlerExtension. /// Description of LineHandlerExtension.
/// </summary> /// </summary>
[ExtensionFor(typeof(Line), OverrideExtensions = new Type[] { typeof(ResizeThumbExtension), typeof(SelectedElementRectangleExtension), typeof(CanvasPositionExtension), typeof(QuickOperationMenuExtension), typeof(RotateThumbExtension), typeof(RenderTransformOriginExtension), typeof(InPlaceEditorExtension), typeof(SkewThumbExtension) })] [ExtensionFor(typeof(Line), OverrideExtensions = new Type[] { typeof(ResizeThumbExtension), typeof(SelectedElementRectangleExtension), typeof(CanvasPositionExtension), typeof(QuickOperationMenuExtension), typeof(RotateThumbExtension), typeof(RenderTransformOriginExtension), typeof(InPlaceEditorExtension), typeof(SkewThumbExtension) })]
internal class LineHandlerExtension : LineExtensionBase public class LineHandlerExtension : LineExtensionBase
{ {
/// <summary>
/// Used instead of Rect to allow negative values on "Width" and "Height" (here called X and Y).
/// </summary>
class Bounds
{
public double X, Y, Left, Top;
}
// //
private double CurrentX2; private double CurrentX2;
private double CurrentY2; private double CurrentY2;
@ -60,7 +68,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
return designerThumb; return designerThumb;
} }
protected Bounds CalculateDrawing(double x, double y, double left, double top, double xleft, double xtop) Bounds CalculateDrawing(double x, double y, double left, double top, double xleft, double xtop)
{ {
Double theta = (180 / Math.PI) * Math.Atan2(y, x); Double theta = (180 / Math.PI) * Math.Atan2(y, x);

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

@ -41,7 +41,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
/// Description of PathHandlerExtension. /// Description of PathHandlerExtension.
/// </summary> /// </summary>
[ExtensionFor(typeof(Path))] [ExtensionFor(typeof(Path))]
internal class PathHandlerExtension : LineExtensionBase, IKeyDown, IKeyUp public class PathHandlerExtension : LineExtensionBase, IKeyDown, IKeyUp
{ {
enum PathPartConvertType enum PathPartConvertType
{ {
@ -159,7 +159,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
} }
} }
private readonly Dictionary<int, Bounds> _selectedThumbs = new Dictionary<int, Bounds>(); private readonly Dictionary<int, Point> _selectedPoints = new Dictionary<int, Point>();
#pragma warning disable 0414 // For future use, disable Warning CS0414: The field is assigned but its value is never used #pragma warning disable 0414 // For future use, disable Warning CS0414: The field is assigned but its value is never used
private bool _isDragging; private bool _isDragging;
#pragma warning restore 0414 #pragma warning restore 0414
@ -331,7 +331,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (rt is DesignerThumb) if (rt is DesignerThumb)
(rt as DesignerThumb).IsPrimarySelection = true; (rt as DesignerThumb).IsPrimarySelection = true;
} }
_selectedThumbs.Clear(); _selectedPoints.Clear();
} }
private void SelectThumb(PathThumb mprt) private void SelectThumb(PathThumb mprt)
@ -340,7 +340,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
var points = GetPoints(); var points = GetPoints();
Point p = points[mprt.Index].TranslatedPoint; Point p = points[mprt.Index].TranslatedPoint;
_selectedThumbs.Add(mprt.Index, new Bounds { X = p.X, Y = p.Y }); _selectedPoints.Add(mprt.Index, p);
mprt.IsPrimarySelection = false; mprt.IsPrimarySelection = false;
} }
@ -356,13 +356,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (mprt != null) if (mprt != null)
{ {
//if not keyboard ctrl is pressed and selected point is not previously selected, clear selection //if not keyboard ctrl is pressed and selected point is not previously selected, clear selection
if (!_selectedThumbs.ContainsKey(mprt.Index) & !Keyboard.IsKeyDown(Key.LeftCtrl) & if (!_selectedPoints.ContainsKey(mprt.Index) & !Keyboard.IsKeyDown(Key.LeftCtrl) &
!Keyboard.IsKeyDown(Key.RightCtrl)) !Keyboard.IsKeyDown(Key.RightCtrl))
{ {
ResetThumbs(); ResetThumbs();
} }
//add selected thumb, if ctrl pressed this could be all points in poly //add selected thumb, if ctrl pressed this could be all points in poly
if (!_selectedThumbs.ContainsKey(mprt.Index)) if (!_selectedPoints.ContainsKey(mprt.Index))
SelectThumb(mprt); SelectThumb(mprt);
_isDragging = false; _isDragging = false;
@ -423,7 +423,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
{ {
if (operation != null) if (operation != null)
{ {
foreach (int i in _selectedThumbs.Keys) foreach (int i in _selectedPoints.Keys)
{ {
pathPoints[i].Commit(); pathPoints[i].Commit();
} }
@ -728,12 +728,12 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
var relativeTo = new Vector(operation.PlacedItems[0].Bounds.TopLeft.X, operation.PlacedItems[0].Bounds.TopLeft.Y); 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 _selectedPoints.Keys) {
Point p = pathPoints[i].TranslatedPoint; Point p = pathPoints[i].TranslatedPoint;
//x and y is calculated from the currentl point //x and y is calculated from the currentl point
double x = _selectedThumbs[i].X + displacementX; double x = _selectedPoints[i].X + displacementX;
double y = _selectedThumbs[i].Y + displacementY; double y = _selectedPoints[i].Y + displacementY;
p.X = x; p.X = x;
p.Y = y; p.Y = y;
@ -749,14 +749,14 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public bool InvokeDefaultAction public bool InvokeDefaultAction
{ {
get { return _selectedThumbs.Count == 0 || _selectedThumbs.Count == pathPoints.Count - 1; } get { return _selectedPoints.Count == 0 || _selectedPoints.Count == pathPoints.Count - 1; }
} }
int _movingDistanceX; int _movingDistanceX;
int _movingDistanceY; int _movingDistanceY;
public void KeyDownAction(object sender, KeyEventArgs e) public void KeyDownAction(object sender, KeyEventArgs e)
{ {
if (_selectedThumbs.Count > 0) { if (_selectedPoints.Count > 0) {
if (IsArrowKey(e.Key)) { if (IsArrowKey(e.Key)) {
if (operation == null) { if (operation == null) {
SetOperation(); SetOperation();

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

@ -27,7 +27,6 @@ using System.Windows.Media;
using System.Windows.Shapes; using System.Windows.Shapes;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
@ -40,9 +39,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
/// </summary> /// </summary>
[ExtensionFor(typeof(Polyline))] [ExtensionFor(typeof(Polyline))]
[ExtensionFor(typeof(Polygon))] [ExtensionFor(typeof(Polygon))]
internal class PolyLineHandlerExtension : LineExtensionBase, IKeyDown, IKeyUp public class PolyLineHandlerExtension : LineExtensionBase, IKeyDown, IKeyUp
{ {
private readonly Dictionary<int, Bounds> _selectedThumbs = new Dictionary<int, Bounds>(); private readonly Dictionary<int, Point> _selectedPoints = new Dictionary<int, Point>();
private bool _isDragging; private bool _isDragging;
ZoomControl _zoom; ZoomControl _zoom;
@ -73,14 +72,14 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (rt is DesignerThumb) if (rt is DesignerThumb)
(rt as DesignerThumb).IsPrimarySelection = true; (rt as DesignerThumb).IsPrimarySelection = true;
} }
_selectedThumbs.Clear(); _selectedPoints.Clear();
} }
private void SelectThumb(MultiPointThumb mprt) private void SelectThumb(MultiPointThumb mprt)
{ {
PointCollection points = GetPointCollection(); PointCollection points = GetPointCollection();
Point p = points[mprt.Index]; Point p = points[mprt.Index];
_selectedThumbs.Add(mprt.Index, new Bounds { X = p.X, Y = p.Y }); _selectedPoints.Add(mprt.Index, p);
mprt.IsPrimarySelection = false; mprt.IsPrimarySelection = false;
} }
@ -119,13 +118,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
else else
{ {
//if not keyboard ctrl is pressed and selected point is not previously selected, clear selection //if not keyboard ctrl is pressed and selected point is not previously selected, clear selection
if (!_selectedThumbs.ContainsKey(mprt.Index) & !Keyboard.IsKeyDown(Key.LeftCtrl) & if (!_selectedPoints.ContainsKey(mprt.Index) & !Keyboard.IsKeyDown(Key.LeftCtrl) &
!Keyboard.IsKeyDown(Key.RightCtrl)) !Keyboard.IsKeyDown(Key.RightCtrl))
{ {
ResetThumbs(); ResetThumbs();
} }
//add selected thumb, if ctrl pressed this could be all points in poly //add selected thumb, if ctrl pressed this could be all points in poly
if (!_selectedThumbs.ContainsKey(mprt.Index)) if (!_selectedPoints.ContainsKey(mprt.Index))
SelectThumb(mprt); SelectThumb(mprt);
_isDragging = false; _isDragging = false;
} }
@ -174,10 +173,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
points = pl.Points; points = pl.Points;
} }
foreach (int i in _selectedThumbs.Keys) foreach (int i in _selectedPoints.Keys.ToList())
{ {
_selectedThumbs[i].X = points[i].X; _selectedPoints[i] = points[i];
_selectedThumbs[i].Y = points[i].Y;
} }
ExtendedItem.Properties.GetProperty(pl != null ? Polyline.PointsProperty : Polygon.PointsProperty).SetValue(points); ExtendedItem.Properties.GetProperty(pl != null ? Polyline.PointsProperty : Polygon.PointsProperty).SetValue(points);
operation.Commit(); operation.Commit();
@ -213,8 +211,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
Double theta; Double theta;
//if one point selected snapping angle is calculated in relation to previous point //if one point selected snapping angle is calculated in relation to previous point
if (_selectedThumbs.Count == 1 && mprt.Index > 0) { if (_selectedPoints.Count == 1 && mprt.Index > 0) {
theta = (180 / Math.PI) * Math.Atan2(_selectedThumbs[mprt.Index].Y + dy - points[mprt.Index - 1].Y, _selectedThumbs[mprt.Index].X + dx - points[mprt.Index - 1].X); theta = (180 / Math.PI) * Math.Atan2(_selectedPoints[mprt.Index].Y + dy - points[mprt.Index - 1].Y, _selectedPoints[mprt.Index].X + dx - points[mprt.Index - 1].X);
} else { //if multiple points snapping angle is calculated in relation to mouse dragging angle } else { //if multiple points snapping angle is calculated in relation to mouse dragging angle
theta = (180 / Math.PI) * Math.Atan2(dy, dx); theta = (180 / Math.PI) * Math.Atan2(dy, dx);
} }
@ -228,7 +226,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
//if dragging occurs on a point and that point is the only selected, a new node will be added. //if dragging occurs on a point and that point is the only selected, a new node will be added.
//_isCtrlDragging is needed since this method is called for every x pixel that the mouse moves //_isCtrlDragging is needed since this method is called for every x pixel that the mouse moves
//so it could be many thousands of times during a single dragging //so it could be many thousands of times during a single dragging
if (!_isDragging && _selectedThumbs.Count == 1 && (Math.Abs(dx) > 0 || Math.Abs(dy) > 0)) if (!_isDragging && _selectedPoints.Count == 1 && (Math.Abs(dx) > 0 || Math.Abs(dy) > 0))
{ {
//duplicate point that is selected //duplicate point that is selected
@ -333,29 +331,29 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
PointCollection MovePoints(PointCollection pc, double displacementX, double displacementY, double theta, int? snapangle) PointCollection MovePoints(PointCollection pc, double displacementX, double displacementY, double theta, int? snapangle)
{ {
//iterate all selected points //iterate all selected points
foreach (int i in _selectedThumbs.Keys) foreach (int i in _selectedPoints.Keys)
{ {
Point p = pc[i]; Point p = pc[i];
//x and y is calculated from the currentl point //x and y is calculated from the currentl point
double x = _selectedThumbs[i].X + displacementX; double x = _selectedPoints[i].X + displacementX;
double y = _selectedThumbs[i].Y + displacementY; double y = _selectedPoints[i].Y + displacementY;
//if snap is applied //if snap is applied
if (snapangle != null) if (snapangle != null)
{ {
if (_selectedThumbs.Count > 0) if (_selectedPoints.Count > 0)
{ {
//horizontal snap //horizontal snap
if (Math.Abs(theta) < snapangle || 180 - Math.Abs(theta) < snapangle) if (Math.Abs(theta) < snapangle || 180 - Math.Abs(theta) < snapangle)
{ {
//if one point selected use point before as snap point, else snap to movement //if one point selected use point before as snap point, else snap to movement
y = _selectedThumbs.Count == 1 ? pc[i - 1].Y : y - displacementY; y = _selectedPoints.Count == 1 ? pc[i - 1].Y : y - displacementY;
} }
else if (Math.Abs(90 - Math.Abs(theta)) < snapangle)//vertical snap else if (Math.Abs(90 - Math.Abs(theta)) < snapangle)//vertical snap
{ {
//if one point selected use point before as snap point, else snap to movement //if one point selected use point before as snap point, else snap to movement
x = _selectedThumbs.Count == 1 ? pc[i - 1].X : x - displacementX; x = _selectedPoints.Count == 1 ? pc[i - 1].X : x - displacementX;
} }
} }
} }
@ -371,7 +369,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public bool InvokeDefaultAction public bool InvokeDefaultAction
{ {
get { return _selectedThumbs.Count == 0 || _selectedThumbs.Count == GetPointCollection().Count - 1; } get { return _selectedPoints.Count == 0 || _selectedPoints.Count == GetPointCollection().Count - 1; }
} }
int _movingDistance; int _movingDistance;

Loading…
Cancel
Save