How can I test with a function whether another function is being executed?

Hi I want the mousePressed () function to be executed whenever the mousePressed function is executed by the parent without having to write it into the function of the parent …

I hope you can help me :slight_smile:

class Joystick extends PApplet {
  PApplet parent;

  PVector mainLoc;
  PVector stickLoc;

  PVector value;

  float mainRadius;
  float stickRadius;

  boolean onStick = false;

  boolean mouseDown = false;
  boolean mouseUp = true;
  Joystick(PApplet p, float x, float y, float rMain) {
    super();
    parent = p;
    mainLoc = new PVector(x, y);
    stickLoc = new PVector(x, y);
    value = new PVector(0, 0);
    mainRadius = rMain;
    stickRadius = rMain/3;
  }
  void update(float x, float y) {
    moveStick(x, y);
    show();
    updateValue();
  }
  void show() {
    parent.fill(180);
    parent.stroke(0);
    parent.ellipse(mainLoc.x, mainLoc.y, mainRadius*2, mainRadius*2);

    parent.fill(130);
    parent.noStroke();
    parent.ellipse(stickLoc.x, stickLoc.y, stickRadius*2, stickRadius*2);
  }
  void updateValue() {
    float x = map(stickLoc.x, mainLoc.x-mainRadius, mainLoc.x+mainRadius, -1, 1);
    float y = map(stickLoc.y, mainLoc.y-mainRadius, mainLoc.y+mainRadius, -1, 1);
    value.set(x, y);
  }
  void moveStick(float x, float y) {
    if (onStick) {
      float d = dist(x, y, mainLoc.x, mainLoc.y);
      if (d <= mainRadius) {
        stickLoc.set(x, y);
      } else {
        PVector sub = PVector.sub(new PVector(x, y), mainLoc);
        sub.normalize();
        stickLoc.set(mainLoc.x+(sub.x*mainRadius), mainLoc.y+(sub.y*mainRadius));
      }
    } else {
      stickLoc.set(mainLoc);
    }
    //if(parent.mousePressed && mouseDown == false){
    //  mousePressed();
    //  mouseDown = true;
    //}
  }
  void mousePressed() {
    float d = dist(mouseX, mouseY, mainLoc.x, mainLoc.y);
    if (d <= mainRadius) {
      onStick = true; 
      //stickLoc.set(mouseX, mouseY);
    } else {
      onStick = false;
    }
  }
  void mouseReleased() {
    onStick = false;
  }
}

2 Likes