picrate 1.2.3-java → 2.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/Gemfile +3 -1
  4. data/README.md +8 -9
  5. data/Rakefile +10 -9
  6. data/bin/picrate +3 -1
  7. data/docs/_config.yml +1 -1
  8. data/docs/_editors/geany.md +1 -0
  9. data/docs/_gems/gems/gems.md +1 -1
  10. data/docs/_posts/2018-05-06-getting_started.md +4 -4
  11. data/docs/_posts/2018-05-06-install_jruby.md +5 -11
  12. data/docs/_posts/2018-05-11-arch-linux-arm.md +1 -11
  13. data/docs/_posts/2018-11-18-building-gem.md +2 -2
  14. data/docs/_posts/2018-11-27-getting_started_geany.md +4 -4
  15. data/docs/_posts/2019-11-11-getting_started_buster.md +4 -7
  16. data/docs/_posts/2020-03-09-auto_install_picrate.md +34 -0
  17. data/docs/_posts/2020-05-11-getting_started_manjaro.md +94 -0
  18. data/docs/about.md +1 -1
  19. data/lib/picrate.rb +1 -1
  20. data/lib/picrate/app.rb +11 -3
  21. data/lib/picrate/creators/parameters.rb +8 -8
  22. data/lib/picrate/creators/sketch_factory.rb +5 -3
  23. data/lib/picrate/helper_methods.rb +21 -21
  24. data/lib/picrate/helpers/numeric.rb +2 -0
  25. data/lib/picrate/library.rb +5 -1
  26. data/lib/picrate/library_loader.rb +2 -0
  27. data/lib/picrate/native_folder.rb +2 -1
  28. data/lib/picrate/native_loader.rb +3 -0
  29. data/lib/picrate/runner.rb +5 -2
  30. data/lib/picrate/version.rb +1 -1
  31. data/library/boids/boids.rb +17 -8
  32. data/library/chooser/chooser.rb +10 -9
  33. data/library/color_group/color_group.rb +2 -0
  34. data/library/control_panel/control_panel.rb +7 -4
  35. data/library/dxf/dxf.rb +2 -0
  36. data/library/library_proxy/library_proxy.rb +2 -0
  37. data/library/net/net.rb +2 -0
  38. data/library/slider/slider.rb +24 -23
  39. data/library/vector_utils/vector_utils.rb +4 -0
  40. data/library/video_event/video_event.rb +2 -0
  41. data/picrate.gemspec +13 -14
  42. data/pom.rb +28 -26
  43. data/pom.xml +18 -6
  44. data/src/main/java/monkstone/ColorUtil.java +1 -1
  45. data/src/main/java/monkstone/MathToolModule.java +1 -1
  46. data/src/main/java/monkstone/PicrateLibrary.java +8 -8
  47. data/src/main/java/monkstone/fastmath/Deglut.java +16 -16
  48. data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
  49. data/src/main/java/monkstone/noise/SimplexNoise.java +3 -3
  50. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  51. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  52. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +12 -12
  53. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  54. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  55. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  56. data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
  57. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  58. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
  59. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
  60. data/src/main/java/monkstone/videoevent/CaptureEvent.java +1 -1
  61. data/src/main/java/monkstone/videoevent/MovieEvent.java +1 -1
  62. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  63. data/src/main/java/processing/awt/PGraphicsJava2D.java +33 -36
  64. data/src/main/java/processing/awt/PImageAWT.java +377 -0
  65. data/src/main/java/processing/awt/PSurfaceAWT.java +0 -20
  66. data/src/main/java/processing/awt/ShimAWT.java +545 -0
  67. data/src/main/java/processing/core/PApplet.java +699 -1523
  68. data/src/main/java/processing/core/PConstants.java +180 -180
  69. data/src/main/java/processing/core/PFont.java +2 -2
  70. data/src/main/java/processing/core/PGraphics.java +190 -176
  71. data/src/main/java/processing/core/PImage.java +1536 -1721
  72. data/src/main/java/processing/core/PMatrix.java +39 -39
  73. data/src/main/java/processing/core/PSurface.java +69 -103
  74. data/src/main/java/processing/core/PSurfaceNone.java +29 -0
  75. data/src/main/java/processing/core/PVector.java +2 -2
  76. data/src/main/java/processing/data/FloatDict.java +251 -284
  77. data/src/main/java/processing/data/TableRow.java +32 -32
  78. data/src/main/java/processing/dxf/RawDXF.java +3 -3
  79. data/src/main/java/processing/net/Client.java +1 -1
  80. data/src/main/java/processing/opengl/PGL.java +1016 -4132
  81. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +223 -184
  82. data/src/main/java/processing/opengl/PJOGL.java +374 -1526
  83. data/src/main/java/processing/opengl/PShapeOpenGL.java +5 -6
  84. data/src/main/java/processing/opengl/PSurfaceJOGL.java +262 -147
  85. data/test/color_group_test.rb +4 -4
  86. data/test/deglut_spec_test.rb +2 -0
  87. data/test/helper_methods_test.rb +41 -13
  88. data/test/math_tool_test.rb +46 -37
  89. data/test/respond_to_test.rb +5 -3
  90. data/test/sketches/key_event.rb +2 -2
  91. data/test/sketches/library/my_library/my_library.rb +3 -0
  92. data/test/test_helper.rb +2 -0
  93. data/test/vecmath_spec_test.rb +30 -19
  94. data/vendors/Rakefile +13 -7
  95. data/vendors/{picrate_sketches.geany → geany.rb} +32 -7
  96. metadata +26 -47
  97. data/docs/_posts/2018-06-26-auto_install_picrate.md +0 -30
  98. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  99. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  100. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  101. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -1756,7 +1756,7 @@ public class PShapeOpenGL extends PShape {
1756
1756
  }
1757
1757
 
1758
1758
  VertexAttribute attrib = polyAttribs.get(name);
1759
- float[] array = inGeo.fattribs.get(name);
1759
+ float[] array = (float[]) inGeo.fattribs.get(name);
1760
1760
  for (int i = 0; i < values.length; i++) {
1761
1761
  array[attrib.size * index + 0] = values[i];
1762
1762
  }
@@ -1772,7 +1772,7 @@ public class PShapeOpenGL extends PShape {
1772
1772
  }
1773
1773
 
1774
1774
  VertexAttribute attrib = polyAttribs.get(name);
1775
- int[] array = inGeo.iattribs.get(name);
1775
+ int[] array = (int[]) inGeo.iattribs.get(name);
1776
1776
  for (int i = 0; i < values.length; i++) {
1777
1777
  array[attrib.size * index + 0] = values[i];
1778
1778
  }
@@ -1788,7 +1788,7 @@ public class PShapeOpenGL extends PShape {
1788
1788
  }
1789
1789
 
1790
1790
  VertexAttribute attrib = polyAttribs.get(name);
1791
- byte[] array = inGeo.battribs.get(name);
1791
+ byte[] array = (byte[]) inGeo.battribs.get(name);
1792
1792
  for (int i = 0; i < values.length; i++) {
1793
1793
  array[attrib.size * index + 0] = (byte)(values[i]?1:0);
1794
1794
  }
@@ -3968,8 +3968,7 @@ public class PShapeOpenGL extends PShape {
3968
3968
  tessGeo.updateAttribBuffer(attrib.name);
3969
3969
  if (!attrib.bufferCreated()) attrib.createBuffer(pgl);
3970
3970
  pgl.bindBuffer(PGL.ARRAY_BUFFER, attrib.buf.glId);
3971
- pgl.bufferData(PGL.ARRAY_BUFFER, attrib.sizeInBytes(size),
3972
- tessGeo.polyAttribBuffers.get(name), glUsage);
3971
+ pgl.bufferData(PGL.ARRAY_BUFFER, attrib.sizeInBytes(size), (Buffer) tessGeo.polyAttribBuffers.get(name), glUsage);
3973
3972
  }
3974
3973
 
3975
3974
  pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
@@ -4333,7 +4332,7 @@ public class PShapeOpenGL extends PShape {
4333
4332
  protected void copyPolyAttrib(VertexAttribute attrib, int offset, int size) {
4334
4333
  tessGeo.updateAttribBuffer(attrib.name, offset, size);
4335
4334
  pgl.bindBuffer(PGL.ARRAY_BUFFER, attrib.buf.glId);
4336
- Buffer buf = tessGeo.polyAttribBuffers.get(attrib.name);
4335
+ Buffer buf = (Buffer) tessGeo.polyAttribBuffers.get(attrib.name);
4337
4336
  buf.position(attrib.size * offset);
4338
4337
  pgl.bufferSubData(PGL.ARRAY_BUFFER, attrib.sizeInBytes(offset),
4339
4338
  attrib.sizeInBytes(size), buf);
@@ -63,6 +63,10 @@ import com.jogamp.newt.awt.NewtCanvasAWT;
63
63
  import com.jogamp.newt.event.InputEvent;
64
64
  import com.jogamp.newt.opengl.GLWindow;
65
65
  import com.jogamp.opengl.util.FPSAnimator;
66
+ import java.awt.EventQueue;
67
+ import java.awt.FileDialog;
68
+ import processing.awt.PImageAWT;
69
+ import processing.awt.ShimAWT;
66
70
 
67
71
  import processing.core.PApplet;
68
72
  import processing.core.PConstants;
@@ -438,21 +442,6 @@ public class PSurfaceJOGL implements PSurface {
438
442
  *
439
443
  */
440
444
  protected void initAnimator() {
441
- if (PApplet.platform == PConstants.WINDOWS) {
442
- // Force Windows to keep timer resolution high by
443
- // sleeping for time which is not a multiple of 10 ms.
444
- // See section "Clocks and Timers on Windows":
445
- // https://blogs.oracle.com/dholmes/entry/inside_the_hotspot_vm_clocks
446
- Thread highResTimerThread = new Thread(() -> {
447
- try {
448
- Thread.sleep(Long.MAX_VALUE);
449
- } catch (InterruptedException ignore) {
450
- }
451
- }, "HighResTimerThread");
452
- highResTimerThread.setDaemon(true);
453
- highResTimerThread.start();
454
- }
455
-
456
445
  animator = new FPSAnimator(window, 60);
457
446
  drawException = null;
458
447
  animator.setUncaughtExceptionHandler((final GLAnimatorControl animator1, final GLAutoDrawable drawable, final Throwable cause) -> {
@@ -462,34 +451,31 @@ public class PSurfaceJOGL implements PSurface {
462
451
  }
463
452
  });
464
453
 
465
- drawExceptionHandler = new Thread(new Runnable() {
466
- @Override
467
- public void run() {
468
- synchronized (drawExceptionMutex) {
469
- try {
470
- while (drawException == null) {
471
- drawExceptionMutex.wait();
472
- }
473
- // System.err.println("Caught exception: " + drawException.getMessage());
474
- if (drawException != null) {
475
- Throwable cause = drawException.getCause();
476
- if (cause instanceof ThreadDeath) {
477
- // System.out.println("caught ThreadDeath");
478
- // throw (ThreadDeath)cause;
479
- } else if (cause instanceof RuntimeException) {
480
- throw (RuntimeException) cause;
481
- } else if (cause instanceof UnsatisfiedLinkError) {
482
- throw new UnsatisfiedLinkError(cause.getMessage());
483
- } else if (cause == null) {
484
- throw new RuntimeException(drawException.getMessage());
485
- } else {
486
- throw new RuntimeException(cause);
487
- }
488
- }
489
- } catch (InterruptedException e) {
490
- }
454
+ drawExceptionHandler = new Thread(() -> {
455
+ synchronized (drawExceptionMutex) {
456
+ try {
457
+ while (drawException == null) {
458
+ drawExceptionMutex.wait();
459
+ }
460
+ // System.err.println("Caught exception: " + drawException.getMessage());
461
+ if (drawException != null) {
462
+ Throwable cause = drawException.getCause();
463
+ if (cause instanceof ThreadDeath) {
464
+ // System.out.println("caught ThreadDeath");
465
+ // throw (ThreadDeath)cause;
466
+ } else if (cause instanceof RuntimeException) {
467
+ throw (RuntimeException) cause;
468
+ } else if (cause instanceof UnsatisfiedLinkError) {
469
+ throw new UnsatisfiedLinkError(cause.getMessage());
470
+ } else if (cause == null) {
471
+ throw new RuntimeException(drawException.getMessage());
472
+ } else {
473
+ throw new RuntimeException(cause);
491
474
  }
475
+ }
476
+ } catch (InterruptedException e) {
492
477
  }
478
+ }
493
479
  });
494
480
  drawExceptionHandler.start();
495
481
  }
@@ -532,7 +518,7 @@ public class PSurfaceJOGL implements PSurface {
532
518
  *
533
519
  */
534
520
  protected void initIcons() {
535
- IOUtil.ClassResources res = null;
521
+ IOUtil.ClassResources res;
536
522
  if (PJOGL.icons == null || PJOGL.icons.length == 0) {
537
523
  // Default Processing icons
538
524
  final int[] sizes = {16, 32, 48, 64, 128, 256, 512};
@@ -560,7 +546,7 @@ public class PSurfaceJOGL implements PSurface {
560
546
  @SuppressWarnings("resource")
561
547
  private String resourceFilename(String filename) {
562
548
  // The code below comes from PApplet.createInputRaw() with a few adaptations
563
- InputStream stream = null;
549
+ InputStream stream;
564
550
  try {
565
551
  // First see if it's in a data folder. This may fail by throwing
566
552
  // a SecurityException. If so, this whole block will be skipped.
@@ -592,10 +578,10 @@ public class PSurfaceJOGL implements PSurface {
592
578
  }
593
579
 
594
580
  stream = new FileInputStream(file);
595
- if (stream != null) {
581
+ // if (stream != null) {
596
582
  stream.close();
597
583
  return file.getCanonicalPath();
598
- }
584
+ // }
599
585
 
600
586
  // have to break these out because a general Exception might
601
587
  // catch the RuntimeException being thrown above
@@ -641,29 +627,29 @@ public class PSurfaceJOGL implements PSurface {
641
627
  try {
642
628
  String path = sketch.dataPath(filename);
643
629
  stream = new FileInputStream(path);
644
- if (stream != null) {
630
+ // if (stream != null) {
645
631
  stream.close();
646
632
  return path;
647
- }
633
+ // }
648
634
  } catch (IOException e2) {
649
635
  }
650
636
 
651
637
  try {
652
638
  String path = sketch.sketchPath(filename);
653
639
  stream = new FileInputStream(path);
654
- if (stream != null) {
640
+ //if (stream != null) {
655
641
  stream.close();
656
642
  return path;
657
- }
643
+ // }
658
644
  } catch (IOException e) {
659
645
  } // ignored
660
646
 
661
647
  try {
662
648
  stream = new FileInputStream(filename);
663
- if (stream != null) {
649
+ // if (stream != null) {
664
650
  stream.close();
665
651
  return filename;
666
- }
652
+ // }
667
653
  } catch (IOException e1) {
668
654
  }
669
655
 
@@ -909,6 +895,148 @@ public class PSurfaceJOGL implements PSurface {
909
895
  });
910
896
  }
911
897
 
898
+ // TODO rewrite before 4.0 release
899
+ @Override
900
+ public PImage loadImage(String path, Object... args) {
901
+ return ShimAWT.loadImage(sketch, path, args);
902
+ }
903
+
904
+
905
+ @Override
906
+ public void selectInput(String prompt, String callbackMethod,
907
+ File file, Object callbackObject) {
908
+ EventQueue.invokeLater(() -> {
909
+ // https://github.com/processing/processing/issues/3831
910
+ boolean hide = (sketch != null) &&
911
+ (PApplet.platform == PConstants.WINDOWS);
912
+ if (hide) setVisible(false);
913
+
914
+ ShimAWT.selectImpl(prompt, callbackMethod, file,
915
+ callbackObject, null, FileDialog.LOAD);
916
+
917
+ if (hide) setVisible(true);
918
+ });
919
+ }
920
+
921
+
922
+ @Override
923
+ public void selectOutput(String prompt, String callbackMethod,
924
+ File file, Object callbackObject) {
925
+ EventQueue.invokeLater(() -> {
926
+ // https://github.com/processing/processing/issues/3831
927
+ boolean hide = (sketch != null) &&
928
+ (PApplet.platform == PConstants.WINDOWS);
929
+ if (hide) setVisible(false);
930
+
931
+ ShimAWT.selectImpl(prompt, callbackMethod, file,
932
+ callbackObject, null, FileDialog.SAVE);
933
+
934
+ if (hide) setVisible(true);
935
+ });
936
+ }
937
+
938
+
939
+ @Override
940
+ public void selectFolder(String prompt, String callbackMethod,
941
+ File file, Object callbackObject) {
942
+ EventQueue.invokeLater(() -> {
943
+ // https://github.com/processing/processing/issues/3831
944
+ boolean hide = (sketch != null) &&
945
+ (PApplet.platform == PConstants.WINDOWS);
946
+ if (hide) setVisible(false);
947
+
948
+ ShimAWT.selectFolderImpl(prompt, callbackMethod, file,
949
+ callbackObject, null);
950
+
951
+ if (hide) setVisible(true);
952
+ });
953
+ }
954
+
955
+ @Override
956
+ public void setCursor(int kind) {
957
+ if (!cursorNames.containsKey(kind)) {
958
+ PGraphics.showWarning("Unknown cursor type: " + kind);
959
+ return;
960
+ }
961
+ CursorInfo cursor = cursors.get(kind);
962
+ if (cursor == null) {
963
+ String name = cursorNames.get(kind);
964
+ if (name != null) {
965
+ ImageIcon icon =
966
+ new ImageIcon(getClass().getResource("cursors/" + name + ".png"));
967
+ PImage img = new PImageAWT(icon.getImage());
968
+ // Most cursors just use the center as the hotspot...
969
+ int x = img.width / 2;
970
+ int y = img.height / 2;
971
+ // ...others are more specific
972
+ switch (kind) {
973
+ case PConstants.ARROW:
974
+ x = 10;
975
+ y = 7;
976
+ break;
977
+ case PConstants.HAND:
978
+ x = 12;
979
+ y = 8;
980
+ break;
981
+ case PConstants.TEXT:
982
+ x = 16;
983
+ y = 22;
984
+ break;
985
+ default:
986
+ break;
987
+ }
988
+ cursor = new CursorInfo(img, x, y);
989
+ cursors.put(kind, cursor);
990
+ }
991
+ }
992
+ if (cursor != null) {
993
+ cursor.set();
994
+ } else {
995
+ PGraphics.showWarning("Cannot load cursor type: " + kind);
996
+ }
997
+ }
998
+
999
+
1000
+ @Override
1001
+ public void setCursor(PImage image, int hotspotX, int hotspotY) {
1002
+ Display disp = window.getScreen().getDisplay();
1003
+ BufferedImage bimg = (BufferedImage)image.getNative();
1004
+ DataBufferInt dbuf = (DataBufferInt)bimg.getData().getDataBuffer();
1005
+ int[] ipix = dbuf.getData();
1006
+ ByteBuffer pixels = ByteBuffer.allocate(ipix.length * 4);
1007
+ pixels.asIntBuffer().put(ipix);
1008
+ PixelFormat format = PixelFormat.ARGB8888;
1009
+ final Dimension size = new Dimension(bimg.getWidth(), bimg.getHeight());
1010
+ PixelRectangle pixelrect = new PixelRectangle.GenericPixelRect(format, size, 0, false, pixels);
1011
+ final PointerIcon pi = disp.createPointerIcon(pixelrect, hotspotX, hotspotY);
1012
+ display.getEDTUtil().invoke(false, () -> {
1013
+ window.setPointerVisible(true);
1014
+ window.setPointerIcon(pi);
1015
+ });
1016
+ }
1017
+
1018
+
1019
+ @Override
1020
+ public void showCursor() {
1021
+ display.getEDTUtil().invoke(false, () -> {
1022
+ window.setPointerVisible(true);
1023
+ });
1024
+ }
1025
+
1026
+
1027
+ @Override
1028
+ public void hideCursor() {
1029
+ display.getEDTUtil().invoke(false, () -> {
1030
+ window.setPointerVisible(false);
1031
+ });
1032
+ }
1033
+
1034
+
1035
+ @Override
1036
+ public boolean openLink(String url) {
1037
+ return ShimAWT.openLink(url);
1038
+ }
1039
+
912
1040
  class DrawListener implements GLEventListener {
913
1041
 
914
1042
  @Override
@@ -1371,108 +1499,95 @@ public class PSurfaceJOGL implements PSurface {
1371
1499
  return def;
1372
1500
  }
1373
1501
 
1374
- // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1375
- class CursorInfo {
1376
-
1377
- PImage image;
1378
- int x, y;
1379
-
1380
- CursorInfo(PImage image, int x, int y) {
1381
- this.image = image;
1382
- this.x = x;
1383
- this.y = y;
1384
- }
1385
-
1386
- void set() {
1387
- setCursor(image, x, y);
1388
- }
1389
- }
1390
1502
 
1391
- static Map<Integer, CursorInfo> cursors = new HashMap<>();
1392
- static Map<Integer, String> cursorNames = new HashMap<>();
1393
1503
 
1394
- static {
1395
- cursorNames.put(PConstants.ARROW, "arrow");
1396
- cursorNames.put(PConstants.CROSS, "cross");
1397
- cursorNames.put(PConstants.WAIT, "wait");
1398
- cursorNames.put(PConstants.MOVE, "move");
1399
- cursorNames.put(PConstants.HAND, "hand");
1400
- cursorNames.put(PConstants.TEXT, "text");
1401
- }
1504
+ class CursorInfo {
1505
+ PImage image;
1506
+ int x, y;
1402
1507
 
1403
- @Override
1404
- public void setCursor(int kind) {
1405
- if (!cursorNames.containsKey(kind)) {
1406
- PGraphics.showWarning("Unknown cursor type: " + kind);
1407
- return;
1408
- }
1409
- CursorInfo cursor = cursors.get(kind);
1410
- if (cursor == null) {
1411
- String name = cursorNames.get(kind);
1412
- if (name != null) {
1413
- ImageIcon icon
1414
- = new ImageIcon(getClass().getResource("cursors/" + name + ".png"));
1415
- PImage img = new PImage(icon.getImage());
1416
- // Most cursors just use the center as the hotspot...
1417
- int x = img.width / 2;
1418
- int y = img.height / 2;
1419
- // ...others are more specific
1420
- switch (kind) {
1421
- case PConstants.ARROW:
1422
- x = 10;
1423
- y = 7;
1424
- break;
1425
- case PConstants.HAND:
1426
- x = 12;
1427
- y = 8;
1428
- break;
1429
- case PConstants.TEXT:
1430
- x = 16;
1431
- y = 22;
1432
- break;
1433
- default:
1434
- break;
1435
- }
1436
- cursor = new CursorInfo(img, x, y);
1437
- cursors.put(kind, cursor);
1438
- }
1439
- }
1440
- if (cursor != null) {
1441
- cursor.set();
1442
- } else {
1443
- PGraphics.showWarning("Cannot load cursor type: " + kind);
1444
- }
1508
+ CursorInfo(PImage image, int x, int y) {
1509
+ this.image = image;
1510
+ this.x = x;
1511
+ this.y = y;
1445
1512
  }
1446
1513
 
1447
- @Override
1448
- public void setCursor(PImage image, int hotspotX, int hotspotY) {
1449
- Display disp = window.getScreen().getDisplay();
1450
- BufferedImage bimg = (BufferedImage) image.getNative();
1451
- DataBufferInt dbuf = (DataBufferInt) bimg.getData().getDataBuffer();
1452
- int[] ipix = dbuf.getData();
1453
- ByteBuffer pixels = ByteBuffer.allocate(ipix.length * 4);
1454
- pixels.asIntBuffer().put(ipix);
1455
- PixelFormat format = PixelFormat.ARGB8888;
1456
- final Dimension size = new Dimension(bimg.getWidth(), bimg.getHeight());
1457
- PixelRectangle pixelrect = new PixelRectangle.GenericPixelRect(format, size, 0, false, pixels);
1458
- final PointerIcon pi = disp.createPointerIcon(pixelrect, hotspotX, hotspotY);
1459
- display.getEDTUtil().invoke(false, () -> {
1460
- window.setPointerVisible(true);
1461
- window.setPointerIcon(pi);
1462
- });
1514
+ void set() {
1515
+ setCursor(image, x, y);
1463
1516
  }
1517
+ }
1518
+
1519
+ static Map<Integer, CursorInfo> cursors = new HashMap<>();
1520
+ static Map<Integer, String> cursorNames = Map.of(
1521
+ PConstants.ARROW, "arrow",
1522
+ PConstants.CROSS, "cross",
1523
+ PConstants.WAIT, "wait",
1524
+ PConstants.MOVE, "move",
1525
+ PConstants.HAND, "hand",
1526
+ PConstants.TEXT, "text"
1527
+ );
1528
+
1529
+
1530
+ // @Override
1531
+ // public void setCursor(int kind) {
1532
+ // if (!cursorNames.containsKey(kind)) {
1533
+ // PGraphics.showWarning("Unknown cursor type: " + kind);
1534
+ // return;
1535
+ // }
1536
+ // CursorInfo cursor = cursors.get(kind);
1537
+ // if (cursor == null) {
1538
+ // String name = cursorNames.get(kind);
1539
+ // if (name != null) {
1540
+ // ImageIcon icon
1541
+ // = new ImageIcon(getClass().getResource("cursors/" + name + ".png"));
1542
+ // PImage img = new PImage(icon.getImage());
1543
+ // // Most cursors just use the center as the hotspot...
1544
+ // int x = img.width / 2;
1545
+ // int y = img.height / 2;
1546
+ // // ...others are more specific
1547
+ // switch (kind) {
1548
+ // case PConstants.ARROW:
1549
+ // x = 10;
1550
+ // y = 7;
1551
+ // break;
1552
+ // case PConstants.HAND:
1553
+ // x = 12;
1554
+ // y = 8;
1555
+ // break;
1556
+ // case PConstants.TEXT:
1557
+ // x = 16;
1558
+ // y = 22;
1559
+ // break;
1560
+ // default:
1561
+ // break;
1562
+ // }
1563
+ // cursor = new CursorInfo(img, x, y);
1564
+ // cursors.put(kind, cursor);
1565
+ // }
1566
+ // }
1567
+ // if (cursor != null) {
1568
+ // cursor.set();
1569
+ // } else {
1570
+ // PGraphics.showWarning("Cannot load cursor type: " + kind);
1571
+ // }
1572
+ // }
1573
+ //
1574
+ // @Override
1575
+ // public void setCursor(PImage image, int hotspotX, int hotspotY) {
1576
+ // Display disp = window.getScreen().getDisplay();
1577
+ // BufferedImage bimg = (BufferedImage) image.getNative();
1578
+ // DataBufferInt dbuf = (DataBufferInt) bimg.getData().getDataBuffer();
1579
+ // int[] ipix = dbuf.getData();
1580
+ // ByteBuffer pixels = ByteBuffer.allocate(ipix.length * 4);
1581
+ // pixels.asIntBuffer().put(ipix);
1582
+ // PixelFormat format = PixelFormat.ARGB8888;
1583
+ // final Dimension size = new Dimension(bimg.getWidth(), bimg.getHeight());
1584
+ // PixelRectangle pixelrect = new PixelRectangle.GenericPixelRect(format, size, 0, false, pixels);
1585
+ // final PointerIcon pi = disp.createPointerIcon(pixelrect, hotspotX, hotspotY);
1586
+ // display.getEDTUtil().invoke(false, () -> {
1587
+ // window.setPointerVisible(true);
1588
+ // window.setPointerIcon(pi);
1589
+ // });
1590
+ // }
1464
1591
 
1465
- @Override
1466
- public void showCursor() {
1467
- display.getEDTUtil().invoke(false, () -> {
1468
- window.setPointerVisible(true);
1469
- });
1470
- }
1471
1592
 
1472
- @Override
1473
- public void hideCursor() {
1474
- display.getEDTUtil().invoke(false, () -> {
1475
- window.setPointerVisible(false);
1476
- });
1477
- }
1478
1593
  }