mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Improve submenu rendering
This commit is contained in:
@@ -17,11 +17,11 @@ import forge.util.Utils;
|
||||
|
||||
public class FMenuItem extends FDisplayObject {
|
||||
public static final float HEIGHT = Utils.AVG_FINGER_HEIGHT * 0.8f;
|
||||
private static final float GAP_X = HEIGHT * 0.1f;
|
||||
protected static final float GAP_X = HEIGHT * 0.1f;
|
||||
private static final float ICON_SIZE = ((int)((HEIGHT - 2 * GAP_X) / 20f)) * 20; //round down to nearest multiple of 20
|
||||
|
||||
private static final FSkinFont FONT = FSkinFont.get(12);
|
||||
private static final FSkinColor FORE_COLOR = FSkinColor.get(Colors.CLR_TEXT);
|
||||
protected static final FSkinColor FORE_COLOR = FSkinColor.get(Colors.CLR_TEXT);
|
||||
private static final FSkinColor PRESSED_COLOR = FSkinColor.get(Colors.CLR_ACTIVE).alphaColor(0.9f);
|
||||
private static final FSkinColor SEPARATOR_COLOR = FORE_COLOR.alphaColor(0.5f);
|
||||
|
||||
@@ -91,12 +91,16 @@ public class FMenuItem extends FDisplayObject {
|
||||
return false; //return false so parent can use event to hide menu
|
||||
}
|
||||
|
||||
protected boolean showPressedColor() {
|
||||
return pressed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void draw(Graphics g) {
|
||||
public void draw(Graphics g) {
|
||||
float w = getWidth();
|
||||
float h = HEIGHT;
|
||||
|
||||
if (pressed) {
|
||||
if (showPressedColor()) {
|
||||
g.fillRect(PRESSED_COLOR, 0, 0, w, h);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package forge.menu;
|
||||
|
||||
import forge.Forge.Graphics;
|
||||
import forge.assets.FImage;
|
||||
|
||||
public class FSubMenu extends FMenuItem {
|
||||
@@ -19,6 +20,11 @@ public class FSubMenu extends FMenuItem {
|
||||
popupMenu = popupMenu0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean showPressedColor() {
|
||||
return super.showPressedColor() || popupMenu.isVisible();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tap(float x, float y, int count) {
|
||||
if (popupMenu.isVisible()) {
|
||||
@@ -29,4 +35,28 @@ public class FSubMenu extends FMenuItem {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics g) {
|
||||
super.draw(g);
|
||||
|
||||
float divotWidth = getDivotWidth();
|
||||
float divotHeight = divotWidth * 2f;
|
||||
float x2 = getWidth() - GAP_X - 1;
|
||||
float x1 = x2 - divotWidth;
|
||||
float x3 = x1;
|
||||
float y2 = getHeight() / 2;
|
||||
float y1 = y2 - divotHeight / 2;
|
||||
float y3 = y2 + divotHeight / 2;
|
||||
g.fillTriangle(FORE_COLOR, x1, y1, x2, y2, x3, y3);
|
||||
}
|
||||
|
||||
private float getDivotWidth() {
|
||||
return getHeight() / 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMinWidth() {
|
||||
return super.getMinWidth() + getDivotWidth() + 2 * GAP_X;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user