Cursor icon with Processing P2D renderer doesn't update as expected

Hi!
I am using processings P2D renderer and want to change the cursor icon when it has a specific location. This works as expected without the renderer, but with P2D the cursor changes to my computers default cursor after the program has been running for less than a minute and doesn’t change icon when it should. Here’s an example:

void setup() {
  size(400, 400, P2D);
}

void draw() {
  if (mouseX < width/2) cursor(ARROW);
  else cursor(HAND);
}

According to Processings cursor() reference, P2D uses a different set of cursors, but after less than a minute of the example above, the cursor changes to my default cursor again.

I’ve tried moving the code in draw() to mouseMoved() but the same result occurs.
I’ve also tried to replace the cursors with images of cursors with cursor(my_cursor_img), but the same thing happens.

Right now the only solution I see is setting the cursor to noCursor() in setup and calling image(my_cursor_img, mouseX, mouseY) every frame, but that doesn’t seem like the optimal solution.

Does anyone have any ideas how to fix this?

@Bjoe – were you able to resolve this issue? It sounds like it might be a bug worth reporting – along with specific details about your operating system / version:

If I was to guess about workarounds, my first guess would be something like this:

if (pmouseX < width/2 && mouseX >= width/2) cursor(HAND);
else if (pmouseX >= width/2 && mouseX < width/2) cursor(ARROW);

This means that cursor() won’t be called every frame – only on (rare) transition frames. See if that makes the problem better or worse.

1 Like

Your solution works!
I never thought of only calling the function at transitions, especially since the example at the reference page calls it every frame.

I did however create an issue:

1 Like

I found a much easier (and obvious) solution:

boolean cursorHand;

void draw() {
  if (mouseX > width/2) {
    if (!cursorHand) {
      cursor(HAND);
      cursorHand = true;
    }
  } else {
    if (cursorHand) {
      cursor(ARROW);
      cursorHand = false;
    }
  }
}

This also results in that the function is called only when a change in the cursor icon should happen because of the boolean.

1 Like