<commit_before>package flounder.fonts;

import flounder.devices.*;
import flounder.framework.*;
import flounder.guis.*;
import flounder.loaders.*;
import flounder.maths.*;
import flounder.maths.vectors.*;
import flounder.visual.*;

/**
 * A class that holds info about a text object.
 */
public class Text {
	private String textString;
	private FontType fontType;
	private float fontSize;
	private GuiAlign guiAlign;

	private int textMesh;
	private int vertexCount;
	private float lineMaxSize;
	private int numberOfLines;
	private float originalWidth;
	private float originalHeight;

	private String newText;

	private ValueDriver positionXDriver;
	private ValueDriver positionYDriver;
	private ValueDriver alphaDriver;
	private ValueDriver scaleDriver;
	private ValueDriver glowDriver;
	private ValueDriver borderDriver;
	private Colour colour;
	private Colour borderColour;
	private Vector2f position;
	private float rotation;

	private boolean solidBorder;
	private boolean glowBorder;

	private float currentScale;
	private float currentX;
	private float currentY;
	private float currentAlpha;
	private float glowSize;
	private float borderSize;

	private boolean loaded;

	/**
	 * Creates a new text object.
	 *
	 * @param text The inital text.
	 * @param font The font family to use.
	 * @param fontSize The font size to use.
	 * @param guiAlign How the text should be aligned.
	 */
	protected Text(String text, FontType font, float fontSize, GuiAlign guiAlign) {
		this.textString = text;
		this.fontType = font;
		this.fontSize = fontSize;
		this.guiAlign = guiAlign;

		this.alphaDriver = new ConstantDriver(1.0f);
		this.scaleDriver = new ConstantDriver(1.0f);
		this.glowDriver = new ConstantDriver(0.0f);
		this.borderDriver = new ConstantDriver(0.0f);
		this.colour = new Colour(0.0f, 0.0f, 0.0f, 1.0f);
		this.borderColour = new Colour(1.0f, 1.0f, 1.0f, 1.0f);
		this.position = new Vector2f();
		this.rotation = 0.0f;

		this.solidBorder = false;
		this.glowBorder = false;

		this.glowSize = 0.0f;
		this.borderSize = 0.0f;

		this.loaded = false;
	}

	/**
	 * Creates a new text builder.
	 *
	 * @param text The inital text.
	 *
	 * @return The newly created text builder.
	 */
	public static TextBuilder newText(String text) {
		return new TextBuilder(text);
	}

	/**
	 * Initializes the text.
	 *
	 * @param absX The absolute x position.
	 * @param absY The absolute Y position.
	 * @param maxXLength The max length for the text.
	 */
	public void init(float absX, float absY, float maxXLength) {
		positionXDriver = new ConstantDriver(absX);
		positionYDriver = new ConstantDriver(absY);
		lineMaxSize = maxXLength;

		if (!loaded) {
			fontType.loadText(this);
			loaded = true;
		}
	}

	/**
	 * Updates the text status.
	 */
	public void update() {
		if (loaded && newText != null) {
			delete();
			textString = newText;
			fontType.loadText(this);
			newText = null;
		}

		float delta = FlounderFramework.getDelta();

		currentScale = scaleDriver.update(delta);
		currentX = positionXDriver.update(delta);
		currentY = positionYDriver.update(delta);
		currentAlpha = alphaDriver.update(delta);
		glowSize = glowDriver.update(delta);
		borderSize = borderDriver.update(delta);
	}

	public String getTextString() {
		return textString;
	}

	public void setText(String newText) {
		if (!textString.equals(newText)) {
			this.newText = newText;
		}
	}

	public float getFontSize() {
		return fontSize;
	}

	public FontType getFontType() {
		return fontType;
	}

	public GuiAlign getGuiAlign() {
		return guiAlign;
	}

	/**
	 * @return {@code true} if the mouse cursor is currently over this component.
	 */
	public boolean isMouseOver() {
		// TODO: Fix maths?
		float positionX = position.x / FlounderDisplay.getAspectRatio();
		float positionY = position.y;

		//	if (FlounderMouse.isDisplaySelected() && FlounderDisplay.isFocused()) {
		if (FlounderGuis.getSelector().getCursorX() >= positionX - (getCurrentWidth() / 2.0f) && FlounderGuis.getSelector().getCursorX() <= positionX + (getCurrentWidth() / 2.0f)) {
			if (FlounderGuis.getSelector().getCursorY() >= positionY - (getCurrentHeight() / 2.0f) && FlounderGuis.getSelector().getCursorY() <= positionY + (getCurrentHeight() / 2.0f)) {
				return true;
			}
		}
		//	}

		return false;
	}

	protected Vector2f getPosition() {
		float scaleFactor = (currentScale - 1.0f) / 2.0f;
		float xChange = scaleFactor * originalWidth;
		float yChange = scaleFactor * originalHeight;

		switch (guiAlign) {
			case LEFT:
				return position.set((currentX - xChange) + (currentScale * originalWidth * 0.5f), currentY - yChange);
			case CENTRE:
				return position.set((currentX - xChange) * FlounderDisplay.getAspectRatio(), currentY - yChange);
			case RIGHT:
				return position.set((currentX - xChange) * FlounderDisplay.getAspectRatio(), currentY - yChange);
			default:
				return position.set((currentX - xChange), currentY - yChange);
		}
	}

	public float getRotation() {
		return rotation;
	}

	public void setRotation(float rotation) {
		this.rotation = rotation;
	}

	protected float getTotalBorderSize() {
		if (solidBorder) {
			if (borderSize == 0.0f) {
				return 0.0f;
			} else {
				return calculateEdgeStart() + borderSize;
			}
		} else if (glowBorder) {
			return calculateEdgeStart();
		} else {
			return 0.0f;
		}
	}<commit_msg>Better paralax<commit_after>package flounder.fonts;

import flounder.devices.*;
import flounder.framework.*;
import flounder.guis.*;
import flounder.loaders.*;
import flounder.maths.*;
import flounder.maths.vectors.*;
import flounder.visual.*;

/**
 * A class that holds info about a text object.
 */
public class Text {
	private String textString;
	private FontType fontType;
	private float fontSize;
	private GuiAlign guiAlign;

	private int textMesh;
	private int vertexCount;
	private float lineMaxSize;
	private int numberOfLines;
	private float originalWidth;
	private float originalHeight;

	private String newText;

	private ValueDriver positionXDriver;
	private ValueDriver positionYDriver;
	private ValueDriver alphaDriver;
	private ValueDriver scaleDriver;
	private ValueDriver glowDriver;
	private ValueDriver borderDriver;
	private Colour colour;
	private Colour borderColour;
	private Vector2f position;
	private float rotation;

	private boolean solidBorder;
	private boolean glowBorder;

	private float currentScale;
	private float currentX;
	private float currentY;
	private float currentAlpha;
	private float glowSize;
	private float borderSize;

	private boolean loaded;

	/**
	 * Creates a new text object.
	 *
	 * @param text The inital text.
	 * @param font The font family to use.
	 * @param fontSize The font size to use.
	 * @param guiAlign How the text should be aligned.
	 */
	protected Text(String text, FontType font, float fontSize, GuiAlign guiAlign) {
		this.textString = text;
		this.fontType = font;
		this.fontSize = fontSize;
		this.guiAlign = guiAlign;

		this.alphaDriver = new ConstantDriver(1.0f);
		this.scaleDriver = new ConstantDriver(1.0f);
		this.glowDriver = new ConstantDriver(0.0f);
		this.borderDriver = new ConstantDriver(0.0f);
		this.colour = new Colour(0.0f, 0.0f, 0.0f, 1.0f);
		this.borderColour = new Colour(1.0f, 1.0f, 1.0f, 1.0f);
		this.position = new Vector2f();
		this.rotation = 0.0f;

		this.solidBorder = false;
		this.glowBorder = false;

		this.glowSize = 0.0f;
		this.borderSize = 0.0f;

		this.loaded = false;
	}

	/**
	 * Creates a new text builder.
	 *
	 * @param text The inital text.
	 *
	 * @return The newly created text builder.
	 */
	public static TextBuilder newText(String text) {
		return new TextBuilder(text);
	}

	/**
	 * Initializes the text.
	 *
	 * @param absX The absolute x position.
	 * @param absY The absolute Y position.
	 * @param maxXLength The max length for the text.
	 */
	public void init(float absX, float absY, float maxXLength) {
		positionXDriver = new ConstantDriver(absX);
		positionYDriver = new ConstantDriver(absY);
		lineMaxSize = maxXLength;

		if (!loaded) {
			fontType.loadText(this);
			loaded = true;
		}
	}

	/**
	 * Updates the text status.
	 */
	public void update() {
		if (loaded && newText != null) {
			delete();
			textString = newText;
			fontType.loadText(this);
			newText = null;
		}

		float delta = FlounderFramework.getDelta();

		currentScale = scaleDriver.update(delta);
		currentX = positionXDriver.update(delta);
		currentY = positionYDriver.update(delta);
		currentAlpha = alphaDriver.update(delta);
		glowSize = glowDriver.update(delta);
		borderSize = borderDriver.update(delta);
	}

	public String getTextString() {
		return textString;
	}

	public void setText(String newText) {
		if (!textString.equals(newText)) {
			this.newText = newText;
		}
	}

	public float getFontSize() {
		return fontSize;
	}

	public FontType getFontType() {
		return fontType;
	}

	public GuiAlign getGuiAlign() {
		return guiAlign;
	}

	/**
	 * @return {@code true} if the mouse cursor is currently over this component.
	 */
	public boolean isMouseOver() {
		// TODO: Fix maths?
		float positionX = position.x / FlounderDisplay.getAspectRatio();
		float positionY = position.y;

		//	if (FlounderMouse.isDisplaySelected() && FlounderDisplay.isFocused()) {
		if (FlounderGuis.getSelector().getCursorX() >= positionX - (getCurrentWidth() / 2.0f) && FlounderGuis.getSelector().getCursorX() <= positionX + (getCurrentWidth() / 2.0f)) {
			if (FlounderGuis.getSelector().getCursorY() >= positionY - (getCurrentHeight() / 2.0f) && FlounderGuis.getSelector().getCursorY() <= positionY + (getCurrentHeight() / 2.0f)) {
				return true;
			}
		}
		//	}

		return false;
	}

	protected Vector2f getPosition() {
		float scaleFactor = (currentScale - 1.0f) / 2.0f;
		float xChange = scaleFactor * originalWidth;
		float yChange = scaleFactor * originalHeight;

		switch (guiAlign) {
			case LEFT:
				return position.set((currentX - xChange) + (currentScale * originalWidth * 0.5f), currentY - yChange);
			case CENTRE:
				return position.set((currentX - xChange) * (currentScale * FlounderDisplay.getAspectRatio()), currentY - yChange);
			case RIGHT:
				return position.set((currentX - xChange) * FlounderDisplay.getAspectRatio(), currentY - yChange);
			default:
				return position.set((currentX - xChange), currentY - yChange);
		}
	}

	public float getRotation() {
		return rotation;
	}

	public void setRotation(float rotation) {
		this.rotation = rotation;
	}

	protected float getTotalBorderSize() {
		if (solidBorder) {
			if (borderSize == 0.0f) {
				return 0.0f;
			} else {
				return calculateEdgeStart() + borderSize;
			}
		} else if (glowBorder) {
			return calculateEdgeStart();
		} else {
			return 0.0f;
		}
	}
{'fraction_non_alphanumeric': 0.11137173953837493, 'fraction_numerical': 0.009945580784387315, 'mean_word_length': 3.8143631436314362, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2947650', 'n_tokens_mistral': 3789, 'n_tokens_neox': 3373, 'n_words': 936}