示例#1
0
 /** Draw the shape into an arbitrary PGraphics. */
 void draw(PGraphics pg) {
   if (iFrame.isEyeFrame()) return;
   if (shift != null)
     if (pg.is3D()) pg.translate(shift.x(), shift.y(), shift.z());
     else pg.translate(shift.x(), shift.y());
   // The shape part took verbatim from Processing, see:
   // https://github.com/processing/processing/blob/master/core/src/processing/core/PGraphics.java
   if (shp != null) {
     // don't do expensive matrix ops if invisible
     if (shp.isVisible() && !iFrame.isEyeFrame()) {
       pg.flush();
       if (pg.shapeMode == PApplet.CENTER) {
         pg.pushMatrix();
         pg.translate(-shp.getWidth() / 2, -shp.getHeight() / 2);
       }
       shp.draw(pg); // needs to handle recorder too
       if (pg.shapeMode == PApplet.CENTER) {
         pg.popMatrix();
       }
     }
   } else if (mth != null && obj != null) {
     try {
       mth.invoke(obj, new Object[] {pg});
     } catch (Exception e1) {
       try {
         mth.invoke(obj, new Object[] {iFrame, pg});
       } catch (Exception e2) {
         PApplet.println("Something went wrong when invoking your " + mth.getName() + " method");
       }
     }
   }
 }
示例#2
0
 /**
  * Immediate mode.
  *
  * <p>High-level routine where the {@code object} declaring the graphics procedure is explicitly
  * given.
  *
  * <p>Looks for a {@link #singleParam(Object, String)} function prototype first. If nothing is
  * hit, then looks for a {@link #doubleParam(Object, String)} function prototype, only if the
  * {@link remixlab.proscene.InteractiveFrame} instance this shape is attached to is not a {@link
  * remixlab.proscene.InteractiveFrame#isEyeFrame()}.
  */
 boolean set(Object object, String methodName) {
   if (!isSetable(object, methodName)) return false;
   boolean success = false;
   try {
     singleParam(object, methodName);
     success = true;
   } catch (Exception e1) {
     try {
       if (iFrame.isEyeFrame()) {
         System.out.println(
             "Warning: not shape set! Check the existence of one of the following method prototypes: "
                 + prototypes(object, methodName));
         return false;
       }
       doubleParam(object, methodName);
       success = true;
     } catch (Exception e2) {
       System.out.println(
           "Warning: not shape set! Check the existence of one of the following method prototypes: "
               + prototypes(object, methodName));
     }
   }
   if (success) shp = null;
   return success;
 }
示例#3
0
 /**
  * Internal use.
  *
  * @see #set(String)
  * @see #set(Object, String)
  */
 String prototypes(Object object, String action) {
   String sgn1 =
       "public void "
           + object.getClass().getSimpleName()
           + "."
           + action
           + "("
           + PGraphics.class.getSimpleName()
           + ")";
   if (!(object instanceof InteractiveFrame) && !iFrame.isEyeFrame()) {
     String sgn2 =
         "public void "
             + object.getClass().getSimpleName()
             + "."
             + action
             + "("
             + InteractiveFrame.class.getSimpleName()
             + ", "
             + PGraphics.class.getSimpleName()
             + ")";
     return sgn1 + ", " + sgn2;
   }
   return sgn1;
 }
示例#4
0
 /**
  * Defines the shape shift, i.e., the translation respect to the frame origin used to draw the
  * shape.
  */
 void shift(Vec s) {
   if (iFrame.isEyeFrame()) AbstractScene.showOnlyEyeWarning("shift", true);
   shift = s;
 }