Created
February 4, 2018 03:50
-
-
Save Swedz/9b4fe54cc1a6b87219ce49c8648f7115 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.swedz.util.render; | |
import java.awt.BasicStroke; | |
import java.awt.Color; | |
import java.awt.Graphics2D; | |
import java.awt.Stroke; | |
public class Rendering { | |
public static void rectangle(Graphics2D g, int x, int y, int w, int h, int thickness, Color color) { | |
Color old = g.getColor(); | |
Stroke oldStroke = g.getStroke(); | |
g.setColor(color); | |
g.setStroke(new BasicStroke(thickness)); | |
g.drawRect(x, y, w, h); | |
g.setStroke(oldStroke); | |
g.setColor(old); | |
} | |
public static void fillRectangle(Graphics2D g,int x, int y, int w, int h, Color color) { | |
Color old = g.getColor(); | |
g.setColor(color); | |
g.fillRect(x, y, w, h); | |
g.setColor(old); | |
} | |
public static void roundRectangle(Graphics2D g, int x, int y, int w, int h, int aw, int ah, Color color) { | |
Color old = g.getColor(); | |
g.setColor(color); | |
g.drawRoundRect(x, y, w, h, aw, ah); | |
g.setColor(old); | |
} | |
public static void line(Graphics2D g, int x1, int y1, int x2, int y2, int thickness, Color color) { | |
Color old = g.getColor(); | |
Stroke oldStroke = g.getStroke(); | |
g.setColor(color); | |
g.setStroke(new BasicStroke(thickness)); | |
g.drawLine(x1, y1, x2, y2); | |
g.setStroke(oldStroke); | |
g.setColor(old); | |
} | |
public static void string(Graphics2D g, String text, int x, int y, Color color) { | |
Color old = g.getColor(); | |
g.setColor(color); | |
g.drawString(text, x, y); | |
g.setColor(old); | |
} | |
public static void centeredString(Graphics2D g, String text, int x, int width, int y, Color color) { | |
int cx = (x+(width/2))-(g.getFontMetrics().stringWidth(text)/2); | |
Color old = g.getColor(); | |
g.setColor(color); | |
g.drawString(text, cx, y+(g.getFontMetrics().getHeight()/2)); | |
g.setColor(old); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment