From 045ca00486e62c89a4da5f880f6f52016e4dd14a Mon Sep 17 00:00:00 2001 From: Wyvest <45589059+Wyvest@users.noreply.github.com> Date: Mon, 25 Jul 2022 22:01:01 +0900 Subject: fix: stop using internal asset classes everywhere (#69) * fix: stop using internal asset classes everywhere new: add wrapper classes for NanoVG rendering and rename original Image wrapper to OneImage * I love regex Co-authored-by: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> --- .../java/cc/polyfrost/oneconfig/gui/SideBar.java | 1 - .../oneconfig/gui/elements/BasicButton.java | 14 +- .../oneconfig/gui/elements/ColorSelector.java | 14 +- .../gui/elements/config/ConfigColorElement.java | 2 +- .../gui/elements/config/ConfigTextBox.java | 3 +- .../gui/elements/text/TextInputField.java | 6 +- .../java/cc/polyfrost/oneconfig/images/Image.java | 327 --------------------- .../cc/polyfrost/oneconfig/images/OneImage.java | 327 +++++++++++++++++++++ .../oneconfig/internal/assets/Images.java | 15 +- .../polyfrost/oneconfig/internal/assets/SVGs.java | 77 +++-- .../cc/polyfrost/oneconfig/renderer/Image.java | 14 + .../oneconfig/renderer/RenderManager.java | 13 +- .../java/cc/polyfrost/oneconfig/renderer/SVG.java | 14 + .../oneconfig/utils/dsl/RenderManagerDSL.kt | 24 +- 14 files changed, 434 insertions(+), 417 deletions(-) delete mode 100644 src/main/java/cc/polyfrost/oneconfig/images/Image.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/images/OneImage.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/renderer/Image.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/renderer/SVG.java (limited to 'src') diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java index b25a8e3..34a5f98 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java @@ -3,7 +3,6 @@ package cc.polyfrost.oneconfig.gui; import cc.polyfrost.oneconfig.gui.animations.Animation; import cc.polyfrost.oneconfig.gui.animations.CubicBezier; import cc.polyfrost.oneconfig.gui.animations.DummyAnimation; -import cc.polyfrost.oneconfig.gui.animations.EaseInOutQuart; import cc.polyfrost.oneconfig.gui.elements.BasicButton; import cc.polyfrost.oneconfig.gui.pages.CreditsPage; import cc.polyfrost.oneconfig.gui.pages.ModConfigPage; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java index afe899d..f98371d 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java @@ -1,11 +1,11 @@ package cc.polyfrost.oneconfig.gui.elements; -import cc.polyfrost.oneconfig.internal.assets.Colors; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.pages.Page; +import cc.polyfrost.oneconfig.internal.assets.Colors; import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.SVG; import cc.polyfrost.oneconfig.renderer.font.Fonts; -import cc.polyfrost.oneconfig.internal.assets.SVGs; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import cc.polyfrost.oneconfig.utils.color.ColorUtils; import org.jetbrains.annotations.NotNull; @@ -13,7 +13,7 @@ import org.jetbrains.annotations.NotNull; public class BasicButton extends BasicElement { protected String text; - protected SVGs icon1, icon2; + protected SVG icon1, icon2; private final int alignment; private final float fontSize, cornerRadius; private final float xSpacing, xPadding; @@ -31,7 +31,7 @@ public class BasicButton extends BasicElement { private Page page; private Runnable runnable; - public BasicButton(int width, int size, String text, SVGs icon1, SVGs icon2, int align, @NotNull ColorPalette colorPalette) { + public BasicButton(int width, int size, String text, SVG icon1, SVG icon2, int align, @NotNull ColorPalette colorPalette) { super(width, 32, colorPalette, true); if (text != null) this.text = text; if (icon1 != null) this.icon1 = icon1; @@ -48,7 +48,7 @@ public class BasicButton extends BasicElement { this.fontSize = size == SIZE_48 ? 20 : (float) (size / 2 - 4); } - public BasicButton(int width, int size, SVGs icon, int align, @NotNull ColorPalette colorPalette) { + public BasicButton(int width, int size, SVG icon, int align, @NotNull ColorPalette colorPalette) { this(width, size, null, icon, null, align, colorPalette); } @@ -156,11 +156,11 @@ public class BasicButton extends BasicElement { this.text = text; } - public void setLeftIcon(SVGs icon) { + public void setLeftIcon(SVG icon) { icon1 = icon; } - public void setRightIcon(SVGs icon) { + public void setRightIcon(SVG icon) { icon2 = icon; } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java index 568567d..d32aa65 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java @@ -102,7 +102,7 @@ public class ColorSelector { recentColors.add(new ColorBox(new OneColor(0, 0, 0, 0))); } - topSlider.setImage(Images.HUE_GRADIENT); + topSlider.setImage(Images.HUE_GRADIENT.filePath); } public void draw(long vg) { @@ -183,7 +183,7 @@ public class ColorSelector { dragging = false; } bottomSlider.setGradient(Colors.TRANSPARENT, color.getRGBNoAlpha()); - RenderManager.drawRoundImage(vg, Images.ALPHA_GRID, x + 16, y + 456, 384, 16, 8f); + RenderManager.drawRoundImage(vg, Images.ALPHA_GRID.filePath, x + 16, y + 456, 384, 16, 8f); bottomSlider.draw(vg, x + 16, y + 456); if (percentMoveMain > 0.96f) { @@ -198,7 +198,7 @@ public class ColorSelector { // draw the color preview RenderManager.drawHollowRoundRect(vg, x + 15, y + 487, 384, 40, Colors.GRAY_300, 12f, 2f); - RenderManager.drawRoundImage(vg, Images.ALPHA_GRID, x + 20, y + 492, 376, 32, 8f); + RenderManager.drawRoundImage(vg, Images.ALPHA_GRID.filePath, x + 20, y + 492, 376, 32, 8f); RenderManager.drawRoundedRect(vg, x + 20, y + 492, 376, 32, color.getRGB(), 8f); inputScissor = InputUtils.blockInputArea(x - 3, y - 3, width + 6, height + 6); @@ -215,7 +215,7 @@ public class ColorSelector { case 0: case 2: //buttons.get(mode).colorAnimation.setPalette(ColorPalette.TERTIARY); - topSlider.setImage(Images.HUE_GRADIENT); + topSlider.setImage(Images.HUE_GRADIENT.filePath); RenderManager.drawHSBBox(vg, x + 16, y + 120, 384, 288, color.getRGBMax(true)); if (mode == 0) { @@ -231,7 +231,7 @@ public class ColorSelector { case 1: //buttons.get(1).colorAnimation.setPalette(ColorPalette.TERTIARY); topSlider.setImage(null); - RenderManager.drawRoundImage(vg, Images.COLOR_WHEEL, x + 64, y + 120, 288, 288, 144f); + RenderManager.drawRoundImage(vg, Images.COLOR_WHEEL.filePath, x + 64, y + 120, 288, 288, 144f); topSlider.setGradient(Colors.BLACK, color.getRGBMax(true)); topSlider.setImage(null); @@ -419,7 +419,7 @@ public class ColorSelector { private static class ColorSlider extends Slider { protected int gradColorStart, gradColorEnd; - protected Images image; + protected String image; protected int color; public ColorSlider(int length, float min, float max, float startValue) { @@ -455,7 +455,7 @@ public class ColorSelector { this.color = color; } - public void setImage(Images image) { + public void setImage(String image) { this.image = image; } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java index a3b45bf..ce6b378 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java @@ -84,7 +84,7 @@ public class ConfigColorElement extends BasicOption { element.update(x1 + 416, y); RenderManager.drawHollowRoundRect(vg, x1 + 415, y - 1, 64, 32, Colors.GRAY_300, 12f, 2f); - RenderManager.drawRoundImage(vg, Images.ALPHA_GRID, x1 + 420, y + 4, 56, 24, 8f); + RenderManager.drawRoundImage(vg, Images.ALPHA_GRID.filePath, x1 + 420, y + 4, 56, 24, 8f); RenderManager.drawRoundedRect(vg, x1 + 420, y + 4, 56, 24, color.getRGB(), 8f); if (element.isClicked() && !open) { open = true; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java index 3d9602b..4f7d0f5 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java @@ -6,6 +6,7 @@ import cc.polyfrost.oneconfig.config.elements.BasicOption; import cc.polyfrost.oneconfig.gui.elements.text.TextInputField; import cc.polyfrost.oneconfig.platform.Platform; import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.SVG; import cc.polyfrost.oneconfig.renderer.font.Fonts; import cc.polyfrost.oneconfig.internal.assets.SVGs; import cc.polyfrost.oneconfig.utils.InputUtils; @@ -46,7 +47,7 @@ public class ConfigTextBox extends BasicOption { textField.draw(vg, x + (size == 1 ? 224 : 352), y); if (secure) { - SVGs icon = textField.getPassword() ? SVGs.EYE_OFF : SVGs.EYE; + final SVG icon = textField.getPassword() ? SVGs.EYE_OFF : SVGs.EYE; boolean hovered = InputUtils.isAreaHovered(x + 967, y + 7, 18, 18) && isEnabled(); int color = hovered ? Colors.WHITE : Colors.WHITE_80; if (hovered && InputUtils.isClicked()) textField.setPassword(!textField.getPassword()); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java index 3c2cb1c..1052487 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java @@ -2,10 +2,10 @@ package cc.polyfrost.oneconfig.gui.elements.text; import cc.polyfrost.oneconfig.gui.elements.BasicElement; import cc.polyfrost.oneconfig.internal.assets.Colors; -import cc.polyfrost.oneconfig.internal.assets.SVGs; import cc.polyfrost.oneconfig.libs.universal.UKeyboard; import cc.polyfrost.oneconfig.platform.Platform; import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.renderer.SVG; import cc.polyfrost.oneconfig.renderer.font.Fonts; import cc.polyfrost.oneconfig.renderer.scissor.Scissor; import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager; @@ -35,12 +35,12 @@ public class TextInputField extends BasicElement { protected boolean onlyNums = false; protected boolean errored = false; protected boolean centered = false; - protected SVGs icon; + protected SVG icon; protected ArrayList wrappedText = null; private long clickTimeD1; private int lines = 1; - public TextInputField(int width, int height, String defaultText, boolean multiLine, boolean password, SVGs icon) { + public TextInputField(int width, int height, String defaultText, boolean multiLine, boolean password, SVG icon) { super(width, height, false); this.multiLine = multiLine; this.defaultText = defaultText; diff --git a/src/main/java/cc/polyfrost/oneconfig/images/Image.java b/src/main/java/cc/polyfrost/oneconfig/images/Image.java deleted file mode 100644 index 16957c1..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/images/Image.java +++ /dev/null @@ -1,327 +0,0 @@ -package cc.polyfrost.oneconfig.images; - -import cc.polyfrost.oneconfig.utils.IOUtils; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import javax.imageio.ImageIO; -import java.awt.*; -import java.awt.geom.AffineTransform; -import java.awt.image.AffineTransformOp; -import java.awt.image.BufferedImage; -import java.io.*; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLEncoder; -import java.util.Base64; -import java.util.Objects; - -/** An Image wrapper class that is used by the OneConfig system.*/ -@SuppressWarnings("unused") -public class Image { - private static final Logger LOGGER = LogManager.getLogger("OneConfig Images"); - private BufferedImage image; - private Graphics2D graphics = null; - private final int width, height; - - /** - * Create a new Image from the file. This can be as a resource location inside your JAR. - * @param filePath The path to the image file. - */ - public Image(String filePath) throws IOException { - image = ImageIO.read(Objects.requireNonNull(Image.class.getResourceAsStream(filePath))); - width = image.getWidth(); - height = image.getHeight(); - } - - /** - * Create a new Image from the file. - * @param is InputStream to the image file. - */ - public Image(InputStream is) throws IOException { - image = ImageIO.read(is); - width = image.getWidth(); - height = image.getHeight(); - } - - /** - * Create a new Image from the file. - * @param file File to the image file. - */ - public Image(File file) throws IOException { - image = ImageIO.read(Objects.requireNonNull(file)); - width = image.getWidth(); - height = image.getHeight(); - } - - /** - * Create a new Image from the BufferedImage. - */ - public Image(BufferedImage image) { - this.image = image; - width = image.getWidth(); - height = image.getHeight(); - } - - /** Create a new blank image with the specified width and height. */ - public Image(int width, int height) { - this.width = width; - this.height = height; - image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); - } - - /** Get the image as a BufferedImage. */ - public BufferedImage getImage() { - return image; - } - - protected void setImage(BufferedImage img) { - image = img; - } - - /** Get the graphics object associated with the image. */ - public Graphics2D getG2D() { - if (graphics == null) { - graphics = image.createGraphics(); - graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - } - return graphics; - } - - - /** Dispose of the graphics object. */ - public void dispose() { - if(graphics != null) { - graphics.dispose(); - graphics = null; - } - } - - /** Get the width of the image. */ - public int getWidth() { - return width; - } - - /** Get the height of the image. */ - public int getHeight() { - return height; - } - - /** Crop the image to the specified width and height. - * @param startX The x coordinate of the top-left corner of the crop. - * @param startY The y coordinate of the top-left corner of the crop. - * @param width The width of the crop. - * @param height The height of the crop. - */ - public void crop(int startX, int startY, int width, int height) { - image = image.getSubimage(startX, startY, width, height); - } - - /** Get the color of a pixel in the image. */ - public void getColorAtPos(int x, int y) { - image.getRGB(x, y); - } - - /** Set the color of a pixel in the image. */ - public void setColorAtPos(int x, int y, int argb) { - image.setRGB(x, y, argb); - } - - /** Attempt to save the image to the specified file. */ - public void save(String filePath) throws IOException { - ImageIO.write(image, "png", new File(filePath)); - } - - /** Attempt to upload the image to Imgur, returning the JSON that the server replied with. */ - public JsonObject uploadToImgur() { - try { - // thanks stack overflow for the help with this :_) - URL url = new URL("https://api.imgur.com/3/image"); - HttpURLConnection con = (HttpURLConnection) url.openConnection(); - con.setDoInput(true); - con.setDoOutput(true); - con.setRequestMethod("POST"); - con.setRequestProperty("Authorization", "Client-ID " + "6cfc432a9954f4d"); - con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - con.connect(); - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - ImageIO.write(image, "png", byteOut); - String encoded = URLEncoder.encode("image", "UTF-8") + "=" + URLEncoder.encode(Base64.getEncoder().encodeToString(byteOut.toByteArray()), "UTF-8"); - BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(con.getOutputStream())); - writer.write(encoded); - byteOut.close(); - writer.close(); - if(con.getResponseCode() != 200) { - LOGGER.error("Error uploading image to Imgur: " + con.getResponseCode()); - return null; - } - - BufferedReader rd = new BufferedReader(new InputStreamReader(con.getInputStream())); - JsonObject object = new JsonParser().parse(rd).getAsJsonObject(); - rd.close(); - - return object; - } catch (Exception e) { - e.printStackTrace(); - LOGGER.error("Error uploading image to Imgur."); - return null; - } - } - - /** Attempt to upload the image to Imgur, returning the URL that the image is hosted at. - * @param copy weather or not to copy the URL to the clipboard as well. */ - public String uploadToImgur(boolean copy) { - JsonObject object = uploadToImgur(); - String link = object.get("data").getAsJsonObject().get("link").getAsString(); - if(copy) IOUtils.copyStringToClipboard(link); - return link; - } - - /** Copy the image to the system clipboard and delete the graphics object. */ - public void copyToClipboard() { - IOUtils.copyImageToClipboard(image); - dispose(); - } - - // MASK METHODS - public void setBrightness(float brightness) { - maskColor(new Color(0f,0f,0f,brightness)); - } - - public void maskColor(Color color) { - Graphics2D g2d = getG2D(); - g2d.setColor(color); - g2d.fillRect(0,0,width,height); - dispose(); - } - - public void maskPaint(Paint paint) { - Graphics2D g2d = getG2D(); - g2d.setPaint(paint); - g2d.fillRect(0,0,width,height); - dispose(); - } - - // LINE METHODS - public void drawLine(Stroke stroke, int sx, int sy, int ex, int ey) { - Graphics2D g2d = getG2D(); - g2d.setStroke(stroke); - g2d.drawLine(sx, sy, ex, ey); - dispose(); - } - - public void drawLine(int sx, int sy, int ex, int ey, int width) { - drawLine(new BasicStroke(width), sx, sy, ex, ey); - } - - // SHAPE METHODS - public void drawTexturedRect(TexturePaint paint, int x, int y, int width, int height) { - Graphics2D g2d = getG2D(); - g2d.setPaint(paint); - g2d.fillRect(x, y, width, height); - dispose(); - } - - public void drawRect(int x, int y, int width, int height, int color) { - Graphics2D g2d = getG2D(); - g2d.setColor(new Color(color, true)); - g2d.drawRect(x, y, width, height); - dispose(); - } - public void drawRoundedRect(int x, int y, int width, int height, int radius, int color) { - Graphics2D g2d = getG2D(); - g2d.setColor(new Color(color, true)); - g2d.fillRoundRect(x, y, width, height, radius, radius); - dispose(); - } - - public void drawPolygon(int x, int y, Polygon polygon, int color) { - Graphics2D g2d = getG2D(); - g2d.setColor(new Color(color, true)); - g2d.translate(x, y); - g2d.fillPolygon(polygon); - dispose(); - } - - public void drawOval(int x, int y, int width, int height, int color) { - Graphics2D g2d = getG2D(); - g2d.setColor(new Color(color, true)); - g2d.fillOval(x, y, width, height); - dispose(); - } - - public void drawTriangle(Point p1, Point p2, Point p3, int color) { - Graphics2D g2d = getG2D(); - g2d.setColor(new Color(color, true)); - g2d.fillPolygon(new int[] {p1.x, p2.x, p3.x}, new int[] {p1.y, p2.y, p3.y}, 3); - dispose(); - } - - public void drawCircle(int x, int y, int radius, int color) { - Graphics2D g2d = getG2D(); - g2d.setColor(new Color(color, true)); - g2d.fillRoundRect(x, y, radius, radius, radius, radius); - dispose(); - } - - - - - - - // STRING METHODS - public void drawString(String text, int x, int y, Font font, int color) { - Graphics2D g2d = getG2D(); - g2d.setColor(new Color(color, true)); - g2d.setFont(font); - g2d.drawString(text, x, y); - dispose(); - } - - - - // IMAGE METHODS - /** Scale the image by the given factor (1.0 = no change). */ - public void scale(double sx, double sy) { - if(sx == 1.0 && sy == 1.0) return; - BufferedImage old = image; - image = new BufferedImage((int) (Math.abs(sx * image.getWidth())), (int) (Math.abs(image.getHeight() * sy)), BufferedImage.TYPE_INT_ARGB); - Graphics2D g2d = getG2D(); - g2d.drawImage(old, new AffineTransformOp(AffineTransform.getScaleInstance(sx, sy), AffineTransformOp.TYPE_BILINEAR), 0, 0); - dispose(); - } - /** - * Scale the image to the specified width and height. - */ - public void setSize(int width, int height) { - if(width == this.width && height == this.height) return; - scale(width / (double) this.width, height / (double) this.height); - } - - /** Rotate the image by the given angle (in degrees). */ - public void rotate(double angle) { - if(angle == 0 || angle == 360) return; - Graphics2D g2d = getG2D(); - g2d.drawImage(image, new AffineTransformOp(AffineTransform.getRotateInstance(Math.toRadians(angle)), AffineTransformOp.TYPE_BILINEAR), 0, 0); - dispose(); - } - - /** Translate the image by the given amount. */ - public void translate(int moveX, int moveY) { - Graphics2D g2d = getG2D(); - g2d.drawImage(image, new AffineTransformOp(AffineTransform.getTranslateInstance(moveX, moveY), AffineTransformOp.TYPE_BILINEAR), 0, 0); - dispose(); - } - - /** Flip the image horizontally. */ - public void flipHorizontal() { - scale(-1, 1); - } - - /** Flip the image vertically. */ - public void flipVertical() { - scale(1, -1); - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/images/OneImage.java b/src/main/java/cc/polyfrost/oneconfig/images/OneImage.java new file mode 100644 index 0000000..20bfc2c --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/images/OneImage.java @@ -0,0 +1,327 @@ +package cc.polyfrost.oneconfig.images; + +import cc.polyfrost.oneconfig.utils.IOUtils; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.geom.AffineTransform; +import java.awt.image.AffineTransformOp; +import java.awt.image.BufferedImage; +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.util.Base64; +import java.util.Objects; + +/** An Image wrapper class that is used by the OneConfig system.*/ +@SuppressWarnings("unused") +public class OneImage { + private static final Logger LOGGER = LogManager.getLogger("OneConfig Images"); + private BufferedImage image; + private Graphics2D graphics = null; + private final int width, height; + + /** + * Create a new OneImage from the file. This can be as a resource location inside your JAR. + * @param filePath The path to the image file. + */ + public OneImage(String filePath) throws IOException { + image = ImageIO.read(Objects.requireNonNull(OneImage.class.getResourceAsStream(filePath))); + width = image.getWidth(); + height = image.getHeight(); + } + + /** + * Create a new OneImage from the file. + * @param is InputStream to the image file. + */ + public OneImage(InputStream is) throws IOException { + image = ImageIO.read(is); + width = image.getWidth(); + height = image.getHeight(); + } + + /** + * Create a new OneImage from the file. + * @param file File to the image file. + */ + public OneImage(File file) throws IOException { + image = ImageIO.read(Objects.requireNonNull(file)); + width = image.getWidth(); + height = image.getHeight(); + } + + /** + * Create a new OneImage from the BufferedImage. + */ + public OneImage(BufferedImage image) { + this.image = image; + width = image.getWidth(); + height = image.getHeight(); + } + + /** Create a new blank image with the specified width and height. */ + public OneImage(int width, int height) { + this.width = width; + this.height = height; + image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); + } + + /** Get the image as a BufferedImage. */ + public BufferedImage getImage() { + return image; + } + + protected void setImage(BufferedImage img) { + image = img; + } + + /** Get the graphics object associated with the image. */ + public Graphics2D getG2D() { + if (graphics == null) { + graphics = image.createGraphics(); + graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + } + return graphics; + } + + + /** Dispose of the graphics object. */ + public void dispose() { + if(graphics != null) { + graphics.dispose(); + graphics = null; + } + } + + /** Get the width of the image. */ + public int getWidth() { + return width; + } + + /** Get the height of the image. */ + public int getHeight() { + return height; + } + + /** Crop the image to the specified width and height. + * @param startX The x coordinate of the top-left corner of the crop. + * @param startY The y coordinate of the top-left corner of the crop. + * @param width The width of the crop. + * @param height The height of the crop. + */ + public void crop(int startX, int startY, int width, int height) { + image = image.getSubimage(startX, startY, width, height); + } + + /** Get the color of a pixel in the image. */ + public void getColorAtPos(int x, int y) { + image.getRGB(x, y); + } + + /** Set the color of a pixel in the image. */ + public void setColorAtPos(int x, int y, int argb) { + image.setRGB(x, y, argb); + } + + /** Attempt to save the image to the specified file. */ + public void save(String filePath) throws IOException { + ImageIO.write(image, "png", new File(filePath)); + } + + /** Attempt to upload the image to Imgur, returning the JSON that the server replied with. */ + public JsonObject uploadToImgur() { + try { + // thanks stack overflow for the help with this :_) + URL url = new URL("https://api.imgur.com/3/image"); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setDoInput(true); + con.setDoOutput(true); + con.setRequestMethod("POST"); + con.setRequestProperty("Authorization", "Client-ID " + "6cfc432a9954f4d"); + con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + con.connect(); + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + ImageIO.write(image, "png", byteOut); + String encoded = URLEncoder.encode("image", "UTF-8") + "=" + URLEncoder.encode(Base64.getEncoder().encodeToString(byteOut.toByteArray()), "UTF-8"); + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(con.getOutputStream())); + writer.write(encoded); + byteOut.close(); + writer.close(); + if(con.getResponseCode() != 200) { + LOGGER.error("Error uploading image to Imgur: " + con.getResponseCode()); + return null; + } + + BufferedReader rd = new BufferedReader(new InputStreamReader(con.getInputStream())); + JsonObject object = new JsonParser().parse(rd).getAsJsonObject(); + rd.close(); + + return object; + } catch (Exception e) { + e.printStackTrace(); + LOGGER.error("Error uploading image to Imgur."); + return null; + } + } + + /** Attempt to upload the image to Imgur, returning the URL that the image is hosted at. + * @param copy weather or not to copy the URL to the clipboard as well. */ + public String uploadToImgur(boolean copy) { + JsonObject object = uploadToImgur(); + String link = object.get("data").getAsJsonObject().get("link").getAsString(); + if(copy) IOUtils.copyStringToClipboard(link); + return link; + } + + /** Copy the image to the system clipboard and delete the graphics object. */ + public void copyToClipboard() { + IOUtils.copyImageToClipboard(image); + dispose(); + } + + // MASK METHODS + public void setBrightness(float brightness) { + maskColor(new Color(0f,0f,0f,brightness)); + } + + public void maskColor(Color color) { + Graphics2D g2d = getG2D(); + g2d.setColor(color); + g2d.fillRect(0,0,width,height); + dispose(); + } + + public void maskPaint(Paint paint) { + Graphics2D g2d = getG2D(); + g2d.setPaint(paint); + g2d.fillRect(0,0,width,height); + dispose(); + } + + // LINE METHODS + public void drawLine(Stroke stroke, int sx, int sy, int ex, int ey) { + Graphics2D g2d = getG2D(); + g2d.setStroke(stroke); + g2d.drawLine(sx, sy, ex, ey); + dispose(); + } + + public void drawLine(int sx, int sy, int ex, int ey, int width) { + drawLine(new BasicStroke(width), sx, sy, ex, ey); + } + + // SHAPE METHODS + public void drawTexturedRect(TexturePaint paint, int x, int y, int width, int height) { + Graphics2D g2d = getG2D(); + g2d.setPaint(paint); + g2d.fillRect(x, y, width, height); + dispose(); + } + + public void drawRect(int x, int y, int width, int height, int color) { + Graphics2D g2d = getG2D(); + g2d.setColor(new Color(color, true)); + g2d.drawRect(x, y, width, height); + dispose(); + } + public void drawRoundedRect(int x, int y, int width, int height, int radius, int color) { + Graphics2D g2d = getG2D(); + g2d.setColor(new Color(color, true)); + g2d.fillRoundRect(x, y, width, height, radius, radius); + dispose(); + } + + public void drawPolygon(int x, int y, Polygon polygon, int color) { + Graphics2D g2d = getG2D(); + g2d.setColor(new Color(color, true)); + g2d.translate(x, y); + g2d.fillPolygon(polygon); + dispose(); + } + + public void drawOval(int x, int y, int width, int height, int color) { + Graphics2D g2d = getG2D(); + g2d.setColor(new Color(color, true)); + g2d.fillOval(x, y, width, height); + dispose(); + } + + public void drawTriangle(Point p1, Point p2, Point p3, int color) { + Graphics2D g2d = getG2D(); + g2d.setColor(new Color(color, true)); + g2d.fillPolygon(new int[] {p1.x, p2.x, p3.x}, new int[] {p1.y, p2.y, p3.y}, 3); + dispose(); + } + + public void drawCircle(int x, int y, int radius, int color) { + Graphics2D g2d = getG2D(); + g2d.setColor(new Color(color, true)); + g2d.fillRoundRect(x, y, radius, radius, radius, radius); + dispose(); + } + + + + + + + // STRING METHODS + public void drawString(String text, int x, int y, Font font, int color) { + Graphics2D g2d = getG2D(); + g2d.setColor(new Color(color, true)); + g2d.setFont(font); + g2d.drawString(text, x, y); + dispose(); + } + + + + // IMAGE METHODS + /** Scale the image by the given factor (1.0 = no change). */ + public void scale(double sx, double sy) { + if(sx == 1.0 && sy == 1.0) return; + BufferedImage old = image; + image = new BufferedImage((int) (Math.abs(sx * image.getWidth())), (int) (Math.abs(image.getHeight() * sy)), BufferedImage.TYPE_INT_ARGB); + Graphics2D g2d = getG2D(); + g2d.drawImage(old, new AffineTransformOp(AffineTransform.getScaleInstance(sx, sy), AffineTransformOp.TYPE_BILINEAR), 0, 0); + dispose(); + } + /** + * Scale the image to the specified width and height. + */ + public void setSize(int width, int height) { + if(width == this.width && height == this.height) return; + scale(width / (double) this.width, height / (double) this.height); + } + + /** Rotate the image by the given angle (in degrees). */ + public void rotate(double angle) { + if(angle == 0 || angle == 360) return; + Graphics2D g2d = getG2D(); + g2d.drawImage(image, new AffineTransformOp(AffineTransform.getRotateInstance(Math.toRadians(angle)), AffineTransformOp.TYPE_BILINEAR), 0, 0); + dispose(); + } + + /** Translate the image by the given amount. */ + public void translate(int moveX, int moveY) { + Graphics2D g2d = getG2D(); + g2d.drawImage(image, new AffineTransformOp(AffineTransform.getTranslateInstance(moveX, moveY), AffineTransformOp.TYPE_BILINEAR), 0, 0); + dispose(); + } + + /** Flip the image horizontally. */ + public void flipHorizontal() { + scale(-1, 1); + } + + /** Flip the image vertically. */ + public void flipVertical() { + scale(1, -1); + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/assets/Images.java b/src/main/java/cc/polyfrost/oneconfig/internal/assets/Images.java index b7dc9cc..1007be7 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/assets/Images.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/assets/Images.java @@ -1,6 +1,7 @@ package cc.polyfrost.oneconfig.internal.assets; import cc.polyfrost.oneconfig.renderer.AssetLoader; +import cc.polyfrost.oneconfig.renderer.Image; /** * An enum of images used in OneConfig. @@ -8,14 +9,8 @@ import cc.polyfrost.oneconfig.renderer.AssetLoader; * @see cc.polyfrost.oneconfig.renderer.RenderManager#drawImage(long, String, float, float, float, float, int) * @see AssetLoader */ -public enum Images { - HUE_GRADIENT("/assets/oneconfig/options/HueGradient.png"), - COLOR_WHEEL("/assets/oneconfig/options/ColorWheel.png"), - ALPHA_GRID("/assets/oneconfig/options/AlphaGrid.png"); - - public final String filePath; - - Images(String filePath) { - this.filePath = filePath; - } +public class Images { + public static final Image HUE_GRADIENT = new Image("/assets/oneconfig/options/HueGradient.png"); + public static final Image COLOR_WHEEL = new Image("/assets/oneconfig/options/ColorWheel.png"); + public static final Image ALPHA_GRID = new Image("/assets/oneconfig/options/AlphaGrid.png"); } \ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/assets/SVGs.java b/src/main/java/cc/polyfrost/oneconfig/internal/assets/SVGs.java index eaad4ba..d0e05bf 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/assets/SVGs.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/assets/SVGs.java @@ -1,6 +1,7 @@ package cc.polyfrost.oneconfig.internal.assets; import cc.polyfrost.oneconfig.renderer.AssetLoader; +import cc.polyfrost.oneconfig.renderer.SVG; /** * An enum of SVGs used in OneConfig. @@ -8,47 +9,41 @@ import cc.polyfrost.oneconfig.renderer.AssetLoader; * @see cc.polyfrost.oneconfig.renderer.RenderManager#drawSvg(long, String, float, float, float, float, int) * @see AssetLoader */ -public enum SVGs { - ONECONFIG("/assets/oneconfig/icons/OneConfig.svg"), - ONECONFIG_OFF("/assets/oneconfig/icons/OneConfigOff.svg"), - COPYRIGHT_FILL("/assets/oneconfig/icons/CopyrightFill.svg"), - APERTURE_FILL("/assets/oneconfig/icons/ApertureFill.svg"), - ARROWS_CLOCKWISE_BOLD("/assets/oneconfig/icons/ArrowsClockwiseBold.svg"), - FADERS_HORIZONTAL_BOLD("/assets/oneconfig/icons/FadersHorizontalBold.svg"), - GAUGE_FILL("/assets/oneconfig/icons/GaugeFill.svg"), - GEAR_SIX_FILL("/assets/oneconfig/icons/GearSixFill.svg"), - MAGNIFYING_GLASS_BOLD("/assets/oneconfig/icons/MagnifyingGlassBold.svg"), - NOTE_PENCIL_BOLD("/assets/oneconfig/icons/NotePencilBold.svg"), - PAINT_BRUSH_BROAD_FILL("/assets/oneconfig/icons/PaintBrushBroadFill.svg"), - USER_SWITCH_FILL("/assets/oneconfig/icons/UserSwitchFill.svg"), - X_CIRCLE_BOLD("/assets/oneconfig/icons/XCircleBold.svg"), - CARET_LEFT("/assets/oneconfig/icons/CaretLeftBold.svg"), - CARET_RIGHT("/assets/oneconfig/icons/CaretRightBold.svg"), +public class SVGs { + public static final SVG ONECONFIG = new SVG("/assets/oneconfig/icons/OneConfig.svg"); + public static final SVG ONECONFIG_OFF = new SVG("/assets/oneconfig/icons/OneConfigOff.svg"); + public static final SVG COPYRIGHT_FILL = new SVG("/assets/oneconfig/icons/CopyrightFill.svg"); + public static final SVG APERTURE_FILL = new SVG("/assets/oneconfig/icons/ApertureFill.svg"); + public static final SVG ARROWS_CLOCKWISE_BOLD = new SVG("/assets/oneconfig/icons/ArrowsClockwiseBold.svg"); + public static final SVG FADERS_HORIZONTAL_BOLD = new SVG("/assets/oneconfig/icons/FadersHorizontalBold.svg"); + public static final SVG GAUGE_FILL = new SVG("/assets/oneconfig/icons/GaugeFill.svg"); + public static final SVG GEAR_SIX_FILL = new SVG("/assets/oneconfig/icons/GearSixFill.svg"); + public static final SVG MAGNIFYING_GLASS_BOLD = new SVG("/assets/oneconfig/icons/MagnifyingGlassBold.svg"); + public static final SVG NOTE_PENCIL_BOLD = new SVG("/assets/oneconfig/icons/NotePencilBold.svg"); + public static final SVG PAINT_BRUSH_BROAD_FILL = new SVG("/assets/oneconfig/icons/PaintBrushBroadFill.svg"); + public static final SVG USER_SWITCH_FILL = new SVG("/assets/oneconfig/icons/UserSwitchFill.svg"); + public static final SVG X_CIRCLE_BOLD = new SVG("/assets/oneconfig/icons/XCircleBold.svg"); + public static final SVG CARET_LEFT = new SVG("/assets/oneconfig/icons/CaretLeftBold.svg"); + public static final SVG CARET_RIGHT = new SVG("/assets/oneconfig/icons/CaretRightBold.svg"); // OLD ICONS - BOX("/assets/oneconfig/old-icons/Box.svg"), - CHECKBOX_TICK("/assets/oneconfig/old-icons/CheckboxTick.svg"), - CHECK_CIRCLE("/assets/oneconfig/old-icons/CheckCircle.svg"), - CHEVRON_DOWN("/assets/oneconfig/old-icons/ChevronDown.svg"), - CHEVRON_UP("/assets/oneconfig/old-icons/ChevronUp.svg"), - COPY("/assets/oneconfig/old-icons/Copy.svg"), - DROPDOWN_LIST("/assets/oneconfig/old-icons/DropdownList.svg"), - ERROR("/assets/oneconfig/old-icons/Error.svg"), - EYE("/assets/oneconfig/old-icons/Eye.svg"), - EYE_OFF("/assets/oneconfig/old-icons/EyeOff.svg"), - HEART_FILL("/assets/oneconfig/old-icons/HeartFill.svg"), - HEART_OUTLINE("/assets/oneconfig/old-icons/HeartOutline.svg"), - HELP_CIRCLE("/assets/oneconfig/old-icons/HelpCircle.svg"), - HISTORY("/assets/oneconfig/old-icons/History.svg"), - INFO_CIRCLE("/assets/oneconfig/old-icons/InfoCircle.svg"), - KEYSTROKE("/assets/oneconfig/old-icons/Keystroke.svg"), - PASTE("/assets/oneconfig/old-icons/Paste.svg"), - POP_OUT("/assets/oneconfig/old-icons/PopOut.svg"), - WARNING("/assets/oneconfig/old-icons/Warning.svg"); - - public final String filePath; - - SVGs(String filePath) { - this.filePath = filePath; - } + public static final SVG BOX = new SVG("/assets/oneconfig/old-icons/Box.svg"); + public static final SVG CHECKBOX_TICK = new SVG("/assets/oneconfig/old-icons/CheckboxTick.svg"); + public static final SVG CHECK_CIRCLE = new SVG("/assets/oneconfig/old-icons/CheckCircle.svg"); + public static final SVG CHEVRON_DOWN = new SVG("/assets/oneconfig/old-icons/ChevronDown.svg"); + public static final SVG CHEVRON_UP = new SVG("/assets/oneconfig/old-icons/ChevronUp.svg"); + public static final SVG COPY = new SVG("/assets/oneconfig/old-icons/Copy.svg"); + public static final SVG DROPDOWN_LIST = new SVG("/assets/oneconfig/old-icons/DropdownList.svg"); + public static final SVG ERROR = new SVG("/assets/oneconfig/old-icons/Error.svg"); + public static final SVG EYE = new SVG("/assets/oneconfig/old-icons/Eye.svg"); + public static final SVG EYE_OFF = new SVG("/assets/oneconfig/old-icons/EyeOff.svg"); + public static final SVG HEART_FILL = new SVG("/assets/oneconfig/old-icons/HeartFill.svg"); + public static final SVG HEART_OUTLINE = new SVG("/assets/oneconfig/old-icons/HeartOutline.svg"); + public static final SVG HELP_CIRCLE = new SVG("/assets/oneconfig/old-icons/HelpCircle.svg"); + public static final SVG HISTORY = new SVG("/assets/oneconfig/old-icons/History.svg"); + public static final SVG INFO_CIRCLE = new SVG("/assets/oneconfig/old-icons/InfoCircle.svg"); + public static final SVG KEYSTROKE = new SVG("/assets/oneconfig/old-icons/Keystroke.svg"); + public static final SVG PASTE = new SVG("/assets/oneconfig/old-icons/Paste.svg"); + public static final SVG POP_OUT = new SVG("/assets/oneconfig/old-icons/PopOut.svg"); + public static final SVG WARNING = new SVG("/assets/oneconfig/old-icons/Warning.svg"); } diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/Image.java b/src/main/java/cc/polyfrost/oneconfig/renderer/Image.java new file mode 100644 index 0000000..fab70a4 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/renderer/Image.java @@ -0,0 +1,14 @@ +package cc.polyfrost.oneconfig.renderer; + +/** + * Data class storing an image. + * This class is purely a data class, and does not contain any logic. It does not need to be used unless you want to + * differentiate between a String and an image. + */ +public class Image { + public final String filePath; + + public Image(String filePath) { + this.filePath = filePath; + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java index 5f8ea11..2e44980 100644 --- a/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java @@ -3,7 +3,6 @@ package cc.polyfrost.oneconfig.renderer; import cc.polyfrost.oneconfig.config.data.InfoType; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.internal.assets.Colors; -import cc.polyfrost.oneconfig.internal.assets.Images; import cc.polyfrost.oneconfig.internal.assets.SVGs; import cc.polyfrost.oneconfig.libs.universal.UGraphics; import cc.polyfrost.oneconfig.libs.universal.UResolution; @@ -377,7 +376,7 @@ public final class RenderManager { * * @see RenderManager#drawImage(long, String, float, float, float, float) */ - public static void drawImage(long vg, Images filePath, float x, float y, float width, float height) { + public static void drawImage(long vg, Image filePath, float x, float y, float width, float height) { drawImage(vg, filePath.filePath, x, y, width, height); } @@ -386,7 +385,7 @@ public final class RenderManager { * * @see RenderManager#drawImage(long, String, float, float, float, float, int) */ - public static void drawImage(long vg, Images filePath, float x, float y, float width, float height, int color) { + public static void drawImage(long vg, Image filePath, float x, float y, float width, float height, int color) { drawImage(vg, filePath.filePath, x, y, width, height, color); } @@ -419,7 +418,7 @@ public final class RenderManager { * * @see RenderManager#drawRoundImage(long, String, float, float, float, float, float) */ - public static void drawRoundImage(long vg, Images filePath, float x, float y, float width, float height, float radius) { + public static void drawRoundImage(long vg, Image filePath, float x, float y, float width, float height, float radius) { drawRoundImage(vg, filePath.filePath, x, y, width, height, radius); } @@ -610,7 +609,7 @@ public final class RenderManager { * * @see RenderManager#drawSvg(long, String, float, float, float, float) */ - public static void drawSvg(long vg, SVGs svg, float x, float y, float width, float height) { + public static void drawSvg(long vg, SVG svg, float x, float y, float width, float height) { drawSvg(vg, svg.filePath, x, y, width, height); } @@ -619,7 +618,7 @@ public final class RenderManager { * * @see RenderManager#drawSvg(long, String, float, float, float, float, int) */ - public static void drawSvg(long vg, SVGs svg, float x, float y, float width, float height, int color) { + public static void drawSvg(long vg, SVG svg, float x, float y, float width, float height, int color) { drawSvg(vg, svg.filePath, x, y, width, height, color); } @@ -633,7 +632,7 @@ public final class RenderManager { * @param size The diameter. */ public static void drawInfo(long vg, InfoType type, float x, float y, float size) { - SVGs icon = null; + SVG icon = null; int colorOuter = 0; int colorInner = 0; switch (type) { diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/SVG.java b/src/main/java/cc/polyfrost/oneconfig/renderer/SVG.java new file mode 100644 index 0000000..0aab043 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/renderer/SVG.java @@ -0,0 +1,14 @@ +package cc.polyfrost.oneconfig.renderer; + +/** + * Data class storing an SVG image. + * This class is purely a data class, and does not contain any logic. It does not need to be used unless you want to + * differentiate between a String and an SVG image. + */ +public class SVG { + public final String filePath; + + public SVG(String filePath) { + this.filePath = filePath; + } +} diff --git a/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/RenderManagerDSL.kt b/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/RenderManagerDSL.kt index 21c33f0..2665c7f 100644 --- a/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/RenderManagerDSL.kt +++ b/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/RenderManagerDSL.kt @@ -3,8 +3,8 @@ package cc.polyfrost.oneconfig.utils.dsl import cc.polyfrost.oneconfig.config.data.InfoType import cc.polyfrost.oneconfig.renderer.RenderManager import cc.polyfrost.oneconfig.renderer.font.Font -import cc.polyfrost.oneconfig.internal.assets.Images -import cc.polyfrost.oneconfig.internal.assets.SVGs +import cc.polyfrost.oneconfig.renderer.Image +import cc.polyfrost.oneconfig.renderer.SVG import cc.polyfrost.oneconfig.utils.color.ColorUtils import org.lwjgl.nanovg.NVGColor @@ -161,16 +161,16 @@ fun Long.drawImage(filePath: String, x: Number, y: Number, width: Number, height fun VG.drawImage(filePath: String, x: Number, y: Number, width: Number, height: Number, color: Int) = instance.drawImage(filePath, x, y, width, height, color) -fun Long.drawImage(image: Images, x: Number, y: Number, width: Number, height: Number) = +fun Long.drawImage(image: Image, x: Number, y: Number, width: Number, height: Number) = RenderManager.drawImage(this, image, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat()) -fun VG.drawImage(image: Images, x: Number, y: Number, width: Number, height: Number) = +fun VG.drawImage(image: Image, x: Number, y: Number, width: Number, height: Number) = instance.drawImage(image, x, y, width, height) -fun Long.drawImage(image: Images, x: Number, y: Number, width: Number, height: Number, color: Int) = +fun Long.drawImage(image: Image, x: Number, y: Number, width: Number, height: Number, color: Int) = RenderManager.drawImage(this, image, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), color) -fun VG.drawImage(image: Images, x: Number, y: Number, width: Number, height: Number, color: Int) = +fun VG.drawImage(image: Image, x: Number, y: Number, width: Number, height: Number, color: Int) = instance.drawImage(image, x, y, width, height, color) @@ -182,12 +182,12 @@ fun Long.drawRoundedImage(filePath: String, x: Number, y: Number, width: Number, fun VG.drawRoundedImage(filePath: String, x: Number, y: Number, width: Number, height: Number, radius: Number) = instance.drawRoundedImage(filePath, x, y, width, height, radius) -fun Long.drawRoundedImage(image: Images, x: Number, y: Number, width: Number, height: Number, radius: Number) = +fun Long.drawRoundedImage(image: Image, x: Number, y: Number, width: Number, height: Number, radius: Number) = RenderManager.drawRoundImage( this, image, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), radius.toFloat() ) -fun VG.drawRoundedImage(image: Images, x: Number, y: Number, width: Number, height: Number, radius: Number) = +fun VG.drawRoundedImage(image: Image, x: Number, y: Number, width: Number, height: Number, radius: Number) = instance.drawRoundedImage(image, x, y, width, height, radius) @@ -248,16 +248,16 @@ fun Long.drawSVG(filePath: String, x: Number, y: Number, width: Number, height: fun VG.drawSVG(filePath: String, x: Number, y: Number, width: Number, height: Number, color: Int) = instance.drawSVG(filePath, x, y, width, height, color) -fun Long.drawSVG(svg: SVGs, x: Number, y: Number, width: Number, height: Number) = +fun Long.drawSVG(svg: SVG, x: Number, y: Number, width: Number, height: Number) = RenderManager.drawSvg(this, svg, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat()) -fun VG.drawSVG(svg: SVGs, x: Number, y: Number, width: Number, height: Number) = +fun VG.drawSVG(svg: SVG, x: Number, y: Number, width: Number, height: Number) = instance.drawSVG(svg, x, y, width, height) -fun Long.drawSVG(svg: SVGs, x: Number, y: Number, width: Number, height: Number, color: Int) = +fun Long.drawSVG(svg: SVG, x: Number, y: Number, width: Number, height: Number, color: Int) = RenderManager.drawSvg(this, svg, x.toFloat(), y.toFloat(), width.toFloat(), height.toFloat(), color) -fun VG.drawSVG(svg: SVGs, x: Number, y: Number, width: Number, height: Number, color: Int) = +fun VG.drawSVG(svg: SVG, x: Number, y: Number, width: Number, height: Number, color: Int) = instance.drawSVG(svg, x, y, width, height, color) -- cgit