/** * Create a wildcard size value that stores a computed value. * * @param computedValue the computed size * @return the size value instance representing the wildcard with computed size * @see de.lessvoid.nifty.tools.SizeValueType#Wildcard */ @Nonnull public static SizeValue wildcard(final int computedValue) { return new SizeValue(SizeValueType.Wildcard, computedValue); }
/** * Get a instance of the default size value with a attached calculated size value. * * @param pixelValue the calculated pixel size * @return the default size value instance with the attached calculated size * @see de.lessvoid.nifty.tools.SizeValueType#Default */ @Nonnull public static SizeValue def(final int pixelValue) { return new SizeValue(SizeValueType.Default, pixelValue); }
/** * Create a percentage based size value. * * @param percentage percentage value * @return the size value instance representing the percentage value * @see de.lessvoid.nifty.tools.SizeValueType#Percent */ @Nonnull public static SizeValue percent(final int percentage) { return new SizeValue(percentage, SizeValueType.Percent); }
/** * Create a sum size value that stores a computed value. * * @param computedValue the computed size * @return the size value instance representing the sum with computed size * @see de.lessvoid.nifty.tools.SizeValueType#Sum */ @Nonnull public static SizeValue sum(final int computedValue) { return new SizeValue(SizeValueType.Sum, computedValue); }
/** * Create a maximum size value that stores a computed value. * * @param computedValue the computed size * @return the size value instance representing the maximum with computed size * @see de.lessvoid.nifty.tools.SizeValueType#Maximum */ @Nonnull public static SizeValue max(final int computedValue) { return new SizeValue(SizeValueType.Maximum, computedValue); }
/** * Create a percentage based size value. This percentage will use the height of the parent element as reference. * This value is only allowed to be used as width value. * * @param percentage percentage value * @return the size value instance representing the percentage value * @see de.lessvoid.nifty.tools.SizeValueType#PercentHeight */ @Nonnull public static SizeValue percentHeight(final int percentage) { return new SizeValue(percentage, SizeValueType.PercentHeight); }
/** * Create a percentage based size value. This percentage will use the width of the parent element as reference. * This value is only allowed to be used as height value. * * @param percentage percentage value * @return the size value instance representing the percentage value * @see de.lessvoid.nifty.tools.SizeValueType#PercentWidth */ @Nonnull public static SizeValue percentWidth(final int percentage) { return new SizeValue(percentage, SizeValueType.PercentWidth); }
/** * Create a pixel based size value. * * @param pixelValue pixel value * @return the size value instance representing the pixel value * @see de.lessvoid.nifty.tools.SizeValueType#Pixel */ @Nonnull public static SizeValue px(final int pixelValue) { if (pixelValue == 0) { return NULL_PX; } return new SizeValue(pixelValue, SizeValueType.Pixel); }
@Nonnull public SizeValue sizeValue(@Nullable final String value) { return new SizeValue(value); }
public int insetSizeValue(@Nullable final String value, final int imageHeight) { if (value == null) { return 0; } SizeValue sizeValue = new SizeValue(value); return sizeValue.getValueAsInt(imageHeight); } }
@Override public void activate( @Nonnull final Nifty nifty, @Nonnull final Element element, @Nonnull final EffectProperties parameter) { startSize = Float.parseFloat(parameter.getProperty("startSize", "1.0")); endSize = Float.parseFloat(parameter.getProperty("endSize", "2.0")); // hover mode only String maxSizeString = parameter.getProperty("maxSize"); if (maxSizeString != null) { textSize = new SizeValue(maxSizeString); } }
@Override public void activate( @Nonnull final Nifty nifty, @Nonnull final Element element, @Nonnull final EffectProperties parameter) { String startSizeString = parameter.getProperty("startSize"); if (startSizeString != null) { startSize = new SizeValue(startSizeString); } String endSizeString = parameter.getProperty("endSize"); if (endSizeString != null) { endSize = new SizeValue(endSizeString); } pulsator = new Pulsator(parameter, nifty.getTimeProvider()); }
@Override public final void activate( @Nonnull final Nifty nifty, @Nonnull final Element element, @Nonnull final EffectProperties parameter) { // for normal mode startSize = Float.parseFloat(parameter.getProperty("startSize", "1.0")); endSize = Float.parseFloat(parameter.getProperty("endSize", "2.0")); // for hover mode only String maxSizeString = parameter.getProperty("maxSize"); if (maxSizeString != null) { imageSize = new SizeValue(maxSizeString); } interpolator = parameter.getInterpolator(); }
@Override public void activate( @Nonnull final Nifty niftyParam, @Nonnull final Element element, @Nonnull final EffectProperties parameter) { nifty = niftyParam; music = nifty.getSoundSystem().getMusic(parameter.getProperty("sound")); if (music == null) { log.warning("Failed to get music for effect."); } else { fromVolume = new SizeValue(parameter.getProperty("from", "0%")).getValue(1.0f); toVolume = new SizeValue(parameter.getProperty("to", "100%")).getValue(1.0f); } }
@Override public void activate( @Nonnull final Nifty nifty, @Nonnull final Element element, @Nonnull final EffectProperties parameter) { entries.clear(); for (Attributes entry : parameter.getEffectValues().getValues()) { SizeValue offset = new SizeValue(entry.get("offset")); Color color = entry.getAsColor("color"); if (color != null) { entries.add(new Entry(offset, color)); } } horizontal = "horizontal".equals(parameter.getProperty("direction", "vertical")); }
@Override public void activate( @Nonnull final Nifty nifty, @Nonnull final Element element, @Nonnull final EffectProperties parameter) { startColor = new Color(parameter.getProperty("startColor", "#0000")); endColor = new Color(parameter.getProperty("endColor", "#ffff")); width = new SizeValue(parameter.getProperty("width")); }
@Override public void activate( @Nonnull final Nifty nifty, @Nonnull final Element element, @Nonnull final EffectProperties parameter) { startColor = new Color(parameter.getProperty("startColor", "#00000000")); endColor = new Color(parameter.getProperty("endColor", "#ffffffff")); width = new SizeValue(parameter.getProperty("width")); changeColorOnly = Boolean.valueOf(parameter.getProperty("changeColorOnly", "false")); pulsator = new Pulsator(parameter, nifty.getTimeProvider()); }
/** * Set ups a sub objective text * * @param id the element ID * @param caption the text * @return returns the element */ private Label setupSubObjectiveLabel(String id, String caption) { // Get the actual label and set the text Label label = screen.findNiftyControl(id, Label.class); label.setText(caption.isEmpty() ? "" : "- ".concat(caption)); // Measure the text height so that the element can be arranged to the the screen without overlapping the othe sub objectives TextRenderer renderer = label.getElement().getRenderer(TextRenderer.class); label.setHeight(new SizeValue(renderer.getTextHeight() + "px")); return label; }
/** * After changing label text, you need to resize its contstraints * * @param label the label */ public static void resetContraints(Label label) { TextRenderer renderer = label.getElement().getRenderer(TextRenderer.class); label.setHeight(new SizeValue(renderer.getTextHeight() + "px")); label.setWidth(new SizeValue(renderer.getTextWidth() + "px")); label.getElement().getParent().layoutElements(); } }