コード例 #1
0
  protected Rectangle checkBounds(Rectangle source, Rectangle target) {
    if (target.contains(source)) return new Rectangle(target);
    else {
      Rectangle trimmedSource = new Rectangle(source);
      // is source outter target left
      if (trimmedSource.x < target.x) {
        trimmedSource.x = target.x;
        if (trimmedSource.width > target.width) trimmedSource.width = target.width;
      }
      // is source outter target top
      if (trimmedSource.y < target.y) {
        trimmedSource.y = target.y;
        if (trimmedSource.height > target.height) trimmedSource.height = target.height;
      }
      // is source outter target right
      if (trimmedSource.getMaxX() > target.getMaxX()) {
        trimmedSource.x = (int) target.getMaxX() - trimmedSource.width;
        //				if (trimmedSource.width > target.width)
        //					trimmedSource.width = target.width;
      }
      // is source outter target bottom
      if (trimmedSource.getMaxY() > target.getMaxY()) {
        trimmedSource.y = (int) target.getMaxY() - trimmedSource.height;
        //				if (trimmedSource.height > target.height)
        //					trimmedSource.height = target.height;
      }

      return trimmedSource;
    }
  }
コード例 #2
0
 /**
  * Creates the map's bounding box in real world coordinates.
  *
  * @param worldToScreen a transform which converts World coordinates to screen pixel coordinates.
  *     No assumptions are done on axis order as this is assumed to be pre-calculated. The affine
  *     transform may specify an rotation, in case the envelope will encompass the complete
  *     (rotated) world polygon.
  * @param paintArea the size of the rendering output area
  * @return the envelope in world coordinates corresponding to the screen rectangle.
  */
 public static Envelope createMapEnvelope(Rectangle paintArea, AffineTransform worldToScreen)
     throws NoninvertibleTransformException {
   //
   // (X1,Y1) (X2,Y1)
   //
   // (X1,Y2) (X2,Y2)
   double[] pts = new double[8];
   pts[0] = paintArea.getMinX();
   pts[1] = paintArea.getMinY();
   pts[2] = paintArea.getMaxX();
   pts[3] = paintArea.getMinY();
   pts[4] = paintArea.getMaxX();
   pts[5] = paintArea.getMaxY();
   pts[6] = paintArea.getMinX();
   pts[7] = paintArea.getMaxY();
   worldToScreen.inverseTransform(pts, 0, pts, 0, 4);
   double xMin = Double.MAX_VALUE;
   double yMin = Double.MAX_VALUE;
   double xMax = -Double.MAX_VALUE;
   double yMax = -Double.MAX_VALUE;
   for (int i = 0; i < 4; i++) {
     xMin = Math.min(xMin, pts[2 * i]);
     yMin = Math.min(yMin, pts[2 * i + 1]);
     xMax = Math.max(xMax, pts[2 * i]);
     yMax = Math.max(yMax, pts[2 * i + 1]);
   }
   return new Envelope(xMin, xMax, yMin, yMax);
 }
コード例 #3
0
ファイル: JpdlModelDrawer.java プロジェクト: junzero/XMXM
	/**
	 * 获得图片的矩形大小
	 * 
	 * @return
	 */
	private Rectangle getCanvasDimension(JpdlModel jpdlModel) {
		Rectangle rectangle = new Rectangle();
		Rectangle rect;
		for (Node node : jpdlModel.getNodes().values()) {
			rect = node.getRectangle();
			if (rect.getMaxX() > rectangle.getMaxX()) {
				rectangle.width = (int) rect.getMaxX();
			}
			if (rect.getMaxY() > rectangle.getMaxY()) {
				rectangle.height = (int) rect.getMaxY();
			}
			for (Transition transition : node.getTransitions()) {
				List<Point> trace = transition.getLineTrace();
				for (Point point : trace) {
					if (rectangle.getMaxX() < point.x) {
						rectangle.width = point.x;
					}
					if (rectangle.getMaxY() < point.y) {
						rectangle.height = point.y;
					}
				}
			}
		}
		rectangle.width += 60;
		rectangle.height += 20;
		return rectangle;
	}
コード例 #4
0
  /**
   * Clears the area of the tile on the graphics
   *
   * @param graphics graphics to draw onto
   * @param style raster symbolizer
   * @throws FactoryException
   * @throws TransformException
   * @throws RenderException
   */
  private void renderBlankTile(Graphics2D graphics, WMTTile tile, WMTRenderJob renderJob)
      throws Exception {

    if (tile == null) {
      return;
    }

    // get the bounds of the tile and convert to necessary viewport projection
    Envelope bnds = renderJob.projectTileToMapCrs(tile.getExtent());

    // determine screen coordinates of tiles
    Point upperLeft = getContext().worldToPixel(new Coordinate(bnds.getMinX(), bnds.getMinY()));
    Point bottomRight = getContext().worldToPixel(new Coordinate(bnds.getMaxX(), bnds.getMaxY()));
    Rectangle tileSize = new Rectangle(upperLeft);
    tileSize.add(bottomRight);

    // render
    try {
      graphics.setBackground(new Color(255, 255, 255, 0)); // set the tile transparent for now
      graphics.clearRect(tileSize.x, tileSize.y, tileSize.width, tileSize.height);

      if (TESTING) {
        /* for testing draw border around tiles */
        graphics.setColor(Color.BLACK);
        graphics.drawLine(
            (int) tileSize.getMinX(),
            (int) tileSize.getMinY(),
            (int) tileSize.getMinX(),
            (int) tileSize.getMaxY());
        graphics.drawLine(
            (int) tileSize.getMinX(),
            (int) tileSize.getMinY(),
            (int) tileSize.getMaxX(),
            (int) tileSize.getMinY());
        graphics.drawLine(
            (int) tileSize.getMaxX(),
            (int) tileSize.getMinY(),
            (int) tileSize.getMaxX(),
            (int) tileSize.getMaxY());
        graphics.drawLine(
            (int) tileSize.getMinX(),
            (int) tileSize.getMaxY(),
            (int) tileSize.getMaxX(),
            (int) tileSize.getMaxY());
      }
    } catch (Throwable t) {
      WMTPlugin.log("Error Rendering Blank tile. Painting Tile: " + tile.getId(), t); // $NON-NLS-1$
    }
  }
コード例 #5
0
  public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
    int cellSize = world.getCellSize();
    double scrollPos = 0;
    if (orientation == SwingConstants.HORIZONTAL) {
      // scrolling left
      if (direction < 0) {
        scrollPos = visibleRect.getMinX();

      }
      // scrolling right
      else if (direction > 0) {
        scrollPos = visibleRect.getMaxX();
      }
    } else {
      // scrolling up
      if (direction < 0) {
        scrollPos = visibleRect.getMinY();
      }
      // scrolling down
      else if (direction > 0) {
        scrollPos = visibleRect.getMaxY();
      }
    }
    int increment = Math.abs((int) Math.IEEEremainder(scrollPos, cellSize));
    if (increment == 0) {
      increment = cellSize;
    }

    return increment;
  }
コード例 #6
0
  protected void checkScale(Rectangle newReal) {
    int maxRealX = (int) newReal.getMaxX();
    int maxRealY = (int) newReal.getMaxY();
    int maxViewX = (int) initViewBounds.getMaxX();
    int maxViewY = (int) initViewBounds.getMaxY();
    int maxX = Math.max(maxRealX, maxViewX);
    int maxY = Math.max(maxRealY, maxViewY);
    realBounds = new Rectangle(0, 0, maxX, maxY);
    //		realBounds = new Rectangle(newReal.x, newReal.y, maxX, maxY);

    if (debugBounds) {
      logger.debug("viewBounds = " + viewBounds); // $NON-NLS-1$
      logger.debug("realBounds = " + realBounds); // $NON-NLS-1$
      logger.debug("initViewBounds = " + initViewBounds); // $NON-NLS-1$
    }
  }
コード例 #7
0
  @Override
  public void refreshContainer() {
    if (!this.isMaximum()) {
      int height = this.getHeight();
      int pos = this.scrollPane.getVerticalScrollBar().getValue();

      this.validate();
      this.pack();

      // this.setMaximumSize(this.getPreferredSize());

      Rectangle bounds = this.getBounds();
      bounds.height = height;
      bounds.width += 32;

      int x2 =
          (int)
              Math.min(
                  bounds.getMaxX(),
                  this.getEditorInterface().getDesktopPane().getBounds().getMaxX());
      int y2 =
          (int)
              Math.min(
                  bounds.getMaxY(),
                  this.getEditorInterface().getDesktopPane().getBounds().getMaxY());

      bounds.setFrameFromDiagonal(bounds.x, bounds.y, x2, y2);

      this.setBounds(bounds);
      this.scrollPane.getVerticalScrollBar().setValue(pos);
    }
  }
コード例 #8
0
  // Draws the ShopMenu
  private void renderShopMenu(Graphics g, Graphics2D g2) {
    renderMenuUI(g, g2, "Shop");

    // Draws gridpane
    int centerX = (int) menuUI.getCenterX();
    int maxX = (int) menuUI.getMaxX();
    int maxY = (int) menuUI.getMaxY();
    int startY = menuUI.y + menuUI.height / 5;
    g2.drawLine(centerX, startY, centerX, maxY);
    g2.drawLine(menuUI.x, startY, maxX, startY);

    // 6*4
    for (int i = 0; i < 6; i++) {
      for (int k = 0; k < 4; k++) {
        g2.drawRect(
            menuUI.x + (menuGrid.width * i),
            startY + (menuGrid.height * k),
            menuGrid.width,
            menuGrid.height);
        drawItems(
            g2,
            menuUI.x + (menuGrid.width * i),
            startY + (menuGrid.height * k),
            menuGrid.width,
            menuGrid.height);
      }
    }

    // display cash
    g.setFont(fntSmall);
    g.drawString("Cash: 1005$", maxX - 2 * menuGrid.width, maxY - menuGrid.height / 3);
  }
コード例 #9
0
  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;
  }
コード例 #10
0
  private Rectangle getLoadedTilesBounds(Rectangle loadedImagePart, Dimension tileSize) {
    int x1 = (int) Math.floor(loadedImagePart.getX() / tileSize.getWidth());
    int y1 = (int) Math.floor(loadedImagePart.getY() / tileSize.getHeight());
    int x2 = (int) Math.ceil((loadedImagePart.getMaxX()) / tileSize.getWidth());
    int y2 = (int) Math.ceil((loadedImagePart.getMaxY()) / tileSize.getHeight());

    return new Rectangle(x1, y1, x2 - x1, y2 - y1);
  }
コード例 #11
0
ファイル: Tiling.java プロジェクト: gvtools/gvtools-legacy
  public Tiling(int tileW, int tileH, Rectangle r) {
    int[] size = this.calcMaxTileSize(tileW, tileH, r);
    tileMaxWidth = size[0];
    tileMaxHeight = size[1];

    int stepX, stepY;
    int xProv, yProv;
    int altoAux, anchoAux;

    // Vamos a hacerlo en trozos de AxH
    numCols = 1 + (int) (r.width) / tileMaxWidth;
    numRows = 1 + (int) (r.height) / tileMaxHeight;

    srcPts = new double[numCols * numRows][8];
    tile = new Rectangle[numCols * numRows];

    yProv = (int) r.y;
    for (stepY = 0; stepY < numRows; stepY++) {
      if ((yProv + tileMaxHeight) > r.getMaxY()) altoAux = (int) r.getMaxY() - yProv;
      else altoAux = tileMaxHeight;

      xProv = (int) r.x;
      for (stepX = 0; stepX < numCols; stepX++) {
        if ((xProv + tileMaxWidth) > r.getMaxX()) anchoAux = (int) r.getMaxX() - xProv;
        else anchoAux = tileMaxWidth;

        // Rectangle newRect = new Rectangle(xProv, yProv, anchoAux,
        // altoAux);
        int tileCnt = stepY * numCols + stepX;
        // Parte que dibuja
        srcPts[tileCnt][0] = xProv;
        srcPts[tileCnt][1] = yProv;
        srcPts[tileCnt][2] = xProv + anchoAux + 1;
        srcPts[tileCnt][3] = yProv;
        srcPts[tileCnt][4] = xProv + anchoAux + 1;
        srcPts[tileCnt][5] = yProv + altoAux + 1;
        srcPts[tileCnt][6] = xProv;
        srcPts[tileCnt][7] = yProv + altoAux + 1;

        tile[tileCnt] = new Rectangle(xProv, yProv, anchoAux + 1, altoAux + 1);

        xProv += tileMaxWidth;
      }
      yProv += tileMaxHeight;
    }
  }
コード例 #12
0
  @Override
  public void mouseMoved(MouseEvent e) {

    if (this.selecting) {
      this.disable();
      if (e.getX() > selected.getMaxX() - 5
          && e.getX() < selected.getMaxX() + 5
          && e.getY() > selected.getMaxY() - 5
          && e.getY() < selected.getMaxY() + 5) {
        e.getComponent().setCursor(new Cursor(Cursor.SE_RESIZE_CURSOR));
        curDir = DIR_SE;

      } else if (e.getX() == selected.getMinX()
          && (e.getY() < selected.getMaxY() && e.getY() > selected.getMinY())) {
        e.getComponent().setCursor(new Cursor(Cursor.W_RESIZE_CURSOR));
        curDir = DIR_W;
      } else if (e.getX() == selected.getMaxX()
          && (e.getY() < selected.getMaxY() && e.getY() > selected.getMinY())) {
        e.getComponent().setCursor(new Cursor(Cursor.E_RESIZE_CURSOR));
        curDir = DIR_E;
      } else if (e.getY() < selected.getMaxY() + 5
          && e.getY() > selected.getMaxY() - 5
          && (e.getX() < selected.getMaxX() && e.getX() > selected.getMinX())) {
        e.getComponent().setCursor(new Cursor(Cursor.S_RESIZE_CURSOR));
        curDir = DIR_S;
      } else if (e.getY() == selected.getMinY()
          && (e.getX() < selected.getMaxX() && e.getX() > selected.getMinX())) {
        curDir = DIR_N;
        e.getComponent().setCursor(new Cursor(Cursor.N_RESIZE_CURSOR));
      } else if (e.getY() < selected.getCenterY() + 10
          && e.getY() > selected.getCenterY() - 10
          && (e.getX() < (selected.getCenterX() + 10) && e.getX() > selected.getCenterX() - 10)) {
        e.getComponent().setCursor(new Cursor(Cursor.MOVE_CURSOR));
        this.enable();

        curDir = NOP;
      } else {
        e.getComponent().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        curDir = NOP;
      }
    } else {
      e.getComponent().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
      curDir = NOP;
    }
  }
コード例 #13
0
  /**
   * Constructor creates an instance to be used for fill operations.
   *
   * @param shading the shading type to be used
   * @param colorModel the color model to be used
   * @param xform transformation for user to device space
   * @param matrix the pattern matrix concatenated with that of the parent content stream
   * @param deviceBounds the bounds of the area to paint, in device units
   * @throws IOException if there is an error getting the color space or doing color conversion.
   */
  public AxialShadingContext(
      PDShadingType2 shading,
      ColorModel colorModel,
      AffineTransform xform,
      Matrix matrix,
      Rectangle deviceBounds)
      throws IOException {
    super(shading, colorModel, xform, matrix);
    this.axialShadingType = shading;
    coords = shading.getCoords().toFloatArray();

    // domain values
    if (shading.getDomain() != null) {
      domain = shading.getDomain().toFloatArray();
    } else {
      // set default values
      domain = new float[] {0, 1};
    }
    // extend values
    COSArray extendValues = shading.getExtend();
    if (shading.getExtend() != null) {
      extend = new boolean[2];
      extend[0] = ((COSBoolean) extendValues.get(0)).getValue();
      extend[1] = ((COSBoolean) extendValues.get(1)).getValue();
    } else {
      // set default values
      extend = new boolean[] {false, false};
    }
    // calculate some constants to be used in getRaster
    x1x0 = coords[2] - coords[0];
    y1y0 = coords[3] - coords[1];
    d1d0 = domain[1] - domain[0];
    denom = Math.pow(x1x0, 2) + Math.pow(y1y0, 2);

    try {
      // get inverse transform to be independent of current user / device space
      // when handling actual pixels in getRaster()
      rat = matrix.createAffineTransform().createInverse();
      rat.concatenate(xform.createInverse());
    } catch (NoninvertibleTransformException ex) {
      LOG.error(ex, ex);
    }

    // shading space -> device space
    AffineTransform shadingToDevice = (AffineTransform) xform.clone();
    shadingToDevice.concatenate(matrix.createAffineTransform());

    // worst case for the number of steps is opposite diagonal corners, so use that
    double dist =
        Math.sqrt(
            Math.pow(deviceBounds.getMaxX() - deviceBounds.getMinX(), 2)
                + Math.pow(deviceBounds.getMaxY() - deviceBounds.getMinY(), 2));
    factor = (int) Math.ceil(dist);

    // build the color table for the given number of steps
    colorTable = calcColorTable();
  }
コード例 #14
0
  /**
   * Compute the bounding screen extent of a rotated rectangle.
   *
   * @param rect Rectangle to rotate.
   * @param x X coordinate of the rotation point.
   * @param y Y coordinate of the rotation point.
   * @param rotation Rotation angle.
   * @return The smallest rectangle that completely contains {@code rect} when rotated by the
   *     specified angle.
   */
  protected Rectangle computeRotatedScreenExtent(Rectangle rect, int x, int y, Angle rotation) {
    Rectangle r = new Rectangle(rect);

    // Translate the rectangle to the rotation point.
    r.translate(-x, -y);

    // Compute corner points
    Vec4[] corners = {
      new Vec4(r.getMaxX(), r.getMaxY()),
      new Vec4(r.getMaxX(), r.getMinY()),
      new Vec4(r.getMinX(), r.getMaxY()),
      new Vec4(r.getMinX(), r.getMinY())
    };

    // Rotate the rectangle
    Matrix rotationMatrix = Matrix.fromRotationZ(rotation);
    for (int i = 0; i < corners.length; i++) {
      corners[i] = corners[i].transformBy3(rotationMatrix);
    }

    // Find the bounding rectangle of rotated points.
    int minX = Integer.MAX_VALUE;
    int minY = Integer.MAX_VALUE;
    int maxX = -Integer.MAX_VALUE;
    int maxY = -Integer.MAX_VALUE;

    for (Vec4 v : corners) {
      if (v.x > maxX) maxX = (int) v.x;

      if (v.x < minX) minX = (int) v.x;

      if (v.y > maxY) maxY = (int) v.y;

      if (v.y < minY) minY = (int) v.y;
    }

    // Set bounds and translate the rectangle back to where it started.
    r.setBounds(minX, minY, maxX - minX, maxY - minY);
    r.translate(x, y);

    return r;
  }
コード例 #15
0
ファイル: GridPanel.java プロジェクト: firesage123/Thor
  /**
   * Moves the current location by a given amount.
   *
   * @param dr the number of rows by which to move the location
   * @param dc the number of columns by which to move the location
   */
  public void moveLocation(int dr, int dc) {
    Location newLocation =
        new Location(currentLocation.getRow() + dr, currentLocation.getCol() + dc);
    if (!grid.isValid(newLocation)) return;

    currentLocation = newLocation;

    JViewport viewPort = getEnclosingViewport();
    if (isPannableUnbounded()) {
      if (originRow > currentLocation.getRow()) originRow = currentLocation.getRow();
      if (originCol > currentLocation.getCol()) originCol = currentLocation.getCol();
      Dimension dim = viewPort.getSize();
      int rows = dim.height / (cellSize + 1);
      int cols = dim.width / (cellSize + 1);
      if (originRow + rows - 1 < currentLocation.getRow())
        originRow = currentLocation.getRow() - rows + 1;
      if (originCol + rows - 1 < currentLocation.getCol())
        originCol = currentLocation.getCol() - cols + 1;
    } else if (viewPort != null) {
      int dx = 0;
      int dy = 0;
      Point p = pointForLocation(currentLocation);
      Rectangle locRect =
          new Rectangle(p.x - cellSize / 2, p.y - cellSize / 2, cellSize + 1, cellSize + 1);

      Rectangle viewRect = viewPort.getViewRect();
      if (!viewRect.contains(locRect)) {
        while (locRect.x < viewRect.x + dx) dx -= cellSize + 1;
        while (locRect.y < viewRect.y + dy) dy -= cellSize + 1;
        while (locRect.getMaxX() > viewRect.getMaxX() + dx) dx += cellSize + 1;
        while (locRect.getMaxY() > viewRect.getMaxY() + dy) dy += cellSize + 1;

        Point pt = viewPort.getViewPosition();
        pt.x += dx;
        pt.y += dy;
        viewPort.setViewPosition(pt);
      }
    }
    repaint();
    showTip(getToolTipText(currentLocation), pointForLocation(currentLocation));
  }
コード例 #16
0
 // Draws a line that connects the building to each other
 private void drawLine(Graphics2D g2, Rectangle r1, Rectangle r2, String type) {
   int x1 = (int) r1.getCenterX();
   int y1 = (int) r1.getCenterY();
   int x2 = (int) r2.getCenterX();
   int y2 = (int) r2.getCenterY();
   if (type.equals("DownToUp")) {
     g2.drawLine(x1, r1.y + r1.height, r2.x, y2);
   } else if (type.equals("UpToDown")) {
     g2.drawLine((int) r1.getMaxX(), y1, x2, (int) r2.getMaxY());
   } else if (type.equals("SideToSide")) {
     g2.drawLine((int) r1.getMaxX(), y1 + 20, r2.x, y2 + 20);
   }
 }
コード例 #17
0
ファイル: GlancePanel.java プロジェクト: Natinux/CodeGlance
  private void paintVisibleWindow(Graphics2D g) {
    Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
    int firstVisibleLine = getMapYFromEditorY((int) visibleArea.getMinY());
    int height =
        coords.linesToPixels(
            (int) ((visibleArea.getMaxY() - visibleArea.getMinY()) / editor.getLineHeight()));

    // Draw the current viewport
    g.setColor(viewportColor);
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.50f));
    g.drawRect(0, firstVisibleLine, getWidth(), height);
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.20f));
    g.fillRect(0, firstVisibleLine, getWidth(), height);
  }
コード例 #18
0
ファイル: XYPlotRenderer.java プロジェクト: cosfish/igv
  protected int computeYPixelValue(Rectangle drawingRect, DataRange axisDefinition, double dataY) {

    double maxValue = axisDefinition.getMaximum();
    double minValue = axisDefinition.getMinimum();

    double yScaleFactor = drawingRect.getHeight() / (maxValue - minValue);

    // Compute the pixel y location.  Clip to bounds of rectangle.
    // The distince in pixels frmo the data value to the axis maximum
    double delta = (maxValue - dataY) * yScaleFactor;
    double pY = drawingRect.getY() + delta;

    return (int) Math.max(drawingRect.getMinY(), Math.min(drawingRect.getMaxY(), pY));
  }
コード例 #19
0
ファイル: BunnyController.java プロジェクト: neduard/sepr4bar
  private Point2D.Double checkInBounds(double newX, double newY) {

    if (!bounds.contains(newX, newY)) {
      if (bounds.getMinX() > newX) {
        newX = bounds.getMinX();
        newY = adjustBunnyWhenHit(180, newX, newY).getY();
      } else if (bounds.getMaxX() < newX) {
        newX = bounds.getMaxX();
        newY = adjustBunnyWhenHit(0, newX, newY).getY();
      }

      if (bounds.getMinY() > newY) {
        newY = bounds.getMinY();
        newX = adjustBunnyWhenHit(270, newX, newY).getX();
      } else if (bounds.getMaxY() < newY) {
        newY = bounds.getMaxY();
        newX = adjustBunnyWhenHit(90, newX, newY).getX();
      }
      orientation = fixOrientation(tempOrientation);
    }

    return (new Point2D.Double(newX, newY));
  }
コード例 #20
0
ファイル: GlancePanel.java プロジェクト: Natinux/CodeGlance
  @Override
  public void paint(Graphics gfx) {
    Graphics2D g = (Graphics2D) gfx;
    g.setColor(editor.getColorsScheme().getDefaultBackground());
    g.fillRect(0, 0, getWidth(), getHeight());

    logger.debug(String.format("Rendering to buffer: %d", activeBuffer));
    if (activeBuffer >= 0) {
      paintSelection(g);

      Minimap minimap = minimaps[activeBuffer];

      Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();

      double documentEndY =
          editor
              .logicalPositionToXY(
                  editor.offsetToLogicalPosition(editor.getDocument().getTextLength() - 1))
              .getY();

      coords
          .setMinimap(minimap)
          .setPanelHeight(getHeight())
          .setPanelWidth(getWidth())
          .setPercentageComplete(
              visibleArea.getMinY()
                  / (documentEndY - (visibleArea.getMaxY() - visibleArea.getMinY())))
          .setHidpiScale(getHidpiScale());

      Rectangle src = coords.getImageSource();
      Rectangle dest = coords.getImageDestination();

      // Draw the image and scale it to stretch vertically.
      g.drawImage(
          minimap.img, // source image
          dest.x,
          dest.y,
          dest.width,
          dest.height,
          src.x,
          src.y,
          src.width,
          src.height,
          null);

      paintVisibleWindow(g);
    }
  }
コード例 #21
0
  public static Point getLocationForCaret(JTextComponent pathTextField) {
    Point point;

    int position = pathTextField.getCaretPosition();
    try {
      final Rectangle rec = pathTextField.modelToView(position);
      point = new Point((int) rec.getMaxX(), (int) rec.getMaxY());
    } catch (BadLocationException e) {
      point = pathTextField.getCaret().getMagicCaretPosition();
    }

    SwingUtilities.convertPointToScreen(point, pathTextField);

    point.y += 2;

    return point;
  }
コード例 #22
0
  private Rectangle getPrefetchingRegion(
      Rectangle loadedTilesBounds, BufferedVirtualSlideImage image, int resIndex) {
    Dimension tileSize = image.getTileSize(resIndex);
    Dimension tilePrefetchingRadius = getPrefetchingRadiusInTiles(tileSize);

    int tileColumns =
        (int) Math.ceil(image.getImageSize(resIndex).getWidth() / tileSize.getWidth());
    int tileRows = (int) Math.ceil(image.getImageSize(resIndex).getHeight() / tileSize.getHeight());

    int x1 = (int) Math.max(loadedTilesBounds.getX() - tilePrefetchingRadius.getWidth(), 0);
    int y1 = (int) Math.max(loadedTilesBounds.getY() - tilePrefetchingRadius.getHeight(), 0);
    int x2 =
        (int) Math.min(loadedTilesBounds.getMaxX() + tilePrefetchingRadius.getWidth(), tileColumns);
    int y2 =
        (int) Math.min(loadedTilesBounds.getMaxY() + tilePrefetchingRadius.getHeight(), tileRows);

    return new Rectangle(x1, y1, x2 - x1, y2 - y1);
  }
コード例 #23
0
  // Draws the CharacterOverview
  private void renderCharMenu(Graphics g, Graphics2D g2) {
    renderMenuUI(g, g2, "Character");

    // Draws gridpane
    int maxX = (int) menuUI.getMaxX();
    int maxY = (int) menuUI.getMaxY();
    int startY = menuUI.y + menuUI.height / 5;
    g2.drawLine(menuUI.x, startY, maxX, startY);
    g2.drawRect(menuUI.x + menuGrid.width, startY, 4 * menuGrid.width, 4 * menuGrid.height);

    // 2*4
    for (int i = 0; i < 2; i++) {
      for (int k = 0; k < 4; k++) {
        g2.drawRect(
            menuUI.x + ((menuUI.width - menuGrid.width) * i),
            startY + (menuGrid.height * k),
            menuGrid.width,
            menuGrid.height);
        drawItems(
            g2,
            menuUI.x + ((menuUI.width - menuGrid.width)),
            startY + (menuGrid.height),
            menuGrid.width,
            menuGrid.height);
      }
    }

    // draws the character inside the big middle grid
    movingCharRight.renderAnimation(
        g,
        menuUI.x + 2 * menuGrid.width,
        startY + menuGrid.height,
        2 * menuGrid.width,
        2 * menuGrid.height);

    // charactar stats
    g.setFont(fntSmall);
    g.drawString("HP: 100/100", menuUI.x + menuGrid.width, maxY - menuGrid.height / 2);
    g.drawString("STR: 100", menuUI.x + menuGrid.width, maxY - menuGrid.height / 4);
    g.drawString("Lvl: 5", (int) menuUI.getCenterX() + menuGrid.width, maxY - menuGrid.height / 2);
    g.drawString(
        "XP: 7/100", (int) menuUI.getCenterX() + menuGrid.width, maxY - menuGrid.height / 4);
  }
コード例 #24
0
 private void paintTextColumns(Graphics g, Rectangle clipBounds) {
   if (!hasIntersection(getTextColumnOffset(), myTextColumnWidth, clipBounds)) {
     return;
   }
   for (AbstractLeftColumn column : myLeftColumns) {
     if (clipBounds.x > column.getX() + column.getWidth()) {
       continue;
     }
     column.paint(g);
     //  COLORS: find out where it is and remove hardcoded color
     UIUtil.drawVDottedLine(
         (Graphics2D) g,
         myRightToLeft ? column.getX() : column.getX() + column.getWidth() - 1,
         (int) clipBounds.getMinY(),
         (int) clipBounds.getMaxY(),
         getBackground(),
         Color.GRAY);
   }
 }
コード例 #25
0
  @Override
  public List<Tile> getTilesToPrefetch(
      BufferedVirtualSlideImage image, Rectangle loadedImagePart, ImageIndex imageIndex) {
    Rectangle loadedTiles =
        getLoadedTilesBounds(loadedImagePart, image.getTileSize(imageIndex.getResolutionIndex()));
    Rectangle prefetchingRegion =
        getPrefetchingRegion(loadedTiles, image, imageIndex.getResolutionIndex());

    List<Tile> tilesToPrefetch = new ArrayList<Tile>();

    for (int y = prefetchingRegion.y; y < prefetchingRegion.getMaxY(); y++) {
      for (int x = prefetchingRegion.x; x < prefetchingRegion.getMaxX(); x++) {
        if (!loadedTiles.contains(x, y)) {
          tilesToPrefetch.add(new Tile(x, y, imageIndex));
        }
      }
    }

    return tilesToPrefetch;
  }
コード例 #26
0
ファイル: VPathwaySwing.java プロジェクト: cinquin/pathvisio
 public void mouseDragged(MouseEvent e) {
   Rectangle r = container.getViewport().getViewRect();
   final int stepSize = 10;
   int newx = (int) r.getMinX();
   int newy = (int) r.getMinY();
   // scroll when dragging out of view
   if (e.getX() > r.getMaxX()) {
     newx += stepSize;
   }
   if (e.getX() < r.getMinX()) {
     newx = Math.max(newx - stepSize, 0);
   }
   if (e.getY() > r.getMaxY()) {
     newy += stepSize;
   }
   if (e.getY() < r.getMinY()) {
     newy = Math.max(newy - stepSize, 0);
   }
   scrollTo(newx, newy);
   child.mouseMove(new SwingMouseEvent(e));
 }
コード例 #27
0
ファイル: Timeline.java プロジェクト: emu1729/ows
  public void paint(Graphics g, Rectangle grid, int max) {
    g.setColor(getColor());

    double divisionSize = (double) grid.getWidth() / getSize();
    double currentLocation = grid.getMinX();
    Point formerLocation = new Point(0, 0);

    for (Integer point : timeline) {
      double x = currentLocation;
      double y = grid.getMaxY() - (double) (point) / max * grid.getHeight();

      g.fillOval(
          (int) (x - circleRadius), (int) (y - circleRadius), 2 * circleRadius, 2 * circleRadius);
      if (currentLocation != (int) grid.getMinX()) {
        g.drawLine((int) formerLocation.getX(), (int) formerLocation.getY(), (int) x, (int) y);
      }

      formerLocation.setLocation(x, y);
      currentLocation += divisionSize;
    }
  }
コード例 #28
0
  public void drawCollapsedMarker(int x, int y, int width, int height) {
    // rectangle
    int rectangleWidth = MARKER_WIDTH;
    int rectangleHeight = MARKER_WIDTH;
    Rectangle rect =
        new Rectangle(
            x + (width - rectangleWidth) / 2,
            y + height - rectangleHeight - 3,
            rectangleWidth,
            rectangleHeight);
    g.draw(rect);

    // plus inside rectangle
    Line2D.Double line =
        new Line2D.Double(
            rect.getCenterX(), rect.getY() + 2, rect.getCenterX(), rect.getMaxY() - 2);
    g.draw(line);
    line =
        new Line2D.Double(
            rect.getMinX() + 2, rect.getCenterY(), rect.getMaxX() - 2, rect.getCenterY());
    g.draw(line);
  }
コード例 #29
0
ファイル: GraphicsUtil.java プロジェクト: adufour/Icy-Kernel
  /**
   * Returns true if the specified region is visible in the specified {@link Graphics} object.<br>
   * Internally use the {@link Graphics} clip area to determine if region is visible.
   */
  public static boolean isVisible(Graphics g, Rectangle region) {
    if ((g == null) || (region == null)) return false;

    final Rectangle clipRegion = g.getClipBounds();

    // no clip region --> return true
    if (clipRegion == null) return true;

    if (region.width == 0) {
      // special case of single point region
      if (region.height == 0) return clipRegion.contains(region.x, region.y);
      else
        // special case of null width region
        return clipRegion.contains(region.x, region.getMinY())
            || clipRegion.contains(region.x, region.getMaxY());

    } else if (region.height == 0)
      // special case of null height region
      return clipRegion.contains(region.getMinX(), region.y)
          || clipRegion.contains(region.getMaxX(), region.y);
    else return clipRegion.intersects(region);
  }
コード例 #30
0
ファイル: GlancePanel.java プロジェクト: Natinux/CodeGlance
    @Override
    public void mousePressed(MouseEvent e) {
      if (!dragging && inResizeGutter(e.getX())) {
        resizing = true;
      } else if (!resizing) {
        dragging = true;
      }

      if (resizing) {
        resizeStart = e.getXOnScreen();
        widthStart = config.width;
      }

      if (dragging) {
        Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
        int firstVisibleLine = getMapYFromEditorY((int) visibleArea.getMinY());
        int height =
            coords.linesToPixels(
                (int) ((visibleArea.getMaxY() - visibleArea.getMinY()) / editor.getLineHeight()));

        int panelY = e.getY() - getY();

        if (config.jumpOnMouseDown
            && (panelY <= firstVisibleLine || panelY >= (firstVisibleLine + height))) {
          editor.getScrollingModel().disableAnimation();
          editor
              .getScrollingModel()
              .scrollTo(
                  editor.offsetToLogicalPosition(
                      coords.screenSpaceToOffset(e.getY(), config.percentageBasedClick)),
                  ScrollType.CENTER);
          editor.getScrollingModel().enableAnimation();
        }

        scrollStart = editor.getScrollingModel().getVerticalScrollOffset();
        mouseStart = e.getY();
      }
    }