X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fgraphics%2FColor.java;h=e3b30c5c50b9f521f93f08b8631f746c3144d5e2;hp=dce2a8d8828e70a6526772da0ed046e4968f86cf;hb=33002baf4ee9f34bd8675d4aa06bcac0eec5f817;hpb=5fbf100852abd0c03dd2d399766b7273933dbbc6 diff --git a/src/org/ibex/graphics/Color.java b/src/org/ibex/graphics/Color.java index dce2a8d..e3b30c5 100644 --- a/src/org/ibex/graphics/Color.java +++ b/src/org/ibex/graphics/Color.java @@ -9,15 +9,20 @@ import org.ibex.util.*; public class Color { public static int stringToColor(String s) { - // FIXME support three-char strings by doubling digits if (s == null) return 0x00000000; else if (standard.get(s) != null) return 0xFF000000 | ((Integer)standard.get(s)).intValue(); - else if (s.length() == 7 && s.charAt(0) == '#') try { - // FEATURE alpha - return 0xFF000000 | - (Integer.parseInt(s.substring(1, 3), 16) << 16) | - (Integer.parseInt(s.substring(3, 5), 16) << 8) | - Integer.parseInt(s.substring(5, 7), 16); + else if ((s.length() == 4 || s.length() == 7 || s.length() == 5 || s.length() == 9) && s.charAt(0) == '#') try { + s = s.substring(1); + switch(s.length()) { + case 3: s = "ff"+s.charAt(0)+s.charAt(0)+s.charAt(1)+s.charAt(1)+s.charAt(2)+s.charAt(2); break; + case 6: s = "ff"+s; break; + case 4: s = ""+s.charAt(0)+s.charAt(0)+s.charAt(1)+s.charAt(1)+s.charAt(2)+s.charAt(2)+s.charAt(3)+s.charAt(3); + } + return + (Integer.parseInt(s.substring(0, 2), 16) << 24) | + (Integer.parseInt(s.substring(2, 4), 16) << 16) | + (Integer.parseInt(s.substring(4, 6), 16) << 8) | + Integer.parseInt(s.substring(6, 8), 16); } catch (NumberFormatException e) { Log.info(Color.class, "invalid color " + s); return 0;