Example usage for com.badlogic.gdx.utils Scaling fit

List of usage examples for com.badlogic.gdx.utils Scaling fit

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils Scaling fit.

Prototype

Scaling fit

To view the source code for com.badlogic.gdx.utils Scaling fit.

Click Source Link

Document

Scales the source to fit the target while keeping the same aspect ratio.

Usage

From source file:com.agateau.pixelwheels.screens.PwStageScreen.java

License:Open Source License

public PwStageScreen(UiAssets uiAssets) {
    super(new ScalingViewport(Scaling.fit, WIDTH, HEIGHT));

    Image image = new Image();
    image.setDrawable(new TiledDrawable(uiAssets.background));
    image.setFillParent(true);// w  ww  .ja va2s  .co  m
    getStage().addActor(image);
}

From source file:com.agateau.ui.gallery.TabbedMenuScreen.java

License:Apache License

TabbedMenuScreen() {
    super(new ScalingViewport(Scaling.fit, 800, 480));
    UiAssets assets = new UiAssets();
    mSkin = assets.skin;
    setupUi();
}

From source file:com.badlogic.gdx.tests.LetterBoxTest2.java

License:Apache License

public void resize(int width, int height) {
    stage.setViewport(width, height, false);
    Vector2 size = Scaling.fit.apply(300, 200, width, height);
    root.setBounds((width - size.x) / 2, (height - size.y) / 2, size.x, size.y);
    root.invalidate();/*  w ww  .jav a2s.  co  m*/
}

From source file:com.badlogic.gdx.tests.LetterBoxTest3.java

License:Apache License

public void resize(int width, int height) {
    Vector2 size = Scaling.fit.apply(300, 200, width, height);
    int viewportX = (int) (width - size.x) / 2;
    int viewportY = (int) (height - size.y) / 2;
    int viewportWidth = (int) size.x;
    int viewportHeight = (int) size.y;
    Gdx.gl.glViewport(viewportX, viewportY, viewportWidth, viewportHeight);
    stage.setViewport(300, 200, true, viewportX, viewportY, viewportWidth, viewportHeight);
}

From source file:com.bladecoder.engine.ui.SceneExtendViewport.java

License:Apache License

@Override
public void update(int screenWidth, int screenHeight, boolean centerCamera) {
    // Fit min size to the screen.
    float worldWidth = minWorldWidth;
    float worldHeight = minWorldHeight;
    Vector2 scaled = Scaling.fit.apply(worldWidth, worldHeight, screenWidth, screenHeight);

    // Extend in the short direction.
    int viewportWidth = Math.round(scaled.x);
    int viewportHeight = Math.round(scaled.y);
    if (viewportWidth < screenWidth) {
        float toViewportSpace = viewportHeight / worldHeight;
        float toWorldSpace = worldHeight / viewportHeight;
        float lengthen = (screenWidth - viewportWidth) * toWorldSpace;
        if (maxWorldWidth > 0)
            lengthen = Math.min(lengthen, maxWorldWidth - minWorldWidth);
        worldWidth += lengthen;/*w w w  . j av a  2 s  .c o  m*/
        viewportWidth += Math.round(lengthen * toViewportSpace);
    } else if (viewportHeight < screenHeight) {
        float toViewportSpace = viewportWidth / worldWidth;
        float toWorldSpace = worldWidth / viewportWidth;
        float lengthen = (screenHeight - viewportHeight) * toWorldSpace;
        if (maxWorldHeight > 0)
            lengthen = Math.min(lengthen, maxWorldHeight - minWorldHeight);
        worldHeight += lengthen;
        viewportHeight += Math.round(lengthen * toViewportSpace);
    }

    super.setWorldSize(worldWidth, worldHeight);

    // Center.
    setScreenBounds((screenWidth - viewportWidth) / 2, (screenHeight - viewportHeight) / 2, viewportWidth,
            viewportHeight);

    apply(centerCamera);

    EngineLogger.debug("SCREEN VIEWPORT: " + getScreenWidth() + "x" + getScreenHeight());
    EngineLogger.debug("SCREEN WORLD: " + getWorldWidth() + "x" + getWorldHeight());
}

From source file:com.bladecoder.engine.ui.SceneFitViewport.java

License:Apache License

@Override
public void update(int screenWidth, int screenHeight, boolean centerCamera) {
    Vector2 scaled = Scaling.fit.apply(getWorldWidth(), getWorldHeight(), screenWidth, screenHeight);
    setScreenSize(Math.round(scaled.x), Math.round(scaled.y));
    // center the viewport in the middle of the screen
    setScreenPosition((screenWidth - getScreenWidth()) / 2, (screenHeight - getScreenHeight()) / 2);

    apply(centerCamera);//from w  w w.  j ava2s. c o m
}

From source file:com.bladecoder.engineeditor.ui.EditSceneDialog.java

License:Apache License

@SuppressWarnings("unchecked")
public EditSceneDialog(Skin skin, World parent, Scene e) {

    super(skin);/* w  w  w  .  j  a  va  2 s  . co  m*/

    id = InputPanelFactory.createInputPanel(skin, "Scene ID",
            "The ID is mandatory for scenes. \nIDs can not contain '.' or '_' characters.", true);
    backgroundAtlas = InputPanelFactory.createInputPanel(skin, "Background Atlas",
            "The atlas where the background for the scene is located", atlasList, false);
    backgroundRegion = InputPanelFactory.createInputPanel(skin, "Background Region Id",
            "The region id for the background.", new String[0], false);
    depthVector = InputPanelFactory.createInputPanel(skin, "Depth Vector",
            "X: the actor 'y' position for a 0.0 scale, Y: the actor 'y' position for a 1.0 scale.",
            Param.Type.VECTOR2, false);
    state = InputPanelFactory.createInputPanel(skin, "State", "The initial state for the scene.", false);
    music = InputPanelFactory.createInputPanel(skin, "Music Filename", "The music for the scene", musicList,
            false);
    loopMusic = InputPanelFactory.createInputPanel(skin, "Loop Music", "If the music is playing in looping",
            Param.Type.BOOLEAN, false);
    initialMusicDelay = InputPanelFactory.createInputPanel(skin, "Initial music delay",
            "The time to wait before playing", Param.Type.FLOAT, true, "0");
    repeatMusicDelay = InputPanelFactory.createInputPanel(skin, "Repeat music delay",
            "The time to wait before repetitions", Param.Type.FLOAT, true, "0");

    sceneSize = InputPanelFactory.createInputPanel(skin, "Scene Dimension",
            "Sets the size of the scene. If empty, the background image size is used as the scene dimension.",
            Param.Type.DIMENSION, false);

    bgImage = new Image();
    bgImage.setScaling(Scaling.fit);
    infoContainer = new Container<Image>(bgImage);
    setInfo(INFO);

    ((SelectBox<String>) backgroundAtlas.getField()).addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            try {
                fillBGRegions(backgroundAtlas, backgroundRegion);
            } catch (Exception e) {
                Message.showMsg(getStage(), "Error loading regions from selected atlas", 4);
            }
        }
    });

    ((SelectBox<String>) backgroundRegion.getField()).addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            showBgImage(backgroundRegion.getText());
        }
    });

    try {
        fillBGRegions(backgroundAtlas, backgroundRegion);
    } catch (Exception e2) {
        EditorLogger.error("Error loading regions from selected atlas");
    }

    init(parent, e, new InputPanel[] { id, backgroundAtlas, backgroundRegion, depthVector, state, sceneSize,
            music, loopMusic, initialMusicDelay, repeatMusicDelay });
}

From source file:com.digitale.screens.CharPicker.java

License:Open Source License

/**
 * /*from w  w w  .  j av a2 s . c om*/
 */
public void setAvatarPicture() {
    if (currentAvatar == null || currentAvatar.equals("avatar00.jpg")) {
        imageActor = new Image(image0, Scaling.fit, Align.CENTER, "avatar");
    } else {
        if (currentAvatar.equals("avatar01.jpg")) {
            imageActor = new Image(image1, Scaling.fit, Align.CENTER, "avatar");
        }
        if (currentAvatar.equals("avatar02.jpg")) {
            imageActor = new Image(image2, Scaling.fit, Align.CENTER, "avatar");
        }
        if (currentAvatar.equals("avatar03.jpg")) {
            imageActor = new Image(image3, Scaling.fit, Align.CENTER, "avatar");
        }
        if (currentAvatar.equals("avatar04.jpg")) {
            imageActor = new Image(image4, Scaling.fit, Align.CENTER, "avatar");
        }
        if (currentAvatar.equals("avatar05.jpg")) {
            imageActor = new Image(image5, Scaling.fit, Align.CENTER, "avatar");
        }
        if (currentAvatar.equals("avatar06.jpg")) {
            imageActor = new Image(image6, Scaling.fit, Align.CENTER, "avatar");
        }
        if (currentAvatar.equals("avatar07.jpg")) {
            imageActor = new Image(image7, Scaling.fit, Align.CENTER, "avatar");
        }
        if (currentAvatar.equals("avatar08.jpg")) {
            imageActor = new Image(image8, Scaling.fit, Align.CENTER, "avatar");
        }

        if (currentAvatar.equals("avatar09.jpg")) {
            imageActor = new Image(image9, Scaling.fit, Align.CENTER, "avatar");
        }

    }
    imageActor.invalidate();
}

From source file:com.kotcrab.vis.editor.module.project.assetsmanager.AtlasItem.java

License:Apache License

public AtlasItem(String relativeAtlasPath, AtlasRegion region) {
    super(VisUI.getSkin());
    this.relativeAtlasPath = relativeAtlasPath;
    this.region = region;

    assetDescriptor = new AtlasRegionAsset(relativeAtlasPath, region.name);

    setTouchable(Touchable.enabled);//from  ww  w  . ja  v  a 2 s .  com
    setBackground("menu-bg");

    Image img = new Image(region);
    img.setScaling(Scaling.fit);
    add(img).expand().fill().row();

    VisLabel name = new VisLabel(region.name, "small");
    name.setWrap(true);
    name.setAlignment(Align.center);
    add(name).expandX().fillX();
}

From source file:com.kotcrab.vis.editor.module.project.assetsmanager.FileItem.java

License:Apache License

private void createContent() {
    String ext = file.extension();
    String relativePath = fileAccess.relativizeToAssetsFolder(file);

    boolean texture = ProjectPathUtils.isTexture(file);
    boolean atlas = ProjectPathUtils.isTextureAtlas(file);

    if (file.isDirectory()) {
        type = AssetType.DIRECTORY;//from w w w  . j  a  v a2 s. co m

        Drawable icon;
        AssetDirectoryDescriptor desc = assetsMetadata.getAsDirectoryDescriptor(file);
        if (desc != null) {
            icon = desc.getAssetsViewIcon();
        } else {
            icon = Icons.FOLDER_MEDIUM.drawable();
        }
        add(new VisImage(icon, Scaling.fillX)).row();

        name = new VisLabel(file.nameWithoutExtension());
    }

    if (ProjectPathUtils.isTrueTypeFont(file)) {
        createDefaultView(AssetType.TTF_FONT, "TTF Font", true);
        return;
    }

    if (ProjectPathUtils.isBitmapFont(file)) {
        createDefaultView(AssetType.BMP_FONT_FILE, "BMP Font", true);
        return;
    }

    if (ProjectPathUtils.isBitmapFontTexture(file)) {
        createDefaultView(AssetType.BMP_FONT_TEXTURE, "BMP Font Texture", true);
        return;
    }

    if (ProjectPathUtils.isTextureAtlasImage(file)) {
        createDefaultView(AssetType.TEXTURE_ATLAS_IMAGE, "TextureAtlas Image", true);
        return;
    }

    if (texture || atlas) {
        type = texture ? AssetType.TEXTURE : AssetType.TEXTURE_ATLAS;

        //don't create region preview for files excluded from texture cache
        AssetDirectoryDescriptor desc = assetsMetadata.getAsDirectoryDescriptorRecursively(file);
        if (desc != null && desc.isExcludeFromTextureCache()) {
            createDefaultView(type, texture ? "Texture" : "Texture Atlas", true);
            return;
        }

        name = new VisLabel(texture ? file.nameWithoutExtension() : file.name(), "small");

        TextureRegion region;

        if (atlas) {
            region = textureCache.getRegion(new AtlasRegionAsset(relativePath, null));
        } else {
            region = textureCache.getRegion(new TextureRegionAsset(relativePath));
        }

        Image img = new Image(region);
        img.setScaling(Scaling.fit);
        add(img).expand().fill().row();

        this.region = region;

        return;
    }

    if (ProjectPathUtils.isParticle(file)) {
        createDefaultView(AssetType.PARTICLE_EFFECT, "Particle Effect", true);
        return;
    }

    if (ProjectPathUtils.isMusicFile(assetsMetadata, file)) {
        createDefaultView(AssetType.MUSIC, "Music");
        return;
    }

    if (ProjectPathUtils.isSoundFile(assetsMetadata, file)) {
        createDefaultView(AssetType.SOUND, "Sound");
        return;
    }

    if (ProjectPathUtils.isFragmentShader(file)) {
        createDefaultView(AssetType.FRAGMENT_SHADER, "Fragment Shader", true);
        return;
    }

    if (ProjectPathUtils.isVertexShader(file)) {
        createDefaultView(AssetType.VERTEX_SHADER, "Vertex Shader", true);
        return;
    }

    if (ProjectPathUtils.isScene(file)) {
        createDefaultView(AssetType.SCENE, "Scene", true);
        return;
    }

    support = findSupportForDirectory(file, relativePath);
    if (support != null) {
        ContentItemProperties item = support.getContentItemProperties(file, relativePath, ext);
        if (item != null) {
            createDefaultView(item.type, item.title, item.hideExtension);
            return;
        }
    }

    type = AssetType.UNKNOWN;
    name = new VisLabel(file.name());
}