|
38 | 38 | import javafx.event.ActionEvent; |
39 | 39 | import javafx.event.EventHandler; |
40 | 40 | import javafx.event.EventType; |
| 41 | +import javafx.scene.Cursor; |
| 42 | +import javafx.scene.ImageCursor; |
41 | 43 | import javafx.scene.Scene; |
42 | 44 | import javafx.scene.SceneAntialiasing; |
43 | 45 | import javafx.scene.canvas.Canvas; |
| 46 | +import javafx.scene.image.PixelFormat; |
| 47 | +import javafx.scene.image.WritableImage; |
44 | 48 | import javafx.scene.input.KeyCode; |
45 | 49 | import javafx.scene.input.KeyEvent; |
46 | 50 | import javafx.scene.input.MouseEvent; |
@@ -590,28 +594,45 @@ public void setFrameRate(float fps) { |
590 | 594 | // canvas.requestFocus(); |
591 | 595 | // } |
592 | 596 |
|
| 597 | + Cursor lastCursor = Cursor.DEFAULT; |
593 | 598 |
|
594 | 599 | 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); |
597 | 612 | } |
598 | 613 |
|
599 | 614 |
|
600 | 615 | 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); |
603 | 626 | } |
604 | 627 |
|
605 | 628 |
|
606 | 629 | public void showCursor() { |
607 | | - // TODO Auto-generated method stub |
608 | | - |
| 630 | + canvas.getScene().setCursor(lastCursor); |
609 | 631 | } |
610 | 632 |
|
611 | 633 |
|
612 | 634 | public void hideCursor() { |
613 | | - // TODO Auto-generated method stub |
614 | | - |
| 635 | + canvas.getScene().setCursor(Cursor.NONE); |
615 | 636 | } |
616 | 637 |
|
617 | 638 |
|
|
0 commit comments