mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
Improve floating point rendering
This commit is contained in:
@@ -393,26 +393,14 @@ public class Forge implements ApplicationListener {
|
||||
if (color.a != 0) { //enable blending so alpha colored shapes work properly
|
||||
Gdx.gl.glEnable(GL20.GL_BLEND);
|
||||
}
|
||||
|
||||
//adjust width/height so rectangle covers equivalent filled area
|
||||
w = Math.round(w - 1);
|
||||
h = Math.round(h - 1);
|
||||
Gdx.gl.glEnable(GL10.GL_LINE_SMOOTH); //must be smooth to ensure edges aren't missed
|
||||
|
||||
shapeRenderer.begin(ShapeType.Line);
|
||||
shapeRenderer.setColor(color);
|
||||
|
||||
//must user 4 line() calls rather than rect() since rect() leaves corner unfilled
|
||||
x = adjustX(x);
|
||||
float y2 = adjustY(y, h);
|
||||
float x2 = x + w;
|
||||
y = y2 + h;
|
||||
shapeRenderer.line(x, y, x, y2);
|
||||
shapeRenderer.line(x, y2, x2 + 1, y2); //+1 prevents corner not being filled
|
||||
shapeRenderer.line(x2, y2, x2, y);
|
||||
shapeRenderer.line(x2 + 1, y, x, y); //+1 prevents corner not being filled
|
||||
|
||||
shapeRenderer.rect(adjustX(x), adjustY(y, h), w, h);
|
||||
shapeRenderer.end();
|
||||
|
||||
Gdx.gl.glDisable(GL10.GL_LINE_SMOOTH);
|
||||
if (color.a != 0) {
|
||||
Gdx.gl.glDisable(GL20.GL_BLEND);
|
||||
}
|
||||
|
||||
@@ -44,24 +44,13 @@ public class FSkinFont {
|
||||
|
||||
private void updateFont() {
|
||||
String dir = FSkin.getDir();
|
||||
String fntFilename = "font" + this.size;
|
||||
|
||||
//attempt to use existing .fnt and .png files
|
||||
FileHandle fntFile = Gdx.files.internal(dir + fntFilename + ".fnt");
|
||||
if (fntFile.exists()) {
|
||||
FileHandle pngFile = Gdx.files.internal(dir + fntFilename + ".png");
|
||||
if (pngFile.exists()) {
|
||||
font = new BitmapFont(fntFile, pngFile, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//generate .fnt and .png files from .ttf if needed
|
||||
FileHandle ttfFile = Gdx.files.internal(dir + TTF_FILE);
|
||||
if (ttfFile.exists()) {
|
||||
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(ttfFile);
|
||||
font = generator.generateFont(this.size);
|
||||
//TODO: Save font to .fnt and .png files for faster loading
|
||||
font.setUseIntegerPositions(true); //prevent parts of text getting cut off at times
|
||||
generator.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import forge.toolbox.FLabel;
|
||||
import forge.utils.Utils;
|
||||
|
||||
public abstract class FScreen extends FContainer {
|
||||
public static final float BTN_HEIGHT = Utils.AVG_FINGER_HEIGHT * 0.8f;
|
||||
public static final float BTN_HEIGHT = Math.round(Utils.AVG_FINGER_HEIGHT * 0.8f);
|
||||
public static final float BTN_WIDTH = BTN_HEIGHT;
|
||||
|
||||
private static final FSkinColor clrTheme = FSkinColor.get(Colors.CLR_THEME);
|
||||
@@ -90,7 +90,7 @@ public abstract class FScreen extends FContainer {
|
||||
if (lblHeader != null) {
|
||||
lblHeader.setBounds(headerX, 0, headerWidth, headerHeight);
|
||||
|
||||
doLayout(headerHeight, width, height);
|
||||
doLayout(headerHeight + 1, width, height); //+1 to account for bottom border of header
|
||||
}
|
||||
else {
|
||||
doLayout(0, width, height);
|
||||
|
||||
@@ -2,11 +2,14 @@ package forge.screens.match;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import forge.Forge;
|
||||
import forge.game.Game;
|
||||
import forge.game.Match;
|
||||
import forge.game.player.LobbyPlayer;
|
||||
import forge.game.player.Player;
|
||||
import forge.model.FModel;
|
||||
import forge.utils.ForgePreferences.FPref;
|
||||
|
||||
public class MatchController {
|
||||
private final MatchScreen view;
|
||||
@@ -58,7 +61,7 @@ public class MatchController {
|
||||
public void initMatch(final List<Player> players, LobbyPlayer localPlayer) {
|
||||
// TODO fix for use with multiplayer
|
||||
|
||||
final String[] indices = new String[] { "1", "2" }; //Singletons.getModel().getPreferences().getPref(FPref.UI_AVATARS).split(",");
|
||||
final String[] indices = FModel.getPreferences().getPref(FPref.UI_AVATARS).split(",");
|
||||
|
||||
// Instantiate all required field slots (user at 0)
|
||||
sortedPlayers = shiftPlayersPlaceLocalFirst(players, localPlayer);
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
package forge.screens.match.views;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import forge.assets.FSkinFont;
|
||||
import forge.assets.FSkinColor.Colors;
|
||||
import forge.toolbox.FButton;
|
||||
import forge.toolbox.FContainer;
|
||||
import forge.toolbox.FLabel;
|
||||
import forge.utils.Utils;
|
||||
|
||||
public class VPrompt extends FContainer {
|
||||
|
||||
@@ -67,7 +67,6 @@ public class FLabel extends FDisplayObject {
|
||||
private static final FSkinColor d10 = clrMain.stepColor(-10);
|
||||
private static final FSkinColor l10 = clrMain.stepColor(10);
|
||||
private static final FSkinColor l20 = clrMain.stepColor(20);
|
||||
private static final FSkinColor l30 = clrMain.stepColor(30);
|
||||
|
||||
private float iconScaleFactor;
|
||||
private FSkinFont font;
|
||||
@@ -156,32 +155,32 @@ public class FLabel extends FDisplayObject {
|
||||
float w = getWidth();
|
||||
float h = getHeight();
|
||||
|
||||
g.startClip(0, 0, w, h); //start clip to ensure nothing escapes bounds
|
||||
|
||||
if (pressed) {
|
||||
if (pressedColor != null) {
|
||||
g.fillRect(pressedColor, 0, 0, w, h);
|
||||
}
|
||||
else {
|
||||
g.fillGradientRect(d50, d10, true, 0, 0, w, h);
|
||||
g.drawRect(1, d50, 0, 0, w, h);
|
||||
g.drawRect(1, d10, 1, 1, w - 2, h - 2);
|
||||
g.fillGradientRect(d50, d10, true, 2, 2, w - 4, h - 4);
|
||||
}
|
||||
}
|
||||
else if (selected && (opaque || selectable)) {
|
||||
g.fillGradientRect(d30, l10, true, 0, 0, w, h);
|
||||
g.drawRect(1, d30, 0, 0, w, h);
|
||||
g.drawRect(1, l10, 1, 1, w - 2, h - 2);
|
||||
g.fillGradientRect(d30, l10, true, 2, 2, w - 4, h - 4);
|
||||
}
|
||||
else if (opaque) {
|
||||
g.fillGradientRect(d10, l20, true, 0, 0, w, h);
|
||||
g.drawRect(1, d50, 0, 0, w, h);
|
||||
g.drawRect(1, l10, 1, 1, w - 2, h - 2);
|
||||
g.fillGradientRect(d10, l20, true, 2, 2, w - 4, h - 4);
|
||||
}
|
||||
else if (selectable) {
|
||||
g.drawRect(1, l10, 0, 0, w, h);
|
||||
g.drawRect(1, l30, 1, 1, w - 2, h - 2);
|
||||
}
|
||||
|
||||
drawContent(g, w, h, pressed);
|
||||
|
||||
g.endClip();
|
||||
}
|
||||
|
||||
protected void drawContent(Graphics g, float w, float h, final boolean pressed) {
|
||||
|
||||
@@ -13,7 +13,7 @@ import forge.utils.Utils;
|
||||
|
||||
public class FList<E> extends FScrollPane {
|
||||
private static final float INSETS_FACTOR = 0.025f;
|
||||
private static final float GROUP_HEADER_HEIGHT = Utils.AVG_FINGER_HEIGHT * 0.6f;
|
||||
private static final float GROUP_HEADER_HEIGHT = Math.round(Utils.AVG_FINGER_HEIGHT * 0.6f);
|
||||
private static final FSkinColor FORE_COLOR = FSkinColor.get(Colors.CLR_TEXT);
|
||||
private static final FSkinColor PRESSED_COLOR = FSkinColor.get(Colors.CLR_ACTIVE).alphaColor(0.9f);
|
||||
private static final FSkinColor LINE_COLOR = FORE_COLOR.alphaColor(0.5f);
|
||||
@@ -183,10 +183,9 @@ public class FList<E> extends FScrollPane {
|
||||
g.fillRect(PRESSED_COLOR, 0, 0, w, h);
|
||||
}
|
||||
|
||||
renderer.drawValue(g, value, font, FORE_COLOR, w, h);
|
||||
renderer.drawValue(g, value, font, FORE_COLOR, w, h); //-1 to not account for border
|
||||
|
||||
float y = h + 1;
|
||||
g.drawLine(1, LINE_COLOR, 0, y, w, y);
|
||||
g.drawLine(1, LINE_COLOR, 0, h, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ public class Utils {
|
||||
private final static float ppcY = Gdx.graphics.getPpcY();
|
||||
private final static float AVG_FINGER_SIZE_CM = 1.1f;
|
||||
|
||||
public final static float AVG_FINGER_WIDTH = cmToPixelsX(AVG_FINGER_SIZE_CM);
|
||||
public final static float AVG_FINGER_HEIGHT = cmToPixelsY(AVG_FINGER_SIZE_CM);
|
||||
public final static float AVG_FINGER_WIDTH = Math.round(cmToPixelsX(AVG_FINGER_SIZE_CM)); //round to nearest int to reduce floating point display issues
|
||||
public final static float AVG_FINGER_HEIGHT = Math.round(cmToPixelsY(AVG_FINGER_SIZE_CM));
|
||||
|
||||
public final static float CARD_ASPECT_RATIO = 3.5f / 2.5f;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user