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:
@@ -41,4 +41,5 @@ public class ScreenMarker
|
||||
private Color color;
|
||||
private Color fill;
|
||||
private boolean visible;
|
||||
private boolean labelled;
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ public class ScreenMarkerOverlay extends Overlay
|
||||
screenMarkerRenderable.setFill(marker.getFill());
|
||||
screenMarkerRenderable.setStroke(new BasicStroke(marker.getBorderThickness()));
|
||||
screenMarkerRenderable.setSize(preferredSize);
|
||||
screenMarkerRenderable.setLabel(marker.isLabelled() ? marker.getName() : "");
|
||||
return screenMarkerRenderable.render(graphics);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,7 +203,8 @@ public class ScreenMarkerPlugin extends Plugin
|
||||
pluginPanel.getSelectedBorderThickness(),
|
||||
pluginPanel.getSelectedColor(),
|
||||
pluginPanel.getSelectedFillColor(),
|
||||
true
|
||||
true,
|
||||
false
|
||||
);
|
||||
|
||||
// Set overlay creator bounds to current position and default size
|
||||
|
||||
@@ -42,6 +42,7 @@ class ScreenMarkerRenderable implements RenderableEntity
|
||||
private Color color;
|
||||
private Color fill;
|
||||
private Stroke stroke;
|
||||
private String label;
|
||||
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics)
|
||||
@@ -60,6 +61,12 @@ class ScreenMarkerRenderable implements RenderableEntity
|
||||
graphics.setColor(color);
|
||||
graphics.setStroke(stroke);
|
||||
graphics.drawRect(offset, offset, width - thickness, height - thickness);
|
||||
|
||||
if (!label.isEmpty())
|
||||
{
|
||||
graphics.drawString(label, 0, 0);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,11 @@ class ScreenMarkerPanel extends JPanel
|
||||
private static final ImageIcon NO_FILL_COLOR_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_HOVER_ICON;
|
||||
private static final ImageIcon INVISIBLE_ICON;
|
||||
@@ -87,6 +92,7 @@ class ScreenMarkerPanel extends JPanel
|
||||
|
||||
private final JLabel borderColorIndicator = new JLabel();
|
||||
private final JLabel fillColorIndicator = new JLabel();
|
||||
private final JLabel labelIndicator = new JLabel();
|
||||
private final JLabel visibilityLabel = new JLabel();
|
||||
private final JLabel deleteLabel = new JLabel();
|
||||
|
||||
@@ -99,6 +105,7 @@ class ScreenMarkerPanel extends JPanel
|
||||
private final JSpinner thicknessSpinner = new JSpinner(spinnerModel);
|
||||
|
||||
private boolean visible;
|
||||
private boolean showLabel;
|
||||
|
||||
static
|
||||
{
|
||||
@@ -118,6 +125,14 @@ class ScreenMarkerPanel extends JPanel
|
||||
NO_FILL_COLOR_ICON = new ImageIcon(fillImgHover);
|
||||
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");
|
||||
VISIBLE_ICON = new ImageIcon(visibleImg);
|
||||
VISIBLE_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(visibleImg, -100));
|
||||
@@ -136,6 +151,7 @@ class ScreenMarkerPanel extends JPanel
|
||||
this.plugin = plugin;
|
||||
this.marker = marker;
|
||||
this.visible = marker.getMarker().isVisible();
|
||||
this.showLabel = marker.getMarker().isLabelled();
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||
@@ -320,8 +336,30 @@ class ScreenMarkerPanel extends JPanel
|
||||
thicknessSpinner.addChangeListener(ce -> updateThickness(true));
|
||||
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(fillColorIndicator);
|
||||
leftActions.add(labelIndicator);
|
||||
leftActions.add(thicknessSpinner);
|
||||
|
||||
JPanel rightActions = new JPanel(new FlowLayout(FlowLayout.RIGHT, 8, 0));
|
||||
@@ -391,7 +429,7 @@ class ScreenMarkerPanel extends JPanel
|
||||
updateFill();
|
||||
updateBorder();
|
||||
updateBorder();
|
||||
|
||||
updateLabelling();
|
||||
}
|
||||
|
||||
private void preview(boolean on)
|
||||
@@ -412,6 +450,14 @@ class ScreenMarkerPanel extends JPanel
|
||||
updateVisibility();
|
||||
}
|
||||
|
||||
private void toggleLabelling(boolean on)
|
||||
{
|
||||
showLabel = on;
|
||||
marker.getMarker().setLabelled(showLabel);
|
||||
plugin.updateConfig();
|
||||
updateLabelling();
|
||||
}
|
||||
|
||||
private void save()
|
||||
{
|
||||
marker.getMarker().setName(nameInput.getText());
|
||||
@@ -460,6 +506,12 @@ class ScreenMarkerPanel extends JPanel
|
||||
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()
|
||||
{
|
||||
final boolean isFullyTransparent = marker.getMarker().getFill().getAlpha() == 0;
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 243 B |
Reference in New Issue
Block a user