Add ColorUtil#fromObject to generate color from object
Add utility method that can generate color based on object hashCode. Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -27,6 +27,7 @@ package net.runelite.client.util;
|
|||||||
import com.google.common.primitives.Ints;
|
import com.google.common.primitives.Ints;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class ColorUtil
|
public class ColorUtil
|
||||||
{
|
{
|
||||||
@@ -226,4 +227,20 @@ public class ColorUtil
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates color from passed object hash code
|
||||||
|
* @param object object with hashCode
|
||||||
|
* @param skipAlpha skips alpha
|
||||||
|
* @return color
|
||||||
|
*/
|
||||||
|
public static Color fromObject(@Nonnull final Object object, boolean skipAlpha)
|
||||||
|
{
|
||||||
|
int i = object.hashCode();
|
||||||
|
int r = (i >> 24) & 0xFF;
|
||||||
|
int g = (i >> 16) & 0xFF;
|
||||||
|
int b = (i >> 8) & 0xFF;
|
||||||
|
int a = i & 0xFF;
|
||||||
|
return new Color(r, g, b, skipAlpha ? 255 : a);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user