diff --git a/forge-gui-mobile/src/forge/CachedCardImage.java b/forge-gui-mobile/src/forge/CachedCardImage.java index 91fad648edd..a58ffff4a27 100644 --- a/forge-gui-mobile/src/forge/CachedCardImage.java +++ b/forge-gui-mobile/src/forge/CachedCardImage.java @@ -34,11 +34,7 @@ public abstract class CachedCardImage implements ImageFetcher.Callback { } public Texture getImage() { - return ImageCache.getImage(key, true, false); - } - - public Texture getImage(boolean mask) { - return ImageCache.getImage(key, true, mask); + return ImageCache.getImage(key, true); } public abstract void onImageFetched(); diff --git a/forge-gui-mobile/src/forge/Graphics.java b/forge-gui-mobile/src/forge/Graphics.java index fd314326040..474560e16ee 100644 --- a/forge-gui-mobile/src/forge/Graphics.java +++ b/forge-gui-mobile/src/forge/Graphics.java @@ -312,21 +312,21 @@ public class Graphics { } //adjust width/height so rectangle covers equivalent filled area - w = Math.round(w - 1); - h = Math.round(h - 1); + w = Math.round(w + 1); + h = Math.round(h + 1); startShape(ShapeType.Line); shapeRenderer.setColor(color); - x = adjustX(x); - float y2 = adjustY(y, h); - float x2 = x + w; - y = y2 + h; - //TODO: draw arcs at corners - 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.arc(adjustX(x) + cornerRadius, adjustY(y + cornerRadius, 0), cornerRadius, 90f, 90f); + shapeRenderer.arc(adjustX(x) + w - cornerRadius, adjustY(y + cornerRadius, 0), cornerRadius, 0f, 90f); + shapeRenderer.arc(adjustX(x) + w - cornerRadius, adjustY(y + h - cornerRadius, 0), cornerRadius, 270, 90f); + shapeRenderer.arc(adjustX(x) + cornerRadius, adjustY(y + h - cornerRadius, 0), cornerRadius, 180, 90f); + + shapeRenderer.rect(adjustX(x) + cornerRadius, adjustY(y, cornerRadius), w - 2*cornerRadius, cornerRadius); + shapeRenderer.rect(adjustX(x) + w - cornerRadius, adjustY(y + cornerRadius, h - 2*cornerRadius), cornerRadius, h - 2*cornerRadius); + shapeRenderer.rect(adjustX(x) + cornerRadius, adjustY(y + h - cornerRadius, cornerRadius), w - 2*cornerRadius, cornerRadius); + shapeRenderer.rect(adjustX(x), adjustY(y + cornerRadius, h - 2*cornerRadius), cornerRadius, h - 2*cornerRadius); endShape(); @@ -343,6 +343,30 @@ public class Graphics { batch.begin(); } + public void fillRoundRect(Color color, float x, float y, float w, float h, float radius) { + batch.end(); //must pause batch while rendering shapes + if (alphaComposite < 1) { + color = FSkinColor.alphaColor(color, color.a * alphaComposite); + } + if (color.a < 1) { //enable blending so alpha colored shapes work properly + Gdx.gl.glEnable(GL_BLEND); + } + startShape(ShapeType.Filled); + shapeRenderer.setColor(color); + shapeRenderer.circle(adjustX(x+radius), adjustY(y+radius, 0), radius); + shapeRenderer.circle(adjustX((x+w) - radius), adjustY(y+radius, 0), radius); + shapeRenderer.circle(adjustX(x+radius), adjustY((y+h) - radius, 0), radius); + shapeRenderer.circle(adjustX((x+w) - radius), adjustY((y+h) - radius, 0), radius); + + shapeRenderer.rect(adjustX(x), adjustY(y+radius, h-radius*2), w, h-radius*2); + shapeRenderer.rect(adjustX(x+radius), adjustY(y, h), w-radius*2, h); + endShape(); + if (color.a < 1) { + Gdx.gl.glDisable(GL_BLEND); + } + batch.begin(); + } + public void drawRect(float thickness, FSkinColor skinColor, float x, float y, float w, float h) { drawRect(thickness, skinColor.getColor(), x, y, w, h); } diff --git a/forge-gui-mobile/src/forge/assets/ImageCache.java b/forge-gui-mobile/src/forge/assets/ImageCache.java index 280771ac490..97d7e6845f7 100644 --- a/forge-gui-mobile/src/forge/assets/ImageCache.java +++ b/forge-gui-mobile/src/forge/assets/ImageCache.java @@ -82,11 +82,7 @@ public class ImageCache { } public static Texture getImage(InventoryItem ii) { - return getImage(ii.getImageKey(false), true, false); - } - - public static Texture getImage(InventoryItem ii, Boolean mask) { - return getImage(ii.getImageKey(false), true, mask); + return getImage(ii.getImageKey(false), true); } /** @@ -112,9 +108,6 @@ public class ImageCache { *

*/ public static Texture getImage(String imageKey, boolean useDefaultIfNotFound) { - return getImage(imageKey, useDefaultIfNotFound, false); - } - public static Texture getImage(String imageKey, boolean useDefaultIfNotFound, boolean maskCard) { if (StringUtils.isEmpty(imageKey)) { return null; } @@ -133,8 +126,6 @@ public class ImageCache { Texture image; if (useDefaultIfNotFound) { // Load from file and add to cache if not found in cache initially. - if (maskCard)//if we add pixmap modification here, it will slow performance so we do this on the image loader lol :)... - imageKey += "#drawroundcorner#"; image = cache.get(imageKey); if (image != null) { return image; } diff --git a/forge-gui-mobile/src/forge/assets/ImageLoader.java b/forge-gui-mobile/src/forge/assets/ImageLoader.java index e1d59279273..ef26a9eced0 100644 --- a/forge-gui-mobile/src/forge/assets/ImageLoader.java +++ b/forge-gui-mobile/src/forge/assets/ImageLoader.java @@ -3,11 +3,7 @@ package forge.assets; import java.io.File; 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.TextureData; -import com.badlogic.gdx.graphics.glutils.PixmapTextureData; import org.cache2k.integration.CacheLoader; import forge.Forge; @@ -16,21 +12,15 @@ import forge.ImageKeys; final class ImageLoader extends CacheLoader { @Override public Texture load(String key) { - boolean mask = key.contains("#drawroundcorner#"); - boolean alphaCard = false; boolean textureFilter = Forge.isTextureFilteringEnabled(); - if (key.length() > 4){ - if ((key.substring(0,4).contains("LEA/")) || (key.substring(0,2).contains("A/"))) - alphaCard = true; - //TODO dont add border on some sets??? - } - - File file = ImageKeys.getImageFile(key.replaceAll("#drawroundcorner#","")); + File file = ImageKeys.getImageFile(key); if (file != null) { FileHandle fh = new FileHandle(file); - Texture t = new Texture(fh, textureFilter); try { - return generateTexture(fh, t, mask, alphaCard, textureFilter); + Texture t = new Texture(fh, textureFilter); + if (textureFilter) + t.setFilter(Texture.TextureFilter.MipMapLinearLinear, Texture.TextureFilter.Linear); + return t; } catch (Exception ex) { Forge.log("Could not read image file " + fh.path() + "\n\nException:\n" + ex.toString()); @@ -38,81 +28,4 @@ final class ImageLoader extends CacheLoader { } return null; } - public Texture generateTexture(FileHandle fh, Texture t, boolean mask, boolean alphaCard, boolean textureFilter) { - if (!mask) { - if (textureFilter) - t.setFilter(Texture.TextureFilter.MipMapLinearLinear, Texture.TextureFilter.Linear); - return t; - } - Pixmap pImage = new Pixmap(fh); - int w = pImage.getWidth(); - int h = pImage.getHeight(); - int radius = alphaCard ? (h - w) / 6 : (h - w) / 8; - Pixmap pMask = createRoundedRectangle(w, h, radius, Color.RED); - drawPixelstoMask(pImage, pMask); - TextureData textureData = new PixmapTextureData( - pMask, //pixmap to use - Pixmap.Format.RGBA8888, - textureFilter, //use mipmaps - false, true); - t = new Texture(textureData); - if (textureFilter) - t.setFilter(Texture.TextureFilter.MipMapLinearLinear, Texture.TextureFilter.Linear); - pImage.dispose(); - pMask.dispose(); - return t; - } - public Pixmap createRoundedRectangle(int width, int height, int cornerRadius, Color color) { - Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888); - Pixmap ret = new Pixmap(width, height, Pixmap.Format.RGBA8888); - pixmap.setColor(color); - //round corners - pixmap.fillCircle(cornerRadius, cornerRadius, cornerRadius); - pixmap.fillCircle(width - cornerRadius - 1, cornerRadius, cornerRadius); - pixmap.fillCircle(cornerRadius, height - cornerRadius - 1, cornerRadius); - pixmap.fillCircle(width - cornerRadius - 1, height - cornerRadius - 1, cornerRadius); - //two rectangle parts - pixmap.fillRectangle(cornerRadius, 0, width - cornerRadius * 2, height); - pixmap.fillRectangle(0, cornerRadius, width, height - cornerRadius * 2); - //draw rounded rectangle - ret.setColor(color); - for (int x = 0; x < width; x++) { - for (int y = 0; y < height; y++) { - if (pixmap.getPixel(x, y) != 0) ret.drawPixel(x, y); - } - } - pixmap.dispose(); - return ret; - } - public void drawPixelstoMask(Pixmap pixmap, Pixmap mask){ - int pixmapWidth = mask.getWidth(); - int pixmapHeight = mask.getHeight(); - Color pixelColor = new Color(); - for (int x=0; x { localizer.getMessage("nlDisableCardEffect")), 4); lstSettings.addItem(new BooleanSetting(FPref.UI_ENABLE_BORDER_MASKING, - "Experimental Round Border Mask", - "When enabled, the card corners are rounded (CPU/GPU Dependent atm)."), + "Enable Round Border Mask", + "When enabled, the card corners are rounded (Preferably Card with Full Borders)."), 4); lstSettings.addItem(new CustomSelectSetting(FPref.UI_CARD_COUNTER_DISPLAY_TYPE,