Simplify component system
- Properly use/not use paddings - Remove title property and extract it to separate component - Remove position property, let user handle the positioning - Extract common constants to ComponentConstants - Use lombok.Setter on classes instead of fields Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -35,10 +35,9 @@ import net.runelite.client.ui.overlay.RenderableEntity;
|
|||||||
|
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@Setter
|
||||||
public class BackgroundComponent implements RenderableEntity
|
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 int BORDER_OFFSET = 2;
|
||||||
|
|
||||||
private static final int OUTSIDE_STROKE_RED_OFFSET = 14;
|
private static final int OUTSIDE_STROKE_RED_OFFSET = 14;
|
||||||
@@ -51,13 +50,8 @@ public class BackgroundComponent implements RenderableEntity
|
|||||||
private static final int INSIDE_STROKE_BLUE_OFFSET = 19;
|
private static final int INSIDE_STROKE_BLUE_OFFSET = 19;
|
||||||
private static final int INSIDE_STROKE_ALPHA = 255;
|
private static final int INSIDE_STROKE_ALPHA = 255;
|
||||||
|
|
||||||
@Setter
|
private Color backgroundColor = ComponentConstants.STANDARD_BACKGROUND_COLOR;
|
||||||
private Color backgroundColor = DEFAULT_BACKGROUND_COLOR;
|
|
||||||
|
|
||||||
@Setter
|
|
||||||
private Rectangle rectangle = new Rectangle();
|
private Rectangle rectangle = new Rectangle();
|
||||||
|
|
||||||
@Setter
|
|
||||||
private boolean fill = true;
|
private boolean fill = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, Tomas Slusny <slusnucky@gmail.com>
|
||||||
|
* 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.Color;
|
||||||
|
|
||||||
|
public class ComponentConstants
|
||||||
|
{
|
||||||
|
public static final int STANDARD_PADDING = 4;
|
||||||
|
public static final int STANDARD_WIDTH = 129;
|
||||||
|
public static final Color STANDARD_BACKGROUND_COLOR = new Color(70, 61, 50, 156);
|
||||||
|
}
|
||||||
@@ -32,29 +32,19 @@ 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.Objects;
|
import java.util.Objects;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import net.runelite.client.ui.overlay.RenderableEntity;
|
import net.runelite.client.ui.overlay.RenderableEntity;
|
||||||
|
|
||||||
|
@Setter
|
||||||
public class InfoBoxComponent implements RenderableEntity
|
public class InfoBoxComponent implements RenderableEntity
|
||||||
{
|
{
|
||||||
private static final int BOX_SIZE = 35;
|
private static final int BOX_SIZE = 35;
|
||||||
private static final int SEPARATOR = 2;
|
private static final int SEPARATOR = 2;
|
||||||
|
|
||||||
@Setter
|
|
||||||
private String text;
|
private String text;
|
||||||
|
|
||||||
@Setter
|
|
||||||
private Color color = Color.WHITE;
|
private Color color = Color.WHITE;
|
||||||
|
private Color backgroundColor = ComponentConstants.STANDARD_BACKGROUND_COLOR;
|
||||||
@Setter
|
|
||||||
private Color backgroundColor = BackgroundComponent.DEFAULT_BACKGROUND_COLOR;
|
|
||||||
|
|
||||||
@Setter
|
|
||||||
private Point position = new Point();
|
private Point position = new Point();
|
||||||
|
|
||||||
@Setter
|
|
||||||
@Nullable
|
|
||||||
private BufferedImage image;
|
private BufferedImage image;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ import lombok.Setter;
|
|||||||
@Builder
|
@Builder
|
||||||
public class LineComponent implements LayoutableRenderableEntity
|
public class LineComponent implements LayoutableRenderableEntity
|
||||||
{
|
{
|
||||||
private static final int SEPARATOR = 1;
|
|
||||||
|
|
||||||
private String left;
|
private String left;
|
||||||
private String right;
|
private String right;
|
||||||
|
|
||||||
@@ -50,7 +48,7 @@ public class LineComponent implements LayoutableRenderableEntity
|
|||||||
private Color rightColor = Color.WHITE;
|
private Color rightColor = Color.WHITE;
|
||||||
|
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
private Dimension preferredSize = new Dimension();
|
private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 0);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension render(Graphics2D graphics)
|
public Dimension render(Graphics2D graphics)
|
||||||
@@ -107,7 +105,7 @@ public class LineComponent implements LayoutableRenderableEntity
|
|||||||
rightLineComponent.setText(rightText);
|
rightLineComponent.setText(rightText);
|
||||||
rightLineComponent.setColor(rightColor);
|
rightLineComponent.setColor(rightColor);
|
||||||
rightLineComponent.render(graphics);
|
rightLineComponent.render(graphics);
|
||||||
y += metrics.getHeight() + SEPARATOR;
|
y += metrics.getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Dimension(preferredSize.width, y);
|
return new Dimension(preferredSize.width, y);
|
||||||
@@ -124,7 +122,7 @@ public class LineComponent implements LayoutableRenderableEntity
|
|||||||
rightLineComponent.setText(right);
|
rightLineComponent.setText(right);
|
||||||
rightLineComponent.setColor(rightColor);
|
rightLineComponent.setColor(rightColor);
|
||||||
rightLineComponent.render(graphics);
|
rightLineComponent.render(graphics);
|
||||||
y += metrics.getHeight() + SEPARATOR;
|
y += metrics.getHeight();
|
||||||
|
|
||||||
return new Dimension(preferredSize.width, y);
|
return new Dimension(preferredSize.width, y);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,12 +24,10 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.ui.overlay.components;
|
package net.runelite.client.ui.overlay.components;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
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.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -44,26 +42,16 @@ public class PanelComponent implements LayoutableRenderableEntity
|
|||||||
VERTICAL;
|
VERTICAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int TOP_BORDER = 4;
|
private static final int TOP_BORDER = ComponentConstants.STANDARD_PADDING;
|
||||||
private static final int LEFT_BORDER = 4;
|
private static final int LEFT_BORDER = ComponentConstants.STANDARD_PADDING;
|
||||||
private static final int RIGHT_BORDER = 4;
|
private static final int RIGHT_BORDER = ComponentConstants.STANDARD_PADDING;
|
||||||
private static final int BOTTOM_BORDER = 4;
|
private static final int BOTTOM_BORDER = ComponentConstants.STANDARD_PADDING;
|
||||||
private static final int SEPARATOR = 1;
|
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
private String title;
|
private Color backgroundColor = ComponentConstants.STANDARD_BACKGROUND_COLOR;
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
private Color titleColor = Color.WHITE;
|
private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 0);
|
||||||
|
|
||||||
@Setter
|
|
||||||
private Color backgroundColor = BackgroundComponent.DEFAULT_BACKGROUND_COLOR;
|
|
||||||
|
|
||||||
@Setter
|
|
||||||
private Point position = new Point();
|
|
||||||
|
|
||||||
@Setter
|
|
||||||
private Dimension preferredSize = new Dimension(129, 0);
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private List<LayoutableRenderableEntity> children = new ArrayList<>();
|
private List<LayoutableRenderableEntity> children = new ArrayList<>();
|
||||||
@@ -71,55 +59,42 @@ public class PanelComponent implements LayoutableRenderableEntity
|
|||||||
@Setter
|
@Setter
|
||||||
private Orientation orientation = Orientation.VERTICAL;
|
private Orientation orientation = Orientation.VERTICAL;
|
||||||
|
|
||||||
private final Dimension savedChildrenSize = new Dimension();
|
private final Dimension childDimensions = new Dimension();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension render(Graphics2D graphics)
|
public Dimension render(Graphics2D graphics)
|
||||||
{
|
{
|
||||||
if (Strings.isNullOrEmpty(title) && children.isEmpty())
|
if (children.isEmpty())
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final FontMetrics metrics = graphics.getFontMetrics();
|
final FontMetrics metrics = graphics.getFontMetrics();
|
||||||
|
|
||||||
// Calculate panel dimensions
|
|
||||||
int width = preferredSize.width;
|
|
||||||
int height = preferredSize.height;
|
|
||||||
int x = LEFT_BORDER;
|
|
||||||
int y = TOP_BORDER + metrics.getHeight();
|
|
||||||
|
|
||||||
// Set graphics offset at correct position
|
|
||||||
graphics.translate(position.x, position.y);
|
|
||||||
|
|
||||||
// Render background
|
// Render background
|
||||||
final Dimension dimension = new Dimension(
|
final Dimension dimension = new Dimension(
|
||||||
savedChildrenSize.width + RIGHT_BORDER,
|
LEFT_BORDER + childDimensions.width + RIGHT_BORDER,
|
||||||
savedChildrenSize.height + BOTTOM_BORDER);
|
TOP_BORDER + childDimensions.height + BOTTOM_BORDER);
|
||||||
|
|
||||||
final BackgroundComponent backgroundComponent = new BackgroundComponent();
|
final BackgroundComponent backgroundComponent = new BackgroundComponent();
|
||||||
backgroundComponent.setRectangle(new Rectangle(dimension));
|
backgroundComponent.setRectangle(new Rectangle(dimension));
|
||||||
backgroundComponent.setBackgroundColor(backgroundColor);
|
backgroundComponent.setBackgroundColor(backgroundColor);
|
||||||
backgroundComponent.render(graphics);
|
backgroundComponent.render(graphics);
|
||||||
|
|
||||||
if (!Strings.isNullOrEmpty(title))
|
// Offset children
|
||||||
{
|
final int baseX = LEFT_BORDER;
|
||||||
// Render title
|
final int baseY = TOP_BORDER + metrics.getHeight();
|
||||||
final TextComponent titleComponent = new TextComponent();
|
int width = 0;
|
||||||
titleComponent.setText(title);
|
int height = 0;
|
||||||
titleComponent.setColor(titleColor);
|
int x = baseX;
|
||||||
titleComponent.setPosition(new Point((dimension.width - metrics.stringWidth(title)) / 2, y));
|
int y = baseY;
|
||||||
titleComponent.render(graphics);
|
|
||||||
|
|
||||||
// Move children a bit
|
// Create child preferred size
|
||||||
height = y += metrics.getHeight() + SEPARATOR;
|
final Dimension childPreferredSize = new Dimension(
|
||||||
}
|
preferredSize.width - LEFT_BORDER - RIGHT_BORDER,
|
||||||
|
preferredSize.height - TOP_BORDER - BOTTOM_BORDER);
|
||||||
|
|
||||||
// Render all children
|
// Render all children
|
||||||
final Dimension childPreferredSize = new Dimension(
|
|
||||||
preferredSize.width - RIGHT_BORDER,
|
|
||||||
preferredSize.height - BOTTOM_BORDER);
|
|
||||||
|
|
||||||
for (final LayoutableRenderableEntity child : children)
|
for (final LayoutableRenderableEntity child : children)
|
||||||
{
|
{
|
||||||
child.setPreferredSize(childPreferredSize);
|
child.setPreferredSize(childPreferredSize);
|
||||||
@@ -130,24 +105,21 @@ public class PanelComponent implements LayoutableRenderableEntity
|
|||||||
switch (orientation)
|
switch (orientation)
|
||||||
{
|
{
|
||||||
case VERTICAL:
|
case VERTICAL:
|
||||||
height = y += childDimension.height + SEPARATOR;
|
height += childDimension.height;
|
||||||
width = Math.max(width, x + childDimension.width);
|
y = baseY + height;
|
||||||
|
width = Math.max(width, childDimension.width);
|
||||||
break;
|
break;
|
||||||
case HORIZONTAL:
|
case HORIZONTAL:
|
||||||
width = x += childDimension.width + SEPARATOR;
|
width += childDimension.width;
|
||||||
height = Math.max(height, y + childDimension.height);
|
x = baseX + width;
|
||||||
|
height = Math.max(height, childDimension.height);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the padding
|
// Cache children bounds
|
||||||
height -= metrics.getHeight();
|
childDimensions.setSize(width, height);
|
||||||
|
|
||||||
// Save children size
|
|
||||||
savedChildrenSize.setSize(width, height);
|
|
||||||
|
|
||||||
// Reset graphics position
|
|
||||||
graphics.translate(-position.x, -position.y);
|
|
||||||
return dimension;
|
return dimension;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,28 +33,16 @@ import java.awt.Point;
|
|||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Setter
|
||||||
public class ProgressBarComponent implements LayoutableRenderableEntity
|
public class ProgressBarComponent implements LayoutableRenderableEntity
|
||||||
{
|
{
|
||||||
@Setter
|
|
||||||
private String text;
|
private String text;
|
||||||
|
|
||||||
@Setter
|
|
||||||
private double progress;
|
private double progress;
|
||||||
|
|
||||||
@Setter
|
|
||||||
private Point position = new Point();
|
private Point position = new Point();
|
||||||
|
|
||||||
@Setter
|
|
||||||
private Color foregroundColor = new Color(82, 161, 82);
|
private Color foregroundColor = new Color(82, 161, 82);
|
||||||
|
|
||||||
@Setter
|
|
||||||
private Color backgroundColor = new Color(255, 255, 255, 127);
|
private Color backgroundColor = new Color(255, 255, 255, 127);
|
||||||
|
|
||||||
@Setter
|
|
||||||
private Color fontColor = Color.WHITE;
|
private Color fontColor = Color.WHITE;
|
||||||
|
private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 16);
|
||||||
@Setter
|
|
||||||
private Dimension preferredSize = new Dimension(129, 16);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension render(Graphics2D graphics)
|
public Dimension render(Graphics2D graphics)
|
||||||
|
|||||||
@@ -34,25 +34,14 @@ import lombok.Setter;
|
|||||||
import net.runelite.api.Point;
|
import net.runelite.api.Point;
|
||||||
import net.runelite.client.ui.overlay.RenderableEntity;
|
import net.runelite.client.ui.overlay.RenderableEntity;
|
||||||
|
|
||||||
|
@Setter
|
||||||
public class ProgressPieComponent implements RenderableEntity
|
public class ProgressPieComponent implements RenderableEntity
|
||||||
{
|
{
|
||||||
@Setter
|
|
||||||
private int diameter = 25;
|
private int diameter = 25;
|
||||||
|
|
||||||
@Setter
|
|
||||||
private Color borderColor = Color.WHITE;
|
private Color borderColor = Color.WHITE;
|
||||||
|
|
||||||
@Setter
|
|
||||||
private Color fill = Color.WHITE;
|
private Color fill = Color.WHITE;
|
||||||
|
|
||||||
@Setter
|
|
||||||
private Stroke stroke = new BasicStroke(1);
|
private Stroke stroke = new BasicStroke(1);
|
||||||
|
|
||||||
@Setter
|
|
||||||
private double progress;
|
private double progress;
|
||||||
|
|
||||||
@Setter
|
|
||||||
private Point position;
|
private Point position;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -33,19 +33,15 @@ import java.util.regex.Pattern;
|
|||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import net.runelite.client.ui.overlay.RenderableEntity;
|
import net.runelite.client.ui.overlay.RenderableEntity;
|
||||||
|
|
||||||
|
@Setter
|
||||||
public class TextComponent implements RenderableEntity
|
public class TextComponent implements RenderableEntity
|
||||||
{
|
{
|
||||||
private static final String COL_TAG_REGEX = "(<col=([0-9a-fA-F]){2,6}>)";
|
private static final String COL_TAG_REGEX = "(<col=([0-9a-fA-F]){2,6}>)";
|
||||||
private static final Pattern COL_TAG_PATTERN_W_LOOKAHEAD = Pattern.compile("(?=" + COL_TAG_REGEX + ")");
|
private static final Pattern COL_TAG_PATTERN_W_LOOKAHEAD = Pattern.compile("(?=" + COL_TAG_REGEX + ")");
|
||||||
private static final Pattern COL_TAG_PATTERN = Pattern.compile(COL_TAG_REGEX);
|
private static final Pattern COL_TAG_PATTERN = Pattern.compile(COL_TAG_REGEX);
|
||||||
|
|
||||||
@Setter
|
|
||||||
private String text;
|
private String text;
|
||||||
|
|
||||||
@Setter
|
|
||||||
private Point position = new Point();
|
private Point position = new Point();
|
||||||
|
|
||||||
@Setter
|
|
||||||
private Color color = Color.WHITE;
|
private Color color = Color.WHITE;
|
||||||
|
|
||||||
public static String textWithoutColTags(String text)
|
public static String textWithoutColTags(String text)
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, Tomas Slusny <slusnucky@gmail.com>
|
||||||
|
* 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.Color;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.FontMetrics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Point;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
public class TitleComponent implements LayoutableRenderableEntity
|
||||||
|
{
|
||||||
|
private String text;
|
||||||
|
|
||||||
|
@Builder.Default
|
||||||
|
private Color color = Color.WHITE;
|
||||||
|
|
||||||
|
@Builder.Default
|
||||||
|
private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 0);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension render(Graphics2D graphics)
|
||||||
|
{
|
||||||
|
final FontMetrics metrics = graphics.getFontMetrics();
|
||||||
|
final TextComponent titleComponent = new TextComponent();
|
||||||
|
titleComponent.setText(text);
|
||||||
|
titleComponent.setColor(color);
|
||||||
|
titleComponent.setPosition(new Point((preferredSize.width - metrics.stringWidth(text)) / 2, 0));
|
||||||
|
final Dimension dimension = titleComponent.render(graphics);
|
||||||
|
return new Dimension(Math.max(preferredSize.width, dimension.width), Math.max(preferredSize.height, dimension.height));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,22 +35,16 @@ import lombok.Setter;
|
|||||||
import net.runelite.api.IndexedSprite;
|
import net.runelite.api.IndexedSprite;
|
||||||
import net.runelite.client.ui.overlay.RenderableEntity;
|
import net.runelite.client.ui.overlay.RenderableEntity;
|
||||||
|
|
||||||
|
@Setter
|
||||||
public class TooltipComponent implements RenderableEntity
|
public class TooltipComponent implements RenderableEntity
|
||||||
{
|
{
|
||||||
private static final Pattern BR = Pattern.compile("</br>");
|
private static final Pattern BR = Pattern.compile("</br>");
|
||||||
private static final int OFFSET = 4;
|
private static final int OFFSET = 4;
|
||||||
private static final int MOD_ICON_WIDTH = 13; // they are generally 13px wide
|
private static final int MOD_ICON_WIDTH = 13; // they are generally 13px wide
|
||||||
|
|
||||||
@Setter
|
|
||||||
private String text;
|
private String text;
|
||||||
|
private Color backgroundColor = ComponentConstants.STANDARD_BACKGROUND_COLOR;
|
||||||
@Setter
|
|
||||||
private Color backgroundColor = BackgroundComponent.DEFAULT_BACKGROUND_COLOR;
|
|
||||||
|
|
||||||
@Setter
|
|
||||||
private Point position = new Point();
|
private Point position = new Point();
|
||||||
|
|
||||||
@Setter
|
|
||||||
private IndexedSprite[] modIcons;
|
private IndexedSprite[] modIcons;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user