Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package strongdk.jme.gui;
- import com.jme3.app.Application;
- import com.jme3.asset.AssetManager;
- import com.jme3.bounding.BoundingBox;
- import com.jme3.font.BitmapFont;
- import com.jme3.font.BitmapText;
- import com.jme3.font.LineWrapMode;
- import com.jme3.font.Rectangle;
- import com.jme3.input.InputManager;
- import com.jme3.input.KeyInput;
- import com.jme3.input.MouseInput;
- import com.jme3.input.RawInputListener;
- import com.jme3.input.event.JoyAxisEvent;
- import com.jme3.input.event.JoyButtonEvent;
- import com.jme3.input.event.KeyInputEvent;
- import com.jme3.input.event.MouseButtonEvent;
- import com.jme3.input.event.MouseMotionEvent;
- import com.jme3.input.event.TouchEvent;
- import com.jme3.material.Material;
- import com.jme3.material.RenderState;
- import com.jme3.math.ColorRGBA;
- import com.jme3.math.Vector2f;
- import com.jme3.math.Vector3f;
- import com.jme3.renderer.ViewPort;
- import com.jme3.scene.Geometry;
- import com.jme3.scene.Node;
- import com.jme3.scene.Spatial;
- import com.jme3.scene.shape.Quad;
- import java.util.List;
- /**
- *
- * A simple Spatial that can be very easily added to a guiNode and provide a button, label, or text field functionality.
- *
- * The motivation here is to be able to add functional gui elements without needing an actual gui library. Most useful for prototyping or debugging.
- *
- * There are no features (or plans for features) for windows, panels, layout management, or extensive customizability.
- *
- * If youre looking for a JME3 gui system with lots of features consider looking at Nifty, t0neg0dgui, or Lemur.
- *
- * @author Daniel Strong aka icamefromspace Dec 2013
- */
- public final class GuiElement extends Node {
- private ViewPort guiViewport;
- private InputManager inputManager;
- private boolean rawInputListenersAdded = false;
- private boolean enabled = true;
- private boolean pressed = false;
- private boolean hovered = false;
- private boolean toggleable = false;
- private boolean toggled = false;
- private boolean editable = false;
- private boolean editFocus = false;
- private Quad quad;
- private Geometry geom;
- private Material mat, hoverMat, clickedMat;
- private float textInset = 10;
- private BitmapText bitmapText;
- private BitmapText inputCursorBitmapText;
- private float inputCursorBlinkDuration = .4f;
- private GuiElementListener guiElementListener;
- private GeRawInputListener rawInputListener;
- /**
- * this is the same as the other constructor, but assumes the obvious values from Application to save typing.
- * @param app
- * @param text
- * @param width
- * @param height
- */
- public GuiElement(Application app, String text, float width, float height) {
- this(app.getGuiViewPort(), app.getInputManager(), text, width, height, darkGrayMat(app.getAssetManager()), lightGrayMat(app.getAssetManager()), blueMat(app.getAssetManager()), app.getAssetManager().loadFont("Interface/Fonts/Default.fnt"), ColorRGBA.Gray.mult(2));
- }
- /**
- * make a gui element with all the specified settings and resources for maximum personalization. It might be quicker to use the factory methods on this lass to create Gui Elements though
- *
- * @param guiViewport
- * @param inputManager
- * @param text
- * @param width
- * @param height
- * @param mat
- * @param hoverMat
- * @param clickedMat
- * @param font
- * @param textColor
- */
- public GuiElement(ViewPort guiViewport, InputManager inputManager, String text, float width, float height, Material mat, Material hoverMat, Material clickedMat, BitmapFont font, ColorRGBA textColor) {
- super(text);
- this.guiViewport = guiViewport;
- this.inputManager = inputManager;
- this.mat = mat;
- this.hoverMat = hoverMat;
- this.clickedMat = clickedMat;
- //textInset = height * .1f;
- geom = new Geometry(getName() + " Geom");
- geom.setMaterial(mat);
- quad = new Quad(width, height);
- geom.setMesh(quad);
- attachChild(geom);
- bitmapText = new BitmapText(font, false);
- bitmapText.setText(text);
- bitmapText.setSize(font.getCharSet().getRenderedSize());
- bitmapText.setColor(textColor);
- bitmapText.setLineWrapMode(LineWrapMode.Word);
- Rectangle rectangle = new Rectangle(0, 0, quad.getWidth() - textInset, quad.getHeight() - textInset);
- bitmapText.setBox(rectangle);
- bitmapText.setVerticalAlignment(BitmapFont.VAlign.Center);
- bitmapText.setAlignment(BitmapFont.Align.Center);
- attachChild(bitmapText);
- bitmapText.setLocalTranslation(0, quad.getHeight() - (textInset / 2f), 0);
- }
- /**
- * this listener is notified of mouse and keyboard interactions with the GuiElement
- *
- * Also note that there is a {@link GuiElementAdapter} available to help condense your code.
- *
- * @param listener
- */
- public void setListener(GuiElementListener listener) {
- this.guiElementListener = listener;
- }
- public void removeListener() {
- this.guiElementListener = null;
- }
- public Vector2f getDimensions() {
- return new Vector2f(quad.getWidth(), quad.getHeight());
- }
- /**
- * Sets the dimensions of the screen space for this element. The quad will have these dimensions
- *
- * and the text will attempt to wrap as to stay in the dimensions, but if the text doesnt fit it doesnt fit.
- *
- * @param width
- * @param height
- */
- public void setDimensions(float width, float height) {
- //textInset = height * .1f;
- quad = new Quad(width, height);
- geom.setMesh(quad);
- Rectangle rectangle = new Rectangle(0, 0, quad.getWidth() - textInset, quad.getHeight() - textInset);
- bitmapText.setBox(rectangle);
- bitmapText.setLocalTranslation(0, quad.getHeight() - (textInset / 2f), 0);
- if (inputCursorBitmapText != null) {
- inputCursorBitmapText.setBox(rectangle);
- }
- }
- /**
- * @param mat the button's idle state material
- */
- @Override
- public void setMaterial(Material mat) {
- this.mat = mat;
- if (!hovered && !pressed) {
- geom.setMaterial(getIdleMaterial());
- }
- }
- /**
- * @param hoverMat the buttons hover state material
- */
- public void setHoverMaterial(Material hoverMat) {
- this.hoverMat = hoverMat;
- if (hovered && !pressed) {
- geom.setMaterial(hoverMat);
- }
- }
- /**
- *
- * @param clickedMat the buttons state while mouse is held down. This is also used as the idle state if setToggleable(true).
- */
- public void setClickedMaterial(Material clickedMat) {
- this.clickedMat = clickedMat;
- if (pressed) {
- geom.setMaterial(clickedMat);
- }
- }
- public Material getMaterial() {
- return mat;
- }
- public Material getHoverMaterial() {
- return hoverMat;
- }
- public Material getClickedMaterial() {
- return clickedMat;
- }
- public void setText(String text) {
- bitmapText.setText(text);
- }
- public void appendText(String text) {
- bitmapText.setText(bitmapText.getText() + text);
- }
- public void appendTextBackspace() {
- String text = getText();
- if (!text.isEmpty()) {
- text = text.substring(0, text.length() - 1);
- setText(text);
- }
- }
- public void clearText() {
- bitmapText.setText("");
- }
- public String getText() {
- return bitmapText.getText();
- }
- public void setTextColor(ColorRGBA color) {
- bitmapText.setColor(color);
- }
- public void setTextColor(int start, int end, ColorRGBA color) {
- bitmapText.setColor(start, end, color);
- }
- public void setTextColor(String regexp, ColorRGBA color) {
- bitmapText.setColor(regexp, color);
- }
- public ColorRGBA getTextColor() {
- return bitmapText.getColor();
- }
- public void setTextAlignment(BitmapFont.Align align) {
- bitmapText.setAlignment(align);
- if (inputCursorBitmapText != null) {
- inputCursorBitmapText.setAlignment(align);
- }
- }
- public BitmapFont.Align getTextAlignment() {
- return bitmapText.getAlignment();
- }
- /**
- * enabled or disables the processing of mouse input on this gui element.
- *
- * The Gui Element will simply "freeze" in its state and ignores mouse interactions. If you want the element to appear disabled you will need to manually change the material/s.
- *
- * @param enabled
- */
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- if (hasEditFocus()) {
- setEditFocus(false);
- }
- if (!enabled) {
- pressed = false;
- hovered = false;
- validateIdleState();
- }
- }
- /**
- * returns true if this gui element responds to mouse and keyboard input
- *
- * @return
- */
- public boolean isEnabled() {
- return enabled;
- }
- /**
- *
- * Note: if isEnabled() == false, then this value will not change
- *
- * @return true if the mouse button is being held down on the button
- */
- public boolean isPressed() {
- return pressed;
- }
- /**
- * Note: if isEnabled() == false, then this value will not change. instead use isMouseOverlappingButton() if youre curious (or do regular checks like you would any other spatial)
- *
- * @return true if the mouse is overlapping the buttons world bound.
- */
- public boolean isHovered() {
- return hovered;
- }
- /**
- *
- * useful only if isToggleable() == true.
- *
- * @param toggled manually set the toggle state of the button, note that the listener will not be informed of this event.
- */
- public void setToggled(boolean toggled) {
- this.toggled = toggled;
- validateIdleState();
- }
- /**
- * if isToggleable() == false then this will always be false
- *
- * @return true if the button is in the "toggled on" state.
- */
- public boolean isToggled() {
- return toggled && toggleable;
- }
- /**
- * returns true if this is a "toggle" button (sort of like a checkbox)
- *
- * @return
- */
- public boolean isToggleable() {
- return toggleable;
- }
- /**
- * @param toggleable true if the button should toggle off and on when it is clicked, false if the button should behave like a normal button
- */
- public void setToggleable(boolean toggleable) {
- this.toggleable = toggleable;
- this.editable = false;
- validateIdleState();
- }
- /**
- * returns true if the user can edit the text when clicking on this gui elemnt.
- *
- * @return
- */
- public boolean isEditable() {
- return editable;
- }
- /**
- * turn on and off giving the ability for the user to change the text
- *
- * @param editable
- */
- public void setEditable(boolean editable) {
- this.editable = editable;
- this.toggleable = false;
- if (editable && inputCursorBitmapText == null) {
- inputCursorBitmapText = new BitmapText(bitmapText.getFont(), false);
- inputCursorBitmapText.setSize(bitmapText.getFont().getCharSet().getRenderedSize());
- inputCursorBitmapText.setColor(bitmapText.getColor());
- Rectangle rectangle = new Rectangle(0, 0, quad.getWidth() - textInset, quad.getHeight() - textInset);
- inputCursorBitmapText.setBox(rectangle);
- inputCursorBitmapText.setVerticalAlignment(bitmapText.getVerticalAlignment());
- inputCursorBitmapText.setAlignment(bitmapText.getAlignment());
- attachChild(inputCursorBitmapText);
- }
- setEditFocus(false);
- }
- @Override
- public void updateLogicalState(float tpf) {
- super.updateLogicalState(tpf);
- // This should all really be in a control. but i need the setTransformRefresh() hack anyway.
- if (!rawInputListenersAdded) {
- setInputListenerAdded(true);
- }
- if (hasEditFocus()) {
- updateCursorLocation();
- inputCursorBlinkDuration -= tpf;
- if (inputCursorBlinkDuration < 0) {
- if (inputCursorBitmapText.getText().isEmpty()) {
- inputCursorBitmapText.setText("|");
- this.inputCursorBlinkDuration = 0.5f;
- } else {
- inputCursorBitmapText.setText("");
- this.inputCursorBlinkDuration = 0.4f;
- }
- }
- }
- }
- private void updateCursorLocation() {
- float x = bitmapText.getFont().getLineWidth(bitmapText.getText());
- float xAddend = bitmapText.getFont().getLineWidth("|");
- //float y = bitmapText.getLineHeight() * (bitmapText.getLineCount() - 1);
- //TODO: doesnt properly support multi-line text field
- switch (bitmapText.getAlignment()) {
- case Left:
- inputCursorBitmapText.setLocalTranslation((x) + (xAddend / 2f), quad.getHeight() - (textInset / 2f), 0);
- break;
- case Center:
- inputCursorBitmapText.setLocalTranslation((x / 2f) + (xAddend / 2f), quad.getHeight() - (textInset / 2f), 0);
- break;
- case Right:
- inputCursorBitmapText.setLocalTranslation((0) + (xAddend / 2f), quad.getHeight() - (textInset / 2f), 0);
- break;
- default:
- throw new AssertionError(bitmapText.getAlignment().name());
- }
- }
- /**
- * does nothing if isEditable() == false
- *
- * sets the state of the element such that the user can start typing as if he or she clicked on it.
- *
- * @param editFocus
- */
- public void setEditFocus(boolean editFocus) {
- this.editFocus = editFocus;
- if (inputCursorBitmapText != null) {
- if (editFocus) {
- updateCursorLocation();
- inputCursorBitmapText.setText("|");
- this.inputCursorBlinkDuration = 0.5f;
- }
- inputCursorBitmapText.setCullHint(hasEditFocus() ? CullHint.Never : CullHint.Always);
- }
- validateIdleState();
- }
- /**
- * always returns false if isEditable() == false
- *
- * determines if the user is currently entering text in to the gui elemnt.
- *
- * @return
- */
- public boolean hasEditFocus() {
- return editable && editFocus;
- }
- private void validateIdleState() {
- if (!hovered && !pressed) {
- geom.setMaterial(getIdleMaterial());
- }
- }
- /**
- * centers the button within the provided viewport
- *
- * TODO: this assumes guiNode is origined at the bottom left corner of the screen. this code should center the button in accordance to its world translation
- *
- * @return
- */
- @Override
- public GuiElement center() {
- setLocalTranslation((guiViewport.getCamera().getWidth() / 2f) - (quad.getWidth() / 2f), (guiViewport.getCamera().getHeight() / 2f) - (quad.getHeight() / 2f), 0);
- return this;
- }
- /**
- * centers the button within the provided viewport
- *
- * TODO: this assumes guiNode is origined at the bottom left corner of the screen. this code should center the button in accordance to its world translation
- *
- * @param offsetX after centering the button it will be moved by this amount
- * @param offsetY after centering the button it will be moved by this amount
- * @return
- */
- public GuiElement center(float offsetX, float offsetY) {
- setLocalTranslation((guiViewport.getCamera().getWidth() / 2f) - (quad.getWidth() / 2f) + offsetX, (guiViewport.getCamera().getHeight() / 2f) - (quad.getHeight() / 2f) + offsetY, 0);
- return this;
- }
- public Spatial move(float x, float y) {
- return super.move(x, y, 0);
- }
- public Spatial move(Vector2f offset) {
- return super.move(offset.x, offset.y, 0);
- }
- /**
- * determines if this spatial is attached to a scene in the provided viewport. (eg "in the scene graph")
- *
- * this is used for automatically removing the raw input listener.
- *
- * @return
- */
- private boolean isInViewport() {
- List<Spatial> scenes = this.guiViewport.getScenes();
- for (Spatial rootScene : scenes) {
- //UtLog.info.log(getName() + " has ancestor? " + rootScene.getName());
- Node current = this;
- while (current.getParent() != null) {
- current = current.getParent();
- if (current == rootScene) {
- //UtLog.info.log("yes");
- return true;
- }
- }
- }
- //UtLog.info.log("no");
- return false;
- }
- private void setInputListenerAdded(boolean added) {
- if (added == rawInputListenersAdded) {
- return;
- }
- if (added) {
- //if (!isInViewport()) {
- // UtLog.warning.log("not in viewport");
- //}
- rawInputListenersAdded = true;
- if (inputManager != null) {
- if (rawInputListener == null) {
- rawInputListener = new GeRawInputListener();
- }
- inputManager.addRawInputListener(rawInputListener);
- }
- } else {
- rawInputListenersAdded = false;
- inputManager.removeRawInputListener(rawInputListener);
- }
- }
- @Override
- protected void setTransformRefresh() {
- super.setTransformRefresh();
- // This hack removes removes the raw input listener if its been added., it is automatically added inside of updateLogicalState. (this is the workaround i found to automatically discover adding and removing spatials from the scene graph)
- if (rawInputListenersAdded == true && !isInViewport()) {
- setInputListenerAdded(false);
- }
- }
- /**
- * determines if mouse is on top of the quad that represents the button
- *
- * @return
- */
- public boolean isMouseOverlappingButton() {
- Vector2f mouse = inputManager.getCursorPosition();
- return isMouseOverlappingButton(mouse.x, mouse.y);
- }
- private boolean isMouseOverlappingButton(float mouseX, float mouseY) {
- if (!enabled) {
- return false;
- }
- Vector3f limit = new Vector3f();
- BoundingBox buttonBoundingBox = (BoundingBox) geom.getWorldBound();
- buttonBoundingBox.getMin(limit);
- if (mouseX < limit.x || mouseY < limit.y) {
- return false;
- }
- buttonBoundingBox.getMax(limit);
- if (mouseX > limit.x || mouseY > limit.y) {
- return false;
- }
- return true;
- }
- /**
- * returns either mat or clickedMat depending on if the button is toggled or not.
- *
- * @return
- */
- private Material getIdleMaterial() {
- if ((toggleable && toggled) || (editable && editFocus)) {
- return clickedMat;
- }
- return mat;
- }
- private class GeRawInputListener implements RawInputListener {
- public void beginInput() {
- }
- public void endInput() {
- }
- public void onJoyAxisEvent(JoyAxisEvent evt) {
- }
- public void onJoyButtonEvent(JoyButtonEvent evt) {
- }
- public void onMouseMotionEvent(MouseMotionEvent evt) {
- if (evt.isConsumed() || pressed || !enabled) {
- return;
- }
- if (isMouseOverlappingButton(evt.getX(), evt.getY())) {
- geom.setMaterial(hoverMat);
- if (!hovered) {
- hovered = true;
- if (guiElementListener != null) {
- guiElementListener.onHover(GuiElement.this);
- }
- }
- } else {
- geom.setMaterial(getIdleMaterial());
- if (hovered) {
- hovered = false;
- if (guiElementListener != null) {
- guiElementListener.onHoverExit(GuiElement.this);
- }
- }
- }
- }
- public void onMouseButtonEvent(MouseButtonEvent evt) {
- if (evt.isConsumed() || !enabled) {
- return;
- }
- if (!pressed && evt.getButtonIndex() == MouseInput.BUTTON_LEFT && evt.isPressed()) {
- if (isMouseOverlappingButton(evt.getX(), evt.getY())) {
- pressed = true;
- geom.setMaterial(clickedMat);
- evt.setConsumed();
- if (guiElementListener != null) {
- guiElementListener.onPressed(GuiElement.this);
- }
- if (isEditable()) {
- setEditFocus(true);
- }
- } else {
- if (hasEditFocus()) {
- evt.setConsumed();
- setEditFocus(false); // material is changed through validateIdleState in this method.
- if (guiElementListener != null) {
- guiElementListener.onTextInput(GuiElement.this);
- }
- }
- }
- } else if (pressed && evt.getButtonIndex() == MouseInput.BUTTON_LEFT && evt.isReleased()) {
- toggled = !toggled;
- pressed = false;
- if (isMouseOverlappingButton(evt.getX(), evt.getY())) {
- geom.setMaterial(hoverMat);
- hovered = true;
- if (guiElementListener != null) {
- guiElementListener.onReleased(GuiElement.this);
- }
- } else {
- geom.setMaterial(getIdleMaterial());
- hovered = false;
- if (guiElementListener != null) {
- guiElementListener.onReleased(GuiElement.this);
- guiElementListener.onHoverExit(GuiElement.this);
- }
- }
- }
- }
- public void onKeyEvent(KeyInputEvent evt) {
- if (!hasEditFocus() || evt.isConsumed()) {
- return;
- }
- evt.setConsumed();
- if (evt.isReleased()) {
- return;
- }
- switch (evt.getKeyCode()) {
- case KeyInput.KEY_ESCAPE:
- setEditFocus(false);
- if (guiElementListener != null) {
- guiElementListener.onTextInput(GuiElement.this);
- }
- break;
- case KeyInput.KEY_BACK:
- appendTextBackspace();
- break;
- case KeyInput.KEY_RETURN:
- setEditFocus(false);
- if (guiElementListener != null) {
- guiElementListener.onTextInput(GuiElement.this);
- }
- break;
- default:
- char keyChar = evt.getKeyChar();
- if (keyChar != 0) {
- appendText(String.valueOf(keyChar));
- }
- break;
- }
- }
- public void onTouchEvent(TouchEvent evt) {
- }
- }
- /**
- * A convenient class that can save valuable code space
- */
- public static class GuiElementAdapter implements GuiElementListener {
- @Override
- public void onHover(GuiElement guiElement) {
- }
- @Override
- public void onHoverExit(GuiElement guiElement) {
- }
- @Override
- public void onReleased(GuiElement guiElement) {
- }
- @Override
- public void onPressed(GuiElement guiElement) {
- }
- @Override
- public void onTextInput(GuiElement guiElement) {
- }
- }
- public interface GuiElementListener {
- /**
- * mouse enters button click space
- *
- * @param guiElement
- */
- public void onHover(GuiElement guiElement);
- /**
- * mouse leaves the button click space
- *
- * @param guiElement
- */
- public void onHoverExit(GuiElement guiElement);
- /**
- * mouse button is released after being pressed
- *
- * NOTE: If you wish to check for the toggle state of the button it should be done in onReleased rather than onPressed()
- *
- * @param guiElement
- */
- public void onReleased(GuiElement guiElement);
- /**
- * mouse button is pressed (as opposed to being released)
- *
- * NOTE: If you wish to check for the toggle state of the button it should be done in onReleased rather than onPressed()
- *
- * @param guiElement
- */
- public void onPressed(GuiElement guiElement);
- /**
- * called when the element is editable and the text is changed by the user.
- *
- * not called until the user dismisses the focus (eg presses enter, escape, or clicks outside the element)
- *
- * @param guiElement
- */
- public void onTextInput(GuiElement guiElement);
- }
- private static Material makeMat(AssetManager assetManager, ColorRGBA color) {
- Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
- mat.setColor("Color", color);
- mat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
- return mat;
- }
- private static Material darkGrayMat(AssetManager assetManager) {
- return makeMat(assetManager, new ColorRGBA(0, 0, 0, 0.2f));
- }
- private static Material lightGrayMat(AssetManager assetManager) {
- return makeMat(assetManager, new ColorRGBA(0.2f, 0.2f, 0.2f, 0.7f));
- }
- private static Material blueMat(AssetManager assetManager) {
- return makeMat(assetManager, new ColorRGBA(0.1f, 0.1f, 0.7f, 0.9f));
- }
- public static GuiElement makeLabel(Application app, String text, float width, float height) {
- return makeLabel(app.getGuiViewPort(), app.getInputManager(), app.getAssetManager(), text, width, height);
- }
- public static GuiElement makeLabel(ViewPort guiViewport, InputManager inputManager, AssetManager assetManager, String text, float width, float height) {
- BitmapFont font = assetManager.loadFont("Interface/Fonts/Default.fnt");
- ColorRGBA textColor = ColorRGBA.Gray.mult(2);
- GuiElement element = new GuiElement(guiViewport, inputManager, text, width, height, darkGrayMat(assetManager), lightGrayMat(assetManager), blueMat(assetManager), font, textColor);
- element.setEnabled(false);
- return element;
- }
- public static GuiElement makeButton(Application app, String text, float width, float height) {
- return makeButton(app.getGuiViewPort(), app.getInputManager(), app.getAssetManager(), text, width, height);
- }
- public static GuiElement makeButton(ViewPort guiViewport, InputManager inputManager, AssetManager assetManager, String text, float width, float height) {
- BitmapFont font = assetManager.loadFont("Interface/Fonts/Default.fnt");
- ColorRGBA textColor = ColorRGBA.Gray.mult(2);
- return new GuiElement(guiViewport, inputManager, text, width, height, darkGrayMat(assetManager), lightGrayMat(assetManager), blueMat(assetManager), font, textColor);
- }
- public static GuiElement makeToggleButton(Application app, String text, float width, float height) {
- return makeToggleButton(app.getGuiViewPort(), app.getInputManager(), app.getAssetManager(), text, width, height);
- }
- public static GuiElement makeToggleButton(ViewPort guiViewport, InputManager inputManager, AssetManager assetManager, String text, float width, float height) {
- BitmapFont font = assetManager.loadFont("Interface/Fonts/Default.fnt");
- ColorRGBA textColor = ColorRGBA.Gray.mult(2);
- GuiElement element = new GuiElement(guiViewport, inputManager, text, width, height, darkGrayMat(assetManager), lightGrayMat(assetManager), blueMat(assetManager), font, textColor);
- element.setToggleable(true);
- return element;
- }
- public static GuiElement makeTextField(Application app, String text, float width, float height) {
- return makeTextField(app.getGuiViewPort(), app.getInputManager(), app.getAssetManager(), text, width, height);
- }
- public static GuiElement makeTextField(ViewPort guiViewport, InputManager inputManager, AssetManager assetManager, String text, float width, float height) {
- BitmapFont font = assetManager.loadFont("Interface/Fonts/Default.fnt");
- ColorRGBA textColor = ColorRGBA.Gray.mult(2);
- GuiElement element = new GuiElement(guiViewport, inputManager, text, width, height, darkGrayMat(assetManager), lightGrayMat(assetManager), blueMat(assetManager), font, textColor);
- element.setEditable(true);
- return element;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement