From 18d579eb628ee1a2a74e54cb80211f9b7109e3dc Mon Sep 17 00:00:00 2001 From: yugecin Date: Tue, 17 Jan 2017 13:37:47 +0100 Subject: [PATCH] smallbold font and newlines when wrapping text (itdelatrisu/opsu@21aa72b) --- src/itdelatrisu/opsu/states/ButtonMenu.java | 2 +- src/itdelatrisu/opsu/ui/Fonts.java | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/itdelatrisu/opsu/states/ButtonMenu.java b/src/itdelatrisu/opsu/states/ButtonMenu.java index 969e3e3c..df9e7db1 100644 --- a/src/itdelatrisu/opsu/states/ButtonMenu.java +++ b/src/itdelatrisu/opsu/states/ButtonMenu.java @@ -446,7 +446,7 @@ public class ButtonMenu extends BasicGameState { for (int i = 0; i < title.length; i++) { // wrap text if too long if (Fonts.LARGE.getWidth(title[i]) > maxLineWidth) { - List list = Fonts.wrap(Fonts.LARGE, title[i], maxLineWidth); + List list = Fonts.wrap(Fonts.LARGE, title[i], maxLineWidth, false); actualTitle.addAll(list); } else actualTitle.add(title[i]); diff --git a/src/itdelatrisu/opsu/ui/Fonts.java b/src/itdelatrisu/opsu/ui/Fonts.java index 14ecbdb0..2b1cb6d6 100644 --- a/src/itdelatrisu/opsu/ui/Fonts.java +++ b/src/itdelatrisu/opsu/ui/Fonts.java @@ -40,7 +40,7 @@ import org.newdawn.slick.util.ResourceLoader; * Fonts used for drawing. */ public class Fonts { - public static UnicodeFont DEFAULT, BOLD, XLARGE, LARGE, MEDIUM, MEDIUMBOLD, SMALL; + public static UnicodeFont DEFAULT, BOLD, XLARGE, LARGE, MEDIUM, MEDIUMBOLD, SMALL, SMALLBOLD; /** Set of all Unicode strings already loaded per font. */ private static HashMap> loadedGlyphs = new HashMap>(); @@ -65,6 +65,7 @@ public class Fonts { MEDIUM = new UnicodeFont(font.deriveFont(fontBase * 3 / 2)); MEDIUMBOLD = new UnicodeFont(font.deriveFont(Font.BOLD, fontBase * 3 / 2)); SMALL = new UnicodeFont(font.deriveFont(fontBase)); + SMALLBOLD = new UnicodeFont(font.deriveFont(Font.BOLD, fontBase)); ColorEffect colorEffect = new ColorEffect(); loadFont(DEFAULT, colorEffect); loadFont(BOLD, colorEffect); @@ -73,6 +74,7 @@ public class Fonts { loadFont(MEDIUM, colorEffect); loadFont(MEDIUMBOLD, colorEffect); loadFont(SMALL, colorEffect); + loadFont(SMALLBOLD, colorEffect); } /** @@ -123,7 +125,7 @@ public class Fonts { * @return the list of split strings * @author davedes (http://slick.ninjacave.com/forum/viewtopic.php?t=3778) */ - public static List wrap(org.newdawn.slick.Font font, String text, int width) { + public static List wrap(org.newdawn.slick.Font font, String text, int width, boolean newlines) { List list = new ArrayList(); String str = text; String line = ""; @@ -134,7 +136,7 @@ public class Fonts { if (Character.isWhitespace(c)) lastSpace = i; String append = line + c; - if (font.getWidth(append) > width) { + if (font.getWidth(append) > width || (newlines && c == '\n')) { int split = (lastSpace != -1) ? lastSpace : i; int splitTrimmed = split; if (lastSpace != -1 && split < str.length() - 1) @@ -153,4 +155,5 @@ public class Fonts { list.add(str); return list; } + }