Skip to content

Commit 429d51a

Browse files
committed
FX: cursors
Fixes #4405
1 parent 9a7306e commit 429d51a

1 file changed

Lines changed: 29 additions & 8 deletions

File tree

core/src/processing/javafx/PSurfaceFX.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@
3838
import javafx.event.ActionEvent;
3939
import javafx.event.EventHandler;
4040
import javafx.event.EventType;
41+
import javafx.scene.Cursor;
42+
import javafx.scene.ImageCursor;
4143
import javafx.scene.Scene;
4244
import javafx.scene.SceneAntialiasing;
4345
import javafx.scene.canvas.Canvas;
46+
import javafx.scene.image.PixelFormat;
47+
import javafx.scene.image.WritableImage;
4448
import javafx.scene.input.KeyCode;
4549
import javafx.scene.input.KeyEvent;
4650
import javafx.scene.input.MouseEvent;
@@ -590,28 +594,45 @@ public void setFrameRate(float fps) {
590594
// canvas.requestFocus();
591595
// }
592596

597+
Cursor lastCursor = Cursor.DEFAULT;
593598

594599
public void setCursor(int kind) {
595-
// TODO Auto-generated method stub
596-
600+
Cursor c;
601+
switch (kind) {
602+
case PConstants.ARROW: c = Cursor.DEFAULT; break;
603+
case PConstants.CROSS: c = Cursor.CROSSHAIR; break;
604+
case PConstants.HAND: c = Cursor.HAND; break;
605+
case PConstants.MOVE: c = Cursor.MOVE; break;
606+
case PConstants.TEXT: c = Cursor.TEXT; break;
607+
case PConstants.WAIT: c = Cursor.WAIT; break;
608+
default: c = Cursor.DEFAULT; break;
609+
}
610+
lastCursor = c;
611+
canvas.getScene().setCursor(c);
597612
}
598613

599614

600615
public void setCursor(PImage image, int hotspotX, int hotspotY) {
601-
// TODO Auto-generated method stub
602-
616+
int w = image.pixelWidth;
617+
int h = image.pixelHeight;
618+
WritableImage im = new WritableImage(w, h);
619+
im.getPixelWriter().setPixels(0, 0, w, h,
620+
PixelFormat.getIntArgbInstance(),
621+
image.pixels,
622+
0, w);
623+
ImageCursor c = new ImageCursor(im, hotspotX, hotspotY);
624+
lastCursor = c;
625+
canvas.getScene().setCursor(c);
603626
}
604627

605628

606629
public void showCursor() {
607-
// TODO Auto-generated method stub
608-
630+
canvas.getScene().setCursor(lastCursor);
609631
}
610632

611633

612634
public void hideCursor() {
613-
// TODO Auto-generated method stub
614-
635+
canvas.getScene().setCursor(Cursor.NONE);
615636
}
616637

617638

0 commit comments

Comments
 (0)