@@ -417,6 +417,14 @@ static public class RendererChangeException extends RuntimeException { }
417
417
418
418
static final String ERROR_MIN_MAX =
419
419
"Cannot use min() or max() on an empty array." ;
420
+
421
+ boolean insideSettings ;
422
+
423
+ String renderer = JAVA2D ;
424
+
425
+ int smooth = 1 ; // default smoothing (whatever that means for the renderer)
426
+
427
+ boolean fullScreen = false ;
420
428
421
429
422
430
//////////////////////////////////////////////////////////////
@@ -448,6 +456,10 @@ public void onCreate(Bundle savedInstanceState) {
448
456
getWindowManager ().getDefaultDisplay ().getMetrics (dm );
449
457
displayWidth = dm .widthPixels ;
450
458
displayHeight = dm .heightPixels ;
459
+
460
+ //Setting the default height and width to be fullscreen
461
+ width = displayWidth ;
462
+ height = displayHeight ;
451
463
// println("density is " + dm.density);
452
464
// println("densityDpi is " + dm.densityDpi);
453
465
if (DEBUG ) println ("display metrics: " + dm );
@@ -464,6 +476,8 @@ public void onCreate(Bundle savedInstanceState) {
464
476
// RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.FILL_PARENT);
465
477
//lp.addRule(RelativeLayout.RIGHT_OF, tv1.getId());
466
478
// layout.setGravity(RelativeLayout.CENTER_IN_PARENT);
479
+
480
+ handleSettings ();
467
481
468
482
int sw = sketchWidth ();
469
483
int sh = sketchHeight ();
@@ -638,6 +652,41 @@ protected void onPause() {
638
652
//}
639
653
// surfaceView.onPause();
640
654
}
655
+
656
+
657
+ /**
658
+ * @param method "size" or "fullScreen"
659
+ * @param args parameters passed to the function so we can show the user
660
+ * @return true if safely inside the settings() method
661
+ */
662
+ boolean insideSettings (String method , Object ... args ) {
663
+ if (insideSettings ) {
664
+ return true ;
665
+ }
666
+ final String url = "https://processing.org/reference/" + method + "_.html" ;
667
+ if (!external ) { // post a warning for users of Eclipse and other IDEs
668
+ StringList argList = new StringList (args );
669
+ System .err .println ("When not using the PDE, " + method + "() can only be used inside settings()." );
670
+ System .err .println ("Remove the " + method + "() method from setup(), and add the following:" );
671
+ System .err .println ("public void settings() {" );
672
+ System .err .println (" " + method + "(" + argList .join (", " ) + ");" );
673
+ System .err .println ("}" );
674
+ }
675
+ throw new IllegalStateException (method + "() cannot be used here, see " + url );
676
+ }
677
+
678
+
679
+ void handleSettings () {
680
+ insideSettings = true ;
681
+ //Do stuff
682
+ settings ();
683
+ insideSettings = false ;
684
+ }
685
+
686
+
687
+ public void settings () {
688
+ //It'll be empty. Will be overridden by user's sketch class.
689
+ }
641
690
642
691
643
692
/**
@@ -1040,17 +1089,23 @@ public int sketchQuality() {
1040
1089
1041
1090
1042
1091
public int sketchWidth () {
1043
- return displayWidth ;
1092
+ if (fullScreen ) {
1093
+ return displayWidth ;
1094
+ }
1095
+ return width ;
1044
1096
}
1045
1097
1046
1098
1047
1099
public int sketchHeight () {
1048
- return displayHeight ;
1100
+ if (fullScreen ) {
1101
+ return displayHeight ;
1102
+ }
1103
+ return height ;
1049
1104
}
1050
1105
1051
1106
1052
1107
public String sketchRenderer () {
1053
- return JAVA2D ;
1108
+ return renderer ;
1054
1109
}
1055
1110
1056
1111
@@ -1465,6 +1520,54 @@ public void draw() {
1465
1520
// layout.invalidate();
1466
1521
// }
1467
1522
// }
1523
+
1524
+
1525
+ /**
1526
+ * Create a full-screen sketch using the default renderer.
1527
+ */
1528
+ public void fullScreen () {
1529
+ if (!fullScreen ) {
1530
+ if (insideSettings ("fullScreen" )) {
1531
+ this .fullScreen = true ;
1532
+ }
1533
+ }
1534
+ }
1535
+
1536
+
1537
+ public void fullScreen (int display ) {
1538
+ //Display index doesn't make sense in Android.
1539
+ //Should we throw some error in log ?
1540
+ if (!fullScreen /*|| display != this.display*/ ) {
1541
+ if (insideSettings ("fullScreen" , display )) {
1542
+ this .fullScreen = true ;
1543
+ // this.display = display;
1544
+ }
1545
+ }
1546
+ }
1547
+
1548
+
1549
+ public void fullScreen (String renderer ) {
1550
+ if (!fullScreen ||
1551
+ !renderer .equals (this .renderer )) {
1552
+ if (insideSettings ("fullScreen" , renderer )) {
1553
+ this .fullScreen = true ;
1554
+ this .renderer = renderer ;
1555
+ }
1556
+ }
1557
+ }
1558
+
1559
+
1560
+ public void fullScreen (String renderer , int display ) {
1561
+ if (!fullScreen ||
1562
+ !renderer .equals (this .renderer ) /*||
1563
+ display != this.display*/ ) {
1564
+ if (insideSettings ("fullScreen" , renderer , display )) {
1565
+ this .fullScreen = true ;
1566
+ this .renderer = renderer ;
1567
+ // this.display = display;
1568
+ }
1569
+ }
1570
+ }
1468
1571
1469
1572
1470
1573
/**
@@ -1477,12 +1580,24 @@ public void draw() {
1477
1580
* previous renderer and simply resize it.
1478
1581
*/
1479
1582
public void size (int iwidth , int iheight ) {
1480
- size (iwidth , iheight , P2D , null );
1583
+ if (iwidth != this .width || iheight != this .height ) {
1584
+ if (insideSettings ("size" , iwidth , iheight )) {
1585
+ this .width = iwidth ;
1586
+ this .height = iheight ;
1587
+ }
1588
+ }
1481
1589
}
1482
1590
1483
1591
1484
1592
public void size (int iwidth , int iheight , String irenderer ) {
1485
- size (iwidth , iheight , irenderer , null );
1593
+ if (iwidth != this .width || iheight != this .height ||
1594
+ !this .renderer .equals (irenderer )) {
1595
+ if (insideSettings ("size" , iwidth , iheight , irenderer )) {
1596
+ this .width = iwidth ;
1597
+ this .height = iheight ;
1598
+ this .renderer = irenderer ;
1599
+ }
1600
+ }
1486
1601
}
1487
1602
1488
1603
@@ -1519,82 +1634,15 @@ public void renderer(String name) {
1519
1634
*/
1520
1635
public void size (final int iwidth , final int iheight ,
1521
1636
final String irenderer , final String ipath ) {
1522
- System .out .println ("This size() method is ignored on Android." );
1523
- System .out .println ("See http://wiki.processing.org/w/Android for more information." );
1524
-
1525
- /*
1526
- // Looper.prepare();
1527
- // Run this from the EDT, just cuz it's AWT stuff (or maybe later Swing)
1528
- // new Handler().post(new Runnable() {
1529
- handler.post(new Runnable() {
1530
- public void run() {
1531
- println("Handler is on thread " + Thread.currentThread().getName());
1532
- // // Set the preferred size so that the layout managers can handle it
1533
- //// setPreferredSize(new Dimension(iwidth, iheight));
1534
- //// setSize(iwidth, iheight);
1535
- // g.setSize(iwidth, iheight);
1536
- // }
1537
- // });
1538
-
1539
- // ensure that this is an absolute path
1540
- // if (ipath != null) ipath = savePath(ipath);
1541
- // no path renderers supported yet
1542
-
1543
- println("I'm the ole thread " + Thread.currentThread().getName());
1544
- String currentRenderer = g.getClass().getName();
1545
- if (currentRenderer.equals(irenderer)) {
1546
- println("resizing renderer inside size(....)");
1547
- // Avoid infinite loop of throwing exception to reset renderer
1548
- resizeRenderer(iwidth, iheight);
1549
- //redraw(); // will only be called insize draw()
1550
-
1551
- } else { // renderer is being changed
1552
- println("changing renderer inside size(....)");
1553
-
1554
- // otherwise ok to fall through and create renderer below
1555
- // the renderer is changing, so need to create a new object
1556
- // g = makeGraphics(iwidth, iheight, irenderer, ipath, true);
1557
- // width = iwidth;
1558
- // height = iheight;
1559
- // if ()
1560
-
1561
- // Remove the old view from the layout
1562
- layout.removeView(surfaceView);
1563
-
1564
- if (irenderer.equals(A2D)) {
1565
- surfaceView = new SketchSurfaceView2D(PApplet.this, iwidth, iheight);
1566
- } else if (irenderer.equals(A3D)) {
1567
- surfaceView = new SketchSurfaceView3D(PApplet.this, iwidth, iheight);
1637
+ if (iwidth != this .width || iheight != this .height ||
1638
+ !this .renderer .equals (irenderer )) {
1639
+ if (insideSettings ("size" , iwidth , iheight , irenderer ,
1640
+ ipath )) {
1641
+ this .width = iwidth ;
1642
+ this .height = iheight ;
1643
+ this .renderer = irenderer ;
1568
1644
}
1569
- g = ((SketchSurfaceView) surfaceView).getGraphics();
1570
-
1571
- // these don't seem like a good idea
1572
- // width = screenWidth;
1573
- // height = screenHeight;
1574
-
1575
- // println("getting window");
1576
- // Window window = getWindow();
1577
- // window.setContentView(surfaceView); // set full screen
1578
- // layout.removeAllViews();
1579
- layout.addView(surfaceView);
1580
-
1581
- // fire resize event to make sure the applet is the proper size
1582
- // setSize(iwidth, iheight);
1583
- // this is the function that will run if the user does their own
1584
- // size() command inside setup, so set defaultSize to false.
1585
- // defaultSize = false;
1586
-
1587
- // throw an exception so that setup() is called again
1588
- // but with a properly sized render
1589
- // this is for opengl, which needs a valid, properly sized
1590
- // display before calling anything inside setup().
1591
- // throw new RendererChangeException();
1592
- println("interrupting animation thread");
1593
- thread.interrupt();
1594
1645
}
1595
- }
1596
- });
1597
- */
1598
1646
}
1599
1647
1600
1648
0 commit comments