/// <summary> /// Converts the color string in Hexadecimal or HDR color format to the /// corresponding Color object. /// The hexadecimal color string should be in #RRGGBB or #AARRGGBB format. /// The '#' character is optional. /// The HDR color string should be in R G B A format. /// (R, G, B & A should have value in the range between 0 and 1, inclusive) /// </summary> /// <param name="colorString">Color string in Hexadecimal or HDR format</param> /// <returns>Color</returns> public static Color CreateColor(string colorString) { using (new CultureShield("en-US")) { return(ColorParser.Parse(colorString)); } }
private void InitInteractiveSimpleLine(IGraphPane pane) { var id = Value.Data.GetId(); m_interactiveSimpleLine = (IInteractiveSimpleLine)pane.GetInteractiveObject(id); var intColor = ColorParser.Parse(Color); MarketPoint marketPosition; if (m_interactiveSimpleLine != null) { marketPosition = new MarketPoint(m_interactiveSimpleLine.MarketPosition.X, Value.Value); if (m_interactiveSimpleLine.PaneSides == PaneSide && m_interactiveSimpleLine.Color == intColor) { m_interactiveSimpleLine.Thickness = Thickness; m_interactiveSimpleLine.MarketPosition = marketPosition; pane.AddUnremovableInteractiveObjectId(id); return; } pane.RemoveInteractiveObject(id); } else { marketPosition = new MarketPoint(DateTime.UtcNow, Value.Value); } m_interactiveSimpleLine = pane.AddInteractiveSimpleLine(id, PaneSide, false, intColor, InteractiveSimpleLineMode.Horizontal, marketPosition); m_interactiveSimpleLine.Thickness = Thickness; }
/// <summary> /// Converts a Vector4 High Dynamic Range Color to Color object. /// Negative components of the Vector4 will be sanitized by taking the absolute /// value of the component. The HDR Color components should have value in /// the range between 0 and 1, inclusive. If they are more than 1, they /// will be clamped at 1. /// Vector4's X, Y, Z, W components match to Color's R, G, B, A components respectively. /// </summary> /// <param name="hdrColor">High Dynamic Range Color</param> /// <returns>Color</returns> public static Color CreateColor(Vector4 hdrColor) { using (new CultureShield("en-US")) { return(ColorParser.Parse(hdrColor)); } }
private static void ColorSample(HtmlRenderer html, string s) { int c = ColorParser.Parse(s); Parameters style = new Parameters(); if (c == ColorParser.InvalidColor) { style["color"] = "#000000"; style["background-color"] = "#ffffff"; } else { s = "#" + c.ToString("x6"); style["color"] = s; style["background-color"] = s; HlsColor hls = ColorTransform.RgbToHls(ColorTransform.IntToRgb(c)); if (hls.L > 800) { style["border"] = "1px solid #808080"; } } html.Add("<div"); html.Style(style); html.Add(">"); html.Add(String.IsNullOrEmpty(s) ? "X" : "?"); html.Add("</div>"); }
public void TestParseColor__Empty() { Assert.Throws <FormatException>(delegate { ColorParser.Parse(""); }); }
private IInteractiveLine GetInteractiveLine(IGraphPane pane, IReadOnlyList <IDataBar> bars) { var minDate = bars.First().Date; var maxDate = bars.Last().Date; var interactiveLine = (IInteractiveLine)pane.GetInteractiveObject(VariableId); var intColor = ColorParser.Parse(Color); var firstMarketPosition = new MarketPoint(FirstDateTime.Value, FirstValue.Value); var secondMarketPosition = new MarketPoint(SecondDateTime.Value, SecondValue.Value); if (interactiveLine != null) { interactiveLine.ExecutionDataBars = bars; CorrectMarketPointsEx(ref firstMarketPosition, ref secondMarketPosition, minDate, maxDate); if (interactiveLine.PaneSides == PaneSide && interactiveLine.Color == intColor && interactiveLine.Mode == Mode) { pane.AddUnremovableInteractiveObjectId(VariableId); interactiveLine.Thickness = Thickness; interactiveLine.FirstPoint.MarketPosition = firstMarketPosition; interactiveLine.SecondPoint.MarketPosition = secondMarketPosition; return(m_interactiveLine = interactiveLine); } pane.RemoveInteractiveObject(VariableId); } else { CorrectMarketPointsEx(ref firstMarketPosition, ref secondMarketPosition, minDate, maxDate); } m_interactiveLine = pane.AddInteractiveLine(VariableId, PaneSide, false, intColor, Mode, firstMarketPosition, secondMarketPosition); m_interactiveLine.Thickness = Thickness; m_interactiveLine.ExecutionDataBars = bars; return(m_interactiveLine); }
public void TestParseColor__Null() { Assert.Throws <ArgumentNullException>(delegate { ColorParser.Parse(null); }); }
public void ParseTest(string[] channels, int[] expectedColorChannels) { var expectedColor = ToColor(expectedColorChannels); var parsed = ColorParser.Parse(channels); AssertColorsAreEqual(parsed, expectedColor); }
public void TestParseColor__FloatList__RGBA() { Color color = ColorParser.Parse("1, 0.7, 0.3, 0"); Assert.Equal(1, color.r); Assert.Equal(0.7f, color.g); Assert.Equal(0.3f, color.b); Assert.Equal(0, color.a); }
public void TestParseColor__HexStr__Upper() { Color color = ColorParser.Parse("#0AF"); Assert.Equal(0, color.r); Assert.Equal(0xa / 15f, color.g); Assert.Equal(1, color.b); Assert.Equal(1, color.a); }
public void TestParseColor__FloatList__TooLarge() { FormatException ex = Assert.Throws <FormatException>(delegate { ColorParser.Parse("0, 1.1, 1"); }); Assert.Equal("Invalid float value when parsing color (should be 0-1): 1.1", ex.Message); }
public void TestParseColor__UnknownFormat() { FormatException ex = Assert.Throws <FormatException>(delegate { ColorParser.Parse("stuff"); }); Assert.Equal("Could not value parse as color: stuff", ex.Message); }
public void TestParseColor__FloatList__TooLong() { FormatException ex = Assert.Throws <FormatException>(delegate { ColorParser.Parse("0, 1, 2, 3, 4"); }); Assert.Equal("Could not value parse as color: 0, 1, 2, 3, 4", ex.Message); }
public void TestParseColor__HexStr__RGB() { Color color = ColorParser.Parse("#07f"); Assert.Equal(0, color.r); Assert.Equal(0x7 / 15f, color.g); Assert.Equal(1, color.b); Assert.Equal(1, color.a); }
public void TestParseColor__FloatList__CommaSeparatedWithNoSpaces() { Color color = ColorParser.Parse("0,0.5,1"); Assert.Equal(0, color.r); Assert.Equal(0.5f, color.g); Assert.Equal(1, color.b); Assert.Equal(1, color.a); }
public void TestParseColor__HexStr__TooShort() { FormatException ex = Assert.Throws <FormatException>(delegate { ColorParser.Parse("#ab"); }); Assert.Equal("Value looks like HTML color (begins with #) but has wrong number of digits (must be 3, 4, 6, or 8): #ab", ex.Message); }
public void TestParseColor__HexStr__RRGGBB() { Color color = ColorParser.Parse("#002fff"); Assert.Equal(0, color.r); Assert.Equal(0x2f / 255f, color.g); Assert.Equal(1, color.b); Assert.Equal(1, color.a); }
public void TestParseColor__HexStr__InvalidHex() { FormatException ex = Assert.Throws <FormatException>(delegate { ColorParser.Parse("#00g"); }); Assert.Equal("Invalid hexadecimal character: g", ex.Message); }
public void TestParseColor__FloatList__RGB() { Color color = ColorParser.Parse("0, 0.5, 1"); Assert.Equal(0, color.r); Assert.Equal(0.5f, color.g); Assert.Equal(1, color.b); Assert.Equal(1, color.a); }
public void TestParseColor__HexStr__RRGGBBAA() { Color color = ColorParser.Parse("#ffab5600"); Assert.Equal(1, color.r); Assert.Equal(0xab / 255f, color.g); Assert.Equal(0x56 / 255f, color.b); Assert.Equal(0, color.a); }
public void TestParseColor__HexStr__RGBA() { Color color = ColorParser.Parse("#fa50"); Assert.Equal(1, color.r); Assert.Equal(0xa / 15f, color.g); Assert.Equal(0x5 / 15f, color.b); Assert.Equal(0, color.a); }
public void TestParseColor__FloatList__TabSeparated() { Color color = ColorParser.Parse("0\t0.5\t1"); Assert.Equal(0, color.r); Assert.Equal(0.5f, color.g); Assert.Equal(1, color.b); Assert.Equal(1, color.a); }
public void Parse_MultipleConsequentCarets_Returns_EscapedCaret() { const string input = "^^2Hello, ^^3World!"; var result = ColorParser.Parse(input); Assert.AreEqual(result.Parts[0].Text, "^"); Assert.AreEqual(result.Parts[1].Text, "Hello, ^"); Assert.AreEqual(result.Parts[2].Text, "World!"); }
public void Parse_MultipleConsequentCarets_Returns_CorrectColors() { const string input = "^^2Hello, ^^3World!"; var result = ColorParser.Parse(input); Assert.AreEqual(result.Parts[0].ColorCode, '7'); Assert.AreEqual(result.Parts[1].ColorCode, '2'); Assert.AreEqual(result.Parts[2].ColorCode, '3'); }
public void Parse_ColorfulString_Returns_CorrectColors() { const string input = "^3Hello^7, ^9World^2!"; var result = ColorParser.Parse(input); Assert.AreEqual(result.Parts[0].ColorCode, '3'); Assert.AreEqual(result.Parts[1].ColorCode, '7'); Assert.AreEqual(result.Parts[2].ColorCode, '9'); Assert.AreEqual(result.Parts[3].ColorCode, '2'); }
public void Parse_ColorfulString_Returns_CorrectAmountOfParts() { const string input = "^3Hello^7, ^9World^2!"; var result = ColorParser.Parse(input); Assert.AreEqual(result.Parts.Count, 4); Assert.AreEqual(result.Parts[0].Text, "Hello"); Assert.AreEqual(result.Parts[1].Text, ", "); Assert.AreEqual(result.Parts[2].Text, "World"); Assert.AreEqual(result.Parts[3].Text, "!"); }
public void TestParseColor__ResourceColors() { Assert.Equal(ResourceColors.LiquidFuel, ColorParser.Parse("ResourceColorLiquidFuel")); Assert.Equal(ResourceColors.LqdHydrogen, ColorParser.Parse("ResourceColorLqdHydrogen")); Assert.Equal(ResourceColors.LqdMethane, ColorParser.Parse("ResourceColorLqdMethane")); Assert.Equal(ResourceColors.Oxidizer, ColorParser.Parse("ResourceColorOxidizer")); Assert.Equal(ResourceColors.MonoPropellant, ColorParser.Parse("ResourceColorMonoPropellant")); Assert.Equal(ResourceColors.XenonGas, ColorParser.Parse("ResourceColorXenonGas")); Assert.Equal(ResourceColors.ElectricChargePrimary, ColorParser.Parse("ResourceColorElectricChargePrimary")); Assert.Equal(ResourceColors.ElectricChargeSecondary, ColorParser.Parse("ResourceColorElectricChargeSecondary")); Assert.Equal(ResourceColors.Ore, ColorParser.Parse("ResourceColorOre")); }
/// <summary> /// Gets the Brush Element Attributes from the Match /// </summary> /// <param name="match">Match object</param> protected override void GetAttributes(Match match) { // Parse the Color _color = ColorParser.Parse(match); // Opacity (optional) var group = match.Groups["Opacity"]; if (group.Success) { Single.TryParse(group.Value, out _opacity); } }
private static void SetColor(object sender, EventArgsCommand e) { var args = e.Command.CalledArgs; if (args.Length < 3) { Log.Error("Wrong arguments count."); return; } if (!args[0].IsInt32()) { Log.Error("First argument must be int."); return; } var x = args[0].AsInt32(); if (!args[1].IsInt32()) { Log.Error("Second argument must be int."); return; } var y = args[1].AsInt32(); var color = ColorParser.Parse(args[2]); if (color == null) { Log.Error("Third argument must be color name."); return; } var chest = Game1.currentLocation.Objects .FirstOrDefault(p => p.Key == new Vector2(x, y) && p.Value is Chest) .Value as Chest; if (chest == null) { Log.Error("Chest is not found."); return; } chest.tint = color.Value; }
public object ParseColor(string id) { string name = Value(id); object method = ParseMethodOrField(name); if (method != null) { return(method); } if (name.IsNullOrEmpty()) { return(null); } if (name[0] == ':') { ColorWrapper colorWrapper = ColorsManager.Instance[name]; if (colorWrapper != null) { return(colorWrapper); } } Color?color = ColorParser.Parse(name); if (color.HasValue) { return(color.Value); } { Exception ex = Error(id, "Invalid format. Color formats are: '#aarrggbb' '#rrggbb' 'r,g,b' 'r,g,b,a' 'Name' 'Name*Alpha'."); if (ex != null) { throw ex; } } return(null); }