mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
Refactor FSkinFont to avoid exposing BitmapFont instance
This commit is contained in:
@@ -12,7 +12,6 @@ import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.GL10;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
@@ -941,10 +940,10 @@ public class Forge implements ApplicationListener {
|
||||
batch.draw(image, adjustX(x), adjustY(y, h), originX - x, h - (originY - y), w, h, 1, 1, rotation, 0, 0, image.getWidth(), image.getHeight(), false, false);
|
||||
}
|
||||
|
||||
public void drawText(String text, FSkinFont skinFont, FSkinColor skinColor, float x, float y, float w, float h, boolean wrap, HAlignment horzAlignment, boolean centerVertically) {
|
||||
drawText(text, skinFont, skinColor.getColor(), x, y, w, h, wrap, horzAlignment, centerVertically);
|
||||
public void drawText(String text, FSkinFont font, FSkinColor skinColor, float x, float y, float w, float h, boolean wrap, HAlignment horzAlignment, boolean centerVertically) {
|
||||
drawText(text, font, skinColor.getColor(), x, y, w, h, wrap, horzAlignment, centerVertically);
|
||||
}
|
||||
public void drawText(String text, FSkinFont skinFont, Color color, float x, float y, float w, float h, boolean wrap, HAlignment horzAlignment, boolean centerVertically) {
|
||||
public void drawText(String text, FSkinFont font, Color color, float x, float y, float w, float h, boolean wrap, HAlignment horzAlignment, boolean centerVertically) {
|
||||
if (alphaComposite < 1) {
|
||||
color = FSkinColor.alphaColor(color, color.a * alphaComposite);
|
||||
}
|
||||
@@ -953,8 +952,7 @@ public class Forge implements ApplicationListener {
|
||||
}
|
||||
|
||||
TextBounds textBounds;
|
||||
int fontSize = skinFont.getSize();
|
||||
BitmapFont font = skinFont.getFont();
|
||||
int fontSize = font.getSize();
|
||||
if (wrap) {
|
||||
textBounds = font.getWrappedBounds(text, w);
|
||||
}
|
||||
@@ -966,7 +964,7 @@ public class Forge implements ApplicationListener {
|
||||
|
||||
while (textBounds.width > w || textBounds.height > h) {
|
||||
if (fontSize > FSkinFont.MIN_FONT_SIZE) { //shrink font to fit if possible
|
||||
font = FSkinFont.get(--fontSize).getFont();
|
||||
font = FSkinFont.get(--fontSize);
|
||||
if (wrap) {
|
||||
textBounds = font.getWrappedBounds(text, w);
|
||||
}
|
||||
@@ -988,14 +986,8 @@ public class Forge implements ApplicationListener {
|
||||
if (h > textHeight && centerVertically) {
|
||||
y += (h - textHeight) / 2;
|
||||
}
|
||||
font.setColor(color);
|
||||
|
||||
if (wrap) {
|
||||
font.drawWrapped(batch, text, adjustX(x), adjustY(y, 0), w, horzAlignment);
|
||||
}
|
||||
else {
|
||||
font.drawMultiLine(batch, text, adjustX(x), adjustY(y, 0), w, horzAlignment);
|
||||
}
|
||||
font.draw(batch, text, color, adjustX(x), adjustY(y, 0), w, wrap, horzAlignment);
|
||||
|
||||
if (needClip) {
|
||||
endClip();
|
||||
|
||||
@@ -5,11 +5,15 @@ import java.util.Map;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
|
||||
import com.badlogic.gdx.graphics.g2d.PixmapPacker;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
|
||||
import com.badlogic.gdx.graphics.glutils.PixmapTextureData;
|
||||
@@ -37,7 +41,7 @@ public class FSkinFont {
|
||||
public static FSkinFont forHeight(final float height) {
|
||||
int size = MIN_FONT_SIZE + 1;
|
||||
while (true) {
|
||||
if (get(size).getFont().getLineHeight() > height) {
|
||||
if (get(size).getLineHeight() > height) {
|
||||
return get(size - 1);
|
||||
}
|
||||
size++;
|
||||
@@ -69,8 +73,34 @@ public class FSkinFont {
|
||||
return size;
|
||||
}
|
||||
|
||||
public BitmapFont getFont() {
|
||||
return font;
|
||||
// Expose methods from font that updates scale as needed
|
||||
public TextBounds getBounds(CharSequence str) {
|
||||
return font.getBounds(str);
|
||||
}
|
||||
public TextBounds getMultiLineBounds(CharSequence str) {
|
||||
return font.getMultiLineBounds(str);
|
||||
}
|
||||
public TextBounds getWrappedBounds(CharSequence str, float wrapWidth) {
|
||||
return font.getWrappedBounds(str, wrapWidth);
|
||||
}
|
||||
public float getAscent() {
|
||||
return font.getAscent();
|
||||
}
|
||||
public float getCapHeight() {
|
||||
return font.getCapHeight();
|
||||
}
|
||||
public float getLineHeight() {
|
||||
return font.getLineHeight();
|
||||
}
|
||||
|
||||
public void draw(SpriteBatch batch, String text, Color color, float x, float y, float w, boolean wrap, HAlignment horzAlignment) {
|
||||
font.setColor(color);
|
||||
if (wrap) {
|
||||
font.drawWrapped(batch, text, x, y, w, horzAlignment);
|
||||
}
|
||||
else {
|
||||
font.drawMultiLine(batch, text, x, y, w, horzAlignment);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateFont() {
|
||||
|
||||
@@ -6,7 +6,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
|
||||
|
||||
@@ -59,7 +58,6 @@ public class TextRenderer {
|
||||
private final boolean parseReminderText;
|
||||
private String fullText = "";
|
||||
private float width, height, totalHeight;
|
||||
private BitmapFont baseBitmapFont;
|
||||
private FSkinFont baseFont, font;
|
||||
private boolean wrap, needClip;
|
||||
private List<Piece> pieces = new ArrayList<Piece>();
|
||||
@@ -80,8 +78,7 @@ public class TextRenderer {
|
||||
needClip = false;
|
||||
if (fullText.isEmpty()) { return; }
|
||||
|
||||
BitmapFont bitmapFont = font.getFont();
|
||||
totalHeight = bitmapFont.getCapHeight();
|
||||
totalHeight = font.getCapHeight();
|
||||
if (totalHeight > height) {
|
||||
//immediately try one font size smaller if no room for anything
|
||||
if (font.getSize() > FSkinFont.MIN_FONT_SIZE) {
|
||||
@@ -97,7 +94,7 @@ public class TextRenderer {
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
float pieceWidth = 0;
|
||||
float lineHeight = bitmapFont.getLineHeight();
|
||||
float lineHeight = font.getLineHeight();
|
||||
int lastSpaceIdx = -1;
|
||||
int lineNum = 0;
|
||||
String text = "";
|
||||
@@ -194,7 +191,7 @@ public class TextRenderer {
|
||||
needClip = true;
|
||||
}
|
||||
}
|
||||
addPiece(new SymbolPiece(symbol, inReminderTextCount > 0), lineNum, x, y - bitmapFont.getAscent() + (lineHeight - pieceWidth) / 2, pieceWidth, pieceWidth);
|
||||
addPiece(new SymbolPiece(symbol, inReminderTextCount > 0), lineNum, x, y - font.getAscent() + (lineHeight - pieceWidth) / 2, pieceWidth, pieceWidth);
|
||||
x += pieceWidth;
|
||||
pieceWidth = 0;
|
||||
text = "";
|
||||
@@ -257,7 +254,7 @@ public class TextRenderer {
|
||||
}
|
||||
text += ch;
|
||||
if (inSymbolCount == 0) {
|
||||
pieceWidth = bitmapFont.getBounds(text).width;
|
||||
pieceWidth = font.getBounds(text).width;
|
||||
if (x + pieceWidth > width) { //wrap or shrink if needed
|
||||
if (wrap && (lastSpaceIdx >= 0 || consecutiveSymbols > 0)) {
|
||||
if (lastSpaceIdx < 0) {
|
||||
@@ -276,7 +273,7 @@ public class TextRenderer {
|
||||
else {
|
||||
String currentLineText = text.substring(0, lastSpaceIdx);
|
||||
if (!currentLineText.isEmpty()) {
|
||||
pieceWidth = bitmapFont.getBounds(text).width;
|
||||
pieceWidth = font.getBounds(text).width;
|
||||
addPiece(new TextPiece(currentLineText, inReminderTextCount > 0 || atReminderTextEnd), lineNum, x, y, pieceWidth, lineHeight);
|
||||
consecutiveSymbols = 0;
|
||||
}
|
||||
@@ -288,7 +285,7 @@ public class TextRenderer {
|
||||
x = 0;
|
||||
}
|
||||
lastSpaceIdx = -1;
|
||||
pieceWidth = text.isEmpty() ? 0 : bitmapFont.getBounds(text).width;
|
||||
pieceWidth = text.isEmpty() ? 0 : font.getBounds(text).width;
|
||||
y += lineHeight;
|
||||
totalHeight += lineHeight;
|
||||
lineNum++;
|
||||
@@ -317,20 +314,20 @@ public class TextRenderer {
|
||||
if (index != -1) {
|
||||
if (index == 0) {
|
||||
textPiece.text = textPiece.text.substring(1);
|
||||
textPiece.w = bitmapFont.getBounds(textPiece.text).width;
|
||||
textPiece.w = font.getBounds(textPiece.text).width;
|
||||
lastPieceIdx--;
|
||||
}
|
||||
else if (index == textPiece.text.length() - 1) {
|
||||
textPiece.text = textPiece.text.substring(0, textPiece.text.length() - 1);
|
||||
textPiece.w = bitmapFont.getBounds(textPiece.text).width;
|
||||
textPiece.w = font.getBounds(textPiece.text).width;
|
||||
}
|
||||
else {
|
||||
TextPiece splitPiece = new TextPiece(textPiece.text.substring(index + 1), textPiece.inReminderText);
|
||||
textPiece.text = textPiece.text.substring(0, index);
|
||||
textPiece.w = bitmapFont.getBounds(textPiece.text).width;
|
||||
textPiece.w = font.getBounds(textPiece.text).width;
|
||||
splitPiece.x = textPiece.x + textPiece.w;
|
||||
splitPiece.y = textPiece.y;
|
||||
splitPiece.w = bitmapFont.getBounds(splitPiece.text).width;
|
||||
splitPiece.w = font.getBounds(splitPiece.text).width;
|
||||
splitPiece.h = textPiece.h;
|
||||
}
|
||||
break;
|
||||
@@ -401,9 +398,8 @@ public class TextRenderer {
|
||||
fullText = text;
|
||||
needUpdate = true;
|
||||
}
|
||||
if (skinFont != baseFont || skinFont.getFont() != baseBitmapFont) {
|
||||
if (skinFont != baseFont) {
|
||||
baseFont = skinFont;
|
||||
baseBitmapFont = skinFont.getFont(); //cache baseBitmapFont separate to handle skin changes
|
||||
needUpdate = true;
|
||||
}
|
||||
if (width != w) {
|
||||
|
||||
@@ -44,7 +44,7 @@ public class CardRenderer {
|
||||
public static final float PT_BOX_TINT = 0.2f;
|
||||
private static final float MANA_COST_PADDING = Utils.scaleMin(3);
|
||||
private static final float SET_BOX_MARGIN = Utils.scaleMin(1);
|
||||
private static final float MANA_SYMBOL_SIZE = FSkinImage.MANA_1.getNearestHQWidth(2 * (NAME_FONT.getFont().getCapHeight() - MANA_COST_PADDING));
|
||||
private static final float MANA_SYMBOL_SIZE = FSkinImage.MANA_1.getNearestHQWidth(2 * (NAME_FONT.getCapHeight() - MANA_COST_PADDING));
|
||||
private static final float NAME_COST_THRESHOLD = Utils.scaleY(200);
|
||||
|
||||
private static Color fromDetailColor(DetailColors detailColor) {
|
||||
@@ -142,7 +142,7 @@ public class CardRenderer {
|
||||
x += outerBorderThickness;
|
||||
y += outerBorderThickness;
|
||||
w -= 2 * outerBorderThickness;
|
||||
float cardNameBoxHeight = Math.max(MANA_SYMBOL_SIZE + 2 * MANA_COST_PADDING, 2 * NAME_FONT.getFont().getCapHeight()) + 2 * TYPE_FONT.getFont().getCapHeight() + 2;
|
||||
float cardNameBoxHeight = Math.max(MANA_SYMBOL_SIZE + 2 * MANA_COST_PADDING, 2 * NAME_FONT.getCapHeight()) + 2 * TYPE_FONT.getCapHeight() + 2;
|
||||
|
||||
//draw name/type box
|
||||
Color nameBoxColor1 = FSkinColor.tintColor(Color.WHITE, color1, NAME_BOX_TINT);
|
||||
@@ -150,7 +150,7 @@ public class CardRenderer {
|
||||
drawCardNameBox(g, card, nameBoxColor1, nameBoxColor2, x, y, w, cardNameBoxHeight);
|
||||
|
||||
float innerBorderThickness = outerBorderThickness / 2;
|
||||
float ptBoxHeight = 2 * PT_FONT.getFont().getCapHeight();
|
||||
float ptBoxHeight = 2 * PT_FONT.getCapHeight();
|
||||
float textBoxHeight = h - cardNameBoxHeight - ptBoxHeight - outerBorderThickness - 3 * innerBorderThickness;
|
||||
|
||||
y += cardNameBoxHeight + innerBorderThickness;
|
||||
@@ -165,7 +165,7 @@ public class CardRenderer {
|
||||
}
|
||||
|
||||
public static float getCardListItemHeight() {
|
||||
return Math.round(MANA_SYMBOL_SIZE + FSkinFont.get(12).getFont().getLineHeight() + 3 * FList.PADDING + 1);
|
||||
return Math.round(MANA_SYMBOL_SIZE + FSkinFont.get(12).getLineHeight() + 3 * FList.PADDING + 1);
|
||||
}
|
||||
|
||||
private static final Map<String, TextureRegion> cardArtCache = new HashMap<String, TextureRegion>();
|
||||
@@ -237,7 +237,7 @@ public class CardRenderer {
|
||||
|
||||
FSkinFont typeFont = FSkinFont.get(12);
|
||||
float availableTypeWidth = w - cardArtWidth;
|
||||
float lineHeight = typeFont.getFont().getLineHeight();
|
||||
float lineHeight = typeFont.getLineHeight();
|
||||
if (!StringUtils.isEmpty(set)) {
|
||||
float setWidth = getSetWidth(typeFont, set);
|
||||
availableTypeWidth -= setWidth;
|
||||
@@ -282,7 +282,7 @@ public class CardRenderer {
|
||||
float padding = h / 8;
|
||||
|
||||
//make sure name/mana cost row height is tall enough for both
|
||||
h = Math.max(MANA_SYMBOL_SIZE + 2 * MANA_COST_PADDING, 2 * NAME_FONT.getFont().getCapHeight());
|
||||
h = Math.max(MANA_SYMBOL_SIZE + 2 * MANA_COST_PADDING, 2 * NAME_FONT.getCapHeight());
|
||||
|
||||
float manaCostWidth = CardFaceSymbols.getWidth(card.getManaCost(), MANA_SYMBOL_SIZE) + MANA_COST_PADDING;
|
||||
CardFaceSymbols.drawManaCost(g, card.getManaCost(), x + w - manaCostWidth, y + (h - MANA_SYMBOL_SIZE) / 2, MANA_SYMBOL_SIZE);
|
||||
@@ -292,7 +292,7 @@ public class CardRenderer {
|
||||
g.drawText(card.isFaceDown() ? "???" : card.getName(), NAME_FONT, Color.BLACK, x, y, w - manaCostWidth - padding, h, false, HAlignment.LEFT, true);
|
||||
|
||||
y += h;
|
||||
h = 2 * TYPE_FONT.getFont().getCapHeight();
|
||||
h = 2 * TYPE_FONT.getCapHeight();
|
||||
|
||||
String set = card.getCurSetCode();
|
||||
if (!StringUtils.isEmpty(set)) {
|
||||
@@ -305,7 +305,7 @@ public class CardRenderer {
|
||||
}
|
||||
|
||||
public static float getSetWidth(FSkinFont font, String set) {
|
||||
return font.getFont().getBounds(set).width + font.getFont().getCapHeight();
|
||||
return font.getBounds(set).width + font.getCapHeight();
|
||||
}
|
||||
|
||||
public static void drawSetLabel(Graphics g, FSkinFont font, String set, CardRarity rarity, float x, float y, float w, float h) {
|
||||
@@ -345,7 +345,7 @@ public class CardRenderer {
|
||||
}
|
||||
g.drawRect(1, Color.BLACK, x, y, w, h);
|
||||
|
||||
float padX = TEXT_FONT.getFont().getCapHeight() / 2;
|
||||
float padX = TEXT_FONT.getCapHeight() / 2;
|
||||
float padY = padX + 2; //add a little more vertical padding
|
||||
x += padX;
|
||||
y += padY;
|
||||
@@ -356,14 +356,14 @@ public class CardRenderer {
|
||||
|
||||
private static void drawCardIdAndPtBox(Graphics g, Card card, Color idForeColor, Color color1, Color color2, float x, float y, float w, float h) {
|
||||
String idText = CardDetailUtil.formatCardId(card);
|
||||
g.drawText(idText, ID_FONT, idForeColor, x, y + ID_FONT.getFont().getCapHeight() / 2, w, h, false, HAlignment.LEFT, false);
|
||||
g.drawText(idText, ID_FONT, idForeColor, x, y + ID_FONT.getCapHeight() / 2, w, h, false, HAlignment.LEFT, false);
|
||||
|
||||
String ptText = CardDetailUtil.formatPowerToughness(card);
|
||||
if (StringUtils.isEmpty(ptText)) { return; }
|
||||
|
||||
float padding = PT_FONT.getFont().getCapHeight() / 2;
|
||||
float boxWidth = Math.min(PT_FONT.getFont().getBounds(ptText).width + 2 * padding,
|
||||
w - ID_FONT.getFont().getBounds(idText).width - padding); //prevent box overlapping ID
|
||||
float padding = PT_FONT.getCapHeight() / 2;
|
||||
float boxWidth = Math.min(PT_FONT.getBounds(ptText).width + 2 * padding,
|
||||
w - ID_FONT.getBounds(idText).width - padding); //prevent box overlapping ID
|
||||
x += w - boxWidth;
|
||||
w = boxWidth;
|
||||
|
||||
@@ -413,7 +413,7 @@ public class CardRenderer {
|
||||
|
||||
if (showCardIdOverlay(card)) {
|
||||
FSkinFont idFont = FSkinFont.forHeight(h * 0.12f);
|
||||
float idHeight = idFont.getFont().getCapHeight();
|
||||
float idHeight = idFont.getCapHeight();
|
||||
g.drawOutlinedText(String.valueOf(card.getUniqueNumber()), idFont, Color.WHITE, Color.BLACK, x + padding, y + h - idHeight - padding, w, h, false, HAlignment.LEFT, false);
|
||||
}
|
||||
|
||||
@@ -494,15 +494,15 @@ public class CardRenderer {
|
||||
if (pieces.isEmpty()) { return; }
|
||||
|
||||
FSkinFont font = FSkinFont.forHeight(h * 0.15f);
|
||||
float padding = Math.round(font.getFont().getCapHeight() / 4);
|
||||
float padding = Math.round(font.getCapHeight() / 4);
|
||||
float boxWidth = padding;
|
||||
List<Float> pieceWidths = new ArrayList<Float>();
|
||||
for (String piece : pieces) {
|
||||
float pieceWidth = font.getFont().getBounds(piece).width + padding;
|
||||
float pieceWidth = font.getBounds(piece).width + padding;
|
||||
pieceWidths.add(pieceWidth);
|
||||
boxWidth += pieceWidth;
|
||||
}
|
||||
float boxHeight = font.getFont().getCapHeight() + font.getFont().getAscent() + 2 * padding;
|
||||
float boxHeight = font.getCapHeight() + font.getAscent() + 2 * padding;
|
||||
|
||||
x += w - boxWidth;
|
||||
y += h - boxHeight;
|
||||
|
||||
@@ -81,9 +81,9 @@ public class BugReportDialog extends FOptionPane {
|
||||
|
||||
@Override
|
||||
protected ScrollBounds layoutAndGetScrollBounds(float visibleWidth, float visibleHeight) {
|
||||
TextBounds bounds = FONT.getFont().getMultiLineBounds(text);
|
||||
TextBounds bounds = FONT.getMultiLineBounds(text);
|
||||
return new ScrollBounds(bounds.width + 2 * PADDING, bounds.height + 2 * PADDING +
|
||||
FONT.getFont().getLineHeight() - FONT.getFont().getCapHeight()); //account for height below baseline of final line);
|
||||
FONT.getLineHeight() - FONT.getCapHeight()); //account for height below baseline of final line);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -259,7 +259,7 @@ public final class DeckManager extends ItemManager<DeckProxy> {
|
||||
//if just string column, use normal list item height
|
||||
return Utils.AVG_FINGER_HEIGHT;
|
||||
}
|
||||
return IMAGE_SIZE + 2 * FSkinFont.get(12).getFont().getLineHeight() + 4 * FList.PADDING;
|
||||
return IMAGE_SIZE + 2 * FSkinFont.get(12).getLineHeight() + 4 * FList.PADDING;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -296,7 +296,7 @@ public final class DeckManager extends ItemManager<DeckProxy> {
|
||||
x = FList.PADDING;
|
||||
y += IMAGE_SIZE + FList.PADDING;
|
||||
font = FSkinFont.get(font.getSize() - 2);
|
||||
float lineHeight = font.getFont().getLineHeight();
|
||||
float lineHeight = font.getLineHeight();
|
||||
|
||||
int mainSize = deck.getMainSize();
|
||||
if (mainSize < 0) {
|
||||
@@ -307,7 +307,7 @@ public final class DeckManager extends ItemManager<DeckProxy> {
|
||||
sideSize = 0; //show sideboard as 0 if empty
|
||||
}
|
||||
String countStr = mainSize + " / " + sideSize;
|
||||
float countWidth = font.getFont().getBounds(countStr).width;
|
||||
float countWidth = font.getBounds(countStr).width;
|
||||
if (!deck.getPath().isEmpty()) {
|
||||
g.drawText(deck.getPath().substring(1) + "/", font, foreColor, x, y, w - countWidth - FList.PADDING, lineHeight, false, HAlignment.LEFT, true);
|
||||
}
|
||||
|
||||
@@ -791,7 +791,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
float y = 0;
|
||||
String caption = name + " (" + items.size() + ")";
|
||||
g.drawText(caption, GROUP_HEADER_FONT, GROUP_HEADER_FORE_COLOR, x, y, getWidth(), GROUP_HEADER_HEIGHT, false, HAlignment.LEFT, true);
|
||||
x += GROUP_HEADER_FONT.getFont().getBounds(caption).width + PADDING;
|
||||
x += GROUP_HEADER_FONT.getBounds(caption).width + PADDING;
|
||||
y += GROUP_HEADER_HEIGHT / 2;
|
||||
g.drawLine(GROUP_HEADER_LINE_THICKNESS, GROUP_HEADER_LINE_COLOR, x, y, getWidth(), y);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public class FMenuBar extends FContainer {
|
||||
}
|
||||
|
||||
public float getPreferredHeight() {
|
||||
return Math.round(FMenuTab.FONT.getFont().getLineHeight() * 1.5f + 2 * FMenuTab.PADDING);
|
||||
return Math.round(FMenuTab.FONT.getLineHeight() * 1.5f + 2 * FMenuTab.PADDING);
|
||||
}
|
||||
|
||||
public int getTabCount() {
|
||||
|
||||
@@ -47,7 +47,7 @@ public class FMenuItem extends FDisplayObject {
|
||||
handler = handler0;
|
||||
setEnabled(enabled0);
|
||||
|
||||
textWidth = FONT.getFont().getBounds(text).width;
|
||||
textWidth = FONT.getBounds(text).width;
|
||||
}
|
||||
|
||||
public boolean hasIcon() {
|
||||
|
||||
@@ -46,7 +46,7 @@ public class FMenuTab extends FDisplayObject {
|
||||
|
||||
public void setText(String text0) {
|
||||
text = text0;
|
||||
minWidth = FONT.getFont().getBounds(text).width;
|
||||
minWidth = FONT.getBounds(text).width;
|
||||
menuBar.revalidate();
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public class FTooltip extends FDropDown {
|
||||
|
||||
@Override
|
||||
protected ScrollBounds updateAndGetPaneSize(float maxWidth, float maxVisibleHeight) {
|
||||
TextBounds bounds = FONT.getFont().getWrappedBounds(text, maxWidth - 2 * PADDING);
|
||||
TextBounds bounds = FONT.getWrappedBounds(text, maxWidth - 2 * PADDING);
|
||||
return new ScrollBounds(maxWidth, bounds.height + 2 * PADDING);
|
||||
}
|
||||
|
||||
|
||||
@@ -1061,7 +1061,7 @@ public class ConstructedScreen extends LaunchScreen {
|
||||
public void drawValue(Graphics g, Variant value, FSkinFont font, FSkinColor color, boolean pressed, float x, float y, float w, float h) {
|
||||
String text = value.gameType.toString();
|
||||
float totalHeight = h;
|
||||
h = font.getFont().getMultiLineBounds(text).height + 5;
|
||||
h = font.getMultiLineBounds(text).height + 5;
|
||||
|
||||
g.drawText(text, font, color, x, y, w, h, false, HAlignment.LEFT, false);
|
||||
value.draw(g, font, color, x, y, w, h);
|
||||
|
||||
@@ -29,7 +29,7 @@ public class MatchLoader extends FOverlay {
|
||||
|
||||
float padding = w * HomeScreen.INSETS_FACTOR;
|
||||
float logoSize = w * HomeScreen.LOGO_SIZE_FACTOR;
|
||||
float fontHeight = FONT.getFont().getLineHeight();
|
||||
float fontHeight = FONT.getLineHeight();
|
||||
float panelHeight = logoSize + fontHeight + 2 * insets + 3 * padding;
|
||||
|
||||
float y = (getHeight() - panelHeight) / 2;
|
||||
|
||||
@@ -97,7 +97,7 @@ public class VManaPool extends VDisplayArea {
|
||||
|
||||
@Override
|
||||
public void draw(Graphics g) {
|
||||
float textHeight = FONT.getFont().getCapHeight();
|
||||
float textHeight = FONT.getCapHeight();
|
||||
float gapY = textHeight / 4f;
|
||||
|
||||
float maxImageHeight = getHeight() - textHeight - 3 * gapY;
|
||||
|
||||
@@ -63,7 +63,7 @@ public class VPhaseIndicator extends FContainer {
|
||||
private float _getPreferredHeight(float w) {
|
||||
TextBounds bounds = null;
|
||||
for (PhaseLabel lbl : phaseLabels.values()) {
|
||||
bounds = font.getFont().getBounds(lbl.caption);
|
||||
bounds = font.getBounds(lbl.caption);
|
||||
if (bounds.width > w) {
|
||||
if (font.getSize() > FSkinFont.MIN_FONT_SIZE) {
|
||||
font = FSkinFont.get(font.getSize() - 1);
|
||||
|
||||
@@ -162,7 +162,7 @@ public class VPlayerPanel extends FContainer {
|
||||
y = height - VAvatar.HEIGHT;
|
||||
avatar.setPosition(0, y);
|
||||
|
||||
float lifeLabelWidth = LIFE_FONT.getFont().getBounds("99").width * 1.2f; //make just wide enough for 2-digit life totals
|
||||
float lifeLabelWidth = LIFE_FONT.getBounds("99").width * 1.2f; //make just wide enough for 2-digit life totals
|
||||
float infoLabelHeight = VAvatar.HEIGHT - phaseIndicator.getHeight();
|
||||
lblLife.setBounds(x, y, lifeLabelWidth, infoLabelHeight);
|
||||
x += lifeLabelWidth;
|
||||
@@ -294,7 +294,7 @@ public class VPlayerPanel extends FContainer {
|
||||
|
||||
//show image left of text if wider than tall
|
||||
if (getWidth() > getHeight()) {
|
||||
float maxImageWidth = getWidth() - INFO_FONT.getFont().getBounds("0").width - 3 * INFO_TAB_PADDING_X;
|
||||
float maxImageWidth = getWidth() - INFO_FONT.getBounds("0").width - 3 * INFO_TAB_PADDING_X;
|
||||
w = icon.getNearestHQWidth(maxImageWidth);
|
||||
if (w > maxImageWidth) {
|
||||
w /= 2;
|
||||
|
||||
@@ -301,7 +301,7 @@ public class SettingsScreen extends FScreen {
|
||||
h -= 2 * offset;
|
||||
|
||||
float totalHeight = h;
|
||||
h = font.getFont().getMultiLineBounds(value.label).height + SETTING_PADDING;
|
||||
h = font.getMultiLineBounds(value.label).height + SETTING_PADDING;
|
||||
|
||||
g.drawText(value.label, font, color, x, y, w, h, false, HAlignment.LEFT, false);
|
||||
value.drawPrefValue(g, font, color, x, y, w, h);
|
||||
|
||||
@@ -123,8 +123,8 @@ public class FButton extends FDisplayObject implements IButton {
|
||||
|
||||
public TextBounds getAutoSizeBounds() {
|
||||
TextBounds bounds = new TextBounds();
|
||||
bounds.width = font.getFont().getBounds(text).width + 2 * PADDING;
|
||||
bounds.height = 3 * font.getFont().getCapHeight();
|
||||
bounds.width = font.getBounds(text).width + 2 * PADDING;
|
||||
bounds.height = 3 * font.getCapHeight();
|
||||
return bounds;
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ public class FComboBox<E> extends FTextField {
|
||||
//use widest item width to determine auto-size width
|
||||
float maxTextWidth = 0;
|
||||
for (E item : items) {
|
||||
float width = font.getFont().getBounds(item.toString()).width;
|
||||
float width = font.getBounds(item.toString()).width;
|
||||
if (width > maxTextWidth) {
|
||||
maxTextWidth = width;
|
||||
}
|
||||
|
||||
@@ -192,8 +192,8 @@ public class FLabel extends FDisplayObject implements IButton {
|
||||
bounds = new TextBounds();
|
||||
}
|
||||
else {
|
||||
bounds = font.getFont().getMultiLineBounds(text);
|
||||
bounds.height += font.getFont().getLineHeight() - font.getFont().getCapHeight(); //account for height below baseline of final line
|
||||
bounds = font.getMultiLineBounds(text);
|
||||
bounds.height += font.getLineHeight() - font.getCapHeight(); //account for height below baseline of final line
|
||||
}
|
||||
bounds.width += 2 * insets.x;
|
||||
bounds.height += 2 * insets.y;
|
||||
@@ -277,7 +277,7 @@ public class FLabel extends FDisplayObject implements IButton {
|
||||
if (alignment == HAlignment.CENTER) {
|
||||
float dx;
|
||||
while (true) {
|
||||
dx = (w - iconWidth - font.getFont().getMultiLineBounds(text).width - insets.x) / 2;
|
||||
dx = (w - iconWidth - font.getMultiLineBounds(text).width - insets.x) / 2;
|
||||
if (dx > 0) {
|
||||
x += dx;
|
||||
break;
|
||||
|
||||
@@ -54,7 +54,7 @@ public class FTextArea extends FScrollPane {
|
||||
|
||||
public float getPreferredHeight(float width) {
|
||||
return renderer.getWrappedBounds(text, font, width - 2 * insets.x).height
|
||||
+ font.getFont().getLineHeight() - font.getFont().getCapHeight() //need to account for difference in line and cap height
|
||||
+ font.getLineHeight() - font.getCapHeight() //need to account for difference in line and cap height
|
||||
+ 2 * insets.y;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class FTextField extends FDisplayObject {
|
||||
return getDefaultHeight(FSkinFont.get(fontSize));
|
||||
}
|
||||
public static float getDefaultHeight(FSkinFont font0) {
|
||||
return font0.getFont().getCapHeight() * 3;
|
||||
return font0.getCapHeight() * 3;
|
||||
}
|
||||
|
||||
private String text, ghostText, textBeforeKeyInput;
|
||||
@@ -119,7 +119,7 @@ public class FTextField extends FDisplayObject {
|
||||
}
|
||||
|
||||
public float getAutoSizeWidth() {
|
||||
return PADDING + font.getFont().getBounds(text).width + getRightPadding();
|
||||
return PADDING + font.getBounds(text).width + getRightPadding();
|
||||
}
|
||||
|
||||
private int getCharIndexAtPoint(float x, float y) {
|
||||
@@ -127,14 +127,14 @@ public class FTextField extends FDisplayObject {
|
||||
if (x < charLeft) {
|
||||
return 0;
|
||||
}
|
||||
if (x >= charLeft + font.getFont().getBounds(text).width) {
|
||||
if (x >= charLeft + font.getBounds(text).width) {
|
||||
return text.length();
|
||||
}
|
||||
|
||||
//find closest character of press
|
||||
float charWidth;
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
charWidth = font.getFont().getBounds(text.substring(i, i + 1)).width;
|
||||
charWidth = font.getBounds(text.substring(i, i + 1)).width;
|
||||
if (x < charLeft + charWidth / 2) {
|
||||
return i;
|
||||
}
|
||||
@@ -296,7 +296,7 @@ public class FTextField extends FDisplayObject {
|
||||
if (isEditing) {
|
||||
float selLeft = PADDING;
|
||||
if (selStart > 0) {
|
||||
selLeft += font.getFont().getBounds(text.substring(0, selStart)).width;
|
||||
selLeft += font.getBounds(text.substring(0, selStart)).width;
|
||||
}
|
||||
float selTop = PADDING;
|
||||
float selHeight = h - 2 * PADDING;
|
||||
@@ -305,7 +305,7 @@ public class FTextField extends FDisplayObject {
|
||||
g.drawLine(BORDER_THICKNESS, FORE_COLOR, selLeft, selTop, selLeft, selTop + selHeight);
|
||||
}
|
||||
else if (selStart == 0 && selLength == text.length()) {
|
||||
float selWidth = font.getFont().getBounds(text.substring(selStart, selStart + selLength)).width;
|
||||
float selWidth = font.getBounds(text.substring(selStart, selStart + selLength)).width;
|
||||
g.fillRect(SEL_COLOR, selLeft, selTop, selWidth, selHeight);
|
||||
drawText(g, w, h); //draw text in front of selection background
|
||||
}
|
||||
@@ -318,7 +318,7 @@ public class FTextField extends FDisplayObject {
|
||||
}
|
||||
|
||||
private void drawText(Graphics g, float w, float h) {
|
||||
float diff = h - font.getFont().getCapHeight();
|
||||
float diff = h - font.getCapHeight();
|
||||
if (diff > 0 && Math.round(diff) % 2 == 1) {
|
||||
h++; //if odd difference between height and font height, increment height so text favors displaying closer to bottom
|
||||
}
|
||||
|
||||
@@ -62,8 +62,8 @@ public class FToggleSwitch extends FDisplayObject {
|
||||
|
||||
public float getAutoSizeWidth(float height) {
|
||||
float width;
|
||||
float onTextWidth = font.getFont().getBounds(onText).width;
|
||||
float offTextWidth = font.getFont().getBounds(offText).width;
|
||||
float onTextWidth = font.getBounds(onText).width;
|
||||
float offTextWidth = font.getBounds(offText).width;
|
||||
if (onTextWidth > offTextWidth) {
|
||||
width = onTextWidth;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user