Exemple #1
0
	/**
	 * 获得图片的矩形大小
	 * 
	 * @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;
	}
  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;
    }
  }
 /**
  * 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);
 }
 // 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);
   }
 }
  /**
   * 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$
    }
  }
Exemple #6
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));
        }
      }
    }
  }
  // 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);
  }
  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;
  }
  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$
    }
  }
 private void adaptDimensions() {
   DimensionFloat textSize = Utils.getTextSize(message, notificationFont, frc);
   int x = (int) (drawPanelSize.getMaxX() - textSize.getWidth() - 20);
   int y = (int) (drawPanelSize.getMinY() + 10);
   this.setLocation(x, y);
   this.setSize((int) textSize.getWidth() + 10, (int) textSize.getHeight() + 10);
 }
  @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);
    }
  }
  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;
  }
  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);
  }
Exemple #14
0
  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;
    }
  }
  @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;
    }
  }
  /**
   * 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();
  }
Exemple #17
0
  /**
   * 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));
  }
Exemple #18
0
  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));
  }
  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;
  }
  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);
  }
  // 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);
  }
  /**
   * 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;
  }
  @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;
  }
Exemple #24
0
 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));
 }
Exemple #25
0
  /**
   * 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);
  }
  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);
  }
Exemple #27
0
  public static void renderCards(
      GameScreen screen,
      Graphics2D g,
      Iterable<Card> cards,
      Rectangle2D loc,
      Map<Card, Rectangle> cardLocations) {
    Shape clip = g.getClip();

    int x = 0;
    int col = 0;
    int row = 0;
    for (Card card : cards) {
      Rectangle r = getCardBounds(x, row, loc.getWidth(), loc.getHeight());
      if (x > 0 && r.getMaxX() > loc.getWidth() && col > 0) {
        x = 0;
        row++;
        r = getCardBounds(x, row, loc.getWidth(), loc.getHeight());
      }
      r.translate((int) loc.getX(), (int) loc.getY());

      cardLocations.put(card, r);

      BufferedImage bi = ClientCache.getCardImage(card.detailsID);

      if (clip.intersects(r) && card != screen.getPickedUpCard()) {
        CardRenderer.draw(card, bi, r, g);
      }

      if (screen.debug) {
        g.setColor(Color.white);
        g.setFont(new Font("Arial", Font.BOLD, 19));
        ClientUtils.drawCenteredString(g, r, card.id + "");
      }

      x += r.width + 10;
      col++;
    }
  }
  /**
   * Creates a master shape of the letter.
   *
   * @param shape
   * @return the master shape
   */
  private final Master createMaster(RenderContext ctx, Shape shape, double ascent) {
    final Area area = new Area(shape);
    final double scale = MASTER_HEIGHT / ascent;

    area.transform(AffineTransform.getScaleInstance(scale, scale));
    final Rectangle bounds = area.getBounds();
    // System.out.println("createMaster bounds " + bounds);
    // area.transform(AffineTransform.getTranslateInstance(-bounds.getMinX(),
    // -bounds.getMinY()));
    // bounds = area.getBounds();

    final int minX = (int) (bounds.getMinX() - 0.5);
    final int maxX = (int) (bounds.getMaxX() + 0.5);
    final int minY = (int) (bounds.getMinY() - 0.5);
    final int maxY = (int) (bounds.getMaxY() + 0.5);
    final int width = maxX - minX;
    final int height = maxY - minY;

    BitSet bits = (BitSet) ctx.getObject(BITS_NAME);
    if (bits == null) {
      bits = new BitSet(width * height);
      ctx.setObject(BITS_NAME, bits);
    } else {
      bits.clear();
    }
    int ofs = 0;
    for (int y = maxY; y > minY; y--) {
      for (int x = minX; x < maxX; x++) {
        if (area.contains(x, y)) {
          bits.set(ofs);
        }
        ofs++;
      }
    }

    return new Master(bits, width, height, minX, minY);
  }
  @Override
  public void mouseDragged(MouseEvent e) {
    if (this.selecting) {
      int to;
      this.dragging = true;
      switch (curDir) {
        case DIR_E:
          to = (int) (e.getX() - this.selected.getMaxX());
          if ((this.selected.width + to) > 0) {
            this.selected.width += to;
            this.gui.getSelected().getNiftyElement().setWidth(selected.width);
            this.gui.getSelected().addAttribute("width", "" + selected.width + "px");
          }
          break;
        case DIR_W:
          to = (int) (this.selected.getMinX() - e.getX());
          if ((this.selected.width + to) > 0) {
            this.selected.x = e.getX();
            this.selected.width += to;
            this.gui.getSelected().addAttribute("width", "" + selected.width + "px");
            if (this.gui.getSelected().getParent().getAttribute("childLayout").equals("absolute")) {
              int x = gui.getSelected().getParent().getNiftyElement().getX();
              this.gui.getSelected().addAttribute("x", "" + (e.getX() - x) + "px");
            }
          }
          break;
        case DIR_S:
          to = (int) (e.getY() - this.selected.getMaxY());
          if ((this.selected.height + to) > 0) {
            this.selected.height += to;

            this.gui.getSelected().getNiftyElement().setHeight(selected.height);
            this.gui.getSelected().addAttribute("height", "" + selected.height + "px");
          }
          break;
        case DIR_SE:
          to = (int) (e.getX() - this.selected.getMaxX());
          int toy = (int) (e.getY() - this.selected.getMaxY());
          if (((this.selected.width + to) > 0) && (this.selected.height + to) > 0) {
            if (e.isControlDown()) this.selected.height += to;
            else this.selected.height += toy;

            this.gui.getSelected().getNiftyElement().setHeight(selected.height);
            this.gui.getSelected().addAttribute("height", "" + selected.height + "px");

            this.selected.width += to;

            this.gui.getSelected().getNiftyElement().setWidth(selected.width);
            this.gui.getSelected().addAttribute("width", "" + selected.width + "px");

            if (e.isControlDown()) {
              Point gtry = new Point((int) selected.getMaxX(), (int) selected.getMaxY());
              //  SwingUtilities.convertPointToScreen(gtry, this);
              // mouseBot.mouseMove(gtry.x,gtry.y);
            }
          }
          break;
        case DIR_N:
          to = (int) (this.selected.getMinY() - e.getY());
          if ((this.selected.height + to) > 0) {
            this.selected.height += to;
            this.selected.y = e.getY();

            this.gui.getSelected().addAttribute("height", "" + selected.height + "px");
            if (this.gui.getSelected().getParent().getAttribute("childLayout").equals("absolute")) {
              int y = gui.getSelected().getParent().getNiftyElement().getY();
              this.gui.getSelected().addAttribute("y", "" + (e.getY() - y) + "px");
            }
          }
          break;
        default:
          dragging = false;
      }
      v.displayRect(selected.x, selected.y, selected.height, selected.width);
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see org.jvnet.flamingo.ribbon.ui.BasicRibbonUI#paintTaskArea(java.awt.
   * Graphics , int, int, int, int)
   */
  @Override
  protected void paintTaskArea(Graphics g, int x, int y, int width, int height) {
    if (this.ribbon.getTaskCount() == 0) return;

    Graphics2D g2d = (Graphics2D) g.create();

    RibbonTask selectedTask = this.ribbon.getSelectedTask();
    JRibbonTaskToggleButton selectedTaskButton = this.taskToggleButtons.get(selectedTask);
    Rectangle selectedTaskButtonBounds = selectedTaskButton.getBounds();
    Point converted =
        SwingUtilities.convertPoint(
            selectedTaskButton.getParent(), selectedTaskButtonBounds.getLocation(), this.ribbon);
    float radius =
        SubstanceSizeUtils.getClassicButtonCornerRadius(
            SubstanceSizeUtils.getComponentFontSize(this.ribbon));

    float borderDelta = SubstanceSizeUtils.getBorderStrokeWidth() / 2.0f;

    SubstanceBorderPainter borderPainter = SubstanceCoreUtilities.getBorderPainter(this.ribbon);
    float borderThickness = SubstanceSizeUtils.getBorderStrokeWidth();

    AbstractRibbonBand band = (selectedTask.getBandCount() == 0) ? null : selectedTask.getBand(0);
    SubstanceColorScheme borderScheme =
        SubstanceColorSchemeUtilities.getColorScheme(
            band, ColorSchemeAssociationKind.BORDER, ComponentState.ENABLED);

    Rectangle taskToggleButtonsViewportBounds =
        taskToggleButtonsScrollablePanel.getView().getParent().getBounds();
    taskToggleButtonsViewportBounds.setLocation(
        SwingUtilities.convertPoint(
            taskToggleButtonsScrollablePanel,
            taskToggleButtonsViewportBounds.getLocation(),
            this.ribbon));
    int startSelectedX = Math.max(converted.x + 1, (int) taskToggleButtonsViewportBounds.getMinX());
    startSelectedX = Math.min(startSelectedX, (int) taskToggleButtonsViewportBounds.getMaxX());
    int endSelectedX =
        Math.min(
            converted.x + selectedTaskButtonBounds.width - 1,
            (int) taskToggleButtonsViewportBounds.getMaxX());
    endSelectedX = Math.max(endSelectedX, (int) taskToggleButtonsViewportBounds.getMinX());

    Shape outerContour =
        RibbonBorderShaper.getRibbonBorderOutline(
            this.ribbon,
            x + borderDelta,
            x + width - borderDelta,
            startSelectedX - borderThickness,
            endSelectedX + borderThickness,
            converted.y + borderDelta,
            y + borderDelta,
            y + height - borderDelta,
            radius);

    Shape innerContour =
        RibbonBorderShaper.getRibbonBorderOutline(
            this.ribbon,
            x + borderDelta + borderThickness,
            x + width - borderThickness - borderDelta,
            startSelectedX - borderThickness,
            endSelectedX + borderThickness,
            converted.y + borderDelta + borderThickness,
            y + borderDelta + borderThickness,
            y + height - borderThickness - borderDelta,
            radius);

    g2d.setColor(
        SubstanceColorSchemeUtilities.getColorScheme(band, ComponentState.ENABLED)
            .getBackgroundFillColor());
    g2d.clipRect(x, y, width, height + 2);
    g2d.fill(outerContour);

    // g2d.setColor(Color.red);
    // g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    // RenderingHints.VALUE_ANTIALIAS_ON);
    // g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
    // RenderingHints.VALUE_STROKE_PURE);
    // g2d.setStroke(new BasicStroke(0.5f));
    // g2d.draw(outerContour);
    // g2d.setColor(Color.blue);
    // g2d.draw(innerContour);
    borderPainter.paintBorder(
        g2d,
        this.ribbon,
        width,
        height + selectedTaskButtonBounds.height + 1,
        outerContour,
        innerContour,
        borderScheme);

    // check whether the currently selected task is a contextual task
    RibbonTask selected = selectedTask;
    RibbonContextualTaskGroup contextualGroup = selected.getContextualGroup();
    if (contextualGroup != null) {
      // paint a small gradient directly below the task area
      Insets ins = this.ribbon.getInsets();
      int topY = ins.top + getTaskbarHeight();
      int bottomY = topY + 5;
      Color hueColor = contextualGroup.getHueColor();
      Paint paint =
          new GradientPaint(
              0,
              topY,
              FlamingoUtilities.getAlphaColor(
                  hueColor, (int) (255 * RibbonContextualTaskGroup.HUE_ALPHA)),
              0,
              bottomY,
              FlamingoUtilities.getAlphaColor(hueColor, 0));
      g2d.setPaint(paint);
      g2d.clip(outerContour);
      g2d.fillRect(0, topY, width, bottomY - topY + 1);
    }

    // paint outlines of the contextual task groups
    // paintContextualTaskGroupsOutlines(g);

    g2d.dispose();
  }