imagePanelComponent: Add support for multiple images

This commit is contained in:
Seth
2018-02-05 18:15:45 -06:00
committed by Adam
parent ca4726d8b8
commit fd81d32909
2 changed files with 39 additions and 15 deletions

View File

@@ -70,7 +70,7 @@ public class FightCaveOverlay extends Overlay
BufferedImage prayerImage = getPrayerImage(attack); BufferedImage prayerImage = getPrayerImage(attack);
ImagePanelComponent imagePanelComponent = new ImagePanelComponent(); ImagePanelComponent imagePanelComponent = new ImagePanelComponent();
imagePanelComponent.setTitle("Switch!"); imagePanelComponent.setTitle("Switch!");
imagePanelComponent.setImage(prayerImage); imagePanelComponent.getImages().add(prayerImage);
return imagePanelComponent.render(graphics, parent); return imagePanelComponent.render(graphics, parent);
} }

View File

@@ -25,10 +25,6 @@
package net.runelite.client.ui.overlay.components; package net.runelite.client.ui.overlay.components;
import com.google.common.base.Strings; 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.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.FontMetrics; import java.awt.FontMetrics;
@@ -36,6 +32,12 @@ import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import lombok.Getter;
import lombok.Setter;
import net.runelite.client.ui.overlay.RenderableEntity;
public class ImagePanelComponent implements RenderableEntity public class ImagePanelComponent implements RenderableEntity
{ {
@@ -54,8 +56,8 @@ public class ImagePanelComponent implements RenderableEntity
@Setter @Setter
private Color backgroundColor = BackgroundComponent.DEFAULT_BACKGROUND_COLOR; private Color backgroundColor = BackgroundComponent.DEFAULT_BACKGROUND_COLOR;
@Setter @Getter
private BufferedImage image; private final List<BufferedImage> images = new ArrayList<>();
@Setter @Setter
private Point position = new Point(); private Point position = new Point();
@@ -65,18 +67,35 @@ public class ImagePanelComponent implements RenderableEntity
{ {
final Dimension dimension = new Dimension(); final Dimension dimension = new Dimension();
final FontMetrics metrics = graphics.getFontMetrics(); final FontMetrics metrics = graphics.getFontMetrics();
int height = TOP_BORDER + (Strings.isNullOrEmpty(title) ? 0 : metrics.getHeight())
+ SEPARATOR + image.getHeight() + BOTTOM_BORDER; //Determine max height and width of images
int width = Math.max(Strings.isNullOrEmpty(title) ? 0 : metrics.stringWidth(title), image.getWidth()) + SIDE_BORDER * 2; int maxImageHeight = 0;
int imageWidth = 0;
for (final BufferedImage image : images)
{
if (image.getHeight() > maxImageHeight)
{
maxImageHeight = image.getHeight();
}
imageWidth += image.getWidth() + SEPARATOR;
}
int height = TOP_BORDER + (Strings.isNullOrEmpty(title) ? 0 : metrics.getHeight() + SEPARATOR)
+ maxImageHeight + BOTTOM_BORDER;
int width = Math.max(Strings.isNullOrEmpty(title) ? 0 : metrics.stringWidth(title), imageWidth) + SIDE_BORDER * 2;
dimension.setSize(width, height); dimension.setSize(width, height);
if (dimension.height == 0) if (dimension.height == TOP_BORDER + BOTTOM_BORDER)
{ {
return null; return null;
} }
// Calculate panel dimensions int y = position.y + TOP_BORDER;
int y = position.y + TOP_BORDER + metrics.getHeight(); if (!Strings.isNullOrEmpty(title))
{
// Calculate panel dimensions
y += metrics.getHeight();
}
// Render background // Render background
final BackgroundComponent backgroundComponent = new BackgroundComponent(); final BackgroundComponent backgroundComponent = new BackgroundComponent();
@@ -95,8 +114,13 @@ public class ImagePanelComponent implements RenderableEntity
y += SEPARATOR; y += SEPARATOR;
} }
// Render image // Render all images
graphics.drawImage(image, position.x + (width - image.getWidth()) / 2, y, null); int imageOffsetX = ((width - imageWidth) / 2) - (SEPARATOR / 2);
for (final BufferedImage image : images)
{
graphics.drawImage(image, imageOffsetX + ((width / images.size()) - image.getWidth()) / 2, y, null);
imageOffsetX += image.getWidth() + SEPARATOR;
}
return dimension; return dimension;
} }