Exemple #1
0
        protected void BuildParameterCustom(GraphParameterValue v)
        {
            try
            {
                PropertyInfo info2 = v.GetType().GetProperty("Value");

                if (v.Value is double || v.Value is float || v.Value is int || v.Type == NodeType.Float)
                {
                    NumberSlider sp = new NumberSlider();
                    sp.Set(v.Min, v.Max, info2, v);
                    Stack.Children.Add(sp);
                }
                else if (v.Value is bool || v.Type == NodeType.Bool)
                {
                    ToggleControl tc = new ToggleControl(v.Name, info2, v);
                    Stack.Children.Add(tc);
                }
                else if (v.Type == NodeType.Float2 || v.Type == NodeType.Float3 || v.Type == NodeType.Float4)
                {
                    VectorSlider vs = new VectorSlider(info2, v, v.Min, v.Max, v.Type);
                    Stack.Children.Add(vs);
                }
                else if (v.Value is MVector || v.Type == NodeType.Color || v.Type == NodeType.Gray)
                {
                    ColorSelect cs = new ColorSelect(info2, v);
                    Stack.Children.Add(cs);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }
Exemple #2
0
 private void NodedAddedHandler(INode n)
 {
     if (!HasNode(n))
     {
         NodeBaseControl nn;
         if (n is NumberInputNode)
         {
             nn = new NumberSlider(_manager, _manager.ActiveKernel.Get <ZoomBorder>(), n);
         }
         else
         {
             nn = new NodeBaseControl(_manager, _manager.ActiveKernel.Get <ZoomBorder>(), n);
         }
         NodesCanvas.Children.Add(nn);
         nn.OnSocketDragStart += SocketDragStarted;
     }
 }
Exemple #3
0
        private void PanGestureRecognizer_PanUpdated(object sender, PanUpdatedEventArgs e)
        {
            var minPan = SliderCanvas.Width * .25f;
            var maxPan = SliderCanvas.Width * .75f;
            var width  = maxPan - minPan;

            var incomingX = NumberSlider.TranslationX + e.TotalX;
            var test      = 0.0;

            switch (e.StatusType)
            {
            case GestureStatus.Running:

                test = Math.Max(minPan, incomingX);
                test = Math.Min(maxPan, test);

                NumberSlider.TranslationX = test;
                SliderBuffer.TranslationX = test;
                Count           = CalculateNumberOfPeople((int)width, 10, (int)test) - 5;
                CountLabel.Text = Count.ToString();

                SliderCanvas.InvalidateSurface();

                break;

            case GestureStatus.Completed:
                test = Math.Max(minPan, incomingX);
                test = Math.Min(maxPan, test);

                NumberSlider.TranslateTo(test, 0);
                SliderBuffer.TranslateTo(test, 0);
                SliderCanvas.InvalidateSurface();

                break;
            }
        }
Exemple #4
0
        protected UIElement BuildParamater(object owner, EditableAttribute edit, PropertyInfo v, PropertyInfo template = null)
        {
            if (v == null || owner == null || edit == null)
            {
                return(null);
            }

            if (template == null)
            {
                template = v;
            }

            switch (edit.Type)
            {
            case ParameterInputType.FloatInput:
                NumberInput nfp = new NumberInput();
                nfp.Set(NumberInputType.Float, owner, v);
                return(nfp);

            case ParameterInputType.FloatSlider:
                NumberSlider nfs = new NumberSlider();
                nfs.Ticks = edit.Ticks;
                nfs.Set(edit.Min, edit.Max, v, owner);
                return(nfs);

            case ParameterInputType.IntInput:
                NumberInput nip = new NumberInput();
                nip.Set(NumberInputType.Int, owner, v);
                return(nip);

            case ParameterInputType.IntSlider:
                NumberSlider nis = new NumberSlider();
                nis.Ticks = edit.Ticks;
                nis.IsInt = true;
                nis.Set(edit.Min, edit.Max, v, owner);
                return(nis);

            case ParameterInputType.Dropdown:
                DropdownAttribute da      = template.GetCustomAttribute <DropdownAttribute>();
                object[]          dvalues = null;
                if (template.PropertyType.IsEnum)
                {
                    dvalues = Enum.GetNames(template.PropertyType);
                }
                else if (v.PropertyType.Equals(typeof(string[])))
                {
                    dvalues = (string[])v.GetValue(owner);
                }
                if (da != null && da.Values != null && da.Values.Length > 0)
                {
                    dvalues = da.Values;
                }
                if (da != null)
                {
                    return(new DropDown(dvalues, owner, v, da.OutputProperty, da.IsEditable));
                }

                return(new DropDown(dvalues, owner, v));

            case ParameterInputType.Color:
                return(new ColorSelect(v, owner));

            case ParameterInputType.Curves:
                return(new UICurves(v, owner));

            case ParameterInputType.Levels:
                Imaging.RawBitmap raw = null;
                if (owner is ImageNode)
                {
                    byte[] bits = (owner as ImageNode).GetPreview(256, 256);
                    if (bits != null)
                    {
                        raw = new Imaging.RawBitmap(256, 256, bits);
                    }
                }
                return(new UILevels(raw, owner, v));

            case ParameterInputType.Map:
                object mo = v.GetValue(owner);
                if (mo is Dictionary <string, GraphParameterValue> && owner is GraphInstanceNode)
                {
                    return(new ParameterMap((owner as GraphInstanceNode).GraphInst, mo as Dictionary <string, GraphParameterValue>));
                }
                else if (mo is List <GraphParameterValue> && owner is Node)
                {
                    return(new ParameterMap(owner as Node, mo as List <GraphParameterValue>));
                }
                else if (mo is List <GraphParameterValue> )
                {
                    return(new ParameterMap(null, mo as List <GraphParameterValue>));
                }
                return(null);

            case ParameterInputType.MapEdit:
                object meo = v.GetValue(owner);
                if (meo is Dictionary <string, GraphParameterValue> && owner is Graph && !(owner is FunctionGraph))
                {
                    return(new GraphParameterEditor(owner as Graph, meo as Dictionary <string, GraphParameterValue>));
                }
                else if (meo is List <GraphParameterValue> && owner is Graph && !(owner is FunctionGraph))
                {
                    return(new CustomParameterEditor(owner as Graph));
                }
                else if (meo is List <FunctionGraph> && owner is Graph && !(owner is FunctionGraph))
                {
                    return(new CustomFunctionEditor(owner as Graph));
                }
                else if (meo is  Dictionary <string, FunctionGraph> && !(owner is FunctionGraph))
                {
                    return(new GraphFunctionEditor(owner as Graph));
                }
                return(null);

            case ParameterInputType.MeshFile:
                return(new FileSelector(v, owner, "Mesh Files|*.fbx;*.obj"));

            case ParameterInputType.ImageFile:
                return(new FileSelector(v, owner, "Image Files|*.png;*.jpg;*.tif;*.bmp;*.jpeg"));

            case ParameterInputType.GraphFile:
                return(new FileSelector(v, owner, "Materia Graph|*.mtg"));

            case ParameterInputType.Text:
                return(new PropertyInput(v, owner, template.GetCustomAttribute <ReadOnlyAttribute>() != null));

            case ParameterInputType.MultiText:
                return(new PropertyInput(v, owner, template.GetCustomAttribute <ReadOnlyAttribute>() != null, true));

            case ParameterInputType.Toggle:
                return(new ToggleControl(edit.Name, v, owner));

            case ParameterInputType.Gradient:
                return(new GradientEditor(v, owner));

            case ParameterInputType.Float2Input:
                return(new VectorInput(v, owner, NodeType.Float2));

            case ParameterInputType.Float2Slider:
                return(new VectorSlider(v, owner, edit.Min, edit.Max, NodeType.Float2));

            case ParameterInputType.Float3Input:
                return(new VectorInput(v, owner, NodeType.Float3));

            case ParameterInputType.Float3Slider:
                return(new VectorSlider(v, owner, edit.Min, edit.Max, NodeType.Float3));

            case ParameterInputType.Float4Input:
                return(new VectorInput(v, owner, NodeType.Float4));

            case ParameterInputType.Float4Slider:
                return(new VectorSlider(v, owner, edit.Min, edit.Max, NodeType.Float4));

            case ParameterInputType.Int2Input:
                return(new VectorInput(v, owner, NodeType.Float2, NumberInputType.Int));

            case ParameterInputType.Int2Slider:
                return(new VectorSlider(v, owner, edit.Min, edit.Max, NodeType.Float2, true));

            case ParameterInputType.Int3Input:
                return(new VectorInput(v, owner, NodeType.Float3, NumberInputType.Int));

            case ParameterInputType.Int3Slider:
                return(new VectorSlider(v, owner, edit.Min, edit.Max, NodeType.Float3, true));

            case ParameterInputType.Int4Input:
                return(new VectorInput(v, owner, NodeType.Float4, NumberInputType.Int));

            case ParameterInputType.Int4Slider:
                return(new VectorSlider(v, owner, edit.Min, edit.Max, NodeType.Float4, true));
            }

            return(null);
        }
Exemple #5
0
        protected void BuildParameter(string parameter, GraphParameterValue v, Node n)
        {
            try
            {
                PropertyInfo info1 = n.GetType().GetProperty(parameter);
                PropertyInfo info2 = v.GetType().GetProperty("Value");

                if (info1 == null)
                {
                    if (v.Value is float)
                    {
                        NumberInput np = new NumberInput(NumberInputType.Float, v, info2);
                        Stack.Children.Add(np);
                    }
                    else if (v.Value is int)
                    {
                        NumberInput np = new NumberInput(NumberInputType.Int, v, info2);
                        Stack.Children.Add(np);
                    }
                    else if (v.Value is bool)
                    {
                        ToggleControl tc = new ToggleControl("True", info2, v);
                        Stack.Children.Add(tc);
                    }
                }
                else
                {
                    if (v.Value is float || v.Value is int)
                    {
                        SliderAttribute sl = info1.GetCustomAttribute <SliderAttribute>();

                        if (sl != null)
                        {
                            NumberSlider inp = new NumberSlider(sl, info2, v);
                            Stack.Children.Add(inp);
                        }
                        else if (v.Value is float)
                        {
                            NumberInput np = new NumberInput(NumberInputType.Float, v, info2);
                            Stack.Children.Add(np);
                        }
                        else if (v.Value is int)
                        {
                            NumberInput np = new NumberInput(NumberInputType.Int, v, info2);
                            Stack.Children.Add(np);
                        }
                    }
                    else if (v.Value is bool)
                    {
                        ToggleControl tc = new ToggleControl(v.Name, info2, v);
                        Stack.Children.Add(tc);
                    }
                    else if (v.Value is Vector4)
                    {
                        ColorSelect cs = new ColorSelect(info2, v);
                        Stack.Children.Add(cs);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }
Exemple #6
0
        void CreateUIElement(Type t, PropertyInfo p, string name)
        {
            DropdownAttribute             dp   = p.GetCustomAttribute <DropdownAttribute>();
            LevelEditorAttribute          le   = p.GetCustomAttribute <LevelEditorAttribute>();
            CurveEditorAttribute          ce   = p.GetCustomAttribute <CurveEditorAttribute>();
            SliderAttribute               sl   = p.GetCustomAttribute <SliderAttribute>();
            FileSelectorAttribute         fsl  = p.GetCustomAttribute <FileSelectorAttribute>();
            HidePropertyAttribute         hp   = p.GetCustomAttribute <HidePropertyAttribute>();
            ColorPickerAttribute          cp   = p.GetCustomAttribute <ColorPickerAttribute>();
            TitleAttribute                ti   = p.GetCustomAttribute <TitleAttribute>();
            TextInputAttribute            tinp = p.GetCustomAttribute <TextInputAttribute>();
            GraphParameterEditorAttribute gpe  = p.GetCustomAttribute <GraphParameterEditorAttribute>();
            ParameterMapEditorAttribute   pme  = p.GetCustomAttribute <ParameterMapEditorAttribute>();
            PromoteAttribute              pro  = p.GetCustomAttribute <PromoteAttribute>();
            ParameterEditorAttribute      pe   = p.GetCustomAttribute <ParameterEditorAttribute>();
            GraphFunctionEditorAttribute  fe   = p.GetCustomAttribute <GraphFunctionEditorAttribute>();

            //handle very special stuff
            //exposed constant parameter variable names
            if (gpe != null)
            {
                if (node is Graph && !(node is FunctionGraph))
                {
                    Graph g = node as Graph;

                    GraphParameterEditor inp = new GraphParameterEditor(g, g.Parameters);
                    Stack.Children.Add(inp);
                    elementLookup[name] = inp;
                }
            }
            //handle special custom parameter editing
            else if (pe != null)
            {
                if (node is Graph && !(node is FunctionGraph))
                {
                    Graph g = node as Graph;
                    CustomParameterEditor inp = new CustomParameterEditor(g);
                    Stack.Children.Add(inp);
                    elementLookup[name] = inp;
                }
            }
            else if (fe != null)
            {
                if (node is Graph && !(node is FunctionGraph))
                {
                    Graph g = node as Graph;
                    CustomFunctionEditor inp = new CustomFunctionEditor(g);
                    Stack.Children.Add(inp);
                    elementLookup[name] = inp;
                }
            }
            //for graph instance exposed parameters from underlying graph
            else if (pme != null)
            {
                if (node is GraphInstanceNode)
                {
                    GraphInstanceNode gin = node as GraphInstanceNode;

                    if (p.PropertyType.Equals(typeof(List <GraphParameterValue>)))
                    {
                        ParameterMap pm = new ParameterMap(gin.CustomParameters);
                        Stack.Children.Add(pm);
                        elementLookup[name] = pm;
                    }
                    else
                    {
                        ParameterMap pm = new ParameterMap(gin.Parameters);
                        Stack.Children.Add(pm);
                        elementLookup[name] = pm;
                    }
                }
            }

            string title = name;

            if (ti != null)
            {
                title = ti.Title;
            }

            PropertyInfo op = null;

            //we don't create an element for this one
            //as it is hidden
            if (hp != null)
            {
                return;
            }

            try
            {
                if (ce != null)
                {
                    op = node.GetType().GetProperty(ce.OutputProperty);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }

            if (t.Equals(typeof(Gradient)))
            {
                var l = new PropertyLabel();
                l.Title = title;

                labels.Add(l);
                Stack.Children.Add(l);

                GradientEditor inp = new GradientEditor(p, node);
                Stack.Children.Add(inp);
                elementLookup[name] = inp;
            }
            else if (t.Equals(typeof(MVector)))
            {
                if (cp != null)
                {
                    PropertyLabel l = null;
                    if (pro != null && node is Node)
                    {
                        l = new PropertyLabel(title, node as Node, name);
                    }
                    else
                    {
                        l       = new PropertyLabel();
                        l.Title = title;
                    }

                    labels.Add(l);
                    Stack.Children.Add(l);

                    ColorSelect cs = new ColorSelect(p, node);
                    Stack.Children.Add(cs);
                    elementLookup[name] = cs;
                }
            }
            else if (t.Equals(typeof(string[])))
            {
                if (dp != null)
                {
                    PropertyLabel l = new PropertyLabel();
                    l.Title = title;
                    labels.Add(l);
                    Stack.Children.Add(l);

                    DropDown inp = new DropDown((string[])p.GetValue(node), node, p, dp.OutputProperty);
                    Stack.Children.Add(inp);
                    elementLookup[name] = inp;
                }
            }
            else if (t.Equals(typeof(bool)))
            {
                PropertyLabel l = null;
                if (pro != null && node is Node)
                {
                    l = new PropertyLabel(title, node as Node, name);
                }
                else
                {
                    l       = new PropertyLabel();
                    l.Title = title;
                }

                labels.Add(l);
                Stack.Children.Add(l);

                ToggleControl tg = new ToggleControl(name, p, node);
                Stack.Children.Add(tg);
                elementLookup[name] = tg;
            }
            else if (t.Equals(typeof(string)))
            {
                if (tinp != null)
                {
                    PropertyLabel l = new PropertyLabel();
                    l.Title = title;
                    labels.Add(l);
                    Stack.Children.Add(l);

                    PropertyInput ip = new PropertyInput(p, node);
                    Stack.Children.Add(ip);
                    elementLookup[name] = ip;
                }
                else if (fsl != null)
                {
                    PropertyLabel l = new PropertyLabel();
                    l.Title = title;
                    labels.Add(l);
                    Stack.Children.Add(l);

                    FileSelector inp = new FileSelector(p, node, fsl.Filter);
                    Stack.Children.Add(inp);
                    elementLookup[name] = inp;
                }
                else if (dp != null)
                {
                    PropertyLabel l = new PropertyLabel();
                    l.Title = title;
                    labels.Add(l);
                    Stack.Children.Add(l);

                    object[] names = dp.Values;
                    DropDown inp   = new DropDown(names, node, p, dp.OutputProperty);
                    Stack.Children.Add(inp);
                    elementLookup[name] = inp;
                }
            }
            else if (t.Equals(typeof(float)))
            {
                if (sl != null)
                {
                    PropertyLabel l = null;
                    if (pro != null && node is Node)
                    {
                        l = new PropertyLabel(title, node as Node, name);
                    }
                    else
                    {
                        l       = new PropertyLabel();
                        l.Title = title;
                    }

                    labels.Add(l);
                    Stack.Children.Add(l);

                    NumberSlider inp = new NumberSlider(sl, p, node);
                    Stack.Children.Add(inp);
                    elementLookup[name] = inp;
                }
                else
                {
                    PropertyLabel l = null;
                    if (pro != null && node is Node)
                    {
                        l = new PropertyLabel(title, node as Node, name);
                    }
                    else
                    {
                        l       = new PropertyLabel();
                        l.Title = title;
                    }

                    labels.Add(l);
                    Stack.Children.Add(l);

                    NumberInput inp = new NumberInput(NumberInputType.Float, node, p);
                    Stack.Children.Add(inp);
                    elementLookup[name] = inp;
                }
            }
            else if (t.Equals(typeof(int)))
            {
                if (dp != null)
                {
                    PropertyLabel l = new PropertyLabel();
                    l.Title = title;
                    labels.Add(l);
                    Stack.Children.Add(l);

                    //do a dropdown
                    object[] names = dp.Values;
                    DropDown inp   = new DropDown(names, node, p, dp.OutputProperty);
                    Stack.Children.Add(inp);
                    elementLookup[name] = inp;
                }
                else if (sl != null)
                {
                    PropertyLabel l = null;
                    if (pro != null && node is Node)
                    {
                        l = new PropertyLabel(title, node as Node, name);
                    }
                    else
                    {
                        l       = new PropertyLabel();
                        l.Title = title;
                    }

                    labels.Add(l);
                    Stack.Children.Add(l);

                    NumberSlider inp = new NumberSlider(sl, p, node);
                    Stack.Children.Add(inp);
                    elementLookup[name] = inp;
                }
                else
                {
                    PropertyLabel l = null;
                    if (pro != null && node is Node)
                    {
                        l = new PropertyLabel(title, node as Node, name);
                    }
                    else
                    {
                        l       = new PropertyLabel();
                        l.Title = title;
                    }

                    labels.Add(l);
                    Stack.Children.Add(l);

                    NumberInput inp = new NumberInput(NumberInputType.Int, node, p);
                    Stack.Children.Add(inp);
                    elementLookup[name] = inp;
                }
            }
            else if (t.Equals(typeof(MultiRange)))
            {
                if (le != null)
                {
                    UILevels lv = null;
                    if (node is Node)
                    {
                        Node nd = (Node)node;
                        if (nd.Inputs.Count > 0 && nd.Inputs[0].Input != null)
                        {
                            var    n      = nd.Inputs[0].Input.Node;
                            byte[] result = n.GetPreview(n.Width, n.Height);

                            RawBitmap bit = null;

                            if (result != null)
                            {
                                bit = new RawBitmap(n.Width, n.Height, result);
                            }

                            lv = new UILevels(bit, node, p);
                        }
                        else
                        {
                            lv = new UILevels(null, node, p);
                        }
                        Stack.Children.Add(lv);
                        elementLookup[name] = lv;
                    }
                }
            }
            else if (op != null && ce != null)
            {
                UICurves cv = new UICurves(p, op, node);
                Stack.Children.Add(cv);
                elementLookup[name] = cv;
            }
            else if (t.IsEnum)
            {
                PropertyLabel l = new PropertyLabel();
                l.Title = title;
                labels.Add(l);
                Stack.Children.Add(l);

                string[] names = Enum.GetNames(t);
                DropDown inp   = new DropDown(names, node, p);
                Stack.Children.Add(inp);
                elementLookup[name] = inp;
            }
        }