colors & fixed a bug in layout
This commit is contained in:
@@ -33,11 +33,7 @@ public abstract class InputComponent extends VisualComponent implements Enableab
|
||||
return enabled;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public abstract void renderComponent();
|
||||
|
||||
protected void triggerAction() {
|
||||
action.run();
|
||||
if(action != null) action.run();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ public abstract class LayoutComponent extends VisualComponent implements Enablea
|
||||
public LayoutComponent(AppAccess app, RectBound context) {
|
||||
this.subModule = new AppSubModule(app);
|
||||
setRect(context);
|
||||
enableCaching(true); // layout is typically updated only when screen resizes.
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ public abstract class VisualComponent extends AbstractRectCache implements Compo
|
||||
|
||||
public VisualComponent() {
|
||||
super();
|
||||
enableCaching(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +88,7 @@ public abstract class VisualComponent extends AbstractRectCache implements Compo
|
||||
/**
|
||||
* Draw the component (it's visible)
|
||||
*/
|
||||
public abstract void renderComponent();
|
||||
protected abstract void renderComponent();
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,7 +4,7 @@ package mightypork.gamecore.gui.components.painters;
|
||||
import mightypork.gamecore.gui.components.VisualComponent;
|
||||
import mightypork.gamecore.render.Render;
|
||||
import mightypork.utils.annotations.FactoryMethod;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.color.Color;
|
||||
|
||||
|
||||
/**
|
||||
@@ -15,22 +15,22 @@ import mightypork.utils.math.color.RGB;
|
||||
public class QuadPainter extends VisualComponent {
|
||||
|
||||
@FactoryMethod
|
||||
public static QuadPainter gradH(RGB colorLeft, RGB colorRight)
|
||||
public static QuadPainter gradH(Color colorLeft, Color colorRight)
|
||||
{
|
||||
return new QuadPainter(colorLeft, colorRight, colorRight, colorLeft);
|
||||
}
|
||||
|
||||
|
||||
@FactoryMethod
|
||||
public static QuadPainter gradV(RGB colorTop, RGB colorBottom)
|
||||
public static QuadPainter gradV(Color colorTop, Color colorBottom)
|
||||
{
|
||||
return new QuadPainter(colorTop, colorTop, colorBottom, colorBottom);
|
||||
}
|
||||
|
||||
private final RGB colorHMinVMin;
|
||||
private final RGB colorHMaxVMin;
|
||||
private final RGB colorHMaxVMax;
|
||||
private final RGB colorHMinVMax;
|
||||
private final Color colorHMinVMin;
|
||||
private final Color colorHMaxVMin;
|
||||
private final Color colorHMaxVMax;
|
||||
private final Color colorHMinVMax;
|
||||
|
||||
|
||||
/**
|
||||
@@ -38,7 +38,7 @@ public class QuadPainter extends VisualComponent {
|
||||
*
|
||||
* @param color
|
||||
*/
|
||||
public QuadPainter(RGB color) {
|
||||
public QuadPainter(Color color) {
|
||||
this.colorHMinVMin = color;
|
||||
this.colorHMaxVMin = color;
|
||||
this.colorHMaxVMax = color;
|
||||
@@ -54,7 +54,7 @@ public class QuadPainter extends VisualComponent {
|
||||
* @param colorHMaxVMax
|
||||
* @param colorHMinVMax
|
||||
*/
|
||||
public QuadPainter(RGB colorHMinVMin, RGB colorHMaxVMin, RGB colorHMaxVMax, RGB colorHMinVMax) {
|
||||
public QuadPainter(Color colorHMinVMin, Color colorHMaxVMin, Color colorHMaxVMax, Color colorHMinVMax) {
|
||||
this.colorHMinVMin = colorHMinVMin;
|
||||
this.colorHMaxVMin = colorHMaxVMin;
|
||||
this.colorHMaxVMax = colorHMaxVMax;
|
||||
|
||||
@@ -5,7 +5,7 @@ import mightypork.gamecore.gui.AlignX;
|
||||
import mightypork.gamecore.gui.components.VisualComponent;
|
||||
import mightypork.gamecore.render.fonts.FontRenderer;
|
||||
import mightypork.gamecore.render.fonts.GLFont;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.color.Color;
|
||||
import mightypork.utils.math.constraints.rect.Rect;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
import mightypork.utils.string.StringProvider;
|
||||
@@ -22,12 +22,12 @@ import mightypork.utils.string.StringProvider.StringWrapper;
|
||||
public class TextPainter extends VisualComponent {
|
||||
|
||||
private final FontRenderer font;
|
||||
private RGB color;
|
||||
private Color color;
|
||||
private AlignX align;
|
||||
private StringProvider text;
|
||||
private boolean shadow;
|
||||
|
||||
private RGB shadowColor = RGB.BLACK;
|
||||
private Color shadowColor = Color.BLACK;
|
||||
private Vect shadowOffset = Vect.make(1, 1);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public class TextPainter extends VisualComponent {
|
||||
* @param font font to use
|
||||
*/
|
||||
public TextPainter(GLFont font) {
|
||||
this(font, AlignX.LEFT, RGB.WHITE);
|
||||
this(font, AlignX.LEFT, Color.WHITE);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class TextPainter extends VisualComponent {
|
||||
* @param color default color
|
||||
* @param text drawn text
|
||||
*/
|
||||
public TextPainter(GLFont font, AlignX align, RGB color, String text) {
|
||||
public TextPainter(GLFont font, AlignX align, Color 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, AlignX align, RGB color, StringProvider text) {
|
||||
public TextPainter(GLFont font, AlignX align, Color 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, AlignX align, RGB color) {
|
||||
public TextPainter(GLFont font, AlignX align, Color color) {
|
||||
this(font, align, color, (StringProvider) null);
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public class TextPainter extends VisualComponent {
|
||||
}
|
||||
|
||||
|
||||
public void setShadow(RGB color, Vect offset)
|
||||
public void setShadow(Color color, Vect offset)
|
||||
{
|
||||
setShadow(true);
|
||||
setShadowColor(color);
|
||||
@@ -107,7 +107,7 @@ public class TextPainter extends VisualComponent {
|
||||
}
|
||||
|
||||
|
||||
public void setShadowColor(RGB shadowColor)
|
||||
public void setShadowColor(Color shadowColor)
|
||||
{
|
||||
this.shadowColor = shadowColor;
|
||||
}
|
||||
@@ -119,7 +119,7 @@ public class TextPainter extends VisualComponent {
|
||||
}
|
||||
|
||||
|
||||
public void setColor(RGB color)
|
||||
public void setColor(Color color)
|
||||
{
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.io.IOException;
|
||||
import mightypork.gamecore.render.textures.TxQuad;
|
||||
import mightypork.utils.files.FileUtils;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.color.Color;
|
||||
import mightypork.utils.math.constraints.rect.Rect;
|
||||
import mightypork.utils.math.constraints.rect.caching.RectDigest;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
@@ -36,23 +36,23 @@ public class Render {
|
||||
/**
|
||||
* Bind GL color
|
||||
*
|
||||
* @param color RGB color
|
||||
* @param color Color color
|
||||
*/
|
||||
public static void setColor(RGB color)
|
||||
public static void setColor(Color color)
|
||||
{
|
||||
if (color != null) glColor4d(color.r, color.g, color.b, color.a);
|
||||
if (color != null) glColor4d(color.red(), color.green(), color.blue(), color.alpha());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Bind GL color
|
||||
*
|
||||
* @param color RGB color
|
||||
* @param color Color color
|
||||
* @param alpha alpha multiplier
|
||||
*/
|
||||
public static void setColor(RGB color, double alpha)
|
||||
public static void setColor(Color color, double alpha)
|
||||
{
|
||||
if (color != null) glColor4d(color.r, color.g, color.b, color.a * alpha);
|
||||
if (color != null) glColor4d(color.red(), color.green(), color.blue(), color.alpha() * alpha);
|
||||
}
|
||||
|
||||
|
||||
@@ -348,7 +348,7 @@ public class Render {
|
||||
* @param rect rectangle
|
||||
* @param color draw color
|
||||
*/
|
||||
public static void quad(Rect rect, RGB color)
|
||||
public static void quad(Rect rect, Color color)
|
||||
{
|
||||
setColor(color);
|
||||
quad(rect);
|
||||
@@ -425,7 +425,7 @@ public class Render {
|
||||
* @param color1 left color
|
||||
* @param color2 right color
|
||||
*/
|
||||
public static void quadGradH(Rect quad, RGB color1, RGB color2)
|
||||
public static void quadGradH(Rect quad, Color color1, Color color2)
|
||||
{
|
||||
quadColor(quad, color1, color2, color2, color1);
|
||||
}
|
||||
@@ -440,7 +440,7 @@ public class Render {
|
||||
* @param colorHMaxVMax
|
||||
* @param colorHMinVMax
|
||||
*/
|
||||
public static void quadColor(Rect quad, RGB colorHMinVMin, RGB colorHMaxVMin, RGB colorHMaxVMax, RGB colorHMinVMax)
|
||||
public static void quadColor(Rect quad, Color colorHMinVMin, Color colorHMaxVMin, Color colorHMaxVMax, Color colorHMinVMax)
|
||||
{
|
||||
final RectDigest r = quad.digest();
|
||||
|
||||
@@ -470,7 +470,7 @@ public class Render {
|
||||
* @param color1 top color
|
||||
* @param color2 bottom color
|
||||
*/
|
||||
public static void quadGradV(Rect quad, RGB color1, RGB color2)
|
||||
public static void quadGradV(Rect quad, Color color1, Color color2)
|
||||
{
|
||||
quadColor(quad, color1, color1, color2, color2);
|
||||
}
|
||||
@@ -484,7 +484,7 @@ public class Render {
|
||||
* @param texture texture instance
|
||||
* @param tint color tint
|
||||
*/
|
||||
public static void quadTextured(Rect quad, Rect uvs, Texture texture, RGB tint)
|
||||
public static void quadTextured(Rect quad, Rect uvs, Texture texture, Color tint)
|
||||
{
|
||||
bindTexture(texture);
|
||||
setColor(tint);
|
||||
@@ -502,7 +502,7 @@ public class Render {
|
||||
*/
|
||||
public static void quadTextured(Rect quad, Rect uvs, Texture texture)
|
||||
{
|
||||
quadTextured(quad, uvs, texture, RGB.WHITE);
|
||||
quadTextured(quad, uvs, texture, Color.WHITE);
|
||||
}
|
||||
|
||||
|
||||
@@ -514,7 +514,7 @@ public class Render {
|
||||
*/
|
||||
public static void quadTextured(Rect quad, Texture texture)
|
||||
{
|
||||
quadTextured(quad, Rect.ONE, texture, RGB.WHITE);
|
||||
quadTextured(quad, Rect.ONE, texture, Color.WHITE);
|
||||
}
|
||||
|
||||
|
||||
@@ -526,7 +526,7 @@ public class Render {
|
||||
*/
|
||||
public static void quadTextured(Rect quad, TxQuad txquad)
|
||||
{
|
||||
quadTextured(quad, txquad, RGB.WHITE);
|
||||
quadTextured(quad, txquad, Color.WHITE);
|
||||
}
|
||||
|
||||
|
||||
@@ -537,7 +537,7 @@ public class Render {
|
||||
* @param txquad texture instance
|
||||
* @param tint color tint
|
||||
*/
|
||||
public static void quadTextured(Rect quad, TxQuad txquad, RGB tint)
|
||||
public static void quadTextured(Rect quad, TxQuad txquad, Color tint)
|
||||
{
|
||||
quadTextured(quad, txquad.uvs, txquad.tx, tint);
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.control.AppAdapter;
|
||||
import mightypork.gamecore.control.bus.events.ResourceLoadRequest;
|
||||
import mightypork.gamecore.render.fonts.impl.DeferredFont;
|
||||
import mightypork.gamecore.render.fonts.impl.NullFont;
|
||||
import mightypork.utils.logging.Log;
|
||||
|
||||
import org.newdawn.slick.opengl.Texture;
|
||||
|
||||
@@ -18,10 +16,7 @@ import org.newdawn.slick.opengl.Texture;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class FontBank extends AppAdapter {
|
||||
|
||||
private static final GLFont NULL_FONT = new NullFont();
|
||||
|
||||
public class FontBank extends AppAdapter {
|
||||
|
||||
/**
|
||||
* @param app app access
|
||||
@@ -31,6 +26,7 @@ public class FontBank extends AppAdapter {
|
||||
}
|
||||
|
||||
private final HashMap<String, GLFont> fonts = new HashMap<>();
|
||||
private final HashMap<String, String> aliases = new HashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
@@ -57,6 +53,17 @@ public class FontBank extends AppAdapter {
|
||||
{
|
||||
fonts.put(key, font);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a font alias.
|
||||
*
|
||||
* @param alias_key alias key
|
||||
* @param font_key font key
|
||||
*/
|
||||
public void addAlias(String alias_key, String font_key)
|
||||
{
|
||||
aliases.put(alias_key, font_key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -67,11 +74,12 @@ public class FontBank extends AppAdapter {
|
||||
*/
|
||||
public GLFont getFont(String key)
|
||||
{
|
||||
final GLFont f = fonts.get(key);
|
||||
GLFont f = fonts.get(key);
|
||||
|
||||
if (f == null) {
|
||||
Log.w("There's no font called " + key + "!");
|
||||
return NULL_FONT;
|
||||
if(f == null) f = fonts.get(aliases.get(key));
|
||||
|
||||
if (f == null) {
|
||||
throw new RuntimeException("There's no font called " + key + "!");
|
||||
}
|
||||
|
||||
return f;
|
||||
|
||||
@@ -3,7 +3,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.color.Color;
|
||||
import mightypork.utils.math.constraints.rect.Rect;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
|
||||
@@ -17,14 +17,14 @@ public class FontRenderer {
|
||||
|
||||
private GLFont font;
|
||||
|
||||
private RGB color;
|
||||
private Color color;
|
||||
|
||||
|
||||
/**
|
||||
* @param font used font
|
||||
*/
|
||||
public FontRenderer(GLFont font) {
|
||||
this(font, RGB.WHITE);
|
||||
this(font, Color.WHITE);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class FontRenderer {
|
||||
* @param font used font
|
||||
* @param color drawing color
|
||||
*/
|
||||
public FontRenderer(GLFont font, RGB color) {
|
||||
public FontRenderer(GLFont font, Color color) {
|
||||
this.font = font;
|
||||
this.color = color;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public class FontRenderer {
|
||||
*
|
||||
* @param color color
|
||||
*/
|
||||
public void setColor(RGB color)
|
||||
public void setColor(Color color)
|
||||
{
|
||||
this.color = color;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public class FontRenderer {
|
||||
* @param height drawing height
|
||||
* @param color drawing color
|
||||
*/
|
||||
public void draw(String text, Vect pos, double height, RGB color)
|
||||
public void draw(String text, Vect pos, double height, Color color)
|
||||
{
|
||||
Render.pushMatrix();
|
||||
|
||||
@@ -136,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, AlignX align, RGB color)
|
||||
public void draw(String text, Rect bounds, AlignX align, Color color)
|
||||
{
|
||||
Vect start;
|
||||
|
||||
@@ -182,7 +182,7 @@ public class FontRenderer {
|
||||
* @param align horizontal alignment
|
||||
* @param color drawing color
|
||||
*/
|
||||
public void draw(String text, Vect pos, double height, AlignX align, RGB color)
|
||||
public void draw(String text, Vect pos, double height, AlignX align, Color color)
|
||||
{
|
||||
|
||||
final double w = getWidth(text, height);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package mightypork.gamecore.render.fonts;
|
||||
|
||||
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.color.Color;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ public interface GLFont {
|
||||
* @param text text to draw
|
||||
* @param color draw color
|
||||
*/
|
||||
void draw(String text, RGB color);
|
||||
void draw(String text, Color color);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,6 @@ package mightypork.gamecore.render.fonts.impl;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
@@ -22,7 +21,7 @@ import java.util.Map;
|
||||
import mightypork.gamecore.render.fonts.GLFont;
|
||||
import mightypork.gamecore.render.textures.FilterMode;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.color.Color;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
import mightypork.utils.math.constraints.vect.VectConst;
|
||||
|
||||
@@ -141,7 +140,7 @@ public class CachedFont implements GLFont {
|
||||
g = (Graphics2D) fontImage.getGraphics();
|
||||
if (antiAlias == true) g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g.setFont(font);
|
||||
g.setColor(Color.WHITE);
|
||||
g.setColor(java.awt.Color.WHITE);
|
||||
g.drawString(String.valueOf(ch), 0, metrics.getAscent());
|
||||
|
||||
return fontImage;
|
||||
@@ -225,7 +224,7 @@ public class CachedFont implements GLFont {
|
||||
BufferedImage imag = new BufferedImage(textureWidth, textureHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
final Graphics2D g = (Graphics2D) imag.getGraphics();
|
||||
|
||||
g.setColor(new Color(0, 0, 0, 1));
|
||||
g.setColor(new java.awt.Color(0, 0, 0, 1));
|
||||
g.fillRect(0, 0, textureWidth, textureHeight);
|
||||
|
||||
int rowHeight = 0, posX = 0, posY = 0;
|
||||
@@ -392,14 +391,14 @@ public class CachedFont implements GLFont {
|
||||
|
||||
|
||||
@Override
|
||||
public void draw(String text, RGB color)
|
||||
public void draw(String text, Color color)
|
||||
{
|
||||
GLUtils.checkGLContext();
|
||||
|
||||
glPushAttrib(GL_ENABLE_BIT);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, textureID);
|
||||
glColor4d(color.r, color.g, color.b, color.a);
|
||||
glColor4d(color.red(), color.green(), color.blue(), color.alpha());
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
CharTile chtx = null;
|
||||
|
||||
@@ -12,7 +12,7 @@ import mightypork.gamecore.render.fonts.GLFont;
|
||||
import mightypork.gamecore.render.textures.FilterMode;
|
||||
import mightypork.utils.annotations.Alias;
|
||||
import mightypork.utils.files.FileUtils;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.color.Color;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ public class DeferredFont extends DeferredResource implements GLFont {
|
||||
* @param color draw color
|
||||
*/
|
||||
@Override
|
||||
public void draw(String str, RGB color)
|
||||
public void draw(String str, Color color)
|
||||
{
|
||||
if (!ensureLoaded()) return;
|
||||
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
package mightypork.gamecore.render.fonts.impl;
|
||||
|
||||
|
||||
import mightypork.gamecore.render.fonts.GLFont;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.constraints.vect.Vect;
|
||||
|
||||
|
||||
/**
|
||||
* Null font used where real resource could not be loaded.
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class NullFont implements GLFont {
|
||||
|
||||
@Override
|
||||
public void draw(String str, RGB color)
|
||||
{
|
||||
// yeah right
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Vect getNeededSpace(String str)
|
||||
{
|
||||
return Vect.ZERO;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getLineHeight()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getWidth(String text)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getFontSize()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user