Start working on Landscape home screen layout

This commit is contained in:
drdev
2015-05-06 01:21:53 +00:00
parent 4a09b1ef92
commit 9697bd298d
5 changed files with 104 additions and 4 deletions

View File

@@ -217,6 +217,10 @@ public class Forge implements ApplicationListener {
});
}
public static boolean isLandscapeMode() {
return screenWidth > screenHeight;
}
public static int getScreenWidth() {
return screenWidth;
}

View File

@@ -76,7 +76,10 @@ public abstract class FScreen extends FContainer {
@Override
protected final void doLayout(float width, float height) {
if (header != null) {
if (width > height) { //handle landscape layout special
doLandscapeLayout(width, height);
}
else if (header != null) {
header.setBounds(0, 0, width, header.getPreferredHeight());
doLayout(header.getHeight(), width, height);
}
@@ -87,6 +90,10 @@ public abstract class FScreen extends FContainer {
protected abstract void doLayout(float startY, float width, float height);
protected void doLandscapeLayout(float width, float height) {
doLayout(0, width, height); //just use normal doLayout function by default
}
@Override
protected void drawBackground(Graphics g) {
float w = getWidth();

View File

@@ -2,8 +2,13 @@ package forge.screens.home;
import java.util.ArrayList;
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
import forge.Forge;
import forge.Graphics;
import forge.screens.FScreen;
import forge.assets.FSkinColor;
import forge.assets.FSkinColor.Colors;
import forge.assets.FSkinImage;
import forge.deck.FDeckChooser;
import forge.game.GameType;
@@ -18,9 +23,13 @@ import forge.util.Utils;
public class HomeScreen extends FScreen {
private static final float PADDING = Utils.scale(5);
private static final FSkinColor clrTheme = FSkinColor.get(Colors.CLR_THEME);
private static final FSkinColor l00 = clrTheme.stepColor(0);
private static final FSkinColor d80 = clrTheme.stepColor(-80);
private static final float MAIN_MENU_WIDTH_FACTOR = 0.35f;
private final FLabel lblLogo = add(new FLabel.Builder().icon(FSkinImage.LOGO).iconInBackground().iconScaleFactor(1).build());
private final ArrayList<FButton> buttons = new ArrayList<FButton>();
private final ArrayList<MenuButton> buttons = new ArrayList<MenuButton>();
private FDeckChooser deckManager;
public HomeScreen() {
@@ -69,7 +78,7 @@ public class HomeScreen extends FScreen {
}
private void addButton(String caption, FEventHandler command) {
buttons.add(add(new FButton(caption, command)));
buttons.add(add(new MenuButton(caption, command)));
}
@Override
@@ -94,4 +103,80 @@ public class HomeScreen extends FScreen {
x = (width - logoSize) / 2;
lblLogo.setBounds(x, y, logoSize, logoSize);
}
@Override
protected void doLandscapeLayout(float width, float height) {
float mainMenuWidth = height * MAIN_MENU_WIDTH_FACTOR;
float logoSize = mainMenuWidth - 2 * PADDING;
lblLogo.setBounds(PADDING, PADDING, logoSize, logoSize);
float x = 2 * PADDING;
float y = lblLogo.getBottom() + PADDING;
float buttonWidth = mainMenuWidth - x;
float buttonHeight = Utils.AVG_FINGER_HEIGHT * 0.9f;
for (MenuButton button : buttons) {
button.setBounds(x, y, buttonWidth, buttonHeight);
y += buttonHeight;
}
}
@Override
protected void drawBackground(Graphics g) {
super.drawBackground(g);
//handle drawing main menu background for Landscape mode
float w = getWidth();
float h = getHeight();
if (w > h) {
float y1 = 0;
float y2 = 0;
float h1 = h;
float h2 = 0;
w = h * MAIN_MENU_WIDTH_FACTOR;
/*if (lblSelected.isShowing()) {
int scrollPanelTop = scrollPanel.getY();
int labelTop = lblSelected.getY() + lblSelected.getParent().getY() + scrollPanelTop - scrollPanel.getVerticalScrollBar().getValue();
y2 = labelTop + lblSelected.getHeight();
//ensure clipped to scroll panel
if (y2 > scrollPanelTop) {
if (labelTop < scrollPanelTop) {
labelTop = scrollPanelTop;
}
h2 = h1 - y2;
h1 = labelTop - y1;
}
}*/
float w1 = w * 0.66f;
float w2 = w - w1;
g.fillRect(l00, 0, y1, w1, h1);
if (h2 > 0) {
g.fillRect(l00, 0, y2, w1, h2);
}
g.fillGradientRect(l00, d80, false, w1, y1, w2, h1);
if (h2 > 0) {
g.fillGradientRect(l00, d80, false, w1, y2, w2, h2);
}
}
}
private class MenuButton extends FButton {
public MenuButton(String caption, FEventHandler command) {
super(caption, command);
}
@Override
public void draw(Graphics g) {
if (Forge.isLandscapeMode()) {
//draw text only for Landscape mode
g.drawText(getText(), getFont(), getForeColor(), 0, 0, getWidth(), getHeight(), false, HAlignment.LEFT, true);
}
else { //draw buttons normally for portrait mode
super.draw(g);
}
}
}
}

View File

@@ -288,4 +288,8 @@ public class FButton extends FDisplayObject implements IButton {
public void setTextColor(int r, int g, int b) {
foreColor = FSkinColor.getStandardColor(r, g, b);
}
public FSkinColor getForeColor() {
return foreColor;
}
}

View File

@@ -5,7 +5,7 @@ import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
public class Utils {
public static final boolean DEV_SCREEN_LANDSCAPE = false;
public static final boolean DEV_SCREEN_LANDSCAPE = true;
public static final float BASE_WIDTH = 320f;
public static final float BASE_HEIGHT = 480f;