Browse Source

Extension is now public to allow it to be overridden by an other extension.

Using .Net built-in type Point instead of custom Bounds type.
Changed _selectedThumbs to _selectedPoints as it describes its purpose better.
pull/659/head
gumme 10 years ago
parent
commit
58b43f2511
  1. 24
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs
  2. 38
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs

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>();
private bool _isDragging; private bool _isDragging;
ZoomControl _zoom; ZoomControl _zoom;
@ -329,7 +329,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)
@ -338,7 +338,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;
} }
@ -354,13 +354,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;
@ -421,7 +421,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();
} }
@ -726,12 +726,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;
@ -747,14 +747,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