Browse Source

Basic Impl. of DrawLine support on Canvas.

Need to work on this a little bit more
pull/637/head
jkuehner 11 years ago
parent
commit
6e461ebc35
  1. 15
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/DragListener.cs
  2. 114
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawLineBehavior.cs
  3. 11
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs
  4. 21
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs
  5. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  6. 35
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DrawItemBehavior.cs
  7. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj

15
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/DragListener.cs

@ -44,6 +44,21 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -44,6 +44,21 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
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;
static void PostProcessInput(object sender, ProcessInputEventArgs e)

114
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasDrawLineBehavior.cs

@ -0,0 +1,114 @@ @@ -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<LineHandlerExtension>().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();
}
}
}

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

@ -49,6 +49,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -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 @@ -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;
}

21
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs

@ -201,14 +201,23 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -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<IPlacementBehavior>();
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<IDrawItemBehavior>();
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<IPlacementBehavior>();
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;
}
}
}
}
}

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

@ -86,6 +86,7 @@ @@ -86,6 +86,7 @@
<Compile Include="ArrangeDirection.cs" />
<Compile Include="Controls\RenderTransformOriginThumb.cs" />
<Compile Include="Extensions\BorderForImageControl.cs" />
<Compile Include="Extensions\CanvasDrawLineBehavior.cs" />
<Compile Include="Extensions\DefaultCommandsContextMenu.xaml.cs">
<DependentUpon>DefaultCommandsContextMenu.xaml</DependentUpon>
<SubType>Code</SubType>

35
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DrawItemBehavior.cs

@ -0,0 +1,35 @@ @@ -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
{
/// <summary>
/// Behavior interface implemented by container elements to support resizing
/// drawing new Elements
/// </summary>
public interface IDrawItemBehavior
{
bool CanItemBeDrawn(Type createItemType);
void StartDrawItem(DesignItem clickedOn, DesignItem createdItem, ChangeGroup changeGroup, IDesignPanel panel, MouseEventArgs e);
}
}

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj

@ -73,6 +73,7 @@ @@ -73,6 +73,7 @@
<Compile Include="Adorners\AdornerProvider.cs" />
<Compile Include="Adorners\AdornerProviderClasses.cs" />
<Compile Include="Adorners\RelativePlacement.cs" />
<Compile Include="DrawItemBehavior.cs" />
<Compile Include="DummyValueInsteadOfNullTypeDescriptionProvider.cs" />
<Compile Include="ExtensionMethods.cs" />
<Compile Include="Extensions\ExtensionAttribute.cs" />

Loading…
Cancel
Save