/// <summary> /// Sets up the properties of an instantiated generator, using the given parameters. /// </summary> /// <param name="generator">Generator to set up.</param> /// <param name="handX">String value for the horizontal hand offset in pixels, presumably from a text field. /// Value should be convertable to an integer.</param> /// <param name="handY">String value for the vertical hand offset in pixels, presumably from a text field. /// Value should be convertable to an integer.</param> /// <param name="ignoreColor">String value of the color to ignore, presumably from a text field. /// If given, value should be formatted RRGGBB or RRGGBBAA (hexadecimal string).</param> /// <returns>Reference to the given object.</returns> public static DrawablesGenerator SetUpGenerator(DrawablesGenerator generator, string handX, string handY, string ignoreColor = null) { generator.OffsetX = Convert.ToInt32(handX) + 1; generator.OffsetY = Convert.ToInt32(handY); generator.RotateFlipStyle = System.Drawing.RotateFlipType.RotateNoneFlipY; generator.ReplaceBlank = true; generator.ReplaceWhite = true; string colorString = ignoreColor.Replace("#", ""); if (colorString.Length == 6 || colorString.Length == 8) { int r = ColorConversions.HexToInt(colorString.Substring(0, 2)); r = Clamp(r, 0, 255); int g = ColorConversions.HexToInt(colorString.Substring(2, 2)); g = Clamp(g, 0, 255); int b = ColorConversions.HexToInt(colorString.Substring(4, 2)); b = Clamp(b, 0, 255); int a = colorString.Length == 8 ? ColorConversions.HexToInt(colorString.Substring(6, 2)) : 255; a = Clamp(a, 0, 255); generator.IgnoreColor = System.Drawing.Color.FromArgb(a, r, g, b); } return(generator); }
public void TestGenerate() { int w = 4, h = 4; string path = CreateTempBitmap(w * 32, h * 8); try { DrawablesGenerator dg = new DrawablesGenerator(path); DrawablesOutput dOutput = dg.Generate(); for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { Drawable drawable = dOutput.Drawables[i, j]; StringBuilder debuilder = new StringBuilder(drawable.Directives); debuilder.Remove(0, 8); while (debuilder.Length >= 18) { string from = debuilder.ToString(1, 6), to = debuilder.ToString(10, 6); int rFrom = Convert.ToInt32(from.Substring(0, 2)), bFrom = Convert.ToInt32(from.Substring(4, 2)); int rTo = ColorConversions.HexToInt(to.Substring(0, 2)), bTo = ColorConversions.HexToInt(to.Substring(4, 2)); if (rTo > 32) { rTo = --rTo % 32; rTo++; } if (bTo > 8) { bTo = --bTo % 8; bTo++; } Assert.AreEqual(rFrom, rTo); Assert.AreEqual(bFrom, bTo); debuilder.Remove(0, 18); } } } } } dg.IgnoreColor = Color.Blue; dg.OffsetX = 5; dg.OffsetY = 3; dg.Generate(); dg.ReplaceBlank = true; dg.ReplaceWhite = true; dg.Generate(); dg.RotateFlipStyle = RotateFlipType.Rotate180FlipY; dg.Generate(); } catch (DrawableException exc) { Assert.Fail(exc.Message); } finally { if (File.Exists(path)) { File.Delete(path); } } }