Example #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");
       }
     }
   }
 }
Example #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;
 }
Example #3
0
 /**
  * Immediate mode.
  *
  * <p>High-level routine where the object declaring the graphics procedure is not given and hence
  * need to be inferred. It could be either:
  *
  * <ol>
  *   <li>The {@link remixlab.proscene.Scene#pApplet()};
  *   <li>The {@link remixlab.proscene.InteractiveFrame} instance this shape is attached to, or;
  *   <li>The {@link remixlab.proscene.InteractiveFrame#scene()} handling that frame instance.
  * </ol>
  *
  * The algorithm looks for a {@link #singleParam(Object, String)} function prototype first. If
  * nothing is hit, then looks for a {@link #doubleParam(Object, String)} function prototype,
  * within the objects in the above order.
  */
 boolean set(String methodName) {
   boolean success = false;
   if (!isSetable(iFrame.scene().pApplet(), methodName)) return false;
   try {
     singleParam(iFrame.scene().pApplet(), methodName);
     success = true;
   } catch (Exception e1) {
     try {
       doubleParam(iFrame.scene().pApplet(), methodName);
       success = true;
     } catch (Exception e2) {
       if (!isSetable(iFrame, methodName)) return false;
       try {
         singleParam(iFrame, methodName);
         success = true;
       } catch (Exception e4) {
         if (!isSetable(iFrame.scene(), methodName)) return false;
         try {
           singleParam(iFrame.scene(), methodName);
           success = true;
         } catch (Exception e3) {
           try {
             doubleParam(iFrame.scene(), methodName);
             success = true;
           } catch (Exception e5) {
             System.out.println(
                 "Warning: not shape set! Check the existence of one of the following method prototypes: "
                     + prototypes(iFrame.scene().pApplet(), methodName)
                     + ", "
                     + prototypes(iFrame, methodName)
                     + ", "
                     + prototypes(iFrame.scene(), methodName)
                     + ". Or, if your shape lies within a different object, use setShape(Object object, String methodName) instead.");
           }
         }
       }
     }
   }
   if (success) shp = null;
   return success;
 }
Example #4
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;
 }
Example #5
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;
 }