Improve scaling for certain UI elements

This commit is contained in:
drdev
2014-05-10 23:20:30 +00:00
parent 4f59dfd0b8
commit 0934e1e831
10 changed files with 44 additions and 29 deletions

View File

@@ -41,6 +41,7 @@ import forge.util.Aggregates;
import forge.util.ItemPool;
import forge.util.LayoutHelper;
import forge.util.ReflectionUtil;
import forge.util.Utils;
import java.util.*;
import java.util.Map.Entry;
@@ -281,29 +282,29 @@ public abstract class ItemManager<T extends InventoryItem> extends FContainer im
}
helper.newLine(ItemFilter.PADDING);
float fieldHeight = mainSearchFilter.getMainComponent().getHeight();
helper.include(btnFilters, 61, fieldHeight);
helper.include(btnFilters, btnFilters.getAutoSizeBounds().width * 1.2f, fieldHeight);
float captionWidth = lblCaption.getAutoSizeBounds().width;
float ratioWidth = lblRatio.getAutoSizeBounds().width;
float viewButtonWidth = fieldHeight;
float viewButtonCount = views.size() + 1;
float viewButtonCount = views.size() + Utils.scaleX(1);
float availableCaptionWidth = helper.getParentWidth() - viewButtonWidth * viewButtonCount - ratioWidth - helper.getX() - (viewButtonCount + 1) * helper.getGapX();
if (captionWidth > availableCaptionWidth) { //truncate caption if not enough room for it
captionWidth = availableCaptionWidth;
}
helper.offset(0, 1); //shift caption downward
helper.offset(0, Utils.scaleY(1)); //shift caption downward
helper.include(lblCaption, captionWidth, fieldHeight);
helper.offset(-helper.getGapX(), 0);
helper.fillLine(lblRatio, fieldHeight, (viewButtonWidth + helper.getGapX()) * viewButtonCount - viewButtonCount + 1); //leave room for view buttons
helper.offset(0, -1); //shift buttons upward
helper.offset(0, Utils.scaleY(1)); //shift buttons upward
for (ItemView<T> view : views) {
helper.include(view.getButton(), viewButtonWidth, fieldHeight);
helper.offset(-1, 0);
helper.offset(Utils.scaleX(-1), 0);
}
helper.include(btnViewOptions, viewButtonWidth, fieldHeight);
helper.newLine(2);
helper.newLine(Utils.scaleY(2));
if (currentView.getPnlOptions().isVisible()) {
helper.fillLine(currentView.getPnlOptions(), fieldHeight + 4);
helper.newLine(3);
helper.fillLine(currentView.getPnlOptions(), fieldHeight + Utils.scaleY(4));
helper.newLine(Utils.scaleY(3));
}
helper.fill(currentView.getScroller());
}

View File

@@ -12,7 +12,7 @@ import forge.util.Utils;
public abstract class ItemFilter<T extends InventoryItem> {
public static final float PADDING = Utils.scaleY(3);
public static final float PADDING = Utils.scaleMax(3);
public static final int DEFAULT_FONT_SIZE = 11;
public static final float PANEL_HEIGHT = FTextField.getDefaultHeight(DEFAULT_FONT_SIZE) + PADDING;

View File

@@ -32,13 +32,12 @@ public abstract class ToggleButtonsFilter<T extends InventoryItem> extends ItemF
@Override
protected void doWidgetLayout(LayoutHelper helper) {
float availableWidth = helper.getParentWidth() - (buttons.size() - 1) * (helper.getGapX() - 1); //account for gaps
float availableWidth = helper.getParentWidth() - (buttons.size() - 1) * helper.getGapX(); //account for gaps
float buttonWidth = availableWidth / buttons.size();
float buttonHeight = helper.getParentHeight();
for (FLabel btn : buttons) {
helper.include(btn, buttonWidth, buttonHeight);
helper.offset(-1, 0); //keep buttons tighter together
}
}

View File

@@ -16,7 +16,6 @@ import forge.toolbox.FEvent.FEventHandler;
import forge.toolbox.FEvent.FEventType;
import forge.toolbox.FLabel;
import forge.toolbox.FScrollPane;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

View File

@@ -14,6 +14,7 @@ import forge.assets.FSkinImage;
import forge.game.GameType;
import forge.game.player.RegisteredPlayer;
import forge.toolbox.FDisplayObject;
import forge.util.Utils;
public abstract class LaunchScreen extends FScreen {
private final StartButton btnStart;
@@ -26,8 +27,9 @@ public abstract class LaunchScreen extends FScreen {
@Override
protected final void doLayout(float startY, float width, float height) {
float imageWidth = FSkinImage.BTN_START_UP.getWidth();
float imageHeight = FSkinImage.BTN_START_UP.getHeight();
float baseImageHeight = FSkinImage.BTN_START_UP.getHeight();
float imageHeight = FSkinImage.BTN_START_UP.getNearestHQHeight(Utils.AVG_FINGER_HEIGHT);
float imageWidth = FSkinImage.BTN_START_UP.getWidth() * imageHeight / baseImageHeight;
float padding = imageHeight * 0.025f;
btnStart.setBounds((width - imageWidth) / 2, height - imageHeight - padding, imageWidth, imageHeight);

View File

@@ -71,18 +71,19 @@ public class SplashScreen extends FContainer {
}
g.drawImage(background, x, y, w, h);
y += h * 300f / 450f;
y += h * 295f / 450f;
if (disclaimerFont == null) {
disclaimerFont = FSkinFont.get(9);
}
float disclaimerHeight = 30f / 450f * h;
String disclaimer = "Forge is not affiliated in any way with Wizards of the Coast.\n"
+ "Forge is open source software, released under the GNU Public License.";
g.drawText(disclaimer, disclaimerFont, FProgressBar.SEL_FORE_COLOR,
x, y, w, 0, true, HAlignment.CENTER, false);
x, y, w, disclaimerHeight, true, HAlignment.CENTER, true);
float padding = 20f / 450f * w;
float pbHeight = 57f / 450f * h;
y += 73f / 450f * h;
y += 78f / 450f * h;
progressBar.setBounds(x + padding, y, w - 2 * padding, pbHeight);
g.draw(progressBar);
}

View File

@@ -12,6 +12,7 @@ import forge.assets.FSkinFont;
import forge.interfaces.IButton;
import forge.toolbox.FEvent.FEventHandler;
import forge.toolbox.FEvent.FEventType;
import forge.util.Utils;
public class FLabel extends FDisplayObject implements IButton {
public static class Builder {
@@ -20,7 +21,7 @@ public class FLabel extends FDisplayObject implements IButton {
private int bldFontSize = 14;
private float bldAlphaComposite = 0.7f;
private HAlignment bldAlignment = HAlignment.LEFT;
private Vector2 bldInsets = new Vector2(3, 3);
private Vector2 bldInsets = new Vector2(Utils.scaleX(3), Utils.scaleY(3));
private boolean bldSelectable = false;
private boolean bldSelected = false;
@@ -75,6 +76,7 @@ public class FLabel extends FDisplayObject implements IButton {
private static final FSkinColor d10 = clrMain.stepColor(-10);
private static final FSkinColor l10 = clrMain.stepColor(10);
private static final FSkinColor l20 = clrMain.stepColor(20);
private static final float BORDER_THICKNESS = Utils.scaleMin(1);
private float iconScaleFactor;
private FSkinFont font;
@@ -221,19 +223,19 @@ public class FLabel extends FDisplayObject implements IButton {
}
else {
g.fillGradientRect(d50, d10, true, 0, 0, w, h);
g.drawRect(1, d50, 0, 0, w, h);
g.drawRect(BORDER_THICKNESS, d50, 0, 0, w, h);
}
}
else if (selected && (opaque || selectable)) {
g.fillGradientRect(d30, l10, true, 0, 0, w, h);
g.drawRect(1, d30, 0, 0, w, h);
g.drawRect(BORDER_THICKNESS, d30, 0, 0, w, h);
}
else if (opaque) {
g.fillGradientRect(d10, l20, true, 0, 0, w, h);
g.drawRect(1, d10, 0, 0, w, h);
g.drawRect(BORDER_THICKNESS, d10, 0, 0, w, h);
}
else if (selectable) {
g.drawRect(1, l10, 0, 0, w, h);
g.drawRect(BORDER_THICKNESS, l10, 0, 0, w, h);
}
drawContent(g, w, h, pressed);

View File

@@ -15,6 +15,7 @@ import forge.util.Utils;
public class FTextField extends FDisplayObject {
private static final int DEFAULT_FONT_SIZE = 14;
private static final float BORDER_THICKNESS = Utils.scaleX(1);
protected static final float PADDING = Utils.scaleX(5);
protected static final FSkinColor FORE_COLOR = FSkinColor.get(Colors.CLR_TEXT);
protected static final FSkinColor BACK_COLOR = FSkinColor.get(Colors.CLR_THEME2);
@@ -301,7 +302,7 @@ public class FTextField extends FDisplayObject {
float selHeight = h - 2 * PADDING;
if (selLength == 0) {
drawText(g, w, h); //draw text behind cursor
g.drawLine(1, FORE_COLOR, selLeft, selTop, selLeft, selTop + selHeight);
g.drawLine(BORDER_THICKNESS, FORE_COLOR, selLeft, selTop, selLeft, selTop + selHeight);
}
else if (selStart == 0 && selLength == text.length()) {
float selWidth = font.getFont().getBounds(text.substring(selStart, selStart + selLength)).width;
@@ -313,7 +314,7 @@ public class FTextField extends FDisplayObject {
drawText(g, w, h);
}
g.drawRect(1, FORE_COLOR, 1, 1, w - 2, h - 2); //allow smooth border to fully display within bounds
g.drawRect(BORDER_THICKNESS, FORE_COLOR, BORDER_THICKNESS, BORDER_THICKNESS, w - 2 * BORDER_THICKNESS, h - 2 * BORDER_THICKNESS); //allow smooth border to fully display within bounds
}
private void drawText(Graphics g, float w, float h) {

View File

@@ -15,6 +15,7 @@ public class FToggleSwitch extends FDisplayObject {
private static final FSkinColor PRESSED_COLOR = ACTIVE_COLOR.stepColor(-30);
private static final FSkinColor INACTIVE_COLOR = FSkinColor.get(Colors.CLR_INACTIVE);
private static final FSkinColor FORE_COLOR = FSkinColor.get(Colors.CLR_TEXT);
private static final float BORDER_THICKNESS = Utils.scaleMin(1);
private static final float INSETS = Utils.scaleMin(2);
private static final float PADDING = Utils.scaleMin(3);
@@ -128,13 +129,13 @@ public class FToggleSwitch extends FDisplayObject {
@Override
public void draw(Graphics g) {
float x = 1; //leave a pixel so border displays in full
float y = 1;
float x = BORDER_THICKNESS; //leave a pixel so border displays in full
float y = BORDER_THICKNESS;
float w = getWidth() - 2 * x;
float h = getHeight() - 2 * x;
float h = getHeight() - 2 * y;
g.fillRect(INACTIVE_COLOR, x, y, w, h);
g.drawRect(1, FORE_COLOR, x, y, w, h);
g.drawRect(BORDER_THICKNESS, FORE_COLOR, x, y, w, h);
final String text;
float switchWidth = w - h + PADDING;

View File

@@ -2,6 +2,8 @@ package forge.util;
import com.badlogic.gdx.Gdx;
import forge.Forge;
public class Utils {
private static final float ppcX = Gdx.graphics.getPpcX();
private static final float ppcY = Gdx.graphics.getPpcY();
@@ -16,6 +18,13 @@ public class Utils {
public static final float MIN_RATIO = Math.min(WIDTH_RATIO, HEIGHT_RATIO);
public static final float MAX_RATIO = Math.max(WIDTH_RATIO, HEIGHT_RATIO);
static {
Forge.debugPrint("width: " + BASE_WIDTH);
Forge.debugPrint("height: " + BASE_HEIGHT);
Forge.debugPrint("width-ratio: " + WIDTH_RATIO);
Forge.debugPrint("height-ratio: " + HEIGHT_RATIO);
}
public static float cmToPixelsX(float cm) {
return ppcX * cm;
}