public IColorReference GetColorReference(ITreeNode element) { if (element is IColorLiteral colorLiteral) { var values = colorLiteral.Numbers; if (values.Count == 3 || values.Count == 4) { var r = GetColorValue(values[0]); var g = GetColorValue(values[1]); var b = GetColorValue(values[2]); // Technically, the colour should have 4 values, but show the highlight even if we're unfinished var a = values.Count == 4 ? GetColorValue(values[3]) : 255; var colorElement = new ColorElement(Color.FromArgb(a, r, g, b)); var range = GetDocumentRange(values[0], values.Last()); return(new ShaderLabColorReference(colorElement, ColorPropertyValueNavigator.GetByColor(colorLiteral), ColorValueNavigator.GetByConstant(colorLiteral), range)); } } return(null); }
public IColorReference GetColorReference(ITreeNode element) { if (element is IVectorLiteral vectorLiteral) { var vectorPropertyValue = VectorPropertyValueNavigator.GetByVector(vectorLiteral); if (vectorPropertyValue != null) { // Does the vector literal belong to a vector property or a color property? var propertyDeclation = PropertyDeclarationNavigator.GetByPropertValue(vectorPropertyValue); if (propertyDeclation == null) { return(null); } if (!(propertyDeclation.PropertyType is ISimplePropertyType simplePropertyType) || simplePropertyType.Keyword?.NodeType != ShaderLabTokenType.COLOR_KEYWORD) { return(null); } } var values = vectorLiteral.Numbers; if (values.Count == 3 || values.Count == 4) { var r = GetColorValue(values[0]); var g = GetColorValue(values[1]); var b = GetColorValue(values[2]); // Technically, the colour should have 4 values, but show the highlight even if we're unfinished var a = values.Count == 4 ? GetColorValue(values[3]) : 255; var colorElement = new ColorElement(Color.FromArgb(a, r, g, b)); var range = GetDocumentRange(values[0], values.Last()); return(new ShaderLabColorReference(colorElement, VectorPropertyValueNavigator.GetByVector(vectorLiteral), ColorValueNavigator.GetByConstant(vectorLiteral), range)); } } return(null); }