mouseEvent - figure out event?

In a class i have:

    p.registerMethod("mouseEvent", this);

I need to know the even for the following:

public void mouseEvent(MouseEvent e){

        if (currentMode == null) return;

        // call mousePressed(), mouseClicked(), mouseDragged() etc. in currentMode
}

How do i get the event?

Answers

  • There's no variable called currentMode in Processing's API. So I dunno what are you checking against! :@)

  • sorry currentMode is something i made. In currentMode i also have mousePressed() etc. And what i want to do is that when currentMode exist make a call like:

    currentMode.mousePressed();

  • edited May 2014

    Still very confusing. Is currentMode a PApplet reference just like p?
    Why do you need both? Your concoction is still a mystery! [..]

  • I need to know from MouseEvent e what kind of event it is. :)

  • edited May 2014

    This might help

    public class MouseHandler {
      PApplet p = null;
    
      public MouseHandler(PApplet papp) {
        p = papp;
        p.registerMethod("mouseEvent", this);
      }
    
      public void mouseEvent(MouseEvent e) {
        switch(e.getAction()) {
        case MouseEvent.PRESS:
          mousePress(e);
          break;
        case MouseEvent.RELEASE:
          mouseRelease(e);
          break;
        case MouseEvent.CLICK:
          mouseClick(e);
          break;
          // Repeat for other event types
        } 
      }
    
      public mousePress(MouseEvent e) { 
        // your code 
      }
    
      public mouseRelease(MouseEvent e) {
         // your code
      }
    
      public mouseClick(MouseEvent e) {
        // your code
      }
      // Add methods for other mouse events
    }
    
  • edited May 2014

    Seems like I'm lacking cognitive skills:
    * Is MyObject() supposed to be the constructor for class MouseHandler?
    * Again, the mysterious field currentMode pops up outta nowhere!

    In short, my Processing v2.0.2 can't compile that!!! [..]

  • edited May 2014

    I started calling the class MyObject and changed it to MouseHandler and forgot to change the ctor. I have now corrected that now.

    True the code will not compile because of the currentMode so I have now removed that now.

    Perhaps I should have said that the code wasn't tested but it was only to show how to structure a possible solution. :)

  • edited May 2014

    @quark, I believe your code only scratches whatever @clankill3r is brewing.
    He said: "In currentMode i also have mousePressed()." Even though he's yet to tell us what type that field actually is!
    So it's more complicated than we think it is. And @clankill3r expects to know how to help him out anyways!

    P.S.: You use mousePress() instead of mousePressed()! ;)

  • @GoToLoop - I agree we haven't got the full story yet.

    I suspect that currentMode is an object instantiated from a class he has created, which is why I provided an outline class.

    When I typed the code I used mousePress instead of mousePressed because it matches the action type, if he wants to use mousePressed instead - no problem. :)

  • Quark is right :) And thanks for the code.

    I jus have different displayModes and to have interaction i want each of them to have own events. But i figured my old way is better since it gives more control. For example:

    void keyPressed() {
       if (key == '1') {
           changeMode(0);
       }
        else if (key == '2') {
           changeMode(1);
       }
        else {
           currentMode.keyPressed();
        }
    }
    
Sign In or Register to comment.