diff --git a/.gitattributes b/.gitattributes
index 6ae20246811..8d89ad71b5d 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -15983,12 +15983,14 @@ forge-m-android/src/com/forge/Main.java -text
forge-m-base/.classpath -text
forge-m-base/.project -text
forge-m-base/.settings/org.eclipse.jdt.core.prefs -text
+forge-m-base/libs/gdx-freetype.jar -text
forge-m-base/libs/gdx-sources.jar -text
forge-m-base/libs/gdx.jar -text
forge-m-base/src/forge/FScreen.java -text
forge-m-base/src/forge/Forge.java -text
forge-m-base/src/forge/assets/FSkin.java -text
forge-m-base/src/forge/assets/FSkinColor.java -text
+forge-m-base/src/forge/assets/FSkinFont.java -text
forge-m-base/src/forge/assets/FSkinImage.java -text
forge-m-base/src/forge/screens/home/HomeScreen.java -text
forge-m-base/src/forge/toolbox/FButton.java -text
@@ -15999,6 +16001,7 @@ forge-m-desktop/.project -text
forge-m-desktop/.settings/org.eclipse.jdt.core.prefs -text
forge-m-desktop/libs/gdx-backend-lwjgl-natives.jar -text
forge-m-desktop/libs/gdx-backend-lwjgl.jar -text
+forge-m-desktop/libs/gdx-freetype-natives.jar -text
forge-m-desktop/libs/gdx-natives.jar -text
forge-m-desktop/src/forge/view/Main.java -text
forge-net/.classpath -text
diff --git a/forge-m-android/.classpath b/forge-m-android/.classpath
index fbd40a5ba9d..ef62de6be3e 100644
--- a/forge-m-android/.classpath
+++ b/forge-m-android/.classpath
@@ -9,5 +9,6 @@
+
diff --git a/forge-m-base/.classpath b/forge-m-base/.classpath
index 4c7c3099327..c8b2ef50879 100644
--- a/forge-m-base/.classpath
+++ b/forge-m-base/.classpath
@@ -3,5 +3,6 @@
+
diff --git a/forge-m-base/libs/gdx-freetype.jar b/forge-m-base/libs/gdx-freetype.jar
new file mode 100644
index 00000000000..a89dcf14709
Binary files /dev/null and b/forge-m-base/libs/gdx-freetype.jar differ
diff --git a/forge-m-base/src/forge/Forge.java b/forge-m-base/src/forge/Forge.java
index e5c449ac376..61c9de569ea 100644
--- a/forge-m-base/src/forge/Forge.java
+++ b/forge-m-base/src/forge/Forge.java
@@ -5,10 +5,14 @@ import java.util.Stack;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
+import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
+import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
import forge.assets.FSkin;
+import forge.assets.FSkinColor;
+import forge.assets.FSkinFont;
import forge.assets.FSkinImage;
import forge.screens.home.HomeScreen;
@@ -93,6 +97,31 @@ public class Forge extends Game {
batch.draw(image, adjustX(x), adjustY(y, h), w, h);
}
+ public void drawText(String text, FSkinFont skinFont, FSkinColor skinColor, float x, float y, float w, float h, boolean wrap, boolean centerHorizontally, boolean centerVertically) {
+ BitmapFont font = skinFont.getFont();
+ font.setColor(skinColor.getColor());
+ if (wrap) {
+ float textHeight = font.getWrappedBounds(text, w).height;
+ if (h > textHeight && centerVertically) {
+ y += (h - textHeight) / 2;
+ }
+ else if (h == 0) {
+ h = textHeight;
+ }
+ font.drawWrapped(batch, text, adjustX(x), adjustY(y, h), w, centerHorizontally ? HAlignment.CENTER : HAlignment.LEFT);
+ }
+ else {
+ float textHeight = font.getMultiLineBounds(text).height;
+ if (h > textHeight && centerVertically) {
+ y += (h - textHeight) / 2;
+ }
+ else if (h == 0) {
+ h = textHeight;
+ }
+ font.drawMultiLine(batch, text, adjustX(x), adjustY(y, 0), w, centerHorizontally ? HAlignment.CENTER : HAlignment.LEFT);
+ }
+ }
+
private float adjustX(float x) {
return x + offsetX;
}
diff --git a/forge-m-base/src/forge/assets/FSkin.java b/forge-m-base/src/forge/assets/FSkin.java
index aae206437c3..8c3a1df8e6c 100644
--- a/forge-m-base/src/forge/assets/FSkin.java
+++ b/forge-m-base/src/forge/assets/FSkin.java
@@ -1,6 +1,5 @@
package forge.assets;
-import java.awt.Color;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -9,6 +8,7 @@ import java.util.Map;
import com.badlogic.gdx.Application.ApplicationType;
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.TextureRegion;
@@ -19,17 +19,14 @@ public class FSkin {
private static final String
FILE_SKINS_DIR = "skins/",
FILE_AVATAR_SPRITE = "sprite_avatars.png",
- FILE_FONT = "font1.ttf",
DEFAULT_DIR = FILE_SKINS_DIR + "default/";
private static final Map images = new HashMap();
private static final Map avatars = new HashMap();
private static ArrayList allSkins;
- private static int currentSkinIndex;
private static String preferredDir;
private static String preferredName;
- private static int defaultFontSize = 12;
private static boolean loaded = false;
public static void changeSkin(final String skinName) {
@@ -68,8 +65,6 @@ public class FSkin {
images.clear();
- currentSkinIndex = allSkins.indexOf(skinName);
-
// Non-default (preferred) skin name and dir.
preferredName = skinName.toLowerCase().replace(' ', '_');
preferredDir = FILE_SKINS_DIR + preferredName + "/";
@@ -93,10 +88,10 @@ public class FSkin {
images.put(FSkinImage.BG_SPLASH, new TextureRegion(texture, image.getX(), image.getY(),
image.getWidth(w), image.getHeight(h)));
- /*UIManager.put("ProgressBar.background", FSkin.getColorFromPixel(img.getRGB(25, h - 75)));
- UIManager.put("ProgressBar.selectionBackground", FSkin.getColorFromPixel(img.getRGB(75, h - 75)));
- UIManager.put("ProgressBar.foreground", FSkin.getColorFromPixel(img.getRGB(25, h - 25)));
- UIManager.put("ProgressBar.selectionForeground", FSkin.getColorFromPixel(img.getRGB(75, h - 25)));
+ /*UIManager.put("ProgressBar.background", new Color(img.getRGB(25, h - 75)));
+ UIManager.put("ProgressBar.selectionBackground", new Color(img.getRGB(75, h - 75)));
+ UIManager.put("ProgressBar.foreground", new Color(img.getRGB(25, h - 25)));
+ UIManager.put("ProgressBar.selectionForeground", new Color(img.getRGB(75, h - 25)));
UIManager.put("ProgressBar.border", new LineBorder(Color.BLACK, 0));*/
}
catch (final Exception e) {
@@ -167,7 +162,7 @@ public class FSkin {
//update colors
for (final FSkinColor.Colors c : FSkinColor.Colors.values()) {
- c.setColor(FSkin.getColorFromPixel(preferredIcons.getPixel(c.getX(), c.getY())));
+ c.setColor(new Color(preferredIcons.getPixel(c.getX(), c.getY())));
}
//add images besides splash background
@@ -199,8 +194,8 @@ public class FSkin {
for (int j = 0; j < ph; j += 100) {
for (int i = 0; i < pw; i += 100) {
if (i == 0 && j == 0) { continue; }
- pxTest = FSkin.getColorFromPixel(pxPreferredAvatars.getPixel(i + 50, j + 50));
- if (pxTest.getAlpha() == 0) { continue; }
+ pxTest = new Color(pxPreferredAvatars.getPixel(i + 50, j + 50));
+ if (pxTest.a == 0) { continue; }
FSkin.avatars.put(counter++, new TextureRegion(txPreferredAvatars, i, j, 100, 100));
}
}
@@ -213,8 +208,8 @@ public class FSkin {
for (int j = 0; j < ah; j += 100) {
for (int i = 0; i < aw; i += 100) {
if (i == 0 && j == 0) { continue; }
- pxTest = FSkin.getColorFromPixel(pxDefaultAvatars.getPixel(i + 50, j + 50));
- if (pxTest.getAlpha() == 0) { continue; }
+ pxTest = new Color(pxDefaultAvatars.getPixel(i + 50, j + 50));
+ if (pxTest.a == 0) { continue; }
FSkin.avatars.put(counter++, new TextureRegion(txDefaultAvatars, i, j, 100, 100));
}
}
@@ -232,11 +227,13 @@ public class FSkin {
e.printStackTrace();
}
- // Initialize fonts
- //SkinFont.setBaseFont(GuiUtils.newFont(FILE_SKINS_DIR + preferredName + "/" + FILE_FONT));
+ // Update fonts if needed
+ if (!onInit) {
+ FSkinFont.updateAll();
+ }
// Run through enums and load their coords.
- //Colors.updateAll();
+ FSkinColor.updateAll();
// Images loaded; can start UI init.
//FView.SINGLETON_INSTANCE.setSplashProgessBarMessage("Creating display components.");
@@ -283,11 +280,8 @@ public class FSkin {
private static TextureRegion loadTextureRegion(FSkinImage image, Map textures, Map pixmaps) {
String filename = image.getSourceFile().getFilename();
String preferredFile = preferredDir + filename;
- Texture texture = null;
- if (textures.containsKey(preferredFile)) {
- texture = textures.get(preferredFile);
- }
- else {
+ Texture texture = textures.get(preferredFile);
+ if (texture == null) {
FileHandle file = Gdx.files.internal(preferredFile);
if (file.exists()) {
try {
@@ -307,9 +301,11 @@ public class FSkin {
int w0 = image.getWidth(fullWidth);
int h0 = image.getHeight(fullHeight);
- if (pixmaps.containsKey(preferredFile)) {
- Pixmap pixmap = pixmaps.get(preferredFile);
-
+ Pixmap pixmap = pixmaps.get(preferredFile);
+ if (pixmap == null) { //return region for preferred file if no pixmap
+ return new TextureRegion(texture, x0, y0, w0, h0);
+ }
+ else {
// Test if requested sub-image in inside bounds of preferred sprite.
// (Height and width of preferred sprite were set in loadFontAndImages.)
if (x0 + w0 <= fullWidth && y0 + h0 <= fullHeight) {
@@ -321,38 +317,33 @@ public class FSkin {
// Center
x = (x0 + w0 / 2);
y = (y0 + h0 / 2);
- c = FSkin.getColorFromPixel(pixmap.getPixel(x, y));
- if (c.getAlpha() != 0) { return new TextureRegion(texture, x0, y0, w0, h0); }
+ c = new Color(pixmap.getPixel(x, y));
+ if (c.a != 0) { return new TextureRegion(texture, x0, y0, w0, h0); }
x += 2;
y += 2;
- c = FSkin.getColorFromPixel(pixmap.getPixel(x, y));
- if (c.getAlpha() != 0) { return new TextureRegion(texture, x0, y0, w0, h0); }
+ c = new Color(pixmap.getPixel(x, y));
+ if (c.a != 0) { return new TextureRegion(texture, x0, y0, w0, h0); }
x -= 4;
- c = FSkin.getColorFromPixel(pixmap.getPixel(x, y));
- if (c.getAlpha() != 0) { return new TextureRegion(texture, x0, y0, w0, h0); }
+ c = new Color(pixmap.getPixel(x, y));
+ if (c.a != 0) { return new TextureRegion(texture, x0, y0, w0, h0); }
y -= 4;
- c = FSkin.getColorFromPixel(pixmap.getPixel(x, y));
- if (c.getAlpha() != 0) { return new TextureRegion(texture, x0, y0, w0, h0); }
+ c = new Color(pixmap.getPixel(x, y));
+ if (c.a != 0) { return new TextureRegion(texture, x0, y0, w0, h0); }
x += 4;
- c = FSkin.getColorFromPixel(pixmap.getPixel(x, y));
- if (c.getAlpha() != 0) { return new TextureRegion(texture, x0, y0, w0, h0); }
+ c = new Color(pixmap.getPixel(x, y));
+ if (c.a != 0) { return new TextureRegion(texture, x0, y0, w0, h0); }
}
}
- else {
- return new TextureRegion(texture, x0, y0, w0, h0);
- }
}
//use default file if can't use preferred file
String defaultFile = DEFAULT_DIR + filename;
- if (textures.containsKey(defaultFile)) {
- texture = textures.get(defaultFile);
- }
- else {
+ texture = textures.get(defaultFile);
+ if (texture == null) {
FileHandle file = Gdx.files.internal(defaultFile);
if (file.exists()) {
try {
@@ -380,6 +371,15 @@ public class FSkin {
return FSkin.preferredName;
}
+ /**
+ * Gets the directory.
+ *
+ * @return Path of directory for the current skin.
+ */
+ public static String getDir() {
+ return FSkin.preferredDir;
+ }
+
/**
* Gets the skins.
*
@@ -423,13 +423,4 @@ public class FSkin {
}
public static boolean isLoaded() { return loaded; }
-
- private static Color getColorFromPixel(final int pixel) {
- int r, g, b, a;
- a = (pixel >> 24) & 0x000000ff;
- r = (pixel >> 16) & 0x000000ff;
- g = (pixel >> 8) & 0x000000ff;
- b = (pixel) & 0x000000ff;
- return new Color(r, g, b, a);
- }
}
diff --git a/forge-m-base/src/forge/assets/FSkinColor.java b/forge-m-base/src/forge/assets/FSkinColor.java
index 0bceac89ab1..0ea166089c9 100644
--- a/forge-m-base/src/forge/assets/FSkinColor.java
+++ b/forge-m-base/src/forge/assets/FSkinColor.java
@@ -1,8 +1,9 @@
package forge.assets;
-import java.awt.Color;
import java.util.HashMap;
+import com.badlogic.gdx.graphics.Color;
+
public class FSkinColor {
public enum Colors {
CLR_THEME (70, 10),
@@ -120,12 +121,12 @@ public class FSkinColor {
if (this.brightnessDelta != NO_BRIGHTNESS_DELTA) {
if (this.brightnessDelta < 0) {
for (int i = 0; i > this.brightnessDelta; i--) {
- this.color = this.color.darker();
+ this.color = FSkinColor.stepColor(this.color, 10);
}
}
else {
for (int i = 0; i < this.brightnessDelta; i++) {
- this.color = this.color.brighter();
+ this.color = FSkinColor.stepColor(this.color, -10);
}
}
}
@@ -149,9 +150,9 @@ public class FSkinColor {
* @return {@link java.awt.Color}
*/
public static Color stepColor(Color clr0, int step) {
- int r = clr0.getRed();
- int g = clr0.getGreen();
- int b = clr0.getBlue();
+ float r = clr0.r;
+ float g = clr0.g;
+ float b = clr0.b;
// Darker
if (step < 0) {
@@ -165,7 +166,7 @@ public class FSkinColor {
b = ((b + step < 255) ? b + step : 255);
}
- return new Color(r, g, b);
+ return new Color(r, g, b, 0);
}
/** Returns RGB components of a color, with a new
@@ -176,7 +177,7 @@ public class FSkinColor {
* @return {@link java.awt.Color}
*/
public static Color alphaColor(Color clr0, int alpha) {
- return new Color(clr0.getRed(), clr0.getGreen(), clr0.getBlue(), alpha);
+ return new Color(clr0.r, clr0.g, clr0.b, alpha);
}
/**
@@ -184,9 +185,9 @@ public class FSkinColor {
*/
public static boolean isColorBright(Color c) {
int v = (int)Math.sqrt(
- c.getRed() * c.getRed() * 0.241 +
- c.getGreen() * c.getGreen() * 0.691 +
- c.getBlue() * c.getBlue() * 0.068);
+ c.r * c.r * 0.241 +
+ c.g * c.g * 0.691 +
+ c.b * c.b * 0.068);
return v >= 130;
}
diff --git a/forge-m-base/src/forge/assets/FSkinFont.java b/forge-m-base/src/forge/assets/FSkinFont.java
new file mode 100644
index 00000000000..0db89d35ce3
--- /dev/null
+++ b/forge-m-base/src/forge/assets/FSkinFont.java
@@ -0,0 +1,74 @@
+package forge.assets;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.files.FileHandle;
+import com.badlogic.gdx.graphics.g2d.BitmapFont;
+import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
+
+public class FSkinFont {
+ private static final String TTF_FILE = "font1.ttf";
+ private static final int defaultFontSize = 12;
+ private static final Map fonts = new HashMap();
+
+ public static FSkinFont get() {
+ return get(defaultFontSize);
+ }
+
+ public static FSkinFont get(final int size0) {
+ FSkinFont skinFont = fonts.get(size0);
+ if (skinFont == null) {
+ skinFont = new FSkinFont(size0);
+ fonts.put(size0, skinFont);
+ }
+ return skinFont;
+ }
+
+ private final int size;
+ private BitmapFont font;
+
+ private FSkinFont(final int size0) {
+ this.size = size0;
+ this.updateFont();
+ }
+
+ public int getSize() {
+ return this.size;
+ }
+
+ public BitmapFont getFont() {
+ return font;
+ }
+
+ 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
+ generator.dispose();
+ }
+ }
+
+ public static void updateAll() {
+ for (FSkinFont skinFont : fonts.values()) {
+ skinFont.updateFont();
+ }
+ }
+}
diff --git a/forge-m-base/src/forge/toolbox/FButton.java b/forge-m-base/src/forge/toolbox/FButton.java
index 0413c1b6875..bf6db51df0d 100644
--- a/forge-m-base/src/forge/toolbox/FButton.java
+++ b/forge-m-base/src/forge/toolbox/FButton.java
@@ -1,10 +1,9 @@
package forge.toolbox;
-import java.awt.AlphaComposite;
-
import forge.Forge.Graphics;
import forge.assets.FSkinColor;
import forge.assets.FSkinColor.Colors;
+import forge.assets.FSkinFont;
import forge.assets.FSkinImage;
public class FButton extends FDisplayObject {
@@ -13,9 +12,9 @@ public class FButton extends FDisplayObject {
private FSkinImage imgL, imgM, imgR;
private String caption;
+ private FSkinFont font;
private boolean enabled = true;
private boolean toggled = false;
- private final AlphaComposite disabledComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.25f);
/**
* Instantiates a new FButton.
@@ -26,7 +25,7 @@ public class FButton extends FDisplayObject {
public FButton(final String caption0) {
caption = caption0;
- //setFont(FSkin.getBoldFont(14));
+ font = FSkinFont.get(14);
resetImg();
}
@@ -93,5 +92,8 @@ public class FButton extends FDisplayObject {
g.drawImage(imgL, 0, 0, h, h);
g.drawImage(imgM, h, 0, w - (2 * h), h);
g.drawImage(imgR, w - h, 0, h, h);
+ if (!caption.isEmpty()) {
+ g.drawText(caption, font, foreColor, insetX, 0, w - 2 * insetX, h, false, true, true);
+ }
}
}
diff --git a/forge-m-desktop/.classpath b/forge-m-desktop/.classpath
index 411872af491..bff9273e666 100644
--- a/forge-m-desktop/.classpath
+++ b/forge-m-desktop/.classpath
@@ -7,5 +7,6 @@
+
diff --git a/forge-m-desktop/libs/gdx-freetype-natives.jar b/forge-m-desktop/libs/gdx-freetype-natives.jar
new file mode 100644
index 00000000000..70c36e88784
Binary files /dev/null and b/forge-m-desktop/libs/gdx-freetype-natives.jar differ