Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Custom Behaviour (Read 4218 times)
Jonathan Terrell
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 13
Joined: May 19th, 2015
Custom Behaviour
May 19th, 2015 at 10:12pm
Print Post  
Hi, I would like to implement a custom behaviour that allows the user to pan, scroll with a single finger and select a node by touching it. I found the forum entry below, but some of the methods do not exist and I am uncertain as to how you "know there there are no nodes at the touch location". Any guidance would be greatly appreciated. Jonathan

============================

We can't see how to implement it as a simple bit-wise combination, there will be too many ambiguities. If you want to combine another type of behavior with single finger panning, you could derive from that behavior class (LinkShapesBehavior let's say), and start panning when you find it appropriate (e.g. there are no nodes at touch location). All the PanBehavior class does is the following, it shouldn't be hard to integrate into a custom class:

Code:
protected void pointerDown(Point pointerPosition, MotionEvent e)
{
     panPoint = new PointF(getDiagramView().getDocScrollX(), getDiagramView().getDocScrollY());
     ptStartDragDev = pointerPosition;
}

protected void pointerMove(Point pointerPosition, MotionEvent e)
{
     Rect visibleRect = getDiagramView().getVisibleRect();
     RectF rcPage = getDiagramView().canvasToDoc(visibleRect);

     float sx = panPoint.x - getDiagramView().componentToDocLength(pointerPosition.x - ptStartDragDev.x);
     float sy = panPoint.y - getDiagramView().componentToDocLength(pointerPosition.y - ptStartDragDev.y);
    getDiagramView().scrollStayInDoc(sx, sy, rcPage);
}

private PointF panPoint;
private Point ptStartDragDev;



Placing index and middle fingers close together and panning with both shouldn't be that hard for your users anyways.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom Behaviour
Reply #1 - May 20th, 2015 at 6:14am
Print Post  
Hi,

If you only need to add selection by touch to the built-in pan behavior, you could do that via nodeClicked event handler:

Code
Select All
diagView.setBehavior(Behavior.Pan);
diagram.addDiagramListener(new DiagramAdapter()
{
	@Override
	public void nodeClicked(NodeEvent e) {
		diagram.getSelection().change(e.getNode());
	}
}); 



If you'd like to prevent panning when there's node at touch location, you could override PanBehavior like this:

Code
Select All
import android.graphics.Point;
import android.graphics.PointF;
import android.view.MotionEvent;

import com.mindfusion.diagramming.DiagramView;
import com.mindfusion.diagramming.PanBehavior;

public class MyBehavior
	extends PanBehavior
{
	protected MyBehavior(DiagramView view)
	{
		super(view);
	}

	boolean allowPan = true;

	@Override
	protected void pointerDown(Point pointerPosition, MotionEvent e)
	{
		super.pointerDown(pointerPosition, e);
		PointF diagramPoint = diagramView.deviceToDoc(pointerPosition);
		allowPan = diagramView.getDiagram().getNodeAt(diagramPoint) == null;
	}

	@Override
	protected void pointerMove(Point pointerPosition, MotionEvent e)
	{
		if (allowPan)
			super.pointerMove(pointerPosition, e);
	}
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Jonathan Terrell
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 13
Joined: May 19th, 2015
Re: Custom Behaviour
Reply #2 - May 22nd, 2015 at 10:54pm
Print Post  
Thank you very much for the feedback. I think the second approach is best for us. It wasn't so much that I wanted to stop the panning, but rather convert the single finger action from selection to scrolling. If there was an option on the DrawLinksBehavior that supported this, it would be perfect. Failing that I have drafted a behaviour that comes close to achieving what we want (the ability to zoom in and out using two fingers, draw lines between two nodes using a single finger and scroll using a single finger). I was hoping you could provide some help with the scrolling logic? Mine is very basic and doesn't support zoomed diagrams or stoping when the diagram limits (boundaries) are reached. Any suggestions as to the functions I should use on the Android platform, or example code would be greatly appreciated. I have included my current code below. Thanks again.

-------------------------------------------------------
package com.businessopera.android.main.jobs.ui;

import android.graphics.Point;
import android.graphics.PointF;
import android.view.MotionEvent;

import com.mindfusion.diagramming.DiagramView;
import com.mindfusion.diagramming.DrawLinksBehavior;

public class TestDrawLinksBehavior extends DrawLinksBehavior {

    private boolean drawRequested;
    private Point startPointerPosition;

    public TestDrawLinksBehavior(final DiagramView diagramView) {
        super(diagramView);
    }

    @Override
    protected void pointerDown(final Point pointerPosition, final MotionEvent event) {
        super.pointerDown(pointerPosition, event);
        // Check if there is a node at the touch point. This means the user wants to draw a line between nodes. Set 'drawRequest' accordingly.
        // Otherwise they are either initiating a zoom request (two fingers) or a scroll request (1 finger).
        final PointF docPointerPosition = diagramView.deviceToDoc(pointerPosition);
        drawRequested = diagramView.getDiagram().getNodeAt(docPointerPosition) != null;
        // Remember start point of touch in case we need it in scroll calculations.
        startPointerPosition = pointerPosition;
    }

    @Override
    protected void pointerMove(final Point pointerPosition, final MotionEvent event) {
        if (drawRequested) {
            // If draw requested then let 'MindFusion' library handle it.
            super.pointerMove(pointerPosition, event);
        } else {
            // It would appear that 'pointerMove is not called during two finger zoom operation. 'MindFusion' library appears to handle this separately.

            // Code to implement single finger scroll goes here. Very basic implementation. Needs work.
            final int xScroll = pointerPosition.x - startPointerPosition.x;
            final int yScroll = pointerPosition.y - startPointerPosition.y;

            diagramView.setDocScrollX(xScroll);
            diagramView.setDocScrollY(yScroll);
        }
    }

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom Behaviour
Reply #3 - May 23rd, 2015 at 12:05pm
Print Post  
This build makes Behavior constructors and some methods public, letting you create kind-of composite behaviors that delegate to standard ones:

https://mindfusion.eu/_temp/DroidDiagram.zip

Now you can combine DrawLinks with Pan as below.

Code
Select All
import android.graphics.Point;
import android.graphics.PointF;
import android.view.MotionEvent;

import com.mindfusion.diagramming.*;

public class TestDrawLinksBehavior extends DrawLinksBehavior {

	private BehaviorBase current = null;

    public TestDrawLinksBehavior(final DiagramView diagramView) {
        super(diagramView);
    }

    @Override
    public void pointerDown(final Point pointerPosition, final MotionEvent event) {
        // Check if there is a node at the touch point. This means the user wants to draw a line between nodes. Set 'drawRequest' accordingly.
        // Otherwise they are either initiating a zoom request (two fingers) or a scroll request (1 finger).
        final PointF docPointerPosition = diagramView.deviceToDoc(pointerPosition);
        boolean drawRequested = diagramView.getDiagram().getNodeAt(docPointerPosition) != null;
        current = drawRequested ?
        	new DrawLinksBehavior(diagramView) :
        	new PanBehavior(diagramView);
        current.pointerDown(pointerPosition, event);
    }

    @Override
    public void pointerMove(final Point pointerPosition, final MotionEvent event) {
        current.pointerMove(pointerPosition, event);
    }

    @Override
    public void pointerUp(Point pointerPosition, MotionEvent event) {
    	current.pointerUp(pointerPosition, event);
    }
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Jonathan Terrell
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 13
Joined: May 19th, 2015
Re: Custom Behaviour
Reply #4 - May 23rd, 2015 at 6:49pm
Print Post  
Thank you very much. This is exactly what we require. Appreciate the excellent support. Jonathan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint