Add .getBounds() to LayoutableRenderableEntity
Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -28,6 +28,7 @@ import java.awt.Color;
|
|||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import java.awt.Stroke;
|
import java.awt.Stroke;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -55,6 +56,9 @@ public class ScreenMarkerRenderable implements LayoutableRenderableEntity
|
|||||||
@Setter(AccessLevel.PACKAGE)
|
@Setter(AccessLevel.PACKAGE)
|
||||||
private Stroke stroke;
|
private Stroke stroke;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final Rectangle bounds = new Rectangle();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension render(Graphics2D graphics)
|
public Dimension render(Graphics2D graphics)
|
||||||
{
|
{
|
||||||
@@ -72,6 +76,7 @@ public class ScreenMarkerRenderable implements LayoutableRenderableEntity
|
|||||||
graphics.setColor(color);
|
graphics.setColor(color);
|
||||||
graphics.setStroke(stroke);
|
graphics.setStroke(stroke);
|
||||||
graphics.drawRect(offset, offset, width - thickness, height - thickness);
|
graphics.drawRect(offset, offset, width - thickness, height - thickness);
|
||||||
|
bounds.setSize(preferredSize);
|
||||||
return preferredSize;
|
return preferredSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ package net.runelite.client.ui.overlay.components;
|
|||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@@ -36,6 +38,10 @@ import lombok.Setter;
|
|||||||
public class ImageComponent implements LayoutableRenderableEntity
|
public class ImageComponent implements LayoutableRenderableEntity
|
||||||
{
|
{
|
||||||
private final BufferedImage image;
|
private final BufferedImage image;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final Rectangle bounds = new Rectangle();
|
||||||
|
|
||||||
private Point preferredLocation = new Point();
|
private Point preferredLocation = new Point();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -47,7 +53,10 @@ public class ImageComponent implements LayoutableRenderableEntity
|
|||||||
}
|
}
|
||||||
|
|
||||||
graphics.drawImage(image, preferredLocation.x, preferredLocation.y, null);
|
graphics.drawImage(image, preferredLocation.x, preferredLocation.y, null);
|
||||||
return new Dimension(image.getWidth(), image.getHeight());
|
final Dimension dimension = new Dimension(image.getWidth(), image.getHeight());
|
||||||
|
bounds.setLocation(preferredLocation);
|
||||||
|
bounds.setSize(dimension);
|
||||||
|
return dimension;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ public class InfoBoxComponent implements LayoutableRenderableEntity
|
|||||||
@Setter
|
@Setter
|
||||||
private Dimension preferredSize = new Dimension(DEFAULT_SIZE, DEFAULT_SIZE);
|
private Dimension preferredSize = new Dimension(DEFAULT_SIZE, DEFAULT_SIZE);
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final Rectangle bounds = new Rectangle();
|
||||||
|
|
||||||
private String text;
|
private String text;
|
||||||
private Color color = Color.WHITE;
|
private Color color = Color.WHITE;
|
||||||
private Color backgroundColor = ComponentConstants.STANDARD_BACKGROUND_COLOR;
|
private Color backgroundColor = ComponentConstants.STANDARD_BACKGROUND_COLOR;
|
||||||
@@ -64,12 +67,14 @@ public class InfoBoxComponent implements LayoutableRenderableEntity
|
|||||||
}
|
}
|
||||||
|
|
||||||
graphics.setFont(getSize() < DEFAULT_SIZE ? FontManager.getRunescapeSmallFont() : FontManager.getRunescapeFont());
|
graphics.setFont(getSize() < DEFAULT_SIZE ? FontManager.getRunescapeSmallFont() : FontManager.getRunescapeFont());
|
||||||
graphics.translate(preferredLocation.x, preferredLocation.y);
|
|
||||||
|
final int baseX = preferredLocation.x;
|
||||||
|
final int baseY = preferredLocation.y;
|
||||||
|
|
||||||
// Calculate dimensions
|
// Calculate dimensions
|
||||||
final FontMetrics metrics = graphics.getFontMetrics();
|
final FontMetrics metrics = graphics.getFontMetrics();
|
||||||
final int size = getSize();
|
final int size = getSize();
|
||||||
final Rectangle bounds = new Rectangle(size, size);
|
final Rectangle bounds = new Rectangle(baseX, baseY, size, size);
|
||||||
|
|
||||||
// Render background
|
// Render background
|
||||||
final BackgroundComponent backgroundComponent = new BackgroundComponent();
|
final BackgroundComponent backgroundComponent = new BackgroundComponent();
|
||||||
@@ -80,18 +85,18 @@ public class InfoBoxComponent implements LayoutableRenderableEntity
|
|||||||
// Render image
|
// Render image
|
||||||
graphics.drawImage(
|
graphics.drawImage(
|
||||||
image,
|
image,
|
||||||
(size - image.getWidth(null)) / 2,
|
baseX + (size - image.getWidth(null)) / 2,
|
||||||
(size - image.getHeight(null)) / 2,
|
baseY + (size - image.getHeight(null)) / 2,
|
||||||
null);
|
null);
|
||||||
|
|
||||||
// Render caption
|
// Render caption
|
||||||
final TextComponent textComponent = new TextComponent();
|
final TextComponent textComponent = new TextComponent();
|
||||||
textComponent.setColor(color);
|
textComponent.setColor(color);
|
||||||
textComponent.setText(text);
|
textComponent.setText(text);
|
||||||
textComponent.setPosition(new Point(((size - metrics.stringWidth(text)) / 2), size - SEPARATOR));
|
textComponent.setPosition(new Point(baseX + ((size - metrics.stringWidth(text)) / 2), baseY + size - SEPARATOR));
|
||||||
textComponent.render(graphics);
|
textComponent.render(graphics);
|
||||||
|
|
||||||
graphics.translate(-preferredLocation.x, -preferredLocation.y);
|
this.bounds.setBounds(bounds);
|
||||||
return bounds.getSize();
|
return bounds.getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,10 +26,12 @@ package net.runelite.client.ui.overlay.components;
|
|||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import net.runelite.client.ui.overlay.RenderableEntity;
|
import net.runelite.client.ui.overlay.RenderableEntity;
|
||||||
|
|
||||||
public interface LayoutableRenderableEntity extends RenderableEntity
|
public interface LayoutableRenderableEntity extends RenderableEntity
|
||||||
{
|
{
|
||||||
|
Rectangle getBounds();
|
||||||
void setPreferredLocation(Point position);
|
void setPreferredLocation(Point position);
|
||||||
void setPreferredSize(Dimension dimension);
|
void setPreferredSize(Dimension dimension);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,9 @@ import java.awt.Dimension;
|
|||||||
import java.awt.FontMetrics;
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
@@ -53,17 +55,22 @@ public class LineComponent implements LayoutableRenderableEntity
|
|||||||
@Builder.Default
|
@Builder.Default
|
||||||
private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 0);
|
private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 0);
|
||||||
|
|
||||||
|
@Builder.Default
|
||||||
|
@Getter
|
||||||
|
private final Rectangle bounds = new Rectangle();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension render(Graphics2D graphics)
|
public Dimension render(Graphics2D graphics)
|
||||||
{
|
{
|
||||||
graphics.translate(preferredLocation.x, preferredLocation.y);
|
|
||||||
// Prevent NPEs
|
// Prevent NPEs
|
||||||
final String left = MoreObjects.firstNonNull(this.left, "");
|
final String left = MoreObjects.firstNonNull(this.left, "");
|
||||||
final String right = MoreObjects.firstNonNull(this.right, "");
|
final String right = MoreObjects.firstNonNull(this.right, "");
|
||||||
|
|
||||||
final FontMetrics metrics = graphics.getFontMetrics();
|
final FontMetrics metrics = graphics.getFontMetrics();
|
||||||
int x = 0;
|
final int baseX = preferredLocation.x;
|
||||||
int y = metrics.getHeight();
|
final int baseY = preferredLocation.y + metrics.getHeight();
|
||||||
|
int x = baseX;
|
||||||
|
int y = baseY;
|
||||||
final int leftFullWidth = getLineWidth(left, metrics);
|
final int leftFullWidth = getLineWidth(left, metrics);
|
||||||
final int rightFullWidth = getLineWidth(right, metrics);
|
final int rightFullWidth = getLineWidth(right, metrics);
|
||||||
|
|
||||||
@@ -112,8 +119,10 @@ public class LineComponent implements LayoutableRenderableEntity
|
|||||||
y += metrics.getHeight();
|
y += metrics.getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
graphics.translate(-preferredLocation.x, -preferredLocation.y);
|
final Dimension dimension = new Dimension(preferredSize.width, y - baseY);
|
||||||
return new Dimension(preferredSize.width, y - metrics.getHeight());
|
bounds.setLocation(preferredLocation);
|
||||||
|
bounds.setSize(dimension);
|
||||||
|
return dimension;
|
||||||
}
|
}
|
||||||
|
|
||||||
final TextComponent leftLineComponent = new TextComponent();
|
final TextComponent leftLineComponent = new TextComponent();
|
||||||
@@ -129,8 +138,10 @@ public class LineComponent implements LayoutableRenderableEntity
|
|||||||
rightLineComponent.render(graphics);
|
rightLineComponent.render(graphics);
|
||||||
y += metrics.getHeight();
|
y += metrics.getHeight();
|
||||||
|
|
||||||
graphics.translate(-preferredLocation.x, -preferredLocation.y);
|
final Dimension dimension = new Dimension(preferredSize.width, y - baseY);
|
||||||
return new Dimension(preferredSize.width, y - metrics.getHeight());
|
bounds.setLocation(preferredLocation);
|
||||||
|
bounds.setSize(dimension);
|
||||||
|
return dimension;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getLineWidth(final String line, final FontMetrics metrics)
|
private static int getLineWidth(final String line, final FontMetrics metrics)
|
||||||
|
|||||||
@@ -43,9 +43,8 @@ public class PanelComponent implements LayoutableRenderableEntity
|
|||||||
VERTICAL;
|
VERTICAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Setter
|
@Getter
|
||||||
@Nullable
|
private final Rectangle bounds = new Rectangle();
|
||||||
private Color backgroundColor = ComponentConstants.STANDARD_BACKGROUND_COLOR;
|
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
private Point preferredLocation = new Point();
|
private Point preferredLocation = new Point();
|
||||||
@@ -53,8 +52,12 @@ public class PanelComponent implements LayoutableRenderableEntity
|
|||||||
@Setter
|
@Setter
|
||||||
private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 0);
|
private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 0);
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Nullable
|
||||||
|
private Color backgroundColor = ComponentConstants.STANDARD_BACKGROUND_COLOR;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private List<LayoutableRenderableEntity> children = new ArrayList<>();
|
private final List<LayoutableRenderableEntity> children = new ArrayList<>();
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
private Orientation orientation = Orientation.VERTICAL;
|
private Orientation orientation = Orientation.VERTICAL;
|
||||||
@@ -82,8 +85,6 @@ public class PanelComponent implements LayoutableRenderableEntity
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
graphics.translate(preferredLocation.x, preferredLocation.y);
|
|
||||||
|
|
||||||
// Calculate panel dimension
|
// Calculate panel dimension
|
||||||
final Dimension dimension = new Dimension(
|
final Dimension dimension = new Dimension(
|
||||||
border.x + childDimensions.width + border.width,
|
border.x + childDimensions.width + border.width,
|
||||||
@@ -93,14 +94,14 @@ public class PanelComponent implements LayoutableRenderableEntity
|
|||||||
if (backgroundColor != null)
|
if (backgroundColor != null)
|
||||||
{
|
{
|
||||||
final BackgroundComponent backgroundComponent = new BackgroundComponent();
|
final BackgroundComponent backgroundComponent = new BackgroundComponent();
|
||||||
backgroundComponent.setRectangle(new Rectangle(dimension));
|
backgroundComponent.setRectangle(new Rectangle(preferredLocation, dimension));
|
||||||
backgroundComponent.setBackgroundColor(backgroundColor);
|
backgroundComponent.setBackgroundColor(backgroundColor);
|
||||||
backgroundComponent.render(graphics);
|
backgroundComponent.render(graphics);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Offset children
|
// Offset children
|
||||||
final int baseX = border.x;
|
final int baseX = preferredLocation.x + border.x;
|
||||||
final int baseY = border.y;
|
final int baseY = preferredLocation.y + border.y;
|
||||||
int width = 0;
|
int width = 0;
|
||||||
int height = 0;
|
int height = 0;
|
||||||
int x = baseX;
|
int x = baseX;
|
||||||
@@ -174,7 +175,9 @@ public class PanelComponent implements LayoutableRenderableEntity
|
|||||||
// Cache children bounds
|
// Cache children bounds
|
||||||
childDimensions.setSize(totalWidth, totalHeight);
|
childDimensions.setSize(totalWidth, totalHeight);
|
||||||
|
|
||||||
graphics.translate(-preferredLocation.x, -preferredLocation.y);
|
// Cache bounds
|
||||||
|
bounds.setLocation(preferredLocation);
|
||||||
|
bounds.setSize(dimension);
|
||||||
return dimension;
|
return dimension;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ import java.awt.Dimension;
|
|||||||
import java.awt.FontMetrics;
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
@@ -43,6 +45,7 @@ public class ProgressBarComponent implements LayoutableRenderableEntity
|
|||||||
|
|
||||||
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("0.0");
|
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("0.0");
|
||||||
private static final DecimalFormat DECIMAL_FORMAT_ABS = new DecimalFormat("#0");
|
private static final DecimalFormat DECIMAL_FORMAT_ABS = new DecimalFormat("#0");
|
||||||
|
|
||||||
private long minimum;
|
private long minimum;
|
||||||
private long maximum = 100;
|
private long maximum = 100;
|
||||||
private double value;
|
private double value;
|
||||||
@@ -53,14 +56,16 @@ public class ProgressBarComponent implements LayoutableRenderableEntity
|
|||||||
private Point preferredLocation = new Point();
|
private Point preferredLocation = new Point();
|
||||||
private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 16);
|
private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 16);
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final Rectangle bounds = new Rectangle();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension render(Graphics2D graphics)
|
public Dimension render(Graphics2D graphics)
|
||||||
{
|
{
|
||||||
graphics.translate(preferredLocation.x, preferredLocation.y);
|
|
||||||
final FontMetrics metrics = graphics.getFontMetrics();
|
final FontMetrics metrics = graphics.getFontMetrics();
|
||||||
|
|
||||||
final int barX = 0;
|
final int barX = preferredLocation.x;
|
||||||
final int barY = 0;
|
final int barY = preferredLocation.y;
|
||||||
|
|
||||||
final long span = maximum - minimum;
|
final long span = maximum - minimum;
|
||||||
final double currentValue = value - minimum;
|
final double currentValue = value - minimum;
|
||||||
@@ -82,7 +87,7 @@ public class ProgressBarComponent implements LayoutableRenderableEntity
|
|||||||
final int progressTextY = barY + ((height - metrics.getHeight()) / 2) + metrics.getHeight();
|
final int progressTextY = barY + ((height - metrics.getHeight()) / 2) + metrics.getHeight();
|
||||||
final int progressFill = (int) (width * Math.min(1, pc));
|
final int progressFill = (int) (width * Math.min(1, pc));
|
||||||
|
|
||||||
//Draw bar
|
// Draw bar
|
||||||
graphics.setColor(backgroundColor);
|
graphics.setColor(backgroundColor);
|
||||||
graphics.fillRect(barX, barY, width, height);
|
graphics.fillRect(barX, barY, width, height);
|
||||||
graphics.setColor(foregroundColor);
|
graphics.setColor(foregroundColor);
|
||||||
@@ -94,7 +99,9 @@ public class ProgressBarComponent implements LayoutableRenderableEntity
|
|||||||
textComponent.setText(textToWrite);
|
textComponent.setText(textToWrite);
|
||||||
textComponent.render(graphics);
|
textComponent.render(graphics);
|
||||||
|
|
||||||
graphics.translate(-preferredLocation.x, -preferredLocation.y);
|
final Dimension dimension = new Dimension(width, height);
|
||||||
return new Dimension(width, height);
|
bounds.setLocation(preferredLocation);
|
||||||
|
bounds.setSize(dimension);
|
||||||
|
return dimension;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ import java.awt.Dimension;
|
|||||||
import java.awt.FontMetrics;
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
@@ -47,17 +49,26 @@ public class TitleComponent implements LayoutableRenderableEntity
|
|||||||
@Builder.Default
|
@Builder.Default
|
||||||
private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 0);
|
private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 0);
|
||||||
|
|
||||||
|
@Builder.Default
|
||||||
|
@Getter
|
||||||
|
private final Rectangle bounds = new Rectangle();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension render(Graphics2D graphics)
|
public Dimension render(Graphics2D graphics)
|
||||||
{
|
{
|
||||||
graphics.translate(preferredLocation.x, preferredLocation.y);
|
final int baseX = preferredLocation.x;
|
||||||
|
final int baseY = preferredLocation.y;
|
||||||
final FontMetrics metrics = graphics.getFontMetrics();
|
final FontMetrics metrics = graphics.getFontMetrics();
|
||||||
final TextComponent titleComponent = new TextComponent();
|
final TextComponent titleComponent = new TextComponent();
|
||||||
titleComponent.setText(text);
|
titleComponent.setText(text);
|
||||||
titleComponent.setColor(color);
|
titleComponent.setColor(color);
|
||||||
titleComponent.setPosition(new Point((preferredSize.width - metrics.stringWidth(text)) / 2, metrics.getHeight()));
|
titleComponent.setPosition(new Point(
|
||||||
final Dimension dimension = titleComponent.render(graphics);
|
baseX + ((preferredSize.width - metrics.stringWidth(text)) / 2),
|
||||||
graphics.translate(-preferredLocation.x, -preferredLocation.y);
|
baseY + metrics.getHeight()));
|
||||||
return new Dimension(preferredSize.width, dimension.height);
|
final Dimension rendered = titleComponent.render(graphics);
|
||||||
|
final Dimension dimension = new Dimension(preferredSize.width, rendered.height);
|
||||||
|
bounds.setLocation(preferredLocation);
|
||||||
|
bounds.setSize(dimension);
|
||||||
|
return dimension;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user