From 6e461ebc35aadba5444a79d04ef8f5bb96458bbd Mon Sep 17 00:00:00 2001 From: jkuehner Date: Sun, 28 Dec 2014 12:37:56 +0100 Subject: [PATCH 01/52] Basic Impl. of DrawLine support on Canvas. Need to work on this a little bit more --- .../Project/Controls/DragListener.cs | 15 +++ .../Extensions/CanvasDrawLineBehavior.cs | 114 ++++++++++++++++++ .../Extensions/LineHandlerExtension.cs | 11 +- .../Project/Services/CreateComponentTool.cs | 21 +++- .../Project/WpfDesign.Designer.csproj | 1 + .../WpfDesign/Project/DrawItemBehavior.cs | 35 ++++++ .../WpfDesign/Project/WpfDesign.csproj | 1 + 7 files changed, 188 insertions(+), 10 deletions(-) create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawLineBehavior.cs create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DrawItemBehavior.cs diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/DragListener.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/DragListener.cs index 6d27a2c276..ae9dfaac51 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/DragListener.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/DragListener.cs @@ -43,6 +43,21 @@ namespace ICSharpCode.WpfDesign.Designer.Controls Target.PreviewMouseMove += Target_MouseMove; Target.PreviewMouseLeftButtonUp += Target_MouseUp; } + + public void ExternalStart() + { + Target_MouseDown(null, null); + } + + public void ExternalMouseMove(MouseEventArgs e) + { + Target_MouseMove(null, e); + } + + public void ExternalStop() + { + Target_MouseUp(null, null); + } static DragListener CurrentListener; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawLineBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawLineBehavior.cs new file mode 100644 index 0000000000..64d439def2 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawLineBehavior.cs @@ -0,0 +1,114 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Linq; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Shapes; +using ICSharpCode.WpfDesign.Extensions; +using ICSharpCode.WpfDesign.Designer.Services; + +namespace ICSharpCode.WpfDesign.Designer.Extensions +{ + [ExtensionFor(typeof(Canvas))] + public class CanvasDrawLineBehavior : BehaviorExtension, IDrawItemBehavior + { + protected override void OnInitialized() + { + base.OnInitialized(); + if (ExtendedItem.ContentProperty == null || Metadata.IsPlacementDisabled(ExtendedItem.ComponentType)) + return; + ExtendedItem.AddBehavior(typeof(IDrawItemBehavior), this); + } + + #region IDrawItemBehavior implementation + + public bool CanItemBeDrawn(Type createItemType) + { + return createItemType == typeof(Line); + } + + public void StartDrawItem(DesignItem clickedOn, DesignItem createdItem, ChangeGroup changeGroup, IDesignPanel panel, System.Windows.Input.MouseEventArgs e) + { + var startPoint = e.GetPosition(clickedOn.View); + var operation = PlacementOperation.TryStartInsertNewComponents(clickedOn, + new DesignItem[] { createdItem }, + new Rect[] { new Rect(startPoint.X, startPoint.Y, 1, 1) }, + PlacementType.AddItem); + if (operation != null) { + createdItem.Services.Selection.SetSelectedComponents(new DesignItem[] { createdItem }); + operation.Commit(); + } + + + //changeGroup.Commit(); + + var lineHandler = createdItem.Extensions.OfType().First(); + lineHandler.DragListener.ExternalStart(); + + new DrawLineMouseGesture(lineHandler, clickedOn.View).Start(panel, (MouseButtonEventArgs) e); + } + + #endregion + } + + sealed class DrawLineMouseGesture : ClickOrDragMouseGesture + { + LineHandlerExtension l; + + public DrawLineMouseGesture(LineHandlerExtension l, IInputElement relativeTo) + { + this.l = l; + this.positionRelativeTo = relativeTo; + } + + protected override void OnMouseMove(object sender, MouseEventArgs e) + { + base.OnMouseMove(sender, e); + l.DragListener.ExternalMouseMove(e); + } + + protected override void OnMouseUp(object sender, MouseButtonEventArgs e) + { + l.DragListener.ExternalStop(); + base.OnMouseUp(sender, e); + } + + protected override void OnStopped() + { + //if (operation != null) + //{ + // operation.Abort(); + // operation = null; + //} + //if (changeGroup != null) + //{ + // changeGroup.Abort(); + // changeGroup = null; + //} + if (services.Tool.CurrentTool is CreateComponentTool) + { + services.Tool.CurrentTool = services.Tool.PointerTool; + } + base.OnStopped(); + } + + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs index 2d74352e00..246bc3a5b0 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs @@ -49,6 +49,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions //Size oldSize; ZoomControl zoom; + public DragListener DragListener {get; private set;} + protected ResizeThumb CreateThumb(PlacementAlignment alignment, Cursor cursor) { ResizeThumb resizeThumb = new ResizeThumb { Alignment = alignment, Cursor = cursor, IsPrimarySelection = true}; @@ -56,10 +58,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions adornerPanel.Children.Add(resizeThumb); - DragListener drag = new DragListener(resizeThumb); - drag.Started += drag_Started; - drag.Changed += drag_Changed; - drag.Completed += drag_Completed; + DragListener = new DragListener(resizeThumb); + DragListener.Started += drag_Started; + DragListener.Changed += drag_Changed; + DragListener.Completed += drag_Completed; + return resizeThumb; } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs index 3071f29e06..be857141b1 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs @@ -201,14 +201,23 @@ namespace ICSharpCode.WpfDesign.Designer.Services IDesignPanel designPanel = (IDesignPanel)sender; DesignPanelHitTestResult result = designPanel.HitTest(e.GetPosition(designPanel), false, true, HitTestType.Default); if (result.ModelHit != null) { - IPlacementBehavior behavior = result.ModelHit.GetBehavior(); - if (behavior != null) { - DesignItem createdItem = CreateItem(designPanel.Context); - - new CreateComponentMouseGesture(result.ModelHit, createdItem, changeGroup).Start(designPanel, e); - // CreateComponentMouseGesture now is responsible for the changeGroup created by CreateItem() + var drawItembehavior = result.ModelHit.GetBehavior(); + if (drawItembehavior != null && drawItembehavior.CanItemBeDrawn(componentType)) { + var createdItem = CreateItem(designPanel.Context); + drawItembehavior.StartDrawItem(result.ModelHit, createdItem, changeGroup, designPanel, e); + // IDrawItemBehavior now is responsible for the changeGroup created by CreateItem() changeGroup = null; } + else { + var placementBehavior = result.ModelHit.GetBehavior(); + if (placementBehavior != null) { + var createdItem = CreateItem(designPanel.Context); + + new CreateComponentMouseGesture(result.ModelHit, createdItem, changeGroup).Start(designPanel, e); + // CreateComponentMouseGesture now is responsible for the changeGroup created by CreateItem() + changeGroup = null; + } + } } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj index a02de6758b..3bfc285617 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj @@ -86,6 +86,7 @@ + DefaultCommandsContextMenu.xaml Code diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DrawItemBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DrawItemBehavior.cs new file mode 100644 index 0000000000..a0273fdc2d --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DrawItemBehavior.cs @@ -0,0 +1,35 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Windows; +using System.Windows.Input; + +namespace ICSharpCode.WpfDesign +{ + /// + /// Behavior interface implemented by container elements to support resizing + /// drawing new Elements + /// + public interface IDrawItemBehavior + { + bool CanItemBeDrawn(Type createItemType); + void StartDrawItem(DesignItem clickedOn, DesignItem createdItem, ChangeGroup changeGroup, IDesignPanel panel, MouseEventArgs e); + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj index ebc325f1c0..812b037ecd 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj @@ -73,6 +73,7 @@ + From 990298c4576aa10d3c360b26e09dc70c986335c5 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Sun, 28 Dec 2014 14:27:12 +0100 Subject: [PATCH 02/52] Support drawing new "Line" Objects on a Canvas --- .../Project/BasicMetadata.cs | 10 ++ .../Extensions/CanvasDrawLineBehavior.cs | 55 ++++--- .../Extensions/LineHandlerExtension.cs | 27 +-- .../PointTrackerPlacementSupport.cs | 154 ++++++++++-------- .../Project/Services/CreateComponentTool.cs | 10 +- .../Project/Xaml/XamlComponentService.cs | 14 +- .../WpfDesign/Project/DrawItemBehavior.cs | 2 +- .../WpfDesign/WpfDesign/Project/Metadata.cs | 32 +++- .../WpfDesign/WpfDesign/Project/Services.cs | 3 + 9 files changed, 183 insertions(+), 124 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs index 266bb736ae..29999bc6bd 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs @@ -285,6 +285,16 @@ namespace ICSharpCode.WpfDesign.Designer Metadata.AddDefaultSize(typeof(Label), new Size(130, 120)); Metadata.AddDefaultSize(typeof(Expander), new Size(130, 120)); + + + Metadata.AddDefaultPropertyValue(typeof(Line), Line.X1Property, 0.0); + Metadata.AddDefaultPropertyValue(typeof(Line), Line.Y1Property, 0.0); + Metadata.AddDefaultPropertyValue(typeof(Line), Line.X2Property, 20.0); + Metadata.AddDefaultPropertyValue(typeof(Line), Line.Y2Property, 20.0); + Metadata.AddDefaultPropertyValue(typeof(Line), Line.StrokeProperty, Colors.Black); + Metadata.AddDefaultPropertyValue(typeof(Line), Line.StrokeThicknessProperty, 2d); + Metadata.AddDefaultPropertyValue(typeof(Line), Line.StretchProperty, Stretch.None); + } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawLineBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawLineBehavior.cs index 64d439def2..7d16163d2c 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawLineBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawLineBehavior.cs @@ -21,6 +21,7 @@ using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using System.Windows.Media; using System.Windows.Shapes; using ICSharpCode.WpfDesign.Extensions; using ICSharpCode.WpfDesign.Designer.Services; @@ -30,6 +31,17 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions [ExtensionFor(typeof(Canvas))] public class CanvasDrawLineBehavior : BehaviorExtension, IDrawItemBehavior { + private ChangeGroup changeGroup; + + DesignItem CreateItem(DesignContext context, Type componentType) + { + object newInstance = context.Services.ExtensionManager.CreateInstanceWithCustomInstanceFactory(componentType, null); + DesignItem item = context.Services.Component.RegisterComponentForDesigner(newInstance); + changeGroup = item.OpenGroup("Draw Line"); + context.Services.ExtensionManager.ApplyDefaultInitializers(item); + return item; + } + protected override void OnInitialized() { base.OnInitialized(); @@ -44,26 +56,29 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions { return createItemType == typeof(Line); } - - public void StartDrawItem(DesignItem clickedOn, DesignItem createdItem, ChangeGroup changeGroup, IDesignPanel panel, System.Windows.Input.MouseEventArgs e) + + public void StartDrawItem(DesignItem clickedOn, Type createItemType, IDesignPanel panel, System.Windows.Input.MouseEventArgs e) { + var createdItem = CreateItem(panel.Context, createItemType); + var startPoint = e.GetPosition(clickedOn.View); var operation = PlacementOperation.TryStartInsertNewComponents(clickedOn, new DesignItem[] { createdItem }, - new Rect[] { new Rect(startPoint.X, startPoint.Y, 1, 1) }, + new Rect[] { new Rect(startPoint.X, startPoint.Y, double.NaN, double.NaN) }, PlacementType.AddItem); if (operation != null) { createdItem.Services.Selection.SetSelectedComponents(new DesignItem[] { createdItem }); operation.Commit(); } - - //changeGroup.Commit(); + createdItem.Properties[Shape.StrokeProperty].SetValue(Colors.Black); + createdItem.Properties[Shape.StrokeThicknessProperty].SetValue(2d); + createdItem.Properties[Shape.StretchProperty].SetValue(Stretch.None); var lineHandler = createdItem.Extensions.OfType().First(); lineHandler.DragListener.ExternalStart(); - new DrawLineMouseGesture(lineHandler, clickedOn.View).Start(panel, (MouseButtonEventArgs) e); + new DrawLineMouseGesture(lineHandler, clickedOn.View, changeGroup).Start(panel, (MouseButtonEventArgs) e); } #endregion @@ -71,12 +86,14 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions sealed class DrawLineMouseGesture : ClickOrDragMouseGesture { - LineHandlerExtension l; - - public DrawLineMouseGesture(LineHandlerExtension l, IInputElement relativeTo) + private LineHandlerExtension l; + private ChangeGroup changeGroup; + + public DrawLineMouseGesture(LineHandlerExtension l, IInputElement relativeTo, ChangeGroup changeGroup) { this.l = l; this.positionRelativeTo = relativeTo; + this.changeGroup = changeGroup; } protected override void OnMouseMove(object sender, MouseEventArgs e) @@ -88,21 +105,21 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions protected override void OnMouseUp(object sender, MouseButtonEventArgs e) { l.DragListener.ExternalStop(); + if (changeGroup != null) + { + changeGroup.Commit(); + changeGroup = null; + } base.OnMouseUp(sender, e); } protected override void OnStopped() { - //if (operation != null) - //{ - // operation.Abort(); - // operation = null; - //} - //if (changeGroup != null) - //{ - // changeGroup.Abort(); - // changeGroup = null; - //} + if (changeGroup != null) + { + changeGroup.Abort(); + changeGroup = null; + } if (services.Tool.CurrentTool is CreateComponentTool) { services.Tool.CurrentTool = services.Tool.PointerTool; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs index 246bc3a5b0..e978cfca5b 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs @@ -18,19 +18,12 @@ using System; using ICSharpCode.WpfDesign.Extensions; -using ICSharpCode.WpfDesign; using ICSharpCode.WpfDesign.Adorners; -using ICSharpCode.WpfDesign.Designer; using ICSharpCode.WpfDesign.Designer.Controls; using System.Windows.Input; using System.Windows.Media; using System.Windows.Shapes; -using System.Windows; using System.Windows.Controls; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; using ICSharpCode.WpfDesign.Designer.UIExtensions; namespace ICSharpCode.WpfDesign.Designer.Extensions { @@ -219,29 +212,17 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions protected override void OnInitialized() { base.OnInitialized(); - if (ExtendedItem.Properties.GetProperty(Line.StrokeProperty).ValueOnInstance == null) - { - ExtendedItem.Properties[Shape.StrokeProperty].SetValue(Colors.Black); - ExtendedItem.Properties[Shape.StrokeThicknessProperty].SetValue(2d); - ExtendedItem.Properties[Shape.StretchProperty].SetValue(Stretch.None); - ExtendedItem.Properties.GetProperty(Line.X1Property).SetValue(0); - ExtendedItem.Properties.GetProperty(Line.Y1Property).SetValue(0); - ExtendedItem.Properties.GetProperty(Line.X2Property).SetValue(20); - ExtendedItem.Properties.GetProperty(Line.Y2Property).SetValue(20); - (ExtendedItem.View as Line).BringIntoView(); - } - + resizeThumbs = new ResizeThumb[] { - CreateThumb(PlacementAlignment.TopLeft, Cursors.SizeNWSE), - CreateThumb(PlacementAlignment.BottomRight, Cursors.SizeNWSE) + CreateThumb(PlacementAlignment.TopLeft, Cursors.Cross), + CreateThumb(PlacementAlignment.BottomRight, Cursors.Cross) }; extendedItemArray[0] = this.ExtendedItem; Invalidate(); - //ResetWidthHeightProperties(); - + this.ExtendedItem.PropertyChanged += OnPropertyChanged; this.Services.Selection.PrimarySelectionChanged += OnPrimarySelectionChanged; resizeBehavior = PlacementOperation.GetPlacementBehavior(extendedItemArray); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs index ec0531a386..ab0ca1e39c 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs @@ -1,11 +1,21 @@ -/* - * Created by SharpDevelop. - * User: trubra - * Date: 2014-12-22 - * Time: 11:05 - * - * To change this template use Tools | Options | Coding | Edit Standard Headers. - */ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + using System; using System.Windows; using System.Windows.Shapes; @@ -15,79 +25,79 @@ using ICSharpCode.WpfDesign.Adorners; namespace ICSharpCode.WpfDesign.Designer.Extensions { public class PointTrackerPlacementSupport : AdornerPlacement - { - private Shape shape; - private PlacementAlignment alignment; + { + private Shape shape; + private PlacementAlignment alignment; - public int Index - { - get; set; - } - public PointTrackerPlacementSupport(Shape s, PlacementAlignment align, int index) - { - shape = s; - alignment = align; - Index = index; - } + public int Index + { + get; set; + } + public PointTrackerPlacementSupport(Shape s, PlacementAlignment align, int index) + { + shape = s; + alignment = align; + Index = index; + } - public PointTrackerPlacementSupport(Shape s, PlacementAlignment align) - { - shape = s; - alignment = align; - Index = -1; - } + public PointTrackerPlacementSupport(Shape s, PlacementAlignment align) + { + shape = s; + alignment = align; + Index = -1; + } - /// - /// Arranges the adorner element on the specified adorner panel. - /// - public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize) - { - Point p = new Point(0, 0); - double thumbsize = 7; - double distance = thumbsize / 2; - 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); + /// + /// Arranges the adorner element on the specified adorner panel. + /// + public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize) + { + Point p = new Point(0, 0); + double thumbsize = 7; + double distance = 0;// thumbsize / 2; + 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 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; - } - 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; - } - p = new Point(x, y); + //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; + } + 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; + } + p = new Point(x, y); - } - Polygon pg = shape as Polygon; - Polyline pl = shape as Polyline; - if (pg != null || pl != null) - { - if (Index > 0) - { - p = pl != null ? pl.Points[Index] : pg.Points[Index]; + } + Polygon pg = shape as Polygon; + Polyline pl = shape as Polyline; + if (pg != null || pl != null) + { + 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, new Size(thumbsize, thumbsize))); + } - } + } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs index be857141b1..7e9f9ba767 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs @@ -155,6 +155,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services object newInstance = context.Services.ExtensionManager.CreateInstanceWithCustomInstanceFactory(componentType, null); DesignItem item = context.Services.Component.RegisterComponentForDesigner(newInstance); changeGroup = item.OpenGroup("Drop Control"); + context.Services.Component.SetDefaultPropertyValues(item); context.Services.ExtensionManager.ApplyDefaultInitializers(item); return item; } @@ -163,7 +164,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services { CreateComponentTool cct = new CreateComponentTool(createdItem); return AddItemWithCustomSize(container, cct.CreateItem(container.Context), position, size); - } + } public static bool AddItemWithDefaultSize(DesignItem container, Type createdItem, Size size) { @@ -203,16 +204,13 @@ namespace ICSharpCode.WpfDesign.Designer.Services if (result.ModelHit != null) { var drawItembehavior = result.ModelHit.GetBehavior(); if (drawItembehavior != null && drawItembehavior.CanItemBeDrawn(componentType)) { - var createdItem = CreateItem(designPanel.Context); - drawItembehavior.StartDrawItem(result.ModelHit, createdItem, changeGroup, designPanel, e); - // IDrawItemBehavior now is responsible for the changeGroup created by CreateItem() - changeGroup = null; + drawItembehavior.StartDrawItem(result.ModelHit, componentType, designPanel, e); } else { var placementBehavior = result.ModelHit.GetBehavior(); if (placementBehavior != null) { var createdItem = CreateItem(designPanel.Context); - + new CreateComponentMouseGesture(result.ModelHit, createdItem, changeGroup).Start(designPanel, e); // CreateComponentMouseGesture now is responsible for the changeGroup created by CreateItem() changeGroup = null; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs index 17aa91f9bf..e51ab53ce2 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs @@ -29,7 +29,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml sealed class XamlComponentService : IComponentService { public event EventHandler PropertyChanged; - + #region IdentityEqualityComparer sealed class IdentityEqualityComparer : IEqualityComparer { @@ -69,7 +69,17 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml _sites.TryGetValue(component, out site); return site; } - + + public void SetDefaultPropertyValues(DesignItem designItem) + { + var values = Metadata.GetDefaultPropertyValues(designItem.ComponentType); + if (values != null) { + foreach (var value in values) { + designItem.Properties[value.Key].SetValue(value.Value); + } + } + } + public DesignItem RegisterComponentForDesigner(object component) { if (component == null) { diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DrawItemBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DrawItemBehavior.cs index a0273fdc2d..ab611aad7d 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DrawItemBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DrawItemBehavior.cs @@ -30,6 +30,6 @@ namespace ICSharpCode.WpfDesign public interface IDrawItemBehavior { bool CanItemBeDrawn(Type createItemType); - void StartDrawItem(DesignItem clickedOn, DesignItem createdItem, ChangeGroup changeGroup, IDesignPanel panel, MouseEventArgs e); + void StartDrawItem(DesignItem clickedOn, Type createItemType, IDesignPanel panel, MouseEventArgs e); } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs index 359a4823a0..ca4509c64f 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs @@ -45,6 +45,8 @@ namespace ICSharpCode.WpfDesign // Why not per-design context (as a service?) static Dictionary> standardValues = new Dictionary>(); + static Dictionary> standardPropertyValues = new Dictionary>(); + /// /// Registers a set of standard values for a by using the /// public static properties of the type . @@ -321,11 +323,39 @@ namespace ICSharpCode.WpfDesign if (defaultSizes.TryGetValue(t, out s)) { return s; } - t = checkBasetype ? t.BaseType : null; + t = checkBasetype ? t.BaseType : null; } } return null; } + + /// + /// Registers a default Property Value wich should be used + /// + public static void AddDefaultPropertyValue(Type t, DependencyProperty p, object value) + { + lock (standardPropertyValues) + { + if (!standardPropertyValues.ContainsKey(t)) + standardPropertyValues.Add(t, new Dictionary()); + + standardPropertyValues[t][p] = value; + } + } + + /// + /// Gets Default Propertie Values for a type + /// + public static Dictionary GetDefaultPropertyValues(Type t) + { + lock (standardPropertyValues) + { + if (standardPropertyValues.ContainsKey(t)) + return standardPropertyValues[t]; + + return null; + } + } } /// diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs index 2a3a41cebf..93f1e9d561 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs @@ -129,6 +129,9 @@ namespace ICSharpCode.WpfDesign /// Property Changed event EventHandler PropertyChanged; + + /// Set's default Property Values as defined in Metadata + void SetDefaultPropertyValues(DesignItem designItem); } #endregion From 831ea01e950599d60460f3d5df3b458a05cdfabc Mon Sep 17 00:00:00 2001 From: jkuehner Date: Sun, 28 Dec 2014 14:45:22 +0100 Subject: [PATCH 03/52] The Shape Control's should also be popular... (As now there is support for some of them (and more to come)) --- .../WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs index 29999bc6bd..86fc6681df 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs @@ -260,6 +260,11 @@ namespace ICSharpCode.WpfDesign.Designer Metadata.AddPopularControl(typeof(Viewbox)); Metadata.AddPopularControl(typeof(Viewport3D)); Metadata.AddPopularControl(typeof(WrapPanel)); + Metadata.AddPopularControl(typeof(Line)); + Metadata.AddPopularControl(typeof(Polyline)); + Metadata.AddPopularControl(typeof(Ellipse)); + Metadata.AddPopularControl(typeof(Rectangle)); + Metadata.AddPopularControl(typeof(Path)); //Basic Metadata Size of double.NaN, means no Size should be set. Metadata.AddDefaultSize(typeof(TextBlock), new Size(double.NaN, double.NaN)); From 5088e7b7868effaf31fcc87588b1e5f55015d893 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Sun, 28 Dec 2014 15:46:51 +0100 Subject: [PATCH 04/52] Better Default Values for Rectangle, Ellipse, Shape... --- .../WpfDesign.Designer/Project/BasicMetadata.cs | 10 +++++++++- .../Project/Extensions/Initializers.cs | 12 ------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs index 86fc6681df..cc2867e783 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs @@ -296,10 +296,18 @@ namespace ICSharpCode.WpfDesign.Designer Metadata.AddDefaultPropertyValue(typeof(Line), Line.Y1Property, 0.0); Metadata.AddDefaultPropertyValue(typeof(Line), Line.X2Property, 20.0); Metadata.AddDefaultPropertyValue(typeof(Line), Line.Y2Property, 20.0); - Metadata.AddDefaultPropertyValue(typeof(Line), Line.StrokeProperty, Colors.Black); + Metadata.AddDefaultPropertyValue(typeof(Line), Line.StrokeProperty, Brushes.Black); Metadata.AddDefaultPropertyValue(typeof(Line), Line.StrokeThicknessProperty, 2d); Metadata.AddDefaultPropertyValue(typeof(Line), Line.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); + + Metadata.AddDefaultPropertyValue(typeof(Ellipse), Ellipse.FillProperty, Brushes.Transparent); + Metadata.AddDefaultPropertyValue(typeof(Ellipse), Ellipse.StrokeProperty, Brushes.Black); + Metadata.AddDefaultPropertyValue(typeof(Ellipse), Ellipse.StrokeThicknessProperty, 2d); + } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs index b6b4aa941b..100c1f27aa 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs @@ -97,16 +97,4 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions.Initializers } } } - - [ExtensionFor(typeof(Shape))] - public class ShapeInitializer : DefaultInitializer - { - public override void InitializeDefaults(DesignItem item) - { - DesignItemProperty fillProperty = item.Properties["Fill"]; - if (fillProperty.ValueOnInstance == null) { - fillProperty.SetValue(Brushes.YellowGreen); - } - } - } } From e5da9a828236fd2112a877dca735da2a6d2f92c2 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Sun, 28 Dec 2014 23:19:27 +0100 Subject: [PATCH 05/52] Code Cleanup -> Line and Polyline Handlers --- .../Project/BasicMetadata.cs | 5 +++ .../Project/Extensions/LineExtensionBase.cs | 7 ++-- .../Extensions/LineHandlerExtension.cs | 20 +++++----- .../PointTrackerPlacementSupport.cs | 37 +++++-------------- .../Extensions/PolyLineHandlerExtension.cs | 11 ------ 5 files changed, 26 insertions(+), 54 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs index cc2867e783..de7fb9ac5b 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs @@ -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); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs index e4d29574c5..8bbe60a626 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs @@ -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 _text.Text = s; Canvas.SetLeft(_text, x); Canvas.SetTop(_text, y); - } protected void HideSizeAndShowHandles() diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs index e978cfca5b..614016985d 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs @@ -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 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 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 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 operation.CurrentContainerBehavior.BeforeSetPosition(operation); operation.CurrentContainerBehavior.SetPosition(info); } + (drag.Target as ResizeThumb).InvalidateArrange(); ResetWidthHeightProperties(); } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs index ab0ca1e39c..93e948bab9 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs @@ -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 Index = index; } - - - public PointTrackerPlacementSupport(Shape s, PlacementAlignment align) - { - shape = s; - alignment = align; - Index = -1; - } - /// /// Arranges the adorner element on the specified adorner panel. /// 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 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))); } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs index c9a88c0423..f68ac904c8 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs @@ -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 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 { 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(); for (int i = 1; i < points.Count; i++) { From 47d7ba0834d8dd989f84245f22ee502ea3b1f0e4 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Mon, 29 Dec 2014 11:33:18 +0100 Subject: [PATCH 06/52] Support for drawing a Polyline --- samples/XamlDesigner/XamlDesigner.sln | 8 +- .../Extensions/CanvasDrawLineBehavior.cs | 82 +++++----- .../Extensions/CanvasDrawPolyLineBehavior.cs | 148 ++++++++++++++++++ .../Project/Services/CreateComponentTool.cs | 4 +- .../Project/Services/MouseGestureBase.cs | 71 ++++++++- .../Project/WpfDesign.Designer.csproj | 1 + ...awItemBehavior.cs => DrawItemExtension.cs} | 2 +- .../WpfDesign/Project/WpfDesign.csproj | 2 +- 8 files changed, 266 insertions(+), 52 deletions(-) create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawPolyLineBehavior.cs rename src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/{DrawItemBehavior.cs => DrawItemExtension.cs} (97%) diff --git a/samples/XamlDesigner/XamlDesigner.sln b/samples/XamlDesigner/XamlDesigner.sln index e4a9c002ca..08bd78a71d 100644 --- a/samples/XamlDesigner/XamlDesigner.sln +++ b/samples/XamlDesigner/XamlDesigner.sln @@ -1,7 +1,9 @@  -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -# SharpDevelop 5.0 +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +# SharpDevelop 5.1 +VisualStudioVersion = 12.0.20827.3 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XamlDesigner", "XamlDesigner.csproj", "{27DA2B5C-2AAA-4478-AB00-3E184273C241}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfDesign", "..\..\src\AddIns\DisplayBindings\WpfDesign\WpfDesign\Project\WpfDesign.csproj", "{66A378A1-E9F4-4AD5-8946-D0EC06C2902F}" diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawLineBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawLineBehavior.cs index 7d16163d2c..4b48228c7d 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawLineBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawLineBehavior.cs @@ -29,7 +29,7 @@ using ICSharpCode.WpfDesign.Designer.Services; namespace ICSharpCode.WpfDesign.Designer.Extensions { [ExtensionFor(typeof(Canvas))] - public class CanvasDrawLineBehavior : BehaviorExtension, IDrawItemBehavior + public class CanvasDrawLineBehavior : BehaviorExtension, IDrawItemExtension { private ChangeGroup changeGroup; @@ -42,14 +42,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions return item; } - protected override void OnInitialized() - { - base.OnInitialized(); - if (ExtendedItem.ContentProperty == null || Metadata.IsPlacementDisabled(ExtendedItem.ComponentType)) - return; - ExtendedItem.AddBehavior(typeof(IDrawItemBehavior), this); - } - #region IDrawItemBehavior implementation public bool CanItemBeDrawn(Type createItemType) @@ -82,50 +74,50 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions } #endregion - } - - sealed class DrawLineMouseGesture : ClickOrDragMouseGesture - { - private LineHandlerExtension l; - private ChangeGroup changeGroup; - - public DrawLineMouseGesture(LineHandlerExtension l, IInputElement relativeTo, ChangeGroup changeGroup) - { - this.l = l; - this.positionRelativeTo = relativeTo; - this.changeGroup = changeGroup; - } - - protected override void OnMouseMove(object sender, MouseEventArgs e) - { - base.OnMouseMove(sender, e); - l.DragListener.ExternalMouseMove(e); - } - protected override void OnMouseUp(object sender, MouseButtonEventArgs e) + sealed class DrawLineMouseGesture : ClickOrDragMouseGesture { - l.DragListener.ExternalStop(); - if (changeGroup != null) + private LineHandlerExtension l; + private ChangeGroup changeGroup; + + public DrawLineMouseGesture(LineHandlerExtension l, IInputElement relativeTo, ChangeGroup changeGroup) { - changeGroup.Commit(); - changeGroup = null; + this.l = l; + this.positionRelativeTo = relativeTo; + this.changeGroup = changeGroup; } - base.OnMouseUp(sender, e); - } - - protected override void OnStopped() - { - if (changeGroup != null) + + protected override void OnMouseMove(object sender, MouseEventArgs e) { - changeGroup.Abort(); - changeGroup = null; + base.OnMouseMove(sender, e); + l.DragListener.ExternalMouseMove(e); } - if (services.Tool.CurrentTool is CreateComponentTool) + + protected override void OnMouseUp(object sender, MouseButtonEventArgs e) { - services.Tool.CurrentTool = services.Tool.PointerTool; + l.DragListener.ExternalStop(); + if (changeGroup != null) + { + changeGroup.Commit(); + changeGroup = null; + } + base.OnMouseUp(sender, e); } - base.OnStopped(); + + protected override void OnStopped() + { + if (changeGroup != null) + { + changeGroup.Abort(); + changeGroup = null; + } + if (services.Tool.CurrentTool is CreateComponentTool) + { + services.Tool.CurrentTool = services.Tool.PointerTool; + } + base.OnStopped(); + } + } - } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawPolyLineBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawPolyLineBehavior.cs new file mode 100644 index 0000000000..244910d690 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawPolyLineBehavior.cs @@ -0,0 +1,148 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Linq; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Shapes; +using ICSharpCode.WpfDesign.Extensions; +using ICSharpCode.WpfDesign.Designer.Services; + +namespace ICSharpCode.WpfDesign.Designer.Extensions +{ + [ExtensionFor(typeof(Canvas))] + public class CanvasDrawPolyLineBehavior : BehaviorExtension, IDrawItemExtension + { + private ChangeGroup changeGroup; + + DesignItem CreateItem(DesignContext context, Type componentType) + { + object newInstance = context.Services.ExtensionManager.CreateInstanceWithCustomInstanceFactory(componentType, null); + DesignItem item = context.Services.Component.RegisterComponentForDesigner(newInstance); + changeGroup = item.OpenGroup("Draw Polyline"); + context.Services.ExtensionManager.ApplyDefaultInitializers(item); + return item; + } + + #region IDrawItemBehavior implementation + + public bool CanItemBeDrawn(Type createItemType) + { + return createItemType == typeof(Polyline); + } + + public void StartDrawItem(DesignItem clickedOn, Type createItemType, IDesignPanel panel, System.Windows.Input.MouseEventArgs e) + { + var createdItem = CreateItem(panel.Context, createItemType); + + var startPoint = e.GetPosition(clickedOn.View); + var operation = PlacementOperation.TryStartInsertNewComponents(clickedOn, + new DesignItem[] { createdItem }, + new Rect[] { new Rect(startPoint.X, startPoint.Y, double.NaN, double.NaN) }, + PlacementType.AddItem); + if (operation != null) { + createdItem.Services.Selection.SetSelectedComponents(new DesignItem[] { createdItem }); + operation.Commit(); + } + + createdItem.Properties[Shape.StrokeProperty].SetValue(Colors.Black); + createdItem.Properties[Shape.StrokeThicknessProperty].SetValue(2d); + createdItem.Properties[Shape.StretchProperty].SetValue(Stretch.None); + + createdItem.Properties[Polyline.PointsProperty].CollectionElements.Add(createdItem.Services.Component.RegisterComponentForDesigner(new Point(0,0))); + + new DrawPolylineMouseGesture(createdItem, clickedOn.View, changeGroup).Start(panel, (MouseButtonEventArgs) e); + } + + #endregion + + sealed class DrawPolylineMouseGesture : ClickOrDragMouseGesture + { + private ChangeGroup changeGroup; + private DesignItem newLine; + private Point startPoint; + + public DrawPolylineMouseGesture(DesignItem newLine, IInputElement relativeTo, ChangeGroup changeGroup) + { + this.newLine = newLine; + this.positionRelativeTo = relativeTo; + this.changeGroup = changeGroup; + + startPoint = Mouse.GetPosition(null); + } + + protected override void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + e.Handled = true; + base.OnPreviewMouseLeftButtonDown(sender, e); + } + + protected override void OnMouseMove(object sender, MouseEventArgs e) + { + var delta = e.GetPosition(null) - startPoint; + var point = new Point(delta.X, delta.Y); + + if (((Polyline)newLine.View).Points.Count <= 1) + newLine.Properties[Polyline.PointsProperty].CollectionElements.Add(newLine.Services.Component.RegisterComponentForDesigner(point)); + newLine.Properties[Polyline.PointsProperty].CollectionElements.RemoveAt(((Polyline)newLine.View).Points.Count - 1); + newLine.Properties[Polyline.PointsProperty].CollectionElements.Add(newLine.Services.Component.RegisterComponentForDesigner(point)); + } + + protected override void OnMouseUp(object sender, MouseButtonEventArgs e) + { + var delta = e.GetPosition(null) - startPoint; + var point = new Point(delta.X, delta.Y); + + newLine.Properties[Polyline.PointsProperty].CollectionElements.Add(newLine.Services.Component.RegisterComponentForDesigner(point)); + } + + protected override void OnMouseDoubleClick(object sender, MouseButtonEventArgs e) + { + base.OnMouseDoubleClick(sender, e); + + newLine.Properties[Polyline.PointsProperty].CollectionElements.RemoveAt(((Polyline)newLine.View).Points.Count - 1); + + if (changeGroup != null) + { + changeGroup.Commit(); + changeGroup = null; + } + + Stop(); + } + + protected override void OnStopped() + { + if (changeGroup != null) + { + changeGroup.Abort(); + changeGroup = null; + } + if (services.Tool.CurrentTool is CreateComponentTool) + { + services.Tool.CurrentTool = services.Tool.PointerTool; + } + base.OnStopped(); + } + + } + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs index 7e9f9ba767..88469fd72f 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs @@ -16,6 +16,7 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +using System.Linq; using System.Windows; using System; using System.Diagnostics; @@ -202,7 +203,8 @@ namespace ICSharpCode.WpfDesign.Designer.Services IDesignPanel designPanel = (IDesignPanel)sender; DesignPanelHitTestResult result = designPanel.HitTest(e.GetPosition(designPanel), false, true, HitTestType.Default); if (result.ModelHit != null) { - var drawItembehavior = result.ModelHit.GetBehavior(); + var darwItemBehaviors = result.ModelHit.Extensions.OfType(); + var drawItembehavior = darwItemBehaviors.FirstOrDefault(x => x.CanItemBeDrawn(componentType)); if (drawItembehavior != null && drawItembehavior.CanItemBeDrawn(componentType)) { drawItembehavior.StartDrawItem(result.ModelHit, componentType, designPanel, e); } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MouseGestureBase.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MouseGestureBase.cs index ae5cc76262..75b4d5551e 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MouseGestureBase.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MouseGestureBase.cs @@ -18,6 +18,8 @@ using System; using System.Diagnostics; +using System.Windows; +using System.Windows.Controls; using System.Windows.Input; namespace ICSharpCode.WpfDesign.Designer.Services @@ -71,6 +73,10 @@ namespace ICSharpCode.WpfDesign.Designer.Services designPanel.MouseMove += OnMouseMove; designPanel.MouseUp += OnMouseUp; designPanel.KeyDown += OnKeyDown; + designPanel.PreviewMouseLeftButtonDown += OnPreviewMouseLeftButtonDown; + designPanel.PreviewMouseLeftButtonUp += OnPreviewMouseLeftButtonUp; + designPanel.PreviewMouseRightButtonDown += OnPreviewMouseRightButtonDown; + designPanel.PreviewMouseRightButtonUp += OnPreviewMouseRightButtonUp; } void UnRegisterEvents() @@ -80,6 +86,10 @@ namespace ICSharpCode.WpfDesign.Designer.Services designPanel.MouseMove -= OnMouseMove; designPanel.MouseUp -= OnMouseUp; designPanel.KeyDown -= OnKeyDown; + designPanel.PreviewMouseLeftButtonDown -= OnPreviewMouseLeftButtonDown; + designPanel.PreviewMouseLeftButtonUp -= OnPreviewMouseLeftButtonUp; + designPanel.PreviewMouseRightButtonDown -= OnPreviewMouseRightButtonDown; + designPanel.PreviewMouseRightButtonUp -= OnPreviewMouseRightButtonUp; } void OnKeyDown(object sender, KeyEventArgs e) @@ -95,10 +105,27 @@ namespace ICSharpCode.WpfDesign.Designer.Services Stop(); } - protected virtual void OnMouseDown(object sender, MouseButtonEventArgs e) + protected virtual void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { + if (MouseButtonHelper.IsDoubleClick(sender, e)) + OnMouseDoubleClick(sender, e); } + protected virtual void OnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { } + + protected virtual void OnPreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e) + { } + + protected virtual void OnPreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e) + { } + + protected virtual void OnMouseDoubleClick(object sender, MouseButtonEventArgs e) + { } + + protected virtual void OnMouseDown(object sender, MouseButtonEventArgs e) + { } + protected virtual void OnMouseMove(object sender, MouseEventArgs e) { } @@ -119,5 +146,47 @@ namespace ICSharpCode.WpfDesign.Designer.Services protected virtual void OnStarted(MouseButtonEventArgs e) {} protected virtual void OnStopped() {} + + static class MouseButtonHelper + { + private const long k_DoubleClickSpeed = 500; + private const double k_MaxMoveDistance = 10; + + private static long _LastClickTicks = 0; + private static Point _LastPosition; + private static WeakReference _LastSender; + + internal static bool IsDoubleClick(object sender, MouseButtonEventArgs e) + { + Point position = e.GetPosition(null); + long clickTicks = DateTime.Now.Ticks; + long elapsedTicks = clickTicks - _LastClickTicks; + long elapsedTime = elapsedTicks / TimeSpan.TicksPerMillisecond; + bool quickClick = (elapsedTime <= k_DoubleClickSpeed); + bool senderMatch = (_LastSender != null && sender.Equals(_LastSender.Target)); + + if (senderMatch && quickClick && Distance(position, _LastPosition) <= k_MaxMoveDistance) + { + // Double click! + _LastClickTicks = 0; + _LastSender = null; + return true; + } + + // Not a double click + _LastClickTicks = clickTicks; + _LastPosition = position; + if (!quickClick) + _LastSender = new WeakReference(sender); + return false; + } + + private static double Distance(Point pointA, Point pointB) + { + double x = pointA.X - pointB.X; + double y = pointA.Y - pointB.Y; + return Math.Sqrt(x * x + y * y); + } + } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj index 3bfc285617..50cd7d67d2 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj @@ -87,6 +87,7 @@ + DefaultCommandsContextMenu.xaml Code diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DrawItemBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DrawItemExtension.cs similarity index 97% rename from src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DrawItemBehavior.cs rename to src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DrawItemExtension.cs index ab611aad7d..a97dffafaa 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DrawItemBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DrawItemExtension.cs @@ -27,7 +27,7 @@ namespace ICSharpCode.WpfDesign /// Behavior interface implemented by container elements to support resizing /// drawing new Elements /// - public interface IDrawItemBehavior + public interface IDrawItemExtension { bool CanItemBeDrawn(Type createItemType); void StartDrawItem(DesignItem clickedOn, Type createItemType, IDesignPanel panel, MouseEventArgs e); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj index 812b037ecd..56127c6a68 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj @@ -73,7 +73,7 @@ - + From 8949c265eb3b50103000166176fdaf7f6da9e0fd Mon Sep 17 00:00:00 2001 From: jkuehner Date: Mon, 29 Dec 2014 11:37:43 +0100 Subject: [PATCH 07/52] Polyline Fixes --- .../Project/Extensions/CanvasDrawPolyLineBehavior.cs | 3 +++ .../Project/Extensions/LineExtensionBase.cs | 6 ------ .../Project/Extensions/RotateThumbExtension.cs | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawPolyLineBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawPolyLineBehavior.cs index 244910d690..4e7bb6d0bd 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawPolyLineBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawPolyLineBehavior.cs @@ -140,6 +140,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions { services.Tool.CurrentTool = services.Tool.PointerTool; } + + ((DesignPanel) newLine.Services.DesignPanel).AdornerLayer.UpdateAdornersForElement(this.newLine.View, true); + base.OnStopped(); } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs index 8bbe60a626..1439678224 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs @@ -102,10 +102,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions if (isPrimarySelection) DependencyPropertyDescriptor.FromProperty(FrameworkElement.HeightProperty, typeof (Shape)) .AddValueChanged(ExtendedItem.View, (s, ev) => ResetWidthHeightProperties()); - //foreach (ResizeThumb g in adornerPanel.Children) - //{ - // g.IsPrimarySelection = isPrimarySelection; - //} } #endregion @@ -193,7 +189,5 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions ExtendedItem.Properties.GetProperty(FrameworkElement.HeightProperty).Reset(); ExtendedItem.Properties.GetProperty(FrameworkElement.WidthProperty).Reset(); } - - } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RotateThumbExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RotateThumbExtension.cs index 3165c03781..b169339371 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RotateThumbExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RotateThumbExtension.cs @@ -137,7 +137,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions } rtTransform.Properties["Angle"].SetValue(destAngle); - ((DesignPanel) this.ExtendedItem.Services.DesignPanel).AdornerLayer.UpdateAdornersForElement(this.ExtendedItem.View, true); + ((DesignPanel) this.ExtendedItem.Services.DesignPanel).AdornerLayer.UpdateAdornersForElement(this.ExtendedItem.View, true); } } From 038373f6f9694a5b6c96918b70ed9b3524163421 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Mon, 29 Dec 2014 11:44:21 +0100 Subject: [PATCH 08/52] Few more Polyline fixes --- .../Project/Extensions/PolyLineHandlerExtension.cs | 4 ++-- .../Project/Services/MouseGestureBase.cs | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs index f68ac904c8..9e513b3874 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs @@ -265,7 +265,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions points.Insert(mprt.Index, p); //create adorner marker - CreateThumb(PlacementAlignment.BottomRight, Cursors.SizeNWSE, mprt.Index); + CreateThumb(PlacementAlignment.BottomRight, Cursors.Cross, mprt.Index); //set index of all points that had a higher index than selected to +1 foreach (FrameworkElement rt in adornerPanel.Children) @@ -333,7 +333,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions resizeThumbs = new List(); for (int i = 1; i < points.Count; i++) { - CreateThumb(PlacementAlignment.BottomRight, Cursors.SizeNWSE, i); + CreateThumb(PlacementAlignment.BottomRight, Cursors.Cross, i); } Invalidate(); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MouseGestureBase.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MouseGestureBase.cs index 75b4d5551e..c92b1c527c 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MouseGestureBase.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MouseGestureBase.cs @@ -18,6 +18,7 @@ using System; using System.Diagnostics; +using System.Runtime.InteropServices; using System.Windows; using System.Windows.Controls; using System.Windows.Input; @@ -149,7 +150,16 @@ namespace ICSharpCode.WpfDesign.Designer.Services static class MouseButtonHelper { - private const long k_DoubleClickSpeed = 500; + [DllImport("user32.dll")] + static extern uint GetDoubleClickTime(); + + static MouseButtonHelper() + { + k_DoubleClickSpeed = GetDoubleClickTime(); + } + + private static readonly uint k_DoubleClickSpeed; + private const double k_MaxMoveDistance = 10; private static long _LastClickTicks = 0; @@ -162,7 +172,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services long clickTicks = DateTime.Now.Ticks; long elapsedTicks = clickTicks - _LastClickTicks; long elapsedTime = elapsedTicks / TimeSpan.TicksPerMillisecond; - bool quickClick = (elapsedTime <= k_DoubleClickSpeed); + bool quickClick = (elapsedTime <= k_DoubleClickSpeed ); bool senderMatch = (_LastSender != null && sender.Equals(_LastSender.Target)); if (senderMatch && quickClick && Distance(position, _LastPosition) <= k_MaxMoveDistance) From 4093e42edfc07c40084e7dfcf6e7384d7179c1df Mon Sep 17 00:00:00 2001 From: jkuehner Date: Mon, 29 Dec 2014 11:52:01 +0100 Subject: [PATCH 09/52] Fix Polyline Points where not saved to XAML --- .../Extensions/CanvasDrawPolyLineBehavior.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawPolyLineBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawPolyLineBehavior.cs index 4e7bb6d0bd..3653f7f517 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawPolyLineBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawPolyLineBehavior.cs @@ -101,9 +101,12 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions var point = new Point(delta.X, delta.Y); if (((Polyline)newLine.View).Points.Count <= 1) - newLine.Properties[Polyline.PointsProperty].CollectionElements.Add(newLine.Services.Component.RegisterComponentForDesigner(point)); - newLine.Properties[Polyline.PointsProperty].CollectionElements.RemoveAt(((Polyline)newLine.View).Points.Count - 1); - newLine.Properties[Polyline.PointsProperty].CollectionElements.Add(newLine.Services.Component.RegisterComponentForDesigner(point)); + //newLine.Properties[Polyline.PointsProperty].CollectionElements.Add(newLine.Services.Component.RegisterComponentForDesigner(point)); + ((Polyline)newLine.View).Points.Add(point); + //newLine.Properties[Polyline.PointsProperty].CollectionElements.RemoveAt(((Polyline)newLine.View).Points.Count - 1); + ((Polyline)newLine.View).Points.RemoveAt(((Polyline)newLine.View).Points.Count - 1); + //newLine.Properties[Polyline.PointsProperty].CollectionElements.Add(newLine.Services.Component.RegisterComponentForDesigner(point)); + ((Polyline)newLine.View).Points.Add(point); } protected override void OnMouseUp(object sender, MouseButtonEventArgs e) @@ -111,14 +114,18 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions var delta = e.GetPosition(null) - startPoint; var point = new Point(delta.X, delta.Y); - newLine.Properties[Polyline.PointsProperty].CollectionElements.Add(newLine.Services.Component.RegisterComponentForDesigner(point)); + //newLine.Properties[Polyline.PointsProperty].CollectionElements.Add(newLine.Services.Component.RegisterComponentForDesigner(point)); + ((Polyline)newLine.View).Points.Add(point); } protected override void OnMouseDoubleClick(object sender, MouseButtonEventArgs e) { base.OnMouseDoubleClick(sender, e); - newLine.Properties[Polyline.PointsProperty].CollectionElements.RemoveAt(((Polyline)newLine.View).Points.Count - 1); + //newLine.Properties[Polyline.PointsProperty].CollectionElements.RemoveAt(((Polyline)newLine.View).Points.Count - 1); + ((Polyline)newLine.View).Points.RemoveAt(((Polyline)newLine.View).Points.Count - 1); + + newLine.Properties[Polyline.PointsProperty].SetValue(string.Join(",", ((Polyline)newLine.View).Points)); if (changeGroup != null) { From f5f4652b670bebc52b58be6d05d95be85ef49885 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Mon, 29 Dec 2014 12:00:54 +0100 Subject: [PATCH 10/52] Support for drawing Polygons --- .../Extensions/CanvasDrawPolyLineBehavior.cs | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawPolyLineBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawPolyLineBehavior.cs index 3653f7f517..132abc46e2 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawPolyLineBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawPolyLineBehavior.cs @@ -46,7 +46,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions public bool CanItemBeDrawn(Type createItemType) { - return createItemType == typeof(Polyline); + return createItemType == typeof(Polyline) || createItemType == typeof(Polygon); } public void StartDrawItem(DesignItem clickedOn, Type createItemType, IDesignPanel panel, System.Windows.Input.MouseEventArgs e) @@ -67,7 +67,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions createdItem.Properties[Shape.StrokeThicknessProperty].SetValue(2d); createdItem.Properties[Shape.StretchProperty].SetValue(Stretch.None); - createdItem.Properties[Polyline.PointsProperty].CollectionElements.Add(createdItem.Services.Component.RegisterComponentForDesigner(new Point(0,0))); + if (createItemType == typeof(Polyline)) + createdItem.Properties[Polyline.PointsProperty].CollectionElements.Add(createdItem.Services.Component.RegisterComponentForDesigner(new Point(0,0))); + else + createdItem.Properties[Polygon.PointsProperty].CollectionElements.Add(createdItem.Services.Component.RegisterComponentForDesigner(new Point(0,0))); new DrawPolylineMouseGesture(createdItem, clickedOn.View, changeGroup).Start(panel, (MouseButtonEventArgs) e); } @@ -99,14 +102,18 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions { var delta = e.GetPosition(null) - startPoint; var point = new Point(delta.X, delta.Y); - - if (((Polyline)newLine.View).Points.Count <= 1) - //newLine.Properties[Polyline.PointsProperty].CollectionElements.Add(newLine.Services.Component.RegisterComponentForDesigner(point)); + + if (newLine.View is Polyline) { + if (((Polyline)newLine.View).Points.Count <= 1) + ((Polyline)newLine.View).Points.Add(point); + ((Polyline)newLine.View).Points.RemoveAt(((Polyline)newLine.View).Points.Count - 1); ((Polyline)newLine.View).Points.Add(point); - //newLine.Properties[Polyline.PointsProperty].CollectionElements.RemoveAt(((Polyline)newLine.View).Points.Count - 1); - ((Polyline)newLine.View).Points.RemoveAt(((Polyline)newLine.View).Points.Count - 1); - //newLine.Properties[Polyline.PointsProperty].CollectionElements.Add(newLine.Services.Component.RegisterComponentForDesigner(point)); - ((Polyline)newLine.View).Points.Add(point); + } else { + if (((Polygon)newLine.View).Points.Count <= 1) + ((Polygon)newLine.View).Points.Add(point); + ((Polygon)newLine.View).Points.RemoveAt(((Polygon)newLine.View).Points.Count - 1); + ((Polygon)newLine.View).Points.Add(point); + } } protected override void OnMouseUp(object sender, MouseButtonEventArgs e) @@ -114,18 +121,23 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions var delta = e.GetPosition(null) - startPoint; var point = new Point(delta.X, delta.Y); - //newLine.Properties[Polyline.PointsProperty].CollectionElements.Add(newLine.Services.Component.RegisterComponentForDesigner(point)); - ((Polyline)newLine.View).Points.Add(point); + if (newLine.View is Polyline) + ((Polyline)newLine.View).Points.Add(point); + else + ((Polygon)newLine.View).Points.Add(point); } protected override void OnMouseDoubleClick(object sender, MouseButtonEventArgs e) { base.OnMouseDoubleClick(sender, e); - //newLine.Properties[Polyline.PointsProperty].CollectionElements.RemoveAt(((Polyline)newLine.View).Points.Count - 1); - ((Polyline)newLine.View).Points.RemoveAt(((Polyline)newLine.View).Points.Count - 1); - - newLine.Properties[Polyline.PointsProperty].SetValue(string.Join(",", ((Polyline)newLine.View).Points)); + if (newLine.View is Polyline) { + ((Polyline)newLine.View).Points.RemoveAt(((Polyline)newLine.View).Points.Count - 1); + newLine.Properties[Polyline.PointsProperty].SetValue(string.Join(",", ((Polyline)newLine.View).Points)); + } else { + ((Polygon)newLine.View).Points.RemoveAt(((Polygon)newLine.View).Points.Count - 1); + newLine.Properties[Polygon.PointsProperty].SetValue(string.Join(",", ((Polygon)newLine.View).Points)); + } if (changeGroup != null) { From 750928d0826bd95f3a8ebadecbfc835590de11ad Mon Sep 17 00:00:00 2001 From: jkuehner Date: Mon, 29 Dec 2014 12:10:22 +0100 Subject: [PATCH 11/52] Polyline -> Some extensions should not be disabled --- .../Project/Extensions/PolyLineHandlerExtension.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs index 9e513b3874..f32ae3d3c5 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs @@ -38,7 +38,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions /// /// Description of PolyLineHandlerExtension. /// - [ExtensionFor(typeof(Polyline), OverrideExtensions = new Type[] { typeof(ResizeThumbExtension), typeof(SelectedElementRectangleExtension), typeof(CanvasPositionExtension), typeof(QuickOperationMenuExtension), typeof(RotateThumbExtension), typeof(RenderTransformOriginExtension), typeof(InPlaceEditorExtension), typeof(SizeDisplayExtension), typeof(SkewThumbExtension) })] + [ExtensionFor(typeof(Polyline), OverrideExtensions = new Type[] { typeof(ResizeThumbExtension), typeof(QuickOperationMenuExtension), })] + [ExtensionFor(typeof(Polygon), OverrideExtensions = new Type[] { typeof(ResizeThumbExtension), typeof(QuickOperationMenuExtension), })] internal class PolyLineHandlerExtension : LineExtensionBase, IKeyDown, IKeyUp { private readonly Dictionary _selectedThumbs = new Dictionary(); From b928039f662adec6108ba014184117ee92e832fb Mon Sep 17 00:00:00 2001 From: jkuehner Date: Mon, 29 Dec 2014 12:23:06 +0100 Subject: [PATCH 12/52] Polygon/Polyline should be Resizeable -> todo: Recalculate the Points when Polyline is stretched --- .../Project/Extensions/LineExtensionBase.cs | 4 ++-- .../Project/Extensions/PolyLineHandlerExtension.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs index 1439678224..75bfaed8dd 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs @@ -186,8 +186,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions protected void ResetWidthHeightProperties() { - ExtendedItem.Properties.GetProperty(FrameworkElement.HeightProperty).Reset(); - ExtendedItem.Properties.GetProperty(FrameworkElement.WidthProperty).Reset(); +// ExtendedItem.Properties.GetProperty(FrameworkElement.HeightProperty).Reset(); +// ExtendedItem.Properties.GetProperty(FrameworkElement.WidthProperty).Reset(); } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs index f32ae3d3c5..4c0e3f924e 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs @@ -38,8 +38,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions /// /// Description of PolyLineHandlerExtension. /// - [ExtensionFor(typeof(Polyline), OverrideExtensions = new Type[] { typeof(ResizeThumbExtension), typeof(QuickOperationMenuExtension), })] - [ExtensionFor(typeof(Polygon), OverrideExtensions = new Type[] { typeof(ResizeThumbExtension), typeof(QuickOperationMenuExtension), })] + [ExtensionFor(typeof(Polyline))] + [ExtensionFor(typeof(Polygon))] internal class PolyLineHandlerExtension : LineExtensionBase, IKeyDown, IKeyUp { private readonly Dictionary _selectedThumbs = new Dictionary(); From 71e42897cdc11268b72a8093482332ee6e58687c Mon Sep 17 00:00:00 2001 From: jkuehner Date: Mon, 29 Dec 2014 13:04:57 +0100 Subject: [PATCH 13/52] Better Polyline/Polygon/Line Support --- .../Project/Controls/ResizeThumb.cs | 2 +- .../Project/Extensions/LineExtensionBase.cs | 15 ++------------- .../Project/Extensions/LineHandlerExtension.cs | 8 ++++---- .../Extensions/PointTrackerPlacementSupport.cs | 3 +++ .../Extensions/PolyLineHandlerExtension.cs | 12 ++---------- 5 files changed, 12 insertions(+), 28 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ResizeThumb.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ResizeThumb.cs index ec82214b0c..c33389f0da 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ResizeThumb.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ResizeThumb.cs @@ -92,7 +92,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls if (checkWidth) this.ResizeThumbVisible = PlacementOperation.GetRealElementSize(parent.AdornedElement).Width > 14; else if (checkHeight) - this.ResizeThumbVisible = PlacementOperation.GetRealElementSize(parent.AdornedElement).Height > 14; + this.ResizeThumbVisible = PlacementOperation.GetRealElementSize(parent.AdornedElement).Height > 14; } return base.ArrangeOverride(arrangeBounds); } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs index 75bfaed8dd..89f3c6ef0e 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs @@ -90,20 +90,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions protected override void OnRemove() { this.ExtendedItem.PropertyChanged -= OnPropertyChanged; - this.Services.Selection.PrimarySelectionChanged -= OnPrimarySelectionChanged; - DependencyPropertyDescriptor.FromProperty(FrameworkElement.HeightProperty, typeof (Shape)) - .RemoveValueChanged(ExtendedItem.View, (s, ev) => ResetWidthHeightProperties()); base.OnRemove(); } - protected void OnPrimarySelectionChanged(object sender, EventArgs e) - { - bool isPrimarySelection = this.Services.Selection.PrimarySelection == this.ExtendedItem; - if (isPrimarySelection) - DependencyPropertyDescriptor.FromProperty(FrameworkElement.HeightProperty, typeof (Shape)) - .AddValueChanged(ExtendedItem.View, (s, ev) => ResetWidthHeightProperties()); - } - #endregion protected void UpdateAdornerVisibility() @@ -186,8 +175,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions protected void ResetWidthHeightProperties() { -// ExtendedItem.Properties.GetProperty(FrameworkElement.HeightProperty).Reset(); -// ExtendedItem.Properties.GetProperty(FrameworkElement.WidthProperty).Reset(); + ExtendedItem.Properties.GetProperty(FrameworkElement.HeightProperty).Reset(); + ExtendedItem.Properties.GetProperty(FrameworkElement.WidthProperty).Reset(); } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs index 614016985d..fb7f46ac15 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs @@ -194,8 +194,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions } else { - if (drag.IsCanceled) changeGroup.Abort(); - else changeGroup.Commit(); + if (drag.IsCanceled) + changeGroup.Abort(); + else + changeGroup.Commit(); changeGroup = null; } @@ -222,10 +224,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions Invalidate(); this.ExtendedItem.PropertyChanged += OnPropertyChanged; - this.Services.Selection.PrimarySelectionChanged += OnPrimarySelectionChanged; resizeBehavior = PlacementOperation.GetPlacementBehavior(extendedItemArray); UpdateAdornerVisibility(); - OnPrimarySelectionChanged(null, null); } #endregion diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs index 93e948bab9..84a80bf512 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs @@ -74,6 +74,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions if (Index > 0) { p = pl != null ? pl.Points[Index] : pg.Points[Index]; + + 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))); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs index 4c0e3f924e..0a9d75e7e7 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs @@ -176,9 +176,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions operation.CurrentContainerBehavior.BeforeSetPosition(operation); operation.CurrentContainerBehavior.SetPosition(info); } - - ResetWidthHeightProperties(); - } void CommitOperation() @@ -204,19 +201,18 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions _selectedThumbs[i].Y = points[i].Y; } ExtendedItem.Properties.GetProperty(pl != null ? Polyline.PointsProperty : Polygon.PointsProperty).SetValue(points); - ResetWidthHeightProperties(); operation.Commit(); operation = null; } else { - changeGroup.Commit(); + if (changeGroup != null) + changeGroup.Commit(); changeGroup = null; } _isResizing = false; - ResetWidthHeightProperties(); Invalidate(); } @@ -339,17 +335,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions Invalidate(); - ResetWidthHeightProperties(); - ResetThumbs(); _isDragging = false; extendedItemArray[0] = ExtendedItem; ExtendedItem.PropertyChanged += OnPropertyChanged; - Services.Selection.PrimarySelectionChanged += OnPrimarySelectionChanged; resizeBehavior = PlacementOperation.GetPlacementBehavior(extendedItemArray); UpdateAdornerVisibility(); - OnPrimarySelectionChanged(null, null); } #endregion From 3486ea6d05aa7db743cb5649fc6aa753ecd11268 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Mon, 29 Dec 2014 13:09:30 +0100 Subject: [PATCH 14/52] Better Basic Metadata --- .../WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs index de7fb9ac5b..0456354940 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs @@ -300,10 +300,15 @@ 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.PointsProperty, new PointCollection() { new Point(0, 0), new Point(20, 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(Polygon), Polygon.PointsProperty, new PointCollection() { new Point(0, 20), new Point(20, 20), new Point(10, 0) }); + Metadata.AddDefaultPropertyValue(typeof(Polygon), Polygon.StrokeProperty, Brushes.Black); + Metadata.AddDefaultPropertyValue(typeof(Polygon), Polygon.StrokeThicknessProperty, 2d); + Metadata.AddDefaultPropertyValue(typeof(Polygon), Polygon.StretchProperty, Stretch.None); Metadata.AddDefaultPropertyValue(typeof(Rectangle), Rectangle.FillProperty, Brushes.Transparent); Metadata.AddDefaultPropertyValue(typeof(Rectangle), Rectangle.StrokeProperty, Brushes.Black); From 2d77356c7a4492316b8d6a1fd2b7c727a6f98622 Mon Sep 17 00:00:00 2001 From: jogibear9988 Date: Mon, 29 Dec 2014 14:02:58 +0100 Subject: [PATCH 15/52] GitIgnore Vs2015 Files --- .gitignore | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index 1d2ebb26f2..d65d9d2e06 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,10 @@ bin/ /src/AddIns/Misc/PackageManagement/Packages/AvalonEdit/lib /packages/ /src/Tools/ResGet/*.log + + +*.ide/ +*.sdsettings +*.DotSettings.user +*.suo +.DS_Store \ No newline at end of file From 37d34713bf8942db147d0abb547b0b3fdea64179 Mon Sep 17 00:00:00 2001 From: jogibear9988 Date: Mon, 29 Dec 2014 14:11:35 +0100 Subject: [PATCH 16/52] Null Ref fix --- .../WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs index d408c95746..b4be953816 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs @@ -203,8 +203,10 @@ namespace ICSharpCode.WpfDesign.XamlDom ResetInternal(); propertyValue = value; - propertyValue.ParentProperty = this; - propertyValue.AddNodeTo(this); + if (propertyValue != null) { + propertyValue.ParentProperty = this; + propertyValue.AddNodeTo(this); + } UpdateValueOnInstance(); ParentObject.OnPropertyChanged(this); From c021640165889c0ea0f7f1c5a93b76d080d187bc Mon Sep 17 00:00:00 2001 From: jkuehner Date: Mon, 29 Dec 2014 17:35:20 +0100 Subject: [PATCH 17/52] Draw Line extensions also work in Grid --- .../{CanvasDrawLineBehavior.cs => DrawLineExtension.cs} | 3 ++- ...CanvasDrawPolyLineBehavior.cs => DrawPolyLineExtension.cs} | 3 ++- .../WpfDesign.Designer/Project/WpfDesign.Designer.csproj | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) rename src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/{CanvasDrawLineBehavior.cs => DrawLineExtension.cs} (97%) rename src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/{CanvasDrawPolyLineBehavior.cs => DrawPolyLineExtension.cs} (98%) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawLineBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawLineExtension.cs similarity index 97% rename from src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawLineBehavior.cs rename to src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawLineExtension.cs index 4b48228c7d..0f592e56b3 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawLineBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawLineExtension.cs @@ -29,7 +29,8 @@ using ICSharpCode.WpfDesign.Designer.Services; namespace ICSharpCode.WpfDesign.Designer.Extensions { [ExtensionFor(typeof(Canvas))] - public class CanvasDrawLineBehavior : BehaviorExtension, IDrawItemExtension + [ExtensionFor(typeof(Grid))] + public class DrawLineExtension : BehaviorExtension, IDrawItemExtension { private ChangeGroup changeGroup; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawPolyLineBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPolyLineExtension.cs similarity index 98% rename from src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawPolyLineBehavior.cs rename to src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPolyLineExtension.cs index 132abc46e2..b475ad34a0 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawPolyLineBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPolyLineExtension.cs @@ -29,7 +29,8 @@ using ICSharpCode.WpfDesign.Designer.Services; namespace ICSharpCode.WpfDesign.Designer.Extensions { [ExtensionFor(typeof(Canvas))] - public class CanvasDrawPolyLineBehavior : BehaviorExtension, IDrawItemExtension + [ExtensionFor(typeof(Grid))] + public class DrawPolyLineExtension : BehaviorExtension, IDrawItemExtension { private ChangeGroup changeGroup; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj index 50cd7d67d2..6491ded4cb 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj @@ -86,8 +86,8 @@ - - + + DefaultCommandsContextMenu.xaml Code From cab11dd55b659461bf2f790fe770f6e5559dfdcf Mon Sep 17 00:00:00 2001 From: jkuehner Date: Mon, 29 Dec 2014 18:43:56 +0100 Subject: [PATCH 18/52] Basic work on a DrawPathExtension --- .../Project/BasicMetadata.cs | 4 + .../Project/Extensions/DrawLineExtension.cs | 2 +- .../Project/Extensions/DrawPathExtension.cs | 161 +++++++ .../Extensions/DrawPolyLineExtension.cs | 2 +- .../Extensions/PathHandlerExtension.cs | 453 ++++++++++++++++++ .../Project/WpfDesign.Designer.csproj | 2 + 6 files changed, 622 insertions(+), 2 deletions(-) create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPathExtension.cs create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs index 0456354940..91c20c5c96 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs @@ -310,6 +310,10 @@ namespace ICSharpCode.WpfDesign.Designer Metadata.AddDefaultPropertyValue(typeof(Polygon), Polygon.StrokeThicknessProperty, 2d); Metadata.AddDefaultPropertyValue(typeof(Polygon), Polygon.StretchProperty, Stretch.None); + Metadata.AddDefaultPropertyValue(typeof(Path), Path.StrokeProperty, Brushes.Black); + Metadata.AddDefaultPropertyValue(typeof(Path), Path.StrokeThicknessProperty, 2d); + Metadata.AddDefaultPropertyValue(typeof(Path), Path.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); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawLineExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawLineExtension.cs index 0f592e56b3..3fdaec59dd 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawLineExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawLineExtension.cs @@ -64,7 +64,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions operation.Commit(); } - createdItem.Properties[Shape.StrokeProperty].SetValue(Colors.Black); + createdItem.Properties[Shape.StrokeProperty].SetValue(Brushes.Black); createdItem.Properties[Shape.StrokeThicknessProperty].SetValue(2d); createdItem.Properties[Shape.StretchProperty].SetValue(Stretch.None); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPathExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPathExtension.cs new file mode 100644 index 0000000000..cbbb325a6c --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPathExtension.cs @@ -0,0 +1,161 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Linq; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Shapes; +using ICSharpCode.WpfDesign.Extensions; +using ICSharpCode.WpfDesign.Designer.Services; + +namespace ICSharpCode.WpfDesign.Designer.Extensions +{ + [ExtensionFor(typeof(Canvas))] + [ExtensionFor(typeof(Grid))] + public class DrawPathExtension : BehaviorExtension, IDrawItemExtension + { + private ChangeGroup changeGroup; + + DesignItem CreateItem(DesignContext context, Type componentType) + { + object newInstance = context.Services.ExtensionManager.CreateInstanceWithCustomInstanceFactory(componentType, null); + DesignItem item = context.Services.Component.RegisterComponentForDesigner(newInstance); + changeGroup = item.OpenGroup("Draw Path"); + context.Services.ExtensionManager.ApplyDefaultInitializers(item); + return item; + } + + #region IDrawItemBehavior implementation + + public bool CanItemBeDrawn(Type createItemType) + { + return createItemType == typeof(Path); + } + + public void StartDrawItem(DesignItem clickedOn, Type createItemType, IDesignPanel panel, System.Windows.Input.MouseEventArgs e) + { + var createdItem = CreateItem(panel.Context, createItemType); + + var startPoint = e.GetPosition(clickedOn.View); + var operation = PlacementOperation.TryStartInsertNewComponents(clickedOn, + new DesignItem[] { createdItem }, + new Rect[] { new Rect(startPoint.X, startPoint.Y, double.NaN, double.NaN) }, + PlacementType.AddItem); + if (operation != null) { + createdItem.Services.Selection.SetSelectedComponents(new DesignItem[] { createdItem }); + operation.Commit(); + } + + createdItem.Properties[Shape.StrokeProperty].SetValue(Brushes.Black); + createdItem.Properties[Shape.StrokeThicknessProperty].SetValue(2d); + createdItem.Properties[Shape.StretchProperty].SetValue(Stretch.None); + + var figure = new PathFigure(); + var geometry = new PathGeometry(); + var geometryDesignItem = createdItem.Services.Component.RegisterComponentForDesigner(geometry); + var figureDesignItem = createdItem.Services.Component.RegisterComponentForDesigner(figure); + createdItem.Properties[Path.DataProperty].SetValue(geometry); + geometryDesignItem.Properties[PathGeometry.FiguresProperty].CollectionElements.Add(figureDesignItem); + figureDesignItem.Properties[PathFigure.StartPointProperty].SetValue(new Point(0,0)); + + new DrawPathMouseGesture(figure, createdItem, clickedOn.View, changeGroup).Start(panel, (MouseButtonEventArgs) e); + } + + #endregion + + sealed class DrawPathMouseGesture : ClickOrDragMouseGesture + { + private ChangeGroup changeGroup; + private DesignItem newLine; + private Point startPoint; + private PathFigure figure; + + public DrawPathMouseGesture(PathFigure figure, DesignItem newLine, IInputElement relativeTo, ChangeGroup changeGroup) + { + this.newLine = newLine; + this.positionRelativeTo = relativeTo; + this.changeGroup = changeGroup; + this.figure = figure; + figure.Segments.Add(new LineSegment()); + + startPoint = Mouse.GetPosition(null); + } + + protected override void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + e.Handled = true; + base.OnPreviewMouseLeftButtonDown(sender, e); + } + + protected override void OnMouseMove(object sender, MouseEventArgs e) + { + var delta = e.GetPosition(null) - startPoint; + var point = new Point(delta.X, delta.Y); + + var segment = figure.Segments.Last(); + if (segment is LineSegment) + { + ((LineSegment)segment).Point = point; + } + } + + protected override void OnMouseUp(object sender, MouseButtonEventArgs e) + { + var delta = e.GetPosition(null) - startPoint; + var point = new Point(delta.X, delta.Y); + + figure.Segments.Add(new LineSegment(point, false)); + } + + protected override void OnMouseDoubleClick(object sender, MouseButtonEventArgs e) + { + base.OnMouseDoubleClick(sender, e); + + var geometry = newLine.Properties[Path.DataProperty].Value; + geometry.Properties[PathGeometry.FiguresProperty].CollectionElements.Clear(); + geometry.Properties[PathGeometry.FiguresProperty].SetValue(figure.ToString()); + + if (changeGroup != null) { + changeGroup.Commit(); + changeGroup = null; + } + + Stop(); + } + + protected override void OnStopped() + { + if (changeGroup != null) { + changeGroup.Abort(); + changeGroup = null; + } + if (services.Tool.CurrentTool is CreateComponentTool) { + services.Tool.CurrentTool = services.Tool.PointerTool; + } + + ((DesignPanel) newLine.Services.DesignPanel).AdornerLayer.UpdateAdornersForElement(this.newLine.View, true); + + base.OnStopped(); + } + + } + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPolyLineExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPolyLineExtension.cs index b475ad34a0..e3d6bf1af1 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPolyLineExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPolyLineExtension.cs @@ -64,7 +64,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions operation.Commit(); } - createdItem.Properties[Shape.StrokeProperty].SetValue(Colors.Black); + createdItem.Properties[Shape.StrokeProperty].SetValue(Brushes.Black); createdItem.Properties[Shape.StrokeThicknessProperty].SetValue(2d); createdItem.Properties[Shape.StretchProperty].SetValue(Stretch.None); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs new file mode 100644 index 0000000000..ad12f41610 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs @@ -0,0 +1,453 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using ICSharpCode.WpfDesign.Extensions; +using ICSharpCode.WpfDesign; +using ICSharpCode.WpfDesign.Adorners; +using ICSharpCode.WpfDesign.Designer; +using ICSharpCode.WpfDesign.Designer.Controls; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Shapes; +using System.Windows; +using System.Windows.Controls; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using ICSharpCode.WpfDesign.Designer.UIExtensions; + +namespace ICSharpCode.WpfDesign.Designer.Extensions +{ + /// + /// Description of PolyLineHandlerExtension. + /// + [ExtensionFor(typeof(Path))] + internal class PathHandlerExtension : LineExtensionBase, IKeyDown, IKeyUp + { + private readonly Dictionary _selectedThumbs = new Dictionary(); + private bool _isDragging; + ZoomControl _zoom; + + #region thumb methods + protected ResizeThumb CreateThumb(PlacementAlignment alignment, Cursor cursor, int index) + { + ResizeThumb resizeThumb = new MultiPointResizeThumb { Index = index, Alignment = alignment, Cursor = cursor, IsPrimarySelection = true }; + AdornerPlacement ap = Place(ref resizeThumb, alignment, index); + (resizeThumb as MultiPointResizeThumb).AdornerPlacement = ap; + + AdornerPanel.SetPlacement(resizeThumb, ap); + adornerPanel.Children.Add(resizeThumb); + + DragListener drag = new DragListener(resizeThumb); + + WeakEventManager.AddHandler(resizeThumb, "PreviewMouseLeftButtonDown", ResizeThumbOnMouseLeftButtonUp); + + drag.Started += drag_Started; + drag.Changed += drag_Changed; + drag.Completed += drag_Completed; + return resizeThumb; + } + + private void ResetThumbs() + { + foreach (FrameworkElement rt in adornerPanel.Children) + { + if (rt is ResizeThumb) + (rt as ResizeThumb).IsPrimarySelection = true; + } + _selectedThumbs.Clear(); + } + + private void SelectThumb(MultiPointResizeThumb mprt) + { + var points = GetPoints(); + Point p = points[mprt.Index]; + _selectedThumbs.Add(mprt.Index, new Bounds { X = p.X, Y = p.Y }); + + mprt.IsPrimarySelection = false; + } + + #endregion + + #region eventhandlers + + private void ResizeThumbOnMouseLeftButtonUp(object sender, MouseButtonEventArgs mouseButtonEventArgs) + { + //get current thumb + MultiPointResizeThumb mprt = sender as MultiPointResizeThumb; + if (mprt != null) + { + //shift+ctrl will remove selected point + if ((Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) && + (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))) + { + //unselect all points + ResetThumbs(); + var points = GetPoints(); + + //iterate thumbs to lower index of remaining thumbs + foreach (MultiPointResizeThumb m in adornerPanel.Children) + { + if (m.Index > mprt.Index) + m.Index--; + } + + //remove point and thumb + points.RemoveAt(mprt.Index); + adornerPanel.Children.Remove(mprt); + + Invalidate(); + } + else + { + //if not keyboard ctrl is pressed and selected point is not previously selected, clear selection + if (!_selectedThumbs.ContainsKey(mprt.Index) & !Keyboard.IsKeyDown(Key.LeftCtrl) & + !Keyboard.IsKeyDown(Key.RightCtrl)) + { + ResetThumbs(); + } + //add selected thumb, if ctrl pressed this could be all points in poly + if (!_selectedThumbs.ContainsKey(mprt.Index)) + SelectThumb(mprt); + _isDragging = false; + } + } + } + + // TODO : Remove all hide/show extensions from here. + protected void drag_Started(DragListener drag) + { + //get current thumb + MultiPointResizeThumb mprt = (drag.Target as MultiPointResizeThumb); + if (mprt != null) + { + SetOperation(); + } + } + + void SetOperation() + { + var designPanel = ExtendedItem.Services.DesignPanel as DesignPanel; + _zoom = designPanel.TryFindParent(); + + if (resizeBehavior != null) + operation = PlacementOperation.Start(extendedItemArray, PlacementType.Resize); + else + { + changeGroup = ExtendedItem.Context.OpenGroup("Resize", extendedItemArray); + } + _isResizing = true; + } + + void ChangeOperation(List points) + { + //this is for SharpDevelop built in undo functionality + if (operation != null) + { + var info = operation.PlacedItems[0]; + var result = info.OriginalBounds; + + IEnumerable xs = points.Select(x => x.X); + IEnumerable ys = points.Select(y => y.Y); + result.X = (double)(info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance); + result.Y = (double)(info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance); + result.Width = xs.Max() - xs.Min(); + result.Height = ys.Max() - ys.Min(); + + info.Bounds = result.Round(); + operation.CurrentContainerBehavior.BeforeSetPosition(operation); + operation.CurrentContainerBehavior.SetPosition(info); + } + } + + void CommitOperation() + { + if (operation != null) + { + PointCollection points; + Polygon pg = ExtendedItem.View as Polygon; + Polyline pl = ExtendedItem.View as Polyline; + if (pl == null) + { + points = pg.Points; + + } + else + { + points = pl.Points; + } + + foreach (int i in _selectedThumbs.Keys) + { + _selectedThumbs[i].X = points[i].X; + _selectedThumbs[i].Y = points[i].Y; + } + ExtendedItem.Properties.GetProperty(pl != null ? Polyline.PointsProperty : Polygon.PointsProperty).SetValue(points); + operation.Commit(); + + operation = null; + } + else + { + if (changeGroup != null) + changeGroup.Commit(); + changeGroup = null; + } + _isResizing = false; + + Invalidate(); + } + + protected void drag_Changed(DragListener drag) + { + var points = GetPoints(); + + MultiPointResizeThumb mprt = drag.Target as MultiPointResizeThumb; + if (mprt != null) + { + double dx = 0; + double dy = 0; + //if has zoomed + if (_zoom != null) + { + dx = drag.Delta.X * (1 / _zoom.CurrentZoom); + dy = drag.Delta.Y * (1 / _zoom.CurrentZoom); + } + + Double theta; + //if one point selected snapping angle is calculated in relation to previous point + if (_selectedThumbs.Count == 1) + { + 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); + } + else//if multiple points snapping angle is calculated in relation to mouse dragging angle + { + theta = (180 / Math.PI) * Math.Atan2(dy, dx); + } + + //snappingAngle is used for snapping function to horizontal or vertical plane in line drawing, and is activated by pressing ctrl or shift button + int? snapAngle = null; + + //shift+alt gives a new point + if ((Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) && (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt))) + { + //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 + //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)) + { + + //duplicate point that is selected + Point p = points[mprt.Index]; + + //insert duplicate + points.Insert(mprt.Index, p); + + //create adorner marker + CreateThumb(PlacementAlignment.BottomRight, Cursors.Cross, mprt.Index); + + //set index of all points that had a higher index than selected to +1 + foreach (FrameworkElement rt in adornerPanel.Children) + { + if (rt is MultiPointResizeThumb) + { + MultiPointResizeThumb t = rt as MultiPointResizeThumb; + if (t.Index > mprt.Index) + t.Index++; + } + } + + //set index of new point to old point index + 1 + mprt.Index = mprt.Index + 1; + ResetThumbs(); + SelectThumb(mprt); + + } + snapAngle = 10; + } + + //snapping occurs when mouse is within 10 degrees from horizontal or vertical plane if shift is pressed + else if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) + { + snapAngle = 10; + } + //snapping occurs within 45 degree intervals that is line will always be horizontal or vertical if alt is pressed + else if (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt)) + { + snapAngle = 45; + } + _isDragging = true; + points = MovePoints(points, dx, dy, theta, snapAngle); + + } + ChangeOperation(points); + (drag.Target as ResizeThumb).InvalidateArrange(); + } + + protected void drag_Completed(DragListener drag) + { + MultiPointResizeThumb mprt = drag.Target as MultiPointResizeThumb; + if (mprt != null) + { + if (operation != null && drag.IsCanceled) + { + operation.Abort(); + } + else if (drag.IsCanceled) + { + changeGroup.Abort(); + } + CommitOperation(); + } + } + + + + protected override void OnInitialized() + { + base.OnInitialized(); + + var points = GetPoints(); + + resizeThumbs = new List(); + for (int i = 1; i < points.Count; i++) + { + CreateThumb(PlacementAlignment.BottomRight, Cursors.Cross, i); + } + + Invalidate(); + + ResetThumbs(); + _isDragging = false; + + extendedItemArray[0] = ExtendedItem; + ExtendedItem.PropertyChanged += OnPropertyChanged; + resizeBehavior = PlacementOperation.GetPlacementBehavior(extendedItemArray); + UpdateAdornerVisibility(); + } + + #endregion + + List GetPoints() + { + var retVal = new List(); + + var path = this.ExtendedItem.View as Path; + var geometry = path.Data as PathGeometry; + if (geometry!=null) { + var figure = geometry.Figures[0] as PathFigure; + if (figure != null) { + foreach (var s in figure.Segments) { + if (s is LineSegment) + retVal.Add(((LineSegment)s).Point); + else if (s is PolyLineSegment) + retVal.AddRange(((PolyLineSegment)s).Points); +// else if (s is BezierSegment) +// retVal.Add(((BezierSegment)s).Point3); +// else if (s is QuadraticBezierSegment) +// retVal.Add(((QuadraticBezierSegment)s).Point2); +// else if (s is ArcSegment) +// retVal.Add(((ArcSegment)s).Point); + } + } + } + + return retVal; + } + + List MovePoints(List pc, double displacementX, double displacementY, double theta, int? snapangle) + { + //iterate all selected points + foreach (int i in _selectedThumbs.Keys) + { + Point p = pc[i]; + + //x and y is calculated from the currentl point + double x = _selectedThumbs[i].X + displacementX; + double y = _selectedThumbs[i].Y + displacementY; + + //if snap is applied + if (snapangle != null) + { + if (_selectedThumbs.Count > 0) + { + //horizontal snap + if (Math.Abs(theta) < snapangle || 180 - Math.Abs(theta) < snapangle) + { + //if one point selected use point before as snap point, else snap to movement + y = _selectedThumbs.Count == 1 ? pc[i - 1].Y : y - displacementY; + } + 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 + x = _selectedThumbs.Count == 1 ? pc[i - 1].X : x - displacementX; + } + } + } + + p.X = x; + p.Y = y; + pc[i] = p; + } + return pc; + } + + #region IKeyDown + + public bool InvokeDefaultAction + { + get { return _selectedThumbs.Count == 0 || _selectedThumbs.Count == GetPoints().Count - 1; } + } + + int _movingDistance; + public void KeyDownAction(object sender, KeyEventArgs e) + { + Debug.WriteLine("KeyDown"); + if (IsArrowKey(e.Key)) + if (operation == null) + { + SetOperation(); + _movingDistance = 0; + } + + + var dx1 = (e.Key == Key.Left) ? Keyboard.IsKeyDown(Key.LeftShift) ? _movingDistance - 10 : _movingDistance - 1 : 0; + var dy1 = (e.Key == Key.Up) ? Keyboard.IsKeyDown(Key.LeftShift) ? _movingDistance - 10 : _movingDistance - 1 : 0; + var dx2 = (e.Key == Key.Right) ? Keyboard.IsKeyDown(Key.LeftShift) ? _movingDistance + 10 : _movingDistance + 1 : 0; + var dy2 = (e.Key == Key.Down) ? Keyboard.IsKeyDown(Key.LeftShift) ? _movingDistance + 10 : _movingDistance + 1 : 0; + + ChangeOperation(MovePoints(GetPoints(), dx1 + dx2, dy1 + dy2, 0, null)); + _movingDistance = (dx1 + dx2 + dy1 + dy2); + } + + public void KeyUpAction(object sender, KeyEventArgs e) + { + Debug.WriteLine("Keyup"); + if (IsArrowKey(e.Key)) + CommitOperation(); + } + + bool IsArrowKey(Key key) + { + return (key == Key.Left || key == Key.Right || key == Key.Up || key == Key.Down); + } + #endregion + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj index 6491ded4cb..7c51c7e382 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj @@ -87,6 +87,7 @@ + DefaultCommandsContextMenu.xaml @@ -100,6 +101,7 @@ EditStyleContextMenu.xaml + From 93d8671d9bfaba2af84628e0eb8e6e176fb5e09c Mon Sep 17 00:00:00 2001 From: jkuehner Date: Mon, 29 Dec 2014 18:47:21 +0100 Subject: [PATCH 19/52] Draw Path extension now works. --- .../Project/Extensions/DrawPathExtension.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPathExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPathExtension.cs index cbbb325a6c..ef81f9ad74 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPathExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPathExtension.cs @@ -73,7 +73,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions var geometryDesignItem = createdItem.Services.Component.RegisterComponentForDesigner(geometry); var figureDesignItem = createdItem.Services.Component.RegisterComponentForDesigner(figure); createdItem.Properties[Path.DataProperty].SetValue(geometry); - geometryDesignItem.Properties[PathGeometry.FiguresProperty].CollectionElements.Add(figureDesignItem); + //geometryDesignItem.Properties[PathGeometry.FiguresProperty].CollectionElements.Add(figureDesignItem); figureDesignItem.Properties[PathFigure.StartPointProperty].SetValue(new Point(0,0)); new DrawPathMouseGesture(figure, createdItem, clickedOn.View, changeGroup).Start(panel, (MouseButtonEventArgs) e); @@ -87,6 +87,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions private DesignItem newLine; private Point startPoint; private PathFigure figure; + private DesignItem geometry; public DrawPathMouseGesture(PathFigure figure, DesignItem newLine, IInputElement relativeTo, ChangeGroup changeGroup) { @@ -97,6 +98,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions figure.Segments.Add(new LineSegment()); startPoint = Mouse.GetPosition(null); + + geometry = newLine.Properties[Path.DataProperty].Value; } protected override void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) @@ -114,7 +117,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions if (segment is LineSegment) { ((LineSegment)segment).Point = point; - } + } + geometry.Properties[PathGeometry.FiguresProperty].SetValue(figure.ToString()); } protected override void OnMouseUp(object sender, MouseButtonEventArgs e) @@ -123,14 +127,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions var point = new Point(delta.X, delta.Y); figure.Segments.Add(new LineSegment(point, false)); + geometry.Properties[PathGeometry.FiguresProperty].SetValue(figure.ToString()); } protected override void OnMouseDoubleClick(object sender, MouseButtonEventArgs e) { base.OnMouseDoubleClick(sender, e); - var geometry = newLine.Properties[Path.DataProperty].Value; - geometry.Properties[PathGeometry.FiguresProperty].CollectionElements.Clear(); geometry.Properties[PathGeometry.FiguresProperty].SetValue(figure.ToString()); if (changeGroup != null) { From a18f1f7821f64a7e1c5895e5d4aeb5ad05a79932 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Mon, 29 Dec 2014 19:01:43 +0100 Subject: [PATCH 20/52] Path Handler Extension --- .../Extensions/MultiPointResizeThumb.cs | 74 ++++++++++--------- .../Extensions/PathHandlerExtension.cs | 35 ++++----- .../PointTrackerPlacementSupport.cs | 34 ++++++--- 3 files changed, 74 insertions(+), 69 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/MultiPointResizeThumb.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/MultiPointResizeThumb.cs index b24a1bd773..5ef05c0c9b 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/MultiPointResizeThumb.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/MultiPointResizeThumb.cs @@ -1,13 +1,22 @@ -/* - * Created by SharpDevelop. - * User: trubra - * Date: 2014-12-22 - * Time: 11:06 - * - * To change this template use Tools | Options | Coding | Edit Standard Headers. - */ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + using System; -using System.Windows; using ICSharpCode.WpfDesign.Adorners; using ICSharpCode.WpfDesign.Designer.Controls; @@ -17,33 +26,26 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions /// Description of MultiPointResizeThumb. /// sealed class MultiPointResizeThumb: ResizeThumb - { - private int _index; - public int Index - { - get { return _index; } - set - { - _index = value; - PointTrackerPlacementSupport p = AdornerPlacement as PointTrackerPlacementSupport; - if (p != null) - p.Index = value; - } - } - - public void Invalidate() - { - PointTrackerPlacementSupport p = AdornerPlacement as PointTrackerPlacementSupport; - - } - - private AdornerPlacement _adornerPlacement; + { + private int _index; + public int Index + { + get { return _index; } + set + { + _index = value; + var p = AdornerPlacement as PointTrackerPlacementSupport; + if (p != null) + p.Index = value; + } + } - public AdornerPlacement AdornerPlacement - { - get { return _adornerPlacement; } - set { _adornerPlacement = value; } - } + private AdornerPlacement _adornerPlacement; + public AdornerPlacement AdornerPlacement + { + get { return _adornerPlacement; } + set { _adornerPlacement = value; } + } - } + } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs index ad12f41610..7e2709b619 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs @@ -36,7 +36,7 @@ using ICSharpCode.WpfDesign.Designer.UIExtensions; namespace ICSharpCode.WpfDesign.Designer.Extensions { /// - /// Description of PolyLineHandlerExtension. + /// Description of PathHandlerExtension. /// [ExtensionFor(typeof(Path))] internal class PathHandlerExtension : LineExtensionBase, IKeyDown, IKeyUp @@ -181,25 +181,14 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions { if (operation != null) { - PointCollection points; - Polygon pg = ExtendedItem.View as Polygon; - Polyline pl = ExtendedItem.View as Polyline; - if (pl == null) - { - points = pg.Points; - - } - else - { - points = pl.Points; - } - - foreach (int i in _selectedThumbs.Keys) - { - _selectedThumbs[i].X = points[i].X; - _selectedThumbs[i].Y = points[i].Y; - } - ExtendedItem.Properties.GetProperty(pl != null ? Polyline.PointsProperty : Polygon.PointsProperty).SetValue(points); +// foreach (int i in _selectedThumbs.Keys) +// { +// _selectedThumbs[i].X = points[i].X; +// _selectedThumbs[i].Y = points[i].Y; +// } + + //ExtendedItem.Properties.GetProperty(pl != null ? Polyline.PointsProperty : Polygon.PointsProperty).SetValue(points); + operation.Commit(); operation = null; @@ -346,10 +335,14 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions #endregion List GetPoints() + { + return GetPoints(this.ExtendedItem.View as Path); + } + + public static List GetPoints(Path path) { var retVal = new List(); - var path = this.ExtendedItem.View as Path; var geometry = path.Data as PathGeometry; if (geometry!=null) { var figure = geometry.Figures[0] as PathFigure; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs index 84a80bf512..e69a9ddabf 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs @@ -49,9 +49,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions Point p = new Point(0, 0); double thumbsize = 7; double distance = 0; - if (shape as Line != null) + if (shape is Line) { - Line s = shape as Line; + var s = shape as Line; double x, y; if (alignment == PlacementAlignment.BottomRight) @@ -65,20 +65,30 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions y = s.Y1; } p = new Point(x, y); - } - - Polygon pg = shape as Polygon; - Polyline pl = shape as Polyline; - if (pg != null || pl != null) - { + } else if (shape is Polygon) { + if (Index > 0) + { + var pg = shape as Polygon; + p = pg.Points[Index]; + } + } else if (shape is Polygon) { if (Index > 0) { - p = pl != null ? pl.Points[Index] : pg.Points[Index]; - - var transform = shape.RenderedGeometry.Transform; - p = transform.Transform(p); + var pg = shape as Polygon; + p = pg.Points[Index]; + } + } else if (shape is Path) { + if (Index > 0) + { + var path = shape as Path; + var points = PathHandlerExtension.GetPoints(path); + p = points[Index]; } } + + 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))); } From ef7668a3827d01779d4ca22ca887792574654104 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Mon, 29 Dec 2014 20:06:54 +0100 Subject: [PATCH 21/52] Bugfix Polyline --- .../Project/Extensions/PointTrackerPlacementSupport.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs index e69a9ddabf..6385a1a2ec 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs @@ -71,10 +71,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions var pg = shape as Polygon; p = pg.Points[Index]; } - } else if (shape is Polygon) { + } else if (shape is Polyline) { if (Index > 0) { - var pg = shape as Polygon; + var pg = shape as Polyline; p = pg.Points[Index]; } } else if (shape is Path) { From 755d653ef7a8995403a9ad7e397de1dfeaac484c Mon Sep 17 00:00:00 2001 From: jkuehner Date: Mon, 29 Dec 2014 20:19:56 +0100 Subject: [PATCH 22/52] A few fixes on the Geometry Extensions --- .../Project/Extensions/DrawPathExtension.cs | 1 + .../PointTrackerPlacementSupport.cs | 10 ++------ .../Extensions/PolyLineHandlerExtension.cs | 24 +------------------ 3 files changed, 4 insertions(+), 31 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPathExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPathExtension.cs index ef81f9ad74..d837a62f43 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPathExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPathExtension.cs @@ -134,6 +134,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions { base.OnMouseDoubleClick(sender, e); + figure.Segments.RemoveAt(figure.Segments.Count - 1); geometry.Properties[PathGeometry.FiguresProperty].SetValue(figure.ToString()); if (changeGroup != null) { diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs index 6385a1a2ec..7e0e8dae20 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs @@ -66,17 +66,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions } p = new Point(x, y); } else if (shape is Polygon) { - if (Index > 0) - { var pg = shape as Polygon; p = pg.Points[Index]; - } } else if (shape is Polyline) { - if (Index > 0) - { - var pg = shape as Polyline; - p = pg.Points[Index]; - } + var pg = shape as Polyline; + p = pg.Points[Index]; } else if (shape is Path) { if (Index > 0) { diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs index 0a9d75e7e7..7aee687777 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs @@ -157,27 +157,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions _isResizing = true; } - void ChangeOperation(PointCollection points) - { - //this is for SharpDevelop built in undo functionality - if (operation != null) - { - var info = operation.PlacedItems[0]; - var result = info.OriginalBounds; - - IEnumerable xs = points.Select(x => x.X); - IEnumerable ys = points.Select(y => y.Y); - result.X = (double)(info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance); - result.Y = (double)(info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance); - result.Width = xs.Max() - xs.Min(); - result.Height = ys.Max() - ys.Min(); - - info.Bounds = result.Round(); - operation.CurrentContainerBehavior.BeforeSetPosition(operation); - operation.CurrentContainerBehavior.SetPosition(info); - } - } - void CommitOperation() { if (operation != null) @@ -298,7 +277,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions points = MovePoints(points, dx, dy, theta, snapAngle); } - ChangeOperation(points); + (drag.Target as ResizeThumb).InvalidateArrange(); } @@ -415,7 +394,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions var dx2 = (e.Key == Key.Right) ? Keyboard.IsKeyDown(Key.LeftShift) ? _movingDistance + 10 : _movingDistance + 1 : 0; var dy2 = (e.Key == Key.Down) ? Keyboard.IsKeyDown(Key.LeftShift) ? _movingDistance + 10 : _movingDistance + 1 : 0; - ChangeOperation(MovePoints(GetPointCollection(), dx1 + dx2, dy1 + dy2, 0, null)); _movingDistance = (dx1 + dx2 + dy1 + dy2); } From 10a277fff90319067d44c636a5422aadbf9b5cbf Mon Sep 17 00:00:00 2001 From: jkuehner Date: Tue, 30 Dec 2014 01:46:36 +0100 Subject: [PATCH 23/52] Fix that SolidBrushEditor was to small, and show WPF Brushes --- .../Editors/BrushEditor/BrushEditor.cs | 18 +++++++++++++---- .../Editors/BrushEditor/BrushEditorView.xaml | 9 +++++++-- .../BrushEditor/BrushEditorView.xaml.cs | 20 ------------------- .../Editors/BrushEditor/SolidBrushEditor.xaml | 7 ++++++- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditor.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditor.cs index 635b45a4a3..2881979631 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditor.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditor.cs @@ -51,10 +51,16 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor .GetProperties(BindingFlags.Static | BindingFlags.Public) .Where(p => p.PropertyType == typeof(Color)) .Select(p => new BrushItem() - { - Name = p.Name, - Brush = new SolidColorBrush((Color)p.GetValue(null, null)) - }) + { + Name = p.Name, + Brush = new SolidColorBrush((Color)p.GetValue(null, null)) + }) + .ToArray(); + + public static BrushItem[] WpfBrushes = typeof(Brushes) + .GetProperties(BindingFlags.Static | BindingFlags.Public) + .Where(p => p.PropertyType == typeof(SolidColorBrush)) + .Select(p => new BrushItem() { Name = p.Name, Brush = (Brush)p.GetValue(null, null) }) .ToArray(); SolidColorBrush solidColorBrush = new SolidColorBrush(Colors.White); @@ -176,6 +182,10 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor public IEnumerable AvailableBrushes { get { return SystemBrushes; } } + + public IEnumerable AvailableWpfBrushes { + get { return WpfBrushes; } + } public void MakeGradientHorizontal() { diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditorView.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditorView.xaml index 2d89ae00a2..173b84cd9a 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditorView.xaml +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditorView.xaml @@ -7,7 +7,7 @@ xmlns:Converters="clr-namespace:ICSharpCode.WpfDesign.Designer.Converters" xmlns:PropertyGrid="clr-namespace:ICSharpCode.WpfDesign.Designer.PropertyGrid" xmlns:widgets="http://icsharpcode.net/sharpdevelop/widgets" - Width="395"> + Width="395" MinHeight="320"> @@ -73,7 +73,12 @@ - + + + diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditorView.xaml.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditorView.xaml.cs index c1cf4480be..8117ceb0ca 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditorView.xaml.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditorView.xaml.cs @@ -43,10 +43,6 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor DataContext = BrushEditor; SpecialInitializeComponent(); - - SetBinding(HeightProperty, new Binding("Brush") { - Converter = HeightConverter.Instance - }); } /// @@ -64,21 +60,5 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor } public BrushEditor BrushEditor { get; private set; } - - class HeightConverter : IValueConverter - { - public static HeightConverter Instance = new HeightConverter(); - - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - if (value is GradientBrush) return double.NaN; - return 315; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotImplementedException(); - } - } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/SolidBrushEditor.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/SolidBrushEditor.xaml index 3a5fffea09..fd74a99ec2 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/SolidBrushEditor.xaml +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/SolidBrushEditor.xaml @@ -3,7 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:widgets="http://icsharpcode.net/sharpdevelop/widgets" x:Name="this" - Height="284"> + Height="320"> @@ -13,5 +13,10 @@ SelectedValue="{Binding Color, ElementName=this}" SelectedValuePath="Brush.Color" /> + + + From 1a6cdeca931df593833faec7d87446132b247010 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Tue, 30 Dec 2014 09:42:02 +0100 Subject: [PATCH 24/52] PolyLine/gon Handler fixes, Path Handler worked on --- .../Project/Controls/DragListener.cs | 3 ++ .../Extensions/PathHandlerExtension.cs | 33 ++++++++++++------- .../PointTrackerPlacementSupport.cs | 3 -- .../Extensions/PolyLineHandlerExtension.cs | 9 ++--- .../Extensions/ResizeThumbExtension.cs | 14 +++++--- 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/DragListener.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/DragListener.cs index ae9dfaac51..20fab52fa2 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/DragListener.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/DragListener.cs @@ -81,6 +81,8 @@ namespace ICSharpCode.WpfDesign.Designer.Controls DeltaDelta = new Vector(); IsDown = true; IsCanceled = false; + if (MouseDown != null) + MouseDown(this); } void Target_MouseMove(object sender, MouseEventArgs e) @@ -125,6 +127,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls } } + public event DragHandler MouseDown; public event DragHandler Started; public event DragHandler Changed; public event DragHandler Completed; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs index 7e2709b619..0b1d43b4b6 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs @@ -59,6 +59,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions WeakEventManager.AddHandler(resizeThumb, "PreviewMouseLeftButtonDown", ResizeThumbOnMouseLeftButtonUp); + drag.MouseDown += drag_MouseDown; drag.Started += drag_Started; drag.Changed += drag_Changed; drag.Completed += drag_Completed; @@ -131,6 +132,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions } } + protected void drag_MouseDown(DragListener drag) + { + + } + // TODO : Remove all hide/show extensions from here. protected void drag_Started(DragListener drag) { @@ -222,12 +228,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions Double theta; //if one point selected snapping angle is calculated in relation to previous point - if (_selectedThumbs.Count == 1) - { + if (_selectedThumbs.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); - } - 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); } @@ -316,7 +319,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions var points = GetPoints(); resizeThumbs = new List(); - for (int i = 1; i < points.Count; i++) + for (int i = 0; i < points.Count; i++) { CreateThumb(PlacementAlignment.BottomRight, Cursors.Cross, i); } @@ -347,17 +350,23 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions if (geometry!=null) { var figure = geometry.Figures[0] as PathFigure; if (figure != null) { + retVal.Add(figure.StartPoint); foreach (var s in figure.Segments) { if (s is LineSegment) retVal.Add(((LineSegment)s).Point); else if (s is PolyLineSegment) retVal.AddRange(((PolyLineSegment)s).Points); -// else if (s is BezierSegment) -// retVal.Add(((BezierSegment)s).Point3); -// else if (s is QuadraticBezierSegment) -// retVal.Add(((QuadraticBezierSegment)s).Point2); -// else if (s is ArcSegment) -// retVal.Add(((ArcSegment)s).Point); + else if (s is BezierSegment) { + retVal.Add(((BezierSegment)s).Point1); + retVal.Add(((BezierSegment)s).Point2); + retVal.Add(((BezierSegment)s).Point3); + } + else if (s is QuadraticBezierSegment) { + retVal.Add(((QuadraticBezierSegment)s).Point1); + retVal.Add(((QuadraticBezierSegment)s).Point2); + } + else if (s is ArcSegment) + retVal.Add(((ArcSegment)s).Point); } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs index 7e0e8dae20..077826cb79 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs @@ -72,12 +72,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions var pg = shape as Polyline; p = pg.Points[Index]; } else if (shape is Path) { - if (Index > 0) - { var path = shape as Path; var points = PathHandlerExtension.GetPoints(path); p = points[Index]; - } } var transform = shape.RenderedGeometry.Transform; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs index 7aee687777..a696aac154 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs @@ -213,12 +213,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions Double theta; //if one point selected snapping angle is calculated in relation to previous point - if (_selectedThumbs.Count == 1) - { + if (_selectedThumbs.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); - } - 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); } @@ -307,7 +304,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions PointCollection points = GetPointCollection(); resizeThumbs = new List(); - for (int i = 1; i < points.Count; i++) + for (int i = 0; i < points.Count; i++) { CreateThumb(PlacementAlignment.BottomRight, Cursors.Cross, i); } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ResizeThumbExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ResizeThumbExtension.cs index 26d0de1c1c..25d0b6a8e9 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ResizeThumbExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ResizeThumbExtension.cs @@ -150,10 +150,16 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions double dy = 0; var alignment = (drag.Target as ResizeThumb).Alignment; - if (alignment.Horizontal == HorizontalAlignment.Left) dx = -drag.Delta.X; - if (alignment.Horizontal == HorizontalAlignment.Right) dx = drag.Delta.X; - if (alignment.Vertical == VerticalAlignment.Top) dy = -drag.Delta.Y; - if (alignment.Vertical == VerticalAlignment.Bottom) dy = drag.Delta.Y; + var delta = drag.Delta; + + var transform = this.ExtendedItem.View.RenderTransform; + if (transform != null) + delta = (Vector)transform.Inverse.Transform((Point)delta); + + if (alignment.Horizontal == HorizontalAlignment.Left) dx = -delta.X; + if (alignment.Horizontal == HorizontalAlignment.Right) dx = delta.X; + if (alignment.Vertical == VerticalAlignment.Top) dy = -delta.Y; + if (alignment.Vertical == VerticalAlignment.Bottom) dy = delta.Y; var designPanel = ExtendedItem.Services.DesignPanel as DesignPanel; From 1af21b6dedc91a7b4bec370a53943adffe36e535 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Tue, 30 Dec 2014 09:53:05 +0100 Subject: [PATCH 25/52] Posibility to draw a freeform while keeping Mouse Button Pressed --- .../Project/Extensions/DrawPolyLineExtension.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPolyLineExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPolyLineExtension.cs index e3d6bf1af1..c55dabcffc 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPolyLineExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPolyLineExtension.cs @@ -107,13 +107,17 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions if (newLine.View is Polyline) { if (((Polyline)newLine.View).Points.Count <= 1) ((Polyline)newLine.View).Points.Add(point); - ((Polyline)newLine.View).Points.RemoveAt(((Polyline)newLine.View).Points.Count - 1); - ((Polyline)newLine.View).Points.Add(point); + if (Mouse.LeftButton != MouseButtonState.Pressed) + ((Polyline)newLine.View).Points.RemoveAt(((Polyline)newLine.View).Points.Count - 1); + if (((Polyline)newLine.View).Points.Last() != point) + ((Polyline)newLine.View).Points.Add(point); } else { if (((Polygon)newLine.View).Points.Count <= 1) ((Polygon)newLine.View).Points.Add(point); - ((Polygon)newLine.View).Points.RemoveAt(((Polygon)newLine.View).Points.Count - 1); - ((Polygon)newLine.View).Points.Add(point); + if (Mouse.LeftButton != MouseButtonState.Pressed) + ((Polygon)newLine.View).Points.RemoveAt(((Polygon)newLine.View).Points.Count - 1); + if (((Polygon)newLine.View).Points.Last() != point) + ((Polygon)newLine.View).Points.Add(point); } } From 1adfe7d235b570ba0020085dc4925adb6b780451 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Thu, 1 Jan 2015 17:10:35 +0100 Subject: [PATCH 26/52] Path -> Support Extended. Points can now be modified. --- .../Extensions/PathHandlerExtension.cs | 219 ++++++++++++------ .../PointTrackerPlacementSupport.cs | 2 +- 2 files changed, 148 insertions(+), 73 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs index 0b1d43b4b6..c7fe348de7 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs @@ -79,7 +79,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions private void SelectThumb(MultiPointResizeThumb mprt) { var points = GetPoints(); - Point p = points[mprt.Index]; + Point p = points[mprt.Index].Point; _selectedThumbs.Add(mprt.Index, new Bounds { X = p.X, Y = p.Y }); mprt.IsPrimarySelection = false; @@ -162,7 +162,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions _isResizing = true; } - void ChangeOperation(List points) + void ChangeOperation(List points) { //this is for SharpDevelop built in undo functionality if (operation != null) @@ -170,8 +170,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions var info = operation.PlacedItems[0]; var result = info.OriginalBounds; - IEnumerable xs = points.Select(x => x.X); - IEnumerable ys = points.Select(y => y.Y); + IEnumerable xs = points.Select(x => x.Point.X); + IEnumerable ys = points.Select(y => y.Point.Y); result.X = (double)(info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance); result.Y = (double)(info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance); result.Width = xs.Max() - xs.Min(); @@ -229,7 +229,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions Double theta; //if one point selected snapping angle is calculated in relation to previous point if (_selectedThumbs.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(_selectedThumbs[mprt.Index].Y + dy - points[mprt.Index - 1].Point.Y, _selectedThumbs[mprt.Index].X + dx - points[mprt.Index - 1].Point.X); } else { //if multiple points snapping angle is calculated in relation to mouse dragging angle theta = (180 / Math.PI) * Math.Atan2(dy, dx); } @@ -238,45 +238,45 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions int? snapAngle = null; //shift+alt gives a new point - if ((Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) && (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt))) - { - //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 - //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)) - { - - //duplicate point that is selected - Point p = points[mprt.Index]; - - //insert duplicate - points.Insert(mprt.Index, p); - - //create adorner marker - CreateThumb(PlacementAlignment.BottomRight, Cursors.Cross, mprt.Index); - - //set index of all points that had a higher index than selected to +1 - foreach (FrameworkElement rt in adornerPanel.Children) - { - if (rt is MultiPointResizeThumb) - { - MultiPointResizeThumb t = rt as MultiPointResizeThumb; - if (t.Index > mprt.Index) - t.Index++; - } - } - - //set index of new point to old point index + 1 - mprt.Index = mprt.Index + 1; - ResetThumbs(); - SelectThumb(mprt); - - } - snapAngle = 10; - } +// if ((Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) && (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt))) +// { +// //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 +// //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)) +// { +// +// //duplicate point that is selected +// Point p = points[mprt.Index].Point; +// +// //insert duplicate +// points.Insert(mprt.Index, p); +// +// //create adorner marker +// CreateThumb(PlacementAlignment.BottomRight, Cursors.Cross, mprt.Index); +// +// //set index of all points that had a higher index than selected to +1 +// foreach (FrameworkElement rt in adornerPanel.Children) +// { +// if (rt is MultiPointResizeThumb) +// { +// MultiPointResizeThumb t = rt as MultiPointResizeThumb; +// if (t.Index > mprt.Index) +// t.Index++; +// } +// } +// +// //set index of new point to old point index + 1 +// mprt.Index = mprt.Index + 1; +// ResetThumbs(); +// SelectThumb(mprt); +// +// } +// snapAngle = 10; +// } //snapping occurs when mouse is within 10 degrees from horizontal or vertical plane if shift is pressed - else if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) + /*else*/ if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) { snapAngle = 10; } @@ -337,49 +337,124 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions #endregion - List GetPoints() + List GetPoints() { return GetPoints(this.ExtendedItem.View as Path); } - public static List GetPoints(Path path) + public static List GetPoints(Path path) { - var retVal = new List(); + var retVal = new List(); + AddGeometryPoints(retVal, path.Data); - var geometry = path.Data as PathGeometry; - if (geometry!=null) { - var figure = geometry.Figures[0] as PathFigure; - if (figure != null) { - retVal.Add(figure.StartPoint); - foreach (var s in figure.Segments) { - if (s is LineSegment) - retVal.Add(((LineSegment)s).Point); - else if (s is PolyLineSegment) - retVal.AddRange(((PolyLineSegment)s).Points); - else if (s is BezierSegment) { - retVal.Add(((BezierSegment)s).Point1); - retVal.Add(((BezierSegment)s).Point2); - retVal.Add(((BezierSegment)s).Point3); - } - else if (s is QuadraticBezierSegment) { - retVal.Add(((QuadraticBezierSegment)s).Point1); - retVal.Add(((QuadraticBezierSegment)s).Point2); + return retVal; + } + + private static void AddGeometryPoints(List list, Geometry geometry) + { + if (geometry is CombinedGeometry) { + var g = geometry as CombinedGeometry; + AddGeometryPoints(list, g.Geometry1); + AddGeometryPoints(list, g.Geometry2); + } else if (geometry is PathGeometry) { + var g = geometry as PathGeometry; + if (geometry!=null) { + foreach(var figure in g.Figures) { + list.Add(new PathPoint(figure.StartPoint, figure, PointType.StartPoint, (p) => figure.StartPoint = p)); + foreach (var s in figure.Segments) { + if (s is LineSegment) + list.Add(new PathPoint(((LineSegment)s).Point, s, PointType.LineSegment, (p) => ((LineSegment)s).Point = p)); + else if (s is PolyLineSegment) { + //list.AddRange(((PolyLineSegment)s).Points); + } + else if (s is BezierSegment) { + list.Add(new PathPoint(((BezierSegment)s).Point1, s, PointType.BezierSegment, (p) => ((BezierSegment)s).Point1 = p)); + //list.Add(((BezierSegment)s).Point1); + //list.Add(((BezierSegment)s).Point2); + //list.Add(((BezierSegment)s).Point3); + } + else if (s is QuadraticBezierSegment) { + list.Add(new PathPoint(((QuadraticBezierSegment)s).Point1, s, PointType.QuadricBezierSegment, (p) => ((QuadraticBezierSegment)s).Point1 = p)); + //list.Add(((QuadraticBezierSegment)s).Point1); + //list.Add(((QuadraticBezierSegment)s).Point2); + } + else if (s is ArcSegment) + list.Add(new PathPoint(((ArcSegment)s).Point, s, PointType.ArcSegment, (p) => ((ArcSegment)s).Point = p)); + //list.Add(((ArcSegment)s).Point); } - else if (s is ArcSegment) - retVal.Add(((ArcSegment)s).Point); } } + } else if (geometry is RectangleGeometry) { + var g = geometry as RectangleGeometry; + list.Add(new PathPoint(g.Rect.TopLeft, geometry, PointType.RectangleGeometryP1, null)); //(p) => g.Rect.Left = p.X)); + list.Add(new PathPoint(g.Rect.TopRight, geometry, PointType.RectangleGeometryP2, null)); //(p) => g.Rect.Width = p.X)); + list.Add(new PathPoint(g.Rect.BottomLeft, geometry, PointType.RectangleGeometryP3, null)); //(p) => g.Rect.Top = p.Y)); + list.Add(new PathPoint(g.Rect.BottomRight, geometry, PointType.RectangleGeometryP4, null)); //(p) => g.Rect.Height = p.Y)); +// list.Add(new Point(g.Rect.Left, g.Rect.Top)); +// list.Add(new Point(g.Rect.Left, g.Rect.Top + g.Rect.Height)); +// list.Add(new Point(g.Rect.Left + g.Rect.Width, g.Rect.Top)); +// list.Add(new Point(g.Rect.Left + g.Rect.Width, g.Rect.Top + g.Rect.Height)); + } else if (geometry is EllipseGeometry) { + var g = geometry as EllipseGeometry; + list.Add(new PathPoint(g.Center, geometry, PointType.EllipseGeometryCenter, (p) => g.Center = p)); + //list.Add(g.Center); + } else if (geometry is LineGeometry) { + var g = geometry as LineGeometry; + list.Add(new PathPoint(g.StartPoint, geometry, PointType.LineGeometryStart, (p) => g.StartPoint = p)); + list.Add(new PathPoint(g.EndPoint, geometry, PointType.LineGeometryEnd, (p) => g.EndPoint = p)); + //list.Add(g.StartPoint); + //list.Add(g.EndPoint); } + } + + public enum PointType{ + StartPoint, + LineSegment, + BezierSegment, + ArcSegment, + QuadricBezierSegment, - return retVal; + LineGeometryStart, + LineGeometryEnd, + EllipseGeometryCenter, + RectangleGeometryP1, + RectangleGeometryP2, + RectangleGeometryP3, + RectangleGeometryP4, } - - List MovePoints(List pc, double displacementX, double displacementY, double theta, int? snapangle) + + public class PathPoint { + public PathPoint(Point point, Object @object, PointType pointType, Action setLambda) + { + this._point = point; + this._setLambda = setLambda; + this.Object = @object; + } + + private Point _point; + Action _setLambda; + + public Point Point { + get{return _point;} + set{_setLambda(value);} + } + public Point ReferencePoint {get; private set;} + public PointType Start {get; private set;} + public PointType End {get; private set;} + public object Object {get; private set;} + } + + //Should not return a List of Points, no a List of Point Object wich say what a Point is. + //For Example: a Center Point of a Circle, should now it's a Center point! + //When he is selected, he should show another drag point to change the radius! + //a Combined Gemoetry should show a Adorner to change the combination mode! + + List MovePoints(List pc, double displacementX, double displacementY, double theta, int? snapangle) { //iterate all selected points foreach (int i in _selectedThumbs.Keys) { - Point p = pc[i]; + Point p = pc[i].Point; //x and y is calculated from the currentl point double x = _selectedThumbs[i].X + displacementX; @@ -394,19 +469,19 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions if (Math.Abs(theta) < snapangle || 180 - Math.Abs(theta) < snapangle) { //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 = _selectedThumbs.Count == 1 ? pc[i - 1].Point.Y : y - displacementY; } 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 - x = _selectedThumbs.Count == 1 ? pc[i - 1].X : x - displacementX; + x = _selectedThumbs.Count == 1 ? pc[i - 1].Point.X : x - displacementX; } } } p.X = x; p.Y = y; - pc[i] = p; + pc[i].Point = p; } return pc; } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs index 077826cb79..54c1fb8b54 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs @@ -74,7 +74,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions } else if (shape is Path) { var path = shape as Path; var points = PathHandlerExtension.GetPoints(path); - p = points[Index]; + p = points[Index].Point; } var transform = shape.RenderedGeometry.Transform; From 3cf4c86e234e52eee0bd4a74d263acc106a14b42 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Thu, 1 Jan 2015 17:21:00 +0100 Subject: [PATCH 27/52] Support modification of PathGeometrys --- .../Extensions/PathHandlerExtension.cs | 70 ++++++------------- 1 file changed, 20 insertions(+), 50 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs index c7fe348de7..a6e0d1f0d6 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs @@ -360,71 +360,48 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions var g = geometry as PathGeometry; if (geometry!=null) { foreach(var figure in g.Figures) { - list.Add(new PathPoint(figure.StartPoint, figure, PointType.StartPoint, (p) => figure.StartPoint = p)); + list.Add(new PathPoint(figure.StartPoint, figure, (p) => figure.StartPoint = p)); foreach (var s in figure.Segments) { if (s is LineSegment) - list.Add(new PathPoint(((LineSegment)s).Point, s, PointType.LineSegment, (p) => ((LineSegment)s).Point = p)); + list.Add(new PathPoint(((LineSegment)s).Point, s, (p) => ((LineSegment)s).Point = p)); else if (s is PolyLineSegment) { - //list.AddRange(((PolyLineSegment)s).Points); + var poly = s as PolyLineSegment; + for(int n=0; n poly.Points[n] = p)); + } } else if (s is BezierSegment) { - list.Add(new PathPoint(((BezierSegment)s).Point1, s, PointType.BezierSegment, (p) => ((BezierSegment)s).Point1 = p)); - //list.Add(((BezierSegment)s).Point1); - //list.Add(((BezierSegment)s).Point2); - //list.Add(((BezierSegment)s).Point3); + list.Add(new PathPoint(((BezierSegment)s).Point1, s, (p) => ((BezierSegment)s).Point1 = p)); + list.Add(new PathPoint(((BezierSegment)s).Point2, s, (p) => ((BezierSegment)s).Point2 = p)); + list.Add(new PathPoint(((BezierSegment)s).Point3, s, (p) => ((BezierSegment)s).Point3 = p)); } else if (s is QuadraticBezierSegment) { - list.Add(new PathPoint(((QuadraticBezierSegment)s).Point1, s, PointType.QuadricBezierSegment, (p) => ((QuadraticBezierSegment)s).Point1 = p)); - //list.Add(((QuadraticBezierSegment)s).Point1); - //list.Add(((QuadraticBezierSegment)s).Point2); + list.Add(new PathPoint(((QuadraticBezierSegment)s).Point1, s, (p) => ((QuadraticBezierSegment)s).Point1 = p)); + list.Add(new PathPoint(((QuadraticBezierSegment)s).Point2, s, (p) => ((QuadraticBezierSegment)s).Point2 = p)); } else if (s is ArcSegment) - list.Add(new PathPoint(((ArcSegment)s).Point, s, PointType.ArcSegment, (p) => ((ArcSegment)s).Point = p)); - //list.Add(((ArcSegment)s).Point); + list.Add(new PathPoint(((ArcSegment)s).Point, s, (p) => ((ArcSegment)s).Point = p)); } } } } else if (geometry is RectangleGeometry) { var g = geometry as RectangleGeometry; - list.Add(new PathPoint(g.Rect.TopLeft, geometry, PointType.RectangleGeometryP1, null)); //(p) => g.Rect.Left = p.X)); - list.Add(new PathPoint(g.Rect.TopRight, geometry, PointType.RectangleGeometryP2, null)); //(p) => g.Rect.Width = p.X)); - list.Add(new PathPoint(g.Rect.BottomLeft, geometry, PointType.RectangleGeometryP3, null)); //(p) => g.Rect.Top = p.Y)); - list.Add(new PathPoint(g.Rect.BottomRight, geometry, PointType.RectangleGeometryP4, null)); //(p) => g.Rect.Height = p.Y)); -// list.Add(new Point(g.Rect.Left, g.Rect.Top)); -// list.Add(new Point(g.Rect.Left, g.Rect.Top + g.Rect.Height)); -// list.Add(new Point(g.Rect.Left + g.Rect.Width, g.Rect.Top)); -// list.Add(new Point(g.Rect.Left + g.Rect.Width, g.Rect.Top + g.Rect.Height)); + list.Add(new PathPoint(g.Rect.TopLeft, geometry, null)); //(p) => g.Rect.Left = p.X)); + list.Add(new PathPoint(g.Rect.TopRight, geometry, null)); //(p) => g.Rect.Width = p.X)); + list.Add(new PathPoint(g.Rect.BottomLeft, geometry, null)); //(p) => g.Rect.Top = p.Y)); + list.Add(new PathPoint(g.Rect.BottomRight, geometry, null)); //(p) => g.Rect.Height = p.Y)); } else if (geometry is EllipseGeometry) { var g = geometry as EllipseGeometry; - list.Add(new PathPoint(g.Center, geometry, PointType.EllipseGeometryCenter, (p) => g.Center = p)); - //list.Add(g.Center); + list.Add(new PathPoint(g.Center, geometry, (p) => g.Center = p)); } else if (geometry is LineGeometry) { var g = geometry as LineGeometry; - list.Add(new PathPoint(g.StartPoint, geometry, PointType.LineGeometryStart, (p) => g.StartPoint = p)); - list.Add(new PathPoint(g.EndPoint, geometry, PointType.LineGeometryEnd, (p) => g.EndPoint = p)); - //list.Add(g.StartPoint); - //list.Add(g.EndPoint); + list.Add(new PathPoint(g.StartPoint, geometry, (p) => g.StartPoint = p)); + list.Add(new PathPoint(g.EndPoint, geometry, (p) => g.EndPoint = p)); } } - public enum PointType{ - StartPoint, - LineSegment, - BezierSegment, - ArcSegment, - QuadricBezierSegment, - - LineGeometryStart, - LineGeometryEnd, - EllipseGeometryCenter, - RectangleGeometryP1, - RectangleGeometryP2, - RectangleGeometryP3, - RectangleGeometryP4, - } - public class PathPoint { - public PathPoint(Point point, Object @object, PointType pointType, Action setLambda) + public PathPoint(Point point, Object @object, Action setLambda) { this._point = point; this._setLambda = setLambda; @@ -439,16 +416,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions set{_setLambda(value);} } public Point ReferencePoint {get; private set;} - public PointType Start {get; private set;} - public PointType End {get; private set;} public object Object {get; private set;} } - //Should not return a List of Points, no a List of Point Object wich say what a Point is. - //For Example: a Center Point of a Circle, should now it's a Center point! - //When he is selected, he should show another drag point to change the radius! - //a Combined Gemoetry should show a Adorner to change the combination mode! - List MovePoints(List pc, double displacementX, double displacementY, double theta, int? snapangle) { //iterate all selected points From ea0b2abdd6f28f963af432db4d64d70a8aba50bd Mon Sep 17 00:00:00 2001 From: jogibear9988 Date: Thu, 8 Jan 2015 15:02:14 +0100 Subject: [PATCH 28/52] A few Refactorings of classes Path Extension -> Now the Segment Types can be switched --- .../Project/Controls/ControlStyles.xaml | 17 +- .../Project/Controls/QuickOperationMenu.cs | 2 - .../DesignerThumb.cs} | 66 ++---- .../Thumbs/MultiPointThumb.cs} | 13 +- .../Project/Controls/Thumbs/PointThumb.cs | 52 +++++ .../Project/Controls/Thumbs/ResizeThumb.cs | 52 +++++ .../Controls/{ => Thumbs}/RotateThumb.cs | 12 +- .../WpfDesign.Designer/Project/Converters.cs | 20 ++ .../Project/Extensions/LineExtensionBase.cs | 6 +- .../Extensions/LineHandlerExtension.cs | 26 +-- .../Extensions/PathHandlerExtension.cs | 221 +++++++++++++----- .../PointTrackerPlacementSupport.cs | 14 +- .../Extensions/PolyLineHandlerExtension.cs | 42 ++-- .../Extensions/ResizeThumbExtension.cs | 34 +-- .../Extensions/RotateThumbExtension.cs | 4 +- .../Project/WpfDesign.Designer.csproj | 8 +- 16 files changed, 397 insertions(+), 192 deletions(-) rename src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/{ResizeThumb.cs => Thumbs/DesignerThumb.cs} (58%) rename src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/{Extensions/MultiPointResizeThumb.cs => Controls/Thumbs/MultiPointThumb.cs} (88%) create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/PointThumb.cs create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/ResizeThumb.cs rename src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/{ => Thumbs}/RotateThumb.cs (80%) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml index c1c8fb22c1..aef237e144 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml @@ -46,11 +46,20 @@ - + + diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/DragListener.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/DragListener.cs index 20fab52fa2..671c332785 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/DragListener.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/DragListener.cs @@ -23,6 +23,7 @@ using System.Text; using System.Windows; using System.Windows.Input; using System.Diagnostics; +using System.Windows.Media; namespace ICSharpCode.WpfDesign.Designer.Controls { @@ -35,6 +36,8 @@ namespace ICSharpCode.WpfDesign.Designer.Controls InputManager.Current.PostProcessInput += new ProcessInputEventHandler(PostProcessInput); } + public Transform Transform { get; set; } + public DragListener(IInputElement target) { Target = target; @@ -141,7 +144,14 @@ namespace ICSharpCode.WpfDesign.Designer.Controls public bool IsCanceled { get; private set; } public Vector Delta { - get { return CurrentPoint - StartPoint; } + get { + if (Transform != null) { + var matrix = Transform.Value; + matrix.Invert(); + return matrix.Transform(CurrentPoint - StartPoint); + } + return CurrentPoint - StartPoint; + } } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PanelMoveAdorner.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PanelMoveAdorner.cs index 5b053c6366..37a186e5fa 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PanelMoveAdorner.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PanelMoveAdorner.cs @@ -28,7 +28,7 @@ using System.Windows.Media; using ICSharpCode.WpfDesign.Designer.Converters; using System.Globalization; using System.Windows.Data; -using ICSharpCode.WpfDesign.Designer.UIExtensions; +using ICSharpCode.WpfDesign.UIExtensions; namespace ICSharpCode.WpfDesign.Designer.Controls { diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs index efc51e8b25..9e942dab80 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs @@ -23,7 +23,7 @@ using System.Windows.Controls; using System.Windows.Media; using ICSharpCode.WpfDesign.Designer.Converters; using System.Windows.Data; -using ICSharpCode.WpfDesign.Designer.UIExtensions; +using ICSharpCode.WpfDesign.UIExtensions; namespace ICSharpCode.WpfDesign.Designer.Controls diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/DesignerThumb.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/DesignerThumb.cs index ee02e39e59..d47c3d832e 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/DesignerThumb.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/DesignerThumb.cs @@ -16,7 +16,7 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -using ICSharpCode.WpfDesign.Designer.UIExtensions; +using ICSharpCode.WpfDesign.UIExtensions; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs index 9ddfc7eefb..907287e1be 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs @@ -32,7 +32,7 @@ using System.Windows.Threading; using ICSharpCode.WpfDesign.Adorners; using ICSharpCode.WpfDesign.Designer.Controls; -using ICSharpCode.WpfDesign.Designer.UIExtensions; +using ICSharpCode.WpfDesign.UIExtensions; using ICSharpCode.WpfDesign.Designer.Xaml; using ICSharpCode.WpfDesign.Extensions; using System.Linq; @@ -511,7 +511,7 @@ namespace ICSharpCode.WpfDesign.Designer PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); } - + #region ContextMenu private Dictionary>> contextMenusAndEntries = new Dictionary>>(); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs index f4b9df59ec..095a46735b 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs @@ -24,7 +24,7 @@ using System.Windows.Input; using System.Windows.Media; using System.Windows.Shapes; using System.Windows.Controls; -using ICSharpCode.WpfDesign.Designer.UIExtensions; +using ICSharpCode.WpfDesign.UIExtensions; namespace ICSharpCode.WpfDesign.Designer.Extensions { /// diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs index 5d9115f232..247579e8a4 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs @@ -28,7 +28,7 @@ using System.Windows.Controls; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using ICSharpCode.WpfDesign.Designer.UIExtensions; +using ICSharpCode.WpfDesign.UIExtensions; using DragListener = ICSharpCode.WpfDesign.Designer.Controls.DragListener; using System.Windows.Data; using System.ComponentModel; @@ -142,39 +142,39 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions MenuItem menuItem = null; if (pathpoint.TargetPathPoint == null && (pathpoint.Object is LineSegment || pathpoint.Object is PolyLineSegment || pathpoint.Object is BezierSegment || pathpoint.Object is QuadraticBezierSegment || pathpoint.Object is ArcSegment)) { - menuItem = new MenuItem() { Header = "insert Point" }; + menuItem = new MenuItem() { Header = "insert Point", HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuItem.Click += (s, e) => ConvertPart(((DependencyObject)s).TryFindParent(), PathPartConvertType.insertPoint); menuList.Add(menuItem); - menuItem = new MenuItem() { Header = "to Line Segment" }; + menuItem = new MenuItem() { Header = "to Line Segment", HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuItem.Click += (s, e) => ConvertPart(((DependencyObject)s).TryFindParent(), PathPartConvertType.ToLineSegment); menuList.Add(menuItem); - menuItem = new MenuItem() {Header = "to Bezier Segment"}; + menuItem = new MenuItem() {Header = "to Bezier Segment", HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuItem.Click += (s, e) => ConvertPart(((DependencyObject)s).TryFindParent(), PathPartConvertType.ToBezierSegment); menuList.Add(menuItem); - menuItem = new MenuItem() {Header = "to Quadric Bezier Segment"}; + menuItem = new MenuItem() {Header = "to Quadric Bezier Segment", HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuItem.Click += (s, e) => ConvertPart(((DependencyObject)s).TryFindParent(), PathPartConvertType.ToQuadricBezierSegment); menuList.Add(menuItem); - menuItem = new MenuItem() { Header = "to Arc Segment" }; + menuItem = new MenuItem() { Header = "to Arc Segment", HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuItem.Click += (s, e) => ConvertPart(((DependencyObject)s).TryFindParent(), PathPartConvertType.ToArcSegment); menuList.Add(menuItem); menuList.Add(new Separator()); - menuItem = new MenuItem() { Header = "is Stroked", IsChecked = ((PathSegment)pathpoint.Object).IsStroked }; + menuItem = new MenuItem() { Header = "is Stroked", IsChecked = ((PathSegment)pathpoint.Object).IsStroked, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuItem.Click += (s, e) => ChangeIsStroked(((DependencyObject)s).TryFindParent(), (MenuItem)s); menuList.Add(menuItem); - menuItem = new MenuItem() { Header = "is Smooth Join", IsChecked = ((PathSegment)pathpoint.Object).IsSmoothJoin }; + menuItem = new MenuItem() { Header = "is Smooth Join", IsChecked = ((PathSegment)pathpoint.Object).IsSmoothJoin, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuList.Add(menuItem); } if (pathpoint.Object is ArcSegment) { - menuItem = new MenuItem() { Header = "is large Arc", IsChecked = ((ArcSegment)pathpoint.Object).IsLargeArc }; + menuItem = new MenuItem() { Header = "is large Arc", IsChecked = ((ArcSegment)pathpoint.Object).IsLargeArc, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuList.Add(menuItem); - menuItem = new MenuItem() { Header = "Rotation Angle", IsChecked = true }; + menuItem = new MenuItem() { Header = "Rotation Angle", IsChecked = true, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuList.Add(menuItem); - menuItem = new MenuItem() { Header = "Clockwise SweepDirection", IsChecked = ((ArcSegment)pathpoint.Object).SweepDirection == SweepDirection.Clockwise }; + menuItem = new MenuItem() { Header = "Clockwise SweepDirection", IsChecked = ((ArcSegment)pathpoint.Object).SweepDirection == SweepDirection.Clockwise, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuList.Add(menuItem); } if (pathpoint.Object is PathFigure) { - menuItem = new MenuItem() { Header = "is Closed", IsChecked = ((PathFigure)pathpoint.Object).IsClosed }; + menuItem = new MenuItem() { Header = "is Closed", IsChecked = ((PathFigure)pathpoint.Object).IsClosed, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuItem.Click += (s, e) => ChangeIsClosed(((DependencyObject)s).TryFindParent(), (MenuItem)s); menuList.Add(menuItem); } @@ -249,7 +249,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions pathFigure.Segments.RemoveAt(idx); var midp = senderThumb.PathPoint.ParentPathPoint.Point - ((senderThumb.PathPoint.ParentPathPoint.Point - point) / 2); - + PathSegment newSegment = null; switch (convertType) { @@ -382,9 +382,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions // result.Height = ys.Max() - ys.Min(); // // info.Bounds = result.Round(); -// -// -// +// +// +// // operation.CurrentContainerBehavior.BeforeSetPosition(operation); // operation.CurrentContainerBehavior.SetPosition(info); // } @@ -420,13 +420,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions protected void drag_Changed(DragListener drag) { var mprt = drag.Target as PathThumb; - if (mprt != null) - { + if (mprt != null) { double dx = 0; double dy = 0; //if has zoomed - if (_zoom != null) - { + if (_zoom != null) { dx = drag.Delta.X * (1 / _zoom.CurrentZoom); dy = drag.Delta.Y * (1 / _zoom.CurrentZoom); } @@ -440,14 +438,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions protected void drag_Completed(DragListener drag) { var mprt = drag.Target as PathThumb; - if (mprt != null) - { - if (operation != null && drag.IsCanceled) - { + if (mprt != null) { + if (operation != null && drag.IsCanceled) { operation.Abort(); - } - else if (drag.IsCanceled) - { + } else if (drag.IsCanceled) { changeGroup.Abort(); } CommitOperation(); @@ -463,8 +457,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions pathPoints = GetPoints(); resizeThumbs = new List(); - for (int i = 0; i < pathPoints.Count; i++) - { + for (int i = 0; i < pathPoints.Count; i++) { CreateThumb(PlacementAlignment.BottomRight, Cursors.Cross, i, pathPoints[i]); } @@ -500,12 +493,15 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions var g = geometry as CombinedGeometry; AddGeometryPoints(list, g.Geometry1); AddGeometryPoints(list, g.Geometry2); - } else if (geometry is GeometryGroup) - { + } else if (geometry is GeometryGroup) { var gg = geometry as GeometryGroup; foreach (var g in gg.Children) { AddGeometryPoints(list, g); } + } else if (geometry is StreamGeometry) { + var sg = geometry as StreamGeometry; + var pg = sg.GetFlattenedPathGeometry().Clone(); + AddGeometryPoints(list, pg); } else if (geometry is PathGeometry) { var g = geometry as PathGeometry; if (geometry!=null) { @@ -515,8 +511,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions var parentp = list.Last(); if (s is LineSegment) list.Add(new PathPoint(((LineSegment)s).Point, s, figure, (p) => ((LineSegment)s).Point = p){ParentPathPoint = parentp}); - else if (s is PolyLineSegment) - { + else if (s is PolyLineSegment) { var poly = s as PolyLineSegment; for (int n = 0; n < poly.Points.Count; n++) { @@ -524,23 +519,17 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions list.Add(new PathPoint(poly.Points[closure_n], s, figure, (p) => poly.Points[closure_n] = p) { PolyLineIndex = closure_n, ParentPathPoint = parentp }); parentp = list.Last(); } - } - else if (s is BezierSegment) - { + } else if (s is BezierSegment) { var pathp = new PathPoint(((BezierSegment)s).Point3, s, figure, (p) => ((BezierSegment)s).Point3 = p){ParentPathPoint = parentp}; var previous = list.Last(); list.Add(new PathPoint(((BezierSegment)s).Point1, s, figure, (p) => ((BezierSegment)s).Point1 = p) { TargetPathPoint = previous }); list.Add(new PathPoint(((BezierSegment)s).Point2, s, figure, (p) => ((BezierSegment)s).Point2 = p) { TargetPathPoint = pathp }); list.Add(pathp); - } - else if (s is QuadraticBezierSegment) - { + } else if (s is QuadraticBezierSegment) { var pathp = new PathPoint(((QuadraticBezierSegment)s).Point2, s, figure, (p) => ((QuadraticBezierSegment)s).Point2 = p){ParentPathPoint = parentp}; list.Add(new PathPoint(((QuadraticBezierSegment)s).Point1, s, figure, (p) => ((QuadraticBezierSegment)s).Point1 = p) { TargetPathPoint = pathp }); list.Add(pathp); - } - else if (s is ArcSegment) - { + } else if (s is ArcSegment) { var arc = ((ArcSegment)s); var pathp = new PathPoint(arc.Point, s, figure, (p) => arc.Point = p){ParentPathPoint = parentp}; list.Add(new PathPoint(arc.Point - new Vector(arc.Size.Width, arc.Size.Height), s, figure, (p) => arc.Size = new Size(Math.Abs(arc.Point.X - p.X), Math.Abs(arc.Point.Y - p.Y))) { TargetPathPoint = pathp }); @@ -568,8 +557,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions List MovePoints(List pc, double displacementX, double displacementY) { //iterate all selected points - foreach (int i in _selectedThumbs.Keys) - { + foreach (int i in _selectedThumbs.Keys) { Point p = pc[i].Point; //x and y is calculated from the currentl point @@ -594,14 +582,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions public void KeyDownAction(object sender, KeyEventArgs e) { Debug.WriteLine("KeyDown"); - if (IsArrowKey(e.Key)) - if (operation == null) - { + if (IsArrowKey(e.Key)) { + if (operation == null) { SetOperation(); _movingDistance = 0; + } } - var dx1 = (e.Key == Key.Left) ? Keyboard.IsKeyDown(Key.LeftShift) ? _movingDistance - 10 : _movingDistance - 1 : 0; var dy1 = (e.Key == Key.Up) ? Keyboard.IsKeyDown(Key.LeftShift) ? _movingDistance - 10 : _movingDistance - 1 : 0; var dx2 = (e.Key == Key.Right) ? Keyboard.IsKeyDown(Key.LeftShift) ? _movingDistance + 10 : _movingDistance + 1 : 0; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs index 21247d31d0..e4e4323273 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs @@ -31,7 +31,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using ICSharpCode.WpfDesign.Designer.UIExtensions; +using ICSharpCode.WpfDesign.UIExtensions; namespace ICSharpCode.WpfDesign.Designer.Extensions { diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ResizeThumbExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ResizeThumbExtension.cs index 4daefcdb13..ab15835f1a 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ResizeThumbExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ResizeThumbExtension.cs @@ -26,7 +26,7 @@ using ICSharpCode.WpfDesign.Adorners; using ICSharpCode.WpfDesign.Designer.Controls; using ICSharpCode.WpfDesign.Extensions; using System.Collections.Generic; -using ICSharpCode.WpfDesign.Designer.UIExtensions; +using ICSharpCode.WpfDesign.UIExtensions; namespace ICSharpCode.WpfDesign.Designer.Extensions { @@ -119,14 +119,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions } Size oldSize; - ZoomControl zoom; // TODO : Remove all hide/show extensions from here. void drag_Started(DragListener drag) { - var designPanel = ExtendedItem.Services.DesignPanel as DesignPanel; - zoom = designPanel.TryFindParent(); - /* Abort editing Text if it was editing, because it interferes with the undo stack. */ foreach(var extension in this.ExtendedItem.Extensions){ if(extension is InPlaceEditorExtension){ @@ -134,6 +130,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions } } + drag.Transform = this.ExtendedItem.GetCompleteAppliedTransformationToView(); + oldSize = new Size(ModelTools.GetWidth(ExtendedItem.View), ModelTools.GetHeight(ExtendedItem.View)); if (resizeBehavior != null) operation = PlacementOperation.Start(extendedItemArray, PlacementType.Resize); @@ -152,10 +150,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions var delta = drag.Delta; - var transform = this.ExtendedItem.View.RenderTransform; - if (transform != null) - delta = (Vector)transform.Inverse.Transform((Point)delta); - if (alignment.Horizontal == HorizontalAlignment.Left) dx = -delta.X; if (alignment.Horizontal == HorizontalAlignment.Right) dx = delta.X; if (alignment.Vertical == VerticalAlignment.Top) dy = -delta.Y; @@ -170,12 +164,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions else dy = dx; } - - if (zoom != null) - { - dx = dx * (1 / zoom.CurrentZoom); - dy = dy * (1 / zoom.CurrentZoom); - } var newWidth = Math.Max(0, oldSize.Width + dx); var newHeight = Math.Max(0, oldSize.Height + dy); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SkewThumbExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SkewThumbExtension.cs index 47c48c1434..65e9da02ce 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SkewThumbExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SkewThumbExtension.cs @@ -27,7 +27,7 @@ using ICSharpCode.WpfDesign.Adorners; using ICSharpCode.WpfDesign.Designer.Controls; using ICSharpCode.WpfDesign.Extensions; using System.Collections.Generic; -using ICSharpCode.WpfDesign.Designer.UIExtensions; +using ICSharpCode.WpfDesign.UIExtensions; namespace ICSharpCode.WpfDesign.Designer.Extensions { diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml.cs index 1b8a1f5d48..ac3ff33c9a 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml.cs @@ -20,7 +20,7 @@ using System; using System.Linq; using System.Windows; using ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor; -using ICSharpCode.WpfDesign.Designer.UIExtensions; +using ICSharpCode.WpfDesign.UIExtensions; using ICSharpCode.WpfDesign.Designer.themes; namespace ICSharpCode.WpfDesign.Designer.Extensions diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs index c5a0aba8e7..88bfe0a00b 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs @@ -26,6 +26,7 @@ using System.Windows.Documents; using System.Windows.Markup; using System.Windows.Media; using System.Windows.Media.Imaging; +using System.Windows.Shapes; using System.Windows.Xps.Serialization; using ICSharpCode.WpfDesign.Designer.Xaml; @@ -589,5 +590,24 @@ namespace ICSharpCode.WpfDesign.Designer operation.Commit(); } + +// public static class Path { +// +// public static PathGeometry ConvertToPathGeometry(this TextBlock textBlock) +// { +// //var ft = new FormatedText(); +// return null; +// } +// +// public static PathGeometry ConvertToPathGeometry(this Rectangle rectangle) +// { +// return null; +// } +// +// public static PathGeometry ConvertToPathGeometry(this Ellipse ellipse) +// { +// return null; +// } +// } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineTreeView.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineTreeView.cs index b15cb23b81..bd86610444 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineTreeView.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineTreeView.cs @@ -20,7 +20,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; -using ICSharpCode.WpfDesign.Designer.UIExtensions; +using ICSharpCode.WpfDesign.UIExtensions; namespace ICSharpCode.WpfDesign.Designer.OutlineView { diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml.cs index e198361c5c..4a8ddbeb0c 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml.cs @@ -24,7 +24,7 @@ using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Media; using ICSharpCode.WpfDesign.Designer.Xaml; -using ICSharpCode.WpfDesign.Designer.UIExtensions; +using ICSharpCode.WpfDesign.UIExtensions; using ICSharpCode.WpfDesign.Designer.themes; namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ThumbnailView/ThumbnailView.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ThumbnailView/ThumbnailView.cs index 606ae58684..876d843ce7 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ThumbnailView/ThumbnailView.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ThumbnailView/ThumbnailView.cs @@ -27,7 +27,7 @@ using System.Windows.Controls.Primitives; using System.Windows.Media; using System.Diagnostics; using ICSharpCode.WpfDesign.Designer.Controls; -using ICSharpCode.WpfDesign.Designer.UIExtensions; +using ICSharpCode.WpfDesign.UIExtensions; namespace ICSharpCode.WpfDesign.Designer.ThumbnailView { diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj index 6d5e1575b7..f052b82398 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj @@ -300,7 +300,6 @@ - diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs index 225c4a7416..b27440de69 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs @@ -22,6 +22,8 @@ using System.ComponentModel; using System.Diagnostics; using System.Windows; +using System.Windows.Media; +using ICSharpCode.WpfDesign.UIExtensions; using ICSharpCode.WpfDesign.Extensions; using System.Linq; @@ -291,5 +293,21 @@ namespace ICSharpCode.WpfDesign /// Creates a copy of this design item. /// public abstract DesignItem Clone(); + + public Transform GetCompleteAppliedTransformationToView() + { + var retVal = new TransformGroup(); + var fe = this.View as FrameworkElement; + while (fe != null) { + if (fe.LayoutTransform != null) + retVal.Children.Add(fe.LayoutTransform); + if (fe.RenderTransform != null) + retVal.Children.Add(fe.RenderTransform); + fe = fe.TryFindParent(true); + } + + return retVal; + + } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/UIExtensions/UIHelpers.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/UIExtensions/UIHelpers.cs similarity index 77% rename from src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/UIExtensions/UIHelpers.cs rename to src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/UIExtensions/UIHelpers.cs index 23f8b8f152..eaffed93ae 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/UIExtensions/UIHelpers.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/UIExtensions/UIHelpers.cs @@ -23,37 +23,39 @@ using System.Text; using System.Windows; using System.Windows.Media; -namespace ICSharpCode.WpfDesign.Designer.UIExtensions +namespace ICSharpCode.WpfDesign.UIExtensions { public static class UIHelpers { - public static DependencyObject GetParentObject(this DependencyObject child) + public static DependencyObject GetParentObject(this DependencyObject child, bool searchCompleteVisualTree) { if (child == null) return null; - var contentElement = child as ContentElement; - if (contentElement != null) - { - DependencyObject parent = ContentOperations.GetParent(contentElement); - if (parent != null) return parent; - - var fce = contentElement as FrameworkContentElement; - return fce != null ? fce.Parent : null; - } - - var frameworkElement = child as FrameworkElement; - if (frameworkElement != null) - { - DependencyObject parent = frameworkElement.Parent; - if (parent != null) return parent; + if (!searchCompleteVisualTree) { + var contentElement = child as ContentElement; + if (contentElement != null) + { + DependencyObject parent = ContentOperations.GetParent(contentElement); + if (parent != null) return parent; + + var fce = contentElement as FrameworkContentElement; + return fce != null ? fce.Parent : null; + } + + var frameworkElement = child as FrameworkElement; + if (frameworkElement != null) + { + DependencyObject parent = frameworkElement.Parent; + if (parent != null) return parent; + } } return VisualTreeHelper.GetParent(child); } - public static T TryFindParent(this DependencyObject child) where T : DependencyObject + public static T TryFindParent(this DependencyObject child, bool searchCompleteVisualTree = false) where T : DependencyObject { - DependencyObject parentObject = GetParentObject(child); + DependencyObject parentObject = GetParentObject(child, searchCompleteVisualTree); if (parentObject == null) return null; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj index 56127c6a68..980bbeff25 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj @@ -116,8 +116,12 @@ + + + + \ No newline at end of file From 508247a1c89b0430f04feae507130ff733201f31 Mon Sep 17 00:00:00 2001 From: jogibear9988 Date: Sun, 11 Jan 2015 21:41:01 +0100 Subject: [PATCH 35/52] Fix a compile error --- .../WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamescopeTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamescopeTest.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamescopeTest.cs index 09d1357a93..26d5360960 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamescopeTest.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamescopeTest.cs @@ -11,7 +11,7 @@ using System.Xml; using ICSharpCode.WpfDesign.XamlDom; using NUnit.Framework; using ICSharpCode.WpfDesign.Designer; -using ICSharpCode.WpfDesign.Designer.UIExtensions; +using ICSharpCode.WpfDesign.UIExtensions; namespace ICSharpCode.WpfDesign.Tests.XamlDom { From ca2ae67ca80c0892674e6bb86f95f0187a836a7a Mon Sep 17 00:00:00 2001 From: jogibear9988 Date: Sun, 11 Jan 2015 22:26:33 +0100 Subject: [PATCH 36/52] Fixes in Stretched Path Point Movement also works --- .../Extensions/PathHandlerExtension.cs | 92 +++++++++++-------- 1 file changed, 55 insertions(+), 37 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs index 247579e8a4..3ae5342e3c 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs @@ -54,16 +54,18 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions //A modifieable Point on the Path protected class PathPoint : INotifyPropertyChanged { - public PathPoint(Point point, Object @object, Object parentObject, Action setLambda) + public PathPoint(Point point, Object @object, Object parentObject, Action setLambda, Shape shape) { this._point = point; this._setLambda = setLambda; this.Object = @object; this.ParentObject = parentObject; + this._shape = shape; } private Point _point; Action _setLambda; + Shape _shape; public Point Point { @@ -74,11 +76,24 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions _point = value; _setLambda(value); if (PropertyChanged != null) + { PropertyChanged(this, new PropertyChangedEventArgs("Point")); + PropertyChanged(this, new PropertyChangedEventArgs("TranslatedPoint")); + } } } } + public Point TranslatedPoint + { + get { + return _shape.RenderedGeometry.Transform.Transform(Point); + } + set { + Point = _shape.RenderedGeometry.Transform.Inverse.Transform(value); + } + } + public PathPoint ParentPathPoint {get; set;} public Point ReferencePoint { get; private set; } @@ -97,11 +112,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions //A Thumb wich displays the Point protected class PathThumb : PointThumb { - public PathThumb(Point point, int index, PathPoint pathpoint) : base(point) + public PathThumb(int index, PathPoint pathpoint) : base() { this.Index = index; this.PathPoint = pathpoint; - var bnd = new Binding("Point") { Source = this.PathPoint, Mode=BindingMode.OneWay }; + var bnd = new Binding("TranslatedPoint") { Source = this.PathPoint, Mode=BindingMode.OneWay }; this.SetBinding(PointProperty, bnd); } @@ -114,9 +129,12 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions protected class RelativeToPointConverter : IValueConverter { PathPoint pathPoint; - public RelativeToPointConverter(PathPoint pathPoint) + Shape shape; + + public RelativeToPointConverter(PathPoint pathPoint/*, Shape shape*/) { this.pathPoint = pathPoint; + //this.shape = shape; } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { @@ -186,13 +204,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions } #region thumb methods - protected virtual PathThumb CreateThumb(PlacementAlignment alignment, Cursor cursor, int index, PathPoint pathpoint) + protected virtual PathThumb CreateThumb(PlacementAlignment alignment, Cursor cursor, int index, PathPoint pathpoint, Transform transform) { - var point = pathpoint.Point; - var transform = ((Shape)this.ExtendedItem.View).RenderedGeometry.Transform; - point = transform.Transform(point); - - var designerThumb = new PathThumb(point, index, pathpoint) {Cursor = cursor}; + var designerThumb = new PathThumb(index, pathpoint) {Cursor = cursor}; designerThumb.OperationMenu = BuildMenu(pathpoint); if (pathpoint.TargetPathPoint != null) { @@ -207,6 +221,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions adornerPanel.Children.Add(designerThumb); DragListener drag = new DragListener(designerThumb); + drag.Transform = transform; WeakEventManager.AddHandler(designerThumb, "PreviewMouseLeftButtonDown", ResizeThumbOnMouseLeftButtonUp); @@ -304,7 +319,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions private void SelectThumb(PathThumb mprt) { var points = GetPoints(); - Point p = points[mprt.Index].Point; + Point p = points[mprt.Index].TranslatedPoint; _selectedThumbs.Add(mprt.Index, new Bounds { X = p.X, Y = p.Y }); mprt.IsPrimarySelection = false; @@ -457,8 +472,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions pathPoints = GetPoints(); resizeThumbs = new List(); + + var transform = this.ExtendedItem.GetCompleteAppliedTransformationToView(); + for (int i = 0; i < pathPoints.Count; i++) { - CreateThumb(PlacementAlignment.BottomRight, Cursors.Cross, i, pathPoints[i]); + CreateThumb(PlacementAlignment.BottomRight, Cursors.Cross, i, pathPoints[i], transform); } Invalidate(); @@ -482,57 +500,57 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions static List GetPoints(Path path) { var retVal = new List(); - AddGeometryPoints(retVal, path.Data); + AddGeometryPoints(retVal, path.Data, path); return retVal; } - private static void AddGeometryPoints(List list, Geometry geometry) + private static void AddGeometryPoints(List list, Geometry geometry, Shape shape) { if (geometry is CombinedGeometry) { var g = geometry as CombinedGeometry; - AddGeometryPoints(list, g.Geometry1); - AddGeometryPoints(list, g.Geometry2); + AddGeometryPoints(list, g.Geometry1, shape); + AddGeometryPoints(list, g.Geometry2, shape); } else if (geometry is GeometryGroup) { var gg = geometry as GeometryGroup; foreach (var g in gg.Children) { - AddGeometryPoints(list, g); + AddGeometryPoints(list, g, shape); } } else if (geometry is StreamGeometry) { var sg = geometry as StreamGeometry; var pg = sg.GetFlattenedPathGeometry().Clone(); - AddGeometryPoints(list, pg); + AddGeometryPoints(list, pg, shape); } else if (geometry is PathGeometry) { var g = geometry as PathGeometry; if (geometry!=null) { foreach(var figure in g.Figures) { - list.Add(new PathPoint(figure.StartPoint, figure, null, (p) => figure.StartPoint = p)); + list.Add(new PathPoint(figure.StartPoint, figure, null, (p) => figure.StartPoint = p, shape)); foreach (var s in figure.Segments) { var parentp = list.Last(); if (s is LineSegment) - list.Add(new PathPoint(((LineSegment)s).Point, s, figure, (p) => ((LineSegment)s).Point = p){ParentPathPoint = parentp}); + list.Add(new PathPoint(((LineSegment)s).Point, s, figure, (p) => ((LineSegment)s).Point = p, shape){ParentPathPoint = parentp}); else if (s is PolyLineSegment) { var poly = s as PolyLineSegment; for (int n = 0; n < poly.Points.Count; n++) { var closure_n = n; - list.Add(new PathPoint(poly.Points[closure_n], s, figure, (p) => poly.Points[closure_n] = p) { PolyLineIndex = closure_n, ParentPathPoint = parentp }); + list.Add(new PathPoint(poly.Points[closure_n], s, figure, (p) => poly.Points[closure_n] = p, shape) { PolyLineIndex = closure_n, ParentPathPoint = parentp }); parentp = list.Last(); } } else if (s is BezierSegment) { - var pathp = new PathPoint(((BezierSegment)s).Point3, s, figure, (p) => ((BezierSegment)s).Point3 = p){ParentPathPoint = parentp}; + var pathp = new PathPoint(((BezierSegment)s).Point3, s, figure, (p) => ((BezierSegment)s).Point3 = p, shape){ParentPathPoint = parentp}; var previous = list.Last(); - list.Add(new PathPoint(((BezierSegment)s).Point1, s, figure, (p) => ((BezierSegment)s).Point1 = p) { TargetPathPoint = previous }); - list.Add(new PathPoint(((BezierSegment)s).Point2, s, figure, (p) => ((BezierSegment)s).Point2 = p) { TargetPathPoint = pathp }); + list.Add(new PathPoint(((BezierSegment)s).Point1, s, figure, (p) => ((BezierSegment)s).Point1 = p, shape) { TargetPathPoint = previous }); + list.Add(new PathPoint(((BezierSegment)s).Point2, s, figure, (p) => ((BezierSegment)s).Point2 = p, shape) { TargetPathPoint = pathp }); list.Add(pathp); } else if (s is QuadraticBezierSegment) { - var pathp = new PathPoint(((QuadraticBezierSegment)s).Point2, s, figure, (p) => ((QuadraticBezierSegment)s).Point2 = p){ParentPathPoint = parentp}; - list.Add(new PathPoint(((QuadraticBezierSegment)s).Point1, s, figure, (p) => ((QuadraticBezierSegment)s).Point1 = p) { TargetPathPoint = pathp }); + var pathp = new PathPoint(((QuadraticBezierSegment)s).Point2, s, figure, (p) => ((QuadraticBezierSegment)s).Point2 = p, shape){ParentPathPoint = parentp}; + list.Add(new PathPoint(((QuadraticBezierSegment)s).Point1, s, figure, (p) => ((QuadraticBezierSegment)s).Point1 = p, shape) { TargetPathPoint = pathp }); list.Add(pathp); } else if (s is ArcSegment) { var arc = ((ArcSegment)s); - var pathp = new PathPoint(arc.Point, s, figure, (p) => arc.Point = p){ParentPathPoint = parentp}; - list.Add(new PathPoint(arc.Point - new Vector(arc.Size.Width, arc.Size.Height), s, figure, (p) => arc.Size = new Size(Math.Abs(arc.Point.X - p.X), Math.Abs(arc.Point.Y - p.Y))) { TargetPathPoint = pathp }); + var pathp = new PathPoint(arc.Point, s, figure, (p) => arc.Point = p, shape){ParentPathPoint = parentp}; + list.Add(new PathPoint(arc.Point - new Vector(arc.Size.Width, arc.Size.Height), s, figure, (p) => arc.Size = new Size(Math.Abs(arc.Point.X - p.X), Math.Abs(arc.Point.Y - p.Y)), shape) { TargetPathPoint = pathp }); list.Add(pathp); } } @@ -540,17 +558,17 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions } } else if (geometry is RectangleGeometry) { var g = geometry as RectangleGeometry; - list.Add(new PathPoint(g.Rect.TopLeft, geometry, null, null)); //(p) => g.Rect.Left = p.X)); - list.Add(new PathPoint(g.Rect.TopRight, geometry, null, null)); //(p) => g.Rect.Width = p.X)); - list.Add(new PathPoint(g.Rect.BottomLeft, geometry, null, null)); //(p) => g.Rect.Top = p.Y)); - list.Add(new PathPoint(g.Rect.BottomRight, geometry, null, null)); //(p) => g.Rect.Height = p.Y)); + list.Add(new PathPoint(g.Rect.TopLeft, geometry, null, null, shape)); //(p) => g.Rect.Left = p.X)); + list.Add(new PathPoint(g.Rect.TopRight, geometry, null, null, shape)); //(p) => g.Rect.Width = p.X)); + list.Add(new PathPoint(g.Rect.BottomLeft, geometry, null, null, shape)); //(p) => g.Rect.Top = p.Y)); + list.Add(new PathPoint(g.Rect.BottomRight, geometry, null, null, shape)); //(p) => g.Rect.Height = p.Y)); } else if (geometry is EllipseGeometry) { var g = geometry as EllipseGeometry; - list.Add(new PathPoint(g.Center, geometry, null, (p) => g.Center = p)); + list.Add(new PathPoint(g.Center, geometry, null, (p) => g.Center = p, shape)); } else if (geometry is LineGeometry) { var g = geometry as LineGeometry; - list.Add(new PathPoint(g.StartPoint, geometry, null, (p) => g.StartPoint = p)); - list.Add(new PathPoint(g.EndPoint, geometry, null, (p) => g.EndPoint = p)); + list.Add(new PathPoint(g.StartPoint, geometry, null, (p) => g.StartPoint = p, shape)); + list.Add(new PathPoint(g.EndPoint, geometry, null, (p) => g.EndPoint = p, shape)); } } @@ -558,7 +576,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions { //iterate all selected points foreach (int i in _selectedThumbs.Keys) { - Point p = pc[i].Point; + Point p = pc[i].TranslatedPoint; //x and y is calculated from the currentl point double x = _selectedThumbs[i].X + displacementX; @@ -566,7 +584,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions p.X = x; p.Y = y; - pc[i].Point = p; + pc[i].TranslatedPoint = p; } return pc; } From e7889637026a2e6d5e8a78fc2a24bd5b1694cc2e Mon Sep 17 00:00:00 2001 From: jogibear9988 Date: Sun, 11 Jan 2015 22:33:49 +0100 Subject: [PATCH 37/52] Now also the Bezier Points work when stretched --- .../Project/Extensions/PathHandlerExtension.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs index 3ae5342e3c..30298831d8 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs @@ -139,7 +139,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var pt = (Point)value; - return pt - new Vector(pathPoint.Point.X - 3.5, pathPoint.Point.Y - 3.5); + return pt - new Vector(pathPoint.TranslatedPoint.X - 3.5, pathPoint.TranslatedPoint.Y - 3.5); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) @@ -213,7 +213,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions designerThumb.IsEllipse = true; designerThumb.Foreground = Brushes.Blue; - var bnd = new Binding("Point") { Source = pathpoint.TargetPathPoint, Mode = BindingMode.OneWay, Converter = new RelativeToPointConverter(pathpoint) }; + var bnd = new Binding("TranslatedPoint") { Source = pathpoint.TargetPathPoint, Mode = BindingMode.OneWay, Converter = new RelativeToPointConverter(pathpoint) }; designerThumb.SetBinding(PathThumb.RelativeToPointProperty, bnd); } From b43d047e7c97db024064818a0b0c44d90128ef1d Mon Sep 17 00:00:00 2001 From: jogibear9988 Date: Sun, 11 Jan 2015 22:55:37 +0100 Subject: [PATCH 38/52] Fix Path Handler when Zoomed --- .../Project/Extensions/PathHandlerExtension.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs index 30298831d8..b1c69345f4 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs @@ -436,16 +436,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions { var mprt = drag.Target as PathThumb; if (mprt != null) { - double dx = 0; - double dy = 0; - //if has zoomed - if (_zoom != null) { - dx = drag.Delta.X * (1 / _zoom.CurrentZoom); - dy = drag.Delta.Y * (1 / _zoom.CurrentZoom); - } - _isDragging = true; - MovePoints(pathPoints, dx, dy); + MovePoints(pathPoints, drag.Delta.X, drag.Delta.Y); } ChangeOperation(pathPoints); } From b63ea4bbe4fd9292eb0aef6a04123db91445dc83 Mon Sep 17 00:00:00 2001 From: jogibear9988 Date: Mon, 12 Jan 2015 00:03:57 +0100 Subject: [PATCH 39/52] Fix Calculate Compl. Transform when in Viewbox --- .../WpfDesign/WpfDesign/Project/DesignItem.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs index b27440de69..b48d766137 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs @@ -22,6 +22,7 @@ using System.ComponentModel; using System.Diagnostics; using System.Windows; +using System.Windows.Controls; using System.Windows.Media; using ICSharpCode.WpfDesign.UIExtensions; using ICSharpCode.WpfDesign.Extensions; @@ -303,6 +304,12 @@ namespace ICSharpCode.WpfDesign retVal.Children.Add(fe.LayoutTransform); if (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}); + } fe = fe.TryFindParent(true); } From 26dedf8ae0ae00544ebdfa93d203eb397ae68051 Mon Sep 17 00:00:00 2001 From: jogibear9988 Date: Mon, 12 Jan 2015 23:25:05 +0100 Subject: [PATCH 40/52] - Fix Context Menu's when Transforms are used - Snap Path Point Thumbs --- .../Project/Controls/ControlStyles.xaml | 36 ++--- .../Project/Controls/QuickOperationMenu.cs | 17 +-- .../Project/Controls/Thumbs/PointThumb.cs | 14 +- .../Extensions/DefaultPlacementBehavior.cs | 5 + .../Extensions/PathHandlerExtension.cs | 27 ++-- .../PointTrackerPlacementSupport.cs | 3 +- .../Extensions/QuickOperationMenuExtension.cs | 2 + .../Extensions/RasterPlacementBehavior.cs | 25 ++++ .../Extensions/SnaplinePlacementBehavior.cs | 131 ++++++++++++++---- .../Project/RootItemBehavior.cs | 5 + .../WpfDesign/WpfDesign/Project/DesignItem.cs | 19 ++- .../WpfDesign/Project/PlacementBehavior.cs | 5 + 12 files changed, 203 insertions(+), 86 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml index 000e7bba3b..d8657e78da 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml @@ -81,23 +81,25 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs index 9e942dab80..c3a11bff06 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs @@ -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 if (mainHeader != null) { _mainHeader = mainHeader; } - - var surface = this.TryFindParent(); - 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); - } } /// diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/PointThumb.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/PointThumb.cs index 2b9bfb07dd..a803df02c7 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/PointThumb.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/PointThumb.cs @@ -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 /// 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 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)); } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs index e0078914f3..31d54e2ebe 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs +++ b/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; + } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs index b1c69345f4..bf85c4fcd5 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs @@ -86,7 +86,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions public Point TranslatedPoint { - get { + get { return _shape.RenderedGeometry.Transform.Transform(Point); } set { @@ -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 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 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 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 List MovePoints(List 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 p.X = x; p.Y = y; + + + p = operation.CurrentContainerBehavior.PlacePoint(p + relativeTo) - relativeTo; + pc[i].TranslatedPoint = p; } return pc; @@ -594,8 +603,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions Debug.WriteLine("KeyDown"); if (IsArrowKey(e.Key)) { if (operation == null) { - SetOperation(); - _movingDistance = 0; + SetOperation(); + _movingDistance = 0; } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs index 9807f3f533..6065dc2479 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs +++ b/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) { 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 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)); } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/QuickOperationMenuExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/QuickOperationMenuExtension.cs index 2ca8308f66..8b291fa37c 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/QuickOperationMenuExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/QuickOperationMenuExtension.cs @@ -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 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); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RasterPlacementBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RasterPlacementBehavior.cs index c5aa6e56ce..cbbfebcb76 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RasterPlacementBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RasterPlacementBehavior.cs @@ -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 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) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs index 11c142a186..f7ff4d79cb 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs @@ -77,7 +77,58 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions base.LeaveContainer(operation); 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(); + var verticalInput = new List(); + + 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 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); @@ -94,21 +145,25 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions foreach (var item in operation.PlacedItems) { bounds.Union(item.Bounds); } - + var horizontalInput = new List(); var verticalInput = new List(); 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 }); } } - + // debug //foreach (var t in horizontalMap.Concat(horizontalInput)) { // surface.Children.Add(new Line() { X1 = t.Start, X2 = t.End, Y1 = t.Offset, Y2 = t.Offset, Stroke = Brushes.Black }); @@ -117,57 +172,75 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions // surface.Children.Add(new Line() { X1 = t.Offset, X2 = t.Offset, Y1 = t.Start , Y2 = t.End, Stroke = Brushes.Black }); //} //return; - + List drawLines; double 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 (Snap(horizontalInput, horizontalMap, Accuracy, out drawLines, out delta)) + { + + 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 (operation.Type == PlacementType.Resize) { - if (info.ResizeThumbAlignment != null && info.ResizeThumbAlignment.Value.Horizontal == HorizontalAlignment.Left) { + + if (Snap(verticalInput, verticalMap, Accuracy, out drawLines, out delta)) + { + + 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); } } } - + void CreateSurface(PlacementOperation operation) { if (ExtendedItem.Services.GetService() != null) { diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/RootItemBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/RootItemBehavior.cs index 4b436dba98..6e429e51f0 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/RootItemBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/RootItemBehavior.cs @@ -94,5 +94,10 @@ namespace ICSharpCode.WpfDesign.Designer { throw new NotImplementedException(); } + + public Point PlacePoint(Point point) + { + return point; + } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs index b48d766137..da353b37c9 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs @@ -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(true); + v = v.TryFindParent(true); } return retVal; - } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementBehavior.cs index f34341e7bb..f75446dc5b 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementBehavior.cs @@ -78,6 +78,11 @@ namespace ICSharpCode.WpfDesign /// Let the placed children enter this container. /// void EnterContainer(PlacementOperation operation); + + /// + /// Place Point. + /// + Point PlacePoint(Point point); } /// From 79e726fb05d17d741c1ee8ce8dd7ca6c8353bf6b Mon Sep 17 00:00:00 2001 From: jogibear9988 Date: Mon, 12 Jan 2015 23:50:19 +0100 Subject: [PATCH 41/52] Draw Path when Transformed --- .../Project/Extensions/DrawPathExtension.cs | 15 +++++++++------ .../Project/Extensions/LineHandlerExtension.cs | 5 +++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPathExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPathExtension.cs index 63659b14b0..828af5c3e3 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPathExtension.cs +++ b/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); 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 @@ -88,13 +88,16 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions private Point sP; private PathFigure figure; 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.positionRelativeTo = relativeTo; this.changeGroup = changeGroup; this.figure = figure; + this.matrix = transform.Value; + matrix.Invert(); sP = Mouse.GetPosition(null); @@ -109,8 +112,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions protected override void OnMouseMove(object sender, MouseEventArgs e) { - var delta = e.GetPosition(null) - sP; - var point = new Point(delta.X, delta.Y); + var delta = matrix.Transform(e.GetPosition(null) - sP); + var point = new Point(Math.Round(delta.X, 0), Math.Round(delta.Y, 0)); var segment = figure.Segments.LastOrDefault() as LineSegment; if (Mouse.LeftButton == MouseButtonState.Pressed) @@ -128,8 +131,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions protected override void OnMouseUp(object sender, MouseButtonEventArgs e) { - var delta = e.GetPosition(null) - sP; - var point = new Point(delta.X, delta.Y); + var delta = matrix.Transform(e.GetPosition(null) - sP); + var point = new Point(Math.Round(delta.X, 0), Math.Round(delta.Y,0)); figure.Segments.Add(new LineSegment(point, false)); geometry.Properties[PathGeometry.FiguresProperty].SetValue(figure.ToString()); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs index 095a46735b..374c838ccf 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs @@ -17,6 +17,7 @@ // DEALINGS IN THE SOFTWARE. using System; +using System.Windows; using ICSharpCode.WpfDesign.Extensions; using ICSharpCode.WpfDesign.Adorners; using ICSharpCode.WpfDesign.Designer.Controls; @@ -173,6 +174,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions info.Bounds = result.Round(); operation.CurrentContainerBehavior.BeforeSetPosition(operation); 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(); From 24f4bb8ed5183eb7250bd20206249321bb0a3859 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Tue, 13 Jan 2015 11:44:56 +0100 Subject: [PATCH 42/52] Fix Menu should always be black --- .../WpfDesign.Designer/Project/Controls/ControlStyles.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml index 000e7bba3b..b84b82e06d 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml @@ -91,7 +91,7 @@ - + From 2ede4f41056e8f3ae3b3c2883ca92b80403e7d23 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Wed, 14 Jan 2015 15:18:09 +0100 Subject: [PATCH 43/52] For Perf. Reasons don't use Exception --- .../Project/CollectionSupport.cs | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs index 01b71be2f6..98d3e71cf6 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs @@ -105,13 +105,22 @@ namespace ICSharpCode.WpfDesign.XamlDom /// /// Adds a value at the specified index in the collection. /// - public static void Insert(Type collectionType, object collectionInstance, XamlPropertyValue newElement, int index) + public static bool Insert(Type collectionType, object collectionInstance, XamlPropertyValue newElement, int index) { - collectionType.InvokeMember( - "Insert", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, - null, collectionInstance, - new object[] { index, newElement.GetValueFor(null) }, - CultureInfo.InvariantCulture); + var mth = collectionType.GetMethod("Insert", BindingFlags.Public | BindingFlags.Instance, + null, CallingConventions.Any, new Type[]{ typeof(int), typeof(object) }, null); + + if (mth != null) { + collectionType.InvokeMember( + "Insert", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, + null, collectionInstance, + new object[] { index, newElement.GetValueFor(null) }, + CultureInfo.InvariantCulture); + + return true; + } + + return false; } /// @@ -121,7 +130,7 @@ namespace ICSharpCode.WpfDesign.XamlDom internal static bool TryInsert(Type collectionType, object collectionInstance, XamlPropertyValue newElement, int index) { try { - Insert(collectionType, collectionInstance, newElement, index); + return Insert(collectionType, collectionInstance, newElement, index); } catch (MissingMethodException) { return false; } From 5aaced89af270e28416694c69631f49a38f8d978 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Wed, 14 Jan 2015 15:40:25 +0100 Subject: [PATCH 44/52] Fix adding two times the same string in the Designer: This does not work before: var addItem = page.designSurface.DesignContext.Services.Component.RegisterComponentForDesigner(se.Value); addItem.Key = se.Key; d.Properties["Hardware"].CollectionElements.Add(addItem); maybe we also need to change for Value Types! --- .../WpfDesign.Designer/Project/Xaml/XamlComponentService.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs index e51ab53ce2..9998929502 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs @@ -89,7 +89,8 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml } XamlDesignItem item = new XamlDesignItem(_context.Document.CreateObject(component), _context); - _sites.Add(component, item); + if (!(component is string)) + _sites.Add(component, item); if (ComponentRegistered != null) { ComponentRegistered(this, new DesignItemEventArgs(item)); } From 47a67fe2d73fe1caeeb4c390eb933c4ced21eaa4 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Wed, 14 Jan 2015 16:38:25 +0100 Subject: [PATCH 45/52] Last fix was not correct -> We don't know the Type of the Insert Object --- .../Project/CollectionSupport.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs index 98d3e71cf6..42f73d18d8 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs @@ -21,6 +21,7 @@ using System.Diagnostics; using System.Collections; using System.ComponentModel; using System.Globalization; +using System.Linq; using System.Reflection; using System.Windows; using System.Windows.Documents; @@ -39,11 +40,11 @@ namespace ICSharpCode.WpfDesign.XamlDom public static bool IsCollectionType(Type type) { return type != typeof(LineBreak) && ( - typeof(IList).IsAssignableFrom(type) + typeof(IList).IsAssignableFrom(type) || type.IsArray || typeof(IAddChild).IsAssignableFrom(type) || typeof(IDictionary).IsAssignableFrom(type)); - } + } /// /// Gets if the collection type can accepts items of type @@ -85,12 +86,12 @@ namespace ICSharpCode.WpfDesign.XamlDom } else if (collectionInstance is IDictionary) { object val = newElement.GetValueFor(null); object key = newElement is XamlObject ? ((XamlObject)newElement).GetXamlAttribute("Key") : null; - if (key == null || key == "") - { - if (val is Style) - key = ((Style)val).TargetType; - } - if (key == null || (key as string) == "") + if (key == null || key == "") + { + if (val is Style) + key = ((Style)val).TargetType; + } + if (key == null || (key as string) == "") key = val; ((IDictionary)collectionInstance).Add(key, val); } else { @@ -102,15 +103,14 @@ namespace ICSharpCode.WpfDesign.XamlDom } } - /// + /// /// Adds a value at the specified index in the collection. /// public static bool Insert(Type collectionType, object collectionInstance, XamlPropertyValue newElement, int index) { - var mth = collectionType.GetMethod("Insert", BindingFlags.Public | BindingFlags.Instance, - null, CallingConventions.Any, new Type[]{ typeof(int), typeof(object) }, null); + var hasInsert = collectionType.GetMethods().Any(x => x.Name == "Insert"); - if (mth != null) { + if (hasInsert) { collectionType.InvokeMember( "Insert", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, collectionInstance, From afb55a62ecf5e0a45ad551d3cbebfd24607e8f57 Mon Sep 17 00:00:00 2001 From: jogibear9988 Date: Sun, 18 Jan 2015 09:37:03 +0100 Subject: [PATCH 46/52] Fixes -> Save of modified Path now works --- .../Project/Controls/ControlStyles.xaml | 18 +- .../WpfDesign.Designer/Project/Converters.cs | 16 +- .../Extensions/PathHandlerExtension.cs | 179 +++++++++++------- 3 files changed, 142 insertions(+), 71 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml index d8657e78da..c4f46f0843 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml @@ -1,4 +1,9 @@ - + @@ -81,9 +86,12 @@ - - - + + + + + +