BravoTaco Posted September 19, 2019 Posted September 19, 2019 (edited) This will paint a progress bar going left-right or right-left. It has one class and two callable methods: drawProgressBar() || drawReversedProgressBar() Example Usage In onPaint() with the Graphics2D named g: Spoiler Defining The Colors To Use: Spoiler ProgressBar.drawProgressBar(15, 260, 160, 8, 8, 8, getConfigs().get(243), maxValue, Color.black, Color.cyan, g); ProgressBar.drawReversedProgressBar(15, 230, 160, 8, 8, 8, currentTime, maxTime, Color.black, Color.cyan, g); Not Defining Colors: Spoiler ProgressBar.drawProgressBar(15, 260, 160, 8, 8, 8, getConfigs().get(243), maxValue, g); ProgressBar.drawReversedProgressBar(15, 230, 160, 8, 8, 8, currentTime, maxTime, g); Code: Spoiler import java.awt.*; public abstract class ProgressBar { public static void drawProgressBar(int xPos, int yPos, int width, int height, int arcWidth, int arcHeight, float currentValue, float maxValue, Color borderColor, Color fillColor, Graphics2D g) { filledProgressBar(currentValue, maxValue, width, xPos, yPos, height, arcWidth, arcHeight, fillColor, g); progressBar(xPos, yPos, width, height, arcWidth, arcHeight, borderColor, g); } public static void drawProgressBar(int xPos, int yPos, int width, int height, int arcWidth, int arcHeight, float currentValue, float maxValue, Graphics2D g) { filledProgressBar(currentValue, maxValue, width, xPos, yPos, height, arcWidth, arcHeight, Color.cyan, g); progressBar(xPos, yPos, width, height, arcWidth, arcHeight, Color.black, g); } public static void drawReversedProgressBar(int xPos, int yPos, int width, int height, int arcWidth, int arcHeight, float currentValue, float maxValue, Color borderColor, Color fillColor, Graphics2D g) { reversedFilledProgressBar(currentValue, maxValue, width, xPos, yPos, height, arcWidth, arcHeight, fillColor, g); progressBar(xPos, yPos, width, height, arcWidth, arcHeight, borderColor, g); } public static void drawReversedProgressBar(int xPos, int yPos, int width, int height, int arcWidth, int arcHeight, float currentValue, float maxValue, Graphics2D g) { reversedFilledProgressBar(currentValue, maxValue, width, xPos, yPos, height, arcWidth, arcHeight, Color.cyan, g); progressBar(xPos, yPos, width, height, arcWidth, arcHeight, Color.black, g); } private static void progressBar(int xPos, int yPos, int width, int height, int arcWidth, int arcHeight, Color colorOfBorder, Graphics2D g) { g.setColor(colorOfBorder); g.drawRoundRect(xPos, yPos, width, height, arcWidth, arcHeight); } private static void filledProgressBar(float currentValue, float maxValue, int width, int xPos, int yPos, int height, int arcWidth, int arcHeight, Color colorOfFill, Graphics2D g) { currentValue = (currentValue >= maxValue) ? maxValue : currentValue; g.setColor(colorOfFill); g.fillRoundRect(xPos, yPos, calculateFillAmount(currentValue, maxValue, width), height, arcWidth, arcHeight); } private static void reversedFilledProgressBar(float currentValue, float maxValue, int width, int xPos, int yPos, int height, int arcWidth, int arcHeight, Color colorOfFill, Graphics2D g) { currentValue = (currentValue >= maxValue) ? maxValue : currentValue; g.setColor(colorOfFill); g.fillRoundRect(xPos, yPos, width - calculateFillAmount(currentValue, maxValue, width), height, arcWidth, arcHeight); } private static int calculateFillAmount(float currentValue, float maxValue, int width) { float percentValueOfFillAmount = currentValue / maxValue; return (int) (percentValueOfFillAmount * width); } } Edited September 19, 2019 by BravoTaco 1
BravoTaco Posted September 19, 2019 Author Posted September 19, 2019 4 hours ago, Kramnik said: Very awesome snippet. Will test sometime Thanks! Let me know how it goes.
BravoTaco Posted September 20, 2019 Author Posted September 20, 2019 4 hours ago, Heist said: Sweet! I’ll test this today. Let me know if anything needs added or fixed