new layouts & start of main menu

This commit is contained in:
Ondřej Hruška
2014-04-16 08:35:47 +02:00
parent 3cad5ad202
commit 990c3de5ca
19 changed files with 335 additions and 33 deletions
+11
View File
@@ -0,0 +1,11 @@
package mightypork.gamecore.gui;
/**
* Horizontal align sides
*
* @author MightyPork
*/
public enum AlignX
{
LEFT, CENTER, RIGHT;
}
+11
View File
@@ -0,0 +1,11 @@
package mightypork.gamecore.gui;
/**
* Vertical align sides
*
* @author MightyPork
*/
public enum AlignY
{
TOP, CENTER, BOTTOM;
}
@@ -7,7 +7,7 @@ import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.ActionTrigger;
public abstract class InputComponent extends VisualComponent implements Component, Enableable, ActionTrigger, MouseButtonEvent.Listener {
public abstract class InputComponent extends VisualComponent implements Enableable, ActionTrigger, MouseButtonEvent.Listener {
private boolean enabled;
private Action action;
@@ -15,7 +15,7 @@ import mightypork.gamecore.render.DisplaySystem;
import mightypork.utils.math.constraints.rect.proxy.RectBound;
public abstract class LayoutComponent extends VisualComponent implements Component, Enableable, ClientHub, AppAccess {
public abstract class LayoutComponent extends VisualComponent implements Enableable, ClientHub, AppAccess {
private boolean enabled;
@@ -67,7 +67,7 @@ public abstract class VisualComponent extends AbstractRectCache implements Compo
if (!visible) return;
renderComponent();
};
}
@Override
@@ -26,7 +26,7 @@ public class ColumnHolder extends LayoutComponent {
*/
public ColumnHolder(AppAccess app, RectBound context, int cols) {
super(app, context);
this.tiler = getRect().columns(cols).zeroBased();
this.tiler = columns(cols).zeroBased();
}
@@ -0,0 +1,82 @@
package mightypork.gamecore.gui.components.layout;
import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.LayoutComponent;
import mightypork.gamecore.gui.components.Component;
import mightypork.utils.math.constraints.num.Num;
import mightypork.utils.math.constraints.rect.Rect;
import mightypork.utils.math.constraints.rect.proxy.RectBound;
/**
* Holder with same-sized columns, aligned to left or right
*
* @author MightyPork
*/
public class HorizontalFixedFlowLayout extends LayoutComponent {
private int col = 0;
private Num colWidth;
private AlignX align;
/**
* @param app app access
* @param context context
* @param elementWidth width of all elements
* @param align component align. Legal values are LEFT and RIGHT.
*/
public HorizontalFixedFlowLayout(AppAccess app, RectBound context, Num elementWidth, AlignX align) {
super(app, context);
this.colWidth = elementWidth;
this.align = align;
if (align != AlignX.LEFT && align != AlignX.RIGHT) {
throw new IllegalArgumentException("Can align only left or right.");
}
}
/**
* make a new holder.<br>
* Context must be assigned before rendering.
*
* @param app app access
* @param elementWidth width of all elements
* @param align component align. Legal values are LEFT and RIGHT.
*/
public HorizontalFixedFlowLayout(AppAccess app, Num elementWidth, AlignX align) {
this(app, null, elementWidth, align);
}
/**
* Add an item
*
* @param elem
*/
public void add(final Component elem)
{
if (elem == null) return;
final Rect r;
switch (align) {
case LEFT:
r = leftEdge().growRight(colWidth).moveX(colWidth.mul(col++));
break;
case RIGHT:
r = rightEdge().growLeft(colWidth).moveX(colWidth.mul(-(col++)));
break;
default:
throw new IllegalArgumentException("Bad align.");
}
elem.setRect(r);
attach(elem);
}
}
@@ -38,7 +38,7 @@ public class RowHolder extends LayoutComponent {
*/
public RowHolder(AppAccess app, RectBound context, int rows) {
super(app, context);
this.tiler = getRect().rows(rows).zeroBased();
this.tiler = rows(rows).zeroBased();
}
@@ -0,0 +1,82 @@
package mightypork.gamecore.gui.components.layout;
import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.gui.AlignY;
import mightypork.gamecore.gui.components.LayoutComponent;
import mightypork.gamecore.gui.components.Component;
import mightypork.utils.math.constraints.num.Num;
import mightypork.utils.math.constraints.rect.Rect;
import mightypork.utils.math.constraints.rect.proxy.RectBound;
/**
* Holder with same-sized rows, aligned to top or bottom
*
* @author MightyPork
*/
public class VerticalFixedFlowLayout extends LayoutComponent {
private int row = 0;
private Num rowHeight;
private AlignY align;
/**
* @param app app access
* @param context context
* @param elementHeight height of all elements
* @param align component align. Legal values are TOP and BOTTOM.
*/
public VerticalFixedFlowLayout(AppAccess app, RectBound context, Num elementHeight, AlignY align) {
super(app, context);
this.rowHeight = elementHeight;
this.align = align;
if (align != AlignY.TOP && align != AlignY.BOTTOM) {
throw new IllegalArgumentException("Can align only to top or bottom.");
}
}
/**
* make a new holder.<br>
* Context must be assigned before rendering.
*
* @param app app access
* @param elementHeight height of all elements
* @param align component align. Legal values are TOP and BOTTOM.
*/
public VerticalFixedFlowLayout(AppAccess app, Num elementHeight, AlignY align) {
this(app, null, elementHeight, align);
}
/**
* Add an item
*
* @param elem
*/
public void add(final Component elem)
{
if (elem == null) return;
final Rect r;
switch (align) {
case TOP:
r = topEdge().growDown(rowHeight).moveY(rowHeight.mul(row++));
break;
case BOTTOM:
r = bottomEdge().growUp(rowHeight).moveY(rowHeight.mul(-(row++)));
break;
default:
throw new IllegalArgumentException("Bad align.");
}
elem.setRect(r);
attach(elem);
}
}
@@ -1,9 +1,9 @@
package mightypork.gamecore.gui.components.painters;
import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.VisualComponent;
import mightypork.gamecore.render.fonts.FontRenderer;
import mightypork.gamecore.render.fonts.FontRenderer.Align;
import mightypork.gamecore.render.fonts.GLFont;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.constraints.rect.Rect;
@@ -23,7 +23,7 @@ public class TextPainter extends VisualComponent {
private final FontRenderer font;
private RGB color;
private Align align;
private AlignX align;
private StringProvider text;
private boolean shadow;
@@ -35,7 +35,7 @@ public class TextPainter extends VisualComponent {
* @param font font to use
*/
public TextPainter(GLFont font) {
this(font, Align.LEFT, RGB.WHITE);
this(font, AlignX.LEFT, RGB.WHITE);
}
@@ -47,7 +47,7 @@ public class TextPainter extends VisualComponent {
* @param color default color
* @param text drawn text
*/
public TextPainter(GLFont font, Align align, RGB color, String text) {
public TextPainter(GLFont font, AlignX align, RGB color, String text) {
this(font, align, color, new StringWrapper(text));
}
@@ -60,7 +60,7 @@ public class TextPainter extends VisualComponent {
* @param color default color
* @param text text provider
*/
public TextPainter(GLFont font, Align align, RGB color, StringProvider text) {
public TextPainter(GLFont font, AlignX align, RGB color, StringProvider text) {
this.font = new FontRenderer(font);
this.color = color;
this.align = align;
@@ -73,7 +73,7 @@ public class TextPainter extends VisualComponent {
* @param align text align
* @param color default color
*/
public TextPainter(GLFont font, Align align, RGB color) {
public TextPainter(GLFont font, AlignX align, RGB color) {
this(font, align, color, (StringProvider) null);
}
@@ -125,7 +125,7 @@ public class TextPainter extends VisualComponent {
}
public void setAlign(Align align)
public void setAlign(AlignX align)
{
this.align = align;
}
@@ -1,6 +1,7 @@
package mightypork.gamecore.render.fonts;
import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.render.Render;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.constraints.rect.Rect;
@@ -16,11 +17,6 @@ public class FontRenderer {
private GLFont font;
public static enum Align
{
LEFT, CENTER, RIGHT;
}
private RGB color;
@@ -125,7 +121,7 @@ public class FontRenderer {
* for align)
* @param align horizontal alignment (with respect to bounds)
*/
public void draw(String text, Rect bounds, Align align)
public void draw(String text, Rect bounds, AlignX align)
{
this.draw(text, bounds, align, this.color);
}
@@ -140,7 +136,7 @@ public class FontRenderer {
* @param align horizontal alignment (with respect to bounds)
* @param color drawing color
*/
public void draw(String text, Rect bounds, Align align, RGB color)
public void draw(String text, Rect bounds, AlignX align, RGB color)
{
Vect start;
@@ -171,7 +167,7 @@ public class FontRenderer {
* @param height drawing height
* @param align horizontal alignment
*/
public void draw(String text, Vect pos, double height, Align align)
public void draw(String text, Vect pos, double height, AlignX align)
{
draw(text, pos, height, align, this.color);
}
@@ -186,7 +182,7 @@ public class FontRenderer {
* @param align horizontal alignment
* @param color drawing color
*/
public void draw(String text, Vect pos, double height, Align align, RGB color)
public void draw(String text, Vect pos, double height, AlignX align, RGB color)
{
final double w = getWidth(text, height);
@@ -2,7 +2,6 @@ package mightypork.gamecore.render.fonts.impl;
import mightypork.gamecore.render.fonts.GLFont;
import mightypork.utils.logging.Log;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.constraints.vect.Vect;