Create support for NVG Colors
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package com.bartlomiejpluta.base.api.game.gui.base;
|
||||
|
||||
public interface Color {
|
||||
void setRGB(float red, float green, float blue);
|
||||
|
||||
void setRGBA(float red, float green, float blue, float alpha);
|
||||
|
||||
void setRed(float value);
|
||||
|
||||
void setGreen(float value);
|
||||
|
||||
void setBlue(float value);
|
||||
|
||||
void setAlpha(float value);
|
||||
|
||||
float getRed();
|
||||
|
||||
float getGreen();
|
||||
|
||||
float getBlue();
|
||||
|
||||
float getAlpha();
|
||||
}
|
||||
@@ -17,6 +17,8 @@ public interface GUI extends Renderable, Disposable, KeyEventHandler {
|
||||
|
||||
void setRoot(Widget root);
|
||||
|
||||
Color createColor();
|
||||
|
||||
void beginPath();
|
||||
|
||||
void closePath();
|
||||
@@ -67,11 +69,11 @@ public interface GUI extends Renderable, Disposable, KeyEventHandler {
|
||||
|
||||
void setGlobalAlpha(float alpha);
|
||||
|
||||
void setFillColor(float red, float green, float blue, float alpha);
|
||||
void setFillColor(Color color);
|
||||
|
||||
void fill();
|
||||
|
||||
void setStrokeColor(float red, float green, float blue, float alpha);
|
||||
void setStrokeColor(Color color);
|
||||
|
||||
void setStrokeWidth(float width);
|
||||
|
||||
|
||||
@@ -1,54 +1,27 @@
|
||||
package com.bartlomiejpluta.base.api.game.gui.component;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.gui.base.Color;
|
||||
import com.bartlomiejpluta.base.api.game.gui.base.GUI;
|
||||
import com.bartlomiejpluta.base.api.game.screen.Screen;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
public class Label extends BaseComponent {
|
||||
private String text;
|
||||
private final GUI gui;
|
||||
|
||||
private String text = "";
|
||||
private String font;
|
||||
|
||||
private float fontSize;
|
||||
|
||||
private int alignment;
|
||||
|
||||
private float red;
|
||||
private float green;
|
||||
private float blue;
|
||||
private float alpha;
|
||||
private int alignment = GUI.ALIGN_LEFT;
|
||||
private final Color color;
|
||||
|
||||
private final float[] bounds = new float[4];
|
||||
|
||||
public Label(String font) {
|
||||
this(font, "", 10f, GUI.ALIGN_LEFT, 1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
public Label(String font, String text) {
|
||||
this(font, text, 10f, GUI.ALIGN_LEFT, 1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
public Label(String font, String text, float fontSize) {
|
||||
this(font, text, fontSize, GUI.ALIGN_LEFT, 1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
public Label(String font, String text, float fontSize, int alignment) {
|
||||
this(font, text, fontSize, alignment, 1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
public Label(String font, String text, float fontSize, int alignment, float red, float green, float blue) {
|
||||
this(font, text, fontSize, alignment, red, green, blue, 1.0f);
|
||||
}
|
||||
|
||||
public Label(String font, String text, float fontSize, int alignment, float red, float green, float blue, float alpha) {
|
||||
this.text = requireNonNull(text);
|
||||
public Label(GUI gui, String font) {
|
||||
this.gui = requireNonNull(gui);
|
||||
this.font = requireNonNull(font);
|
||||
this.fontSize = fontSize;
|
||||
this.alignment = alignment;
|
||||
this.red = red;
|
||||
this.green = green;
|
||||
this.blue = blue;
|
||||
this.alpha = alpha;
|
||||
|
||||
this.color = this.gui.createColor();
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
@@ -84,48 +57,43 @@ public class Label extends BaseComponent {
|
||||
}
|
||||
|
||||
public float getRed() {
|
||||
return red;
|
||||
return color.getRed();
|
||||
}
|
||||
|
||||
public void setRed(float red) {
|
||||
this.red = red;
|
||||
public void setRed(float value) {
|
||||
color.setRed(value);
|
||||
}
|
||||
|
||||
public float getGreen() {
|
||||
return green;
|
||||
return color.getGreen();
|
||||
}
|
||||
|
||||
public void setGreen(float green) {
|
||||
this.green = green;
|
||||
public void setGreen(float value) {
|
||||
color.setGreen(value);
|
||||
}
|
||||
|
||||
public float getBlue() {
|
||||
return blue;
|
||||
return color.getBlue();
|
||||
}
|
||||
|
||||
public void setBlue(float blue) {
|
||||
this.blue = blue;
|
||||
public void setBlue(float value) {
|
||||
color.setBlue(value);
|
||||
}
|
||||
|
||||
public float getAlpha() {
|
||||
return alpha;
|
||||
return color.getAlpha();
|
||||
}
|
||||
|
||||
public void setAlpha(float alpha) {
|
||||
this.alpha = alpha;
|
||||
public void setAlpha(float value) {
|
||||
color.setAlpha(value);
|
||||
}
|
||||
|
||||
public void setColor(float red, float green, float blue, float alpha) {
|
||||
this.red = red;
|
||||
this.green = green;
|
||||
this.blue = blue;
|
||||
this.alpha = alpha;
|
||||
color.setRGBA(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
public void setColor(float red, float green, float blue) {
|
||||
this.red = red;
|
||||
this.green = green;
|
||||
this.blue = blue;
|
||||
color.setRGB(red, green, blue);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -144,7 +112,7 @@ public class Label extends BaseComponent {
|
||||
gui.setFontFace(font);
|
||||
gui.setTextAlignment(alignment);
|
||||
gui.setFontSize(fontSize);
|
||||
gui.setFillColor(red, green, blue, alpha);
|
||||
gui.setFillColor(color);
|
||||
gui.fill();
|
||||
gui.putTextBox(x + paddingLeft, y + paddingTop, getWidth() - paddingLeft - paddingRight, text, bounds);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user