mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
Alternative/Faster Round Border
This commit is contained in:
@@ -343,6 +343,30 @@ public class Graphics {
|
|||||||
batch.begin();
|
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) {
|
public void drawRect(float thickness, FSkinColor skinColor, float x, float y, float w, float h) {
|
||||||
drawRect(thickness, skinColor.getColor(), x, y, w, h);
|
drawRect(thickness, skinColor.getColor(), x, y, w, h);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package forge.card;
|
package forge.card;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import forge.Graphics;
|
import forge.Graphics;
|
||||||
import forge.assets.FImage;
|
import forge.assets.FImage;
|
||||||
import forge.assets.ImageCache;
|
import forge.assets.ImageCache;
|
||||||
@@ -22,6 +24,24 @@ public class CardImage implements FImage {
|
|||||||
private static boolean isPreferenceEnabled(ForgePreferences.FPref preferenceName) {
|
private static boolean isPreferenceEnabled(ForgePreferences.FPref preferenceName) {
|
||||||
return FModel.getPreferences().getPrefBoolean(preferenceName);
|
return FModel.getPreferences().getPrefBoolean(preferenceName);
|
||||||
}
|
}
|
||||||
|
public static TextureRegion croppedBorderImage(Texture image) {
|
||||||
|
float rscale = 0.96f;
|
||||||
|
int rw = Math.round(image.getWidth()*rscale);
|
||||||
|
int rh = Math.round(image.getHeight()*rscale);
|
||||||
|
int rx = Math.round((image.getWidth() - rw)/2);
|
||||||
|
int ry = Math.round((image.getHeight() - rh)/2);
|
||||||
|
TextureRegion rimage = new TextureRegion(image, rx, ry, rw, rh);
|
||||||
|
return rimage;
|
||||||
|
}
|
||||||
|
public static Color borderColor(PaperCard c) {
|
||||||
|
if (c == null)
|
||||||
|
return Color.valueOf("#1c1c1c");
|
||||||
|
|
||||||
|
CardEdition ed = FModel.getMagicDb().getEditions().get(c.getEdition());
|
||||||
|
if (ed != null && ed.isWhiteBorder())
|
||||||
|
return Color.valueOf("#fffffd");
|
||||||
|
return Color.valueOf("#1c1c1c");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getWidth() {
|
public float getWidth() {
|
||||||
@@ -38,9 +58,9 @@ public class CardImage implements FImage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics g, float x, float y, float w, float h) {
|
public void draw(Graphics g, float x, float y, float w, float h) {
|
||||||
|
boolean mask = isPreferenceEnabled(ForgePreferences.FPref.UI_ENABLE_BORDER_MASKING);
|
||||||
if (image == null) { //attempt to retrieve card image if needed
|
if (image == null) { //attempt to retrieve card image if needed
|
||||||
boolean mask = isPreferenceEnabled(ForgePreferences.FPref.UI_ENABLE_BORDER_MASKING);
|
image = ImageCache.getImage(card);
|
||||||
image = ImageCache.getImage(card, mask);
|
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
if (mask) //render this if mask is still loading
|
if (mask) //render this if mask is still loading
|
||||||
CardImageRenderer.drawCardImage(g, CardView.getCardForUi(card), false, x, y, w, h, CardStackPosition.Top);
|
CardImageRenderer.drawCardImage(g, CardView.getCardForUi(card), false, x, y, w, h, CardStackPosition.Top);
|
||||||
@@ -53,7 +73,13 @@ public class CardImage implements FImage {
|
|||||||
CardImageRenderer.drawCardImage(g, CardView.getCardForUi(card), false, x, y, w, h, CardStackPosition.Top);
|
CardImageRenderer.drawCardImage(g, CardView.getCardForUi(card), false, x, y, w, h, CardStackPosition.Top);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
g.drawImage(image, x, y, w, h);
|
if (mask) {
|
||||||
|
float radius = (h - w)/8;
|
||||||
|
g.fillRoundRect(borderColor(card), x, y, w, h, radius);
|
||||||
|
g.drawImage(croppedBorderImage(image), x+radius/2.2f, y+radius/2, w*0.96f, h*0.96f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
g.drawImage(image, x, y, w, h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -326,6 +326,7 @@ public class CardImageRenderer {
|
|||||||
|
|
||||||
public static void drawZoom(Graphics g, CardView card, GameView gameView, boolean altState, float x, float y, float w, float h, float dispW, float dispH, boolean isCurrentCard) {
|
public static void drawZoom(Graphics g, CardView card, GameView gameView, boolean altState, float x, float y, float w, float h, float dispW, float dispH, boolean isCurrentCard) {
|
||||||
boolean mask = isPreferenceEnabled(ForgePreferences.FPref.UI_ENABLE_BORDER_MASKING);
|
boolean mask = isPreferenceEnabled(ForgePreferences.FPref.UI_ENABLE_BORDER_MASKING);
|
||||||
|
//this one is currently using the mask, others are cropped and use generated borders from shaperenderer ...
|
||||||
final Texture image = ImageCache.getImage(card.getState(altState).getImageKey(MatchController.instance.getLocalPlayers()), true, mask);
|
final Texture image = ImageCache.getImage(card.getState(altState).getImageKey(MatchController.instance.getLocalPlayers()), true, mask);
|
||||||
if (image == null) { //draw details if can't draw zoom
|
if (image == null) { //draw details if can't draw zoom
|
||||||
drawDetails(g, card, gameView, altState, x, y, w, h);
|
drawDetails(g, card, gameView, altState, x, y, w, h);
|
||||||
|
|||||||
@@ -391,16 +391,50 @@ public class CardRenderer {
|
|||||||
g.drawText(set, font, foreColor, x, y, w, h, false, Align.center, true);
|
g.drawText(set, font, foreColor, x, y, w, h, false, Align.center, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TextureRegion croppedBorderImage(Texture image) {
|
||||||
|
float rscale = 0.96f;
|
||||||
|
int rw = Math.round(image.getWidth()*rscale);
|
||||||
|
int rh = Math.round(image.getHeight()*rscale);
|
||||||
|
int rx = Math.round((image.getWidth() - rw)/2);
|
||||||
|
int ry = Math.round((image.getHeight() - rh)/2);
|
||||||
|
TextureRegion rimage = new TextureRegion(image, rx, ry, rw, rh);
|
||||||
|
return rimage;
|
||||||
|
}
|
||||||
|
public static Color borderColor(IPaperCard c) {
|
||||||
|
if (c == null)
|
||||||
|
return Color.valueOf("#1c1c1c");
|
||||||
|
|
||||||
|
CardEdition ed = FModel.getMagicDb().getEditions().get(c.getEdition());
|
||||||
|
if (ed != null && ed.isWhiteBorder())
|
||||||
|
return Color.valueOf("#fffffd");
|
||||||
|
return Color.valueOf("#1c1c1c");
|
||||||
|
}
|
||||||
|
public static Color borderColor(CardView c) {
|
||||||
|
if (c == null)
|
||||||
|
return Color.valueOf("#1c1c1c");
|
||||||
|
|
||||||
|
CardStateView state = c.getCurrentState();
|
||||||
|
CardEdition ed = FModel.getMagicDb().getEditions().get(state.getSetCode());
|
||||||
|
if (ed != null && ed.isWhiteBorder() && state.getFoilIndex() == 0)
|
||||||
|
return Color.valueOf("#fffffd");
|
||||||
|
return Color.valueOf("#1c1c1c");
|
||||||
|
}
|
||||||
public static void drawCard(Graphics g, IPaperCard pc, float x, float y, float w, float h, CardStackPosition pos) {
|
public static void drawCard(Graphics g, IPaperCard pc, float x, float y, float w, float h, CardStackPosition pos) {
|
||||||
boolean mask = isPreferenceEnabled(FPref.UI_ENABLE_BORDER_MASKING);
|
boolean mask = isPreferenceEnabled(FPref.UI_ENABLE_BORDER_MASKING);
|
||||||
Texture image = new RendererCachedCardImage(pc, false).getImage(mask);
|
Texture image = new RendererCachedCardImage(pc, false).getImage();
|
||||||
|
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
if (image == ImageCache.defaultImage) {
|
if (image == ImageCache.defaultImage) {
|
||||||
CardImageRenderer.drawCardImage(g, CardView.getCardForUi(pc), false, x, y, w, h, pos);
|
CardImageRenderer.drawCardImage(g, CardView.getCardForUi(pc), false, x, y, w, h, pos);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
g.drawImage(image, x, y, w, h);
|
if (mask) {
|
||||||
|
float radius = (h - w)/8;
|
||||||
|
g.fillRoundRect(borderColor(pc), x, y, w, h, radius);
|
||||||
|
g.drawImage(croppedBorderImage(image), x+radius/2.2f, y+radius/2, w*0.96f, h*0.96f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
g.drawImage(image, x, y, w, h);
|
||||||
}
|
}
|
||||||
if (pc.isFoil()) { //draw foil effect if needed
|
if (pc.isFoil()) { //draw foil effect if needed
|
||||||
final CardView card = CardView.getCardForUi(pc);
|
final CardView card = CardView.getCardForUi(pc);
|
||||||
@@ -420,7 +454,7 @@ public class CardRenderer {
|
|||||||
|
|
||||||
public static void drawCard(Graphics g, CardView card, float x, float y, float w, float h, CardStackPosition pos, boolean rotate) {
|
public static void drawCard(Graphics g, CardView card, float x, float y, float w, float h, CardStackPosition pos, boolean rotate) {
|
||||||
boolean mask = isPreferenceEnabled(FPref.UI_ENABLE_BORDER_MASKING);
|
boolean mask = isPreferenceEnabled(FPref.UI_ENABLE_BORDER_MASKING);
|
||||||
Texture image = new RendererCachedCardImage(card, false).getImage(mask);
|
Texture image = new RendererCachedCardImage(card, false).getImage();
|
||||||
|
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
if (image == ImageCache.defaultImage) {
|
if (image == ImageCache.defaultImage) {
|
||||||
@@ -428,10 +462,24 @@ public class CardRenderer {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(FModel.getPreferences().getPrefBoolean(ForgePreferences.FPref.UI_ROTATE_PLANE_OR_PHENOMENON)
|
if(FModel.getPreferences().getPrefBoolean(ForgePreferences.FPref.UI_ROTATE_PLANE_OR_PHENOMENON)
|
||||||
&& (card.getCurrentState().isPhenomenon() || card.getCurrentState().isPlane()) && rotate)
|
&& (card.getCurrentState().isPhenomenon() || card.getCurrentState().isPlane()) && rotate){
|
||||||
g.drawRotatedImage(image, x, y, w, h, x + w / 2, y + h / 2, -90);
|
if (mask) {
|
||||||
else
|
float radius = (h - w)/8;
|
||||||
g.drawImage(image, x, y, w, h);
|
g.fillRoundRect(borderColor(card), x, y, w, h, radius);
|
||||||
|
g.drawRotatedImage(croppedBorderImage(image), x+radius/2.2f, y+radius/2, w*0.96f, h*0.96f, (x+radius/2) + (w*0.96f) / 2, (y+radius/2) + (h*0.96f) / 2, -90);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
g.drawRotatedImage(image, x, y, w, h, x + w / 2, y + h / 2, -90);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (mask) {
|
||||||
|
float radius = (h - w)/8;
|
||||||
|
g.fillRoundRect(borderColor(card), x, y, w, h, radius);
|
||||||
|
g.drawImage(croppedBorderImage(image), x+radius/2.2f, y+radius/2, w*0.96f, h*0.96f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
g.drawImage(image, x, y, w, h);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
drawFoilEffect(g, card, x, y, w, h, false);
|
drawFoilEffect(g, card, x, y, w, h, false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -302,8 +302,8 @@ public class SettingsPage extends TabPage<SettingsScreen> {
|
|||||||
localizer.getMessage("nlDisableCardEffect")),
|
localizer.getMessage("nlDisableCardEffect")),
|
||||||
4);
|
4);
|
||||||
lstSettings.addItem(new BooleanSetting(FPref.UI_ENABLE_BORDER_MASKING,
|
lstSettings.addItem(new BooleanSetting(FPref.UI_ENABLE_BORDER_MASKING,
|
||||||
"Experimental Round Border Mask",
|
"Enable Round Border Mask",
|
||||||
"When enabled, the card corners are rounded (CPU/GPU Dependent atm)."),
|
"When enabled, the card corners are rounded (Preferably Card with Full Borders)."),
|
||||||
4);
|
4);
|
||||||
|
|
||||||
lstSettings.addItem(new CustomSelectSetting(FPref.UI_CARD_COUNTER_DISPLAY_TYPE,
|
lstSettings.addItem(new CustomSelectSetting(FPref.UI_CARD_COUNTER_DISPLAY_TYPE,
|
||||||
|
|||||||
Reference in New Issue
Block a user