/**
  * Splits a bar into subregions (elsewhere, these subregions will have different gradients applied
  * to them).
  *
  * @param bar the bar shape.
  * @param a the first division.
  * @param b the second division.
  * @param c the third division.
  * @return An array containing four subregions.
  */
 private Rectangle2D[] splitHorizontalBar(RectangularShape bar, double a, double b, double c) {
   Rectangle2D[] result = new Rectangle2D[4];
   double y0 = bar.getMinY();
   double y1 = Math.rint(y0 + (bar.getHeight() * a));
   double y2 = Math.rint(y0 + (bar.getHeight() * b));
   double y3 = Math.rint(y0 + (bar.getHeight() * c));
   result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), bar.getWidth(), y1 - y0);
   result[1] = new Rectangle2D.Double(bar.getMinX(), y1, bar.getWidth(), y2 - y1);
   result[2] = new Rectangle2D.Double(bar.getMinX(), y2, bar.getWidth(), y3 - y2);
   result[3] = new Rectangle2D.Double(bar.getMinX(), y3, bar.getWidth(), bar.getMaxY() - y3);
   return result;
 }
 private void zoom(final Zoomable dst, final Point2D center, final double ratio, final int dt) {
   if (dst == null) return;
   final RectangularShape src = dst.getZoom();
   final double w = src.getWidth() * ratio;
   final double h = src.getHeight() * ratio;
   final double cx, cy;
   if (center == null) {
     cx = src.getCenterX();
     cy = src.getCenterY();
   } else {
     cx = center.getX();
     cy = center.getY();
   }
   zoom(dst, new Rectangle2D.Double(cx - w / 2, cy - h / 2, Math.abs(w), Math.abs(h)), dt);
 }
Beispiel #3
0
  void renderer(Graphics2D g2d) {
    height = window.getHeight() - 20;
    width = window.getWidth();

    lastTime = curTime;
    curTime = System.currentTimeMillis();
    totalTime += curTime - lastTime;
    if (totalTime > 1000) {
      totalTime -= 1000;
      fps = frames;
      frames = 0;
    }
    ++frames;

    delta = 16.0 / (curTime - lastTime);
    if (delta < 0) delta = 0;

    g2d.setColor(Color.white);
    if (removeMode) g2d.fill(new Rectangle(0, 0, width, height));

    if (eventHandeler(g2d)) {
      renderBackground(g2d);
      return;
    }

    Graphics2D map = (Graphics2D) g2d.create();
    playerHandeler();
    xOffset = -player.body.getCenterX() + width / 2;
    yOffset = -player.body.getCenterY() + height / 2;

    if (-xOffset < bounds.getBounds2D().getX()) xOffset = -bounds.getBounds2D().getX();
    else if (-xOffset > bounds.getBounds2D().getMaxX() - width)
      xOffset = -bounds.getBounds2D().getMaxX() + width;

    if (-yOffset < bounds.getBounds2D().getY()) yOffset = -bounds.getBounds2D().getY();
    else if (-yOffset > bounds.getBounds2D().getMaxY() - height + 3)
      yOffset = -bounds.getBounds2D().getMaxY() + height - 3;

    map.translate(xOffset, yOffset);

    renderBackground(map);
    itemHandeler(map);
    enemieHandeler();
    characterHandeler(map);

    map.setColor(Color.black);
    map.draw(bounds);

    renderUI(g2d);
  }
  @Override
  public Transition2DInstruction[] getInstructions(float progress, Dimension size) {
    if (type == OUT) {
      progress = 1 - progress;
    }
    progress = (float) Math.pow(progress, .5);

    float ySize = (size.height) * .05f;
    float xSize = (size.width) * .05f;
    Vector<RectangularShape> v = new Vector<RectangularShape>();
    float angleProgress = (float) Math.pow(1 - Math.min(progress, 1), .5);
    // pop it over 1:
    float progressZ = 1.3f * progress;
    double w = xSize * progressZ;
    double h = ySize * progressZ;
    float min = (float) (Math.min(w, h));
    for (float y = 0; y < size.height; y += ySize) {
      for (float x = 0; x < size.width; x += xSize) {
        v.add(
            new RoundRectangle2D.Double(
                x + xSize / 2 - w / 2,
                y + ySize / 2 - h / 2,
                w * progress + (1 - progress) * min,
                h * progress + (1 - progress) * min,
                w * angleProgress * progress + (1 - progress) * min * angleProgress,
                h * angleProgress * progress + (1 - progress) * min * angleProgress));
      }
    }
    ImageInstruction[] instr = new ImageInstruction[v.size() + 1];
    instr[0] = new ImageInstruction(false);
    for (int a = 0; a < v.size(); a++) {
      float progress2 = progress; // (float)Math.pow(progress, .9+.2*random.nextFloat());
      RectangularShape r = v.get(a);
      Point2D p1 = new Point2D.Double(r.getCenterX(), r.getCenterY());
      Point2D p2 = new Point2D.Double(r.getCenterX(), r.getCenterY());
      AffineTransform transform = new AffineTransform();
      transform.translate(r.getCenterX(), r.getCenterY());
      transform.scale(30 * (1 - progress) + 1, 30 * (1 - progress) + 1);
      transform.translate(-r.getCenterX(), -r.getCenterY());

      transform.rotate(.3 * (1 - progress2), size.width / 3, size.height / 2);

      transform.transform(p1, p2);
      transform.setToTranslation(p1.getX() - p2.getX(), p1.getY() - p2.getY());
      Shape shape = transform.createTransformedShape(r);
      instr[a + 1] = new ImageInstruction(true, transform, shape);
    }
    if (type == IN) {
      for (int a = 0; a < instr.length; a++) {
        instr[a].isFirstFrame = !instr[a].isFirstFrame;
      }
    }

    return instr;
  }
Beispiel #5
0
  double[] checkIfInsideBounds(Item target) {
    double[] targetFixInsideBounds = new double[2];
    targetFixInsideBounds[0] = target.body.getX();
    targetFixInsideBounds[1] = target.body.getY();
    if (target.body.getX() < bounds.getBounds2D().getX())
      targetFixInsideBounds[0] = bounds.getBounds2D().getX();
    else if (target.body.getX() > bounds.getBounds2D().getMaxX() - target.body.getWidth())
      targetFixInsideBounds[0] = bounds.getBounds2D().getMaxX() - target.body.getWidth();

    if (target.body.getY() < bounds.getBounds2D().getY())
      targetFixInsideBounds[1] = bounds.getBounds2D().getY();
    else if (target.body.getY() > bounds.getBounds2D().getMaxY() - target.body.getHeight())
      targetFixInsideBounds[1] = bounds.getBounds2D().getMaxY() - target.body.getHeight();
    return targetFixInsideBounds;
  }
 private void pan(final Zoomable dst, final double rx, final double ry, final int dt) {
   if (dst == null) return;
   final RectangularShape src = dst.getZoom();
   zoom(
       dst,
       new Rectangle2D.Double(
           src.getX() + src.getWidth() * rx,
           src.getY() + src.getHeight() * ry,
           src.getWidth(),
           src.getHeight()),
       dt);
 }
 /**
  * Creates a shadow for the bar.
  *
  * @param bar the bar shape.
  * @param xOffset the x-offset for the shadow.
  * @param yOffset the y-offset for the shadow.
  * @param base the edge that is the base of the bar.
  * @param pegShadow peg the shadow to the base?
  * @return A rectangle for the shadow.
  */
 private Rectangle2D createShadow(
     RectangularShape bar, double xOffset, double yOffset, RectangleEdge base, boolean pegShadow) {
   double x0 = bar.getMinX();
   double x1 = bar.getMaxX();
   double y0 = bar.getMinY();
   double y1 = bar.getMaxY();
   if (base == RectangleEdge.TOP) {
     x0 += xOffset;
     x1 += xOffset;
     if (!pegShadow) {
       y0 += yOffset;
     }
     y1 += yOffset;
   } else if (base == RectangleEdge.BOTTOM) {
     x0 += xOffset;
     x1 += xOffset;
     y0 += yOffset;
     if (!pegShadow) {
       y1 += yOffset;
     }
   } else if (base == RectangleEdge.LEFT) {
     if (!pegShadow) {
       x0 += xOffset;
     }
     x1 += xOffset;
     y0 += yOffset;
     y1 += yOffset;
   } else if (base == RectangleEdge.RIGHT) {
     x0 += xOffset;
     if (!pegShadow) {
       x1 += xOffset;
     }
     y0 += yOffset;
     y1 += yOffset;
   }
   return new Rectangle2D.Double(x0, y0, (x1 - x0), (y1 - y0));
 }
Beispiel #8
0
  @Override
  public void init() {
    //////// BUTTONS
    cmng = new ComponentManager();

    for (int i = 0; i < BUTTONS_NAME.length; i++) {
      String name = BUTTONS_NAME[i];
      final SButton button =
          SButton.getCenterButtonWithGap(
              name,
              Experiment.WIDTH,
              Experiment.HEIGHT,
              BUTTONS_WIDTH,
              BUTTONS_HEIGHT,
              BUTTONS_PLUS_X,
              i * BUTTONS_HEIGHT + BUTTONS_PLUS_Y,
              Color.YELLOW,
              Type.GHOSTRY);
      final RectangularShape shape = button.getShape();
      cmng.addComponent(StringUtils.deleteWhitespace(name).toLowerCase(), button);

      marksButton[i] = new Point((int) (shape.getMinX() - BUTTONS_HEIGHT), (int) (shape.getMinY()));
    }
  }
Beispiel #9
0
 boolean render(Graphics2D map) {
   double diff = (System.nanoTime() - created) / 1000 / 1000;
   if (diff > timeAlive) return true;
   map.setColor(new Color(100, 100, 100, (int) (255 - (diff / timeAlive * 250))));
   for (int i = 0; i < particles.length; i++) {
     RectangularShape tmp = (RectangularShape) particles[i][0];
     double xD = (Double) particles[i][1];
     double yD = (Double) particles[i][2];
     tmp.setFrame(
         (double) tmp.getX() + xD / delta,
         (double) tmp.getY() + yD / delta,
         tmp.getWidth(),
         tmp.getHeight());
     map.draw(tmp);
   }
   return false;
 }
 public void redrawShape() {
   setPathTo(shape);
   //		shape.setFrame(shape.getBounds2D());
   setBounds(shape.getBounds2D());
 }
 /**
  * Splits a bar into subregions (elsewhere, these subregions will have different gradients applied
  * to them).
  *
  * @param bar the bar shape.
  * @param a the first division.
  * @param b the second division.
  * @param c the third division.
  * @return An array containing four subregions.
  */
 private Rectangle2D[] splitVerticalBar(RectangularShape bar, double a, double b, double c) {
   Rectangle2D[] result = new Rectangle2D[4];
   double x0 = bar.getMinX();
   double x1 = Math.rint(x0 + (bar.getWidth() * a));
   double x2 = Math.rint(x0 + (bar.getWidth() * b));
   double x3 = Math.rint(x0 + (bar.getWidth() * c));
   result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), x1 - x0, bar.getHeight());
   result[1] = new Rectangle2D.Double(x1, bar.getMinY(), x2 - x1, bar.getHeight());
   result[2] = new Rectangle2D.Double(x2, bar.getMinY(), x3 - x2, bar.getHeight());
   result[3] = new Rectangle2D.Double(x3, bar.getMinY(), bar.getMaxX() - x3, bar.getHeight());
   return result;
 }
    @Override
    public void render(Graphics2D g, VisualItem item) {

      if (item.isVisible()) {
        item.setShape(Constants.SHAPE_RECTANGLE);
        RectangularShape shape = (RectangularShape) getShape(item);
        if (shape != null) {

          shape
              .getBounds2D()
              .setRect(
                  (double) item.get(VisualItem.X),
                  (double) item.get(VisualItem.Y),
                  item.getSize(),
                  item.getSize());

          // draw basic glyph
          Color strokeColor = ColorLib.getColor(item.getStrokeColor());
          Color fillColor = ColorLib.getColor(item.getFillColor());

          //                    int size = (int)item.getSize();
          int x = (int) item.getX() + bufferPx;
          int y = (int) item.getY() + bufferPx;
          int w = (int) item.getDouble(WIDTH) - 2 * bufferPx;
          int h = (int) item.getDouble(HEIGHT) - 2 * bufferPx;
          g.setPaint(fillColor);
          g.fillRect(x, y, w, h);

          // draw string on-top of glyph, filling the glyph's area

          //                    String s = "doc=" + item.getString(NODE_NAME) + "\n";
          String s = "";

          // set text: full document if no search term, else excerpts containing the search term
          String queryStr = searchQ.getSearchSet().getQuery();
          String focusText = item.getString(DocumentGridTable.NODE_FOCUS_TEXT);
          if (queryStr != null
              && !queryStr.isEmpty()
              && focusText != null
              && !focusText.equals("null")
              && !focusText.equals("")) {
            // if search query and terms present in document, use term-containing spans
            s += focusText;
          } else if (queryStr != null
              && !queryStr.isEmpty()
              && focusText.equals(FOCUS_SENT_SPLITTER)) {
            // if search query but no terms present in document, use blank
            s += "";
          } else if ((queryStr == null || queryStr.isEmpty()) && item.canGetInt(NODE_ID)) {
            // if no search query, build feature-oriented summary based on color attribute
            s = controller.getDocumentSummary(item.getInt(NODE_ID), colorAttrName);
          }

          // TODO : idea: set font size dynamically based on number of active nodes? based on size
          // of rect?
          int fontSize = 10;

          item.setFont(FontLib.getFont("Tahoma", Font.PLAIN, fontSize));

          Font f = item.getFont();

          // compute width, height for the given text
          // NOTE: this logic has been moved into drawStringMultiline
          //                    int[] textDims = getTextDims(g, f, s);

          // debug
          //                    System.out.println("debug: "+this.getClass().getName()+":
          // drawStringMultiline at x="+x1+", y="+y1+", w="+w+", h="+h);
          drawStringMultiline(g, f, s, x, y, w, h);
        }
      }
    }
Beispiel #13
0
 public Rectangle2D getBoundingBox() throws SVGException {
   return boundsToParent(includeStrokeInBounds(rect.getBounds2D()));
 }
Beispiel #14
0
  void generateBackground(int size) {
    backgroundWidth = 100;
    int spacing = backgroundWidth;
    int id = 0;
    for (int i = 0; i < bounds.getWidth() / spacing; i++) {
      background[id][0] = spacing * (i + 1) - bounds.getWidth() / 2;
      background[id][1] = -bounds.getHeight() / 2;
      background[id][2] = spacing * (i + 1) - bounds.getWidth() / 2;
      background[id][3] = 0;
      background[id][4] = spacing * (i + 1) - bounds.getWidth() / 2;
      background[id][5] = bounds.getHeight();

      background[id][6] = rand.nextInt(3) - 1;
      background[id][7] = rand.nextInt(3) - 1;
      background[id][8] = 1;
      id++;
    }
    for (int i = 0; i < bounds.getHeight() / spacing; i++) {
      background[id][0] = -bounds.getHeight() / 2;
      background[id][1] = spacing * (i + 1) - bounds.getHeight() / 2;
      background[id][2] = 0;
      background[id][3] = spacing * (i + 1) - bounds.getWidth() / 2;
      background[id][4] = bounds.getWidth();
      background[id][5] = spacing * (i + 1) - bounds.getHeight() / 2;

      background[id][6] = rand.nextInt(3) - 1;
      background[id][7] = rand.nextInt(3) - 1;
      background[id][8] = 1;
      id++;
    }
  }