From 849e7acbf370bd83256fa2bd8ea0f1fa808a8c67 Mon Sep 17 00:00:00 2001 From: drdev Date: Fri, 23 May 2014 11:05:30 +0000 Subject: [PATCH] Fix some scaling issues --- .../src/forge/itemmanager/ItemManager.java | 33 ++++++----------- .../itemmanager/filters/CardSearchFilter.java | 9 ++--- .../forge/itemmanager/views/ImageView.java | 37 ++++++++++++------- .../src/forge/toolbox/FLabel.java | 4 +- 4 files changed, 41 insertions(+), 42 deletions(-) diff --git a/forge-gui-mobile/src/forge/itemmanager/ItemManager.java b/forge-gui-mobile/src/forge/itemmanager/ItemManager.java index 698b57c3dd7..a5da9047a44 100644 --- a/forge-gui-mobile/src/forge/itemmanager/ItemManager.java +++ b/forge-gui-mobile/src/forge/itemmanager/ItemManager.java @@ -61,6 +61,7 @@ public abstract class ItemManager extends FContainer im private FEventHandler selectionChangedHandler, itemActivateHandler; private final Class genericType; private ItemManagerConfig config; + private String caption, ratio; private final ItemFilter mainSearchFilter; @@ -73,11 +74,6 @@ public abstract class ItemManager extends FContainer im .fontSize(12) .build(); - private final FLabel lblRatio = new FLabel.Builder() - .align(HAlignment.LEFT) - .fontSize(12) - .build(); - private static final FSkinImage VIEW_OPTIONS_ICON = FSkinImage.SETTINGS; private final FLabel btnViewOptions = new FLabel.Builder() .selectable(true).align(HAlignment.CENTER) @@ -121,7 +117,6 @@ public abstract class ItemManager extends FContainer im add(mainSearchFilter.getPanel()); add(btnFilters); add(lblCaption); - add(lblRatio); for (ItemView view : views) { add(view.getButton()); view.getButton().setSelected(view == currentView); @@ -283,19 +278,9 @@ public abstract class ItemManager extends FContainer im helper.newLine(ItemFilter.PADDING); float fieldHeight = mainSearchFilter.getMainComponent().getHeight(); 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() + 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, 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, Utils.scaleY(1)); //shift buttons upward + helper.fillLine(lblCaption, fieldHeight, (viewButtonWidth + helper.getGapX()) * viewButtonCount - viewButtonCount + 1); //leave room for view buttons for (ItemView view : views) { helper.include(view.getButton(), viewButtonWidth, fieldHeight); helper.offset(Utils.scaleX(-1), 0); @@ -326,7 +311,7 @@ public abstract class ItemManager extends FContainer im * @return caption to display before ratio */ public String getCaption() { - return lblCaption.getText(); + return caption; } /** @@ -335,8 +320,13 @@ public abstract class ItemManager extends FContainer im * * @param caption - caption to display before ratio */ - public void setCaption(String caption) { - lblCaption.setText(caption); + public void setCaption(String caption0) { + caption = caption0; + updateCaptionLabel(); + } + + private void updateCaptionLabel() { + lblCaption.setText(caption + " " + ratio); } /** @@ -916,7 +906,8 @@ public abstract class ItemManager extends FContainer im else { total = pool.countAll(); } - lblRatio.setText("(" + getFilteredItems().countAll() + " / " + total + ")"); + ratio = "(" + getFilteredItems().countAll() + " / " + total + ")"; + updateCaptionLabel(); } /** diff --git a/forge-gui-mobile/src/forge/itemmanager/filters/CardSearchFilter.java b/forge-gui-mobile/src/forge/itemmanager/filters/CardSearchFilter.java index 49b8503d657..ab3d55bb61d 100644 --- a/forge-gui-mobile/src/forge/itemmanager/filters/CardSearchFilter.java +++ b/forge-gui-mobile/src/forge/itemmanager/filters/CardSearchFilter.java @@ -68,19 +68,18 @@ public class CardSearchFilter extends TextSearchFilter { @Override protected void doWidgetLayout(LayoutHelper helper) { - final float comboBoxWidth = 61; - final float buttonWidth = 51; + final float buttonWidth = Math.max(Math.max(btnName.getAutoSizeBounds().width, btnType.getAutoSizeBounds().width), btnText.getAutoSizeBounds().width); final float height = helper.getParentHeight(); - helper.fillLine(txtSearch, height, comboBoxWidth + buttonWidth * 3 + helper.getGapX() * 4); //leave space for combo box and buttons - helper.include(cbSearchMode, comboBoxWidth, height); + helper.fillLine(txtSearch, height, (buttonWidth + helper.getGapX()) * 4); //leave space for combo box and buttons + helper.include(cbSearchMode, buttonWidth, height); //use button width for combo box too helper.include(btnName, buttonWidth, height); helper.include(btnType, buttonWidth, height); helper.include(btnText, buttonWidth, height); } private FLabel addButton(Widget widget, String text) { - FLabel button = new FLabel.Builder().text(text).align(HAlignment.CENTER) + FLabel button = new FLabel.Builder().text(text).fontSize(txtSearch.getFontSize()).align(HAlignment.CENTER) .selectable().selected().command(new FEventHandler() { @Override public void handleEvent(FEvent e) { diff --git a/forge-gui-mobile/src/forge/itemmanager/views/ImageView.java b/forge-gui-mobile/src/forge/itemmanager/views/ImageView.java index 673772dfb77..2c7f9454955 100644 --- a/forge-gui-mobile/src/forge/itemmanager/views/ImageView.java +++ b/forge-gui-mobile/src/forge/itemmanager/views/ImageView.java @@ -101,27 +101,36 @@ public class ImageView extends ItemView { @Override protected void drawContent(Graphics g, float w, float h, final boolean pressed) { - float squareSize = w / 2 - 2; - float offset = 2; - float x = (w - squareSize) / 2 - offset; - float y = (h - squareSize) / 2 - offset; - if (!pressed) { - x--; - y--; + float lineThickness = Utils.scaleMin(1); + float offset = 2 * lineThickness; + float squareSize = Math.round(w / 2 - offset); + if (squareSize % 2 == 1) { + squareSize++; //needs to be even number for this to look right + } + float x = Math.round((w - squareSize) / 2 - offset); + float y = Math.round((h - squareSize) / 2 - offset); + if (pressed) { + y += lineThickness; + } + else { + x -= lineThickness; } for (int i = 0; i < 2; i++) { - g.drawLine(1, GROUP_HEADER_FORE_COLOR, x, y, x + squareSize, y); - g.drawLine(1, GROUP_HEADER_FORE_COLOR, x + squareSize, y, x + squareSize, y + offset); - g.drawLine(1, GROUP_HEADER_FORE_COLOR, x, y, x, y + squareSize); - g.drawLine(1, GROUP_HEADER_FORE_COLOR, x, y + squareSize, x + offset, y + squareSize); + g.drawLine(lineThickness, GROUP_HEADER_FORE_COLOR, x, y, x + squareSize, y); + g.drawLine(lineThickness, GROUP_HEADER_FORE_COLOR, x + squareSize, y, x + squareSize, y + offset); + g.drawLine(lineThickness, GROUP_HEADER_FORE_COLOR, x, y, x, y + squareSize); + g.drawLine(lineThickness, GROUP_HEADER_FORE_COLOR, x, y + squareSize, x + offset, y + squareSize); x += offset; y += offset; } - g.drawRect(1, GROUP_HEADER_FORE_COLOR, x, y, squareSize, squareSize); - g.drawLine(1, GROUP_HEADER_FORE_COLOR, x + offset + 1, y + squareSize / 2, x + squareSize - 2 * offset + 1, y + squareSize / 2); + g.drawLine(lineThickness, GROUP_HEADER_FORE_COLOR, x, y, x + squareSize, y); + g.drawLine(lineThickness, GROUP_HEADER_FORE_COLOR, x + squareSize, y, x + squareSize, y + squareSize); + g.drawLine(lineThickness, GROUP_HEADER_FORE_COLOR, x, y, x, y + squareSize); + g.drawLine(lineThickness, GROUP_HEADER_FORE_COLOR, x, y + squareSize, x + squareSize, y + squareSize); + g.drawLine(lineThickness, GROUP_HEADER_FORE_COLOR, x + offset + 1, y + squareSize / 2, x + squareSize - offset, y + squareSize / 2); if (isAllCollapsed) { - g.drawLine(1, GROUP_HEADER_FORE_COLOR, x + squareSize / 2, y + offset + 1, x + squareSize / 2, y + squareSize - 2 * offset + 1); + g.drawLine(lineThickness, GROUP_HEADER_FORE_COLOR, x + squareSize / 2, y + offset, x + squareSize / 2, y + squareSize - offset - 1); } } } diff --git a/forge-gui-mobile/src/forge/toolbox/FLabel.java b/forge-gui-mobile/src/forge/toolbox/FLabel.java index ebbb20e9b1d..12fb7633036 100644 --- a/forge-gui-mobile/src/forge/toolbox/FLabel.java +++ b/forge-gui-mobile/src/forge/toolbox/FLabel.java @@ -253,8 +253,8 @@ public class FLabel extends FDisplayObject implements IButton { w -= 2 * x; h -= 2 * x; if (pressed) { //while pressed, translate graphics so icon and text appear shifted down and to the right - x++; - y++; + x += Utils.scaleX(1); + y += Utils.scaleY(1); } if (icon != null) {