void drawRoiLabel(Graphics g, int index, Roi roi) { Rectangle r = roi.getBounds(); int x = screenX(r.x); int y = screenY(r.y); double mag = getMagnification(); int width = (int) (r.width * mag); int height = (int) (r.height * mag); int size = width > 40 && height > 40 ? 12 : 9; if (font != null) { g.setFont(font); size = font.getSize(); } else if (size == 12) g.setFont(largeFont); else g.setFont(smallFont); boolean drawingList = index >= LIST_OFFSET; if (drawingList) index -= LIST_OFFSET; String label = "" + (index + 1); if (drawNames && roi.getName() != null) label = roi.getName(); FontMetrics metrics = g.getFontMetrics(); int w = metrics.stringWidth(label); x = x + width / 2 - w / 2; y = y + height / 2 + Math.max(size / 2, 6); int h = metrics.getAscent() + metrics.getDescent(); if (bgColor != null) { g.setColor(bgColor); g.fillRoundRect(x - 1, y - h + 2, w + 1, h - 3, 5, 5); } if (!drawingList && labelRects != null && index < labelRects.length) labelRects[index] = new Rectangle(x - 1, y - h + 2, w + 1, h); g.setColor(labelColor); g.drawString(label, x, y - 2); g.setColor(defaultColor); }
public void displayScore2( Graphics g, int cx, int cy, int sx1, int sy1, int sx2, int sy2, int sx3, int sy3) { g.setFont(scoreFont); g.setColor(Color.WHITE); g.drawImage(new ImageIcon("InGameMenu/coin.png").getImage(), cx, cy, this); g.drawString("" + coins, sx1, sy1); g.drawString("Score: " + score, sx2, sy2); g.drawString("Height: " + height + " m", sx3, sy3); }
public void gameOverMenu( Graphics g) { // CHANGE THIS TO INCLUDE HIGHSCORES AND STUFF AFTER TEXTFILES ARE MADE // Menu that shows up when user gets Game Over if (pause == true && die == true) { g.drawImage( new ImageIcon("InGameMenu/pauseBckgrnd.png").getImage(), 0, 0, this); // Graphics stuff g.setFont(scoreFont); g.setColor(Color.BLACK); g.drawImage(new ImageIcon("InGameMenu/GameOver.png").getImage(), 10, 200, this); displayScore2(g, 115, 350, 185, 385, 110, 440, 110, 490); // Shows stats g.drawImage(menuB.getPic(mx, my), menuB.getX(), menuB.getY(), this); // Draws menu button } }
// ------------------------------------------------------------------------------------------------------------------------------------ // In game menus public void pauseMenu(Graphics g) { // Pause menu if (pause == true && lvlClear == false) { g.setFont(scoreFont); g.setColor(Color.BLACK); g.drawImage(new ImageIcon("InGameMenu/pauseBckgrnd.png").getImage(), 0, 0, this); g.drawString("P A U S E D", 155, 200); displayScore2(g, 115, 350, 185, 380, 110, 440, 110, 490); // Displays stats g.drawImage( resumeB.getPic(mx, my), resumeB.getX(), resumeB.getY(), this); // Draws the resume button g.drawImage( menuB.getPic(mx, my), menuB.getX(), menuB.getY(), this); // Draws the back to menu button if (musicOn == true) { // Draws the mute or unmute button (based on if music is on or not) g.drawImage(muteB.getPic(mx, my), muteB.getX(), muteB.getY(), this); } if (musicOn == false) { g.drawImage(unmuteB.getPic(mx, my), unmuteB.getX(), unmuteB.getY(), this); } } }
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; RenderingHints rh = g2d.getRenderingHints(); rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHints(rh); // Background. D = this.getSize(); g.setColor(backgroundColor); g.fillRect(0, 0, D.width, D.height); Graphics2D g2 = (Graphics2D) g; g2.setStroke(lineStroke); // Axes, bounding box. g.setColor(Color.gray); g.drawLine(inset, D.height - inset, D.width - inset, D.height - inset); g.drawLine(D.width - inset, inset, D.width - inset, D.height - inset); g.drawLine(inset, inset, inset, D.height - inset); g.drawLine(inset, inset, D.width - inset, inset); double xDelta = (maxX - minX) / numIntervals; // X-ticks and labels. for (int i = 1; i <= numIntervals; i++) { double xTickd = i * xDelta; int xTick = (int) (xTickd / (maxX - minX) * (D.width - 2 * inset)); g.drawLine(inset + xTick, D.height - inset - 5, inset + xTick, D.height - inset + 5); double x = minX + i * xDelta; g.drawString(df.format(x), xTick + inset - 5, D.height - inset + 20); } // Y-ticks double yDelta = (maxY - minY) / numIntervals; for (int i = 0; i < numIntervals; i++) { int yTick = (i + 1) * (int) ((D.height - 2 * inset) / (double) numIntervals); g.drawLine(inset - 5, D.height - yTick - inset, inset + 5, D.height - yTick - inset); double y = minY + (i + 1) * yDelta; g.drawString(df.format(y), 1, D.height - yTick - inset); } // Zoom+move Font savedFont = g.getFont(); g.setFont(plusFont); g.drawString("+", D.width - 25, 20); g.setFont(minusFont); g.drawString("-", D.width - 25, 50); drawArrow(g2d, D.width - 70, 20, D.width - 70, 0, 1.0f, lineStroke); // Up drawArrow(g2d, D.width - 70, 30, D.width - 70, 50, 1.0f, lineStroke); // Down drawArrow(g2d, D.width - 65, 25, D.width - 45, 25, 1.0f, lineStroke); // Right drawArrow(g2d, D.width - 75, 25, D.width - 95, 25, 1.0f, lineStroke); // Left g.setFont(savedFont); // See if standard axes are in the middle. g.setColor(Color.gray); if ((minX < 0) && (maxX > 0) && (drawMiddleAxes)) { // Draw y-axis int x = (int) ((0 - minX) / (maxX - minX) * (D.width - 2 * inset)); g.drawLine(inset + x, D.height - inset, inset + x, inset); } if ((minY < 0) && (maxY > 0) && (drawMiddleAxes)) { // Draw x-axis int y = (int) ((0 - minY) / (maxY - minY) * (D.height - 2.0 * inset)); g.drawLine(inset, D.height - y - inset, D.width - inset, D.height - y - inset); } // Draw the objects. drawObjects(g, points, lines, ovals, rectangles, images, labels, eqnLines); if (animationMode) { drawObjects(g, animPoints, animLines, animOvals, animRectangles, null, labels, eqnLines); // No images in animation mode. } drawScribbles(g); }
public void paintComponent(Graphics screen) { if (inactive == null) { inactive = new Image[BUTTON_COUNT]; rollover = new Image[BUTTON_COUNT]; active = new Image[BUTTON_COUNT]; int IMAGE_SIZE = 33; for (int i = 0; i < BUTTON_COUNT; i++) { inactive[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT); Graphics g = inactive[i].getGraphics(); g.drawImage(buttons, -(i * IMAGE_SIZE) - 3, -2 * IMAGE_SIZE, null); rollover[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT); g = rollover[i].getGraphics(); g.drawImage(buttons, -(i * IMAGE_SIZE) - 3, -1 * IMAGE_SIZE, null); active[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT); g = active[i].getGraphics(); g.drawImage(buttons, -(i * IMAGE_SIZE) - 3, -0 * IMAGE_SIZE, null); } state = new int[buttonCount]; stateImage = new Image[buttonCount]; for (int i = 0; i < buttonCount; i++) { setState(i, INACTIVE, false); } } Dimension size = getSize(); if ((offscreen == null) || (size.width != width) || (size.height != height)) { offscreen = createImage(size.width, size.height); width = size.width; height = size.height; y1 = 0; y2 = BUTTON_HEIGHT; x1 = new int[buttonCount]; x2 = new int[buttonCount]; int offsetX = 3; for (int i = 0; i < buttonCount; i++) { x1[i] = offsetX; if (i == 2) x1[i] += BUTTON_GAP; x2[i] = x1[i] + BUTTON_WIDTH; offsetX = x2[i]; } } Graphics g = offscreen.getGraphics(); g.setColor(bgcolor); // getBackground()); g.fillRect(0, 0, width, height); for (int i = 0; i < buttonCount; i++) { g.drawImage(stateImage[i], x1[i], y1, null); } g.setColor(statusColor); g.setFont(statusFont); /* // if i ever find the guy who wrote the java2d api, i will hurt him. Graphics2D g2 = (Graphics2D) g; FontRenderContext frc = g2.getFontRenderContext(); float statusW = (float) statusFont.getStringBounds(status, frc).getWidth(); float statusX = (getSize().width - statusW) / 2; g2.drawString(status, statusX, statusY); */ // int statusY = (BUTTON_HEIGHT + statusFont.getAscent()) / 2; int statusY = (BUTTON_HEIGHT + g.getFontMetrics().getAscent()) / 2; g.drawString(status, buttonCount * BUTTON_WIDTH + 2 * BUTTON_GAP, statusY); screen.drawImage(offscreen, 0, 0, null); }
static void paintShadowTitle( Graphics g, String title, int x, int y, Color frente, Color shadow, int desp, int tipo, int orientation) { // Si hay que rotar la fuente, se rota Font f = g.getFont(); if (orientation == SwingConstants.VERTICAL) { AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2); f = f.deriveFont(rotate); } // Si hay que pintar sombra, se hacen un monton de cosas if (shadow != null) { int matrix = (tipo == THIN ? MATRIX_THIN : MATRIX_FAT); Rectangle2D rect = g.getFontMetrics().getStringBounds(title, g); int w, h; if (orientation == SwingConstants.HORIZONTAL) { w = (int) rect.getWidth() + 6 * matrix; // Hay que dejar espacio para las sombras y el borde h = (int) rect.getHeight() + 6 * matrix; // que ConvolveOp ignora por el EDGE_NO_OP } else { h = (int) rect.getWidth() + 6 * matrix; // Hay que dejar espacio para las sombras y el borde w = (int) rect.getHeight() + 6 * matrix; // que ConvolveOp ignora por el EDGE_NO_OP } // La sombra del titulo BufferedImage iTitulo = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); BufferedImage iSombra = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = iTitulo.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.setFont(f); g2.setColor(shadow); g2.drawString(title, 3 * matrix, 3 * matrix); // La pintamos en el centro ConvolveOp cop = new ConvolveOp((tipo == THIN ? kernelThin : kernelFat), ConvolveOp.EDGE_NO_OP, null); cop.filter(iTitulo, iSombra); // A ditorsionar // Por fin, pintamos el jodio titulo g.drawImage( iSombra, x - 3 * matrix + desp, // Lo llevamos a la posicion original y le sumamos 1 y - 3 * matrix + desp, // para que la sombra quede pelin desplazada null); } // Si hay que pintar el frente, se pinta if (frente != null) { g.setFont(f); g.setColor(frente); g.drawString(title, x, y); } }