diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java index 7b5ec6f8bf..e8fd39065d 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java @@ -241,7 +241,7 @@ public class OverlayRenderer bottomLeftPoint.x += dimension.width + (dimension.width == 0 ? 0 : PADDING); break; case BOTTOM_RIGHT: - bottomRightPoint.x -= dimension.width - (dimension.width == 0 ? 0 : PADDING); + bottomRightPoint.x -= dimension.width + (dimension.width == 0 ? 0 : PADDING); break; case TOP_LEFT: topLeftPoint.y += dimension.height + (dimension.height == 0 ? 0 : PADDING); diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/BackgroundComponent.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/BackgroundComponent.java index 9326193a0a..b38dbe368e 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/BackgroundComponent.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/BackgroundComponent.java @@ -38,10 +38,22 @@ import net.runelite.client.ui.overlay.RenderableEntity; @AllArgsConstructor public class BackgroundComponent implements RenderableEntity { + public static final Color DEFAULT_BACKGROUND_COLOR = new Color(70, 61, 50, 156); + private static final int BORDER_OFFSET = 2; - private static final Color BACKGROUND_COLOR = new Color(70, 61, 50, 156); - private static final Color OUTSIDE_STROKE_COLOR = new Color(56, 48, 35, 255); - private static final Color INSIDE_STROKE_COLOR = new Color(90, 82, 69, 255); + + private static final int OUTSIDE_STROKE_RED_OFFSET = 14; + private static final int OUTSIDE_STROKE_GREEN_OFFSET = 13; + private static final int OUTSIDE_STROKE_BLUE_OFFSET = 15; + private static final int OUTSIDE_STROKE_ALPHA = 255; + + private static final int INSIDE_STROKE_RED_OFFSET = 20; + private static final int INSIDE_STROKE_GREEN_OFFSET = 21; + private static final int INSIDE_STROKE_BLUE_OFFSET = 19; + private static final int INSIDE_STROKE_ALPHA = 255; + + @Setter + private Color backgroundColor = DEFAULT_BACKGROUND_COLOR; @Setter private Rectangle rectangle = new Rectangle(); @@ -49,20 +61,34 @@ public class BackgroundComponent implements RenderableEntity @Override public Dimension render(Graphics2D graphics, Point parent) { + Color outsideStrokeColor = new Color( + Math.max(0, backgroundColor.getRed() - OUTSIDE_STROKE_RED_OFFSET), + Math.max(0, backgroundColor.getGreen() - OUTSIDE_STROKE_GREEN_OFFSET), + Math.max(0, backgroundColor.getBlue() - OUTSIDE_STROKE_BLUE_OFFSET), + OUTSIDE_STROKE_ALPHA + ); + + Color insideStrokeColor = new Color( + Math.min(255, backgroundColor.getRed() + INSIDE_STROKE_RED_OFFSET), + Math.min(255, backgroundColor.getGreen() + INSIDE_STROKE_GREEN_OFFSET), + Math.min(255, backgroundColor.getBlue() + INSIDE_STROKE_BLUE_OFFSET), + INSIDE_STROKE_ALPHA + ); + // Render background - graphics.setColor(BACKGROUND_COLOR); + graphics.setColor(backgroundColor); graphics.fill(rectangle); // Render outside stroke final Rectangle outsideStroke = new Rectangle(rectangle); outsideStroke.grow(-BORDER_OFFSET / 2,- BORDER_OFFSET / 2); - graphics.setColor(OUTSIDE_STROKE_COLOR); + graphics.setColor(outsideStrokeColor); graphics.draw(outsideStroke); // Render inside stroke final Rectangle insideStroke = new Rectangle(rectangle); insideStroke.grow(-BORDER_OFFSET, -BORDER_OFFSET); - graphics.setColor(INSIDE_STROKE_COLOR); + graphics.setColor(insideStrokeColor); graphics.draw(insideStroke); return new Dimension(rectangle.getSize()); } diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/ImagePanelComponent.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/ImagePanelComponent.java new file mode 100644 index 0000000000..3de964fce1 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/ImagePanelComponent.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2017, Devin French + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.ui.overlay.components; + +import com.google.common.base.Strings; +import lombok.Setter; +import net.runelite.client.ui.overlay.RenderableEntity; + +import javax.annotation.Nullable; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FontMetrics; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.image.BufferedImage; + +public class ImagePanelComponent implements RenderableEntity +{ + private static final int TOP_BORDER = 3; + private static final int SIDE_BORDER = 6; + private static final int BOTTOM_BORDER = 6; + private static final int SEPARATOR = 4; + + @Setter + @Nullable + private String title; + + @Setter + private Color titleColor = Color.WHITE; + + @Setter + private Color backgroundColor = BackgroundComponent.DEFAULT_BACKGROUND_COLOR; + + @Setter + private BufferedImage image; + + @Setter + private Point position = new Point(); + + @Override + public Dimension render(Graphics2D graphics, Point parent) + { + final Dimension dimension = new Dimension(); + final FontMetrics metrics = graphics.getFontMetrics(); + int height = TOP_BORDER + (Strings.isNullOrEmpty(title) ? 0 : metrics.getHeight()) + + SEPARATOR + image.getHeight() + BOTTOM_BORDER; + int width = Math.max(Strings.isNullOrEmpty(title) ? 0 : metrics.stringWidth(title), image.getWidth()) + SIDE_BORDER * 2; + dimension.setSize(width, height); + + if (dimension.height == 0) + { + return null; + } + + // Calculate panel dimensions + int y = position.y + TOP_BORDER + metrics.getHeight(); + + // Render background + final BackgroundComponent backgroundComponent = new BackgroundComponent(); + backgroundComponent.setBackgroundColor(backgroundColor); + backgroundComponent.setRectangle(new Rectangle(position.x, position.y, dimension.width, dimension.height)); + backgroundComponent.render(graphics, parent); + + // Render title + if (!Strings.isNullOrEmpty(title)) + { + final TextComponent titleComponent = new TextComponent(); + titleComponent.setText(title); + titleComponent.setColor(titleColor); + titleComponent.setPosition(new Point(position.x + (width - metrics.stringWidth(title)) / 2, y)); + titleComponent.render(graphics, parent); + y += SEPARATOR; + } + + // Render image + graphics.drawImage(image, position.x + (width - image.getWidth()) / 2, y, null); + + return dimension; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/InfoBoxComponent.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/InfoBoxComponent.java index 39db76efb2..36621e57d3 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/InfoBoxComponent.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/InfoBoxComponent.java @@ -47,6 +47,9 @@ public class InfoBoxComponent implements RenderableEntity @Setter private Color color = Color.WHITE; + @Setter + private Color backgroundColor = BackgroundComponent.DEFAULT_BACKGROUND_COLOR; + @Setter private Point position = new Point(); @@ -60,6 +63,7 @@ public class InfoBoxComponent implements RenderableEntity final FontMetrics metrics = graphics.getFontMetrics(); final Rectangle bounds = new Rectangle(position.x, position.y, BOX_SIZE, BOX_SIZE); final BackgroundComponent backgroundComponent = new BackgroundComponent(); + backgroundComponent.setBackgroundColor(backgroundColor); backgroundComponent.setRectangle(bounds); backgroundComponent.render(graphics, parent); diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/PanelComponent.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/PanelComponent.java index 77026ceded..dcd28a3916 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/PanelComponent.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/PanelComponent.java @@ -67,6 +67,9 @@ public class PanelComponent implements RenderableEntity @Setter private Color titleColor = Color.WHITE; + @Setter + private Color backgroundColor = BackgroundComponent.DEFAULT_BACKGROUND_COLOR; + @Setter private Point position = new Point(); @@ -98,6 +101,7 @@ public class PanelComponent implements RenderableEntity // Render background final BackgroundComponent backgroundComponent = new BackgroundComponent(); + backgroundComponent.setBackgroundColor(backgroundColor); backgroundComponent.setRectangle(new Rectangle(position.x, position.y, dimension.width, dimension.height)); backgroundComponent.render(graphics, parent); diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/TooltipComponent.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/TooltipComponent.java index 2443caae25..2c080c1d21 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/TooltipComponent.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/TooltipComponent.java @@ -45,6 +45,9 @@ public class TooltipComponent implements RenderableEntity @Setter private String text; + @Setter + private Color backgroundColor = BackgroundComponent.DEFAULT_BACKGROUND_COLOR; + @Setter private Point position = new Point(); @@ -92,6 +95,7 @@ public class TooltipComponent implements RenderableEntity final Rectangle tooltipBackground = new Rectangle(x, y, tooltipWidth + OFFSET * 2, tooltipHeight + OFFSET * 2); final BackgroundComponent backgroundComponent = new BackgroundComponent(); + backgroundComponent.setBackgroundColor(backgroundColor); backgroundComponent.setRectangle(tooltipBackground); backgroundComponent.render(graphics, parent); graphics.setColor(Color.WHITE);