Example usage for com.badlogic.gdx.graphics.g2d GlyphLayout setText

List of usage examples for com.badlogic.gdx.graphics.g2d GlyphLayout setText

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d GlyphLayout setText.

Prototype

public void setText(BitmapFont font, CharSequence str) 

Source Link

Document

Calls #setText(BitmapFont,CharSequence,int,int,Color,float,int,boolean,String) setText with the whole string, the font's current color, and no alignment or wrapping.

Usage

From source file:CB_UI.GL_UI.Views.AboutView.java

License:Open Source License

private void createControls() {
    this.removeChilds();

    if (this.isDisposed())
        return;/*from w  ww  . j a  va  2 s.  c o m*/

    this.setBackground(Sprites.AboutBack);
    float ref = UI_Size_Base.that.getWindowHeight() / 13;
    margin = UI_Size_Base.that.getMargin();
    CB_RectF CB_LogoRec = new CB_RectF(this.getHalfWidth() - (ref * 2.5f),
            this.getHeight() - ((ref * 5) / 4.11f) - ref - margin - margin, ref * 5, (ref * 5) / 4.11f);
    //Log.debug(log, "CB_Logo" + CB_LogoRec.toString());
    CB_Logo = new Image(CB_LogoRec, "CB_Logo", false);
    CB_Logo.setDrawable(new SpriteDrawable(Sprites.getSpriteDrawable("cachebox-logo")));
    this.addChild(CB_Logo);

    String VersionString = GlobalCore.getVersionString() + GlobalCore.br + GlobalCore.br + GlobalCore.aboutMsg;

    GlyphLayout layout = new GlyphLayout();
    layout.setText(Fonts.getSmall(), VersionString);

    descTextView = new Label(this.name + " descTextView", 0,
            CB_Logo.getY() - margin - margin - margin - layout.height, this.getWidth(), layout.height + margin);
    descTextView.setFont(Fonts.getSmall()).setHAlignment(HAlignment.CENTER);

    descTextView.setWrappedText(VersionString);
    this.addChild(descTextView);

    CachesFoundLabel = new Label("", Fonts.getNormal(), COLOR.getLinkFontColor(), WrapType.SINGLELINE)
            .setHAlignment(HAlignment.CENTER);
    CachesFoundLabel.setWidth(getWidth());

    CachesFoundLabel.setOnClickListener(new OnClickListener() {
        GL_MsgBox ms;

        @Override
        public boolean onClick(GL_View_Base v, int x, int y, int pointer, int button) {

            ms = GL_MsgBox.Show(Translation.Get("LoadFounds"), Translation.Get("AdjustFinds"),
                    MessageBoxButtons.YesNo, MessageBoxIcon.GC_Live, new OnMsgBoxClickListener() {

                        @Override
                        public boolean onClick(int which, Object data) {
                            // Behandle das ergebniss
                            switch (which) {
                            case 1:
                                ms.close();
                                pd = CancelWaitDialog.ShowWait(Translation.Get("LoadFounds"),
                                        DownloadAnimation.GetINSTANCE(), new IcancelListener() {

                                            @Override
                                            public void isCanceld() {

                                            }
                                        }, new cancelRunnable() {

                                            @Override
                                            public void run() {
                                                result = GroundspeakAPI.GetCachesFound(this);
                                                pd.close();

                                                if (result > -1) {
                                                    String Text = Translation.Get("FoundsSetTo",
                                                            String.valueOf(result));
                                                    GL_MsgBox.Show(Text, Translation.Get("LoadFinds!"),
                                                            MessageBoxButtons.OK, MessageBoxIcon.GC_Live, null);

                                                    Config.FoundOffset.setValue(result);
                                                    Config.AcceptChanges();
                                                    AboutView.this.refreshText();
                                                }
                                                if (result == GroundspeakAPI.CONNECTION_TIMEOUT) {
                                                    GL.that.Toast(ConnectionError.INSTANCE);
                                                }
                                                if (result == GroundspeakAPI.API_IS_UNAVAILABLE) {
                                                    GL.that.Toast(ApiUnavailable.INSTANCE);
                                                }
                                            }

                                            @Override
                                            public boolean cancel() {
                                                // TODO handle cancel
                                                return false;
                                            }
                                        });

                                break;
                            case 3:
                                ms.close();
                                GL.that.RunOnGL(new IRunOnGL() {

                                    @Override
                                    public void run() {
                                        NumericInputBox.Show(Translation.Get("TelMeFounds"),
                                                Translation.Get("AdjustFinds"), Config.FoundOffset.getValue(),
                                                mDialogListener);
                                    }
                                });

                                break;

                            }
                            return true;
                        }
                    });

            return true;
        }
    });

    this.addChild(CachesFoundLabel);

    createTable();

    refreshText();
}

From source file:CB_UI_Base.Math.GL_UISizes.java

License:Open Source License

/**
 * Berechnet die Positionen der UI-Elemente
 */// w ww  .  java  2  s .c  o m
private static void calcPos() {
    Log.debug(log, "GL_UISizes.calcPos()");

    float w = Global.isTab ? UI_Right.getWidth() : UI_Left.getWidth();
    float h = Global.isTab ? UI_Right.getHeight() : UI_Left.getHeight();

    Info.setPos(new Vector2(margin, (h - margin - Info.getHeight())));

    Float CompassMargin = (Info.getHeight() - Compass.getWidth()) / 2;

    Compass.setPos(new Vector2(Info.getX() + CompassMargin, Info.getY() + infoShadowHeight + CompassMargin));

    Toggle.setPos(new Vector2((w - margin - Toggle.getWidth()), h - margin - Toggle.getHeight()));

    ZoomBtn.setPos(new Vector2((w - margin - ZoomBtn.getWidth()), margin));

    InfoLine1.x = Compass.getMaxX() + margin;
    GlyphLayout bounds;
    if (Fonts.getNormal() != null) {
        bounds = new GlyphLayout();
        bounds.setText(Fonts.getSmall(), "52 34,806N ");
    } else {
        bounds = new GlyphLayout();
        bounds.height = 20;
        bounds.width = 100;
    }

    InfoLine2.x = Info.getX() + Info.getWidth() - bounds.width - (margin * 2);

    Float T1 = Info.getHeight() / 4;

    InfoLine1.y = Info.getMaxY() - T1;
    InfoLine2.y = Info.getY() + T1 + bounds.height;

    // Aufrumen
    CompassMargin = null;

}

From source file:com.bladecoder.engineeditor.ui.components.CustomList.java

License:Apache License

public void layout() {
    final BitmapFont font = style.font;
    final BitmapFont subfont = style.subtitleFont;
    final Drawable selectedDrawable = style.selection;

    cellRenderer.layout(style);/*from  ww  w.  j  av  a 2 s .c o  m*/

    GlyphLayout textLayout = new GlyphLayout();

    prefWidth = 0;
    for (int i = 0; i < items.size; i++) {

        textLayout.setText(font, cellRenderer.getCellTitle(items.get(i)));

        prefWidth = Math.max(textLayout.width, prefWidth);

        if (cellRenderer.hasImage()) {
            TextureRegion r = cellRenderer.getCellImage(items.get(i));

            float ih = r.getRegionHeight();
            float iw = r.getRegionWidth();

            if (ih > getItemHeight() - 10) {
                ih = getItemHeight() - 10;
                iw *= ih / r.getRegionHeight();
            }

            prefWidth = Math.max(iw + textLayout.width, prefWidth);
        }

        if (cellRenderer.hasSubtitle()) {
            String subtitle = cellRenderer.getCellSubTitle(items.get(i));

            if (subtitle != null) {
                textLayout.setText(subfont, subtitle);
                prefWidth = Math.max(textLayout.width, prefWidth);
            }
        }
    }

    prefWidth += selectedDrawable.getLeftWidth() + selectedDrawable.getRightWidth();

    prefHeight = items.size * cellRenderer.getItemHeight();

    Drawable background = style.background;
    if (background != null) {
        prefWidth += background.getLeftWidth() + background.getRightWidth();
        prefHeight += background.getTopHeight() + background.getBottomHeight();
    }
}

From source file:com.github.badoualy.badoualyve.ui.actor.Dialog.java

License:Open Source License

public Dialog() {
    font = gdxUtils().getDefaultFont();/*from   w w w  .ja  v  a  2s.c  om*/
    bg = gdxUtils().createImageFromTexture(AssetsUtils.BG_DIALOG);
    setSize(bg.getWidth(), bg.getHeight());
    addActor(bg);

    // Compute title width
    GlyphLayout layout = new GlyphLayout(); // Don't do this every frame! Store it as member
    layout.setText(font, inputValue);
    inputWidth = layout.width;

    // Compute message width
    layout = new GlyphLayout(); // Don't do this every frame! Store it as member
    layout.setText(font, message);
    messageWith = layout.width;
}

From source file:com.github.badoualy.badoualyve.ui.actor.Dialog.java

License:Open Source License

public void setTitle(String title) {
    this.title = title;

    // Compute new title width
    GlyphLayout layout = new GlyphLayout(); // Don't do this every frame! Store it as member
    layout.setText(font, title);
    titleWidth = layout.width;/*  w  ww .j  a v a 2s.c o  m*/
}

From source file:com.github.badoualy.badoualyve.ui.actor.Dialog.java

License:Open Source License

public void setInputValue(String inputValue) {
    this.inputValue = inputValue;
    // Compute new input width
    GlyphLayout layout = new GlyphLayout(); // Don't do this every frame! Store it as member
    layout.setText(font, inputValue);
    inputWidth = layout.width;/* w  ww  .  j a va2 s .  co m*/
}

From source file:com.github.badoualy.badoualyve.ui.actor.Dialog.java

License:Open Source License

public void keyTyped(char c) {
    inputValue += c;/*from  w w  w .j  a  va 2s  . c  o m*/
    // Compute new input width
    GlyphLayout layout = new GlyphLayout(); // Don't do this every frame! Store it as member
    layout.setText(font, inputValue);
    inputWidth = layout.width;
}

From source file:com.github.badoualy.badoualyve.ui.actor.StatDialog.java

License:Open Source License

public StatDialog(Player player) {
    this.player = player;

    bg = new Image(gdxUtils().getTexture(AssetsUtils.BG_STATS));
    setSize(bg.getWidth(), bg.getHeight());
    addActor(bg);/*from  w w  w. j  av  a 2 s.  com*/

    font = WantedGame.gdxUtils().getDefaultFont();
    smallFont = WantedGame.gdxUtils().getDefaultFontSmall();

    // Compute title width
    GlyphLayout layout = new GlyphLayout(); // Don't do this every frame! Store it as member
    layout.setText(font, player.name);
    titleWidth = layout.width;
}

From source file:com.github.badoualy.badoualyve.ui.actor.StatDialog.java

License:Open Source License

public void setTitle(String title) {
    this.title = title;

    // Compute title width
    GlyphLayout layout = new GlyphLayout(); // Don't do this every frame! Store it as member
    layout.setText(font, player.name);
    titleWidth = layout.width;//w  ww  .  j  a  va  2s .  c  om
}

From source file:com.kotcrab.vis.ui.widget.HighlightTextArea.java

License:Apache License

@Override
protected void calculateOffsets() {
    super.calculateOffsets();
    if (chunkUpdateScheduled == false)
        return;//  www  . j av  a  2 s .  c om
    chunkUpdateScheduled = false;
    highlights.sort();
    renderChunks.clear();

    String text = getText();

    Pool<GlyphLayout> layoutPool = Pools.get(GlyphLayout.class);
    GlyphLayout layout = layoutPool.obtain();
    boolean carryHighlight = false;
    for (int lineIdx = 0, highlightIdx = 0; lineIdx < linesBreak.size; lineIdx += 2) {
        int lineStart = linesBreak.items[lineIdx];
        int lineEnd = linesBreak.items[lineIdx + 1];
        int lineProgress = lineStart;
        float chunkOffset = 0;

        for (; highlightIdx < highlights.size;) {
            Highlight highlight = highlights.get(highlightIdx);
            if (highlight.getStart() > lineEnd) {
                break;
            }

            if (highlight.getStart() == lineProgress || carryHighlight) {
                renderChunks.add(new Chunk(text.substring(lineProgress, Math.min(highlight.getEnd(), lineEnd)),
                        highlight.getColor(), chunkOffset, lineIdx));
                lineProgress = Math.min(highlight.getEnd(), lineEnd);

                if (highlight.getEnd() > lineEnd) {
                    carryHighlight = true;
                } else {
                    carryHighlight = false;
                    highlightIdx++;
                }
            } else {
                //protect against overlapping highlights
                boolean noMatch = false;
                while (highlight.getStart() <= lineProgress) {
                    highlightIdx++;
                    if (highlightIdx >= highlights.size) {
                        noMatch = true;
                        break;
                    }
                    highlight = highlights.get(highlightIdx);
                    if (highlight.getStart() > lineEnd) {
                        noMatch = true;
                        break;
                    }
                }
                if (noMatch)
                    break;
                renderChunks.add(new Chunk(text.substring(lineProgress, highlight.getStart()), defaultColor,
                        chunkOffset, lineIdx));
                lineProgress = highlight.getStart();
            }

            Chunk chunk = renderChunks.peek();
            layout.setText(style.font, chunk.text);
            chunkOffset += layout.width;
            //current highlight needs to be applied to next line meaning that there is no other highlights that can be applied to currently parsed line
            if (carryHighlight)
                break;
        }

        if (lineProgress < lineEnd) {
            renderChunks
                    .add(new Chunk(text.substring(lineProgress, lineEnd), defaultColor, chunkOffset, lineIdx));
        }
    }

    maxAreaWidth = 0;
    for (String line : text.split("\\n")) {
        layout.setText(style.font, line);
        maxAreaWidth = Math.max(maxAreaWidth, layout.width + 30);
    }

    layoutPool.free(layout);
    updateScrollLayout();
}