views:

92

answers:

1

I am using the Piccolo 2D ZUI library in a C# Winform application.

One of the examples that the library shows is adding a squiggle (line drawing) handler to the canvas.

The problem is that if you enable the squiggle handler and allow canvas dragging then both events occur at the same time.

What I would like to do is inherit the PDragEventhandler so that it only runs when the CTRL is not pressed down. Then when the CTRL key is pressed down the squiggler will run (I got this figured out).

The code used for the drag handler is:

InitializeComponent(); //add input event listener
pCanvas1.AddInputEventListener(new PDragEventHandler());

Can I inherit the PDragEventhandler and then say only run when CTRL not pressed? Or do I need to recompile the Piccolo library to enable this feature?

+2  A: 

For java it is extremely straight foward. In the initialize you will want to make the following changes:

public void mouseDragged(PInputEvent e) {
    super.mouseDragged(e);

    // Update the squiggle while dragging.
    updateSquiggle(e);
}

to

public void mouseDragged(PInputEvent e) {
     super.mouseDragged(e);
     if (e.isControlDown()) {
         updateSquiggle(e);
     }   
}


Explanantion: This is possible because PInputEvent inherits the java event and therefore has the isControlDown() option. In C# this is not the case and you will need to extend it manually, or add it. There is a description of how to do it for C# (which I am not very familiar with) in Part 3 of the following tutorial.


For C# I would assume the listener should look something like the following:

protected void squiggle_ControlDown(object sender, PInputEventArgs e) {
    PNode node = (PNode)sender;
    switch (e.KeyCode) {
            case Keys.Control:
                    updateSquiggle();
                    break;
    }

}

I hope this helps, I wish it hadn't been so long since I'd used C# or I could have given you a more specific answer.

macneil