Renderer/src/main/java/electrosphere/renderer/ui/elements/TextBox.java
2024-03-09 20:05:47 -05:00

151 lines
4.7 KiB
Java

package electrosphere.renderer.ui.elements;
import electrosphere.engine.Globals;
import electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.renderer.model.Model;
import electrosphere.renderer.ui.DrawableElement;
import electrosphere.renderer.ui.events.Event;
import electrosphere.renderer.ui.font.FontUtils;
import org.joml.Vector3f;
public class TextBox implements DrawableElement {
String text;
boolean editable;
Vector3f scalar;
public TextBox(int positionX, int positionY, int width, int height, String text, boolean render, boolean editable) {
this.positionX = positionX;
this.positionY = positionY;
this.width = width;
this.height = height;
this.text = text;
scalar = new Vector3f(1,1,1);
}
public TextBox(int positionX, int positionY, int width, int height, String text, boolean render, boolean editable, Vector3f scalar) {
this.positionX = positionX;
this.positionY = positionY;
this.width = width;
this.height = height;
this.text = text;
this.scalar = scalar;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public boolean isEditable() {
return editable;
}
public void setEditable(boolean editable) {
this.editable = editable;
}
@Override
public void draw(int parentFramebufferPointer, int parentWidth, int parentHeight){
throw new UnsupportedOperationException("Transparent Text box draw function not implemented yet oop");
// float ndcX = (float)positionX/Globals.WINDOW_WIDTH;
// float ndcY = (float)positionY/Globals.WINDOW_HEIGHT;
// float ndcWidth = (float)width/Globals.WINDOW_WIDTH;
// float ndcHeight = (float)height/Globals.WINDOW_HEIGHT;
// //monowidth for the moment
// float charWidth = ndcWidth/cols;
// float charHeight = ndcHeight/rows;
// for(int y = 0; y < rows; y++){
// for(int x = 0; x < cols; x++){
// char toDraw = ' ';
// if(x + y * cols < text.length()){
// toDraw = text.charAt(x + y * cols);
// }
// Vector3f characterPosition = new Vector3f(ndcX + x * charWidth,ndcY + y * charHeight,0);
// Vector3f characterDimensions = new Vector3f(charWidth,charHeight,0);
// Vector3f bitMapPosition = FontUtils.getPositionOfCharacter(toDraw);
// Vector3f bitMapDimension = FontUtils.getDimensionOfCharacter(toDraw);
// Model charModel = Globals.assetManager.fetchModel(AssetDataStrings.ASSET_STRING_BITMAP_FONT);
// if(charModel != null && toDraw != ' '){
// charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "mPosition", characterPosition);
// charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "mDimension", characterDimensions);
// charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "tPosition", bitMapPosition);
// charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "tDimension", bitMapDimension);
// charModel.pushUniformToMesh(AssetDataStrings.ASSET_STRING_BITMAP_FONT_MESH_NAME, "color", color);
// charModel.drawUI();
// }
// }
// }
}
public int width = 1;
public int height = 1;
public int positionX = 0;
public int positionY = 0;
public int parentWidth = 1;
public int parentHeight = 1;
public boolean visible = false;
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public int getPositionX() {
return positionX;
}
public int getPositionY() {
return positionY;
}
public boolean getVisible() {
return visible;
}
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
public void setPositionX(int positionX) {
this.positionX = positionX;
}
public void setPositionY(int positionY) {
this.positionY = positionY;
}
public void setVisible(boolean draw) {
this.visible = draw;
}
public void setParentWidth(int width){
parentWidth = width;
}
public void setParentHeight(int height){
this.parentHeight = height;
}
public boolean handleEvent(Event event){
return true;
}
}