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;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract void renderComponent();
|
|
||||||
|
|
||||||
protected void triggerAction() {
|
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) {
|
public LayoutComponent(AppAccess app, RectBound context) {
|
||||||
this.subModule = new AppSubModule(app);
|
this.subModule = new AppSubModule(app);
|
||||||
setRect(context);
|
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() {
|
public VisualComponent() {
|
||||||
super();
|
super();
|
||||||
|
enableCaching(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -87,7 +88,7 @@ public abstract class VisualComponent extends AbstractRectCache implements Compo
|
|||||||
/**
|
/**
|
||||||
* Draw the component (it's visible)
|
* Draw the component (it's visible)
|
||||||
*/
|
*/
|
||||||
public abstract void renderComponent();
|
protected abstract void renderComponent();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ package mightypork.gamecore.gui.components.painters;
|
|||||||
import mightypork.gamecore.gui.components.VisualComponent;
|
import mightypork.gamecore.gui.components.VisualComponent;
|
||||||
import mightypork.gamecore.render.Render;
|
import mightypork.gamecore.render.Render;
|
||||||
import mightypork.utils.annotations.FactoryMethod;
|
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 {
|
public class QuadPainter extends VisualComponent {
|
||||||
|
|
||||||
@FactoryMethod
|
@FactoryMethod
|
||||||
public static QuadPainter gradH(RGB colorLeft, RGB colorRight)
|
public static QuadPainter gradH(Color colorLeft, Color colorRight)
|
||||||
{
|
{
|
||||||
return new QuadPainter(colorLeft, colorRight, colorRight, colorLeft);
|
return new QuadPainter(colorLeft, colorRight, colorRight, colorLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@FactoryMethod
|
@FactoryMethod
|
||||||
public static QuadPainter gradV(RGB colorTop, RGB colorBottom)
|
public static QuadPainter gradV(Color colorTop, Color colorBottom)
|
||||||
{
|
{
|
||||||
return new QuadPainter(colorTop, colorTop, colorBottom, colorBottom);
|
return new QuadPainter(colorTop, colorTop, colorBottom, colorBottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final RGB colorHMinVMin;
|
private final Color colorHMinVMin;
|
||||||
private final RGB colorHMaxVMin;
|
private final Color colorHMaxVMin;
|
||||||
private final RGB colorHMaxVMax;
|
private final Color colorHMaxVMax;
|
||||||
private final RGB colorHMinVMax;
|
private final Color colorHMinVMax;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,7 +38,7 @@ public class QuadPainter extends VisualComponent {
|
|||||||
*
|
*
|
||||||
* @param color
|
* @param color
|
||||||
*/
|
*/
|
||||||
public QuadPainter(RGB color) {
|
public QuadPainter(Color color) {
|
||||||
this.colorHMinVMin = color;
|
this.colorHMinVMin = color;
|
||||||
this.colorHMaxVMin = color;
|
this.colorHMaxVMin = color;
|
||||||
this.colorHMaxVMax = color;
|
this.colorHMaxVMax = color;
|
||||||
@@ -54,7 +54,7 @@ public class QuadPainter extends VisualComponent {
|
|||||||
* @param colorHMaxVMax
|
* @param colorHMaxVMax
|
||||||
* @param colorHMinVMax
|
* @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.colorHMinVMin = colorHMinVMin;
|
||||||
this.colorHMaxVMin = colorHMaxVMin;
|
this.colorHMaxVMin = colorHMaxVMin;
|
||||||
this.colorHMaxVMax = colorHMaxVMax;
|
this.colorHMaxVMax = colorHMaxVMax;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import mightypork.gamecore.gui.AlignX;
|
|||||||
import mightypork.gamecore.gui.components.VisualComponent;
|
import mightypork.gamecore.gui.components.VisualComponent;
|
||||||
import mightypork.gamecore.render.fonts.FontRenderer;
|
import mightypork.gamecore.render.fonts.FontRenderer;
|
||||||
import mightypork.gamecore.render.fonts.GLFont;
|
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.rect.Rect;
|
||||||
import mightypork.utils.math.constraints.vect.Vect;
|
import mightypork.utils.math.constraints.vect.Vect;
|
||||||
import mightypork.utils.string.StringProvider;
|
import mightypork.utils.string.StringProvider;
|
||||||
@@ -22,12 +22,12 @@ import mightypork.utils.string.StringProvider.StringWrapper;
|
|||||||
public class TextPainter extends VisualComponent {
|
public class TextPainter extends VisualComponent {
|
||||||
|
|
||||||
private final FontRenderer font;
|
private final FontRenderer font;
|
||||||
private RGB color;
|
private Color color;
|
||||||
private AlignX align;
|
private AlignX align;
|
||||||
private StringProvider text;
|
private StringProvider text;
|
||||||
private boolean shadow;
|
private boolean shadow;
|
||||||
|
|
||||||
private RGB shadowColor = RGB.BLACK;
|
private Color shadowColor = Color.BLACK;
|
||||||
private Vect shadowOffset = Vect.make(1, 1);
|
private Vect shadowOffset = Vect.make(1, 1);
|
||||||
|
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ public class TextPainter extends VisualComponent {
|
|||||||
* @param font font to use
|
* @param font font to use
|
||||||
*/
|
*/
|
||||||
public TextPainter(GLFont font) {
|
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 color default color
|
||||||
* @param text drawn text
|
* @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));
|
this(font, align, color, new StringWrapper(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ public class TextPainter extends VisualComponent {
|
|||||||
* @param color default color
|
* @param color default color
|
||||||
* @param text text provider
|
* @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.font = new FontRenderer(font);
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.align = align;
|
this.align = align;
|
||||||
@@ -73,7 +73,7 @@ public class TextPainter extends VisualComponent {
|
|||||||
* @param align text align
|
* @param align text align
|
||||||
* @param color default color
|
* @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);
|
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);
|
setShadow(true);
|
||||||
setShadowColor(color);
|
setShadowColor(color);
|
||||||
@@ -107,7 +107,7 @@ public class TextPainter extends VisualComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setShadowColor(RGB shadowColor)
|
public void setShadowColor(Color shadowColor)
|
||||||
{
|
{
|
||||||
this.shadowColor = 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;
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import java.io.IOException;
|
|||||||
import mightypork.gamecore.render.textures.TxQuad;
|
import mightypork.gamecore.render.textures.TxQuad;
|
||||||
import mightypork.utils.files.FileUtils;
|
import mightypork.utils.files.FileUtils;
|
||||||
import mightypork.utils.logging.Log;
|
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.Rect;
|
||||||
import mightypork.utils.math.constraints.rect.caching.RectDigest;
|
import mightypork.utils.math.constraints.rect.caching.RectDigest;
|
||||||
import mightypork.utils.math.constraints.vect.Vect;
|
import mightypork.utils.math.constraints.vect.Vect;
|
||||||
@@ -36,23 +36,23 @@ public class Render {
|
|||||||
/**
|
/**
|
||||||
* Bind GL color
|
* 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
|
* Bind GL color
|
||||||
*
|
*
|
||||||
* @param color RGB color
|
* @param color Color color
|
||||||
* @param alpha alpha multiplier
|
* @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 rect rectangle
|
||||||
* @param color draw color
|
* @param color draw color
|
||||||
*/
|
*/
|
||||||
public static void quad(Rect rect, RGB color)
|
public static void quad(Rect rect, Color color)
|
||||||
{
|
{
|
||||||
setColor(color);
|
setColor(color);
|
||||||
quad(rect);
|
quad(rect);
|
||||||
@@ -425,7 +425,7 @@ public class Render {
|
|||||||
* @param color1 left color
|
* @param color1 left color
|
||||||
* @param color2 right 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);
|
quadColor(quad, color1, color2, color2, color1);
|
||||||
}
|
}
|
||||||
@@ -440,7 +440,7 @@ public class Render {
|
|||||||
* @param colorHMaxVMax
|
* @param colorHMaxVMax
|
||||||
* @param colorHMinVMax
|
* @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();
|
final RectDigest r = quad.digest();
|
||||||
|
|
||||||
@@ -470,7 +470,7 @@ public class Render {
|
|||||||
* @param color1 top color
|
* @param color1 top color
|
||||||
* @param color2 bottom 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);
|
quadColor(quad, color1, color1, color2, color2);
|
||||||
}
|
}
|
||||||
@@ -484,7 +484,7 @@ public class Render {
|
|||||||
* @param texture texture instance
|
* @param texture texture instance
|
||||||
* @param tint color tint
|
* @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);
|
bindTexture(texture);
|
||||||
setColor(tint);
|
setColor(tint);
|
||||||
@@ -502,7 +502,7 @@ public class Render {
|
|||||||
*/
|
*/
|
||||||
public static void quadTextured(Rect quad, Rect uvs, Texture texture)
|
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)
|
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)
|
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 txquad texture instance
|
||||||
* @param tint color tint
|
* @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);
|
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.AppAdapter;
|
||||||
import mightypork.gamecore.control.bus.events.ResourceLoadRequest;
|
import mightypork.gamecore.control.bus.events.ResourceLoadRequest;
|
||||||
import mightypork.gamecore.render.fonts.impl.DeferredFont;
|
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;
|
import org.newdawn.slick.opengl.Texture;
|
||||||
|
|
||||||
@@ -20,9 +18,6 @@ import org.newdawn.slick.opengl.Texture;
|
|||||||
*/
|
*/
|
||||||
public class FontBank extends AppAdapter {
|
public class FontBank extends AppAdapter {
|
||||||
|
|
||||||
private static final GLFont NULL_FONT = new NullFont();
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param app app access
|
* @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, GLFont> fonts = new HashMap<>();
|
||||||
|
private final HashMap<String, String> aliases = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,6 +54,17 @@ public class FontBank extends AppAdapter {
|
|||||||
fonts.put(key, font);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a loaded {@link Texture}
|
* Get a loaded {@link Texture}
|
||||||
@@ -67,11 +74,12 @@ public class FontBank extends AppAdapter {
|
|||||||
*/
|
*/
|
||||||
public GLFont getFont(String key)
|
public GLFont getFont(String key)
|
||||||
{
|
{
|
||||||
final GLFont f = fonts.get(key);
|
GLFont f = fonts.get(key);
|
||||||
|
|
||||||
|
if(f == null) f = fonts.get(aliases.get(key));
|
||||||
|
|
||||||
if (f == null) {
|
if (f == null) {
|
||||||
Log.w("There's no font called " + key + "!");
|
throw new RuntimeException("There's no font called " + key + "!");
|
||||||
return NULL_FONT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return f;
|
return f;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package mightypork.gamecore.render.fonts;
|
|||||||
|
|
||||||
import mightypork.gamecore.gui.AlignX;
|
import mightypork.gamecore.gui.AlignX;
|
||||||
import mightypork.gamecore.render.Render;
|
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.rect.Rect;
|
||||||
import mightypork.utils.math.constraints.vect.Vect;
|
import mightypork.utils.math.constraints.vect.Vect;
|
||||||
|
|
||||||
@@ -17,14 +17,14 @@ public class FontRenderer {
|
|||||||
|
|
||||||
private GLFont font;
|
private GLFont font;
|
||||||
|
|
||||||
private RGB color;
|
private Color color;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param font used font
|
* @param font used font
|
||||||
*/
|
*/
|
||||||
public FontRenderer(GLFont 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 font used font
|
||||||
* @param color drawing color
|
* @param color drawing color
|
||||||
*/
|
*/
|
||||||
public FontRenderer(GLFont font, RGB color) {
|
public FontRenderer(GLFont font, Color color) {
|
||||||
this.font = font;
|
this.font = font;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
@@ -86,7 +86,7 @@ public class FontRenderer {
|
|||||||
*
|
*
|
||||||
* @param color color
|
* @param color color
|
||||||
*/
|
*/
|
||||||
public void setColor(RGB color)
|
public void setColor(Color color)
|
||||||
{
|
{
|
||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,7 @@ public class FontRenderer {
|
|||||||
* @param height drawing height
|
* @param height drawing height
|
||||||
* @param color drawing color
|
* @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();
|
Render.pushMatrix();
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ public class FontRenderer {
|
|||||||
* @param align horizontal alignment (with respect to bounds)
|
* @param align horizontal alignment (with respect to bounds)
|
||||||
* @param color drawing color
|
* @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;
|
Vect start;
|
||||||
|
|
||||||
@@ -182,7 +182,7 @@ public class FontRenderer {
|
|||||||
* @param align horizontal alignment
|
* @param align horizontal alignment
|
||||||
* @param color drawing color
|
* @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);
|
final double w = getWidth(text, height);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package mightypork.gamecore.render.fonts;
|
package mightypork.gamecore.render.fonts;
|
||||||
|
|
||||||
|
|
||||||
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.Vect;
|
||||||
|
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ public interface GLFont {
|
|||||||
* @param text text to draw
|
* @param text text to draw
|
||||||
* @param color draw color
|
* @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 static org.lwjgl.opengl.GL11.*;
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.FontMetrics;
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.RenderingHints;
|
import java.awt.RenderingHints;
|
||||||
@@ -22,7 +21,7 @@ import java.util.Map;
|
|||||||
import mightypork.gamecore.render.fonts.GLFont;
|
import mightypork.gamecore.render.fonts.GLFont;
|
||||||
import mightypork.gamecore.render.textures.FilterMode;
|
import mightypork.gamecore.render.textures.FilterMode;
|
||||||
import mightypork.utils.logging.Log;
|
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.Vect;
|
||||||
import mightypork.utils.math.constraints.vect.VectConst;
|
import mightypork.utils.math.constraints.vect.VectConst;
|
||||||
|
|
||||||
@@ -141,7 +140,7 @@ public class CachedFont implements GLFont {
|
|||||||
g = (Graphics2D) fontImage.getGraphics();
|
g = (Graphics2D) fontImage.getGraphics();
|
||||||
if (antiAlias == true) g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
if (antiAlias == true) g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
g.setFont(font);
|
g.setFont(font);
|
||||||
g.setColor(Color.WHITE);
|
g.setColor(java.awt.Color.WHITE);
|
||||||
g.drawString(String.valueOf(ch), 0, metrics.getAscent());
|
g.drawString(String.valueOf(ch), 0, metrics.getAscent());
|
||||||
|
|
||||||
return fontImage;
|
return fontImage;
|
||||||
@@ -225,7 +224,7 @@ public class CachedFont implements GLFont {
|
|||||||
BufferedImage imag = new BufferedImage(textureWidth, textureHeight, BufferedImage.TYPE_INT_ARGB);
|
BufferedImage imag = new BufferedImage(textureWidth, textureHeight, BufferedImage.TYPE_INT_ARGB);
|
||||||
final Graphics2D g = (Graphics2D) imag.getGraphics();
|
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);
|
g.fillRect(0, 0, textureWidth, textureHeight);
|
||||||
|
|
||||||
int rowHeight = 0, posX = 0, posY = 0;
|
int rowHeight = 0, posX = 0, posY = 0;
|
||||||
@@ -392,14 +391,14 @@ public class CachedFont implements GLFont {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(String text, RGB color)
|
public void draw(String text, Color color)
|
||||||
{
|
{
|
||||||
GLUtils.checkGLContext();
|
GLUtils.checkGLContext();
|
||||||
|
|
||||||
glPushAttrib(GL_ENABLE_BIT);
|
glPushAttrib(GL_ENABLE_BIT);
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glBindTexture(GL_TEXTURE_2D, textureID);
|
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);
|
glBegin(GL_QUADS);
|
||||||
|
|
||||||
CharTile chtx = null;
|
CharTile chtx = null;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import mightypork.gamecore.render.fonts.GLFont;
|
|||||||
import mightypork.gamecore.render.textures.FilterMode;
|
import mightypork.gamecore.render.textures.FilterMode;
|
||||||
import mightypork.utils.annotations.Alias;
|
import mightypork.utils.annotations.Alias;
|
||||||
import mightypork.utils.files.FileUtils;
|
import mightypork.utils.files.FileUtils;
|
||||||
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.Vect;
|
||||||
|
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ public class DeferredFont extends DeferredResource implements GLFont {
|
|||||||
* @param color draw color
|
* @param color draw color
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void draw(String str, RGB color)
|
public void draw(String str, Color color)
|
||||||
{
|
{
|
||||||
if (!ensureLoaded()) return;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -60,12 +60,15 @@ public class Res {
|
|||||||
font = new DeferredFont("/res/font/PolygonPixel5x7Standard.ttf", Glyphs.basic, 16);
|
font = new DeferredFont("/res/font/PolygonPixel5x7Standard.ttf", Glyphs.basic, 16);
|
||||||
font.setAntialias(true);
|
font.setAntialias(true);
|
||||||
font.setFilter(FilterMode.NEAREST);
|
font.setFilter(FilterMode.NEAREST);
|
||||||
fonts.loadFont("default", font);
|
fonts.loadFont("polygon_pixel", font);
|
||||||
|
|
||||||
font = new DeferredFont("/res/font/PressStart2P.ttf", Glyphs.basic, 16);
|
font = new DeferredFont("/res/font/PressStart2P.ttf", Glyphs.basic, 16);
|
||||||
font.setAntialias(true);
|
font.setAntialias(true);
|
||||||
font.setFilter(FilterMode.NEAREST);
|
font.setFilter(FilterMode.NEAREST);
|
||||||
fonts.loadFont("press_start", font);
|
fonts.loadFont("press_start", font);
|
||||||
|
|
||||||
|
fonts.addAlias("default", "polygon_pixel");
|
||||||
|
fonts.addAlias("main_menu_button", "press_start");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import mightypork.gamecore.input.KeyStroke;
|
|||||||
import mightypork.gamecore.input.Keys;
|
import mightypork.gamecore.input.Keys;
|
||||||
import mightypork.gamecore.render.fonts.GLFont;
|
import mightypork.gamecore.render.fonts.GLFont;
|
||||||
import mightypork.rogue.Res;
|
import mightypork.rogue.Res;
|
||||||
import mightypork.utils.math.color.RGB;
|
import mightypork.utils.math.color.Color;
|
||||||
import mightypork.utils.math.constraints.rect.proxy.RectBound;
|
import mightypork.utils.math.constraints.rect.proxy.RectBound;
|
||||||
import mightypork.utils.math.constraints.vect.Vect;
|
import mightypork.utils.math.constraints.vect.Vect;
|
||||||
import mightypork.utils.string.StringProvider;
|
import mightypork.utils.string.StringProvider;
|
||||||
@@ -40,7 +40,7 @@ public class LayerFps extends ScreenLayer {
|
|||||||
|
|
||||||
final RectBound constraint = root.topRight().add(-8, 8).expand(0, 0, 0, 32);
|
final RectBound constraint = root.topRight().add(-8, 8).expand(0, 0, 0, 32);
|
||||||
|
|
||||||
tp = new TextPainter(font, AlignX.RIGHT, RGB.WHITE, new StringProvider() {
|
tp = new TextPainter(font, AlignX.RIGHT, Color.WHITE, new StringProvider() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getString()
|
public String getString()
|
||||||
@@ -50,7 +50,7 @@ public class LayerFps extends ScreenLayer {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tp.setRect(constraint);
|
tp.setRect(constraint);
|
||||||
tp.setShadow(RGB.BLACK, Vect.make(tp.height().div(16)));
|
tp.setShadow(Color.BLACK, Vect.make(tp.height().div(16)));
|
||||||
|
|
||||||
root.add(tp);
|
root.add(tp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package mightypork.rogue.screens.main_menu;
|
||||||
|
|
||||||
|
import mightypork.gamecore.gui.AlignX;
|
||||||
|
import mightypork.gamecore.gui.components.ClickableComponent;
|
||||||
|
import mightypork.gamecore.gui.components.painters.TextPainter;
|
||||||
|
import mightypork.gamecore.render.fonts.GLFont;
|
||||||
|
import mightypork.rogue.Res;
|
||||||
|
import mightypork.utils.math.color.Color;
|
||||||
|
|
||||||
|
|
||||||
|
class MenuButton extends ClickableComponent {
|
||||||
|
|
||||||
|
private static GLFont font = Res.getFont("main_menu_button");
|
||||||
|
private TextPainter painter;
|
||||||
|
|
||||||
|
public MenuButton(String text, Color color) {
|
||||||
|
this.painter = new TextPainter(font, AlignX.CENTER, color, text);
|
||||||
|
painter.setRect(this.shrink(this.height().perc(5)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void renderComponent()
|
||||||
|
{
|
||||||
|
painter.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
package mightypork.rogue.screens.main_menu;
|
package mightypork.rogue.screens.main_menu;
|
||||||
|
|
||||||
|
import java.net.Authenticator.RequestorType;
|
||||||
|
|
||||||
|
import mightypork.gamecore.control.bus.events.ScreenRequestEvent;
|
||||||
|
import mightypork.gamecore.gui.Action;
|
||||||
import mightypork.gamecore.gui.AlignX;
|
import mightypork.gamecore.gui.AlignX;
|
||||||
import mightypork.gamecore.gui.AlignY;
|
import mightypork.gamecore.gui.AlignY;
|
||||||
import mightypork.gamecore.gui.components.layout.VerticalFixedFlowLayout;
|
import mightypork.gamecore.gui.components.layout.VerticalFixedFlowLayout;
|
||||||
@@ -8,7 +12,9 @@ import mightypork.gamecore.gui.screens.Screen;
|
|||||||
import mightypork.gamecore.gui.screens.ScreenLayer;
|
import mightypork.gamecore.gui.screens.ScreenLayer;
|
||||||
import mightypork.gamecore.render.fonts.GLFont;
|
import mightypork.gamecore.render.fonts.GLFont;
|
||||||
import mightypork.rogue.Res;
|
import mightypork.rogue.Res;
|
||||||
import mightypork.utils.math.color.RGB;
|
import mightypork.rogue.events.ActionRequest;
|
||||||
|
import mightypork.rogue.events.ActionRequest.RequestType;
|
||||||
|
import mightypork.utils.math.color.Color;
|
||||||
import mightypork.utils.math.constraints.num.Num;
|
import mightypork.utils.math.constraints.num.Num;
|
||||||
import mightypork.utils.math.constraints.rect.Rect;
|
import mightypork.utils.math.constraints.rect.Rect;
|
||||||
|
|
||||||
@@ -25,16 +31,54 @@ class MenuLayer extends ScreenLayer {
|
|||||||
{
|
{
|
||||||
Rect menuBox = root.shrink(root.height().min(root.width()).mul(0.1));
|
Rect menuBox = root.shrink(root.height().min(root.width()).mul(0.1));
|
||||||
|
|
||||||
Num lineHeight = menuBox.height().min(menuBox.width()).mul(0.13);
|
Num lineHeight = menuBox.height().min(menuBox.width()).mul(0.1);
|
||||||
|
|
||||||
VerticalFixedFlowLayout layout = new VerticalFixedFlowLayout(root, menuBox, lineHeight, AlignY.TOP);
|
VerticalFixedFlowLayout layout = new VerticalFixedFlowLayout(root, menuBox, lineHeight, AlignY.TOP);
|
||||||
root.add(layout);
|
root.add(layout);
|
||||||
|
|
||||||
GLFont f = Res.getFont("press_start");
|
GLFont f = Res.getFont("press_start");
|
||||||
layout.add(new TextPainter(f, AlignX.CENTER, RGB.WHITE, "Hello!"));
|
MenuButton b1,b2,b3,b4;
|
||||||
layout.add(new TextPainter(f, AlignX.CENTER, RGB.CYAN, "Woof Woof"));
|
layout.add(b1 = new MenuButton("Render test", Color.WHITE));
|
||||||
layout.add(new TextPainter(f, AlignX.CENTER, RGB.PURPLE, "MooooOOoOO"));
|
layout.add(b2 = new MenuButton("Bouncy Cubes", Color.CYAN));
|
||||||
layout.add(new TextPainter(f, AlignX.CENTER, RGB.GREEN, "Bye!"));
|
layout.add(b3 = new MenuButton("Flying Cat",Color.MAGENTA));
|
||||||
|
layout.add(b4 = new MenuButton("Bye!", Color.GREEN));
|
||||||
|
|
||||||
|
b1.setAction(new Action() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute()
|
||||||
|
{
|
||||||
|
getEventBus().send(new ScreenRequestEvent("test.render"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
b2.setAction(new Action() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute()
|
||||||
|
{
|
||||||
|
getEventBus().send(new ScreenRequestEvent("test.bouncy"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
b3.setAction(new Action() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute()
|
||||||
|
{
|
||||||
|
getEventBus().send(new ScreenRequestEvent("test.cat"));
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
b4.setAction(new Action() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute()
|
||||||
|
{
|
||||||
|
getEventBus().send(new ActionRequest(RequestType.SHUTDOWN));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import mightypork.gamecore.control.timing.Updateable;
|
|||||||
import mightypork.gamecore.gui.components.VisualComponent;
|
import mightypork.gamecore.gui.components.VisualComponent;
|
||||||
import mightypork.gamecore.render.Render;
|
import mightypork.gamecore.render.Render;
|
||||||
import mightypork.utils.math.Easing;
|
import mightypork.utils.math.Easing;
|
||||||
import mightypork.utils.math.color.RGB;
|
import mightypork.utils.math.color.Color;
|
||||||
import mightypork.utils.math.constraints.num.Num;
|
import mightypork.utils.math.constraints.num.Num;
|
||||||
import mightypork.utils.math.constraints.num.mutable.NumAnimated;
|
import mightypork.utils.math.constraints.num.mutable.NumAnimated;
|
||||||
import mightypork.utils.math.constraints.rect.Rect;
|
import mightypork.utils.math.constraints.rect.Rect;
|
||||||
@@ -24,6 +24,7 @@ public class BouncyBox extends VisualComponent implements Updateable {
|
|||||||
|
|
||||||
|
|
||||||
public BouncyBox() {
|
public BouncyBox() {
|
||||||
|
super();
|
||||||
enableCaching(true);
|
enableCaching(true);
|
||||||
|
|
||||||
Rect abox;
|
Rect abox;
|
||||||
@@ -39,7 +40,7 @@ public class BouncyBox extends VisualComponent implements Updateable {
|
|||||||
@Override
|
@Override
|
||||||
public void renderComponent()
|
public void renderComponent()
|
||||||
{
|
{
|
||||||
Render.quad(box, RGB.GREEN);
|
Render.quad(box, Color.GREEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import mightypork.gamecore.gui.screens.ScreenLayer;
|
|||||||
import mightypork.gamecore.input.KeyStroke;
|
import mightypork.gamecore.input.KeyStroke;
|
||||||
import mightypork.gamecore.input.Keys;
|
import mightypork.gamecore.input.Keys;
|
||||||
import mightypork.rogue.Res;
|
import mightypork.rogue.Res;
|
||||||
import mightypork.utils.math.color.RGB;
|
import mightypork.utils.math.color.Color;
|
||||||
import mightypork.utils.math.constraints.num.Num;
|
import mightypork.utils.math.constraints.num.Num;
|
||||||
import mightypork.utils.math.constraints.vect.Vect;
|
import mightypork.utils.math.constraints.vect.Vect;
|
||||||
|
|
||||||
@@ -54,10 +54,10 @@ public class LayerBouncyBoxes extends ScreenLayer {
|
|||||||
boxes.add(bbr);
|
boxes.add(bbr);
|
||||||
}
|
}
|
||||||
|
|
||||||
final TextPainter tp = new TextPainter(Res.getFont("default"), AlignX.LEFT, RGB.WHITE);
|
final TextPainter tp = new TextPainter(Res.getFont("default"), AlignX.LEFT, Color.WHITE);
|
||||||
tp.setText("Press \"C\" for \"Cat\" screen.");
|
tp.setText("Press \"C\" for \"Cat\" screen.");
|
||||||
final Num shadowOffset = tp.height().div(16);
|
final Num shadowOffset = tp.height().div(16);
|
||||||
tp.setShadow(RGB.RED, Vect.make(shadowOffset, shadowOffset));
|
tp.setShadow(Color.RED, Vect.make(shadowOffset, shadowOffset));
|
||||||
|
|
||||||
layout.add(tp);
|
layout.add(tp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package mightypork.rogue.screens.test_cat_sound;
|
||||||
|
|
||||||
|
import mightypork.gamecore.gui.components.painters.QuadPainter;
|
||||||
|
import mightypork.gamecore.gui.screens.Screen;
|
||||||
|
import mightypork.gamecore.gui.screens.ScreenLayer;
|
||||||
|
import mightypork.utils.math.color.Color;
|
||||||
|
|
||||||
|
|
||||||
|
public class LayerColor extends ScreenLayer{
|
||||||
|
|
||||||
|
public LayerColor(Screen screen, Color color) {
|
||||||
|
super(screen);
|
||||||
|
|
||||||
|
root.add(new QuadPainter(color));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPriority()
|
||||||
|
{
|
||||||
|
return Integer.MIN_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -15,7 +15,7 @@ import mightypork.gamecore.input.KeyStroke;
|
|||||||
import mightypork.gamecore.input.Keys;
|
import mightypork.gamecore.input.Keys;
|
||||||
import mightypork.rogue.Res;
|
import mightypork.rogue.Res;
|
||||||
import mightypork.utils.math.Easing;
|
import mightypork.utils.math.Easing;
|
||||||
import mightypork.utils.math.color.RGB;
|
import mightypork.utils.math.color.Color;
|
||||||
import mightypork.utils.math.constraints.num.Num;
|
import mightypork.utils.math.constraints.num.Num;
|
||||||
import mightypork.utils.math.constraints.num.mutable.NumAnimated;
|
import mightypork.utils.math.constraints.num.mutable.NumAnimated;
|
||||||
import mightypork.utils.math.constraints.rect.Rect;
|
import mightypork.utils.math.constraints.rect.Rect;
|
||||||
@@ -48,12 +48,12 @@ public class LayerFlyingCat extends ScreenLayer implements MouseButtonEvent.List
|
|||||||
cat.enableCaching(false);
|
cat.enableCaching(false);
|
||||||
|
|
||||||
// frame around cat
|
// frame around cat
|
||||||
QuadPainter cat_frame = QuadPainter.gradV(RGB.YELLOW, RGB.RED);
|
QuadPainter cat_frame = QuadPainter.gradV(Color.YELLOW, Color.RED);
|
||||||
cat_frame.setRect(cat.grow(cat.height().mul(0.05)));
|
cat_frame.setRect(cat.grow(cat.height().mul(0.05)));
|
||||||
cat_frame.enableCaching(false);
|
cat_frame.enableCaching(false);
|
||||||
|
|
||||||
// frame shadow
|
// frame shadow
|
||||||
QuadPainter cat_shadow = new QuadPainter(RGB.dark(0.4));
|
QuadPainter cat_shadow = new QuadPainter(Color.dark(0.4));
|
||||||
cat_shadow.setRect(cat_frame.move(Vect.make(cat.height().mul(0.05))));
|
cat_shadow.setRect(cat_frame.move(Vect.make(cat.height().mul(0.05))));
|
||||||
cat_shadow.enableCaching(false);
|
cat_shadow.enableCaching(false);
|
||||||
|
|
||||||
@@ -66,9 +66,9 @@ public class LayerFlyingCat extends ScreenLayer implements MouseButtonEvent.List
|
|||||||
// Meow
|
// Meow
|
||||||
TextPainter tp = new TextPainter(Res.getFont("press_start"));
|
TextPainter tp = new TextPainter(Res.getFont("press_start"));
|
||||||
tp.setAlign(AlignX.CENTER);
|
tp.setAlign(AlignX.CENTER);
|
||||||
tp.setColor(RGB.YELLOW);
|
tp.setColor(Color.YELLOW);
|
||||||
tp.setText("Meow!");
|
tp.setText("Meow!");
|
||||||
tp.setShadow(RGB.dark(0.5), Vect.make(tp.height().div(16)));
|
tp.setShadow(Color.dark(0.5), Vect.make(tp.height().div(16)));
|
||||||
tp.setRect(Rect.make(cat.height().half()).centerTo(mouse));
|
tp.setRect(Rect.make(cat.height().half()).centerTo(mouse));
|
||||||
tp.enableCaching(false);
|
tp.enableCaching(false);
|
||||||
root.add(tp);
|
root.add(tp);
|
||||||
|
|||||||
@@ -61,12 +61,4 @@ public class ScreenTestCat extends LayeredScreen {
|
|||||||
{
|
{
|
||||||
return "test.cat";
|
return "test.cat";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void renderScreen()
|
|
||||||
{
|
|
||||||
|
|
||||||
super.renderScreen();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ package mightypork.rogue.screens.test_render;
|
|||||||
import mightypork.gamecore.gui.screens.Screen;
|
import mightypork.gamecore.gui.screens.Screen;
|
||||||
import mightypork.gamecore.gui.screens.ScreenLayer;
|
import mightypork.gamecore.gui.screens.ScreenLayer;
|
||||||
import mightypork.gamecore.render.Render;
|
import mightypork.gamecore.render.Render;
|
||||||
import mightypork.utils.math.color.RGB;
|
import mightypork.utils.math.color.Color;
|
||||||
import mightypork.utils.math.constraints.rect.proxy.RectBound;
|
import mightypork.utils.math.constraints.rect.proxy.RectBound;
|
||||||
|
|
||||||
|
|
||||||
@@ -25,9 +25,9 @@ public class LayerTestGradient extends ScreenLayer {
|
|||||||
@Override
|
@Override
|
||||||
protected void renderLayer()
|
protected void renderLayer()
|
||||||
{
|
{
|
||||||
Render.quadColor(root, RGB.WHITE, RGB.BLUE, RGB.BLACK, RGB.PURPLE);
|
Render.quadColor(root, Color.WHITE, Color.BLUE, Color.BLACK, Color.MAGENTA);
|
||||||
Render.quadGradH(pos1.getRect(), RGB.GREEN, RGB.RED);
|
Render.quadGradH(pos1.getRect(), Color.GREEN, Color.RED);
|
||||||
Render.quadGradV(pos2.getRect(), RGB.WHITE, RGB.PURPLE);
|
Render.quadGradV(pos2.getRect(), Color.WHITE, Color.MAGENTA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ public class ScreenTestRender extends LayeredScreen {
|
|||||||
|
|
||||||
addLayer(new LayerFps(this));
|
addLayer(new LayerFps(this));
|
||||||
addLayer(new LayerTestGradient(this));
|
addLayer(new LayerTestGradient(this));
|
||||||
addLayer(new LayerFlyingCat(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,144 @@
|
|||||||
|
package mightypork.utils.math.color;
|
||||||
|
|
||||||
|
|
||||||
|
import mightypork.utils.annotations.FactoryMethod;
|
||||||
|
import mightypork.utils.math.Calc;
|
||||||
|
import mightypork.utils.math.constraints.num.Num;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Color.<br>
|
||||||
|
* All values are 0-1
|
||||||
|
*
|
||||||
|
* @author MightyPork
|
||||||
|
*/
|
||||||
|
public abstract class Color {
|
||||||
|
|
||||||
|
public static final Color NONE = rgba(0, 0, 0, 0);
|
||||||
|
public static final Color SHADOW = rgba(0, 0, 0, 0.5);
|
||||||
|
|
||||||
|
public static final Color WHITE = rgb(1, 1, 1);
|
||||||
|
public static final Color BLACK = rgb(0, 0, 0);
|
||||||
|
public static final Color DARK_GRAY = rgb(0.25, 0.25, 0.25);
|
||||||
|
public static final Color GRAY = rgb(0.5, 0.5, 0.5);
|
||||||
|
public static final Color LIGHT_GRAY = rgb(0.75, 0.75, 0.75);
|
||||||
|
|
||||||
|
public static final Color RED = rgb(1, 0, 0);
|
||||||
|
public static final Color GREEN = rgb(0, 1, 0);
|
||||||
|
public static final Color BLUE = rgb(0, 0, 1);
|
||||||
|
|
||||||
|
public static final Color YELLOW = rgb(1, 1, 0);
|
||||||
|
public static final Color MAGENTA = rgb(1, 0, 1);
|
||||||
|
public static final Color CYAN = rgb(0, 1, 1);
|
||||||
|
|
||||||
|
public static final Color ORANGE = rgb(1, 0.78, 0);
|
||||||
|
public static final Color PINK = rgb(1, 0.68, 0.68);
|
||||||
|
|
||||||
|
@FactoryMethod
|
||||||
|
public static final Color rgb(double r, double g, double b)
|
||||||
|
{
|
||||||
|
return rgba(Num.make(r), Num.make(g), Num.make(b), Num.ONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FactoryMethod
|
||||||
|
public static final Color rgba(double r, double g, double b, double a)
|
||||||
|
{
|
||||||
|
return rgba(Num.make(r), Num.make(g), Num.make(b), Num.make(a));
|
||||||
|
}
|
||||||
|
|
||||||
|
@FactoryMethod
|
||||||
|
public static final Color rgba(Num r, Num g, Num b)
|
||||||
|
{
|
||||||
|
return rgba(r, g, b, Num.ONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FactoryMethod
|
||||||
|
public static final Color rgba(Num r, Num g, Num b, Num a)
|
||||||
|
{
|
||||||
|
return new ColorRgb(r, g, b, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FactoryMethod
|
||||||
|
public static final Color hsb(double h, double s, double b)
|
||||||
|
{
|
||||||
|
return hsba(Num.make(h), Num.make(s), Num.make(b), Num.ONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FactoryMethod
|
||||||
|
public static final Color hsba(double h, double s, double b, double a)
|
||||||
|
{
|
||||||
|
return hsba(Num.make(h), Num.make(s), Num.make(b), Num.make(a));
|
||||||
|
}
|
||||||
|
|
||||||
|
@FactoryMethod
|
||||||
|
public static final Color hsb(Num h, Num s, Num b)
|
||||||
|
{
|
||||||
|
return hsba(h, s, b, Num.ONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FactoryMethod
|
||||||
|
public static final Color hsba(Num h, Num s, Num b, Num a)
|
||||||
|
{
|
||||||
|
return new ColorHsb(h, s, b, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FactoryMethod
|
||||||
|
public static final Color light(double a)
|
||||||
|
{
|
||||||
|
return light(Num.make(a));
|
||||||
|
}
|
||||||
|
|
||||||
|
@FactoryMethod
|
||||||
|
public static final Color light(Num a)
|
||||||
|
{
|
||||||
|
return rgba(Num.ONE, Num.ONE, Num.ONE, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FactoryMethod
|
||||||
|
public static final Color dark(double a)
|
||||||
|
{
|
||||||
|
return dark(Num.make(a));
|
||||||
|
}
|
||||||
|
|
||||||
|
@FactoryMethod
|
||||||
|
public static final Color dark(Num a)
|
||||||
|
{
|
||||||
|
return rgba(Num.ZERO, Num.ZERO, Num.ZERO, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected static final double clamp(Num n)
|
||||||
|
{
|
||||||
|
return Calc.clampd(n.value(), 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected static final double clamp(double n)
|
||||||
|
{
|
||||||
|
return Calc.clampd(n, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return red 0-1
|
||||||
|
*/
|
||||||
|
public abstract double red();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return green 0-1
|
||||||
|
*/
|
||||||
|
public abstract double green();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return blue 0-1
|
||||||
|
*/
|
||||||
|
public abstract double blue();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return alpha 0-1
|
||||||
|
*/
|
||||||
|
public abstract double alpha();
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package mightypork.utils.math.color;
|
||||||
|
|
||||||
|
import mightypork.utils.math.constraints.num.Num;
|
||||||
|
|
||||||
|
|
||||||
|
public class ColorHsb extends Color {
|
||||||
|
|
||||||
|
private final Num h;
|
||||||
|
private final Num s;
|
||||||
|
private final Num b;
|
||||||
|
private final Num a;
|
||||||
|
|
||||||
|
|
||||||
|
public ColorHsb(Num h, Num s, Num b, Num a) {
|
||||||
|
this.h = h;
|
||||||
|
this.s = s;
|
||||||
|
this.b = b;
|
||||||
|
this.a = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private double[] asRgb()
|
||||||
|
{
|
||||||
|
final int hex = java.awt.Color.HSBtoRGB((float) clamp(h), (float) clamp(s), (float) clamp(b));
|
||||||
|
|
||||||
|
final int bi = hex & 0xff;
|
||||||
|
final int gi = (hex >> 8) & 0xff;
|
||||||
|
final int ri = (hex >> 16) & 0xff;
|
||||||
|
return new double[] { ri / 255D, gi / 255D, bi / 255D, clamp(a) };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double red()
|
||||||
|
{
|
||||||
|
return asRgb()[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double green()
|
||||||
|
{
|
||||||
|
return asRgb()[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double blue()
|
||||||
|
{
|
||||||
|
return asRgb()[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double alpha()
|
||||||
|
{
|
||||||
|
return asRgb()[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package mightypork.utils.math.color;
|
||||||
|
|
||||||
|
import mightypork.utils.math.constraints.num.Num;
|
||||||
|
|
||||||
|
|
||||||
|
public class ColorRgb extends Color {
|
||||||
|
|
||||||
|
private final Num r;
|
||||||
|
private final Num g;
|
||||||
|
private final Num b;
|
||||||
|
private final Num a;
|
||||||
|
|
||||||
|
|
||||||
|
public ColorRgb(Num r, Num g, Num b, Num a) {
|
||||||
|
this.r = r;
|
||||||
|
this.g = g;
|
||||||
|
this.b = b;
|
||||||
|
this.a = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double red()
|
||||||
|
{
|
||||||
|
return clamp(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double green()
|
||||||
|
{
|
||||||
|
return clamp(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double blue()
|
||||||
|
{
|
||||||
|
return clamp(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double alpha()
|
||||||
|
{
|
||||||
|
return clamp(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,178 +0,0 @@
|
|||||||
package mightypork.utils.math.color;
|
|
||||||
|
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
|
|
||||||
import mightypork.utils.math.Calc;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HSV color
|
|
||||||
*
|
|
||||||
* @author MightyPork
|
|
||||||
*/
|
|
||||||
public class HSV {
|
|
||||||
|
|
||||||
/** H */
|
|
||||||
public double h;
|
|
||||||
/** S */
|
|
||||||
public double s;
|
|
||||||
/** V */
|
|
||||||
public double v;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create black color 0,0,0
|
|
||||||
*/
|
|
||||||
public HSV() {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Color from HSV 0-1
|
|
||||||
*
|
|
||||||
* @param h
|
|
||||||
* @param s
|
|
||||||
* @param v
|
|
||||||
*/
|
|
||||||
public HSV(Number h, Number s, Number v) {
|
|
||||||
this.h = h.doubleValue();
|
|
||||||
this.s = s.doubleValue();
|
|
||||||
this.v = v.doubleValue();
|
|
||||||
norm();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return hue 0-1
|
|
||||||
*/
|
|
||||||
public double h()
|
|
||||||
{
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return saturation 0-1
|
|
||||||
*/
|
|
||||||
public double s()
|
|
||||||
{
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return value/brightness 0-1
|
|
||||||
*/
|
|
||||||
public double v()
|
|
||||||
{
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set color to other color
|
|
||||||
*
|
|
||||||
* @param copied copied color
|
|
||||||
* @return this
|
|
||||||
*/
|
|
||||||
public HSV setTo(HSV copied)
|
|
||||||
{
|
|
||||||
h = copied.h;
|
|
||||||
s = copied.s;
|
|
||||||
v = copied.v;
|
|
||||||
|
|
||||||
norm();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set to H,S,V 0-1
|
|
||||||
*
|
|
||||||
* @param h hue
|
|
||||||
* @param s saturation
|
|
||||||
* @param v value
|
|
||||||
* @return this
|
|
||||||
*/
|
|
||||||
public HSV setTo(Number h, Number s, Number v)
|
|
||||||
{
|
|
||||||
this.h = h.doubleValue();
|
|
||||||
this.s = s.doubleValue();
|
|
||||||
this.v = v.doubleValue();
|
|
||||||
norm();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fix numbers out of range 0-1
|
|
||||||
*/
|
|
||||||
public void norm()
|
|
||||||
{
|
|
||||||
h = Calc.clampd(h, 0, 1);
|
|
||||||
s = Calc.clampd(s, 0, 1);
|
|
||||||
v = Calc.clampd(v, 0, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert to RGB
|
|
||||||
*
|
|
||||||
* @return RGB representation
|
|
||||||
*/
|
|
||||||
public RGB toRGB()
|
|
||||||
{
|
|
||||||
norm();
|
|
||||||
|
|
||||||
final int rgb = Color.HSBtoRGB((float) h, (float) s, (float) v);
|
|
||||||
|
|
||||||
return RGB.fromHex(rgb);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Make from RGB
|
|
||||||
*
|
|
||||||
* @param color RGB
|
|
||||||
* @return HSV
|
|
||||||
*/
|
|
||||||
public static HSV fromRGB(RGB color)
|
|
||||||
{
|
|
||||||
return color.toHSV();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
return "HSV[" + h + ";" + s + ";" + v + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj)
|
|
||||||
{
|
|
||||||
if (obj == null) return false;
|
|
||||||
if (!(obj instanceof HSV)) return false;
|
|
||||||
return ((HSV) obj).h == h && ((HSV) obj).s == s && ((HSV) obj).v == v;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode()
|
|
||||||
{
|
|
||||||
return Double.valueOf(h).hashCode() ^ Double.valueOf(s).hashCode() ^ Double.valueOf(v).hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a copy
|
|
||||||
*
|
|
||||||
* @return copy
|
|
||||||
*/
|
|
||||||
public HSV copy()
|
|
||||||
{
|
|
||||||
return new HSV().setTo(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,399 +0,0 @@
|
|||||||
package mightypork.utils.math.color;
|
|
||||||
|
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
|
|
||||||
import mightypork.utils.annotations.FactoryMethod;
|
|
||||||
import mightypork.utils.math.Calc;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RGB color
|
|
||||||
*
|
|
||||||
* @author MightyPork
|
|
||||||
*/
|
|
||||||
public class RGB {
|
|
||||||
|
|
||||||
/** White */
|
|
||||||
public static final RGB WHITE = new RGB(1, 1, 1);
|
|
||||||
/** Black */
|
|
||||||
public static final RGB BLACK = new RGB(0, 0, 0);
|
|
||||||
/** Red */
|
|
||||||
public static final RGB RED = new RGB(1, 0, 0);
|
|
||||||
/** Lime green */
|
|
||||||
public static final RGB GREEN = new RGB(0, 1, 0);
|
|
||||||
/** Blue */
|
|
||||||
public static final RGB BLUE = new RGB(0, 0, 1);
|
|
||||||
/** Yellow */
|
|
||||||
public static final RGB YELLOW = new RGB(1, 1, 0);
|
|
||||||
/** Purple */
|
|
||||||
public static final RGB PURPLE = new RGB(1, 0, 1);
|
|
||||||
/** Cyan */
|
|
||||||
public static final RGB CYAN = new RGB(0, 1, 1);
|
|
||||||
/** orange */
|
|
||||||
public static final RGB ORANGE = new RGB(1, 0.6, 0);
|
|
||||||
/** no color (alpha=0) */
|
|
||||||
public static final RGB TRANSPARENT = new RGB(0, 0, 0, 0);
|
|
||||||
|
|
||||||
/** R */
|
|
||||||
public double r;
|
|
||||||
/** G */
|
|
||||||
public double g;
|
|
||||||
/** B */
|
|
||||||
public double b;
|
|
||||||
/** ALPHA */
|
|
||||||
public double a = 1;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create black color 0,0,0
|
|
||||||
*/
|
|
||||||
public RGB() {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get copy with custom alpha
|
|
||||||
*
|
|
||||||
* @param alpha alpha to set
|
|
||||||
* @return copy w/ alpha
|
|
||||||
*/
|
|
||||||
public RGB setAlpha(double alpha)
|
|
||||||
{
|
|
||||||
return copy().setAlpha_ip(alpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set alpha IP
|
|
||||||
*
|
|
||||||
* @param alpha alpha to set
|
|
||||||
* @return this
|
|
||||||
*/
|
|
||||||
public RGB setAlpha_ip(double alpha)
|
|
||||||
{
|
|
||||||
a = alpha;
|
|
||||||
norm();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get copy.
|
|
||||||
*
|
|
||||||
* @return copy
|
|
||||||
*/
|
|
||||||
public RGB copy()
|
|
||||||
{
|
|
||||||
return new RGB(r, g, b, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get copy with alpha multiplied by custom value
|
|
||||||
*
|
|
||||||
* @param alpha alpha to set
|
|
||||||
* @return copy w/ alpha
|
|
||||||
*/
|
|
||||||
public RGB mulAlpha(double alpha)
|
|
||||||
{
|
|
||||||
return copy().mulAlpha_ip(alpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Multiply alpha by given number
|
|
||||||
*
|
|
||||||
* @param alpha alpha multiplier
|
|
||||||
* @return this
|
|
||||||
*/
|
|
||||||
public RGB mulAlpha_ip(double alpha)
|
|
||||||
{
|
|
||||||
a *= alpha;
|
|
||||||
norm();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Color from RGB 0-1
|
|
||||||
*
|
|
||||||
* @param r red
|
|
||||||
* @param g green
|
|
||||||
* @param b blue
|
|
||||||
*/
|
|
||||||
public RGB(Number r, Number g, Number b) {
|
|
||||||
this.r = r.doubleValue();
|
|
||||||
this.g = g.doubleValue();
|
|
||||||
this.b = b.doubleValue();
|
|
||||||
norm();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Color from RGB 0-1
|
|
||||||
*
|
|
||||||
* @param r red
|
|
||||||
* @param g green
|
|
||||||
* @param b blue
|
|
||||||
* @param a alpha
|
|
||||||
*/
|
|
||||||
public RGB(Number r, Number g, Number b, Number a) {
|
|
||||||
this.r = r.doubleValue();
|
|
||||||
this.g = g.doubleValue();
|
|
||||||
this.b = b.doubleValue();
|
|
||||||
this.a = a.doubleValue();
|
|
||||||
norm();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Color from hex 0xRRGGBB
|
|
||||||
*
|
|
||||||
* @param hex hex integer
|
|
||||||
*/
|
|
||||||
public RGB(int hex) {
|
|
||||||
setTo(RGB.fromHex(hex));
|
|
||||||
norm();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Color from hex 0xRRGGBB
|
|
||||||
*
|
|
||||||
* @param hex hex integer
|
|
||||||
* @param alpha alpha color
|
|
||||||
*/
|
|
||||||
public RGB(int hex, double alpha) {
|
|
||||||
setTo(RGB.fromHex(hex));
|
|
||||||
a = alpha;
|
|
||||||
norm();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Color from other RGB and alpha channel
|
|
||||||
*
|
|
||||||
* @param color other RGB color
|
|
||||||
* @param alpha new alpha channel
|
|
||||||
*/
|
|
||||||
public RGB(RGB color, double alpha) {
|
|
||||||
setTo(color);
|
|
||||||
setAlpha_ip(alpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return red channel 0-1
|
|
||||||
*/
|
|
||||||
public double r()
|
|
||||||
{
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return green channel 0-1
|
|
||||||
*/
|
|
||||||
public double g()
|
|
||||||
{
|
|
||||||
return g;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return blue channel 0-1
|
|
||||||
*/
|
|
||||||
public double b()
|
|
||||||
{
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return alpha 0-1
|
|
||||||
*/
|
|
||||||
public double a()
|
|
||||||
{
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set color to other color
|
|
||||||
*
|
|
||||||
* @param copied copied color
|
|
||||||
* @return this
|
|
||||||
*/
|
|
||||||
public RGB setTo(RGB copied)
|
|
||||||
{
|
|
||||||
r = copied.r;
|
|
||||||
g = copied.g;
|
|
||||||
b = copied.b;
|
|
||||||
a = copied.a;
|
|
||||||
|
|
||||||
norm();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set to represent hex color
|
|
||||||
*
|
|
||||||
* @param hex hex integer RRGGBB
|
|
||||||
* @return this
|
|
||||||
*/
|
|
||||||
public RGB setTo(int hex)
|
|
||||||
{
|
|
||||||
setTo(RGB.fromHex(hex));
|
|
||||||
norm();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set to R,G,B 0-1
|
|
||||||
*
|
|
||||||
* @param r red
|
|
||||||
* @param g green
|
|
||||||
* @param b blue
|
|
||||||
* @param a alpha
|
|
||||||
* @return this
|
|
||||||
*/
|
|
||||||
public RGB setTo(Number r, Number g, Number b, Number a)
|
|
||||||
{
|
|
||||||
this.r = r.doubleValue();
|
|
||||||
this.g = g.doubleValue();
|
|
||||||
this.b = b.doubleValue();
|
|
||||||
this.a = a.doubleValue();
|
|
||||||
norm();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set to R,G,B 0-1
|
|
||||||
*
|
|
||||||
* @param r red
|
|
||||||
* @param g green
|
|
||||||
* @param b blue
|
|
||||||
* @return this
|
|
||||||
*/
|
|
||||||
public RGB setTo(Number r, Number g, Number b)
|
|
||||||
{
|
|
||||||
this.r = r.doubleValue();
|
|
||||||
this.g = g.doubleValue();
|
|
||||||
this.b = b.doubleValue();
|
|
||||||
this.a = 1;
|
|
||||||
norm();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fix numbers out of range 0-1
|
|
||||||
*
|
|
||||||
* @return this
|
|
||||||
*/
|
|
||||||
public RGB norm()
|
|
||||||
{
|
|
||||||
r = Calc.clampd(r, 0, 1);
|
|
||||||
g = Calc.clampd(g, 0, 1);
|
|
||||||
b = Calc.clampd(b, 0, 1);
|
|
||||||
a = Calc.clampd(a, 0, 1);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get hex value 0xRRGGBB
|
|
||||||
*
|
|
||||||
* @return hex value RRGGBB
|
|
||||||
*/
|
|
||||||
public int getHex()
|
|
||||||
{
|
|
||||||
final int ri = (int) Math.round(r * 255);
|
|
||||||
final int gi = (int) Math.round(g * 255);
|
|
||||||
final int bi = (int) Math.round(b * 255);
|
|
||||||
return (ri << 16) | (gi << 8) | bi;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert to HSV
|
|
||||||
*
|
|
||||||
* @return HSV representation
|
|
||||||
*/
|
|
||||||
public HSV toHSV()
|
|
||||||
{
|
|
||||||
final float[] hsv = { 0, 0, 0 };
|
|
||||||
Color.RGBtoHSB((int) (r * 255), (int) (g * 255), (int) (b * 255), hsv);
|
|
||||||
return new HSV(hsv[0], hsv[1], hsv[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create color from hex 0xRRGGBB
|
|
||||||
*
|
|
||||||
* @param hex hex RRGGBB
|
|
||||||
* @return the new color
|
|
||||||
*/
|
|
||||||
@FactoryMethod
|
|
||||||
public static RGB fromHex(int hex)
|
|
||||||
{
|
|
||||||
final int bi = hex & 0xff;
|
|
||||||
final int gi = (hex >> 8) & 0xff;
|
|
||||||
final int ri = (hex >> 16) & 0xff;
|
|
||||||
return new RGB(ri / 255D, gi / 255D, bi / 255D);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Make from HSV
|
|
||||||
*
|
|
||||||
* @param color HSV color
|
|
||||||
* @return RGB
|
|
||||||
*/
|
|
||||||
@FactoryMethod
|
|
||||||
public static RGB fromHSV(HSV color)
|
|
||||||
{
|
|
||||||
return color.toRGB();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
return "RGB[" + r + ";" + g + ";" + b + ";" + a + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj)
|
|
||||||
{
|
|
||||||
if (obj == null) return false;
|
|
||||||
if (!(obj instanceof RGB)) return false;
|
|
||||||
return ((RGB) obj).r == r && ((RGB) obj).g == g && ((RGB) obj).b == b && ((RGB) obj).a == a;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode()
|
|
||||||
{
|
|
||||||
return Double.valueOf(r).hashCode() ^ Double.valueOf(g).hashCode() ^ Double.valueOf(b).hashCode() ^ Double.valueOf(a).hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@FactoryMethod
|
|
||||||
public static RGB dark(double d)
|
|
||||||
{
|
|
||||||
return new RGB(0, 0, 0, d);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@FactoryMethod
|
|
||||||
public static RGB light(double d)
|
|
||||||
{
|
|
||||||
return new RGB(1, 1, 1, d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,21 +9,21 @@ package mightypork.utils.math.constraints;
|
|||||||
*/
|
*/
|
||||||
public abstract class DigestCache<D> implements Digestable<D> {
|
public abstract class DigestCache<D> implements Digestable<D> {
|
||||||
|
|
||||||
private D digest;
|
private D last_digest;
|
||||||
private boolean enabled;
|
private boolean caching_enabled;
|
||||||
private boolean dirty;
|
private boolean dirty = true;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final D digest()
|
public final D digest()
|
||||||
{
|
{
|
||||||
if (enabled) {
|
if (caching_enabled) {
|
||||||
if (dirty || digest == null) {
|
if (dirty || last_digest == null) {
|
||||||
digest = createDigest();
|
last_digest = createDigest();
|
||||||
dirty = false;
|
dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return digest;
|
return last_digest;
|
||||||
}
|
}
|
||||||
|
|
||||||
return createDigest();
|
return createDigest();
|
||||||
@@ -39,7 +39,7 @@ public abstract class DigestCache<D> implements Digestable<D> {
|
|||||||
@Override
|
@Override
|
||||||
public final void enableDigestCaching(boolean yes)
|
public final void enableDigestCaching(boolean yes)
|
||||||
{
|
{
|
||||||
enabled = yes;
|
caching_enabled = yes;
|
||||||
markDigestDirty(); // mark dirty
|
markDigestDirty(); // mark dirty
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ public abstract class DigestCache<D> implements Digestable<D> {
|
|||||||
@Override
|
@Override
|
||||||
public final boolean isDigestCachingEnabled()
|
public final boolean isDigestCachingEnabled()
|
||||||
{
|
{
|
||||||
return enabled;
|
return caching_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user