private string GenerateSvg() { var g = new Graph(); g.ColorScheme = "svg"; g.RankDir = RankDirType.LR; foreach (var cls in Model.Classes.Values) { if (cls.TargetClass.Compiled.Attr("nosvg").ToBool()) { continue; } var n = new Node { Code = cls.Name, Label = cls.Name, Tooltip = cls.Comment, Shape = NodeShapeType.Box3d }; var dotcolor = cls.TargetClass.Compiled.Attr("dot-color"); if (!string.IsNullOrWhiteSpace(dotcolor)) { n.Style = NodeStyleType.Filled; n.FillColor = ColorAttribute.Single(Color.Create(dotcolor)); } g.AddNode(n); foreach (var r in cls.GetReferences()) { if (r.NoSql) { continue; } if (null == r.ReferenceClass.TargetClass) { continue; } if (r.ReferenceClass.TargetClass.Compiled.Attr("nosvg").ToBool()) { continue; } var e = new Edge { From = cls.Name, To = r.ReferenceClass.Name, ArrowHead = new Arrow { MainType = ArrowType.Normal } }; if (r.IsReverese) { e.ArrowTail = new Arrow { MainType = ArrowType.Diamond }; } g.AddEdge(e); } } var provider = new DotGraphProvider(); var render = GraphRender.Create(g); var script = render.GenerateGraphScript(); var svg = provider.Generate(script, new GraphOptions { Format = "svg" }); return(svg.ToString()); }
private static Color GetColor(ColorAttribute attribute, object source, bool ignoreAlpha) { if (attribute != null) { Color color = attribute.Value; if (ignoreAlpha) { color.a = 1f; } return(color); } else if (hardCodedColors.TryGetValue(source, out Color color)) { if (ignoreAlpha) { color.a = 1f; } return(color); } else { var hash = source.GetHashCode(); var a = ignoreAlpha ? 1f : (0b00000000000000000000000011111111 & hash) / 255f; var b = ((0b00000000000000001111111100000000 & hash) >> 8) / 255f; var g = ((0b00000000111111110000000000000000 & hash) >> 16) / 255f; var r = ((0b11111111000000000000000000000000 & hash) >> 24) / 255f; return(new Color(r, g, b, a)); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { Color oldColor = GUI.backgroundColor; ColorAttribute colorAttribute = attribute as ColorAttribute; GUI.backgroundColor = colorAttribute.color; EditorGUI.PropertyField(position, property, label); GUI.backgroundColor = oldColor; }
/// <summary> /// Populates the element (including children) with information from its XML definition. /// </summary> /// <param name="Input">XML definition.</param> public override void FromXml(XmlElement Input) { base.FromXml(Input); this.fontId = new StringAttribute(Input, "fontId"); this.penId = new StringAttribute(Input, "penId"); this.backgroundId = new StringAttribute(Input, "backgroundId"); this.textColor = new ColorAttribute(Input, "textColor"); }
/// <summary> /// Populates the element (including children) with information from its XML definition. /// </summary> /// <param name="Input">XML definition.</param> public override void FromXml(XmlElement Input) { base.FromXml(Input); this.dX = new LengthAttribute(Input, "dX"); this.dY = new LengthAttribute(Input, "dY"); this.sigmaX = new DoubleAttribute(Input, "sigmaX"); this.sigmaY = new DoubleAttribute(Input, "sigmaY"); this.color = new ColorAttribute(Input, "color"); }
/// <summary> /// Populates the element (including children) with information from its XML definition. /// </summary> /// <param name="Input">XML definition.</param> public override void FromXml(XmlElement Input) { base.FromXml(Input); this.name = new StringAttribute(Input, "name"); this.size = new LengthAttribute(Input, "size"); this.weight = new EnumAttribute <SKFontStyleWeight>(Input, "weight"); this.width = new EnumAttribute <SKFontStyleWidth>(Input, "width"); this.slant = new EnumAttribute <SKFontStyleSlant>(Input, "slant"); this.color = new ColorAttribute(Input, "color"); }
public void CanSumColorAndDouble() { var item = Color.Red + 0.3; Assert.IsInstanceOf <ColorListItem>(item); ColorList list = item; ColorAttribute attr = list; var item2 = Color.Red + 0.3 + Color.RGB(0x00, 0xFF, 0xAA) + 0.2 + Color.Create("33abcd") + 0.5; Assert.IsInstanceOf <ColorList>(item2); Assert.AreEqual("red;0.3:#00ffaa;0.2:#33abcd;0.5", item2.ToString()); }
/* * Build an attribute based on a value. Search in the static fields for the value. * */ public static Logical GetLogicalAttribute(String value) { Domain.Entities.Attribute attribute = null; if (fuel.Contains(value)) { attribute = new EngineAttribute(value); } if (colors.Contains(value)) { attribute = new ColorAttribute(value); } if (vehicleClass.Contains(value)) { attribute = new ClassAttribute(value); } if (transmission.Contains(value)) { attribute = new TransmissionAttribute(value); } if (value.Contains("seater")) { attribute = new SeatsAttribute(value); } if (value.Equals("gps")) { attribute = new GPSAttribute(); } if (value.Equals("sunroof")) { attribute = new SunroofAttribute(); } if (attribute == null) { throw new ParseException($"Attribute {value} not found!"); } return(new LogicalAttribute(attribute)); }
/// <summary> /// Pres the draw node window. /// </summary> /// <param name="item">Item.</param> protected override void PreDrawNodeWindow(EditorWindowLayoutItem item) { ZEntity en = curPoolConfig.CurPool.FindEntityTemplateByID(item.wndID); GUI.color = Color.yellow; if (en != null) { ColorAttribute ca = en.GetSupportAttribute <ColorAttribute> (); if (ca != null) { //Debug.Log ("NodeColor is " + ca.NodeColor); GUI.color = ca.ToUnityColor(); } } if (en.EType == EntityType.System) { GUI.color = Color.gray; } }
/// <summary> /// Устанавливает стиль узла /// </summary> /// <param name="builder"></param> /// <param name="color"></param> /// <returns></returns> public static T SetColor <T>(this T builder, ColorAttribute color) where T : IGraphElementBuilder { builder.Set(DotConstants.ColorAttribute, color); return(builder); }
/// <summary> /// Populates the element (including children) with information from its XML definition. /// </summary> /// <param name="Input">XML definition.</param> public override void FromXml(XmlElement Input) { base.FromXml(Input); this.color = new ColorAttribute(Input, "color"); }
public FieldInspector(SerializedProperty property) { BindingFlags flags = BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; Field = property.serializedObject.targetObject.GetType().GetField(property.name, flags); Property = property; Label = property.displayName; if (Field != null) { InspectorAttribute[] iattributes = (InspectorAttribute[])Field.GetCustomAttributes(typeof(InspectorAttribute), true); for (int i = 0; i < iattributes.Length; i++) { if (iattributes[i] is EnableAttribute) { EnableCondition = property.serializedObject.targetObject.GetType().GetMethod(iattributes[i].Cast <EnableAttribute>().Condition, flags); if (EnableCondition != null && EnableCondition.ReturnType != typeof(bool)) { EnableCondition = null; } } else if (iattributes[i] is DisplayAttribute) { DisplayCondition = property.serializedObject.targetObject.GetType().GetMethod(iattributes[i].Cast <DisplayAttribute>().Condition, flags); if (DisplayCondition != null && DisplayCondition.ReturnType != typeof(bool)) { DisplayCondition = null; } } else if (iattributes[i] is LabelAttribute) { Label = iattributes[i].Cast <LabelAttribute>().Name; } else if (iattributes[i] is ColorAttribute) { ColorAttribute attribute = iattributes[i] as ColorAttribute; UseColor = new Color(attribute.R, attribute.G, attribute.B, attribute.A); } else if (iattributes[i] is ReadOnlyAttribute) { IsReadOnly = true; } else { var attr = iattributes[i]; var drawerType = MonoComponentInspector.GetDrawerType(attr.GetType()); Drawers.Add(Utility.Reflection.CreateInstance <FieldDrawer>(drawerType, attr)); } } SceneHandlerAttribute[] sattributes = (SceneHandlerAttribute[])Field.GetCustomAttributes(typeof(SceneHandlerAttribute), true); for (int i = 0; i < sattributes.Length; i++) { if (sattributes[i] is MoveHandlerAttribute) { SceneHandlers.Add(new MoveHandler(sattributes[i])); } else if (sattributes[i] is RadiusHandlerAttribute) { SceneHandlers.Add(new RadiusHandler(sattributes[i])); } else if (sattributes[i] is BoundsHandlerAttribute) { SceneHandlers.Add(new BoundsHandler(sattributes[i])); } else if (sattributes[i] is DirectionHandlerAttribute) { SceneHandlers.Add(new DirectionHandler(sattributes[i])); } else if (sattributes[i] is CircleAreaHandlerAttribute) { SceneHandlers.Add(new CircleAreaHandler(sattributes[i])); } } } }
public void ChangeElement(ColorAttribute element) { colorOrb = element; }
public ColorAttribute(ColorAttribute copyFrom) : this(copyFrom.type, copyFrom.color) { }
/// <summary> /// Устанавливает стиль узла /// </summary> /// <param name="builder"></param> /// <param name="fillcolor"></param> /// <returns></returns> public static IGraphNodeBuilder SetFillColor(this IGraphNodeBuilder builder, ColorAttribute fillcolor) { builder.Set(DotConstants.FillColorAttribute, fillcolor); return(builder); }
public void SetUp() { ColorAttribute = new ColorAttribute(); }
void LoadFieldAttributes() { //get input variables System.Reflection.FieldInfo[] fInfos = GetType().GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); List <string> actualFields = new List <string>(); anchorFieldInfoMap.Clear(); foreach (var field in fInfos) { // reading field informations. actualFields.Add(field.Name); anchorFieldInfoMap[field.Name] = field; if (!anchorFieldDictionary.ContainsKey(field.Name)) { anchorFieldDictionary[field.Name] = CreateAnchorField(); } AnchorField anchorField = anchorFieldDictionary[field.Name]; //detect multi-anchor by checking for PWArray<T> type if (field.FieldType.IsGenericType) { if (field.FieldType.GetGenericTypeDefinition() == typeof(PWArray <>)) { anchorField.multiple = true; } } System.Object[] attrs = field.GetCustomAttributes(true); foreach (var attr in attrs) { InputAttribute inputAttr = attr as InputAttribute; OutputAttribute outputAttr = attr as OutputAttribute; ColorAttribute colorAttr = attr as ColorAttribute; OffsetAttribute offsetAttr = attr as OffsetAttribute; VisibilityAttribute visibilityAttr = attr as VisibilityAttribute; NotRequiredAttribute notRequiredAttr = attr as NotRequiredAttribute; if (inputAttr != null) { anchorField.anchorType = AnchorType.Input; if (inputAttr.name != null) { anchorField.name = inputAttr.name; } } if (outputAttr != null) { anchorField.anchorType = AnchorType.Output; if (outputAttr.name != null) { anchorField.name = outputAttr.name; } } if (colorAttr != null) { anchorField.color = new SerializableColor(colorAttr.color); } if (offsetAttr != null) { anchorField.offset = offsetAttr.offset; anchorField.padding = offsetAttr.padding; } if (notRequiredAttr != null) { anchorField.required = false; } if (visibilityAttr != null) { anchorField.defaultVisibility = visibilityAttr.visibility; } } if (anchorField.anchorType == AnchorType.None) //field does not have a PW attribute { anchorFieldDictionary.Remove(field.Name); } else { //create anchor in this anchorField if there is not existing one if (anchorField.anchors.Count == 0) { anchorField.CreateNewAnchor(); } anchorField.colorSchemeName = ColorTheme.GetAnchorColorSchemeName(field.FieldType); anchorField.fieldName = field.Name; anchorField.fieldType = (SerializableType)field.FieldType; anchorField.fieldValue = field.GetValue(this); anchorField.nodeRef = this; } } //remove inhexistants field dictionary entries (for renamed variables): var toRemoveKeys = new List <string>(); foreach (var kp in anchorFieldDictionary) { if (!actualFields.Contains(kp.Key)) { toRemoveKeys.Add(kp.Key); } } foreach (var toRemoveKey in toRemoveKeys) { anchorFieldDictionary.Remove(toRemoveKey); } }
public override Panel CreateControl(BaseConfigurationAttribute attr, PropertyInfo prop, object configuration_instance) { var panel = base.CreateControl(attr, prop, configuration_instance); ColorAttribute cattr = attr as ColorAttribute; var color_str = GetConfigValue(prop, configuration_instance); var color_box = new TextBox() { Text = color_str, Width = 160, Height = 22, VerticalContentAlignment = VerticalAlignment.Center }; var bound = new Border() { BorderBrush = Brushes.Black, BorderThickness = new Thickness(1), Width = 15, Height = 15, Margin = new Thickness(5, 0, 0, 0) }; var color_rect = new Rectangle() { }; var button = new Button() { Content = DefaultLanguage.BUTTON_COLOR, Width = 75, Margin = new Thickness(5, 0, 5, 0) }; var color = StringToColor(color_str); color_rect.Fill = new SolidColorBrush() { Color = Color.FromArgb(color.A, color.R, color.G, color.B) }; bound.Child = color_rect; panel.Children.Add(color_box); panel.Children.Add(bound); panel.Children.Add(button); button.Click += (s, e) => { var colorDialog = new System.Windows.Forms.ColorDialog(); color_str = GetConfigValue(prop, configuration_instance); color = StringToColor(color_str); colorDialog.Color = color; colorDialog.FullOpen = true; if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { color = colorDialog.Color; color_box.Text = RgbaToString(color.R, color.G, color.B, color.A); } }; color_box.TextChanged += (s, e) => { color = StringToColor(color_box.Text); color_rect.Fill = new SolidColorBrush() { Color = Color.FromArgb(color.A, color.R, color.G, color.B) }; if (cattr.Check(color_box.Text)) { SetConfigValue(prop, configuration_instance, color_box.Text); } ConfigWindow.RequireRestart = attr.RequireRestart; }; return(panel); }