Search in sources :

Example 1 with ScalingViewport

use of com.badlogic.gdx.utils.viewport.ScalingViewport in project libgdx by libgdx.

the class ViewportTest1 method getViewports.

public static Array<Viewport> getViewports(Camera camera) {
    int minWorldWidth = 640;
    int minWorldHeight = 480;
    int maxWorldWidth = 800;
    int maxWorldHeight = 480;
    Array<Viewport> viewports = new Array();
    viewports.add(new StretchViewport(minWorldWidth, minWorldHeight, camera));
    viewports.add(new FillViewport(minWorldWidth, minWorldHeight, camera));
    viewports.add(new FitViewport(minWorldWidth, minWorldHeight, camera));
    viewports.add(new ExtendViewport(minWorldWidth, minWorldHeight, camera));
    viewports.add(new ExtendViewport(minWorldWidth, minWorldHeight, maxWorldWidth, maxWorldHeight, camera));
    viewports.add(new ScreenViewport(camera));
    ScreenViewport screenViewport = new ScreenViewport(camera);
    screenViewport.setUnitsPerPixel(0.75f);
    viewports.add(screenViewport);
    viewports.add(new ScalingViewport(Scaling.none, minWorldWidth, minWorldHeight, camera));
    return viewports;
}
Also used : Array(com.badlogic.gdx.utils.Array) FillViewport(com.badlogic.gdx.utils.viewport.FillViewport) ExtendViewport(com.badlogic.gdx.utils.viewport.ExtendViewport) StretchViewport(com.badlogic.gdx.utils.viewport.StretchViewport) ExtendViewport(com.badlogic.gdx.utils.viewport.ExtendViewport) ScalingViewport(com.badlogic.gdx.utils.viewport.ScalingViewport) FitViewport(com.badlogic.gdx.utils.viewport.FitViewport) Viewport(com.badlogic.gdx.utils.viewport.Viewport) FillViewport(com.badlogic.gdx.utils.viewport.FillViewport) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) StretchViewport(com.badlogic.gdx.utils.viewport.StretchViewport) FitViewport(com.badlogic.gdx.utils.viewport.FitViewport) ScalingViewport(com.badlogic.gdx.utils.viewport.ScalingViewport)

Example 2 with ScalingViewport

use of com.badlogic.gdx.utils.viewport.ScalingViewport in project libgdx by libgdx.

the class ViewportTest2 method render.

public void render() {
    batch.setProjectionMatrix(camera.projection);
    batch.setTransformMatrix(camera.view);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.begin();
    // draw a white background so we are able to see the black bars
    batch.setColor(1, 1, 1, 1);
    batch.draw(texture, -4096, -4096, 4096, 4096, 8192, 8192, 1, 1, 0, 0, 0, 16, 16, false, false);
    batch.setColor(1, 0, 0, 1);
    batch.draw(texture, 150, 100, 16, 16, 32, 32, 1, 1, 45, 0, 0, 16, 16, false, false);
    font.draw(batch, viewport.getClass().getSimpleName(), 150, 100);
    batch.end();
    if (viewport instanceof ScalingViewport) {
        // This shows how to set the viewport to the whole screen and draw within the black bars.
        ScalingViewport scalingViewport = (ScalingViewport) viewport;
        int screenWidth = Gdx.graphics.getWidth();
        int screenHeight = Gdx.graphics.getHeight();
        HdpiUtils.glViewport(0, 0, screenWidth, screenHeight);
        batch.getProjectionMatrix().idt().setToOrtho2D(0, 0, screenWidth, screenHeight);
        batch.getTransformMatrix().idt();
        batch.begin();
        float leftGutterWidth = scalingViewport.getLeftGutterWidth();
        if (leftGutterWidth > 0) {
            batch.draw(texture, 0, 0, leftGutterWidth, screenHeight);
            batch.draw(texture, scalingViewport.getRightGutterX(), 0, scalingViewport.getRightGutterWidth(), screenHeight);
        }
        float bottomGutterHeight = scalingViewport.getBottomGutterHeight();
        if (bottomGutterHeight > 0) {
            batch.draw(texture, 0, 0, screenWidth, bottomGutterHeight);
            batch.draw(texture, 0, scalingViewport.getTopGutterY(), screenWidth, scalingViewport.getTopGutterHeight());
        }
        batch.end();
        // Restore viewport.
        viewport.update(screenWidth, screenHeight, true);
    }
}
Also used : ScalingViewport(com.badlogic.gdx.utils.viewport.ScalingViewport)

Example 3 with ScalingViewport

use of com.badlogic.gdx.utils.viewport.ScalingViewport in project libgdx by libgdx.

the class BaseG3dHudTest method createHUD.

protected void createHUD() {
    hud = new Stage(new ScalingViewport(Scaling.fit, PREF_HUDWIDTH, PREF_HUDHEIGHT));
    hudWidth = hud.getWidth();
    hudHeight = hud.getHeight();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    final List<String> modelsList = new List(skin);
    modelsList.setItems(models);
    modelsList.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (!modelsWindow.isCollapsed() && getTapCount() == 2) {
                onModelClicked(modelsList.getSelected());
                modelsWindow.collapse();
            }
        }
    });
    modelsWindow = addListWindow("Models", modelsList, 0, -1);
    fpsLabel = new Label("FPS: 999", skin);
    hud.addActor(fpsLabel);
    gridCheckBox = new CheckBox("Show grid", skin);
    gridCheckBox.setChecked(showAxes);
    gridCheckBox.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            showAxes = gridCheckBox.isChecked();
        }
    });
    gridCheckBox.setPosition(hudWidth - gridCheckBox.getWidth(), 0);
    hud.addActor(gridCheckBox);
    rotateCheckBox = new CheckBox("Rotate", skin);
    rotateCheckBox.setChecked(true);
    rotateCheckBox.setPosition(hudWidth - rotateCheckBox.getWidth(), gridCheckBox.getHeight());
    hud.addActor(rotateCheckBox);
    moveCheckBox = new CheckBox("Move", skin);
    moveCheckBox.setChecked(false);
    moveCheckBox.setPosition(hudWidth - moveCheckBox.getWidth(), rotateCheckBox.getTop());
    hud.addActor(moveCheckBox);
}
Also used : Label(com.badlogic.gdx.scenes.scene2d.ui.Label) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) List(com.badlogic.gdx.scenes.scene2d.ui.List) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) ScalingViewport(com.badlogic.gdx.utils.viewport.ScalingViewport)

Example 4 with ScalingViewport

use of com.badlogic.gdx.utils.viewport.ScalingViewport in project libgdx by libgdx.

the class StagePerformanceTest method create.

@Override
public void create() {
    batch = new SpriteBatch();
    font = new BitmapFont();
    stage = new Stage(new ScalingViewport(Scaling.fit, 24, 12));
    regions = new TextureRegion[8 * 8];
    sprites = new Sprite[24 * 12];
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    for (int y = 0; y < 8; y++) {
        for (int x = 0; x < 8; x++) {
            regions[x + y * 8] = new TextureRegion(texture, x * 32, y * 32, 32, 32);
        }
    }
    Random rand = new Random();
    for (int y = 0, i = 0; y < 12; y++) {
        for (int x = 0; x < 24; x++) {
            Image img = new Image(regions[rand.nextInt(8 * 8)]);
            img.setBounds(x, y, 1, 1);
            stage.addActor(img);
            sprites[i] = new Sprite(regions[rand.nextInt(8 * 8)]);
            sprites[i].setPosition(x, y);
            sprites[i].setSize(1, 1);
            i++;
        }
    }
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Random(java.util.Random) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) Stage(com.badlogic.gdx.scenes.scene2d.Stage) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) ScalingViewport(com.badlogic.gdx.utils.viewport.ScalingViewport)

Aggregations

ScalingViewport (com.badlogic.gdx.utils.viewport.ScalingViewport)4 Stage (com.badlogic.gdx.scenes.scene2d.Stage)2 Texture (com.badlogic.gdx.graphics.Texture)1 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)1 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)1 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)1 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)1 List (com.badlogic.gdx.scenes.scene2d.ui.List)1 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)1 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)1 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)1 Array (com.badlogic.gdx.utils.Array)1 ExtendViewport (com.badlogic.gdx.utils.viewport.ExtendViewport)1 FillViewport (com.badlogic.gdx.utils.viewport.FillViewport)1 FitViewport (com.badlogic.gdx.utils.viewport.FitViewport)1