public float gf() { return g() / 255.f; }
/** * Method to append the color string hex representation back to a string buffer. * Package-only access as it is for internal use in ColorTextureAssetResolver, * but should be here for maintenance with the color-to-color-string code. * * @param sb StringBuilder into which to append name * @param color represented by hexColorName */ private static void appendColorName(StringBuilder sb, Color color) { int red = color.r(); if (red < 16) { sb.append('0'); } sb.append(Integer.toHexString(red)); int green = color.g(); if (green < 16) { sb.append('0'); } sb.append(Integer.toHexString(green)); int blue = color.b(); if (blue < 16) { sb.append('0'); } sb.append(Integer.toHexString(blue)); int alpha = color.a(); if (alpha < 16) { sb.append('0'); } sb.append(Integer.toHexString(alpha)); }
/** * Stores the color with (4 + 4 + 4) = 12 bit accuracy as Unicode char * @param color the color * @return the unicode char * @deprecated use {@link FontColor#getColored(String, Color)} instead */ @Deprecated public static char toChar(org.terasology.rendering.nui.Color color) { return toChar(color.r(), color.g(), color.b()); }
/** * Create TextureData for a Texture all of a single color. * @param color to use for creating TextureData * @return TextureData created using specified color */ public static TextureData newInstance(Color color) { byte red = (byte) color.r(); byte green = (byte) color.g(); byte blue = (byte) color.b(); byte alpha = (byte) color.a(); ByteBuffer data = ByteBuffer.allocateDirect(4 * TEXTURE_WIDTH * TEXTURE_HEIGHT); for (int height = 0; height < TEXTURE_HEIGHT; height++) { for (int width = 0; width < TEXTURE_WIDTH; width++) { data.put(red).put(green).put(blue).put(alpha); } } // The buffer must be reset back to the initial position before passing it onward. data.rewind(); return new TextureData(TEXTURE_WIDTH, TEXTURE_HEIGHT, new ByteBuffer[]{data}, WrapMode.REPEAT, FilterMode.NEAREST); }
public Vector3i toVector3i() { return new Vector3i(r(), g(), b()); }
@Override public PersistedData serialize(Color value, SerializationContext context) { if (value == null) { return context.createNull(); } else { return context.create(value.r(), value.g(), value.b(), value.a()); } }
@Test public void testGetGreen() { assertEquals(10, color.g()); }
@Test public void testAlterGreen() { color = color.alterGreen(72); assertEquals(72, color.g()); }
@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()); } }