public static void drawAtPoint(String texttodisplay, CGPoint point, UIFont font) { Graphics2D graphicsContext = CGContext.UICurrentContext().xmlvmGetGraphics2D(); Font savedFont = graphicsContext.getFont(); graphicsContext.setFont(font.xmlvmGetFont()); graphicsContext.drawString(texttodisplay, point.x, point.y); graphicsContext.setFont(savedFont); }
@Override public void paintIcon(Component c, Graphics g, int x, int y) { final Graphics2D g2d = (Graphics2D) g; // Turn AA on g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); final Font original = g2d.getFont(); if (value != null) { String text = value.toString(); final int textLen = text.length(); g2d.translate(leftPad, (c.getHeight()) / 2); g2d.setColor(color); if (textLen > MAX_TEXT_LEN) { text = text.substring(0, 5) + "..."; g2d.setFont(FONT_SMALL); } else g2d.setFont(FONT); g2d.drawString(text, 0, 0); g2d.translate(-leftPad, -((c.getHeight()) / 2)); } g2d.setFont(original); }
public void drawPause(Graphics2D graphics) { Rectangle2D textBackground = new Rectangle2D.Double(219, 232, 292, 146); Rectangle2D textBackground2 = new Rectangle2D.Double(222, 235, 286, 140); String text = "Paused!"; String text2 = "Press to Resume"; String text3 = "Press to"; String text4 = "Return to Menu"; String text5 = "Enter"; String text6 = "BackSpace"; graphics.setColor(Color.gray); graphics.fill(textBackground); graphics.setColor(Color.darkGray); graphics.fill(textBackground2); graphics.setColor(Color.orange); Font arial2 = new Font("Tekton Pro", Font.PLAIN, 25); Font arial = new Font("Tekton Pro", Font.PLAIN, 50); graphics.setFont(arial); graphics.setColor(Color.white); graphics.drawString(text, 285, 285); graphics.setColor(Color.orange); graphics.setFont(arial2); graphics.drawString(text2, 250, 310); graphics.drawString(text3, 260, 335); graphics.drawString(text4, 290, 360); graphics.setColor(Color.red); graphics.drawString(text5, 315, 310); graphics.drawString(text6, 325, 335); }
@Override public void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; super.paintComponent(g2d); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (level < MAX_LEVEL) { g2d.drawImage(ground, 0, 0, Game.WIDTH, Game.HEIGHT2, null); g2d.drawImage(barbg, 250, Game.HEIGHT, 500, 100, null); play.draw(g2d); if (numDonuts < MAX_DONUTS) { g2d.setFont(font.deriveFont(30f)); g2d.setColor(Color.BLACK); g2d.drawString("Level " + (level + 1), 280, Game.HEIGHT + 50); g2d.setColor(Color.BLUE); g2d.drawString(score + "", 670, Game.HEIGHT + 30); g2d.setColor(Color.RED); g2d.drawString(numDonuts + "/" + MAX_DONUTS, 450, Game.HEIGHT + 30); } } else { g2d.setColor(Color.CYAN); g2d.fillRect(0, 0, Game.WIDTH, Game.HEIGHT2); g2d.setFont(font.deriveFont(30f)); g2d.setColor(Color.BLACK); if (perioTime % 12 > 0 && perioTime % 12 < 6) g2d.drawString("Please wait..", 320, 300); else g2d.drawString("Please wait...", 320, 300); } }
@Override public void onRepaint(Graphics g1) { Graphics2D g = (Graphics2D) g1; final Color color1 = new Color(213, 214, 175); final Color color2 = new Color(0, 0, 0); final Color color3 = new Color(1, 1, 1); final BasicStroke stroke1 = new BasicStroke(1); final Font font1 = new Font("Verdana", 3, 18); final Font font2 = new Font("Verdana", 1, 12); if (Game.isLoggedIn()) { currentWcExp = Skills.getExperience(Skills.WOODCUTTING); woodcuttingExpGained = currentWcExp - startWoodcuttingExp; int xpHour = (int) (3600000.0 / (runTime.getElapsed()) * woodcuttingExpGained); g.setColor(color1); g.fillRect(8, 394, 487, 114); g.setColor(color2); g.setStroke(stroke1); g.drawRect(8, 394, 487, 114); g.setFont(font1); g.setColor(color3); g.drawString("AnDraynorWillowChopper v0.3", 219, 421); g.setFont(font2); g.drawString("Status: " + Status, 18, 433); g.drawString("Run Time: " + runTime.toElapsedString(), 18, 452); g.drawString("Xp gained: " + woodcuttingExpGained + "(" + xpHour + ")/hr", 19, 472); g.drawString("WoodCutting Level: " + Skills.getLevel(Skills.WOODCUTTING), 18, 491); } }
private void paintString( Graphics g, int x, int y, int width, int height, int fillStart, int amountFull, Insets b) { if (!(g instanceof Graphics2D)) { return; } Graphics2D g2D = (Graphics2D) g; String progressString = progressBar.getString(); g2D.setFont(progressBar.getFont()); Point renderLocation = getStringPlacement(g2D, progressString, x, y, width, height); Rectangle savedClip = g2D.getClipBounds(); if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { g2D.setColor(getSelectionBackground()); Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y); g2D.setColor(getSelectionForeground()); g2D.clipRect(fillStart, y, amountFull, height); Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y); } else { // VERTICAL g2D.setColor(getSelectionBackground()); AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2); g2D.setFont(progressBar.getFont().deriveFont(rotate)); renderLocation = getStringPlacement(g2D, progressString, x, y, width, height); Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y); g2D.setColor(getSelectionForeground()); g2D.clipRect(x, fillStart, width, amountFull); Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y); } g2D.setClip(savedClip); }
@Override public Point paint(Graphics2D g2, Point p) { Position = p; Font tmp = g2.getFont(); g2.setFont(new Font("SansSerif", Font.PLAIN, 18)); Rectangle2D NBounds = g2.getFont().getStringBounds(Integer.toString(currentNumber), g2.getFontRenderContext()); g2.draw( Arrow2D.getArrow( new Point( (int) (getPosition().getX() + NBounds.getCenterX()), (int) (getPosition().getY() - NBounds.getHeight())), new Point( (int) (getPosition().getX() + NBounds.getCenterX()), (int) getPosition().getY()), 8, 30)); g2.drawString( Integer.toString(currentNumber), (float) Position.getX(), (float) (Position.getY() - NBounds.getHeight())); g2.setFont(tmp); ShapeSize = new Rectangle2D.Double(0, 0, NBounds.getWidth(), NBounds.getHeight() + NBounds.getHeight()); return new Point((int) (p.getX() + ShapeSize.getWidth()), (int) p.getY()); }
private BufferedImage getFontImage(char ch) { // Create a temporary image to extract the character's size BufferedImage tempfontImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D) tempfontImage.getGraphics(); if (antiAlias == true) { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } g.setFont(font); fontMetrics = g.getFontMetrics(); int charwidth = fontMetrics.charWidth(ch) + 8; if (charwidth <= 0) { charwidth = 7; } int charheight = fontMetrics.getHeight() + 3; if (charheight <= 0) { charheight = fontSize; } // Create another image holding the character we are creating BufferedImage fontImage; fontImage = new BufferedImage(charwidth, charheight, BufferedImage.TYPE_INT_ARGB); Graphics2D gt = (Graphics2D) fontImage.getGraphics(); if (antiAlias == true) { gt.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } gt.setFont(font); gt.setColor(Color.WHITE); int charx = 3; int chary = 1; gt.drawString(String.valueOf(ch), (charx), (chary) + fontMetrics.getAscent()); return fontImage; }
@Override void myRendering(Graphics2D display, AffineTransform boxTransform) { Rectangle visRect = getComponent().getVisibleRect(); display.setBackground(Color.WHITE); display.clearRect(visRect.x, visRect.y, visRect.width, visRect.height); final String logo = getVisConfig().getLogo(); if (logo != null && logo.length() > 0) { int targetLogoHeight = visRect.height * 8 / 10; int targetLogoWidth = visRect.width * 9 / 10; display.setFont(new Font(display.getFont().getName(), Font.BOLD, targetLogoHeight)); int trueLogoWidth = display.getFontMetrics().stringWidth(logo); double scaling = Math.min((double) targetLogoWidth / trueLogoWidth, 1); int scaledLogoHeight = (int) Math.round(scaling * targetLogoHeight); display.setFont(new Font(display.getFont().getName(), Font.PLAIN, scaledLogoHeight)); int scaledLogoWidth = display.getFontMetrics().stringWidth(logo); display.setColor(Color.LIGHT_GRAY); int xCoord = visRect.x + (visRect.width - scaledLogoWidth) / 2; int yCoord = visRect.y + (visRect.height + scaledLogoHeight) / 2; display.drawString(logo, xCoord, yCoord); } }
@Override protected void paintIcon( java.awt.Component c, java.awt.Graphics2D g2, int width, int height, java.awt.Paint fillPaint, java.awt.Paint drawPaint) { java.awt.Font prevFont = g2.getFont(); g2.setFont(font); String text = "A"; java.awt.FontMetrics fm = g2.getFontMetrics(); int messageWidth = fm.stringWidth(text); int ascent = fm.getMaxAscent(); int descent = fm.getMaxDescent(); int x = (width / 2) - (messageWidth / 2); int y = ((height / 2) + (ascent / 2)) - (descent / 2); java.awt.font.GlyphVector glyphVector = font.createGlyphVector(g2.getFontRenderContext(), text); java.awt.Shape outline = glyphVector.getOutline(x, y); g2.setPaint(drawPaint); g2.draw(outline); g2.setPaint(fillPaint); g2.fill(outline); // g2.drawString( text, x, y ); g2.setFont(prevFont); }
public void drawPoolOrLane(String name, int x, int y, int width, int height) { g.drawRect(x, y, width, height); // Add the name as text, vertical if (name != null && name.length() > 0) { // Include some padding int availableTextSpace = height - 6; // Create rotation for derived font AffineTransform transformation = new AffineTransform(); transformation.setToIdentity(); transformation.rotate(270 * Math.PI / 180); Font currentFont = g.getFont(); Font theDerivedFont = currentFont.deriveFont(transformation); g.setFont(theDerivedFont); String truncated = fitTextToWidth(name, availableTextSpace); int realWidth = fontMetrics.stringWidth(truncated); g.drawString( truncated, x + 2 + fontMetrics.getHeight(), 3 + y + availableTextSpace - (availableTextSpace - realWidth) / 2); g.setFont(currentFont); } }
/** Creates and initializes a splash screen based on image shown by vm while starting. */ private void createSplashscreen() { // Create splash screen only when not yet happened. if (splash != null) { splashGraphics = splash.createGraphics(); if (splashGraphics != null) { final Color splashscreenColor = new Color(85, 85, 85); final int versionX = 38; final int versionY = 126; final float versionFontSize = 18; final String versionString = RunUI.class.getPackage().getSpecificationVersion(); splashGraphics.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); splashGraphics.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); splashGraphics.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); splashGraphics.setRenderingHint( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); splashGraphics.setColor(splashscreenColor); splashGraphics.setFont(FontFactory.createSplashscreenFont().deriveFont(versionFontSize)); splashGraphics.setPaintMode(); splashGraphics.drawString("Version " + versionString, versionX, versionY); splash.update(); splashGraphics.setFont(FontFactory.createSplashscreenFont()); } } }
public static void evokeCombat(Graphics g1, boolean hide, int skill) { final Color color1 = new Color(0, 0, 0); final Color color2 = new Color(255, 0, 0); final BasicStroke stroke1 = new BasicStroke(1); final Font font1 = new Font("Arial", 0, 10); final Font font2 = new Font("Arial", 0, 18); if (!hide) { Graphics2D g = (Graphics2D) g1; g.setColor(color1); g.fillRect(1, 1, 162, 180); g.setStroke(stroke1); g.drawRect(1, 1, 162, 180); g.setFont(font1); g.setColor(color2); g.drawString("Current Level: " + Skills.getLevel(skill), 5, 48); g.drawString("Levels Gained: " + sd.level(skill), 5, 65); g.drawString("Experiance / hour: " + getXpHr(skill), 5, 82); g.drawString("TTL: " + getTtl(skill), 6, 100); g.setFont(font2); g.drawString("Monk Killer", 6, 26); g.setFont(font1); g.drawString("Run Time: " + runTime.toElapsedString(), 6, 116); g.drawString("Monks Killed: " + monksKilled, 6, 133); g.drawString("Bones looted: " + bonesLooted, 6, 150); g.setFont(font2); g.drawString("By: Kirinsoul!", 5, 176); } }
@Override public final void paint(Graphics g) { super.paint(g); Graphics2D g2 = (Graphics2D) g; Composite old = g2.getComposite(); // Store non-transparent composite g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f)); // 40% transparency g2.drawRect(0, 0, getWidth() - 1, getHeight() - 1); Font drawFont = g2.getFont(); g2.setFont(notificationFont); adaptDimensions(); int textX = 5; int textY = (getHeight() / 2 + 3); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f)); // 70% transparency g2.drawString(message, textX, textY); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.05f)); // 5% transparency g2.setColor(java.awt.Color.blue); g2.fillRect(0, 0, this.getWidth() - 1, this.getHeight() - 1); g2.setComposite(old); g2.setFont(drawFont); }
@Override public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setColor(new Color(0, 0, 0)); for (int j = 0; j < 8; j++) { ImageIcon ii = new ImageIcon(this.getClass().getResource("/images/" + 2 + ".png")); g2.drawImage(ii.getImage(), j * 70, 560, this); } for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { ImageIcon ii = new ImageIcon(this.getClass().getResource("/images/" + mGame[i][j] + ".png")); g2.setFont(new Font("ARIAL", Font.BOLD, 60)); if (mGame[i][j] == OK) { g2.drawString(" " + logic.getScore(), j * 70, i * 70); } if (mGame[i][j] == ERROR) { g2.drawString("-3", j * 70, i * 70); } g2.drawImage(ii.getImage(), j * 70, i * 70, this); g2.setFont(new Font("ARIAL", Font.BOLD, 20)); g2.setColor(Color.DARK_GRAY); g2.drawString("Seus Tijolos : " + logic.getScore(), 10, 600); g2.drawString("Quantidade : " + QUANTIDADE_TIJOLO, 200, 600); g2.drawString("Tempo : " + time, 450, 600); } } }
@Override public void paint(Graphics g) { float width = getWidth(); float height = getHeight(); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.black); g2.fill(new Rectangle2D.Float(0, 0, width, height)); g2.setFont(getFont().deriveFont(FONT_SIZE)); g2.setColor(Color.green); FontMetrics fm = g2.getFontMetrics(); g2.drawString("Input", width / 4f - fm.stringWidth("Input") / 2f, 30); g2.setColor(Color.red); g2.drawString("Output", width - width / 4f - fm.stringWidth("Output") / 2f, 30); g2.setFont(getFont().deriveFont(FONT_SIZE / 2)); fm = g2.getFontMetrics(); g2.setColor(new Color(0, 255, 0)); g2.drawString("response", width / 4f - fm.stringWidth("response") / 2f, 48); g2.setColor(new Color(0, 255, 255)); g2.drawString("request", width / 4f - fm.stringWidth("request") / 2f, 60); g2.setColor(new Color(255, 0, 0)); g2.drawString("request", width - width / 4f - fm.stringWidth("request") / 2f, 48); g2.setColor(new Color(255, 0, 255)); g2.drawString("response", width - width / 4f - fm.stringWidth("response") / 2f, 60); synchronized (lock) { painter.paint(this, g2); } }
public void paintBar(Graphics2D g) { g.setColor(Color.RED); g.setFont(new Font("", 1, 25)); g.drawString( "Infecting Computer...", fitTextInBoxWidth("Infecting Computer...", g, FakeVTroll.WIDTH), 100); g.setColor(Color.GRAY); g.fillRoundRect(50, FakeVTroll.HEIGHT / 2, FakeVTroll.WIDTH - 100, 20, 10, 10); g.setColor(Color.RED); g.fillRoundRect(50, FakeVTroll.HEIGHT / 2, calcBarProgress(FakeVTroll.WIDTH - 100), 20, 10, 10); g.setFont(new Font("", 1, 15)); g.setColor(Color.BLACK); g.drawString( progressPercent2 + "%", fitTextInBoxWidth(progressPercent2 + "%", g, FakeVTroll.WIDTH), (FakeVTroll.HEIGHT / 2) + 15); if (shouldUseScare) { g.setFont(new Font("", 1, 20)); g.drawString( fakeInstalls[fakeInstUse], fitTextInBoxWidth(fakeInstalls[fakeInstUse], g, FakeVTroll.WIDTH), (FakeVTroll.HEIGHT / 2) + 90); } }
public static void drawAdHoc(Graphics2D g2, int x, int y) { Font oldFont = g2.getFont(); g2.setFont(new Font("Arial", Font.BOLD, 28)); g2.setPaint(Color.BLACK); g2.drawString("~", x - MARKER_ICON_SIZE, y + MARKER_ICON_SIZE); g2.setFont(oldFont); }
@Override public void drawString(String string, BoundingBox2d bounds, double padding) { FontMetrics metrics = pipe.getFontMetrics(pipe.getFont()); final double stringWidth = metrics.stringWidth(string); final double stringHeight = metrics.getHeight(); // calculate scale, so that bb fits into bounds - padding final double sx = bounds.getWidth() / (stringWidth + padding); final double sy = bounds.getHeight() / (stringHeight + padding); final double scale = Math.min(sx, sy); java.awt.Font oldFont = pipe.getFont(); java.awt.Font scaledFont = oldFont.deriveFont((float) (oldFont.getSize2D() * scale)); // position b inside bounds final double x = bounds.getLocation().getX() + (bounds.getWidth() - stringWidth * scale) / 2; final double y = bounds.getLocation().getY() + bounds.getHeight() - (bounds.getHeight() - scaledFont.getSize2D()) / 2; pipe.setFont(scaledFont); try { pipe.drawString(string, (float) x, (float) y); } finally { pipe.setFont(oldFont); } }
@Override public void drawTextAxis( Graphics2D g2d, Dimension dim, boolean isHorizontal, String text, double coordinate) { if (!this.showAxisFonts) return; g2d.setFont(this.axisFont); int width = g2d.getFontMetrics().stringWidth(text) + this.axisFontMargin; int height = g2d.getFontMetrics().getHeight(); /*if (isHorizontal) g2d.fillRect(0, (int) dim.getHeight()-width, (int) dim.getWidth(), (int) dim.getHeight()); else g2d.fillRect(0, 0, width, (int) dim.getHeight());*/ g2d.setFont(axisFont); AffineTransform orig = g2d.getTransform(); double angle = Math.toRadians(90); if (this.showAxisFonts) if (!isHorizontal) { g2d.setColor(this.axisBackgroundColor); g2d.fillRect(axisFontMargin, (int) coordinate - height, width, height); g2d.setColor(this.axisFontColor); g2d.drawString(text, this.axisFontMargin, (int) coordinate - axisFontMargin); } else { g2d.rotate( -angle, (int) coordinate - this.axisFontMargin, (int) dim.getHeight() - axisFontMargin); g2d.setColor(this.axisBackgroundColor); g2d.fillRect( (int) coordinate - this.axisFontMargin, (int) dim.getHeight() - height, width, height); g2d.setColor(this.axisFontColor); g2d.drawString( text, (int) coordinate - this.axisFontMargin, (int) dim.getHeight() - axisFontMargin); g2d.setTransform(orig); } }
protected void drawMultiplier(int xpix, int ypix, int exponent, Graphics2D g2) { Font oldFont = g2.getFont(); g2.drawString("10", xpix, ypix); // $NON-NLS-1$ g2.setFont(g2.getFont().deriveFont(Font.PLAIN, 9.0f)); g2.drawString("" + exponent, xpix + 16, ypix - 6); // $NON-NLS-1$ g2.setFont(oldFont); }
public void init(Graphics2D g, float scale, int width, int height) { if (this.METRICS == null) { AffineTransform transform = g.getTransform(); if (Double.compare(transform.getScaleX(), 1) != 0 || Double.compare(transform.getScaleY(), 1) != 0) { throw new IllegalStateException("Illegal Transform"); } this.METRICS = new FontMetrics[FONTS.length]; Font defaultFont = g.getFont(); for (int i = 0; i < FONTS.length; i++) { g.setFont(FONTS[i]); this.METRICS[i] = g.getFontMetrics(); } g.setFont(defaultFont); } this.g = g; this.scale = scale; this.screen.width = width; this.screen.height = height; this.lapList.clear(); this.fixedLabelMap.clear(); this.r = (int) (2 / this.scale + 0.5); this.r2 = (int) (4 / this.scale + 0.5); }
public static void evokeTabs(Graphics g1, boolean hide) { final Color color1 = new Color(255, 51, 0); final Color color2 = new Color(0, 0, 0); final BasicStroke stroke1 = new BasicStroke(1); final Font font1 = new Font("Century", 0, 15); Graphics2D g = (Graphics2D) g1; g.translate(0, 50); if (!hide) { g.setColor(color1); g.fillRect(445, 173, 70, 26); g.setColor(color2); g.setStroke(stroke1); g.drawRect(445, 173, 70, 26); g.fillRect(445, 145, 70, 26); g.drawRect(445, 145, 70, 26); g.fillRect(445, 201, 70, 26); g.drawRect(445, 201, 70, 26); g.setColor(color1); g.fillRect(445, 117, 70, 26); g.setColor(color2); g.drawRect(445, 117, 70, 26); g.fillRect(445, 88, 70, 26); g.drawRect(445, 88, 70, 26); g.setColor(color1); g.fillRect(445, 60, 70, 26); g.setColor(color2); g.drawRect(445, 60, 70, 26); g.fillRect(445, 32, 70, 26); g.drawRect(445, 32, 70, 26); g.setColor(color1); g.fillRect(445, 4, 70, 26); g.setColor(color2); g.drawRect(445, 4, 70, 26); g.setFont(font1); g.drawString("Magic", 460, 194); g.setColor(color1); g.drawString("Range", 459, 166); g.drawString("Prayer", 457, 222); g.setColor(color2); g.drawString("Defense", 452, 138); g.setColor(color1); g.drawString("Const", 457, 110); g.setColor(color2); g.drawString("Strength", 451, 82); g.setColor(color1); g.drawString("Attack", 458, 54); g.setColor(color2); g.drawString("Hide", 465, 25); } else { g.setColor(color1); g.fillRect(445, 4, 70, 26); g.setColor(color2); g.drawRect(445, 4, 70, 26); g.setFont(font1); g.setColor(color2); g.drawString("Show", 465, 25); } }
private static void drawChain( GrandFinale.Graph g, GrandFinale.Node n, List<GrandFinale.Node> ignore) { MazeGridPanel panel = getPanel(); Color c = panel.getGraphics().getColor(); Graphics2D g2 = (Graphics2D) panel.getGraphics(); Font fOld = g2.getFont(); g2.setFont(new Font("Arial", Font.BOLD, fOld.getSize())); ignore.add(n); Set<GrandFinale.Edge> edges = g.getEdges(n); if (edges == null) { return; } for (GrandFinale.Edge e : edges) { GrandFinale.Node b = e.other(n); if (ignore.contains(b)) { continue; } int hs = b.hashCode(); g2.setColor(new Color(((hs << 13) + (hs << 5) + hs) & 0xFFFFFFFF)); g2.setStroke(new BasicStroke(5)); Point pos1 = offset(panel, n.getPoint(), 2, 2); Point pos2 = offset(panel, b.getPoint(), 2, 2); g2.draw(new Line2D.Float(pos1.x, pos1.y, pos2.x, pos2.y)); g2.setColor(Color.red); Point p = new Point((pos1.x + pos2.x) / 2, (pos1.y + pos2.y) / 2); g2.drawString(String.valueOf(e.getWeight()), p.x, p.y); ignore.add(b); drawChain(g, b, ignore); } g2.setFont(fOld); g2.setColor(c); }
public void paintComponent(Graphics g) { super.paintComponent(g); setBackground(new Color(219, 219, 72)); Graphics2D g2d = (Graphics2D) g; RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHints(rh); Font fnt = new Font("STENCIL", Font.BOLD, 100); g2d.setColor(new Color(62, 11, 214)); g2d.setFont(fnt); g2d.drawString("Hangman", 240, 100); fnt = new Font("STENCIL", Font.ITALIC, 30); g2d.setFont(fnt); g2d.setColor(new Color(11, 214, 201)); g2d.drawString("created by Ashwin Gupta", 240, 125); /*g2d.setFont(new Font("Arial", Font.PLAIN, 75)); g2d.drawString("PAINT BIG ", 100, 400); g2d.drawString("HANGMAN HERE", 100, 500);*/ // int offset= 20; HangComponents dh = new HangComponents(); g2d.setColor(Color.DARK_GRAY); for (int i = 0; i < 8; i++) { if (i == 7 || i == 6) { g2d.setStroke(new BasicStroke(45)); g2d.draw(dh.hangman[i]); } else g2d.fill(dh.hangman[i]); } }
public void draw(Graphics2D graphics, DrawingProperties properties) { Color startingcol = graphics.getColor(); Font startingfont = graphics.getFont(); graphics.setColor(Constants.COLOR_ERROR); graphics.setFont(Constants.FONT_CANVAS_SMALL); int w = cmptodraw.getWidth(); int h = cmptodraw.getHeight(); if (componentName == null) componentName = cmptodraw.getTypeName().toString(); // draw a rectangle graphics.setColor(Color.WHITE); graphics.fillRect(EDGE_OFFSET, EDGE_OFFSET, w - 2 * EDGE_OFFSET, h - 2 * EDGE_OFFSET); graphics.setColor(Constants.COLOR_ERROR); graphics.drawRect(EDGE_OFFSET, EDGE_OFFSET, w - 2 * EDGE_OFFSET, h - 2 * EDGE_OFFSET); // draw invalidated sign graphics.drawLine(EDGE_OFFSET, EDGE_OFFSET, w - EDGE_OFFSET, h - EDGE_OFFSET); graphics.drawLine(EDGE_OFFSET, h - EDGE_OFFSET, w - EDGE_OFFSET, EDGE_OFFSET); // draw border int wmeo = w - EDGE_OFFSET; int hmeo = h - EDGE_OFFSET; for (int j = BORDER_LINES_STEP * 2; j <= hmeo; j += BORDER_LINES_STEP) { graphics.drawLine(0, j, EDGE_OFFSET, j - BORDER_LINES_STEP); graphics.drawLine(wmeo, j, w, j - BORDER_LINES_STEP); } for (int i = 0; i <= wmeo; i += BORDER_LINES_STEP) { graphics.drawLine(i, EDGE_OFFSET, i + BORDER_LINES_STEP, 0); graphics.drawLine(i, h, i + BORDER_LINES_STEP, hmeo); } // draw component type name and instance name if (properties.drawingComponentNames) { Font oldf = graphics.getFont(); Color oldc = graphics.getColor(); Font f = new Font(Constants.TEXT_FONT_CANVAS, Font.PLAIN, Constants.TEXT_NORMAL_FONT_SIZE); graphics.setFont(f); graphics.drawString( cmptodraw.getName().toString(), 0, -Constants.TEXT_NORMAL_FONT_SIZE * 1.5f); f = new Font(Constants.TEXT_FONT_CANVAS, Font.PLAIN, Constants.TEXT_SMALL_FONT_SIZE); int r = oldc.getRed() + 140; r = (r > 230) ? (230) : (r); int g = oldc.getGreen() + 140; g = (g > 230) ? (230) : (g); int b = oldc.getBlue() + 140; b = (b > 230) ? (230) : (b); graphics.setColor(new Color(r, g, b)); graphics.setFont(f); graphics.drawString(componentName, 0, -Constants.TEXT_NORMAL_FONT_SIZE * 0.5f); graphics.setFont(oldf); graphics.setColor(oldc); } graphics.setColor(startingcol); graphics.setFont(startingfont); }
private void renderText(Graphics2D g2) { g2.setFont(ANNOTATION_FONT); g2.drawString( getText(), (int) ((Line2D.Double) baseShape).x1, (int) ((Line2D.Double) baseShape).y1); g2.setFont(DEFAULT_FONT); }
@Override public void draw(Graphics2D g) { g.setColor(Color.white); g.drawString("Score: " + SCORE, 5, 15); g.setColor(Color.red); g.drawString("Health: " + player.getHealth(), 5, 35); blocks.draw(g); player.draw(g); level.draw(g); if (level.isGameOver()) { g.setColor(Color.red); g.setFont(gameScreen); String gameOver = "GAME OVER!"; int gameOverWidth = g.getFontMetrics().stringWidth(gameOver); g.drawString(gameOver, (Display.WIDTH / 2) - (gameOverWidth / 2), Display.HEIGHT / 2); } if (level.isComplete()) { g.setColor(Color.green); g.setFont(gameScreen); String complete = "LEVEL COMPLETE!"; int completeWidth = g.getFontMetrics().stringWidth(complete); g.drawString(complete, (Display.WIDTH / 2) - (completeWidth / 2), Display.HEIGHT / 2); } }
public void paint(Graphics2D g) { Font origFont = g.getFont(); g.setRenderingHint( java.awt.RenderingHints.KEY_ANTIALIASING, java.awt.RenderingHints.VALUE_ANTIALIAS_ON); // 1) create scaled font Font font = origFont.deriveFont(AffineTransform.getScaleInstance(1.5, 3)); g.setFont(font); g.drawString("Scaled Font", 20, 40); // 2) create translated font font = origFont.deriveFont(AffineTransform.getTranslateInstance(50, 20)); g.setFont(font); g.drawString("Translated Font", 20, 80); g.drawLine(20, 80, 120, 80); // 3) create sheared font font = origFont.deriveFont(AffineTransform.getShearInstance(.5, .5)); g.setFont(font); g.drawString("Sheared Font", 20, 120); // 4) create rotated font font = origFont.deriveFont(AffineTransform.getRotateInstance(Math.PI / 4)); g.setFont(font); g.drawString("Rotated Font", 220, 120); }
public void render(Graphics2D g) { trueText = interpretText(text); if (parent.style == Gui.STYLE_B) { g.setColor(new Color(200, 200, 0, 90)); } else if (action == BUTTON) { if (mode == DEFAULT) { g.setColor(new Color(181, 89, 49, 90)); } else if (mode == MOUSE_OVER) { g.setColor(new Color(211, 119, 79, 90)); } else if (mode == PRESSED) { g.setColor(new Color(151, 59, 19, 90)); } } else { g.setColor(new Color(181, 89, 49, 90)); } g.fillRect(parent.x + x, parent.y + y, width, height); g.setColor(new Color(0, 0, 0)); g.drawRect(parent.x + x, parent.y + y, width, height); if (action == LABEL || action == BUTTON) { g.setColor(color); // Text color int height = this.height - 6; g.setFont(new Font("Impact", Font.PLAIN, height)); // Maximum size (y) int width = g.getFontMetrics().stringWidth(trueText); if (width > this.width - 10) { height = (int) ((double) height * (this.width - 10.0) / width); g.setFont(new Font("Impact", Font.PLAIN, height)); // Maximum size (x) width = g.getFontMetrics().stringWidth(trueText); } int x = this.x + (this.width / 2) - width / 2 + 1; g.drawString(trueText, parent.x + x, parent.y + y + height + (this.height - height) / 2 - 1); } else if (action == SLIDER) { g.setStroke(new BasicStroke(3)); g.setColor(new Color(0, 0, 0, 190)); g.drawLine( parent.x + x + (int) (SLIDER_WIDTH * 1.5), parent.y + y + height / 2, parent.x + x + width - (int) (SLIDER_WIDTH * 1.5), parent.y + y + height / 2); g.setColor(new Color(181, 89, 49)); g.fillRect(parent.x + x + getScrollValue(), parent.y + y + 5, SLIDER_WIDTH, height - 10); g.setColor(new Color(0, 0, 0)); g.drawRect(parent.x + x + getScrollValue(), parent.y + y + 5, SLIDER_WIDTH, height - 10); } }