|
6 | 6 | import java.awt.GraphicsConfiguration; |
7 | 7 | import java.awt.GraphicsDevice; |
8 | 8 | import java.awt.GraphicsEnvironment; |
| 9 | +import java.awt.Image; |
| 10 | +import java.awt.Point; |
9 | 11 | import java.awt.Rectangle; |
| 12 | +import java.awt.Toolkit; |
10 | 13 | import java.awt.geom.Rectangle2D; |
| 14 | +import java.awt.image.BufferedImage; |
| 15 | +import java.awt.image.MemoryImageSource; |
| 16 | +import java.nio.IntBuffer; |
11 | 17 |
|
| 18 | +import org.lwjgl.BufferUtils; |
12 | 19 | import org.lwjgl.LWJGLException; |
| 20 | +import org.lwjgl.input.Cursor; |
13 | 21 | import org.lwjgl.input.Keyboard; |
14 | 22 | import org.lwjgl.input.Mouse; |
15 | 23 | import org.lwjgl.opengl.Display; |
@@ -40,6 +48,11 @@ public class PSurfaceLWJGL implements PSurface { |
40 | 48 | PLWJGL pgl; |
41 | 49 |
|
42 | 50 | boolean fullScreenRequested; |
| 51 | + |
| 52 | + int cursorType = PConstants.ARROW; // cursor type |
| 53 | + boolean cursorVisible = true; // cursor visibility flag |
| 54 | + Cursor invisibleCursor; |
| 55 | + |
43 | 56 | // ........................................................ |
44 | 57 |
|
45 | 58 | // Event handling |
@@ -307,24 +320,68 @@ public void blit() { |
307 | 320 | @Override |
308 | 321 | public void setCursor(int kind) { |
309 | 322 | // TODO Auto-generated method stub |
| 323 | + if (PApplet.platform == PConstants.MACOSX && kind == PConstants.MOVE) { |
| 324 | + kind = PConstants.HAND; |
| 325 | + } |
| 326 | + java.awt.Cursor cursor0 = java.awt.Cursor.getPredefinedCursor(kind); |
| 327 | + |
| 328 | + |
| 329 | +// Cursor cursor1 = Cursor(cursor0., |
| 330 | +// int height, |
| 331 | +// int xHotspot, |
| 332 | +// int yHotspot, |
| 333 | +// int numImages, |
| 334 | +// java.nio.IntBuffer images, |
| 335 | +// java.nio.IntBuffer delays); |
| 336 | + |
| 337 | + |
| 338 | +// Mouse.setNativeCursor(cursor1); |
| 339 | + cursorVisible = true; |
| 340 | + this.cursorType = kind; |
310 | 341 |
|
311 | 342 | } |
312 | 343 |
|
313 | 344 | @Override |
314 | 345 | public void setCursor(PImage image, int hotspotX, int hotspotY) { |
315 | | - // TODO Auto-generated method stub |
316 | | - |
| 346 | + BufferedImage jimg = (BufferedImage)image.getNative(); |
| 347 | + IntBuffer buf = IntBuffer.wrap(jimg.getRGB(0, 0, jimg.getWidth(), jimg.getHeight(), |
| 348 | + null, 0, jimg.getWidth())); |
| 349 | + try { |
| 350 | + Cursor cursor = new Cursor(jimg.getWidth(), jimg.getHeight(), |
| 351 | + hotspotX, hotspotY, 1, buf, null); |
| 352 | + Mouse.setNativeCursor(cursor); |
| 353 | + cursorVisible = true; |
| 354 | + } catch (LWJGLException e) { |
| 355 | + // TODO Auto-generated catch block |
| 356 | + e.printStackTrace(); |
| 357 | + } |
317 | 358 | } |
318 | 359 |
|
319 | 360 | @Override |
320 | 361 | public void showCursor() { |
321 | | - // TODO Auto-generated method stub |
322 | | - |
| 362 | +// if (!cursorVisible) { |
| 363 | +// cursorVisible = true; |
| 364 | +// Mouse.setCursor(Cursor.getPredefinedCursor(cursorType)); |
| 365 | +// } |
323 | 366 | } |
324 | 367 |
|
325 | 368 | @Override |
326 | 369 | public void hideCursor() { |
327 | | - // TODO Auto-generated method stub |
| 370 | + if (invisibleCursor == null) { |
| 371 | + try { |
| 372 | + invisibleCursor = new Cursor(1, 1, 0, 0, 1, BufferUtils.createIntBuffer(1), null); |
| 373 | + } catch (LWJGLException e1) { |
| 374 | + // TODO Auto-generated catch block |
| 375 | + e1.printStackTrace(); |
| 376 | + } |
| 377 | + } |
| 378 | + try { |
| 379 | + Mouse.setNativeCursor(invisibleCursor); |
| 380 | + cursorVisible = false; |
| 381 | + } catch (LWJGLException e) { |
| 382 | + // TODO Auto-generated catch block |
| 383 | + e.printStackTrace(); |
| 384 | + } |
328 | 385 | } |
329 | 386 |
|
330 | 387 | class AnimationThread extends Thread { |
@@ -693,6 +750,8 @@ public void requestStop() { |
693 | 750 | // To complete later... |
694 | 751 | // http://docs.oracle.com/javase/6/docs/api/java/awt/event/KeyEvent.html |
695 | 752 | // http://processing.org/reference/keyCode.html |
| 753 | + // This might be very useful: |
| 754 | + // http://gtge.googlecode.com/svn/trunk/GTGE%20Add-Ons/src/com/golden/gamedev/engine/lwjgl/LWJGLInput.java |
696 | 755 | protected int LWJGLtoAWTCode(int code) { |
697 | 756 | switch (code) { |
698 | 757 | case Keyboard.KEY_0: |
|
0 commit comments