Skip to content

Commit 7c7fd45

Browse files
Merge pull request #5740 from bubblobill/dovetail
Minor tweak to facing arrow
2 parents bf6f340 + 83abcba commit 7c7fd45

8 files changed

Lines changed: 136 additions & 19 deletions

File tree

common/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies {
1717

1818
implementation(libs.bundles.imageio)
1919
implementation(libs.batik)
20+
implementation(libs.jsvg)
2021

2122
implementation(libs.apache.commons.io)
2223

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* This software Copyright by the RPTools.net development team, and
3+
* licensed under the Affero GPL Version 3 or, at your option, any later
4+
* version.
5+
*
6+
* MapTool Source Code is distributed in the hope that it will be
7+
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
8+
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9+
*
10+
* You should have received a copy of the GNU Affero General Public
11+
* License * along with this source Code. If not, please visit
12+
* <http://www.gnu.org/licenses/> and specifically the Affero license
13+
* text at <http://www.gnu.org/licenses/agpl.html>.
14+
*/
15+
package net.rptools.lib;
16+
17+
import com.github.weisj.jsvg.geometry.path.BuildHistory;
18+
import com.github.weisj.jsvg.geometry.path.PathCommand;
19+
import com.github.weisj.jsvg.geometry.path.PathParser;
20+
import java.awt.geom.AffineTransform;
21+
import java.awt.geom.Path2D;
22+
23+
public class SVGUtils {
24+
public static Path2D svgToPath2D(String pathString) {
25+
PathParser pp = new PathParser(pathString);
26+
PathCommand[] commands = pp.parsePathCommand();
27+
Path2D path = new Path2D.Float();
28+
BuildHistory hist = new BuildHistory();
29+
for (PathCommand pathCommand : commands) {
30+
pathCommand.appendPath(path, hist);
31+
}
32+
path.trimToSize();
33+
path =
34+
new Path2D.Float(
35+
AffineTransform.getTranslateInstance(
36+
-path.getBounds2D().getCenterX(), -path.getBounds2D().getCenterY())
37+
.createTransformedShape(path));
38+
return path;
39+
}
40+
}

src/main/java/net/rptools/maptool/client/AppPreferences.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,15 @@ public static PreferenceStore getAppPreferenceStore() {
639639
"Preferences.label.tokens.portrait.mouse",
640640
"Preferences.label.tokens.portrait.mouse.tooltip",
641641
true);
642+
public static final Preference<Color> facingArrowBGColour =
643+
store
644+
.defineColor("facingArrowBGColour", Color.yellow, false)
645+
.setLabel("Preferences.label.tokens.arrow.background");
646+
647+
public static final Preference<Color> facingArrowBorderColour =
648+
store
649+
.defineColor("facingArrowBorderColour", Color.darkGray, false)
650+
.setLabel("Preferences.label.tokens.arrow.border");
642651

643652
public static final Preference<Boolean> forceFacingArrow =
644653
store.defineBoolean(

src/main/java/net/rptools/maptool/client/ui/preferencesdialog/PreferencesDialog.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ public class PreferencesDialog extends AbeillePanel {
245245
/** Checkbox for if macro link details should be suppressed in tooltips. */
246246
private final JCheckBox suppressToolTipsMacroLinks = getCheckBox("suppressToolTipsMacroLinks");
247247

248+
/** ColorWell for the facing arrow border colour. */
249+
private final ColorWell facingArrowBorderColour =
250+
(ColorWell) getComponent("facingArrowBorderColour");
251+
252+
/** ColorWell for the facing arrow colour. */
253+
private final ColorWell facingArrowColour = (ColorWell) getComponent("facingArrowColour");
254+
248255
/** ColorWell for the completed trusted path output foreground color. */
249256
private final ColorWell trustedOutputForeground =
250257
(ColorWell) getComponent("trustedOuputForeground");
@@ -915,6 +922,16 @@ protected Integer convertString(String value) throws ParseException {
915922
}
916923
});
917924

925+
facingArrowColour.addActionListener(
926+
e -> {
927+
AppPreferences.facingArrowBGColour.set(facingArrowColour.getColor());
928+
});
929+
930+
facingArrowBorderColour.addActionListener(
931+
e -> {
932+
AppPreferences.facingArrowBorderColour.set(facingArrowBorderColour.getColor());
933+
});
934+
918935
chatNotificationColor.addActionListener(
919936
e -> {
920937
AppPreferences.chatNotificationColor.set(chatNotificationColor.getColor());
@@ -1668,6 +1685,8 @@ private void setInitialState() {
16681685
showStatSheetModifierCheckBox.setSelected(
16691686
AppPreferences.showStatSheetRequiresModifierKey.get());
16701687
forceFacingArrowCheckBox.setSelected(AppPreferences.forceFacingArrow.get());
1688+
facingArrowColour.setColor(AppPreferences.facingArrowBGColour.get());
1689+
facingArrowBorderColour.setColor(AppPreferences.facingArrowBorderColour.get());
16711690
backgroundsStartSnapToGridCheckBox.setSelected(AppPreferences.backgroundsStartSnapToGrid.get());
16721691
defaultGridSizeTextField.setText(Integer.toString(AppPreferences.defaultGridSize.get()));
16731692
// Localizes units per cell, using the proper separator. Fixes #507.

src/main/java/net/rptools/maptool/client/ui/preferencesdialog/PreferencesDialogView.form

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@
603603
<properties/>
604604
<border type="none"/>
605605
<children>
606-
<grid id="b641a" layout-manager="GridLayoutManager" row-count="17" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
606+
<grid id="b641a" layout-manager="GridLayoutManager" row-count="19" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
607607
<margin top="0" left="0" bottom="0" right="0"/>
608608
<constraints>
609609
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="true"/>
@@ -803,7 +803,7 @@
803803
</component>
804804
<component id="e774c" class="javax.swing.JCheckBox">
805805
<constraints>
806-
<grid row="12" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
806+
<grid row="14" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
807807
</constraints>
808808
<properties>
809809
<actionCommand value="Show statsheet on mouseover"/>
@@ -851,7 +851,7 @@
851851
</component>
852852
<component id="bf608" class="javax.swing.JLabel">
853853
<constraints>
854-
<grid row="13" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
854+
<grid row="15" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
855855
</constraints>
856856
<properties>
857857
<text resource-bundle="net/rptools/maptool/language/i18n" key="Preferences.label.tokens.drag.snap"/>
@@ -860,7 +860,7 @@
860860
</component>
861861
<component id="88d43" class="javax.swing.JCheckBox">
862862
<constraints>
863-
<grid row="13" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
863+
<grid row="15" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
864864
</constraints>
865865
<properties>
866866
<name value="tokensSnapWhileDragging"/>
@@ -869,7 +869,7 @@
869869
</component>
870870
<component id="c0cdd" class="javax.swing.JLabel">
871871
<constraints>
872-
<grid row="12" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
872+
<grid row="14" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
873873
</constraints>
874874
<properties>
875875
<text resource-bundle="net/rptools/maptool/language/i18n" key="Preferences.label.tokens.arrow"/>
@@ -878,7 +878,7 @@
878878
</component>
879879
<component id="82a88" class="javax.swing.JLabel">
880880
<constraints>
881-
<grid row="14" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
881+
<grid row="16" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
882882
</constraints>
883883
<properties>
884884
<text resource-bundle="net/rptools/maptool/language/i18n" key="Preferences.label.tokens.drag.hide"/>
@@ -887,7 +887,7 @@
887887
</component>
888888
<component id="2dbc6" class="javax.swing.JCheckBox">
889889
<constraints>
890-
<grid row="14" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
890+
<grid row="16" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
891891
</constraints>
892892
<properties>
893893
<name value="hideMousePointerWhileDragging"/>
@@ -897,7 +897,7 @@
897897
</component>
898898
<component id="60bed" class="javax.swing.JLabel">
899899
<constraints>
900-
<grid row="15" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
900+
<grid row="17" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
901901
</constraints>
902902
<properties>
903903
<text resource-bundle="net/rptools/maptool/language/i18n" key="Preferences.label.tokens.stack.hide"/>
@@ -906,13 +906,49 @@
906906
</component>
907907
<component id="93234" class="javax.swing.JCheckBox">
908908
<constraints>
909-
<grid row="15" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
909+
<grid row="17" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
910910
</constraints>
911911
<properties>
912912
<name value="hideTokenStackIndicator"/>
913913
<text value="&#9;"/>
914914
</properties>
915915
</component>
916+
<component id="d6a90" class="javax.swing.JLabel">
917+
<constraints>
918+
<grid row="12" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
919+
</constraints>
920+
<properties>
921+
<text resource-bundle="net/rptools/maptool/language/i18n" key="Preferences.label.tokens.arrow.background"/>
922+
<toolTipText value=""/>
923+
</properties>
924+
</component>
925+
<component id="2b798" class="net.rptools.maptool.client.swing.ColorWell">
926+
<constraints>
927+
<grid row="12" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
928+
</constraints>
929+
<properties>
930+
<font swing-font="Panel.font"/>
931+
<name value="facingArrowColour"/>
932+
</properties>
933+
</component>
934+
<component id="bc0b6" class="javax.swing.JLabel">
935+
<constraints>
936+
<grid row="13" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
937+
</constraints>
938+
<properties>
939+
<text resource-bundle="net/rptools/maptool/language/i18n" key="Preferences.label.tokens.arrow.border"/>
940+
<toolTipText value=""/>
941+
</properties>
942+
</component>
943+
<component id="56c18" class="net.rptools.maptool.client.swing.ColorWell">
944+
<constraints>
945+
<grid row="13" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
946+
</constraints>
947+
<properties>
948+
<font swing-font="Panel.font"/>
949+
<name value="facingArrowBorderColour"/>
950+
</properties>
951+
</component>
916952
</children>
917953
</grid>
918954
<vspacer id="a9eb4">

src/main/java/net/rptools/maptool/client/ui/zone/renderer/ZoneRenderer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,11 +1825,6 @@ protected void renderTokens(
18251825
tokenRenderer.renderToken(token, position, tokenG, opacity);
18261826
timer.stop("token-list-7");
18271827

1828-
timer.start("token-list-8");
1829-
// Facing
1830-
facingArrowRenderer.paintArrow(tokenG, position);
1831-
timer.stop("token-list-8");
1832-
18331828
timer.start("token-list-9");
18341829
// Set up the graphics so that the overlay can just be painted.
18351830
Rectangle2D tokenBounds = zoneScale.toScreenSpace(position.transformedBounds().getBounds2D());
@@ -1875,6 +1870,11 @@ protected void renderTokens(
18751870
locG.dispose();
18761871
timer.stop("token-list-10");
18771872

1873+
timer.start("token-list-8");
1874+
// Facing
1875+
facingArrowRenderer.paintArrow(tokenG, position);
1876+
timer.stop("token-list-8");
1877+
18781878
timer.start("token-list-11");
18791879
// Keep track of which tokens have been drawn for post-processing on them later
18801880
// (such as selection borders and names/labels)

src/main/java/net/rptools/maptool/client/ui/zone/renderer/tokenRender/FacingArrowRenderer.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.awt.geom.Rectangle2D;
2121
import java.util.ArrayList;
2222
import net.rptools.lib.CodeTimer;
23+
import net.rptools.lib.image.ImageUtil;
2324
import net.rptools.maptool.client.AppPreferences;
2425
import net.rptools.maptool.client.ui.zone.ZoneViewModel.TokenPosition;
2526
import net.rptools.maptool.client.ui.zone.renderer.RenderHelper;
@@ -30,16 +31,18 @@
3031

3132
public class FacingArrowRenderer {
3233
private static final Logger log = LogManager.getLogger(FacingArrowRenderer.class);
34+
private static final double tailX = -0.25;
35+
private static final double dovetailX = -0.15;
36+
private static final double tailY = .35;
3337

3438
/** An arrow facing horizontally to the positive x-axis, with its point at (0, 0). */
35-
private static final Path2D UNIT_ARROW;
39+
public static final Path2D UNIT_ARROW;
3640

3741
static {
38-
final double tailX = -0.25;
39-
final double tailY = .35;
4042
UNIT_ARROW = new Path2D.Double();
4143
UNIT_ARROW.moveTo(0, 0);
4244
UNIT_ARROW.lineTo(tailX, -tailY);
45+
UNIT_ARROW.lineTo(dovetailX, 0);
4346
UNIT_ARROW.lineTo(tailX, tailY);
4447
UNIT_ARROW.closePath();
4548
}
@@ -48,8 +51,13 @@ public class FacingArrowRenderer {
4851
private final Zone zone;
4952

5053
private final ArrayList<Color> figureFillColours = new ArrayList<>();
51-
private final Color fillColour = Color.YELLOW;
52-
private final Color borderColour = Color.DARK_GRAY;
54+
private Color fillColour = AppPreferences.facingArrowBGColour.get();
55+
private Color borderColour = AppPreferences.facingArrowBorderColour.get();
56+
57+
{
58+
AppPreferences.facingArrowBGColour.onChange(color -> fillColour = color);
59+
AppPreferences.facingArrowBorderColour.onChange(color -> borderColour = color);
60+
}
5361

5462
public FacingArrowRenderer(RenderHelper renderHelper, Zone zone) {
5563
this.renderHelper = renderHelper;
@@ -117,7 +125,9 @@ private void paintArrowWorld(
117125
timer.stop("FacingArrowRenderer-fill");
118126

119127
timer.start("FacingArrowRenderer-draw");
128+
tokenG.setRenderingHints(ImageUtil.getRenderingHintsQuality());
120129
tokenG.setColor(borderColour);
130+
tokenG.setStroke(new BasicStroke(0.85f));
121131
tokenG.draw(facingArrow);
122132
timer.stop("FacingArrowRenderer-draw");
123133
} catch (Exception e) {

src/main/resources/net/rptools/maptool/language/i18n.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,8 @@ Preferences.label.tokens.statsheet.mouse = Show statsheet on mouseover
772772
Preferences.label.tokens.statsheet.mouse.tooltip = Whether to show the statsheet when the mouse hovers over a Token.
773773
Preferences.label.tokens.statsheet.shift = Stat sheet requires Shift key
774774
Preferences.label.tokens.statsheet.shift.tooltip = The stat sheet will only show when the mouse hovers over a Token if the Shift key is also held down. Otherwise, Shift key will hide stat sheet on mouse hovers.
775+
Preferences.label.tokens.arrow.background = Token Facing Arrow color
776+
Preferences.label.tokens.arrow.border = Token Facing Arrow border color
775777
Preferences.label.tokens.arrow = Force Token Facing Arrow
776778
Preferences.label.tokens.arrow.tooltip = Forces the display of the token facing arrow for Top Down tokens and tokens with image tables.
777779
Preferences.label.tokens.drag.snap = Snap Token while dragging

0 commit comments

Comments
 (0)