Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Handlestyles questions. (Read 7865 times)
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Handlestyles questions.
Mar 21st, 2011 at 8:58pm
Print Post  
Hello Again.
I found 2 probems wit handlestyles, probably like always Sotyo or any other user have the answers:

Answer 1:
The handles are always outside of the object, is possible setup the handles for be showed in the exat border of the node, or if possile isnde the node?  HatchHandles3 is what i use alwyas.

Answer 2:
HatchHandles3is perfect for what im doing, is possible for some object draw that handled but without resize disable, just move available?


One more final answer, where can find some example of how cutomize HatchHandles3?
Is possible make the ine between square points be invisible (invisible but ned work in same way HatchHandles3 do)

Bets regards

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Handlestyles questions.
Reply #1 - Mar 22nd, 2011 at 8:23am
Print Post  
Hi Pablo,

1. You can do that only by using the Custom handles style and handling the DrawAdjustmentHandles event. Here are some examples:

http://mindfusion.eu/Forum/YaBB.pl?board=wpfdg_disc;action=display;num=125291255...
http://mindfusion.eu/Forum/YaBB.pl?board=wpfdg_disc;action=display;num=125291255...

2. Set node.EnabledHandles = AdjustmentHandles.Move;

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Handlestyles questions.
Reply #2 - Mar 22nd, 2011 at 9:55am
Print Post  
Sorry, im not lazy, but not understand that examples:



Code
Select All
 form.DrawAdjustmentHandles += new DrawItemEventHandler(form_DrawAdjustmentHandles);


form.HitTestAdjustmentHandles += new HitTestEventHandler(form_HitTestAdjustmentHandles);



   void form_HitTestAdjustmentHandles(object sender, HitTestEventArgs e)
{
// this is in diagram coordinates
Rect r = e.Item.GetBounds();
r.X -= 0;
r.Width = 0;
if (r.Contains(e.MousePosition))
e.HitResult = 0; // move
}

void form_DrawAdjustmentHandles(object sender, DrawItemEventArgs e)
{
// this is in local coordinates
Rect r = e.Item.GetBounds();
r.Y = 0;
r.Width = 15;
r.X = -20;
e.Graphics.DrawRectangle(Brushes.White, new Pen(), r);

DiagramNode node = e.Item as DiagramNode;
 if (node != null)
{
node.HandlesStyle = HandlesStyle.HatchHandles3;
//node.DrawHandles(e.Graphics, Brushes.Black);
node.HandlesStyle = HandlesStyle.Custom;
}
}



 





In first place i have error:

Error2The best overloaded method match for 'MindFusion.Diagramming.Wpf.DiagramItem.DrawHandles(System.Windows.Media.Drawing
Context, MindFusion.Diagramming.Wpf.HandlesVisualStyle)' has some invalid arguments

and


Error5Argument 2: cannot convert from 'System.Windows.Media.SolidColorBrush' to 'MindFusion.Diagramming.Wpf.HandlesVisualStyle'

For now just for test how this work i comented : node.DrawHandles(e.Graphics, Brushes.Black);

Now i run and really nt understand how this work, but i stuck on this, not understand, this drag a big rectangle at the left of my node.

Please is to much request and example for show HatchHandles3 inside of my nodes exactly in the border?
Probably cna be great have some style work like HatchHandle3 , in the border of object but inside : )

If possible, can show complete example for do this now?

, if not..... is ok, some times i feel a little of shame to lot of request i send in the last weeks Embarrassed Undecided Kiss Roll Eyes

Also i have a second trouble, i checkk al examples and cant find any way to make handlestyiles can resize node in same proportion for width height.
basically i need for some specific node resize node without change the aspect of node.
Example, if node is square, when i move the mouse for resize, no matter what i do or how moe te node can be resized but without change the proportion .
How is posible do this?

Best regrds.
« Last Edit: Mar 23rd, 2011 at 6:43am by PDM. »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Handlestyles questions.
Reply #3 - Mar 23rd, 2011 at 7:44am
Print Post  
1. We have changed the signature of this method recently, it now takes a HandlesVisualStyle parameter instead of color. E.g. you can pass diagram.SelectedItemHandlesStyle as the second argument.

If you don't feel like drawing handles via the DrawingContext API, you could use a temporary node to render the handles for you:

Code
Select All
void diagram_DrawAdjustmentHandles(object sender, DrawItemEventArgs e)
{
	var node = e.Item as DiagramNode;
	if (node != null)
	{
		var hs = diagram.AdjustmentHandlesSize / 2;
		var bounds = node.Bounds;
		bounds.Inflate(-hs, -hs);
		var handlesPainter = diagram.Factory.CreateShapeNode(bounds);
		handlesPainter.HandlesStyle = HandlesStyle.HatchHandles3;
		e.Graphics.PushTransform(new TranslateTransform(hs, hs));
		handlesPainter.DrawHandles(e.Graphics, diagram.SelectedItemHandlesStyle);
		e.Graphics.Pop();
	diagram.Nodes.Remove(handlesPainter);
	}
} 



I suppose we can add some utility method for drawing handles at specified position for the next release.

2. Set node.Cosntraints.KeepRatio.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Handlestyles questions.
Reply #4 - Mar 23rd, 2011 at 9:19am
Print Post  
I have this error when run your example:


System.InvalidOperationException was unhandled
Message=Collection was modified; enumeration operation may not execute.
Source=mscorlib
StackTrace:

at System.Collections.ArrayList.ArrayListEnumeratorSimple.MoveNext()

at MindFusion.Diagramming.Wpf.x2965d493a804ca6b.x7aa38d23def3ba94(Rect x559038a612e67522)

at MindFusion.Diagramming.Wpf.x2965d493a804ca6b.ArrangeOverride(Size arrangeSize)

at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)

at System.Windows.UIElement.Arrange(Rect finalRect)

at MindFusion.Diagramming.Wpf.Diagram.ArrangeOverride(Size finalSize)

at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)

at System.Windows.UIElement.Arrange(Rect finalRect)

at System.Windows.ContextLayoutManager.UpdateLayout()

at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)

at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()

at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()

at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)

at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)

at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)

at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

at System.Windows.Threading.DispatcherOperation.InvokeImpl()

at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)

at System.Threading.ExecutionContext.runTryCode(Object userData)

at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(
TryCode code, CleanupCode backoutCode, Object userData)

at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Windows.Threading.DispatcherOperation.Invoke()

at System.Windows.Threading.Dispatcher.ProcessQueue()

at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)

at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)

at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)

at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)

at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)

at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)

at System.Windows.Threading.Dispatcher.Run()

at System.Windows.Application.RunDispatcher(Object ignore)

at System.Windows.Application.RunInternal(Window window)

at System.Windows.Application.Run(Window window)

at System.Windows.Application.Run()

at Project.App.Main() in C:\Users\MainWindow\obj\x86\Debug\App.g.cs:line 0

at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)

at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart()
InnerException:


What im doing wrong?
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Handlestyles questions.
Reply #5 - Mar 23rd, 2011 at 9:24am
Print Post  
This is my code:

//catch event
form.DrawAdjustmentHandles += new DrawItemEventHandler(form_DrawAdjustmentHandles);




void form_DrawAdjustmentHandles(object sender, DrawItemEventArgs e)
{

var node = e.Item as DiagramNode;

if (node != null)

{

var hs = form.AdjustmentHandlesSize / 2;

var bounds = node.Bounds;

bounds.Inflate(-hs, -hs);

var handlesPainter = form.Factory.CreateShapeNode(bounds);

handlesPainter.HandlesStyle = HandlesStyle.HatchHandles3;

e.Graphics.PushTransform(new TranslateTransform(hs, hs));

handlesPainter.DrawHandles(e.Graphics, form.SelectedItemHandlesStyle);

e.Graphics.Pop();

form.Nodes.Remove(handlesPainter);

}
}



//create node
var mshape = new myshape();


var node = new DiagramNodeAdapter(form, mshape);

node.Bounds = new Rect(e.MousePosition, new Size(150, 150));

form.Nodes.Add(node);

node.HandlesStyle = HandlesStyle.Custom;

node.Selected = true;



About your comment:
I suppose we can add some utility method for drawing handles at specified position for the next release.

YES ! please : )
Some easy way !! : )

About your help:
THANKYOU !!
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Handlestyles questions.
Reply #6 - Mar 24th, 2011 at 7:59pm
Print Post  
Any news about this?
Best regards.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Handlestyles questions.
Reply #7 - Mar 24th, 2011 at 8:44pm
Print Post  
Ok, it seems this won't work with multiple selected items because adding the temporary item to the diagram while its elements are being iterated causes that exception. Instead, try creating the handlesPainter only once in the Load handles somewhere offscreen, e,g, at -1000,-1000, and then only set its size in the DrawHandles method. Or just use the DrawingContext methods to draw a rectangle for each handle, which is the natural way to implement that event in any case.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Handlestyles questions.
Reply #8 - Mar 24th, 2011 at 9:09pm
Print Post  
???....absolutly stuck on this  Embarrassed



  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Handlestyles questions.
Reply #9 - Mar 25th, 2011 at 8:58am
Print Post  
On what, aligning the handle rectangles to the node rectangle? It's not high math you know, here 's an example that aligns and draws the bottom-middle handle, you should be able to do the rest yourself:

Code
Select All
void diagram_DrawAdjustmentHandles(object sender, DrawItemEventArgs e)
{
	var node = e.Item as DiagramNode;
	var size = new Size(
		diagram.AdjustmentHandlesSize,
		diagram.AdjustmentHandlesSize);

	if (node != null)
	{
		// draw bottom-middle handle
		var bottomMiddle = new Point(
			node.Bounds.Width / 2 - size.Width / 2,
			node.Bounds.Height - size.Height);
		e.Graphics.DrawRectangle(
			diagram.SelectedItemHandlesStyle.HandleBrush,
			diagram.SelectedItemHandlesStyle.HandlePen,
			new Rect(bottomMiddle, size));
	}
} 

  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Handlestyles questions.
Reply #10 - Mar 25th, 2011 at 11:11am
Print Post  
void form_DrawAdjustmentHandles(object sender, DrawItemEventArgs e)
{
var node = e.Item as DiagramNode;
var size = new Size(form.AdjustmentHandlesSize,form.AdjustmentHandlesSize);

if (node != null)
{
         
          var TopLeft = new Point(0, 0);
          e.Graphics.DrawRectangle(form.SelectedItemHandlesStyle.HandleBrush, form.SelectedItemHandlesStyle.HandlePen, new Rect(TopLeft, size));

          var TopMiddle = new Point(node.Bounds.Width / 2 - size.Width / 2, 0);
          e.Graphics.DrawRectangle(form.SelectedItemHandlesStyle.HandleBrush, form.SelectedItemHandlesStyle.HandlePen, new Rect(TopMiddle, size));

          var TopRight = new Point(node.Bounds.Width  - size.Width , 0);
          e.Graphics.DrawRectangle(form.SelectedItemHandlesStyle.HandleBrush, form.SelectedItemHandlesStyle.HandlePen, new Rect(TopRight, size));


          var MiddleLeft = new Point(0, node.Bounds.Height /2 - size.Height /2);
          e.Graphics.DrawRectangle(form.SelectedItemHandlesStyle.HandleBrush, form.SelectedItemHandlesStyle.HandlePen, new Rect(MiddleLeft, size));

          var MiddleRight = new Point(node.Bounds.Width - size.Width, node.Bounds.Height / 2 - size.Height / 2);
          e.Graphics.DrawRectangle(form.SelectedItemHandlesStyle.HandleBrush, form.SelectedItemHandlesStyle.HandlePen, new Rect(MiddleRight, size));

          var bottomLeft = new Point(0, node.Bounds.Height - size.Height);
          e.Graphics.DrawRectangle(form.SelectedItemHandlesStyle.HandleBrush, form.SelectedItemHandlesStyle.HandlePen,new Rect(bottomLeft, size));
      
        
    var bottomMiddle = new Point(node.Bounds.Width / 2 - size.Width / 2,node.Bounds.Height - size.Height);
    e.Graphics.DrawRectangle(form.SelectedItemHandlesStyle.HandleBrush,form.Selected
ItemHandlesStyle.HandlePen,new Rect(bottomMiddle, size));

           var bottomRight = new Point(node.Bounds.Width  - size.Width ,node.Bounds.Height - size.Height);
           e.Graphics.DrawRectangle(form.SelectedItemHandlesStyle.HandleBrush,form.Selected
ItemHandlesStyle.HandlePen,new Rect(bottomRight, size));
           
}
}

I have handles now in the place i want.
I think is all needed to make handles work, but now i cant move node or resize.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Handlestyles questions.
Reply #11 - Mar 25th, 2011 at 1:47pm
Print Post  
If you set HandlesStyle to Custom, you must also handle the HitTestAdjustmentHandles event.
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Handlestyles questions.
Reply #12 - Mar 25th, 2011 at 9:28pm
Print Post  
Im tring and make this work and this is what i have.
When i crete the node i enabled:
node.EnabledHandles = AdjustmentHandles.ResizeHandles;

void form_HitTestAdjustmentHandles(object sender, HitTestEventArgs e)
{


var node = e.Item as DiagramNode;

if (node != null)

{

node.HandlesStyle = HandlesStyle.HatchFrame;

int handle = -1;

if (node.HitTestHandle(e.MousePosition, ref handle))


e.HitResult = handle;

node.HandlesStyle = HandlesStyle.Custom;

if (handle < 8 && node.Bounds.Contains(e.MousePosition))


e.HitResult = 8;

}
}


This way is more simple , but only can move, cant move and resize at same time and not figure how do resize and move ats ame time in this way.

void form_HitTestAdjustmentHandles(object sender, HitTestEventArgs e)
{

var node = e.Item as DiagramNode;

Rect r = e.Item.GetBounds();

if (r.Contains(e.MousePosition))

e.HitResult = 8;

}

For move this work perfect, now i cna move, but is impossible resize in easy way, is very hard catch the handles for resize, imagine that happen due incorrect alineation with my new custom handles.
Please some guide to solve this?

Best regards.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Handlestyles questions.
Reply #13 - Mar 26th, 2011 at 12:08pm
Print Post  
Here's an example again for the bottom-middle custom handle. You should set HitResult to 8 only if no other handle rectangle contains MousePosition.

Code
Select All
private void diagram_HitTestAdjustmentHandles(object sender, HitTestEventArgs e)
{
	var node = e.Item as DiagramNode;
	var size = new Size(
		diagram.AdjustmentHandlesSize,
		diagram.AdjustmentHandlesSize);

	if (node != null)
	{
		var location = node.Bounds.Location;
		var diagOffset = new Vector(location.X, location.Y);

		// draw bottom-middle handle
		var bottomMiddle = new Point(
			node.Bounds.Width / 2 - size.Width / 2,
			node.Bounds.Height - size.Height);
		var bottomMiddleRect = new Rect(bottomMiddle, size);
		if (bottomMiddleRect.Contains(e.MousePosition - diagOffset))
			e.HitResult = 6;

		// etc.
	}
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Handlestyles questions.
Reply #14 - Apr 26th, 2011 at 8:35am
Print Post  
Hi Pablo,

We have made the method that draws adjustment handles public. It's the DrawAdjustmentHandles method from the InternalUtils class here:

https://mindfusion.eu/_beta/wpfdiagram252.zip

Now you can call it to draw the standard adjustment handles when custom drawing.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint