Commit 4845c2eb authored by Nico Mack's avatar Nico Mack

Added features to ColorFactory allowing to modify Hue, Saturation and

Brightness of colours.
Added saturation property to rgb colours in BootstrappingUtils
parent 0e3818be
......@@ -136,6 +136,7 @@ ROTATE_WITH_HANDLE_NODE=rotateWithHandle
ROTATE_WITH_TETHER_NODE=rotateWithTether
ROTATION_DIRECTION_NODE=rotationDirection
SCALE_NODE=scale
SATURATION_NODE=saturation
SCREEN_ID_NODE=screenId
SECTION_NODE=section
SECTIONS_NODE=sections
......
......@@ -597,6 +597,7 @@ public class BootstrappingUtils {
int rgb = getContentAsInteger(colourNode, Externalization.RGB_COLOUR_NODE, BootstrappingUtils.MANDATORY, null, context);
String shade = getAttributeAsString(rgbNode, Externalization.SHADE_ATTRIBUTE, BootstrappingUtils.OPTIONAL, Externalization.EMPTY_STRING);
int alpha = getContentAsInteger(colourNode, Externalization.ALPHA_NODE, BootstrappingUtils.OPTIONAL, 255, context);
double saturation = getContentAsDouble(colourNode, Externalization.SATURATION_NODE, BootstrappingUtils.OPTIONAL, 1.0d, context);
rgb += alpha << 24;
colour = new Color(rgb, true); // With Alpha Channel
......@@ -608,8 +609,10 @@ public class BootstrappingUtils {
colour = colour.brighter();
} else if (Externalization.SHADE_EXTRA_BRIGHT_VALUE.equals(shade)) {
colour = colour.brighter().brighter();
} else if (Externalization.SHADE_DESATURATED_VALUE.equals(shade)) {
colour = ColorFactory.desaturateColour(colour);
}
if (saturation != 1.0d) {
colour = ColorFactory.changeColourSaturation(colour, saturation);
}
} else {
String colourString = getContent(colourNode, Externalization.EMPTY_STRING, null);
......@@ -624,7 +627,9 @@ public class BootstrappingUtils {
}
}
if (colour == null) {
if (colour == null)
{
if (optional) {
colour = defaultColour;
} else {
......
......@@ -121,23 +121,68 @@ public class ColorFactory {
// ---------------------------------------------------------------------------
/**
* @param colour
* @param factor
* @return
*/
// ---------------------------------------------------------------------------
public static Color desaturateColour(Color colour) {
public static Color changeColourHue(Color colour, double factor) {
float[] hsb = new float[3];
hsb = Color.RGBtoHSB(colour.getRed(), colour.getGreen(), colour.getBlue(), hsb);
int alpha = colour.getAlpha();
hsb[SATURATION] *= 0.3;
Preconditions.checkArgument(factor >= 0, "Factor MUST be positive!"); //$NON-NLS-1$
hsb[HUE] *= factor;
int rgb = Color.HSBtoRGB(hsb[HUE], hsb[SATURATION], hsb[BRIGHTNESS]);
rgb |= ((alpha << 24) & 0xFF000000);
return new Color(rgb);
}
// ---------------------------------------------------------------------------
/**
* @param colour
* @param factor
* @return
*/
// ---------------------------------------------------------------------------
public static Color changeColourSaturation(Color colour, double factor) {
float[] hsb = new float[3];
hsb = Color.RGBtoHSB(colour.getRed(), colour.getGreen(), colour.getBlue(), hsb);
int alpha = colour.getAlpha();
Preconditions.checkArgument(factor >= 0, "Factor MUST be positive!"); //$NON-NLS-1$
hsb[SATURATION] *= factor;
int rgb = Color.HSBtoRGB(hsb[HUE], hsb[SATURATION], hsb[BRIGHTNESS]);
rgb |= ((alpha << 24) & 0xFF000000);
return new Color(rgb);
}
// ---------------------------------------------------------------------------
/**
* @param colour
* @param factor
* @return
*/
// ---------------------------------------------------------------------------
public static Color changeColourBrightness(Color colour, double factor) {
float[] hsb = new float[3];
hsb = Color.RGBtoHSB(colour.getRed(), colour.getGreen(), colour.getBlue(), hsb);
int alpha = colour.getAlpha();
Preconditions.checkArgument(factor >= 0, "Factor MUST be positive!"); //$NON-NLS-1$
hsb[BRIGHTNESS] *= factor;
int rgb = Color.HSBtoRGB(hsb[HUE], hsb[SATURATION], hsb[BRIGHTNESS]);
rgb |= ((alpha << 24) & 0xFF000000);
return new Color(rgb);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
......
......@@ -171,6 +171,7 @@ public class Externalization extends NLS {
public static String ROTATE_WITH_TETHER_NODE;
public static String ROTATION_DIRECTION_NODE;
public static String SCALE_NODE;
public static String SATURATION_NODE;
public static String SCREEN_ID_NODE;
public static String SECTION_NODE;
public static String SECTIONS_NODE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment