Search in sources :

Example 26 with Color

use of org.terasology.rendering.nui.Color in project Terasology by MovingBlocks.

the class ColorTypeHandlerTest method testDeserializeHex.

@Test
public void testDeserializeHex() {
    PersistedData data = new PersistedString("DEADBEEF");
    Color color = handler.deserialize(data, deserializationContext);
    Assert.assertEquals(0xDEADBEEF, color.rgba());
}
Also used : PersistedString(org.terasology.persistence.typeHandling.inMemory.PersistedString) Color(org.terasology.rendering.nui.Color) PersistedData(org.terasology.persistence.typeHandling.PersistedData) Test(org.junit.Test)

Example 27 with Color

use of org.terasology.rendering.nui.Color in project Terasology by MovingBlocks.

the class ColorTypeHandlerTest method testSerialize.

@Test
public void testSerialize() {
    SerializationContext serializationContext = Mockito.mock(SerializationContext.class);
    handler.serialize(new Color(0x010380FF), serializationContext);
    Mockito.verify(serializationContext).create(1, 3, 128, 255);
}
Also used : SerializationContext(org.terasology.persistence.typeHandling.SerializationContext) Color(org.terasology.rendering.nui.Color) Test(org.junit.Test)

Example 28 with Color

use of org.terasology.rendering.nui.Color in project Terasology by MovingBlocks.

the class ColorTypeHandlerTest method testDeserializeArray.

@Test
public void testDeserializeArray() {
    JsonArray array = new Gson().fromJson("[12, 34, 56, 78]", JsonArray.class);
    PersistedData data = new GsonPersistedDataArray(array);
    Color color = handler.deserialize(data, deserializationContext);
    Assert.assertEquals(12, color.r());
    Assert.assertEquals(34, color.g());
    Assert.assertEquals(56, color.b());
    Assert.assertEquals(78, color.a());
}
Also used : JsonArray(com.google.gson.JsonArray) Color(org.terasology.rendering.nui.Color) Gson(com.google.gson.Gson) PersistedData(org.terasology.persistence.typeHandling.PersistedData) GsonPersistedDataArray(org.terasology.persistence.typeHandling.gson.GsonPersistedDataArray) Test(org.junit.Test)

Example 29 with Color

use of org.terasology.rendering.nui.Color in project Terasology by MovingBlocks.

the class TextureDataFactoryTest method testRedColorNoAlphaTransformedToTextureUri.

@Test
public void testRedColorNoAlphaTransformedToTextureUri() throws Exception {
    Color expectedColor = Color.RED;
    int expectedRed = -1;
    int expectedGreen = 0;
    int expectedBlue = 0;
    int expectedAlpha = -1;
    testRepeatedColorInDataTexture(expectedColor, expectedRed, expectedGreen, expectedBlue, expectedAlpha);
}
Also used : Color(org.terasology.rendering.nui.Color) Test(org.junit.Test)

Example 30 with Color

use of org.terasology.rendering.nui.Color in project Terasology by MovingBlocks.

the class FloraFacetLayer method render.

@Override
public void render(BufferedImage img, Region region) {
    FloraFacet treeFacet = region.getFacet(FloraFacet.class);
    Graphics2D g = img.createGraphics();
    int width = img.getWidth();
    ColorModel colorModel = img.getColorModel();
    ColorBlender blender = ColorBlenders.forColorModel(ColorModels.RGBA, colorModel);
    DataBufferInt dataBuffer = (DataBufferInt) img.getRaster().getDataBuffer();
    for (Entry<BaseVector3i, FloraType> entry : treeFacet.getRelativeEntries().entrySet()) {
        FloraType treeGen = entry.getValue();
        int wx = entry.getKey().getX();
        int wz = entry.getKey().getZ();
        Color color = colorFunc.apply(treeGen);
        int src = color.rgba();
        int dst = dataBuffer.getElem(wz * width + wx);
        int mix = blender.blend(src, dst);
        dataBuffer.setElem(wz * width + wx, mix);
    }
    g.dispose();
}
Also used : FloraType(org.terasology.core.world.generator.rasterizers.FloraType) ColorBlender(org.terasology.world.viewer.color.ColorBlender) FloraFacet(org.terasology.core.world.generator.facets.FloraFacet) ColorModel(java.awt.image.ColorModel) Color(org.terasology.rendering.nui.Color) BaseVector3i(org.terasology.math.geom.BaseVector3i) DataBufferInt(java.awt.image.DataBufferInt) Graphics2D(java.awt.Graphics2D)

Aggregations

Color (org.terasology.rendering.nui.Color)30 Test (org.junit.Test)9 ColorModel (java.awt.image.ColorModel)3 DataBufferInt (java.awt.image.DataBufferInt)3 ResourceUrn (org.terasology.assets.ResourceUrn)3 Rect2i (org.terasology.math.geom.Rect2i)3 Vector2i (org.terasology.math.geom.Vector2i)3 Font (org.terasology.rendering.assets.font.Font)3 Map (java.util.Map)2 EntityRef (org.terasology.entitySystem.entity.EntityRef)2 PersistedData (org.terasology.persistence.typeHandling.PersistedData)2 ColorBlender (org.terasology.world.viewer.color.ColorBlender)2 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 Graphics2D (java.awt.Graphics2D)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 ByteBuffer (java.nio.ByteBuffer)1