Fix so rotated 90 components can capture input

This commit is contained in:
drdev
2014-09-29 21:33:07 +00:00
parent 167c2befb0
commit a82123bb95
12 changed files with 58 additions and 39 deletions

View File

@@ -234,8 +234,10 @@ public class Forge implements ApplicationListener {
}
graphics.begin(screenWidth, screenHeight);
screen.screenPos.setSize(screenWidth, screenHeight);
screen.draw(graphics);
for (FOverlay overlay : FOverlay.getOverlays()) {
overlay.screenPos.setSize(screenWidth, screenHeight);
overlay.setSize(screenWidth, screenHeight); //update overlay sizes as they're rendered
if (overlay.getRotate180()) {
graphics.startRotateTransform(screenWidth / 2, screenHeight / 2, 180);

View File

@@ -98,13 +98,11 @@ public class Graphics {
final Rectangle parentBounds = bounds;
bounds = new Rectangle(parentBounds.x + displayObj.getLeft(), parentBounds.y + displayObj.getTop(), displayObj.getWidth(), displayObj.getHeight());
if (!transforms.isEmpty()) { //transform screen position if needed
tmp.set(bounds.x + bounds.width / 2, regionHeight - bounds.y - bounds.height / 2, 0);
tmp.mul(batch.getTransformMatrix());
displayObj.setScreenPosition(tmp.x - bounds.width / 2, regionHeight - tmp.y - bounds.height / 2);
if (!transforms.isEmpty()) { //transform screen position if needed by applying transform matrix to rectangle
updateScreenPosForRotation(displayObj);
}
else {
displayObj.setScreenPosition(bounds.x, bounds.y);
displayObj.screenPos.set(bounds);
}
Rectangle intersection = Utils.getIntersection(bounds, visibleBounds);
@@ -114,9 +112,11 @@ public class Graphics {
if (displayObj.getRotate90()) { //use top-right corner of bounds as pivot point
startRotateTransform(displayObj.getWidth(), 0, -90);
updateScreenPosForRotation(displayObj);
}
else if (displayObj.getRotate180()) { //use center of bounds as pivot point
startRotateTransform(displayObj.getWidth() / 2, displayObj.getHeight() / 2, 180);
//screen position won't change for this object from a 180 degree rotation
}
displayObj.draw(this);
@@ -131,6 +131,39 @@ public class Graphics {
bounds = parentBounds;
}
private void updateScreenPosForRotation(FDisplayObject displayObj) {
tmp.set(bounds.x, regionHeight - bounds.y, 0);
tmp.mul(batch.getTransformMatrix());
tmp.y = regionHeight - tmp.y;
float minX = tmp.x;
float maxX = minX;
float minY = tmp.y;
float maxY = minY;
tmp.set(bounds.x + bounds.width, regionHeight - bounds.y, 0);
tmp.mul(batch.getTransformMatrix());
tmp.y = regionHeight - tmp.y;
if (tmp.x < minX) { minX = tmp.x; }
else if (tmp.x > maxX) { maxX = tmp.x; }
if (tmp.y < minY) { minY = tmp.y; }
else if (tmp.y > maxY) { maxY = tmp.y; }
tmp.set(bounds.x + bounds.width, regionHeight - bounds.y - bounds.height, 0);
tmp.mul(batch.getTransformMatrix());
tmp.y = regionHeight - tmp.y;
if (tmp.x < minX) { minX = tmp.x; }
else if (tmp.x > maxX) { maxX = tmp.x; }
if (tmp.y < minY) { minY = tmp.y; }
else if (tmp.y > maxY) { maxY = tmp.y; }
tmp.set(bounds.x, regionHeight - bounds.y - bounds.height, 0);
tmp.mul(batch.getTransformMatrix());
tmp.y = regionHeight - tmp.y;
if (tmp.x < minX) { minX = tmp.x; }
else if (tmp.x > maxX) { maxX = tmp.x; }
if (tmp.y < minY) { minY = tmp.y; }
else if (tmp.y > maxY) { maxY = tmp.y; }
displayObj.screenPos.set(minX, minY, maxX - minX, maxY - minY);
}
public void drawLine(float thickness, FSkinColor skinColor, float x1, float y1, float x2, float y2) {
drawLine(thickness, skinColor.getColor(), x1, y1, x2, y2);
}

View File

@@ -767,10 +767,9 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
if (selectedIndices.isEmpty()) { return null; }
ItemInfo itemInfo = orderedItems.get(selectedIndices.get(0));
Vector2 screenPos = itemInfo.group.getScreenPosition();
Vector2 relPos = itemInfo.group.getChildRelativePosition(itemInfo);
return new Rectangle(screenPos.x + relPos.x - SEL_BORDER_SIZE + itemInfo.group.getLeft(),
screenPos.y + relPos.y - SEL_BORDER_SIZE,
return new Rectangle(itemInfo.group.screenPos.x + relPos.x - SEL_BORDER_SIZE + itemInfo.group.getLeft(),
itemInfo.group.screenPos.y + relPos.y - SEL_BORDER_SIZE,
itemInfo.getWidth() + 2 * SEL_BORDER_SIZE, itemInfo.getHeight() + 2 * SEL_BORDER_SIZE);
}

View File

@@ -34,8 +34,6 @@ import forge.toolbox.FDisplayObject;
import forge.toolbox.FList;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import java.util.*;
import java.util.Map.Entry;
@@ -128,8 +126,7 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
public Rectangle getSelectionBounds() {
if (selectedIndices.isEmpty()) { return null; }
Vector2 screenPos = list.getScreenPosition();
return new Rectangle(screenPos.x, screenPos.y + list.getItemTop(getSelectedIndex()), list.getWidth(), list.getListItemRenderer().getItemHeight());
return new Rectangle(list.screenPos.x, list.screenPos.y + list.getItemTop(getSelectedIndex()), list.getWidth(), list.getListItemRenderer().getItemHeight());
}
@Override

View File

@@ -1,7 +1,5 @@
package forge.menu;
import com.badlogic.gdx.math.Vector2;
import forge.Forge;
import forge.Graphics;
import forge.assets.FSkinColor;
@@ -119,9 +117,8 @@ public abstract class FDropDown extends FScrollPane {
float screenWidth = screen.getWidth();
float screenHeight = screen.getHeight();
Vector2 tabScreenPos = menuTab.getScreenPosition();
float x = tabScreenPos.x;
float y = tabScreenPos.y + menuTab.getHeight();
float x = menuTab.screenPos.x;
float y = menuTab.screenPos.y + menuTab.getHeight();
float maxVisibleHeight = screenHeight - VPrompt.HEIGHT - y; //prevent covering prompt
paneSize = updateAndGetPaneSize(screenWidth, maxVisibleHeight);

View File

@@ -34,8 +34,8 @@ public class FMagnifyView extends FDropDown {
@Override
protected void updateSizeAndPosition() {
float x = owner.getScreenPosition().x;
float y = owner.getScreenPosition().y + owner.getHeight();
float x = owner.screenPos.x;
float y = owner.screenPos.y + owner.getHeight();
paneSize = updateAndGetPaneSize(owner.getWidth(), y);
float height = paneSize.getHeight();
if (height > y) {

View File

@@ -36,7 +36,7 @@ public class VAvatar extends FDisplayObject {
}
public Vector2 getTargetingArrowOrigin() {
Vector2 origin = new Vector2(getScreenPosition());
Vector2 origin = new Vector2(screenPos.x, screenPos.y);
origin.x += WIDTH * 0.75f;
if (origin.y < MatchController.getView().getHeight() / 2) {

View File

@@ -307,7 +307,7 @@ public abstract class VCardDisplayArea extends VDisplayArea {
//don't show targeting arrow unless in display area that's visible
if (displayArea == null || !displayArea.isVisible()) { return null; }
Vector2 origin = new Vector2(getScreenPosition());
Vector2 origin = new Vector2(screenPos.x, screenPos.y);
float left = PADDING;
float top = PADDING;

View File

@@ -48,7 +48,7 @@ public class VLog extends FDropDown {
List<GameLogEntry> logEntrys = MatchUtil.getGameView().getLogEntries(logVerbosityFilter);
LogEntryDisplay logEntryDisplay;
float width = maxWidth - getMenuTab().getScreenPosition().x; //stretch from tab to edge of screen
float width = maxWidth - getMenuTab().screenPos.x; //stretch from tab to edge of screen
float minWidth = 4 * Utils.AVG_FINGER_WIDTH;
if (width < minWidth) {
width = minWidth;

View File

@@ -179,7 +179,7 @@ public class VStack extends FDropDown {
activeItem.getTop() + VStack.CARD_HEIGHT * FCardPanel.TARGET_ORIGIN_FACTOR_Y + VStack.PADDING + VStack.BORDER_THICKNESS);
PlayerView activator = activeStackInstance.getActivatingPlayer();
arrowOrigin = arrowOrigin.add(getScreenPosition());
arrowOrigin = arrowOrigin.add(screenPos.x, screenPos.y);
StackItemView instance = activeStackInstance;
while (instance != null) {

View File

@@ -107,7 +107,7 @@ public abstract class FContainer extends FDisplayObject {
@Override
public void buildTouchListeners(float screenX, float screenY, ArrayList<FDisplayObject> listeners) {
if (isEnabled() && contains(getLeft() + screenToLocalX(screenX), getTop() + screenToLocalY(screenY))) {
if (isEnabled() && isVisible() && screenPos.contains(screenX, screenY)) {
for (int i = children.size() - 1; i >= 0; i--) {
children.get(i).buildTouchListeners(screenX, screenY, listeners);
}

View File

@@ -3,8 +3,6 @@ package forge.toolbox;
import java.util.ArrayList;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import forge.Graphics;
public abstract class FDisplayObject {
@@ -15,7 +13,7 @@ public abstract class FDisplayObject {
private boolean rotate90 = false;
private boolean rotate180 = false;
private final Rectangle bounds = new Rectangle();
private final Vector2 screenPosition = new Vector2();
public final Rectangle screenPos = new Rectangle();
public void setPosition(float x, float y) {
bounds.setPosition(x, y);
@@ -60,24 +58,17 @@ public abstract class FDisplayObject {
return visible && bounds.contains(x, y);
}
public Vector2 getScreenPosition() {
return screenPosition;
}
public void setScreenPosition(float x, float y) { //only call from Graphics when drawn
screenPosition.set(x, y);
}
public float screenToLocalX(float x) {
return x - screenPosition.x;
return x - screenPos.x;
}
public float screenToLocalY(float y) {
return y - screenPosition.y;
return y - screenPos.y;
}
public float localToScreenX(float x) {
return x + screenPosition.x;
return x + screenPos.x;
}
public float localToScreenY(float y) {
return y + screenPosition.y;
return y + screenPos.y;
}
public boolean isEnabled() {
@@ -119,7 +110,7 @@ public abstract class FDisplayObject {
public abstract void draw(Graphics g);
public void buildTouchListeners(float screenX, float screenY, ArrayList<FDisplayObject> listeners) {
if (enabled && contains(getLeft() + screenToLocalX(screenX), getTop() + screenToLocalY(screenY))) {
if (enabled && visible && screenPos.contains(screenX, screenY)) {
listeners.add(this);
}
}