Exemple #1
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);
  }
Exemple #2
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;
  }
 public void redrawShape() {
   setPathTo(shape);
   //		shape.setFrame(shape.getBounds2D());
   setBounds(shape.getBounds2D());
 }
    @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);
        }
      }
    }
Exemple #5
0
 public Rectangle2D getBoundingBox() throws SVGException {
   return boundsToParent(includeStrokeInBounds(rect.getBounds2D()));
 }