Exemplo n.º 1
0
  protected String[] getSketchParams(boolean presenting) {
    ArrayList<String> params = new ArrayList<String>();

    // It's dangerous to add your own main() to your code,
    // but if you've done it, we'll respect your right to hang yourself.
    // http://processing.org/bugs/bugzilla/1446.html
    if (build.getFoundMain()) {
      params.add(build.getSketchClassName());

    } else {
      params.add("processing.core.PApplet");

      // get the stored device index (starts at 0)
      int runDisplay = Preferences.getInteger("run.display");

      // If there was a saved location (this guy has been run more than once)
      // then the location will be set to the last position of the sketch window.
      // This will be passed to the PApplet runner using something like
      // --location=30,20
      // Otherwise, the editor location will be passed, and the applet will
      // figure out where to place itself based on the editor location.
      // --editor-location=150,20
      if (editor != null) { // if running processing-cmd, don't do placement
        GraphicsDevice editorDevice = editor.getGraphicsConfiguration().getDevice();
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] devices = ge.getScreenDevices();

        // Make sure the display set in Preferences actually exists
        GraphicsDevice runDevice = editorDevice;
        if (runDisplay >= 0 && runDisplay < devices.length) {
          runDevice = devices[runDisplay];
        } else {
          runDevice = editorDevice;
          for (int i = 0; i < devices.length; i++) {
            if (devices[i] == runDevice) {
              runDisplay = i;
              break;
              // Don't set the pref, might be a temporary thing. Users can
              // open/close Preferences to reset the device themselves.
              //              Preferences.setInteger("run.display", runDisplay);
            }
          }
        }

        Point windowLocation = editor.getSketchLocation();
        //        if (windowLocation != null) {
        //          // could check to make sure the sketch location is on the device
        //          // that's specified in Preferences, but that's going to be annoying
        //          // if you move a sketch to another window, then it keeps jumping
        //          // back to the specified window.
        ////          Rectangle screenRect =
        ////            runDevice.getDefaultConfiguration().getBounds();
        //        }
        if (windowLocation == null) {
          if (editorDevice == runDevice) {
            // If sketches are to be shown on the same display as the editor,
            // provide the editor location so the sketch's main() can place it.
            Point editorLocation = editor.getLocation();
            params.add(
                PApplet.ARGS_EDITOR_LOCATION + "=" + editorLocation.x + "," + editorLocation.y);
          } else {
            // The sketch's main() will set a location centered on the new
            // display. It has to happen in main() because the width/height
            // of the sketch are not known here.
            //             Set a location centered on the other display
            //            Rectangle screenRect =
            //              runDevice.getDefaultConfiguration().getBounds();
            //            int runX =
            //            params.add(PApplet.ARGS_LOCATION + "=" + runX + "," + runY);
          }
        } else {
          params.add(PApplet.ARGS_LOCATION + "=" + windowLocation.x + "," + windowLocation.y);
        }
        params.add(PApplet.ARGS_EXTERNAL);
      }

      params.add(PApplet.ARGS_DISPLAY + "=" + runDisplay);

      if (presenting) {
        params.add(PApplet.ARGS_FULL_SCREEN);
        //        if (Preferences.getBoolean("run.present.exclusive")) {
        //          params.add(PApplet.ARGS_EXCLUSIVE);
        //        }
        params.add(PApplet.ARGS_STOP_COLOR + "=" + Preferences.get("run.present.stop.color"));
        params.add(PApplet.ARGS_BGCOLOR + "=" + Preferences.get("run.present.bgcolor"));
      }

      params.add(build.getSketchClassName());
      params.add(PApplet.ARGS_SKETCH_FOLDER + "=" + build.getSketchPath());
      // Adding sketch path in the end coz it's likely to
      // contain spaces and things go wrong on UNIX systems.
    }

    //    String outgoing[] = new String[params.size()];
    //    params.toArray(outgoing);
    //    return outgoing;
    return params.toArray(new String[0]);
  }
Exemplo n.º 2
0
  protected String[] getSketchParams(boolean presenting) {
    ArrayList<String> params = new ArrayList<String>();

    // It's dangerous to add your own main() to your code,
    // but if you've done it, we'll respect your right to hang yourself.
    // http://processing.org/bugs/bugzilla/1446.html
    if (build.getFoundMain()) {
      params.add(build.getSketchClassName());

    } else {
      params.add("processing.core.PApplet");

      // get the stored device index (starts at 1)
      int runDisplay = Preferences.getInteger("run.display");

      // If there was a saved location (this guy has been run more than once)
      // then the location will be set to the last position of the sketch window.
      // This will be passed to the PApplet runner using something like
      // --location=30,20
      // Otherwise, the editor location will be passed, and the applet will
      // figure out where to place itself based on the editor location.
      // --editor-location=150,20
      if (editor != null) { // if running processing-cmd, don't do placement
        GraphicsDevice editorDevice = editor.getGraphicsConfiguration().getDevice();
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] devices = ge.getScreenDevices();

        // Make sure the display set in Preferences actually exists
        GraphicsDevice runDevice = editorDevice;
        if (runDisplay > 0 && runDisplay <= devices.length) {
          runDevice = devices[runDisplay - 1];
        } else {
          // If a bad display is selected, use the same display as the editor
          if (runDisplay > 0) { // don't complain about -1 or 0
            System.err.println("Display " + runDisplay + " not available.");
          }
          runDevice = editorDevice;
          for (int i = 0; i < devices.length; i++) {
            if (devices[i] == runDevice) {
              // Wasn't setting the pref to avoid screwing things up with
              // something temporary. But not setting it makes debugging one's
              // setup just too damn weird, so changing that behavior.
              runDisplay = i + 1;
              System.err.println(
                  "Setting 'Run Sketches on Display' preference to display " + runDisplay);
              Preferences.setInteger("run.display", runDisplay);
              break;
            }
          }
        }

        Point windowLocation = editor.getSketchLocation();
        //        if (windowLocation != null) {
        //          // could check to make sure the sketch location is on the device
        //          // that's specified in Preferences, but that's going to be annoying
        //          // if you move a sketch to another window, then it keeps jumping
        //          // back to the specified window.
        ////          Rectangle screenRect =
        ////            runDevice.getDefaultConfiguration().getBounds();
        //        }
        if (windowLocation == null) {
          if (editorDevice == runDevice) {
            // If sketches are to be shown on the same display as the editor,
            // provide the editor location so the sketch's main() can place it.
            Point editorLocation = editor.getLocation();
            params.add(
                PApplet.ARGS_EDITOR_LOCATION + "=" + editorLocation.x + "," + editorLocation.y);
          } else {
            // The sketch's main() will set a location centered on the new
            // display. It has to happen in main() because the width/height
            // of the sketch are not known here.
            //             Set a location centered on the other display
            //            Rectangle screenRect =
            //              runDevice.getDefaultConfiguration().getBounds();
            //            int runX =
            //            params.add(PApplet.ARGS_LOCATION + "=" + runX + "," + runY);
          }
        } else {
          params.add(PApplet.ARGS_LOCATION + "=" + windowLocation.x + "," + windowLocation.y);
        }
        params.add(PApplet.ARGS_EXTERNAL);
      }

      params.add(PApplet.ARGS_DISPLAY + "=" + runDisplay);

      if (presenting) {
        params.add(PApplet.ARGS_PRESENT);
        //        if (Preferences.getBoolean("run.present.exclusive")) {
        //          params.add(PApplet.ARGS_EXCLUSIVE);
        //        }
        params.add(PApplet.ARGS_STOP_COLOR + "=" + Preferences.get("run.present.stop.color"));
        params.add(PApplet.ARGS_WINDOW_COLOR + "=" + Preferences.get("run.present.bgcolor"));
      }

      // There was a PDE X hack that put this after the class name, but it was
      // removed for 3.0a6 because it would break the args passed to sketches.
      params.add(PApplet.ARGS_SKETCH_FOLDER + "=" + build.getSketchPath());

      params.add(build.getSketchClassName());
    }

    //    String outgoing[] = new String[params.size()];
    //    params.toArray(outgoing);
    //    return outgoing;
    return params.toArray(new String[0]);
  }