bearstampede / piccolo2d

Automatically exported from code.google.com/p/piccolo2d
0 stars 0 forks source link

event listeners are automatically created even if disabled #179

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

I think that there is a BUG that creates a new form that 
AUTOMATICALLY creates a new PanEventHandler by default probably 
whenever a new event handler is created (PDragevent). Therefore, if you:

1) Disable the pan event listener
2) add a drag event listener 
3) remove the drag event listener
4) create a new pan event listener

you end up with two pan event listeners even if you previously disabled the 
pan event.

Therefore you need to remove it always EVEN if you have already 
instructed it to remove it in the first place. 

The following code creates a double space pan action when the steps above 
are followed:

private void handTool_Click(object sender, System.EventArgs e) 
            { 
                Canvas.RemoveInputEventListener(drag); 
                Canvas.RemoveInputEventListener(pan); 
                Canvas.AddInputEventListener(pan); 
            } 
            private void dragTool_Click(object sender, 
System.EventArgs e) 
            { 
                Canvas.RemoveInputEventListener(drag); 
                    Canvas.RemoveInputEventListener(pan); 
                Canvas.AddInputEventListener(drag); 
            } 
drag and pan are declared after my namespace: 
public partial class Form1 : PForm 
    { 
        PDragEventHandler drag = new PDragEventHandler(); 
        PPanEventHandler pan = new PPanEventHandler(); 

The solution (hacky way of doing it) is: 

private void handTool_Click(object sender, System.EventArgs e) 
            { 
                    Canvas.RemoveInputEventListener(drag); 
Canvas.RemoveInputEventListener(Canvas.PanEventHandler); 
Canvas.AddInputEventListener(Canvas.PanEventHandler); 
            } 
            private void dragTool_Click(object sender, 
System.EventArgs e) 
            { 
Canvas.RemoveInputEventListener(Canvas.PanEventHandler); 
                Canvas.RemoveInputEventListener(drag); 
                Canvas.AddInputEventListener(drag); 
            } 

Best,

Fernando Loizides

Original issue reported on code.google.com by fernando...@gmail.com on 12 May 2010 at 1:23

GoogleCodeExporter commented 9 years ago

Original comment by heue...@gmail.com on 27 Aug 2010 at 4:14