diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/blastfurnace/BlastFurnaceOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/blastfurnace/BlastFurnaceOverlay.java index d57fd53fc9..48253cdfe3 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/blastfurnace/BlastFurnaceOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/blastfurnace/BlastFurnaceOverlay.java @@ -35,6 +35,7 @@ import net.runelite.client.ui.overlay.Overlay; import static net.runelite.client.ui.overlay.OverlayManager.OPTION_CONFIGURE; import net.runelite.client.ui.overlay.OverlayMenuEntry; import net.runelite.client.ui.overlay.OverlayPosition; +import net.runelite.client.ui.overlay.components.ComponentOrientation; import net.runelite.client.ui.overlay.components.ImageComponent; import net.runelite.client.ui.overlay.components.PanelComponent; @@ -54,7 +55,7 @@ class BlastFurnaceOverlay extends Overlay this.plugin = plugin; this.client = client; setPosition(OverlayPosition.TOP_LEFT); - imagePanelComponent.setOrientation(PanelComponent.Orientation.HORIZONTAL); + imagePanelComponent.setOrientation(ComponentOrientation.HORIZONTAL); getMenuEntries().add(new OverlayMenuEntry(RUNELITE_OVERLAY_CONFIG, OPTION_CONFIGURE, "Blast furnace overlay")); } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/blastmine/BlastMineOreCountOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/blastmine/BlastMineOreCountOverlay.java index d4566f89c8..f660eb2b63 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/blastmine/BlastMineOreCountOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/blastmine/BlastMineOreCountOverlay.java @@ -39,6 +39,7 @@ import net.runelite.client.ui.overlay.Overlay; import static net.runelite.client.ui.overlay.OverlayManager.OPTION_CONFIGURE; import net.runelite.client.ui.overlay.OverlayMenuEntry; import net.runelite.client.ui.overlay.OverlayPosition; +import net.runelite.client.ui.overlay.components.ComponentOrientation; import net.runelite.client.ui.overlay.components.ImageComponent; import net.runelite.client.ui.overlay.components.PanelComponent; @@ -57,7 +58,7 @@ class BlastMineOreCountOverlay extends Overlay this.client = client; this.config = config; this.itemManager = itemManager; - panelComponent.setOrientation(PanelComponent.Orientation.HORIZONTAL); + panelComponent.setOrientation(ComponentOrientation.HORIZONTAL); getMenuEntries().add(new OverlayMenuEntry(RUNELITE_OVERLAY_CONFIG, OPTION_CONFIGURE, "Blast mine overlay")); } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/cerberus/CerberusOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/cerberus/CerberusOverlay.java index 5ddbf21f7a..2f384fcd80 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/cerberus/CerberusOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/cerberus/CerberusOverlay.java @@ -31,6 +31,7 @@ import javax.inject.Singleton; import net.runelite.client.game.SkillIconManager; import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.OverlayPosition; +import net.runelite.client.ui.overlay.components.ComponentOrientation; import net.runelite.client.ui.overlay.components.ImageComponent; import net.runelite.client.ui.overlay.components.PanelComponent; @@ -47,7 +48,7 @@ public class CerberusOverlay extends Overlay this.plugin = plugin; this.iconManager = iconManager; setPosition(OverlayPosition.BOTTOM_RIGHT); - panelComponent.setOrientation(PanelComponent.Orientation.HORIZONTAL); + panelComponent.setOrientation(ComponentOrientation.HORIZONTAL); } @Override diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inventoryviewer/InventoryViewerOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/inventoryviewer/InventoryViewerOverlay.java index 71da3492aa..7162be5290 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/inventoryviewer/InventoryViewerOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inventoryviewer/InventoryViewerOverlay.java @@ -37,6 +37,7 @@ import net.runelite.api.ItemContainer; import net.runelite.client.game.ItemManager; import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.OverlayPosition; +import net.runelite.client.ui.overlay.components.ComponentOrientation; import net.runelite.client.ui.overlay.components.ImageComponent; import net.runelite.client.ui.overlay.components.PanelComponent; @@ -58,7 +59,7 @@ class InventoryViewerOverlay extends Overlay setPosition(OverlayPosition.BOTTOM_RIGHT); panelComponent.setWrapping(4); panelComponent.setGap(new Point(6, 4)); - panelComponent.setOrientation(PanelComponent.Orientation.HORIZONTAL); + panelComponent.setOrientation(ComponentOrientation.HORIZONTAL); this.itemManager = itemManager; this.client = client; } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/teamcapes/TeamCapesOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/teamcapes/TeamCapesOverlay.java index b5cc7858bf..9dbd2dc861 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/teamcapes/TeamCapesOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/teamcapes/TeamCapesOverlay.java @@ -36,6 +36,7 @@ import static net.runelite.client.ui.overlay.OverlayManager.OPTION_CONFIGURE; import net.runelite.client.ui.overlay.OverlayMenuEntry; import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayPriority; +import net.runelite.client.ui.overlay.components.ComponentOrientation; import net.runelite.client.ui.overlay.components.ImageComponent; import net.runelite.client.ui.overlay.components.PanelComponent; @@ -55,7 +56,7 @@ public class TeamCapesOverlay extends Overlay this.plugin = plugin; this.config = config; this.manager = manager; - panelComponent.setOrientation(PanelComponent.Orientation.HORIZONTAL); + panelComponent.setOrientation(ComponentOrientation.HORIZONTAL); panelComponent.setWrapping(4); getMenuEntries().add(new OverlayMenuEntry(RUNELITE_OVERLAY_CONFIG, OPTION_CONFIGURE, "Teamcapes overlay")); } diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/ComponentOrientation.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/ComponentOrientation.java new file mode 100644 index 0000000000..e06875e970 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/ComponentOrientation.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018, Jasper Ketelaar + * 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; + +public enum ComponentOrientation +{ + HORIZONTAL, + VERTICAL +} \ No newline at end of file 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 5ea81f2006..6baf20985e 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 @@ -37,12 +37,6 @@ import lombok.Setter; public class PanelComponent implements LayoutableRenderableEntity { - public enum Orientation - { - HORIZONTAL, - VERTICAL; - } - @Getter private final Rectangle bounds = new Rectangle(); @@ -60,7 +54,7 @@ public class PanelComponent implements LayoutableRenderableEntity private final List children = new ArrayList<>(); @Setter - private Orientation orientation = Orientation.VERTICAL; + private ComponentOrientation orientation = ComponentOrientation.VERTICAL; @Setter private int wrapping = -1; diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/SplitComponent.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/SplitComponent.java new file mode 100644 index 0000000000..2e77a7dde2 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/components/SplitComponent.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2018, Jasper Ketelaar + * 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 java.awt.Dimension; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +@Setter +@Builder +public class SplitComponent implements LayoutableRenderableEntity +{ + private LayoutableRenderableEntity first; + private LayoutableRenderableEntity second; + + @Builder.Default + private Point preferredLocation = new Point(); + + @Builder.Default + private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 0); + + @Builder.Default + private ComponentOrientation orientation = ComponentOrientation.VERTICAL; + + @Builder.Default + private Point gap = new Point(0, 0); + + @Builder.Default + @Getter + private final Rectangle bounds = new Rectangle(); + + @Override + public Dimension render(Graphics2D graphics) + { + graphics.translate(preferredLocation.x, preferredLocation.y); + first.setPreferredSize(preferredSize); + first.setPreferredLocation(new Point(0, 0)); + + final Dimension firstDimension = first.render(graphics); + int x = 0, y = 0; + + if (orientation == ComponentOrientation.VERTICAL) + { + y = firstDimension.height + gap.y; + } + else + { + x = firstDimension.width + gap.x; + } + + second.setPreferredLocation(new Point(x, y)); + // Make the second component fit to whatever size is left after the first component is rendered + second.setPreferredSize(new Dimension(preferredSize.width - x, preferredSize.height - y)); + + // The total width/height need to be determined as they are now always the same as the + // individual width/height (for example image width/height will just be the height of the image + // and not the height of the area the image is in + final Dimension secondDimension = second.render(graphics); + int totalWidth, totalHeight; + + if (orientation == ComponentOrientation.VERTICAL) + { + totalWidth = Math.max(firstDimension.width, secondDimension.width); + totalHeight = y + secondDimension.height; + } + else + { + totalHeight = Math.max(firstDimension.height, secondDimension.height); + totalWidth = x + secondDimension.width; + } + + graphics.translate(-preferredLocation.x, -preferredLocation.y); + + final Dimension dimension = new Dimension(totalWidth, totalHeight); + bounds.setLocation(preferredLocation); + bounds.setSize(dimension); + return dimension; + } +} \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/infobox/InfoBoxOverlay.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/infobox/InfoBoxOverlay.java index 58f20aae63..08412783f1 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/infobox/InfoBoxOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/infobox/InfoBoxOverlay.java @@ -38,6 +38,7 @@ import net.runelite.api.Client; import net.runelite.client.config.RuneLiteConfig; import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.OverlayPosition; +import net.runelite.client.ui.overlay.components.ComponentOrientation; import net.runelite.client.ui.overlay.components.InfoBoxComponent; import net.runelite.client.ui.overlay.components.LayoutableRenderableEntity; import net.runelite.client.ui.overlay.components.PanelComponent; @@ -84,8 +85,8 @@ public class InfoBoxOverlay extends Overlay panelComponent.getChildren().clear(); panelComponent.setWrapping(config.infoBoxWrap()); panelComponent.setOrientation(config.infoBoxVertical() - ? PanelComponent.Orientation.VERTICAL - : PanelComponent.Orientation.HORIZONTAL); + ? ComponentOrientation.VERTICAL + : ComponentOrientation.HORIZONTAL); panelComponent.setPreferredSize(new Dimension(config.infoBoxSize(), config.infoBoxSize())); for (InfoBox box : infoBoxes)