public float af() { return a() / 255.f; }
@Test public void testAlterAlpha() { color = color.alterAlpha(72); assertEquals(72, color.a()); }
public Color inverse() { return new Color((~representation & ALPHA_FILTER) | a()); }
/** * 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)); }
/** * 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); }
@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 testGetAlpha() { assertEquals(255, color.a()); }
private void applyUnderline() { if (currentUnderline && underlineStart != UNKNOWN) { MeshBuilder builder = getBuilderFor(underlineMaterial); if (shadowColor.a() != 0) { addUnderline(builder, underlineStart + SHADOW_HORIZONTAL_OFFSET, underlineEnd + SHADOW_HORIZONTAL_OFFSET, y + font.getBaseHeight() + SHADOW_VERTICAL_OFFSET + font.getUnderlineOffset(), font.getUnderlineThickness(), shadowColor, SHADOW_DEPTH); } addUnderline(builder, underlineStart, underlineEnd, y + font.getBaseHeight() + font.getUnderlineOffset(), font.getUnderlineThickness(), currentColor, 0); } underlineStart = UNKNOWN; underlineEnd = UNKNOWN; }
@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()); } }
private void processLines() { for (String line : lines) { int w = font.getWidth(line); x = alignment.getOffset(w, width); for (char c : line.toCharArray()) { FontCharacter character = font.getCharacterData(c); if (character != null && character.getPage() != null) { MeshBuilder builder = getBuilderFor(character.getPageMat()); if (shadowColor.a() != 0) { addCharacter(builder, character, shadowColor, SHADOW_HORIZONTAL_OFFSET, SHADOW_VERTICAL_OFFSET, SHADOW_DEPTH); } addCharacter(builder, character, currentColor, 0, 0, 0); updateUnderline(c, character); x += character.getxAdvance(); } else if (FontColor.isValid(c)) { applyUnderline(); processColorCode(c); } else if (FontUnderline.isValid(c)) { processUnderlineCode(c); } } applyUnderline(); y += font.getLineHeight(); } }