From 65114f50d8c8074da4da20980c0f74554692dbdd Mon Sep 17 00:00:00 2001 From: Devin Date: Sat, 16 Dec 2017 10:54:26 -0800 Subject: [PATCH 1/3] Add ImagePanelComponent overlay component --- .../components/ImagePanelComponent.java | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 runelite-client/src/main/java/net/runelite/client/ui/overlay/components/ImagePanelComponent.java 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..ba734fac2f --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/ImagePanelComponent.java @@ -0,0 +1,99 @@ +/* + * 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 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.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; + } +} From 66dad47992561072d255d99f3e1a1556dcd0fe04 Mon Sep 17 00:00:00 2001 From: Devin Date: Sat, 16 Dec 2017 10:59:53 -0800 Subject: [PATCH 2/3] Add setter for background color of overlay components --- .../components/BackgroundComponent.java | 38 ++++++++++++++++--- .../components/ImagePanelComponent.java | 4 ++ .../overlay/components/InfoBoxComponent.java | 4 ++ .../ui/overlay/components/PanelComponent.java | 4 ++ .../overlay/components/TooltipComponent.java | 4 ++ 5 files changed, 48 insertions(+), 6 deletions(-) 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 index ba734fac2f..3de964fce1 100644 --- 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 @@ -51,6 +51,9 @@ public class ImagePanelComponent implements RenderableEntity @Setter private Color titleColor = Color.WHITE; + @Setter + private Color backgroundColor = BackgroundComponent.DEFAULT_BACKGROUND_COLOR; + @Setter private BufferedImage image; @@ -77,6 +80,7 @@ public class ImagePanelComponent 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/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); From ddf9ee89e7eb5ada12be89498bf6a77612309fe7 Mon Sep 17 00:00:00 2001 From: Devin Date: Sat, 16 Dec 2017 16:23:52 -0800 Subject: [PATCH 3/3] Fix padding for bottom right overlays --- .../java/net/runelite/client/ui/overlay/OverlayRenderer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 00c400ae68..d991ee3f61 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 @@ -228,7 +228,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);