Search in sources :

Example 1 with HorizontalAlign

use of org.terasology.nui.HorizontalAlign in project Terasology by MovingBlocks.

the class HTMLUtils method createParagraphRenderStyleFromCommonAttributes.

public static ParagraphRenderStyle createParagraphRenderStyleFromCommonAttributes(Attributes attributes) {
    Color textColor = getTextColor(attributes);
    ParagraphRenderStyle.FloatStyle floatStyle = getFloatStyle(attributes);
    ParagraphRenderStyle.ClearStyle clearStyle = getClearStyle(attributes);
    HorizontalAlign horizontalAlign = getHorizontalAlign(attributes);
    Color backgroundColor = getBackgroundColor(attributes);
    ContainerInteger paragraphMarginTop = getParagraphMarginTop(attributes);
    ContainerInteger paragraphMarginBottom = getParagraphMarginBottom(attributes);
    ContainerInteger paragraphMarginLeft = getParagraphMarginLeft(attributes);
    ContainerInteger paragraphMarginRight = getParagraphMarginRight(attributes);
    ContainerInteger paragraphPaddingTop = getParagraphPaddingTop(attributes);
    ContainerInteger paragraphPaddingBottom = getParagraphPaddingBottom(attributes);
    ContainerInteger paragraphPaddingLeft = getParagraphPaddingLeft(attributes);
    ContainerInteger paragraphPaddingRight = getParagraphPaddingRight(attributes);
    ContainerInteger minimumWidth = getMinimumWidth(attributes);
    return new ParagraphRenderStyle() {

        @Override
        public Color getColor(boolean hyperlink) {
            return textColor;
        }

        @Override
        public FloatStyle getFloatStyle() {
            return floatStyle;
        }

        @Override
        public ClearStyle getClearStyle() {
            return clearStyle;
        }

        @Override
        public HorizontalAlign getHorizontalAlignment() {
            return horizontalAlign;
        }

        @Override
        public Color getParagraphBackground() {
            return backgroundColor;
        }

        @Override
        public ContainerInteger getParagraphMarginTop() {
            return paragraphMarginTop;
        }

        @Override
        public ContainerInteger getParagraphMarginBottom() {
            return paragraphMarginBottom;
        }

        @Override
        public ContainerInteger getParagraphMarginLeft() {
            return paragraphMarginLeft;
        }

        @Override
        public ContainerInteger getParagraphMarginRight() {
            return paragraphMarginRight;
        }

        @Override
        public ContainerInteger getParagraphPaddingTop() {
            return paragraphPaddingTop;
        }

        @Override
        public ContainerInteger getParagraphPaddingBottom() {
            return paragraphPaddingBottom;
        }

        @Override
        public ContainerInteger getParagraphPaddingLeft() {
            return paragraphPaddingLeft;
        }

        @Override
        public ContainerInteger getParagraphPaddingRight() {
            return paragraphPaddingRight;
        }

        @Override
        public ContainerInteger getParagraphMinimumWidth() {
            return minimumWidth;
        }
    };
}
Also used : PercentageContainerInteger(org.terasology.engine.rendering.nui.widgets.browser.ui.style.PercentageContainerInteger) ContainerInteger(org.terasology.engine.rendering.nui.widgets.browser.ui.style.ContainerInteger) FixedContainerInteger(org.terasology.engine.rendering.nui.widgets.browser.ui.style.FixedContainerInteger) Color(org.terasology.nui.Color) HorizontalAlign(org.terasology.nui.HorizontalAlign) ParagraphRenderStyle(org.terasology.engine.rendering.nui.widgets.browser.ui.style.ParagraphRenderStyle)

Example 2 with HorizontalAlign

use of org.terasology.nui.HorizontalAlign in project Terasology by MovingBlocks.

the class LwjglCanvasRenderer method drawText.

@Override
public void drawText(String text, Font font, HorizontalAlign hAlign, VerticalAlign vAlign, Rectanglei absoluteRegionRectangle, Colorc color, Colorc shadowColor, float alpha, boolean underlined) {
    Rectanglei absoluteRegion = new Rectanglei(absoluteRegionRectangle);
    TextCacheKey key = new TextCacheKey(text, font, absoluteRegion.getSizeX(), hAlign, color, shadowColor, underlined);
    usedText.add(key);
    Map<Material, Mesh> fontMesh = cachedText.get(key);
    List<String> lines = TextLineBuilder.getLines(font, text, absoluteRegion.getSizeX());
    if (fontMesh != null) {
        for (Mesh mesh : fontMesh.values()) {
            if (mesh.isDisposed()) {
                fontMesh = null;
                break;
            }
        }
    }
    if (fontMesh == null) {
        fontMesh = fontMeshBuilder.createTextMesh((org.terasology.engine.rendering.assets.font.Font) font, lines, absoluteRegion.getSizeX(), hAlign, color, shadowColor, underlined);
        cachedText.put(key, fontMesh);
    }
    Vector2i offset = new Vector2i(absoluteRegion.minX, absoluteRegion.minY);
    offset.y += vAlign.getOffset(lines.size() * font.getLineHeight(), absoluteRegion.lengthY());
    fontMesh.entrySet().stream().filter(entry -> entry.getKey().isRenderable()).forEach(entry -> {
        entry.getKey().bindTextures();
        entry.getKey().setMatrix4("projectionMatrix", projMatrix);
        entry.getKey().setMatrix4("modelViewMatrix", modelMatrixStack);
        entry.getKey().setFloat4(CROPPING_BOUNDARIES_PARAM, requestedCropRegion.minX, requestedCropRegion.maxX, requestedCropRegion.minY, requestedCropRegion.maxY);
        entry.getKey().setFloat2("offset", offset.x, offset.y);
        entry.getKey().setFloat("alpha", alpha);
        entry.getValue().render();
    });
}
Also used : Quaternionf(org.joml.Quaternionf) GL11.glDisable(org.lwjgl.opengl.GL11.glDisable) GL11.glViewport(org.lwjgl.opengl.GL11.glViewport) Vector2ic(org.joml.Vector2ic) DisplayDevice(org.terasology.engine.core.subsystem.DisplayDevice) UITextureRegion(org.terasology.nui.UITextureRegion) Map(java.util.Map) Vector3f(org.joml.Vector3f) GL11(org.lwjgl.opengl.GL11) TeraMath(org.terasology.math.TeraMath) VerticalAlign(org.terasology.nui.VerticalAlign) Quaternionfc(org.joml.Quaternionfc) FrameBufferObject(org.terasology.engine.rendering.opengl.FrameBufferObject) GL_SRC_ALPHA(org.lwjgl.opengl.GL11.GL_SRC_ALPHA) RenderingConfig(org.terasology.engine.config.RenderingConfig) GL_DEPTH_TEST(org.lwjgl.opengl.GL11.GL_DEPTH_TEST) TextLineBuilder(org.terasology.nui.TextLineBuilder) Set(java.util.Set) ScaleMode(org.terasology.nui.ScaleMode) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) MeshBuilder(org.terasology.engine.rendering.assets.mesh.MeshBuilder) List(java.util.List) Context(org.terasology.engine.context.Context) TextureRegion(org.terasology.engine.rendering.assets.texture.TextureRegion) Vector2i(org.joml.Vector2i) Border(org.terasology.nui.Border) PropertyChangeListener(java.beans.PropertyChangeListener) Vector2f(org.joml.Vector2f) Matrix3f(org.joml.Matrix3f) LwjglFrameBufferObject(org.terasology.engine.rendering.opengl.LwjglFrameBufferObject) Matrix4fStack(org.joml.Matrix4fStack) Rectanglef(org.terasology.joml.geom.Rectanglef) Rectanglei(org.terasology.joml.geom.Rectanglei) Colorc(org.terasology.nui.Colorc) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) AABBfc(org.terasology.joml.geom.AABBfc) GL11.glClear(org.lwjgl.opengl.GL11.glClear) Font(org.terasology.nui.asset.font.Font) Matrix4f(org.joml.Matrix4f) FontMeshBuilder(org.terasology.engine.rendering.assets.font.FontMeshBuilder) PropertyChangeEvent(java.beans.PropertyChangeEvent) AssetManager(org.terasology.gestalt.assets.management.AssetManager) GL11.glEnable(org.lwjgl.opengl.GL11.glEnable) Assets(org.terasology.engine.utilities.Assets) Iterator(java.util.Iterator) Maps(com.google.common.collect.Maps) GL11.glBlendFunc(org.lwjgl.opengl.GL11.glBlendFunc) GL_ONE_MINUS_SRC_ALPHA(org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA) Vector3fc(org.joml.Vector3fc) Config(org.terasology.engine.config.Config) Material(org.terasology.engine.rendering.assets.material.Material) GL_BLEND(org.lwjgl.opengl.GL11.GL_BLEND) Mesh(org.terasology.engine.rendering.assets.mesh.Mesh) HorizontalAlign(org.terasology.nui.HorizontalAlign) Mesh(org.terasology.engine.rendering.assets.mesh.Mesh) Material(org.terasology.engine.rendering.assets.material.Material) Rectanglei(org.terasology.joml.geom.Rectanglei) Font(org.terasology.nui.asset.font.Font) Vector2i(org.joml.Vector2i)

Aggregations

Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Matrix3f (org.joml.Matrix3f)1 Matrix4f (org.joml.Matrix4f)1 Matrix4fStack (org.joml.Matrix4fStack)1 Quaternionf (org.joml.Quaternionf)1 Quaternionfc (org.joml.Quaternionfc)1 Vector2f (org.joml.Vector2f)1 Vector2i (org.joml.Vector2i)1 Vector2ic (org.joml.Vector2ic)1 Vector3f (org.joml.Vector3f)1 Vector3fc (org.joml.Vector3fc)1 GL11 (org.lwjgl.opengl.GL11)1