Example #1
0
        private DragData OnDragParameter(DraggablePropertyNameLabel label)
        {
            var window    = (IVisjectSurfaceWindow)Values[0];
            var parameter = window.VisjectSurface.Parameters[(int)label.Tag];

            return(DragNames.GetDragData(SurfaceParameter.DragPrefix, parameter.Name));
        }
Example #2
0
        /// <inheritdoc />
        public override void Initialize(LayoutElementsContainer layout)
        {
            var window = Values[0] as IVisjectSurfaceWindow;
            var asset  = window?.VisjectAsset;

            if (asset == null)
            {
                layout.Label("No parameters");
                return;
            }
            if (asset.LastLoadFailed)
            {
                layout.Label("Failed to load asset");
                return;
            }
            if (!asset.IsLoaded)
            {
                layout.Label("Loading...");
                return;
            }
            var          parameters = window.VisjectSurface.Parameters;
            GroupElement lastGroup  = null;

            for (int i = 0; i < parameters.Count; i++)
            {
                var p = parameters[i];
                if (!p.IsPublic)
                {
                    continue;
                }

                var pIndex     = i;
                var pValue     = p.Value;
                var attributes = p.Meta.GetAttributes();
                if (attributes == null || attributes.Length == 0)
                {
                    attributes = DefaultAttributes;
                }
                var itemLayout = layout;
                var name       = p.Name;

                // Editor Display
                var editorDisplay = (EditorDisplayAttribute)attributes.FirstOrDefault(x => x is EditorDisplayAttribute);
                if (editorDisplay?.Group != null)
                {
                    if (lastGroup == null || lastGroup.Panel.HeaderText != editorDisplay.Group)
                    {
                        lastGroup = layout.Group(editorDisplay.Group);
                        lastGroup.Panel.Open(false);
                    }
                    itemLayout = lastGroup;
                }
                else
                {
                    lastGroup  = null;
                    itemLayout = layout;
                }
                if (editorDisplay?.Name != null)
                {
                    name = editorDisplay.Name;
                }

                // Space
                var space = (SpaceAttribute)attributes.FirstOrDefault(x => x is SpaceAttribute);
                if (space != null)
                {
                    itemLayout.Space(space.Height);
                }

                // Header
                var header = (HeaderAttribute)attributes.FirstOrDefault(x => x is HeaderAttribute);
                if (header != null)
                {
                    itemLayout.Header(header.Text);
                }

                var propertyValue = new CustomValueContainer
                                    (
                    p.Type,
                    pValue,
                    (instance, index) => ((IVisjectSurfaceWindow)instance).GetParameter(pIndex),
                    (instance, index, value) => ((IVisjectSurfaceWindow)instance).SetParameter(pIndex, value),
                    attributes
                                    );

                var propertyLabel = new DraggablePropertyNameLabel(name)
                {
                    Tag  = pIndex,
                    Drag = OnDragParameter
                };
                var tooltip = (TooltipAttribute)attributes.FirstOrDefault(x => x is TooltipAttribute);
                propertyLabel.MouseLeftDoubleClick += (label, location) => StartParameterRenaming(pIndex, label);
                propertyLabel.SetupContextMenu     += OnPropertyLabelSetupContextMenu;
                var property = itemLayout.AddPropertyItem(propertyLabel, tooltip?.Text);
                property.Object(propertyValue);
            }

            // Parameters creating
            var newParameterTypes = window.NewParameterTypes;

            if (newParameterTypes != null)
            {
                layout.Space(parameters.Count > 0 ? 10 : 4);
                var newParam = layout.Button("Add parameter...");
                newParam.Button.ButtonClicked += OnAddParameterButtonClicked;
                layout.Space(10);
            }
        }