diff --git a/forge-m-base/src/forge/FScreen.java b/forge-m-base/src/forge/FScreen.java index 1c1ce542e62..7404bb81e6a 100644 --- a/forge-m-base/src/forge/FScreen.java +++ b/forge-m-base/src/forge/FScreen.java @@ -3,10 +3,14 @@ package forge; import com.badlogic.gdx.Screen; import forge.Forge.Graphics; +import forge.assets.FSkinColor; import forge.assets.FSkinImage; +import forge.assets.FSkinColor.Colors; import forge.toolbox.FDisplayObject; public abstract class FScreen extends FDisplayObject implements Screen { + private static final FSkinColor clrTheme = FSkinColor.get(Colors.CLR_THEME); + @Override public final void resize(int width, int height) { setBounds(0, 0, width, height); @@ -26,6 +30,7 @@ public abstract class FScreen extends FDisplayObject implements Screen { protected void drawBackground(Graphics g) { g.drawImage(FSkinImage.BG_TEXTURE, 0, 0, getWidth(), getHeight()); + g.fillRect(clrTheme, 0, 0, getWidth(), getHeight()); } @Override diff --git a/forge-m-base/src/forge/Forge.java b/forge-m-base/src/forge/Forge.java index 61c9de569ea..93aa9392337 100644 --- a/forge-m-base/src/forge/Forge.java +++ b/forge-m-base/src/forge/Forge.java @@ -4,11 +4,15 @@ import java.util.Stack; import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL10; +import com.badlogic.gdx.graphics.GL20; 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 com.badlogic.gdx.graphics.glutils.ShapeRenderer; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType; import forge.assets.FSkin; import forge.assets.FSkinColor; @@ -20,6 +24,7 @@ public class Forge extends Game { private static Forge game; private static int screenHeight; private static SpriteBatch batch; + private static ShapeRenderer shapeRenderer; private static final Stack screens = new Stack(); public Forge() { @@ -32,7 +37,8 @@ public class Forge extends Game { @Override public void create() { batch = new SpriteBatch(); - //Gdx.graphics.setContinuousRendering(false); //save power consumption by disabling continuous rendering + shapeRenderer = new ShapeRenderer(); + Gdx.graphics.setContinuousRendering(false); //save power consumption by disabling continuous rendering FSkin.loadLight("journeyman", true); FSkin.loadFull(true); @@ -69,6 +75,7 @@ public class Forge extends Game { public void dispose () { super.dispose(); batch.dispose(); + shapeRenderer.dispose(); } public static class Graphics { @@ -84,6 +91,23 @@ public class Forge extends Game { offsetY = g.offsetY + y; } + public void fillRect(FSkinColor skinColor, float x, float y, float w, float h) { + fillRect(skinColor.getColor(), x, y, w, h); + } + public void fillRect(Color color, float x, float y, float w, float h) { + batch.end(); //must pause batch while rendering shapes + + if (color.a != 0) { //enable blending so alpha colored shapes work properly + Gdx.gl.glEnable(GL20.GL_BLEND); + } + shapeRenderer.begin(ShapeType.Filled); + shapeRenderer.setColor(color); + shapeRenderer.rect(x, y, w, h); + shapeRenderer.end(); + + batch.begin(); + } + public void drawImage(FSkinImage image, float x, float y) { drawImage(FSkin.getImages().get(image), x, y); } diff --git a/forge-m-base/src/forge/assets/FSkin.java b/forge-m-base/src/forge/assets/FSkin.java index 8c3a1df8e6c..223be7e3f8b 100644 --- a/forge-m-base/src/forge/assets/FSkin.java +++ b/forge-m-base/src/forge/assets/FSkin.java @@ -130,7 +130,6 @@ public class FSkin { avatars.clear(); final Map textures = new HashMap(); - final Map pixmaps = new HashMap(); //FView.SINGLETON_INSTANCE.setSplashProgessBarMessage("Processing image sprites: ", 5); @@ -144,11 +143,9 @@ public class FSkin { try { textures.put(f1.path(), new Texture(f1)); - Pixmap preferredIcons = new Pixmap(f1); - pixmaps.put(f1.path(), preferredIcons); //FView.SINGLETON_INSTANCE.incrementSplashProgessBar(++p); textures.put(f2.path(), new Texture(f2)); - pixmaps.put(f2.path(), new Pixmap(f2)); + Pixmap preferredIcons = new Pixmap(f2); //FView.SINGLETON_INSTANCE.incrementSplashProgessBar(++p); textures.put(f3.path(), new Texture(f3)); //FView.SINGLETON_INSTANCE.incrementSplashProgessBar(++p); @@ -168,7 +165,7 @@ public class FSkin { //add images besides splash background for (FSkinImage image : FSkinImage.values()) { if (image != FSkinImage.BG_SPLASH) { - TextureRegion textureRegion = loadTextureRegion(image, textures, pixmaps); + TextureRegion textureRegion = loadTextureRegion(image, textures, preferredIcons); if (textureRegion != null) { images.put(image, textureRegion); } @@ -214,9 +211,7 @@ public class FSkin { } } - for (Pixmap pixmap : pixmaps.values()) { - pixmap.dispose(); - } + preferredIcons.dispose(); pxDefaultAvatars.dispose(); //FView.SINGLETON_INSTANCE.incrementSplashProgessBar(++p); @@ -277,8 +272,9 @@ public class FSkin { addEncodingSymbol("T", GameplayImages.IMG_TAP);*/ } - private static TextureRegion loadTextureRegion(FSkinImage image, Map textures, Map pixmaps) { - String filename = image.getSourceFile().getFilename(); + private static TextureRegion loadTextureRegion(FSkinImage image, Map textures, Pixmap preferredIcons) { + SourceFile sourceFile = image.getSourceFile(); + String filename = sourceFile.getFilename(); String preferredFile = preferredDir + filename; Texture texture = textures.get(preferredFile); if (texture == null) { @@ -301,8 +297,7 @@ public class FSkin { int w0 = image.getWidth(fullWidth); int h0 = image.getHeight(fullHeight); - Pixmap pixmap = pixmaps.get(preferredFile); - if (pixmap == null) { //return region for preferred file if no pixmap + if (sourceFile != SourceFile.ICONS) { //just return region for preferred file if not icons file return new TextureRegion(texture, x0, y0, w0, h0); } else { @@ -317,24 +312,24 @@ public class FSkin { // Center x = (x0 + w0 / 2); y = (y0 + h0 / 2); - c = new Color(pixmap.getPixel(x, y)); + c = new Color(preferredIcons.getPixel(x, y)); if (c.a != 0) { return new TextureRegion(texture, x0, y0, w0, h0); } x += 2; y += 2; - c = new Color(pixmap.getPixel(x, y)); + c = new Color(preferredIcons.getPixel(x, y)); if (c.a != 0) { return new TextureRegion(texture, x0, y0, w0, h0); } x -= 4; - c = new Color(pixmap.getPixel(x, y)); + c = new Color(preferredIcons.getPixel(x, y)); if (c.a != 0) { return new TextureRegion(texture, x0, y0, w0, h0); } y -= 4; - c = new Color(pixmap.getPixel(x, y)); + c = new Color(preferredIcons.getPixel(x, y)); if (c.a != 0) { return new TextureRegion(texture, x0, y0, w0, h0); } x += 4; - c = new Color(pixmap.getPixel(x, y)); + c = new Color(preferredIcons.getPixel(x, y)); if (c.a != 0) { return new TextureRegion(texture, x0, y0, w0, h0); } } } diff --git a/forge-m-base/src/forge/assets/FSkinColor.java b/forge-m-base/src/forge/assets/FSkinColor.java index 0ea166089c9..f4fee129d25 100644 --- a/forge-m-base/src/forge/assets/FSkinColor.java +++ b/forge-m-base/src/forge/assets/FSkinColor.java @@ -58,7 +58,7 @@ public class FSkinColor { private final int brightnessDelta; private final int step; private final int contrastStep; - private final int alpha; + private final float alpha; protected Color color; public Color getColor() { return color; } @@ -67,7 +67,7 @@ public class FSkinColor { private FSkinColor(Colors baseColor0) { this(baseColor0, NO_BRIGHTNESS_DELTA, NO_STEP, NO_STEP, NO_ALPHA); } - private FSkinColor(Colors baseColor0, int brightnessDelta0, int step0, int contrastStep0, int alpha0) { + private FSkinColor(Colors baseColor0, int brightnessDelta0, int step0, int contrastStep0, float alpha0) { this.baseColor = baseColor0; this.brightnessDelta = brightnessDelta0; this.step = step0; @@ -76,7 +76,7 @@ public class FSkinColor { this.updateColor(); } - private FSkinColor getDerivedColor(int brightnessDelta0, int step0, int contrastStep0, int alpha0) { + private FSkinColor getDerivedColor(int brightnessDelta0, int step0, int contrastStep0, float alpha0) { String key = this.baseColor.name() + "|" + brightnessDelta0 + "|" + step0 + "|" + contrastStep0 + "|" + alpha0; FSkinColor derivedColor = derivedColors.get(key); if (derivedColor == null) { @@ -112,7 +112,7 @@ public class FSkinColor { return getContrastColor(255); } - public FSkinColor alphaColor(int alpha0) { + public FSkinColor alphaColor(float alpha0) { return getDerivedColor(this.brightnessDelta, this.step, this.contrastStep, alpha0); } @@ -150,9 +150,9 @@ public class FSkinColor { * @return {@link java.awt.Color} */ public static Color stepColor(Color clr0, int step) { - float r = clr0.r; - float g = clr0.g; - float b = clr0.b; + float r = clr0.r * 255; + float g = clr0.g * 255; + float b = clr0.b * 255; // Darker if (step < 0) { @@ -166,17 +166,14 @@ public class FSkinColor { b = ((b + step < 255) ? b + step : 255); } - return new Color(r, g, b, 0); + return new Color(r / 255, g / 255, b / 255, 0); } - /** Returns RGB components of a color, with a new - * value for alpha. 0 = transparent, 255 = opaque. - * - * @param clr0 {@link java.awt.Color} - * @param alpha int - * @return {@link java.awt.Color} + /** + * Returns RGB components of a color, with a new + * value for alpha. 0f = transparent, 1f = opaque. */ - public static Color alphaColor(Color clr0, int alpha) { + public static Color alphaColor(Color clr0, float alpha) { return new Color(clr0.r, clr0.g, clr0.b, alpha); } @@ -184,11 +181,11 @@ public class FSkinColor { * @see http://www.nbdtech.com/Blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx */ public static boolean isColorBright(Color c) { - int v = (int)Math.sqrt( + double v = Math.sqrt( c.r * c.r * 0.241 + c.g * c.g * 0.691 + c.b * c.b * 0.068); - return v >= 130; + return v > 0.5; } public static Color getHighContrastColor(Color c) {