/** * Create a color from another color, using the given alpha value. * * @param newColor color * @param newAlpha alpha component */ public Color(@Nonnull final Color newColor, final float newAlpha) { this.red = newColor.getRed(); this.green = newColor.getGreen(); this.blue = newColor.getBlue(); this.alpha = newAlpha; this.colorString = fromRGBA(red, green, blue, alpha); }
public void renderQuad(int x, int y, int width, int height, Color color) { //We test for alpha >0 as an optimization to prevent the render of completely transparent quads. //Nifty use layers that are often used for logical positionning and not rendering. //each layer is rendered as a quad, but that can bump up the number of geometry rendered by a lot. //Since we disable depth write, there is absolutely no point in rendering those quads //This optimization can result in a huge increase of perfs on complex Nifty UIs. if(color.getAlpha() >0){ colorMaterial.setColor("Color", convertColor(color, tempColor)); tempMat.loadIdentity(); tempMat.setTranslation(x, getHeight() - y, 0); tempMat.setScale(width, height, 0); rm.setWorldMatrix(tempMat); rm.setForcedRenderState(renderState); colorMaterial.render(quadGeom, rm); } //System.out.format("renderQuad1(%d, %d, %d, %d, %s)\n", x, y, width, height, color.toString()); }
@Override public void renderQuad( final int x, final int y, final int width, final int height, @Nonnull final Color topLeft, @Nonnull final Color topRight, @Nonnull final Color bottomRight, @Nonnull final Color bottomLeft) { if (isColorAlphaChanged()) { Color a = new Color(topLeft, color.getAlpha()); Color b = new Color(topRight, color.getAlpha()); Color c = new Color(bottomRight, color.getAlpha()); Color d = new Color(bottomLeft, color.getAlpha()); renderDevice.renderQuad(x + getX(), y + getY(), width, height, a, b, c, d); } else { renderDevice.renderQuad(x + getX(), y + getY(), width, height, topLeft, topRight, bottomRight, bottomLeft); } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(header); sb.append(";"); sb.append(width); sb.append(";"); sb.append(type.getName()); sb.append(";"); sb.append(color.getColorString()); return sb.toString(); } }
private Color getGammaEffectColor(Creature.GammaEffect type) { Color c = new Color(0, 0, 0, 0); switch (type) { case NORMAL: c = new Color(1f, 1f, 1f, 0); break; case VAMPIRE_RED: c = new Color(0.8f, 0, 0, 0.2f); break; case DARK_ELF_PURPLE: c = new Color(0.9f, 0, 0.9f, 0.2f); break; case SKELETON_BLACK_N_WHITE: c = new Color(0, 0, 1f, 0.1f); break; case SALAMANDER_INFRARED: c = new Color(1f, 0, 0, 0.1f); break; case DARK_ANGER_BRIGHT_BLUE: case DEATH_VIEW_HALF_RED: case FREEZE_VIEW_ONLY_BLUE: case BLACKOUT: case GHOST: case MAIDEN: case REDOUT: case WHITEOUT: break; } return c; }
/** * Set only the color component of the given color. This assumes that alpha has already been changed. * * @param newColor color */ @Override public void setColorIgnoreAlpha(@Nonnull final Color newColor) { color.setRed(newColor.getRed()); color.setGreen(newColor.getGreen()); color.setBlue(newColor.getBlue()); colorChanged = true; if (colorAlphaChanged && color.getAlpha() > newColor.getAlpha()) { color.setAlpha(newColor.getAlpha()); colorAlphaChanged = true; } }
private void saveColorAlpha() { colorAlpha = NiftyRenderEngineImpl.this.color.getAlpha(); colorAlphaChanged = NiftyRenderEngineImpl.this.colorAlphaChanged; }
@Override public void activate( @Nonnull final Nifty nifty, @Nonnull final Element element, @Nonnull final EffectProperties parameter) { // startColor and endColor (only alpha component used) are the old version of this // and are kept here only for backward compatibility. The current attributes are "start" and "end" alpha values. if (parameter.getProperty("startColor") != null) { start = new Alpha(new Color(parameter.getProperty("startColor", "#000000ff")).getAlpha()); } if (parameter.getProperty("endColor") != null) { end = new Alpha(new Color(parameter.getProperty("endColor", "#ffffffff")).getAlpha()); } if (parameter.getProperty("start") != null) { start = new Alpha(parameter.getProperty("start")); } if (parameter.getProperty("end") != null) { end = new Alpha(parameter.getProperty("end")); } interpolator = parameter.getInterpolator(); }
public ElementBuilder backgroundColor(@Nonnull final Color backgroundColor) { attributes.setBackgroundColor(backgroundColor.getColorString()); return this; }
@Nullable public Color color(@Nullable final String value) { if (value == null) { return null; } return new Color(value); }
/** * Get parameter as Color instance. * * @param name the name of the attribute * @return the Color value of the attributes value */ @Nullable public Color getAsColor(@Nonnull final String name) { String value = get(name); if (value == null) { return null; } if (Color.check(value)) { return new Color(value); } return null; }
@Override public int preProcess(@Nonnull final String text, final int offset) { int index = offset; colorValueParser.isColor(text, index); while (colorValueParser.isColor()) { final Color color = colorValueParser.getColor(); assert color != null; textColor.setRed(color.getRed()); textColor.setGreen(color.getGreen()); textColor.setBlue(color.getBlue()); textColor.setAlpha(color.getAlpha()); hasColor = true; index = colorValueParser.getNextIndex(); if (index >= text.length()) { return index; } colorValueParser.isColor(text, index); } return index; }