picrate 2.0.1-java → 2.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -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;
@@ -891,6 +895,148 @@ public class PSurfaceJOGL implements PSurface {
891
895
  });
892
896
  }
893
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
+
894
1040
  class DrawListener implements GLEventListener {
895
1041
 
896
1042
  @Override
@@ -1353,24 +1499,24 @@ public class PSurfaceJOGL implements PSurface {
1353
1499
  return def;
1354
1500
  }
1355
1501
 
1356
- // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1357
- class CursorInfo {
1358
1502
 
1359
- PImage image;
1360
- int x, y;
1361
1503
 
1362
- CursorInfo(PImage image, int x, int y) {
1363
- this.image = image;
1364
- this.x = x;
1365
- this.y = y;
1366
- }
1504
+ class CursorInfo {
1505
+ PImage image;
1506
+ int x, y;
1367
1507
 
1368
- void set() {
1369
- setCursor(image, x, y);
1370
- }
1508
+ CursorInfo(PImage image, int x, int y) {
1509
+ this.image = image;
1510
+ this.x = x;
1511
+ this.y = y;
1371
1512
  }
1372
1513
 
1373
- static Map<Integer, CursorInfo> cursors = new HashMap<>();
1514
+ void set() {
1515
+ setCursor(image, x, y);
1516
+ }
1517
+ }
1518
+
1519
+ static Map<Integer, CursorInfo> cursors = new HashMap<>();
1374
1520
  static Map<Integer, String> cursorNames = Map.of(
1375
1521
  PConstants.ARROW, "arrow",
1376
1522
  PConstants.CROSS, "cross",
@@ -1381,79 +1527,67 @@ public class PSurfaceJOGL implements PSurface {
1381
1527
  );
1382
1528
 
1383
1529
 
1384
- @Override
1385
- public void setCursor(int kind) {
1386
- if (!cursorNames.containsKey(kind)) {
1387
- PGraphics.showWarning("Unknown cursor type: " + kind);
1388
- return;
1389
- }
1390
- CursorInfo cursor = cursors.get(kind);
1391
- if (cursor == null) {
1392
- String name = cursorNames.get(kind);
1393
- if (name != null) {
1394
- ImageIcon icon
1395
- = new ImageIcon(getClass().getResource("cursors/" + name + ".png"));
1396
- PImage img = new PImage(icon.getImage());
1397
- // Most cursors just use the center as the hotspot...
1398
- int x = img.width / 2;
1399
- int y = img.height / 2;
1400
- // ...others are more specific
1401
- switch (kind) {
1402
- case PConstants.ARROW:
1403
- x = 10;
1404
- y = 7;
1405
- break;
1406
- case PConstants.HAND:
1407
- x = 12;
1408
- y = 8;
1409
- break;
1410
- case PConstants.TEXT:
1411
- x = 16;
1412
- y = 22;
1413
- break;
1414
- default:
1415
- break;
1416
- }
1417
- cursor = new CursorInfo(img, x, y);
1418
- cursors.put(kind, cursor);
1419
- }
1420
- }
1421
- if (cursor != null) {
1422
- cursor.set();
1423
- } else {
1424
- PGraphics.showWarning("Cannot load cursor type: " + kind);
1425
- }
1426
- }
1427
-
1428
- @Override
1429
- public void setCursor(PImage image, int hotspotX, int hotspotY) {
1430
- Display disp = window.getScreen().getDisplay();
1431
- BufferedImage bimg = (BufferedImage) image.getNative();
1432
- DataBufferInt dbuf = (DataBufferInt) bimg.getData().getDataBuffer();
1433
- int[] ipix = dbuf.getData();
1434
- ByteBuffer pixels = ByteBuffer.allocate(ipix.length * 4);
1435
- pixels.asIntBuffer().put(ipix);
1436
- PixelFormat format = PixelFormat.ARGB8888;
1437
- final Dimension size = new Dimension(bimg.getWidth(), bimg.getHeight());
1438
- PixelRectangle pixelrect = new PixelRectangle.GenericPixelRect(format, size, 0, false, pixels);
1439
- final PointerIcon pi = disp.createPointerIcon(pixelrect, hotspotX, hotspotY);
1440
- display.getEDTUtil().invoke(false, () -> {
1441
- window.setPointerVisible(true);
1442
- window.setPointerIcon(pi);
1443
- });
1444
- }
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
+ // }
1445
1591
 
1446
- @Override
1447
- public void showCursor() {
1448
- display.getEDTUtil().invoke(false, () -> {
1449
- window.setPointerVisible(true);
1450
- });
1451
- }
1452
1592
 
1453
- @Override
1454
- public void hideCursor() {
1455
- display.getEDTUtil().invoke(false, () -> {
1456
- window.setPointerVisible(false);
1457
- });
1458
- }
1459
1593
  }
@@ -2,12 +2,13 @@
2
2
 
3
3
  require 'fileutils'
4
4
  require 'rake/clean'
5
+ require_relative './geany'
5
6
  WARNING = 'WARNING: wget download failed you could do a manual download'
6
7
  SOUND = 'sound.zip'
7
8
  SOUND_VERSION = 'v1.3.2'
8
9
  VIDEO = 'video-2.0-beta4.zip'
9
10
  VIDEO_VERSION = 'r6-v2.0-beta4'
10
- EXAMPLES = '0.5.2'
11
+ EXAMPLES = '0.5.4'
11
12
  HOME_DIR = ENV['HOME']
12
13
  LIBRARY = File.join(HOME_DIR, '.picrate', 'libraries')
13
14
  PROJECT_DIR = File.join(HOME_DIR, 'projects')
@@ -69,9 +70,11 @@ task :install_config do
69
70
  FileUtils.mkdir_p "#{HOME_DIR}/.config/geany/templates/files"
70
71
  FileUtils.cp 'picrate.rb', "#{HOME_DIR}/.config/geany/templates/files"
71
72
  end
72
- unless File.exist? "#{HOME_DIR}/projects/sketchbook/picrate_sketches.geany"
73
- FileUtils.mkdir_p "#{HOME_DIR}/projects/sketchbook"
74
- FileUtils.cp 'picrate_sketches.geany', "#{HOME_DIR}/projects/sketchbook"
73
+ project_dir = File.join(HOME_DIR, 'projects')
74
+ unless File.exist? File.join(project_dir, 'examples', 'picrate_sketches.geany')
75
+ FileUtils.mkdir_p "#{HOME_DIR}/projects/examples"
76
+ config = GeanyConfig.new(project_dir, 'examples')
77
+ config.save(File.join(project_dir, 'examples', 'picrate_sketches.geany'))
75
78
  end
76
79
  end
77
80
 
@@ -1,3 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'erb'
4
+
5
+ def geany_config
6
+ %(
1
7
  [editor]
2
8
  line_wrapping=false
3
9
  line_break_column=72
@@ -19,7 +25,7 @@ indent_mode=2
19
25
 
20
26
  [project]
21
27
  name=picrate_samples
22
- base_path=/home/pi/projects/picrate_sketches
28
+ base_path=<%= home %>
23
29
  description=Exploring PiCrate
24
30
  file_patterns=*.rb;*.glsl;*.txt;
25
31
 
@@ -28,14 +34,9 @@ long_line_behaviour=1
28
34
  long_line_column=72
29
35
 
30
36
  [files]
31
- current_page=3
32
- FILE_NAME_0=667;Ruby;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fprojects%2Fpicrate_sketches%2Fbasics%2Farrays%2Farray.rb;0;2
33
- FILE_NAME_1=1664;Ruby;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fprojects%2Fpicrate_sketches%2Fadvanced_data%2Fload_save_json.rb;0;2
34
- FILE_NAME_2=259;Sh;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fjruby_install.sh;0;2
35
- FILE_NAME_3=236;Sh;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Ftest.sh;0;2
36
37
 
37
38
  [VTE]
38
- last_dir=/home/pi
39
+ last_dir=<%= directory %>
39
40
 
40
41
  [build-menu]
41
42
  EX_00_LB=_Execute
@@ -60,3 +61,27 @@ NF_02_WD=
60
61
  RubyFT_02_LB=_Reek
61
62
  RubyFT_02_CM=reek --failure-exit-code=0 "%f"
62
63
  RubyFT_02_WD=
64
+ )
65
+ end
66
+
67
+ # Class to merge ERB template and write config to file
68
+ class GeanyConfig
69
+ include ERB::Util
70
+ attr_accessor :home, :directory, :template
71
+
72
+ def initialize(home, directory, template = geany_config)
73
+ @home = home
74
+ @directory = File.join(home, directory)
75
+ @template = template
76
+ end
77
+
78
+ def render
79
+ ERB.new(@template).result(binding)
80
+ end
81
+
82
+ def save(file)
83
+ File.open(file, 'w+') do |f|
84
+ f.write(render)
85
+ end
86
+ end
87
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: java
6
6
  authors:
7
7
  - monkstone
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-12 00:00:00.000000000 Z
11
+ date: 2020-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -190,7 +190,7 @@ files:
190
190
  - lib/jogl-all-natives-linux-amd64.jar
191
191
  - lib/jogl-all-natives-linux-armv6hf.jar
192
192
  - lib/jogl-all.jar
193
- - lib/picrate-2.0.1.jar
193
+ - lib/picrate-2.1.0.jar
194
194
  - lib/picrate.rb
195
195
  - lib/picrate/app.rb
196
196
  - lib/picrate/creators/parameters.rb
@@ -253,8 +253,10 @@ files:
253
253
  - src/main/java/monkstone/videoevent/MovieEvent.java
254
254
  - src/main/java/monkstone/videoevent/package-info.java
255
255
  - src/main/java/processing/awt/PGraphicsJava2D.java
256
+ - src/main/java/processing/awt/PImageAWT.java
256
257
  - src/main/java/processing/awt/PShapeJava2D.java
257
258
  - src/main/java/processing/awt/PSurfaceAWT.java
259
+ - src/main/java/processing/awt/ShimAWT.java
258
260
  - src/main/java/processing/core/PApplet.java
259
261
  - src/main/java/processing/core/PConstants.java
260
262
  - src/main/java/processing/core/PFont.java
@@ -343,8 +345,8 @@ files:
343
345
  - test/test_helper.rb
344
346
  - test/vecmath_spec_test.rb
345
347
  - vendors/Rakefile
348
+ - vendors/geany.rb
346
349
  - vendors/picrate.rb
347
- - vendors/picrate_sketches.geany
348
350
  homepage: https://ruby-processing.github.io/PiCrate/
349
351
  licenses:
350
352
  - GPL-3.0