screen markers: add marker labels

This adds a toggle to display the marker name as a label above the
marker

Co-authored-by: Skretzo <53493631+Skretzo@users.noreply.github.com>
This commit is contained in:
Adam
2022-02-19 19:13:10 -05:00
parent 9f5a3a7b3b
commit 109ad81473
6 changed files with 64 additions and 2 deletions

View File

@@ -41,4 +41,5 @@ public class ScreenMarker
private Color color; private Color color;
private Color fill; private Color fill;
private boolean visible; private boolean visible;
private boolean labelled;
} }

View File

@@ -79,6 +79,7 @@ public class ScreenMarkerOverlay extends Overlay
screenMarkerRenderable.setFill(marker.getFill()); screenMarkerRenderable.setFill(marker.getFill());
screenMarkerRenderable.setStroke(new BasicStroke(marker.getBorderThickness())); screenMarkerRenderable.setStroke(new BasicStroke(marker.getBorderThickness()));
screenMarkerRenderable.setSize(preferredSize); screenMarkerRenderable.setSize(preferredSize);
screenMarkerRenderable.setLabel(marker.isLabelled() ? marker.getName() : "");
return screenMarkerRenderable.render(graphics); return screenMarkerRenderable.render(graphics);
} }
} }

View File

@@ -203,7 +203,8 @@ public class ScreenMarkerPlugin extends Plugin
pluginPanel.getSelectedBorderThickness(), pluginPanel.getSelectedBorderThickness(),
pluginPanel.getSelectedColor(), pluginPanel.getSelectedColor(),
pluginPanel.getSelectedFillColor(), pluginPanel.getSelectedFillColor(),
true true,
false
); );
// Set overlay creator bounds to current position and default size // Set overlay creator bounds to current position and default size

View File

@@ -42,6 +42,7 @@ class ScreenMarkerRenderable implements RenderableEntity
private Color color; private Color color;
private Color fill; private Color fill;
private Stroke stroke; private Stroke stroke;
private String label;
@Override @Override
public Dimension render(Graphics2D graphics) public Dimension render(Graphics2D graphics)
@@ -60,6 +61,12 @@ class ScreenMarkerRenderable implements RenderableEntity
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);
if (!label.isEmpty())
{
graphics.drawString(label, 0, 0);
}
return size; return size;
} }
} }

View File

@@ -74,6 +74,11 @@ class ScreenMarkerPanel extends JPanel
private static final ImageIcon NO_FILL_COLOR_ICON; private static final ImageIcon NO_FILL_COLOR_ICON;
private static final ImageIcon NO_FILL_COLOR_HOVER_ICON; private static final ImageIcon NO_FILL_COLOR_HOVER_ICON;
private static final ImageIcon LABEL_ICON;
private static final ImageIcon LABEL_HOVER_ICON;
private static final ImageIcon NO_LABEL_ICON;
private static final ImageIcon NO_LABEL_HOVER_ICON;
private static final ImageIcon VISIBLE_ICON; private static final ImageIcon VISIBLE_ICON;
private static final ImageIcon VISIBLE_HOVER_ICON; private static final ImageIcon VISIBLE_HOVER_ICON;
private static final ImageIcon INVISIBLE_ICON; private static final ImageIcon INVISIBLE_ICON;
@@ -87,6 +92,7 @@ class ScreenMarkerPanel extends JPanel
private final JLabel borderColorIndicator = new JLabel(); private final JLabel borderColorIndicator = new JLabel();
private final JLabel fillColorIndicator = new JLabel(); private final JLabel fillColorIndicator = new JLabel();
private final JLabel labelIndicator = new JLabel();
private final JLabel visibilityLabel = new JLabel(); private final JLabel visibilityLabel = new JLabel();
private final JLabel deleteLabel = new JLabel(); private final JLabel deleteLabel = new JLabel();
@@ -99,6 +105,7 @@ class ScreenMarkerPanel extends JPanel
private final JSpinner thicknessSpinner = new JSpinner(spinnerModel); private final JSpinner thicknessSpinner = new JSpinner(spinnerModel);
private boolean visible; private boolean visible;
private boolean showLabel;
static static
{ {
@@ -118,6 +125,14 @@ class ScreenMarkerPanel extends JPanel
NO_FILL_COLOR_ICON = new ImageIcon(fillImgHover); NO_FILL_COLOR_ICON = new ImageIcon(fillImgHover);
NO_FILL_COLOR_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(fillImgHover, -100)); NO_FILL_COLOR_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(fillImgHover, -100));
final BufferedImage labelImg = ImageUtil.loadImageResource(ScreenMarkerPlugin.class, "label_icon.png");
final BufferedImage labelImgHover = ImageUtil.luminanceOffset(labelImg, -150);
LABEL_ICON = new ImageIcon(labelImg);
LABEL_HOVER_ICON = new ImageIcon(labelImgHover);
NO_LABEL_ICON = new ImageIcon(labelImgHover);
NO_LABEL_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(labelImgHover, -100));
final BufferedImage visibleImg = ImageUtil.loadImageResource(ScreenMarkerPlugin.class, "visible_icon.png"); final BufferedImage visibleImg = ImageUtil.loadImageResource(ScreenMarkerPlugin.class, "visible_icon.png");
VISIBLE_ICON = new ImageIcon(visibleImg); VISIBLE_ICON = new ImageIcon(visibleImg);
VISIBLE_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(visibleImg, -100)); VISIBLE_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(visibleImg, -100));
@@ -136,6 +151,7 @@ class ScreenMarkerPanel extends JPanel
this.plugin = plugin; this.plugin = plugin;
this.marker = marker; this.marker = marker;
this.visible = marker.getMarker().isVisible(); this.visible = marker.getMarker().isVisible();
this.showLabel = marker.getMarker().isLabelled();
setLayout(new BorderLayout()); setLayout(new BorderLayout());
setBackground(ColorScheme.DARKER_GRAY_COLOR); setBackground(ColorScheme.DARKER_GRAY_COLOR);
@@ -320,8 +336,30 @@ class ScreenMarkerPanel extends JPanel
thicknessSpinner.addChangeListener(ce -> updateThickness(true)); thicknessSpinner.addChangeListener(ce -> updateThickness(true));
thicknessSpinner.setToolTipText("Border thickness"); thicknessSpinner.setToolTipText("Border thickness");
labelIndicator.addMouseListener(new MouseAdapter()
{
@Override
public void mousePressed(MouseEvent mouseEvent)
{
toggleLabelling(!showLabel);
}
@Override
public void mouseEntered(MouseEvent mouseEvent)
{
labelIndicator.setIcon(showLabel ? LABEL_HOVER_ICON : NO_LABEL_HOVER_ICON);
}
@Override
public void mouseExited(MouseEvent mouseEvent)
{
labelIndicator.setIcon(showLabel ? LABEL_ICON : NO_LABEL_ICON);
}
});
leftActions.add(borderColorIndicator); leftActions.add(borderColorIndicator);
leftActions.add(fillColorIndicator); leftActions.add(fillColorIndicator);
leftActions.add(labelIndicator);
leftActions.add(thicknessSpinner); leftActions.add(thicknessSpinner);
JPanel rightActions = new JPanel(new FlowLayout(FlowLayout.RIGHT, 8, 0)); JPanel rightActions = new JPanel(new FlowLayout(FlowLayout.RIGHT, 8, 0));
@@ -391,7 +429,7 @@ class ScreenMarkerPanel extends JPanel
updateFill(); updateFill();
updateBorder(); updateBorder();
updateBorder(); updateBorder();
updateLabelling();
} }
private void preview(boolean on) private void preview(boolean on)
@@ -412,6 +450,14 @@ class ScreenMarkerPanel extends JPanel
updateVisibility(); updateVisibility();
} }
private void toggleLabelling(boolean on)
{
showLabel = on;
marker.getMarker().setLabelled(showLabel);
plugin.updateConfig();
updateLabelling();
}
private void save() private void save()
{ {
marker.getMarker().setName(nameInput.getText()); marker.getMarker().setName(nameInput.getText());
@@ -460,6 +506,12 @@ class ScreenMarkerPanel extends JPanel
visibilityLabel.setToolTipText(visible ? "Hide screen marker" : "Show screen marker"); visibilityLabel.setToolTipText(visible ? "Hide screen marker" : "Show screen marker");
} }
private void updateLabelling()
{
labelIndicator.setIcon(showLabel ? LABEL_ICON : NO_LABEL_ICON);
labelIndicator.setToolTipText(showLabel ? "Hide label" : "Show label");
}
private void updateFill() private void updateFill()
{ {
final boolean isFullyTransparent = marker.getMarker().getFill().getAlpha() == 0; final boolean isFullyTransparent = marker.getMarker().getFill().getAlpha() == 0;

Binary file not shown.

After

Width:  |  Height:  |  Size: 243 B