/*
 * Copyright 2020 MovingBlocks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.terasology.nui.backends.libgdx;

import com.badlogic.gdx.graphics.g2d.TextureRegion;
import org.terasology.gestalt.assets.AssetData;
import org.terasology.joml.geom.Rectanglef;
import org.terasology.joml.geom.Rectanglei;
import org.joml.Vector2i;
import org.terasology.nui.UITextureRegion;
import org.terasology.nui.util.RectUtility;

public class LibGDXTexture implements UITextureRegion, AssetData {
    private final TextureRegion texture;

    public LibGDXTexture(TextureRegion texture) {
        this.texture = texture;
    }

    /**
     * @return The region of the texture represented by this asset
     */
    @Override
    public Rectanglef getRegion() {
        return RectUtility.createFromMinAndSize((float) texture.getRegionX(), texture.getRegionY(), texture.getRegionWidth(), texture.getRegionHeight());
    }

    /**
     * @return The pixel region of the texture represented by this asset
     */
    @Override
    public Rectanglei getPixelRegion() {
        return RectUtility.createFromMinAndSize(texture.getRegionX(), texture.getRegionY(), texture.getRegionWidth(), texture.getRegionHeight());
    }

    @Override
    public int getWidth() {
        return texture.getRegionWidth();
    }

    @Override
    public int getHeight() {
        return texture.getRegionHeight();
    }

    @Override
    public Vector2i size() {
        return new Vector2i(texture.getRegionWidth(), texture.getRegionHeight());
    }

    public TextureRegion getGdxTexture() {
        return texture;
    }
}

@@ -1280,55 +1280,195 @@
     
-return RectUtility.createFromMinAndSize((float)
+float minX = texture.isFlipX() ? texture.getTexture().getWidth() - texture.getRegionX() : texture.getRegionX();%0A        float minY = texture.isFlipY() ? texture.getTexture().getHeight() -
  tex
@@ -1473,36 +1473,37 @@
 exture.getRegion
-X(),
+Y() :
  texture.getRegi
@@ -1499,32 +1499,92 @@
 ure.getRegionY()
+;%0A        return RectUtility.createFromMinAndSize(minX, minY
 , texture.getReg
@@ -1786,48 +1786,192 @@
     
-return RectUtility.createFromMinAndSize(
+int minX = texture.isFlipX() ? texture.getTexture().getWidth() - texture.getRegionX() : texture.getRegionX();%0A        int minY = texture.isFlipY() ? texture.getTexture().getHeight() - 
 text
@@ -1987,12 +1987,13 @@
 gion
-X(),
+Y() :
  tex
@@ -2009,16 +2009,76 @@
 egionY()
+;%0A        return RectUtility.createFromMinAndSize(minX, minY
 , textur

fix rendering flipped textures (#66)