Flesh out ConstructedScreen more

Support alphaComposite for Graphics
This commit is contained in:
drdev
2014-04-03 04:21:59 +00:00
parent 41d864cbe8
commit 9fbb1eedb8
8 changed files with 178 additions and 72 deletions

View File

@@ -339,6 +339,7 @@ public class Forge implements ApplicationListener {
public static class Graphics { public static class Graphics {
private Rectangle bounds; private Rectangle bounds;
private int failedClipCount; private int failedClipCount;
private float alphaComposite = 1;
private Graphics() { private Graphics() {
bounds = new Rectangle(0, 0, screenWidth, screenHeight); bounds = new Rectangle(0, 0, screenWidth, screenHeight);
@@ -388,6 +389,9 @@ public class Forge implements ApplicationListener {
if (thickness > 1) { if (thickness > 1) {
Gdx.gl.glLineWidth(thickness); Gdx.gl.glLineWidth(thickness);
} }
if (alphaComposite < 1) {
color = FSkinColor.alphaColor(color, color.a * alphaComposite);
}
boolean needSmoothing = (x1 != x2 && y1 != y2); boolean needSmoothing = (x1 != x2 && y1 != y2);
if (color.a < 1 || needSmoothing) { //enable blending so alpha colored shapes work properly if (color.a < 1 || needSmoothing) { //enable blending so alpha colored shapes work properly
Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glEnable(GL20.GL_BLEND);
@@ -423,6 +427,9 @@ public class Forge implements ApplicationListener {
if (thickness > 1) { if (thickness > 1) {
Gdx.gl.glLineWidth(thickness); Gdx.gl.glLineWidth(thickness);
} }
if (alphaComposite < 1) {
color = FSkinColor.alphaColor(color, color.a * alphaComposite);
}
if (color.a < 1 || cornerRadius > 0) { //enable blending so alpha colored shapes work properly if (color.a < 1 || cornerRadius > 0) { //enable blending so alpha colored shapes work properly
Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glEnable(GL20.GL_BLEND);
} }
@@ -471,6 +478,9 @@ public class Forge implements ApplicationListener {
if (thickness > 1) { if (thickness > 1) {
Gdx.gl.glLineWidth(thickness); Gdx.gl.glLineWidth(thickness);
} }
if (alphaComposite < 1) {
color = FSkinColor.alphaColor(color, color.a * alphaComposite);
}
Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glEnable(GL20.GL_BLEND);
Gdx.gl.glEnable(GL10.GL_LINE_SMOOTH); //must be smooth to ensure edges aren't missed Gdx.gl.glEnable(GL10.GL_LINE_SMOOTH); //must be smooth to ensure edges aren't missed
@@ -494,6 +504,9 @@ public class Forge implements ApplicationListener {
public void fillRect(Color color, float x, float y, float w, float h) { public void fillRect(Color color, float x, float y, float w, float h) {
batch.end(); //must pause batch while rendering shapes 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 if (color.a < 1) { //enable blending so alpha colored shapes work properly
Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glEnable(GL20.GL_BLEND);
} }
@@ -519,6 +532,9 @@ public class Forge implements ApplicationListener {
if (thickness > 1) { if (thickness > 1) {
Gdx.gl.glLineWidth(thickness); Gdx.gl.glLineWidth(thickness);
} }
if (alphaComposite < 1) {
color = FSkinColor.alphaColor(color, color.a * alphaComposite);
}
Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glEnable(GL20.GL_BLEND);
Gdx.gl.glEnable(GL10.GL_LINE_SMOOTH); Gdx.gl.glEnable(GL10.GL_LINE_SMOOTH);
@@ -542,6 +558,9 @@ public class Forge implements ApplicationListener {
public void fillCircle(Color color, float x, float y, float radius) { public void fillCircle(Color color, float x, float y, float radius) {
batch.end(); //must pause batch while rendering shapes 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 if (color.a < 1) { //enable blending so alpha colored shapes work properly
Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glEnable(GL20.GL_BLEND);
} }
@@ -564,6 +583,9 @@ public class Forge implements ApplicationListener {
public void fillTriangle(Color color, float x1, float y1, float x2, float y2, float x3, float y3) { public void fillTriangle(Color color, float x1, float y1, float x2, float y2, float x3, float y3) {
batch.end(); //must pause batch while rendering shapes 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 if (color.a < 1) { //enable blending so alpha colored shapes work properly
Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glEnable(GL20.GL_BLEND);
} }
@@ -592,6 +614,10 @@ public class Forge implements ApplicationListener {
public void fillGradientRect(Color color1, Color color2, boolean vertical, float x, float y, float w, float h) { public void fillGradientRect(Color color1, Color color2, boolean vertical, float x, float y, float w, float h) {
batch.end(); //must pause batch while rendering shapes batch.end(); //must pause batch while rendering shapes
if (alphaComposite < 1) {
color1 = FSkinColor.alphaColor(color1, color1.a * alphaComposite);
color2 = FSkinColor.alphaColor(color2, color2.a * alphaComposite);
}
boolean needBlending = (color1.a < 1 || color2.a < 1); boolean needBlending = (color1.a < 1 || color2.a < 1);
if (needBlending) { //enable blending so alpha colored shapes work properly if (needBlending) { //enable blending so alpha colored shapes work properly
Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glEnable(GL20.GL_BLEND);
@@ -613,10 +639,12 @@ public class Forge implements ApplicationListener {
batch.begin(); batch.begin();
} }
public void setImageTint(Color color) { public void setAlphaComposite(float alphaComposite0) {
batch.setColor(color); alphaComposite = alphaComposite0;
batch.setColor(new Color(1, 1, 1, alphaComposite));
} }
public void clearImageTint() { public void resetAlphaComposite() {
alphaComposite = 1;
batch.setColor(Color.WHITE); batch.setColor(Color.WHITE);
} }
@@ -651,6 +679,13 @@ public class Forge implements ApplicationListener {
drawText(text, skinFont, skinColor.getColor(), x, y, w, h, wrap, horzAlignment, centerVertically); drawText(text, skinFont, skinColor.getColor(), x, y, w, h, wrap, horzAlignment, centerVertically);
} }
public void drawText(String text, FSkinFont skinFont, Color color, float x, float y, float w, float h, boolean wrap, HAlignment horzAlignment, boolean centerVertically) { public void drawText(String text, FSkinFont skinFont, Color color, float x, float y, float w, float h, boolean wrap, HAlignment horzAlignment, boolean centerVertically) {
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(GL20.GL_BLEND);
}
int fontSize = skinFont.getSize(); int fontSize = skinFont.getSize();
BitmapFont font = skinFont.getFont(); BitmapFont font = skinFont.getFont();
if (wrap) { if (wrap) {
@@ -679,6 +714,10 @@ public class Forge implements ApplicationListener {
font.setColor(color); font.setColor(color);
font.drawMultiLine(batch, text, adjustX(x), adjustY(y, 0), w, horzAlignment); font.drawMultiLine(batch, text, adjustX(x), adjustY(y, 0), w, horzAlignment);
} }
if (color.a < 1) {
Gdx.gl.glDisable(GL20.GL_BLEND);
}
} }
private float adjustX(float x) { private float adjustX(float x) {

View File

@@ -13,8 +13,10 @@ import java.util.Vector;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import forge.Forge.Graphics;
import forge.assets.FSkin; import forge.assets.FSkin;
import forge.assets.FSkinColor; import forge.assets.FSkinColor;
import forge.assets.FSkinColor.Colors; import forge.assets.FSkinColor.Colors;
@@ -49,7 +51,7 @@ import forge.utils.Utils;
public class ConstructedScreen extends LaunchScreen { public class ConstructedScreen extends LaunchScreen {
private static final FSkinColor PLAYER_BORDER_COLOR = FSkinColor.get(Colors.CLR_THEME).alphaColor(0.8f); private static final FSkinColor PLAYER_BORDER_COLOR = FSkinColor.get(Colors.CLR_THEME).alphaColor(0.8f);
private static final ForgePreferences prefs = FModel.getPreferences(); private static final ForgePreferences prefs = FModel.getPreferences();
private static final float PADDING = 5;
private static final int MAX_PLAYERS = 8; private static final int MAX_PLAYERS = 8;
// General variables // General variables
@@ -73,7 +75,13 @@ public class ConstructedScreen extends LaunchScreen {
private final FScrollPane playersScroll = new FScrollPane() { private final FScrollPane playersScroll = new FScrollPane() {
@Override @Override
protected ScrollBounds layoutAndGetScrollBounds(float visibleWidth, float visibleHeight) { protected ScrollBounds layoutAndGetScrollBounds(float visibleWidth, float visibleHeight) {
//TODO float y = 0;
float height;
for (int i = 0; i < activePlayersNum; i++) {
height = playerPanels.get(i).getPreferredHeight();
playerPanels.get(i).setBounds(0, y, visibleWidth, height);
y += height;
}
return new ScrollBounds(visibleWidth, visibleHeight); return new ScrollBounds(visibleWidth, visibleHeight);
} }
}; };
@@ -122,9 +130,8 @@ public class ConstructedScreen extends LaunchScreen {
///////////////////// Player Panel ///////////////////// ///////////////////// Player Panel /////////////////////
// Construct individual player panels // Construct individual player panels
String constraints = "pushx, growx, wrap, hidemode 3";
for (int i = 0; i < MAX_PLAYERS; i++) { for (int i = 0; i < MAX_PLAYERS; i++) {
teams.add(i+1); teams.add(i + 1);
archenemyTeams.add(i == 0 ? 1 : 2); archenemyTeams.add(i == 0 ? 1 : 2);
PlayerPanel player = new PlayerPanel(i); PlayerPanel player = new PlayerPanel(i);
@@ -134,12 +141,8 @@ public class ConstructedScreen extends LaunchScreen {
player.setVisible(i < activePlayersNum); player.setVisible(i < activePlayersNum);
playersScroll.add(player); playersScroll.add(player);
if (i == 0) {
constraints += ", gaptop 5px";
}
} }
add(playersScroll); add(playersScroll);
addPlayerBtn.setCommand(new FEventHandler() { addPlayerBtn.setCommand(new FEventHandler() {
@@ -150,6 +153,11 @@ public class ConstructedScreen extends LaunchScreen {
}); });
add(addPlayerBtn); add(addPlayerBtn);
} }
@Override
protected void doLayoutAboveBtnStart(float startY, float width, float height) {
playersScroll.setBounds(0, startY, width, height - startY);
}
private void addPlayer() { private void addPlayer() {
if (activePlayersNum >= MAX_PLAYERS) { if (activePlayersNum >= MAX_PLAYERS) {
@@ -177,19 +185,6 @@ public class ConstructedScreen extends LaunchScreen {
PlayerPanel player = playerPanels.get(playerIndex); PlayerPanel player = playerPanels.get(playerIndex);
player.setVisible(false); player.setVisible(false);
addPlayerBtn.setEnabled(true); addPlayerBtn.setEnabled(true);
//find closest player still in game and give focus
int min = MAX_PLAYERS;
int closest = 2;
for (int participantIndex : getParticipants()) {
final int diff = Math.abs(playerIndex - participantIndex);
if (diff < min) {
min = diff;
closest = participantIndex;
}
}
} }
public boolean isPlayerAI(int playernum) { public boolean isPlayerAI(int playernum) {
@@ -210,10 +205,6 @@ public class ConstructedScreen extends LaunchScreen {
return participants; return participants;
} }
@Override
protected void doLayoutAboveBtnStart(float startY, float width, float height) {
}
@Override @Override
protected boolean buildLaunchParams(LaunchParams launchParams) { protected boolean buildLaunchParams(LaunchParams launchParams) {
launchParams.gameType = GameType.Constructed; launchParams.gameType = GameType.Constructed;
@@ -325,6 +316,61 @@ public class ConstructedScreen extends LaunchScreen {
updateVariantControlsVisibility(); updateVariantControlsVisibility();
} }
@Override
protected void doLayout(float width, float height) {
float x = PADDING;
float y = PADDING;
float fieldHeight = txtPlayerName.getHeight();
float avatarSize = 2 * fieldHeight + PADDING;
avatarLabel.setBounds(x, y, avatarSize, avatarSize);
x += avatarSize + PADDING;
float w = width - x - fieldHeight - 2 * PADDING;
txtPlayerName.setBounds(x, y, w, fieldHeight);
x += w + PADDING;
nameRandomiser.setBounds(x, y, fieldHeight, fieldHeight);
y += fieldHeight + PADDING;
radioHuman.setHeight(fieldHeight); //must set height before width so icon is correct size
radioAi.setHeight(fieldHeight);
radioHuman.setWidth(radioHuman.getAutoSizeBounds().width);
radioAi.setWidth(radioAi.getAutoSizeBounds().width);
x = width - radioAi.getWidth();
radioAi.setPosition(x, y);
x -= radioHuman.getWidth() - PADDING;
radioHuman.setPosition(x, y);
w = x - avatarSize - 2 * PADDING;
x = avatarSize + 2 * PADDING;
teamComboBox.setBounds(x, y, w, fieldHeight);
y += fieldHeight + PADDING;
x = PADDING;
deckLabel.setBounds(x, y, avatarSize, fieldHeight);
x += avatarSize + PADDING;
w = width - x - PADDING;
deckBtn.setBounds(x, y, w, fieldHeight);
}
private float getPreferredHeight() {
int rows = 3;
if (vntArchenemy.isSelected()) {
rows++;
}
if (vntPlanechase.isSelected()) {
rows++;
}
if (vntVanguard.isSelected()) {
rows++;
}
return rows * (txtPlayerName.getHeight() + PADDING) + PADDING;
}
@Override
protected void drawOverlay(Graphics g) {
float y = getHeight();
g.drawLine(1, PLAYER_BORDER_COLOR, 0, y, getWidth(), y);
}
private final FEventHandler radioMouseAdapter = new FEventHandler() { private final FEventHandler radioMouseAdapter = new FEventHandler() {
@Override @Override
public void handleEvent(FEvent e) { public void handleEvent(FEvent e) {
@@ -350,12 +396,6 @@ public class ConstructedScreen extends LaunchScreen {
} }
}; };
@Override
protected void doLayout(float width, float height) {
// TODO Auto-generated method stub
}
private FEventHandler avatarCommand = new FEventHandler() { private FEventHandler avatarCommand = new FEventHandler() {
@Override @Override
public void handleEvent(FEvent e) { public void handleEvent(FEvent e) {
@@ -430,7 +470,7 @@ public class ConstructedScreen extends LaunchScreen {
aeTeamComboBox.setEnabled(playerIsArchenemy); aeTeamComboBox.setEnabled(playerIsArchenemy);
for (int i = 1; i <= MAX_PLAYERS; i++) { for (int i = 1; i <= MAX_PLAYERS; i++) {
teamComboBox.addItem(i); teamComboBox.addItem("Team " + i);
} }
teamComboBox.setSelectedIndex(teams.get(index) - 1); teamComboBox.setSelectedIndex(teams.get(index) - 1);
teamComboBox.setEnabled(true); teamComboBox.setEnabled(true);
@@ -691,7 +731,7 @@ public class ConstructedScreen extends LaunchScreen {
/** Adds a pre-styled FLabel component with the specified title. */ /** Adds a pre-styled FLabel component with the specified title. */
private FLabel newLabel(String title) { private FLabel newLabel(String title) {
return new FLabel.Builder().text(title).fontSize(14).build(); return new FLabel.Builder().text(title).fontSize(14).align(HAlignment.RIGHT).build();
} }
private List<Integer> getUsedAvatars() { private List<Integer> getUsedAvatars() {

View File

@@ -24,7 +24,7 @@ public class VStack extends FDropDown {
private static final float CARD_WIDTH = Utils.AVG_FINGER_WIDTH; private static final float CARD_WIDTH = Utils.AVG_FINGER_WIDTH;
private static final float CARD_HEIGHT = Math.round(CARD_WIDTH * FCardPanel.ASPECT_RATIO); private static final float CARD_HEIGHT = Math.round(CARD_WIDTH * FCardPanel.ASPECT_RATIO);
private static final FSkinFont FONT = FSkinFont.get(11); private static final FSkinFont FONT = FSkinFont.get(11);
private static final Color ALPHA_COMPOSITE = new Color(1, 1, 1, 0.5f); private static final float ALPHA_COMPOSITE = 0.5f;
private final MagicStack stack; private final MagicStack stack;
private final LobbyPlayer localPlayer; private final LobbyPlayer localPlayer;
@@ -104,7 +104,7 @@ public class VStack extends FDropDown {
private class StackInstanceDisplay extends FDisplayObject { private class StackInstanceDisplay extends FDisplayObject {
private final SpellAbilityStackInstance stackInstance; private final SpellAbilityStackInstance stackInstance;
private final boolean isTop; private final boolean isTop;
private FSkinColor foreColor, backColor; private final FSkinColor foreColor, backColor;
private String text; private String text;
private StackInstanceDisplay(SpellAbilityStackInstance stackInstance0, boolean isTop0) { private StackInstanceDisplay(SpellAbilityStackInstance stackInstance0, boolean isTop0) {
@@ -154,11 +154,6 @@ public class VStack extends FDropDown {
backColor = FSkinColor.get(Colors.CLR_OVERLAY); backColor = FSkinColor.get(Colors.CLR_OVERLAY);
foreColor = FSkinColor.get(Colors.CLR_TEXT); foreColor = FSkinColor.get(Colors.CLR_TEXT);
} }
if (!isTop) {
backColor = backColor.alphaColor(ALPHA_COMPOSITE.a);
foreColor = foreColor.alphaColor(ALPHA_COMPOSITE.a);
}
} }
private float getMinHeight(float width) { private float getMinHeight(float width) {
@@ -174,6 +169,10 @@ public class VStack extends FDropDown {
float w = getWidth(); float w = getWidth();
float h = getHeight(); float h = getHeight();
if (!isTop) {
g.setAlphaComposite(ALPHA_COMPOSITE);
}
g.fillRect(backColor, 0, 0, w, h); g.fillRect(backColor, 0, 0, w, h);
float padding = PADDING; float padding = PADDING;
@@ -182,16 +181,14 @@ public class VStack extends FDropDown {
float x = padding; float x = padding;
float y = padding; float y = padding;
if (!isTop) {
g.setImageTint(ALPHA_COMPOSITE);
}
g.drawImage(ImageCache.getImage(stackInstance.getSourceCard()), x, y, cardWidth, cardHeight); g.drawImage(ImageCache.getImage(stackInstance.getSourceCard()), x, y, cardWidth, cardHeight);
if (!isTop) {
g.clearImageTint();
}
x += cardWidth + padding; x += cardWidth + padding;
g.drawText(text, FONT, foreColor, x, y, w - x - padding, h - y - padding, true, HAlignment.LEFT, true); g.drawText(text, FONT, foreColor, x, y, w - x - padding, h - y - padding, true, HAlignment.LEFT, true);
if (!isTop) {
g.resetAlphaComposite();
}
} }
} }
} }

View File

@@ -2,7 +2,6 @@ package forge.toolbox;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment; import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
import forge.Forge.Graphics; import forge.Forge.Graphics;
@@ -15,8 +14,7 @@ import forge.toolbox.FEvent.FEventType;
public class FButton extends FDisplayObject { public class FButton extends FDisplayObject {
private static final FSkinColor FORE_COLOR = FSkinColor.get(Colors.CLR_TEXT); private static final FSkinColor FORE_COLOR = FSkinColor.get(Colors.CLR_TEXT);
private static final Color DISABLED_COMPOSITE = new Color(1, 1, 1, 0.25f); private static final float DISABLED_COMPOSITE = 0.25f;
private static final FSkinColor DISABLED_FORE_COLOR = FORE_COLOR.alphaColor(DISABLED_COMPOSITE.a);
private FSkinImage imgL, imgM, imgR; private FSkinImage imgL, imgM, imgR;
private String text; private String text;
@@ -155,11 +153,9 @@ public class FButton extends FDisplayObject {
float cornerTextOffsetX = cornerButtonWidth / 2; float cornerTextOffsetX = cornerButtonWidth / 2;
float cornerTextOffsetY = (cornerButtonHeight - h) / 2; float cornerTextOffsetY = (cornerButtonHeight - h) / 2;
FSkinColor foreColor = FORE_COLOR;
boolean disabled = !isEnabled(); boolean disabled = !isEnabled();
if (disabled) { if (disabled) {
g.setImageTint(DISABLED_COMPOSITE); g.setAlphaComposite(DISABLED_COMPOSITE);
foreColor = DISABLED_FORE_COLOR;
} }
//determine images to draw and text alignment based on which corner button is in (if any) //determine images to draw and text alignment based on which corner button is in (if any)
@@ -192,12 +188,12 @@ public class FButton extends FDisplayObject {
break; break;
} }
if (disabled) { if (!StringUtils.isEmpty(text)) {
g.clearImageTint(); g.drawText(text, font, FORE_COLOR, x, y, w, h, false, HAlignment.CENTER, true);
} }
if (!StringUtils.isEmpty(text)) { if (disabled) {
g.drawText(text, font, foreColor, x, y, w, h, false, HAlignment.CENTER, true); g.resetAlphaComposite();
} }
} }
} }

View File

@@ -18,7 +18,7 @@ public class FCheckBox extends FLabel {
this(text0, false); this(text0, false);
} }
public FCheckBox(String text0, boolean selected0) { public FCheckBox(String text0, boolean selected0) {
super(new Builder().align(HAlignment.LEFT).selectable().selected(selected0)); super(new Builder().text(text0).align(HAlignment.LEFT).selectable().selected(selected0));
setIcon(new CheckBoxIcon()); setIcon(new CheckBoxIcon());
} }
@@ -47,4 +47,9 @@ public class FCheckBox extends FLabel {
} }
} }
} }
@Override
public void draw(Graphics g) {
drawContent(g, getWidth(), getHeight(), false);
}
} }

View File

@@ -17,6 +17,7 @@ public class FLabel extends FDisplayObject {
//========== Default values for FLabel are set here. //========== Default values for FLabel are set here.
private float bldIconScaleFactor = 0.8f; private float bldIconScaleFactor = 0.8f;
private int bldFontSize = 14; private int bldFontSize = 14;
private float bldAlphaComposite = 0.7f;
private HAlignment bldAlignment = HAlignment.LEFT; private HAlignment bldAlignment = HAlignment.LEFT;
private Vector2 bldInsets = new Vector2(3, 3); private Vector2 bldInsets = new Vector2(3, 3);
@@ -48,6 +49,7 @@ public class FLabel extends FDisplayObject {
public Builder selected() { selected(true); return this; } public Builder selected() { selected(true); return this; }
public Builder command(final FEventHandler c0) { this.bldCommand = c0; return this; } public Builder command(final FEventHandler c0) { this.bldCommand = c0; return this; }
public Builder fontSize(final int i0) { this.bldFontSize = i0; return this; } public Builder fontSize(final int i0) { this.bldFontSize = i0; return this; }
public Builder alphaComposite(final float a0) { this.bldAlphaComposite = a0; return this; }
public Builder enabled(final boolean b0) { this.bldEnabled = b0; return this; } public Builder enabled(final boolean b0) { this.bldEnabled = b0; return this; }
public Builder iconScaleAuto(final boolean b0) { this.bldIconScaleAuto = b0; return this; } public Builder iconScaleAuto(final boolean b0) { this.bldIconScaleAuto = b0; return this; }
public Builder iconScaleFactor(final float f0) { this.bldIconScaleFactor = f0; return this; } public Builder iconScaleFactor(final float f0) { this.bldIconScaleFactor = f0; return this; }
@@ -75,6 +77,7 @@ public class FLabel extends FDisplayObject {
private float iconScaleFactor; private float iconScaleFactor;
private FSkinFont font; private FSkinFont font;
private float alphaComposite;
private HAlignment alignment; private HAlignment alignment;
private Vector2 insets; private Vector2 insets;
private boolean selectable, selected, opaque, iconInBackground, iconScaleAuto, pressed; private boolean selectable, selected, opaque, iconInBackground, iconScaleAuto, pressed;
@@ -88,6 +91,7 @@ public class FLabel extends FDisplayObject {
protected FLabel(final Builder b0) { protected FLabel(final Builder b0) {
iconScaleFactor = b0.bldIconScaleFactor; iconScaleFactor = b0.bldIconScaleFactor;
font = FSkinFont.get(b0.bldFontSize); font = FSkinFont.get(b0.bldFontSize);
alphaComposite = b0.bldAlphaComposite;
alignment = b0.bldAlignment; alignment = b0.bldAlignment;
insets = b0.bldInsets; insets = b0.bldInsets;
selectable = b0.bldSelectable; selectable = b0.bldSelectable;
@@ -184,7 +188,7 @@ public class FLabel extends FDisplayObject {
bounds.height += 2 * insets.y; bounds.height += 2 * insets.y;
if (icon != null) { if (icon != null) {
bounds.width += icon.getWidth(); bounds.width += icon.getWidth() + insets.x;
} }
return bounds; return bounds;
@@ -196,6 +200,11 @@ public class FLabel extends FDisplayObject {
float h = getHeight(); float h = getHeight();
g.startClip(0, 0, w, h); //start clip to ensure nothing escapes bounds g.startClip(0, 0, w, h); //start clip to ensure nothing escapes bounds
boolean applyAlphaComposite = (opaque && !pressed);
if (applyAlphaComposite) {
g.setAlphaComposite(alphaComposite);
}
if (pressed) { if (pressed) {
if (pressedColor != null) { if (pressedColor != null) {
@@ -220,6 +229,10 @@ public class FLabel extends FDisplayObject {
drawContent(g, w, h, pressed); drawContent(g, w, h, pressed);
if (applyAlphaComposite) {
g.resetAlphaComposite();
}
g.endClip(); g.endClip();
} }
@@ -249,14 +262,19 @@ public class FLabel extends FDisplayObject {
y += (h - iconHeight) / 2; y += (h - iconHeight) / 2;
} }
else { else {
x = 0; //TODO: calculation these //TODO: Calculate these for center/right alignment
y = 0; y += (h - iconHeight) / 2;
} }
g.drawImage(icon, x, y, iconWidth, iconHeight); g.drawImage(icon, x, y, iconWidth, iconHeight);
if (!text.isEmpty()) { if (!text.isEmpty()) {
x += iconWidth; y = insets.y;
if (pressed) {
y++;
}
x += iconWidth + insets.x;
w -= iconWidth + insets.x;
g.startClip(x, y, w, h); g.startClip(x, y, w, h);
g.drawText(text, font, textColor, x, y, w, h, false, HAlignment.LEFT, true); g.drawText(text, font, textColor, x, y, w, h, false, HAlignment.LEFT, true);
g.endClip(); g.endClip();

View File

@@ -23,7 +23,7 @@ public class FRadioButton extends FLabel {
this(text0, false); this(text0, false);
} }
public FRadioButton(String text0, boolean selected0) { public FRadioButton(String text0, boolean selected0) {
super(new Builder().align(HAlignment.LEFT).selectable().selected(selected0)); super(new Builder().text(text0).align(HAlignment.LEFT).selectable().selected(selected0));
setIcon(new RadioButtonIcon()); setIcon(new RadioButtonIcon());
} }
@@ -67,9 +67,9 @@ public class FRadioButton extends FLabel {
@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) {
float radius = h / 5; float radius = h / 3;
x += w - radius; x += w / 2;
y = h / 2; y += h / 2;
g.drawCircle(1, OUTER_CIRCLE_COLOR, x, y, radius); g.drawCircle(1, OUTER_CIRCLE_COLOR, x, y, radius);
if (isSelected()) { if (isSelected()) {
g.fillCircle(INNER_CIRCLE_COLOR, x, y, radius / 2); g.fillCircle(INNER_CIRCLE_COLOR, x, y, radius / 2);
@@ -77,6 +77,11 @@ public class FRadioButton extends FLabel {
} }
} }
@Override
public void draw(Graphics g) {
drawContent(g, getWidth(), getHeight(), false);
}
public static class RadioButtonGroup { public static class RadioButtonGroup {
private final List<FRadioButton> buttons = new ArrayList<FRadioButton>(); private final List<FRadioButton> buttons = new ArrayList<FRadioButton>();
} }

View File

@@ -9,8 +9,9 @@ import forge.assets.FSkinColor.Colors;
import forge.toolbox.FEvent.FEventHandler; import forge.toolbox.FEvent.FEventHandler;
public class FTextField extends FDisplayObject { public class FTextField extends FDisplayObject {
private static final float PADDING = 3; private static final float PADDING = 5;
private static final FSkinColor FORE_COLOR = FSkinColor.get(Colors.CLR_TEXT); private static final FSkinColor FORE_COLOR = FSkinColor.get(Colors.CLR_TEXT);
private static final FSkinColor BACK_COLOR = FSkinColor.get(Colors.CLR_THEME2);
private FEventHandler changedHandler; private FEventHandler changedHandler;
private String text; private String text;
@@ -22,7 +23,7 @@ public class FTextField extends FDisplayObject {
} }
public FTextField(String text0) { public FTextField(String text0) {
text = text0; text = text0;
font = FSkinFont.get(14); setFontSize(14);
alignment = HAlignment.LEFT; alignment = HAlignment.LEFT;
} }
@@ -42,6 +43,7 @@ public class FTextField extends FDisplayObject {
public void setFontSize(int fontSize0) { public void setFontSize(int fontSize0) {
font = FSkinFont.get(fontSize0); font = FSkinFont.get(fontSize0);
setHeight(font.getFont().getCapHeight() * 3);
} }
public FEventHandler getChangedHandler() { public FEventHandler getChangedHandler() {
@@ -59,6 +61,10 @@ public class FTextField extends FDisplayObject {
@Override @Override
public void draw(Graphics g) { public void draw(Graphics g) {
g.drawText(text, font, FORE_COLOR, PADDING, 0, getWidth() - 2 * PADDING, getHeight(), false, alignment, true); float w = getWidth();
float h = getHeight();
g.fillRect(BACK_COLOR, 0, 0, w, h);
g.drawText(text, font, FORE_COLOR, PADDING, 0, w - 2 * PADDING, h, false, alignment, true);
g.drawRect(1, FORE_COLOR, 1, 1, w - 2, h - 2); //allow smooth border to fully display within bounds
} }
} }