public void checarColisoes() {
    Rectangle formaNave = nave.getBounds();
    Rectangle formaInimigo;
    Rectangle formaMissel;

    for (int i = 0; i < inimigos.size(); i++) {

      Inimigo tempInimigo = inimigos.get(i);
      formaInimigo = tempInimigo.getBounds();

      if (formaNave.intersects(formaInimigo)) {
        nave.setVisivel(false);
        tempInimigo.setVisible(false);
        emJogo = false;
      }
    }

    List<Missel> misseis = nave.getMisseis();

    for (int i = 0; i < misseis.size(); i++) {
      Missel tempMissel = misseis.get(i);
      formaMissel = tempMissel.getBounds();

      for (int j = 0; j < inimigos.size(); j++) {
        Inimigo tempInimigo = inimigos.get(j);
        formaInimigo = tempInimigo.getBounds();

        if (formaMissel.intersects(formaInimigo)) {
          tempInimigo.setVisible(false);
          tempMissel.setVisible(false);
        }
      }
    }
  }
示例#2
0
  public void mousePressed(java.awt.event.MouseEvent e) {
    if (e.isPopupTrigger()) {
      doPopup(e);
      return;
    }
    if (!org.nlogo.awt.Mouse.hasButton1(e)) {
      return;
    }

    // this is so the user can use action keys to control buttons
    // - ST 8/6/04,8/31/04
    this.requestFocus();

    java.awt.Point p = e.getPoint();
    java.awt.Rectangle rect = this.getBounds();

    p.x += rect.x;
    p.y += rect.y;

    if (!rect.contains(p)) {
      return;
    }
    unselectWidgets();
    startDragPoint = e.getPoint();
    if (widgetCreator == null) {
      return;
    }
    Widget widget = widgetCreator.getWidget();
    if (widget == null) {
      return;
    }
    addWidget(widget, e.getX(), e.getY(), true, false);
    revalidate();
  }
 @Override
 protected RelativePoint getPointToShowResults() {
   Rectangle rect = myEntryTable.getCellRect(myEntryTable.getSelectedRow(), 1, false);
   Point location = rect.getLocation();
   location.y += rect.height;
   return new RelativePoint(myEntryTable, location);
 }
示例#4
0
 private int countAttackableElixirs(
     final List<RegionMatch> doFindAll, final List<Rectangle> matchedElixirs, final Path next) {
   int attackableElixirs = 0;
   int c = 0;
   RECT_LOOP:
   for (final RegionMatch i : doFindAll) {
     // if matched area is out of enemy poly
     if (!ENEMY_BASE_POLY.contains(i.x, i.y)) {
       continue;
     }
     // check if it's an existing match
     for (final Rectangle r : matchedElixirs) {
       if (r.intersects(i.getBounds())) {
         break RECT_LOOP;
       }
     }
     c++;
     matchedElixirs.add(i.getBounds());
     if (next.getFileName().toString().startsWith("empty")) {
       attackableElixirs--;
     } else if (next.getFileName().toString().startsWith("full")) {
       attackableElixirs++;
     }
     logger.finest("\t" + i.getBounds() + " score: " + i.getScore());
   }
   if (c > 0) {
     logger.finest(
         String.format("\tfound %d elixirs matching %s\n", c, next.getFileName().toString()));
   }
   return attackableElixirs;
 }
示例#5
0
  /**
   * Paint to an offscreen graphic, e.g. a graphic for an image or svg file.
   *
   * @param g
   * @param rect
   */
  public void paintOffscreen(Graphics2D g, Rectangle rect) {

    // Get the components of the sort by X position.
    Component[] components = getComponents();
    Arrays.sort(
        components,
        new Comparator<Component>() {
          public int compare(Component component, Component component1) {
            return component.getX() - component1.getX();
          }
        });

    for (Component c : this.getComponents()) {

      if (c instanceof DataPanel) {
        Graphics2D g2d = (Graphics2D) g.create();
        Rectangle clipRect = new Rectangle(c.getBounds());
        clipRect.height = rect.height;
        g2d.setClip(clipRect);
        g2d.translate(c.getX(), 0);
        ((DataPanel) c).paintOffscreen(g2d, rect);
      }
    }
    // super.paintBorder(g);
  }
  private static int preferredWidth(JTable table, int col) {
    TableColumn tableColumn = table.getColumnModel().getColumn(col);
    int width =
        (int)
            table
                .getTableHeader()
                .getDefaultRenderer()
                .getTableCellRendererComponent(
                    table, tableColumn.getIdentifier(), false, false, -1, col)
                .getPreferredSize()
                .getWidth();

    if (table.getRowCount() != 0) {
      int from = 0, to = 0;
      Rectangle rect = table.getVisibleRect();
      from = table.rowAtPoint(rect.getLocation());
      to = table.rowAtPoint(new Point((int) rect.getMaxX(), (int) rect.getMaxY())) + 1;

      for (int row = from; row < to; row++) {
        int preferedWidth =
            (int)
                table
                    .getCellRenderer(row, col)
                    .getTableCellRendererComponent(
                        table, table.getValueAt(row, col), false, false, row, col)
                    .getPreferredSize()
                    .getWidth();
        width = Math.max(width, preferedWidth);
      }
    }
    return width + table.getIntercellSpacing().width;
  }
示例#7
0
  public TabSpawnable spawn() {
    JFrame f = new JFrame();
    f.getContentPane().setLayout(new BorderLayout());
    f.setTitle(_title);
    TabSpawnable newPanel = (TabSpawnable) clone();
    if (newPanel == null) return null; // failed to clone
    newPanel.setTitle(_title);
    if (newPanel instanceof TabToDoTarget) {
      TabToDoTarget me = (TabToDoTarget) this;
      TabToDoTarget it = (TabToDoTarget) newPanel;
      it.setTarget(me.getTarget());
    } else if (newPanel instanceof TabModelTarget) {
      TabModelTarget me = (TabModelTarget) this;
      TabModelTarget it = (TabModelTarget) newPanel;
      it.setTarget(me.getTarget());
    }
    f.getContentPane().add(newPanel, BorderLayout.CENTER);
    Rectangle bounds = getBounds();
    bounds.height += OVERLAPP * 2;
    f.setBounds(bounds);

    Point loc = new Point(0, 0);
    SwingUtilities.convertPointToScreen(loc, this);
    loc.y -= OVERLAPP;
    f.setLocation(loc);
    f.setVisible(true);

    if (_tear && (getParent() instanceof JTabbedPane)) ((JTabbedPane) getParent()).remove(this);

    return newPanel;
  }
示例#8
0
  public void paint(Graphics2D g, ChartFrame cf, Rectangle bounds) {
    Dataset ls = visibleDataset(cf, LS);

    if (ls != null) {
      Range range = cf.getSplitPanel().getChartPanel().getRange();

      g.setColor(properties.getColor());
      g.setStroke(properties.getStroke());

      double y = cf.getChartData().getY(range.getLowerBound(), bounds, range, false);
      g.draw(new Line2D.Double(bounds.getMinX(), y, bounds.getMaxX(), y));

      for (int i = 0; i < ls.getItemsCount(); i++) {
        if (ls.getDataItem(i) != null) {
          double x = cf.getChartData().getX(i, bounds);
          double y1 = cf.getChartData().getY(range.getLowerBound(), bounds, range, false);
          double y2 = cf.getChartData().getY(range.getUpperBound(), bounds, range, false);
          double w = cf.getChartProperties().getBarWidth();

          g.draw(new Line2D.Double(x - w / 2, y1, x, y2));
          g.draw(new Line2D.Double(x + w / 2, y1, x, y2));
        }
      }
    }
  }
  /** Scroll the current visible area to the rectangle where the saved {@link #jumpNode} lays. */
  void jumpToNodeVisible() {
    if (this.jumpNode == null) {
      return;
    }

    // get the Component nodes to evaluate the positions
    // on the viewport
    SmallStepNodeComponent node = (SmallStepNodeComponent) this.jumpNode.getUserObject();
    if (node == null) {
      return;
    }

    // get the visible rect to ensure the x coordinate is in the
    // visible area. only vertical scolling is requested
    Rectangle visibleRect = this.getVisibleRect();

    Rectangle rect = new Rectangle();
    rect.x = visibleRect.x;
    rect.y = node.getY();
    rect.width = 1;
    rect.height = node.getHeight();

    this.scrollRectToVisible(rect);

    this.jumpNode = null;
  }
示例#10
0
  /**
   * Get the horizontal drop line rectangle.
   *
   * @param loc the drop location.
   * @return the rectangle.
   */
  private Rectangle getHDropLineRect(JTable.DropLocation loc) {
    if (!loc.isInsertRow()) {
      return null;
    }

    int row = loc.getRow();
    int col = loc.getColumn();

    if (col >= table.getColumnCount()) {
      col--;
    }

    Rectangle rect = table.getCellRect(row, col, true);

    if (row >= table.getRowCount()) {
      row--;
      Rectangle prevRect = table.getCellRect(row, col, true);

      rect.y = prevRect.y + prevRect.height;
    }

    if (rect.y == 0) {
      rect.y = -1;
    } else {
      rect.y -= 2;
    }

    rect.height = 3;

    return rect;
  }
示例#11
0
 /* (non-Javadoc)
  * @see org.xamjwg.html.renderer.BoundableRenderable#onMouseReleased(java.awt.event.MouseEvent, int, int)
  */
 public void onMouseReleased(MouseEvent event, int x, int y) {
   Iterator i = this.blocks.iterator();
   boolean found = false;
   while (i.hasNext()) {
     Object r = i.next();
     if (r instanceof BoundableRenderable) {
       BoundableRenderable br = (BoundableRenderable) r;
       Rectangle bounds = br.getBounds();
       if (bounds.contains(x, y)) {
         found = true;
         br.onMouseReleased(event, x - bounds.x, y - bounds.y);
         BoundableRenderable oldArmedRenderable = this.armedRenderable;
         if (oldArmedRenderable != null && br != oldArmedRenderable) {
           oldArmedRenderable.onMouseDisarmed(event);
           this.armedRenderable = null;
         }
       }
     }
   }
   if (!found) {
     BoundableRenderable oldArmedRenderable = this.armedRenderable;
     if (oldArmedRenderable != null) {
       oldArmedRenderable.onMouseDisarmed(event);
       this.armedRenderable = null;
     }
   }
 }
示例#12
0
  private static void showOnScreen(int screen, JFrame frame, boolean fullscreen) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gd = ge.getScreenDevices();
    if (!Main.protection || (screen > -1 && screen < gd.length)) {
      if (!Main.protection || (fullscreen && screen == Main.secondScreen)) {
        // frame.setSize(gd[screen].getDefaultConfiguration().getBounds().x,gd[screen].getDefaultConfiguration().getBounds().y);
        gd[screen].setFullScreenWindow(frame);
      } else {
        frame.setSize(600, 300);
        Rectangle bound = gd[screen].getDefaultConfiguration().getBounds();
        System.out.println(
            "x: "
                + bound.x
                + " y: "
                + bound.y
                + " width: "
                + bound.width
                + " height : "
                + bound.height);
        frame.setLocation((int) (bound.x + bound.getWidth() / 2 - 300), frame.getY());
      }

      return;
    }
    System.out.println("Erreur : l'ecran " + screen + " n'a pas ete trouve");
  }
 public static boolean isPointNearPoint(Point from, Point testPos, int nearTolerance) {
   Rectangle r1 =
       new Rectangle(
           from.x - nearTolerance / 2, from.y - nearTolerance / 2, nearTolerance, nearTolerance);
   Rectangle r2 = new Rectangle(testPos.x, testPos.y, 1, 1);
   return r2.intersects(r1);
 }
示例#14
0
  /**
   * Process this text Token to optimize tokens and evaluate the token bounding box.
   *
   * @param g Graphics to get the font metrics.
   * @param text Text to add to the current textTokan.
   * @param textTok Current TextToken.
   * @param isText True if the previous textToken was a Text Token so we can merge it with this.
   */
  private void updateText(Graphics g, String text, TextToken textTok, boolean isText) {
    // The text exists!
    if (text.length() > 0) {
      FontMetrics fm = g.getFontMetrics();
      int a = fm.getAscent(), d = fm.getDescent(), w = fm.stringWidth(text), h = fm.getHeight();

      // The previous token was a text too so we must merge it with this new one.
      if (isText) {
        textTok = (TextToken) m_tokens.lastElement();

        textTok.m_text += text;
        textTok.m_bounds.width += w;
        if (textTok.m_bounds.height < h) textTok.m_bounds.height = h;
      }
      // The previous token was a formating one.
      else {
        m_tokens.addElement(textTok);

        textTok.m_text = text;
        textTok.m_bounds = new Rectangle(0, 0, w, h);
      }

      if (a > m_body.m_aMax) m_body.m_aMax = a;
      if (d > m_body.m_dMax) m_body.m_dMax = d;

      m_wCur += w;
    }
  }
示例#15
0
 /**
  * Makes the given rectangle slightly larger. The given rectangle is modified and also returned.
  *
  * @param r A Rectangle to be enlarged.
  * @return The same Rectangle, after enlargement.
  */
 private static Rectangle enlarge(Rectangle r) {
   r.x -= 2;
   r.y -= 2;
   r.width += 4;
   r.height += 4;
   return r;
 }
示例#16
0
 private void ensureRectIsInBounds(final Rectangle rectangle, final Dimension bounds) {
   if (rectangle.x < 0) {
     rectangle.x = 0;
   }
   if (rectangle.x + rectangle.width > bounds.width) {
     final JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
     final int scrollBarWidth;
     if (verticalScrollBar != null) {
       scrollBarWidth = verticalScrollBar.getWidth();
     } else {
       scrollBarWidth = 0;
     }
     rectangle.x = bounds.width - rectangle.width - scrollBarWidth;
   }
   if (rectangle.y < 0) {
     rectangle.y = 0;
   }
   if (rectangle.y + rectangle.height > bounds.height) {
     final JScrollBar horizontalScrollBar = scrollPane.getHorizontalScrollBar();
     final int scrollBarHeight;
     if (horizontalScrollBar != null) {
       scrollBarHeight = horizontalScrollBar.getHeight();
     } else {
       scrollBarHeight = 0;
     }
     rectangle.y = bounds.height - rectangle.height - scrollBarHeight;
   }
 }
  private void drawSelection(Graphics2D g2d) {
    if (srcx != destx || srcy != desty) {
      int x1 = (srcx < destx) ? srcx : destx;
      int y1 = (srcy < desty) ? srcy : desty;
      int x2 = (srcx > destx) ? srcx : destx;
      int y2 = (srcy > desty) ? srcy : desty;

      rectSelection.x = x1;
      rectSelection.y = y1;
      rectSelection.width = (x2 - x1) + 1;
      rectSelection.height = (y2 - y1) + 1;
      if (rectSelection.width > 0 && rectSelection.height > 0) {
        g2d.drawImage(scr_img.getSubimage(x1, y1, x2 - x1 + 1, y2 - y1 + 1), null, x1, y1);
      }

      g2d.setColor(selFrameColor);
      g2d.setStroke(bs);
      g2d.draw(rectSelection);
      int cx = (x1 + x2) / 2;
      int cy = (y1 + y2) / 2;
      g2d.setColor(selCrossColor);
      g2d.setStroke(_StrokeCross);
      g2d.drawLine(cx, y1, cx, y2);
      g2d.drawLine(x1, cy, x2, cy);

      if (Screen.getNumberScreens() > 1) {
        drawScreenFrame(g2d, srcScreenId);
      }
    }
  }
示例#18
0
 private static void setCenter(final Rectangle rectangle, final Point center) {
   final int diffX = center.x - (int) rectangle.getCenterX();
   final int diffY = center.y - (int) rectangle.getCenterY();
   final int x = ((int) rectangle.getX()) + diffX;
   final int y = (int) (rectangle.getY() + diffY);
   rectangle.setLocation(x, y);
 }
 @Override
 public boolean isContainedInSelection(Rectangle drawingViewSelection, double scale) {
   FGERectangle drawingViewBounds =
       new FGERectangle(
           drawingViewSelection.getX(),
           drawingViewSelection.getY(),
           drawingViewSelection.getWidth(),
           drawingViewSelection.getHeight(),
           Filling.FILLED);
   boolean isFullyContained = true;
   for (ControlArea<?> ca : getConnector().getControlAreas()) {
     if (ca instanceof ControlPoint) {
       ControlPoint cp = (ControlPoint) ca;
       Point cpInContainerView =
           convertLocalNormalizedPointToRemoteViewCoordinates(
               cp.getPoint(), getDrawingGraphicalRepresentation(), scale);
       FGEPoint preciseCPInContainerView = new FGEPoint(cpInContainerView.x, cpInContainerView.y);
       if (!drawingViewBounds.containsPoint(preciseCPInContainerView)) {
         // System.out.println("Going outside: point="+preciseCPInContainerView+"
         // bounds="+containerViewBounds);
         isFullyContained = false;
       }
     }
   }
   return isFullyContained;
 }
示例#20
0
  /**
   * Ecrit le nom de l'element.
   *
   * @param g graphics
   * @param vueElement vue de l'element a dessiner
   * @param coordX abscisse de l'element
   * @param coordY ordonnee de l'element
   * @return vrai si le texte a ete ecrit en dessous de la forme representant l'element, faux sinon
   */
  private boolean dessineElementNom(Graphics g, VueElement<?> vueElement, int coordX, int coordY) {
    Rectangle rect = this.getBounds();

    // affiche au dessus du point ses informations
    String s = vueElement.getElement().getNom();
    int stringWidth = (int) g.getFontMetrics().getStringBounds(s, g).getWidth();
    int stringHeight = (int) g.getFontMetrics().getStringBounds(s, g).getHeight();
    int start = (stringWidth / 2) - (ELEMENT_SIZE / 2);

    // gestion du debordement des infos
    int coordXString = Math.max(coordX - start, 2);

    if (coordXString + stringWidth > rect.getWidth()) {
      coordXString = (int) (rect.getWidth() - 2 - stringWidth);
    }

    int coordYString = coordY - 10;
    boolean descendu = false;

    if (coordY < stringHeight) {
      coordYString = coordY + 29;
      descendu = true;
    }

    g.drawString(s, coordXString, coordYString);

    return descendu;
  }
示例#21
0
 @Override
 public void run(Component c) {
   final Rectangle r = c.getBounds();
   r.width -= 64;
   r.height -= 64;
   c.setBounds(r);
 }
 public void paintSelection(Graphics g, int rowMin, int rowMax, int colMin, int colMax) {
   for (int row = rowMin; row <= rowMax; row++) {
     for (int column = colMin; column <= colMax; column++) {
       if (!grid.isCellSpan(row, column)) {
         Rectangle cellBounds = grid.getCellBounds(row, column);
         if (grid.getSelectionModel().isSelected(row, column)) {
           g.setColor(Color.RED);
           g.drawRect(
               (int) cellBounds.getX() + 1,
               (int) cellBounds.getY() + 1,
               (int) cellBounds.getWidth() - 2,
               (int) cellBounds.getHeight() - 2);
         }
       } else {
         CellSpan span = grid.getSpanModel().getSpanOver(row, column);
         if (grid.getSelectionModel().isSelected(span.getRow(), span.getColumn())) {
           g.setColor(Color.RED);
           Rectangle cellBounds = grid.getCellBounds(span.getFirstRow(), span.getLastColumn());
           g.drawRect(
               (int) cellBounds.getX() + 1,
               (int) cellBounds.getY() + 1,
               (int) cellBounds.getWidth() - 2,
               (int) cellBounds.getHeight() - 2);
         }
       }
     }
   }
 }
示例#23
0
  @Test
  public void drawWithClipAndTransform() throws Exception {
    graphics.setPaint(Color.BLACK);
    graphics.fill(imageBounds);

    AffineTransform tr =
        AffineTransform.getRotateInstance(
            Math.PI / 4,
            image.getMinX() + image.getWidth() / 2,
            image.getMinY() + image.getHeight() / 2);

    graphics.transform(tr);
    graphics.clip(midRect);

    graphics.setPaint(Color.RED);
    graphics.fill(imageBounds);

    showImage("drawWithClipAndTransform");

    // Outside transformed clip region
    Rectangle outer = new Rectangle(midRect);
    outer.grow(5, 5);
    Point2D[] corners = getCorners(outer);
    Point2D[] trPoints = new Point2D[corners.length];
    tr.transform(corners, 0, trPoints, 0, corners.length);
    assertColor(Color.BLACK, trPoints);

    // Inside transformed clip region
    Rectangle inner = new Rectangle(midRect);
    inner.grow(-5, -5);
    corners = getCorners(inner);
    tr.transform(corners, 0, trPoints, 0, corners.length);
    assertColor(Color.RED, trPoints);
  }
  @Override
  public void showFeedback() {
    createFeedback();

    myBounds =
        myContext.getTransformedRectangle(
            myComponent.getBounds(myContext.getArea().getFeedbackLayer()));
    myBounds.width = Math.max(myBounds.width, 0);
    myBounds.height = Math.max(myBounds.height, 0);

    int direction = myContext.getResizeDirection();

    if ((direction & Position.EAST) != 0) {
      if (!snapToWidth(myBounds, myWrapSize, SNAP_DELTA)) {
        snapToWidth(myBounds, myFillSize, SNAP_DELTA);
      }
    }
    if ((direction & Position.SOUTH) != 0) {
      if (!snapToHeight(myBounds, myWrapSize, SNAP_DELTA)) {
        snapToHeight(myBounds, myFillSize, SNAP_DELTA);
      }
    }

    myFeedback.setBounds(myBounds);

    myTextFeedback.clear();

    addTextSize(myStaticWidth, myBounds.width, myWrapSize.width, myFillSize.width);
    myTextFeedback.append(" x ", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
    addTextSize(myStaticHeight, myBounds.height, myWrapSize.height, myFillSize.height);

    myTextFeedback.locationTo(myContext.getLocation(), 15);
  }
示例#25
0
  protected java.awt.Point restrictDrag(java.awt.Point p, WidgetWrapper w) {
    int x = p.x;
    int y = p.y;
    java.awt.Rectangle wb = w.originalBounds;
    java.awt.Rectangle b = getBounds();
    java.awt.Rectangle newWb = new java.awt.Rectangle(wb.x + x, wb.y + y, wb.width, wb.height);
    if (workspace.snapOn() && !this.isZoomed()) {
      int xGridSnap = newWb.x - (newWb.x / GRID_SNAP) * GRID_SNAP;
      int yGridSnap = newWb.y - (newWb.y / GRID_SNAP) * GRID_SNAP;
      x -= xGridSnap;
      y -= yGridSnap;
      newWb.x -= xGridSnap;
      newWb.y -= yGridSnap;
    }

    if (newWb.x + newWb.width < WidgetWrapper.BORDER_E * 2) {
      x += WidgetWrapper.BORDER_E * 2 - (newWb.x + newWb.width);
    }
    if (newWb.y < WidgetWrapper.BORDER_N) {
      y += WidgetWrapper.BORDER_N - newWb.y;
    }
    if (newWb.x + 2 * WidgetWrapper.BORDER_W > b.width) {
      x -= (newWb.x + 2 * WidgetWrapper.BORDER_W) - b.width;
    }
    if (newWb.y + WidgetWrapper.BORDER_N > b.height) {
      y -= (newWb.y + WidgetWrapper.BORDER_N) - b.height;
    }

    return new java.awt.Point(x, y);
  }
示例#26
0
 /**
  * Renders using the given rendering surface and area on that surface.
  *
  * @param g the rendering surface to use
  * @param allocation the allocated region to render into
  * @see View#paint
  */
 public void paint(Graphics g, Shape allocation) {
   super.paint(g, allocation);
   Rectangle alloc = allocation.getBounds();
   Rectangle clip = g.getClipBounds();
   // Since listPainter paints in the insets we have to check for the
   // case where the child is not painted because the paint region is
   // to the left of the child. This assumes the ListPainter paints in
   // the left margin.
   if ((clip.x + clip.width) < (alloc.x + getLeftInset())) {
     Rectangle childRect = alloc;
     alloc = getInsideAllocation(allocation);
     int n = getViewCount();
     int endY = clip.y + clip.height;
     for (int i = 0; i < n; i++) {
       childRect.setBounds(alloc);
       childAllocation(i, childRect);
       if (childRect.y < endY) {
         if ((childRect.y + childRect.height) >= clip.y) {
           listPainter.paint(
               g, childRect.x, childRect.y, childRect.width, childRect.height, this, i);
         }
       } else {
         break;
       }
     }
   }
 }
  public void setRect(int dx, int dy, Raster srcRaster) {
    Rectangle targetUnclipped =
        new Rectangle(
            srcRaster.getMinX() + dx,
            srcRaster.getMinY() + dy,
            srcRaster.getWidth(),
            srcRaster.getHeight());

    Rectangle target = getBounds().intersection(targetUnclipped);

    if (target.isEmpty()) return;

    int sx = target.x - dx;
    int sy = target.y - dy;

    // FIXME: Do tests on rasters and use get/set data instead.

    /* The JDK documentation seems to imply this implementation.
    (the trucation of higher bits), but an implementation using
    get/setDataElements would be more efficient. None of the
    implementations would do anything sensible when the sample
    models don't match.

    But this is probably not the place to consider such
    optimizations.*/

    int[] pixels = srcRaster.getPixels(sx, sy, target.width, target.height, (int[]) null);

    setPixels(target.x, target.y, target.width, target.height, pixels);
  }
示例#28
0
 private Rectangle getBounds(FigureEnumeration fe) {
   Rectangle r = fe.nextFigure().displayBox();
   while (fe.hasNextFigure()) {
     r.add(fe.nextFigure().displayBox());
   }
   return r;
 }
示例#29
0
  /**
   * See TextObject's getLocalBoundingPolygon() description for details.
   *
   * <p>Do not modify the returned Polygon, because it may be cached.
   *
   * <p>XXXBUG: This method always returns a rectangle unless we write some convex hull
   * calculations.
   *
   * @return A bounding polygon; the polygon could be empty if the group has no glyph descendants.
   * @see net.nexttext.TextObject#getLocalBoundingPolygon()
   */
  public synchronized Polygon getLocalBoundingPolygon() {

    if (localBoundingPolygonValidToFrame >= getFrameCount()) {
      return localBoundingPolygon;
    }
    localBoundingPolygonValidToFrame = Long.MAX_VALUE;

    TextObject to = getLeftMostChild();

    // if to has no children and is a group, then return an empty polygon
    if (to == null) {
      localBoundingPolygon = new Polygon();
      return localBoundingPolygon;
    }

    Rectangle bounds = to.getRelativeBoundingPolygon().getBounds();

    while ((to = to.getRightSibling()) != null) {
      bounds.add(to.getRelativeBoundingPolygon().getBounds());
    }

    // Return the box as a polygon object

    int[] x = new int[] {bounds.x, bounds.x + bounds.width, bounds.x + bounds.width, bounds.x};
    int[] y = new int[] {bounds.y, bounds.y, bounds.y + bounds.height, bounds.y + bounds.height};

    localBoundingPolygon = new Polygon(x, y, 4);
    return localBoundingPolygon;
  }
示例#30
0
  public boolean wallCollision(Bullet bullet) {
    Rectangle boundingBox = bullet.getBoundingBox();
    int tile;
    int tileWidth = tileMap.getTileWidth();
    int tileHeight = tileMap.getTileHeight();

    /*
     * nested four loop only is grabbing the 4 corners of the
     * bullet's hit box and checking the type of tiles that they
     * contact. The current bullets range from 8x8 to 17x17, so they
     * all can contact the same range of tiles at any given time:
     * 1-4 A bullet expires on contact with a solid object(besides
     * ring bullets)
     */

    for (int y = bullet.yPos;
        y <= bullet.yPos + boundingBox.getHeight();
        y += boundingBox.getHeight()) {
      for (int x = bullet.xPos;
          x <= bullet.xPos + boundingBox.getWidth();
          x += boundingBox.getWidth()) {
        int tileCoordX = (int) (x + distanceScrolled) / tileWidth;
        int tileCoordY = y / tileHeight;

        tile = tileMap.getTile(((tileCoordY) * tileMap.getTileMapWidth()) + (tileCoordX));
        if (tile < 17 || 23 < tile) {
          return true;
        }
      }
    }
    return false;
  }