Color


Node Information
Color, ARGB type.
General Information
• This node doesn't have other available options.
Visual
Visual

Ports
Text Type DataType Accepts IsList CustomAcception
Value OUT Color MULTIPLE FALSE FALSE
R IN Byte ONE FALSE FALSE
G IN Byte ONE FALSE FALSE
B IN Byte ONE FALSE FALSE

Source
namespace Korduene.KGraph.Nodes.Variables
{
    [IsNode("Color")]
    public class VarColor : Node
    {
        Port color = new Port(PortType.OUT, typeof(System.Drawing.Color), AcceptsLinks.MULTIPLE, "Value");
        Port r = new Port(PortType.IN, typeof(byte), AcceptsLinks.ONE, "R");
        Port g = new Port(PortType.IN, typeof(byte), AcceptsLinks.ONE, "G");
        Port b = new Port(PortType.IN, typeof(byte), AcceptsLinks.ONE, "B");
        bool change = false;
        public System.Drawing.Color Color
        {
            set
            {
                R = value.R;
                G = value.G;
                B = value.B;
                color.Value = value.R + "," + value.G + "," + value.B;
            }
            get
            {
                return System.Drawing.Color.FromArgb(R, G, B);
            }
        }
        public byte R
        {
            set { r.Value = value.ToString(); }
            get { return GetRuntimeValue(r); }
        }
        public byte G
        {
            set { g.Value = value.ToString(); }
            get { return GetRuntimeValue(g); }
        }
        public byte B
        {
            set { b.Value = value.ToString(); }
            get { return GetRuntimeValue(b); }
        }
        public VarColor()
        {
            NodeType = KGraph.NodeType.Variable;
            ReturnType = typeof(System.Drawing.Color);
            color.Value = "0,0,0";
            Color = System.Drawing.Color.Black;
            r.Value = "0";
            g.Value = "0";
            b.Value = "0";
            Name = "Color";
            AddPort(color);
            AddPort(r);
            AddPort(g);
            AddPort(b);
            Information = "Color, ARGB type.";
            color.ValueChanged += color_ValueChanged;
            r.ValueChanged += rgb_ValueChanged;
            g.ValueChanged += rgb_ValueChanged;
            b.ValueChanged += rgb_ValueChanged;
        }
        void rgb_ValueChanged(object sender, string e)
        {
            if (!change)
            {
                if (color.Editor != null)
                {
                    color.Editor.SetValue(r.Value + "," + g.Value + "," + b.Value);
                }
            }
        }
        void color_ValueChanged(object sender, string e)
        {
            change = true;
            string[] c = color.Value.Split(',');
            R = byte.Parse(c[0]);
            G = byte.Parse(c[1]);
            B = byte.Parse(c[2]);
            if (ParentGraph != null)
            {
                ParentGraph.RefreshPropertyGrid();
            }
            change = false;
        }
        public override string Code()
        {
            return "System.Drawing.Color.FromArgb(" + R + "," + G + "," + B + ")";
        }
        public override void UpdateResults()
        {
            Code();
            ParentGraph.RefreshPropertyGrid();
        }
    }
}