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; }
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 ICssValue Convert(StringSource source) { var color = default(ICssValue); var width = default(ICssValue); var style = default(ICssValue); var pos = 0; do { pos = source.Index; if (color == null) { color = ColorParser.ParseColor(source); source.SkipSpacesAndComments(); } if (width == null) { width = source.ParseLineWidth(); source.SkipSpacesAndComments(); } if (style == null) { style = source.ParseConstant(Map.LineStyles); source.SkipSpacesAndComments(); } }while (pos != source.Index); return(new CssTupleValue(new[] { color, width, style })); }
/// <summary> /// Create the brush for the given attribute name /// </summary> private GraphicBrush CreateBrush(XElement element, string name, bool setDefault, GraphicPath graphicPath, Matrix currentTransformationMatrix, double parentOpacity) { var strVal = cssStyleCascade.GetProperty(name); // 1: there is no value in the cascade if (string.IsNullOrEmpty(strVal)) { if (setDefault) { var alphad = GetAlpha(name, parentOpacity); return(new GraphicSolidColorBrush { Color = Color.FromArgb((byte)(alphad * 255), 0x00, 0x00, 0x00) }); } return(null); } strVal = strVal.Trim(); // 2: "none" is specified if (strVal == "none") { return(null); } var alpha = GetAlpha(name, parentOpacity); // 3: an url is specified if (strVal.StartsWith("url(", StringComparison.OrdinalIgnoreCase)) { int endUri = strVal.IndexOf(")", StringComparison.OrdinalIgnoreCase); var uri = strVal.Substring(4, endUri - 4); uri = uri.Trim(); var id = uri.Substring(1); var bounds = graphicPath.Geometry.Bounds; return(CreateGradientBrush(id, alpha, currentTransformationMatrix, bounds)); } // 4: use the current color if (strVal == "currentColor") { return(CreateBrush(element, "color", setDefault, graphicPath, currentTransformationMatrix, parentOpacity)); } // 5: try color formats of different flavours (hex, rgb, name) var success = ColorParser.TryParseColor(strVal, alpha, out Color color); if (success) { return(new GraphicSolidColorBrush { Color = color }); } return(null); }
/// <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)); } }
public static Color?ParseColor(string color) { if (string.IsNullOrEmpty(color)) { return(null); } lock (cache) { if (cache.TryGetValue(color, out var cached)) { return(cached); } } Color?value; try { value = new ColorParser().Parse(color.Trim()); } catch (FormatException) { value = null; } lock (cache) { return(cache[color] = value); } }
/// <summary> /// Attempts to convert 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> /// <param name="color">Output Color object</param> /// <returns>True if successful, otherwise False</returns> public static bool TryCreateColor(string colorString, out Color color) { using (new CultureShield("en-US")) { return(ColorParser.TryParse(colorString, out color)); } }
public void TestParseColor__Null() { Assert.Throws <ArgumentNullException>(delegate { ColorParser.Parse(null); }); }
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); }
private static bool IsValidColor(string color) { color = color.Trim(); return(color.StartsWith("#", StringComparison.Ordinal) || Regex.IsMatch(color, @"[\/\\*|\-|\+].*#") || // Test case when there is color math involved: like @light-blue: @nice-blue + #111; ColorParser.TryParseColor(color, ColorParser.Options.AllowNames | ColorParser.Options.LooseParsing) != null); }
/// <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)); } }
public IEnumerable <ITagSpan <ColorTag> > GetTags(NormalizedSnapshotSpanCollection spans) { if (WebEditor.Host == null || spans.Count == 0 || spans[0].Length == 0 || spans[0].Length >= _buffer.CurrentSnapshot.Length) { yield break; } var tree = CssEditorDocument.FromTextBuffer(_buffer).Tree; IEnumerable <ParseItem> items = GetColors(tree, spans[0]); foreach (var item in items.Where(i => (i.Start + i.Length) <= _buffer.CurrentSnapshot.Length)) { SnapshotSpan span = new SnapshotSpan(_buffer.CurrentSnapshot, item.Start, item.Length); ColorModel colorModel = ColorParser.TryParseColor(item, ColorParser.Options.AllowAlpha | ColorParser.Options.AllowNames); // Fix up for rebeccapurple adornment as it isn't parsed by ColorParser currently if (colorModel == null && item.Text == "rebeccapurple") { // as per http://lists.w3.org/Archives/Public/www-style/2014Jun/0312.html colorModel = ColorParser.TryParseColor("#663399", ColorParser.Options.AllowAlpha | ColorParser.Options.AllowNames); } if (colorModel != null) { yield return(new TagSpan <ColorTag>(span, new ColorTag(colorModel.Color))); } } }
private async void buttonCreateGroup_Click(object sender, RoutedEventArgs e) { string name = textName.Text; string description = textDescription.Text; string password = textPassword.Password; float color = ColorParser.parseColorToFloat(comboBoxColors.SelectedItem.ToString()); string user = ApplicationData.Current.LocalSettings.Values["Email"].ToString(); if (String.IsNullOrWhiteSpace(name) || String.IsNullOrWhiteSpace(description)) { var dialog = new MessageDialog("Brak nazwy lub opisu."); dialog.Title = "Błąd"; dialog.Commands.Add(new UICommand { Label = "OK", Id = 0 }); var res = await dialog.ShowAsync(); return; } HttpClient httpClient = new HttpClient(); string url = string.Format("http://www.friendszone.cba.pl/api/add_group.php?name={0}&description={1}&password={2}&user={3}&color={4}", name, description, password, user, color ); string ResponseString = await httpClient.GetStringAsync(new Uri(url)); processResponse(ResponseString); }
public IEnumerable <ISmartTagAction> GetSmartTagActions(ParseItem item, int position, ITrackingSpan itemTrackingSpan, ITextView view) { FunctionColor function = (FunctionColor)item; if (!function.IsValid) { yield break; } ColorModel model = ColorParser.TryParseColor(function.Text, ColorParser.Options.AllowAlpha); if (model != null) { // Don't convert RGBA and HSLA to HEX or named color if (model.Alpha == 1) { if (ColorConverterSmartTagAction.GetNamedColor(model.Color) != null) { yield return(new ColorConverterSmartTagAction(itemTrackingSpan, model, ColorFormat.Name)); } yield return(new ColorConverterSmartTagAction(itemTrackingSpan, model, ColorFormat.RgbHex3)); } if (model.Format == ColorFormat.Rgb) { yield return(new ColorConverterSmartTagAction(itemTrackingSpan, model, ColorFormat.Hsl)); } else if (model.Format == ColorFormat.Hsl) { yield return(new ColorConverterSmartTagAction(itemTrackingSpan, model, ColorFormat.Rgb)); } } }
public IEnumerable <ISmartTagAction> GetSmartTagActions(ParseItem item, int position, ITrackingSpan itemTrackingSpan, ITextView view) { HexColorValue hex = (HexColorValue)item; if (!item.IsValid) { yield break; } ColorModel model = ColorParser.TryParseColor(hex.Text, ColorParser.Options.None); if (model != null) { if (ColorConverterSmartTagAction.GetNamedColor(model.Color) != null) { yield return(new ColorConverterSmartTagAction(itemTrackingSpan, model, ColorFormat.Name)); } if (model.Format == ColorFormat.RgbHex6) { model.Format = ColorFormat.RgbHex3; string hex3 = ColorFormatter.FormatColor(model, ColorFormat.RgbHex3); if (hex3.Length == 4) { yield return(new ColorConverterSmartTagAction(itemTrackingSpan, model, ColorFormat.RgbHex3)); } } yield return(new ColorConverterSmartTagAction(itemTrackingSpan, model, ColorFormat.Rgb)); yield return(new ColorConverterSmartTagAction(itemTrackingSpan, model, ColorFormat.Hsl)); } }
private static string GetChannelExpression(Match match, char channel) { var color = ColorParser.TryParseColor(match.Value, ColorParser.Options.AllowNames | ColorParser.Options.LooseParsing); int num = 0; if (color == null && !int.TryParse(match.Value, out num)) { return(null); } else if (color != null) { if (channel == 'R') { return(color.Color.R.ToString(CultureInfo.CurrentCulture)); } if (channel == 'G') { return(color.Color.G.ToString(CultureInfo.CurrentCulture)); } return(color.Color.B.ToString(CultureInfo.CurrentCulture)); } return(Math.Min(num, 255).ToString(CultureInfo.CurrentCulture)); }
public void TestParseColor__Empty() { Assert.Throws <FormatException>(delegate { ColorParser.Parse(""); }); }
public void ParseTest(string[] channels, int[] expectedColorChannels) { var expectedColor = ToColor(expectedColorChannels); var parsed = ColorParser.Parse(channels); AssertColorsAreEqual(parsed, expectedColor); }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { string color1 = ColorParser.GetColorString(panel1.BackColor); string color2 = customColorControl1.GetConfigString(); frmSettings.Petronode_ColorPicker_Configuration = color1 + color2; frmSettings.Save(); }
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__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__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__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__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__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__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__InvalidHex() { FormatException ex = Assert.Throws <FormatException>(delegate { ColorParser.Parse("#00g"); }); Assert.Equal("Invalid hexadecimal character: g", ex.Message); }
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 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); }
// Build the gradient from data found in the node void IParserEventSubscriber.Apply(ConfigNode node) { // List of keyframes points = new SortedList<float, Color>(); // Iterate through all the values in the node (all are keyframes) foreach(ConfigNode.Value point in node.values) { // Convert the "name" (left side) into a float for sorting float p = float.Parse(point.name); // Get the color at this point ColorParser cp = new ColorParser(); cp.SetFromString(point.value); // Add the keyframe to the list points.Add(p, cp.value); } }