Example usage for com.badlogic.gdx.utils Align top

List of usage examples for com.badlogic.gdx.utils Align top

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils Align top.

Prototype

int top

To view the source code for com.badlogic.gdx.utils Align top.

Click Source Link

Usage

From source file:com.agateau.ui.UiBuilder.java

License:Apache License

private static int parseAlign(XmlReader.Element element) {
    String alignText = element.getAttribute("align", "");
    if (alignText.isEmpty()) {
        return -1;
    }/*from  w  w w  .ja v a2s . c om*/
    if (alignText.equals("center")) {
        return Align.center;
    } else if (alignText.equals("centerLeft")) {
        return Align.left;
    } else if (alignText.equals("centerRight")) {
        return Align.right;
    } else if (alignText.equals("topLeft")) {
        return Align.topLeft;
    } else if (alignText.equals("topCenter")) {
        return Align.top;
    } else if (alignText.equals("topRight")) {
        return Align.topRight;
    } else if (alignText.equals("bottomLeft")) {
        return Align.bottomLeft;
    } else if (alignText.equals("bottomCenter")) {
        return Align.bottom;
    } else if (alignText.equals("bottomRight")) {
        return Align.bottomRight;
    } else {
        throw new RuntimeException("Unknown value of 'align': " + alignText);
    }
}

From source file:com.badlogic.gdx.tests.dragome.examples.bullet.BulletTestCollection.java

@Override
public void create() {
    if (app == null) {
        app = Gdx.app;/*from  ww w . j ava 2s  .com*/
        tests[testIndex].create();
    }

    cameraController = new CameraInputController(tests[testIndex].camera);
    cameraController.activateKey = Keys.CONTROL_LEFT;
    cameraController.autoUpdate = false;
    cameraController.forwardTarget = false;
    cameraController.translateTarget = false;
    Gdx.input.setInputProcessor(new InputMultiplexer(cameraController, this, new GestureDetector(this)));

    font = new BitmapFont(false);
    hud = new Stage();
    hud.addActor(fpsLabel = new Label(" ", new Label.LabelStyle(font, Color.WHITE)));
    fpsLabel.setPosition(0, 0);
    hud.addActor(titleLabel = new Label(tests[testIndex].getClass().getSimpleName(),
            new Label.LabelStyle(font, Color.WHITE)));
    titleLabel.setY(hud.getHeight() - titleLabel.getHeight());
    hud.addActor(instructLabel = new Label("A\nB\nC\nD\nE\nF", new Label.LabelStyle(font, Color.WHITE)));
    instructLabel.setY(titleLabel.getY() - instructLabel.getHeight());
    instructLabel.setAlignment(Align.top | Align.left);
    instructLabel.setText(tests[testIndex].instructions);
}

From source file:com.crashinvaders.common.scene2d.HorizontalGroupExtended.java

License:Apache License

@Override
public void layout() {
    float spacing = this.spacing, padBottom = this.padBottom;
    int align = this.align;
    boolean reverse = this.reverse, round = this.round;

    float groupHeight = getHeight() - padTop - padBottom;
    float x = !reverse ? padLeft : getWidth() - padRight + spacing;
    Array<Actor> children = getVisibleChildren();
    for (int i = 0, n = children.size; i < n; i++) {
        Actor child = children.get(i);//www .ja  v a 2 s.  c  o m
        float width, height;
        if (child instanceof Layout) {
            Layout layout = (Layout) child;
            if (fill > 0)
                height = groupHeight * fill;
            else
                height = Math.min(layout.getPrefHeight(), groupHeight);
            height = Math.max(height, layout.getMinHeight());
            float maxHeight = layout.getMaxHeight();
            if (maxHeight > 0 && height > maxHeight)
                height = maxHeight;
            width = layout.getPrefWidth();
        } else {
            width = child.getWidth();
            height = child.getHeight();
            if (fill > 0)
                height *= fill;
        }

        float y = padBottom;
        if ((align & Align.top) != 0)
            y += groupHeight - height;
        else if ((align & Align.bottom) == 0) // center
            y += (groupHeight - height) / 2;

        if (reverse)
            x -= (width + spacing);
        if (round)
            child.setBounds(Math.round(x), Math.round(y), Math.round(width), Math.round(height));
        else
            child.setBounds(x, y, width, height);
        if (!reverse)
            x += (width + spacing);
    }
}

From source file:com.crashinvaders.common.scene2d.HorizontalGroupExtended.java

License:Apache License

/** Sets {@link Align#top} and clears {@link Align#bottom} for the alignment of widgets within the horizontal group. */
public HorizontalGroupExtended top() {
    align |= Align.top;
    align &= ~Align.bottom;//from   w  w w  .jav a2  s . co  m
    return this;
}

From source file:com.crashinvaders.common.scene2d.HorizontalGroupExtended.java

License:Apache License

/** Sets {@link Align#bottom} and clears {@link Align#top} for the alignment of widgets within the horizontal group. */
public HorizontalGroupExtended bottom() {
    align |= Align.bottom;//from  ww  w . j  ava  2  s  .co m
    align &= ~Align.top;
    return this;
}

From source file:com.kotcrab.vis.editor.module.scene.entitymanipulator.AlignmentToolsDialog.java

License:Apache License

public AlignmentToolsDialog(ModuleInjector injector) {
    injector.injectModules(this);

    setBackground(VisUI.getSkin().getDrawable("window-bg"));
    setTouchable(Touchable.enabled);//  www .ja v  a 2  s. co  m
    setVisible(false);

    top().left();
    defaults().left();
    TableUtils.setSpacingDefaults(this);

    VisTable horizontalAlign = new VisTable(true);

    VisImageButton alignLeft = new VisImageButton(Icons.ALIGN_LEFT.drawable(), "Align entities at left edge");
    VisImageButton alignRight = new VisImageButton(Icons.ALIGN_RIGHT.drawable(),
            "Align entities at right edge");
    VisImageButton alignCenterX = new VisImageButton(Icons.ALIGN_CENTER_X.drawable(),
            "Center entities at x axis");
    VisImageButton alignTop = new VisImageButton(Icons.ALIGN_BOTTOM.drawable(), "Align entities at top edge");
    VisImageButton alignBottom = new VisImageButton(Icons.ALIGN_TOP.drawable(),
            "Align entities at bottom edge");
    VisImageButton alignCenterY = new VisImageButton(Icons.ALIGN_CENTER_Y.drawable(),
            "Center entities at y axis");

    VisImageButton closeButton = new VisImageButton("close-window");

    horizontalAlign.add("Horizontal").width(70);
    horizontalAlign.add(alignLeft);
    horizontalAlign.add(alignRight);
    horizontalAlign.add(alignCenterX);

    VisTable verticalAlign = new VisTable(true);

    verticalAlign.add("Vertical").width(70);
    verticalAlign.add(alignTop);
    verticalAlign.add(alignBottom);
    verticalAlign.add(alignCenterY);

    add(new VisLabel("Alignment", Align.center)).expandX().fillX().top();
    add(closeButton).right().row();
    add(horizontalAlign).padLeft(3).colspan(2).row();
    add(verticalAlign).padLeft(3).colspan(2);

    pack();

    alignLeft.addListener(new VisChangeListener((event, actor) -> alignSelected(Align.left)));
    alignRight.addListener(new VisChangeListener((event, actor) -> alignSelected(Align.right)));
    alignCenterX.addListener(new VisChangeListener((event, actor) -> alignSelectedCenter(false)));
    alignTop.addListener(new VisChangeListener((event, actor) -> alignSelected(Align.top)));
    alignBottom.addListener(new VisChangeListener((event, actor) -> alignSelected(Align.bottom)));
    alignCenterY.addListener(new VisChangeListener((event, actor) -> alignSelectedCenter(true)));

    closeButton.addListener(new VisChangeListener((event, actor) -> setVisible(false)));
}

From source file:com.kotcrab.vis.editor.module.scene.entitymanipulator.AlignmentToolsDialog.java

License:Apache License

private void alignSelected(int align) {
    ImmutableArray<EntityProxy> selectedEntities = entityManipulator.getSelectedEntities();
    if (selectedEntities.size() == 0)
        return;//from ww w  .  jav a2  s .co m

    UndoableActionGroup undoableGroup = new UndoableActionGroup("Change Alignment");

    if (align == Align.left || align == Align.right) {
        float targetX = selectedEntities.get(0).getX();

        for (EntityProxy proxy : selectedEntities) {
            if (align == Align.left) {
                if (proxy.getX() < targetX)
                    targetX = proxy.getX();
            } else {
                if (proxy.getX() > targetX)
                    targetX = proxy.getX();
            }
        }

        for (EntityProxy proxy : selectedEntities) {
            TransformEntityAction action = new TransformEntityAction(proxy);
            proxy.setX(targetX);
            action.saveNewData(proxy);
            undoableGroup.add(action);
        }
    }

    if (align == Align.top || align == Align.bottom) {
        float targetY = selectedEntities.get(0).getY();

        for (EntityProxy proxy : selectedEntities) {
            if (align == Align.top) {
                if (proxy.getY() < targetY)
                    targetY = proxy.getY();
            } else {
                if (proxy.getY() > targetY)
                    targetY = proxy.getY();
            }
        }

        for (EntityProxy proxy : selectedEntities) {
            TransformEntityAction action = new TransformEntityAction(proxy);
            proxy.setY(targetY);
            action.saveNewData(proxy);
            undoableGroup.add(action);
        }
    }

    undoableGroup.finalizeGroup();
    undoModule.add(undoableGroup);
}

From source file:com.kotcrab.vis.editor.ui.dialog.DetailsDialog.java

License:Apache License

public DetailsDialog(String text, String title, String details) {
    super(title);

    addCloseButton();/*from  w w w  . j  a v a 2 s  . c  o m*/
    closeOnEscape();
    setModal(true);

    VisTextButton copyButton = new VisTextButton("Copy");
    VisTextButton okButton = new VisTextButton("OK");
    VisLabel errorLabel = new VisLabel(details);
    errorLabel.setAlignment(Align.top | Align.left);

    VisTable detailsTable = new VisTable(true);
    detailsTable.add("Details:").left().expand().padTop(6);
    detailsTable.add(copyButton);
    detailsTable.row();
    detailsTable.add(createScrollPane(errorLabel)).colspan(2).width(600).height(300);

    if (text != null)
        add(text).row();
    add(detailsTable).row();
    add(okButton).padBottom(3).padTop(3);

    okButton.addListener(new VisChangeListener((event, actor) -> fadeOut()));

    copyButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            Gdx.app.getClipboard().setContents((errorLabel.getText().toString()));
            copyButton.setText("Copied");
        }
    });

    pack();
    centerWindow();
}

From source file:com.kotcrab.vis.ui.building.utilities.Alignment.java

License:Apache License

/** @return true for TOP, TOP_LEFT and TOP_RIGHT. */
public boolean isAlignedWithTop() {
    return (alignment & Align.top) != 0;
}

From source file:com.kotcrab.vis.ui.util.ActorUtils.java

License:Apache License

/**
 * Makes sures that actor will be fully visible in stage. If it's necessary actor position will be changed to fit it
 * on screen./*from ww w .  j a  v a  2s. c  om*/
 */
public static void keepWithinStage(Stage stage, Actor actor) {
    //taken from scene2d.ui Window
    Camera camera = stage.getCamera();
    if (camera instanceof OrthographicCamera) {
        OrthographicCamera orthographicCamera = (OrthographicCamera) camera;
        float parentWidth = stage.getWidth();
        float parentHeight = stage.getHeight();
        if (actor.getX(Align.right) - camera.position.x > parentWidth / 2 / orthographicCamera.zoom)
            actor.setPosition(camera.position.x + parentWidth / 2 / orthographicCamera.zoom,
                    actor.getY(Align.right), Align.right);
        if (actor.getX(Align.left) - camera.position.x < -parentWidth / 2 / orthographicCamera.zoom)
            actor.setPosition(camera.position.x - parentWidth / 2 / orthographicCamera.zoom,
                    actor.getY(Align.left), Align.left);
        if (actor.getY(Align.top) - camera.position.y > parentHeight / 2 / orthographicCamera.zoom)
            actor.setPosition(actor.getX(Align.top),
                    camera.position.y + parentHeight / 2 / orthographicCamera.zoom, Align.top);
        if (actor.getY(Align.bottom) - camera.position.y < -parentHeight / 2 / orthographicCamera.zoom)
            actor.setPosition(actor.getX(Align.bottom),
                    camera.position.y - parentHeight / 2 / orthographicCamera.zoom, Align.bottom);
    } else if (actor.getParent() == stage.getRoot()) {
        float parentWidth = stage.getWidth();
        float parentHeight = stage.getHeight();
        if (actor.getX() < 0)
            actor.setX(0);
        if (actor.getRight() > parentWidth)
            actor.setX(parentWidth - actor.getWidth());
        if (actor.getY() < 0)
            actor.setY(0);
        if (actor.getTop() > parentHeight)
            actor.setY(parentHeight - actor.getHeight());
    }
}