开发者

C# Piccolo ZUI - Squiggles only when CTRL wiggles?

开发者 https://www.devze.com 2022-12-14 09:07 出处:网络
I am using thePiccolo 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.

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?


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.


You can override acceptsEvent() method to control events dispatch. For example to accept events only with control key modifier:

public class DragHandler extends PDragEventhandler {
    @Override
    public boolean acceptsEvent(PInputEvent event, int type) {
        return super.acceptsEvent(event, type) && event.isControlDown();
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消