Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Anchor point resizing changes the mouse position (Read 13504 times)
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Anchor point resizing changes the mouse position
Feb 3rd, 2010 at 6:28am
Print Post  
Hi Stoyo

I modified your custom node creation from template file to have a following look.


As you see in the image, the node is having two colors. This is done by having two nested grids in the template.
The outer grid is having 3 rows and 3 columns. The inner grid is placed in 2nd row and 2nd column.

To show the anchor points, I overide two function,
AddHandlesToCanvas and UpdateVisuals as discussed in one of my topic posted previously.
The anchor points are adjusted such that they will either add/remove some offset value from top,left and right, bottom values of shape node to show anchor point inside the node.

The offset is having the value for the 1st and last row,column of the outer grid.

Here when I try to resize the shape by picking one of the anchor point, my mouse cursor move to the actual corner of the shape.

I guess, since i can provide my anchor point, when resizing mouse cursor should retain its position.

I want to implement something like shown in following 5 min demo -[ Please click on the demo link on the page]
http://www.bizagi.com/index.php?option=com_content&view=article&id=15&catid=5&It...

Regards
Rajesh


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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Anchor point resizing changes the mouse positi
Reply #1 - Feb 3rd, 2010 at 11:28am
Print Post  
Hi Rajesh,

While it's possible to implement that by overriding the UpdateDrag method, this looks like a more simple way to define the outer rectangle (or some panel in your case):

1. In the Xaml template:
Code
Select All
<Canvas x:Name="Adorner">

<Canvas.Resources>
	<local:ExpandConverter x:Key="expandConverter"/>
</Canvas.Resources>

<Rectangle Fill="Green" Canvas.Left="-20" Canvas.Top="-20"
	Width="{Binding Path=Width, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource expandConverter}, ConverterParameter=40}"
	Height="{Binding Path=Height, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource expandConverter}, ConverterParameter=40}" />

...
 



2. The converter class just adds the parameter to the bound value:
Code
Select All
public class ExpandConverter : IValueConverter
{
	public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
	{
		return (double)value + int.Parse(parameter.ToString());
	}

	public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
	{
	}
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: Anchor point resizing changes the mouse positi
Reply #2 - Feb 3rd, 2010 at 1:46pm
Print Post  
Hi Stoyo

Thanks for the reply. Your suggested method is so cool.

Will you provide me a template in which I can display a border when the mouse is moved to the shapes canvas/shape itself and when mouse is out of canvas/shape the border is hidden.

Regards
Rajesh
  
Back to top
WWW  
IP Logged
 
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: Anchor point resizing changes the mouse positi
Reply #3 - Feb 3rd, 2010 at 2:29pm
Print Post  
Hi Stoyo

I am able to change the color for the rectangle fill color on mouse move.

The issue with this is that, if cursor is on canvas area, the color is updated with "MouseEnter" but as i move the cursor on shape, "MouseLeave" event get fired and the color of the rectangle changes to original color.

How i can resolve this ?
--------------------------------------------
A small update on this -
Adding the handler for Grid and Rectangle or adding handler for the canvas and changing the state in those event handle i can have same color when cursor is in canvas or on shape node but if i move the cursor on anchor points the color gets changed ( MouseLeave event get fired.)

How i can resolve this ?

Regards
Rajesh
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Anchor point resizing changes the mouse positi
Reply #4 - Feb 3rd, 2010 at 2:47pm
Print Post  
Hi Rajesh,

Are you attaching MouseEnter and Leave events to the node, or to the Rectangle object?

Stoyan
  
Back to top
 
IP Logged
 
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: Anchor point resizing changes the mouse positi
Reply #5 - Feb 3rd, 2010 at 2:57pm
Print Post  
Hi Stoyo

The event are either attached to Canvas ( Topmost element in template)
Or the events are attached to Rectangle and Grid
(Grid host the node element)

-Rajesh
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Anchor point resizing changes the mouse positi
Reply #6 - Feb 3rd, 2010 at 7:14pm
Print Post  
Hi Rajesh,

Attaching them to the node seems to work fine:

1. In the page code-behind:
Code
Select All
node1.MouseEnter += new System.Windows.Input.MouseEventHandler(OnNodeMouseEnter);
node1.MouseLeave += new System.Windows.Input.MouseEventHandler(OnNodeMouseLeave);
...

void OnNodeMouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
	var node = (OrgChartNode)sender;
	var outerRect = node.GetOuterRect();
	if (outerRect != null)
		outerRect.Fill = new SolidColorBrush(Colors.Blue);
}

void OnNodeMouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
	var node = (OrgChartNode)sender;
	var outerRect = node.GetOuterRect();
	if (outerRect != null)
		outerRect.Fill = new SolidColorBrush(Colors.Red);
}
 



2. In the template:
Code
Select All
<Rectangle x:Name="OuterRect" ...
 



3. In the derived node class:
Code
Select All
public Rectangle GetOuterRect()
{
	return GetTemplateChild("OuterRect") as Rectangle;
}
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: Anchor point resizing changes the mouse positi
Reply #7 - Feb 4th, 2010 at 9:42am
Print Post  
Hi Stoyo

In your example you are referring node1, where as in my code, I guess i should write "this".

Writing "this." referes to the complete canvas which is top level element.

Will you explained how i can do this in my attached zip file. [ Zip file contains orgchartnode.cs and generic.xaml]

File : https://cid-2b9bf77533900b84.skydrive.live.com/self.aspx/.Public/Tutorial3.zip

Regards
Rajesh
  
Back to top
WWW  
IP Logged
 
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: Anchor point resizing changes the mouse positi
Reply #8 - Feb 4th, 2010 at 9:50am
Print Post  
Hi Stoyo

Will you provide me solution for the above issue. Please find the url in previous message.

Another issue - How i will get the event which indicates that the node gets added in the selection list and removed from the selection list.

In my example I am trying to achive following behaviour -

1. When user moves the mouse cursor on the node area, border is shown.

2. Once border is shown, user can either move the cursor on the node or rectangle ( complete canvas area) border remains visible [ Even user moves the cursor outsider the node(grid area ]

3. Case 2nd has exception : if node is selected then moving outside the node area/canvas area border is not removed until user moves cursor on another node [ Moving mouse cursor on another node keeps the previous node selected ]

4. With case 3, if user moves the mouse cursor outside the shape canvas border remains visible (node is selected) but now clicking on anywhere on the diagram area (not on any node) I want to remove the border which is shown visible.

How to handle case 4 or do I need the extra event ( node added in selection and node removed from selection).

Regards
Rajesh


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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Anchor point resizing changes the mouse positi
Reply #9 - Feb 4th, 2010 at 10:04am
Print Post  
Hi Rajesh,

That code is a modification of Tutorial3, and node1 there is one of the sample nodes created in the control_loaded handler.

Stoyan
  
Back to top
 
IP Logged
 
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: Anchor point resizing changes the mouse positi
Reply #10 - Feb 4th, 2010 at 10:21am
Print Post  
Hi Stoyo

Ya. True. The code is modified from Tutorial3.

I modified the derived class and generic template.
Node1 is referred in main.xaml.cs.

To meet my requirement for all nodes of type orgchart , it gets handled from generic.xaml and orgchatnode.cs file with help of visual state.
I guess, i should not write the handler explicitiy for all nodes from main.xaml.cs explicitly.

----------------------------------------------------------
Update on the above issue :
I just re-checked my sample and it seems working with anchor point also. May be somechanges which I applied make it working.

How I resolve my last issue i.e getting the event for node gets selected and unselected in its own class.

Regards
Rajesh
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Anchor point resizing changes the mouse positi
Reply #11 - Feb 4th, 2010 at 11:40am
Print Post  
Hi Rajesh,

I think you can implement that without handling extra events. In MouseLeave do not hide the border if the Selected property returns true, but save a reference to the node in some variable. In MouseEnter raised for a different node, hide the border for the previous selected node if there is a saved reference and set the variable to null.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
rajesh_patil74
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 220
Joined: Sep 3rd, 2009
Re: Anchor point resizing changes the mouse positi
Reply #12 - Feb 4th, 2010 at 12:03pm
Print Post  
Hi Stoyo

I think, you didn't get my question. Will explain it again -

With mouseenter in another node, I am able to hide the border of selected node ( using this.diagram.Selection.Item[0] )

diagram.Selection.Item[0] and this both are different node.

My concern is when node is selected, I keep the border active even mouse is moved in diagram area. Now when user clicks anywhere in the diagram, item which exists in selection collection is removed. When this item is removed from selection, I want to remove the border.

-Rajesh
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Anchor point resizing changes the mouse positi
Reply #13 - Feb 4th, 2010 at 2:19pm
Print Post  
Hi Rajesh,

You could handle NodeDeselected to detect that.

Stoyan
  
Back to top
 
IP Logged
 
sandeep.vetakari
YaBB Newbies
*
Offline


:) :) :)

Posts: 2
Joined: Apr 11th, 2011
Re: Anchor point resizing changes the mouse positi
Reply #14 - Apr 11th, 2011 at 7:17am
Print Post  
I have a problem regarding Anchor Points. I have different diagram nodes and i have set anchor points as percentage points to them to set it onto the boundaries of the node. The issue is these points behaves like absolute values when i do the scaling or resizing of the node. ie The points location does not change as the size of the Node changes.

Please tell me what could be the issue.

my code is like
AnchorPattern anchorPattern = new AnchorPattern();
           anchorPattern.Points = inputAnchorPoints;

           foreach (AnchorPoint anchorPoint in anchorPattern.Points)
           {
               anchorPoint.MarkStyle = MarkStyle.Rectangle;
           }

           diagramNode.EnabledHandles = nodeControl.EnableHandles;
           diagramNode.AnchorPattern = anchorPattern;
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint