From 00db8ef1dcc357a8d1f8b71d051152f0c78c8948 Mon Sep 17 00:00:00 2001 From: drdev Date: Tue, 15 Apr 2014 05:13:04 +0000 Subject: [PATCH] Support moving dialogs around by dragging titlebar --- .../src/forge/toolbox/FContainer.java | 4 +- .../src/forge/toolbox/FDialog.java | 61 +++++++++++++++++-- 2 files changed, 58 insertions(+), 7 deletions(-) diff --git a/forge-gui-mobile/src/forge/toolbox/FContainer.java b/forge-gui-mobile/src/forge/toolbox/FContainer.java index 31dd7e9632f..b03367a1b1c 100644 --- a/forge-gui-mobile/src/forge/toolbox/FContainer.java +++ b/forge-gui-mobile/src/forge/toolbox/FContainer.java @@ -49,11 +49,13 @@ public abstract class FContainer extends FDisplayObject { @Override public void setBounds(float x, float y, float width, float height) { super.setBounds(x, y, width, height); - doLayout(width, height); + doLayout(width, height); //always re-do layout when setBounds used } @Override public void setSize(float width, float height) { + if (getWidth() == width && getHeight() == height) { return; } + super.setSize(width, height); doLayout(width, height); } diff --git a/forge-gui-mobile/src/forge/toolbox/FDialog.java b/forge-gui-mobile/src/forge/toolbox/FDialog.java index e3217d696b8..6f56ab38413 100644 --- a/forge-gui-mobile/src/forge/toolbox/FDialog.java +++ b/forge-gui-mobile/src/forge/toolbox/FDialog.java @@ -16,11 +16,11 @@ public abstract class FDialog extends FOverlay { private static final float TITLE_HEIGHT = Math.round(Utils.AVG_FINGER_HEIGHT * 0.6f); private static float INSETS = 10; - private FLabel lblTitlebar; + private Titlebar lblTitlebar; private float totalHeight; protected FDialog(String title) { - lblTitlebar = add(new FLabel.Builder().text(title).icon(FSkinImage.FAVICON).fontSize(12).align(HAlignment.LEFT).build()); + lblTitlebar = add(new Titlebar(title)); } @Override @@ -49,9 +49,9 @@ public abstract class FDialog extends FOverlay { protected void drawBackground(Graphics g) { super.drawBackground(g); - float x = INSETS; + float x = lblTitlebar.getLeft(); float y = lblTitlebar.getTop(); - float w = getWidth() - 2 * x; + float w = lblTitlebar.getWidth(); float h = totalHeight; g.drawImage(FSkinTexture.BG_TEXTURE, x, y, w, h); g.fillRect(FScreen.TEXTURE_OVERLAY_COLOR, x, y, w, h); @@ -62,9 +62,9 @@ public abstract class FDialog extends FOverlay { @Override protected void drawOverlay(Graphics g) { - float x = INSETS; + float x = lblTitlebar.getLeft(); float y = lblTitlebar.getTop(); - float w = getWidth() - 2 * x; + float w = lblTitlebar.getWidth(); float h = totalHeight; //draw border around dialog @@ -74,4 +74,53 @@ public abstract class FDialog extends FOverlay { y += TITLE_HEIGHT; g.drawLine(1, BORDER_COLOR, x, y, x + w, y); } + + private class Titlebar extends FLabel { + private Titlebar(String title) { + super(new FLabel.Builder().text(title).icon(FSkinImage.FAVICON).fontSize(12).align(HAlignment.LEFT)); + } + + @Override + public boolean pan(float x, float y, float deltaX, float deltaY) { + for (FDisplayObject child : FDialog.this.getChildren()) { + child.setLeft(child.getLeft() + deltaX); + child.setTop(child.getTop() + deltaY); + } + return true; + } + + @Override + public boolean panStop(float x, float y) { + //ensure titlebar in view after stopping panning so it's accessible + float dx = 0; + float dy = 0; + float maxLeft = FDialog.this.getWidth() - lblTitlebar.getHeight(); + if (lblTitlebar.getLeft() > maxLeft) { + dx = maxLeft - lblTitlebar.getLeft(); + } + else { + float minRight = lblTitlebar.getHeight(); + if (lblTitlebar.getRight() < minRight) { + dx = minRight - lblTitlebar.getRight(); + } + } + float maxTop = FDialog.this.getHeight() - lblTitlebar.getHeight(); + if (lblTitlebar.getTop() > maxTop) { + dy = maxTop - lblTitlebar.getTop(); + } + else { + float minBottom = lblTitlebar.getHeight(); + if (lblTitlebar.getBottom() < minBottom) { + dy = minBottom - lblTitlebar.getBottom(); + } + } + if (dx != 0 || dy != 0) { + for (FDisplayObject child : FDialog.this.getChildren()) { + child.setLeft(child.getLeft() + dx); + child.setTop(child.getTop() + dy); + } + } + return true; + } + } }