Exemplo n.º 1
0
 /// <inheritdoc />
 public Sample(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch)
     : base(id, context, nodeArch, groupArch)
 {
 }
Exemplo n.º 2
0
 /// <inheritdoc />
 protected StructureNode(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch, bool isUnpacking)
     : base(id, context, nodeArch, groupArch)
 {
     _isUnpacking = isUnpacking;
 }
Exemplo n.º 3
0
 /// <inheritdoc />
 public UnpackStructureNode(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch)
     : base(id, context, nodeArch, groupArch, true)
 {
 }
Exemplo n.º 4
0
 /// <inheritdoc />
 public SurfaceNodeParamsGet(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch)
     : base(id, context, nodeArch, groupArch)
 {
     // Force first layout init for every param type
     _layoutType = (ParameterType)int.MaxValue;
 }
Exemplo n.º 5
0
 /// <inheritdoc />
 public SurfaceNodeParamsGetParticleEmitter(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch)
     : base(id, context, nodeArch, groupArch)
 {
     Prototypes = DefaultPrototypesParticleEmitter;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VisjectCMItem"/> class.
 /// </summary>
 /// <param name="group">The group.</param>
 /// <param name="archetype">The archetype.</param>
 public VisjectCMItem(VisjectCMGroup group, NodeArchetype archetype)
     : base(0, 0, 120, 12)
 {
     Group      = group;
     _archetype = archetype;
 }
Exemplo n.º 7
0
 public BranchOnEnumNode(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch)
     : base(id, context, nodeArch, groupArch)
 {
 }
Exemplo n.º 8
0
        /// <summary>
        /// Updates the filter.
        /// </summary>
        /// <param name="filterText">The filter text.</param>
        public void UpdateFilter(string filterText)
        {
            if (string.IsNullOrWhiteSpace(filterText))
            {
                // Clear filter
                _highlights?.Clear();
                Visible = true;
            }
            else
            {
                object[] data;

                QueryFilterHelper.Range[] ranges;
                if (QueryFilterHelper.Match(filterText, _archetype.Title, out ranges))
                {
                    // Update highlights
                    if (_highlights == null)
                    {
                        _highlights = new List <Rectangle>(ranges.Length);
                    }
                    else
                    {
                        _highlights.Clear();
                    }
                    var style = Style.Current;
                    var font  = style.FontSmall;
                    for (int i = 0; i < ranges.Length; i++)
                    {
                        var start = font.GetCharPosition(_archetype.Title, ranges[i].StartIndex);
                        var end   = font.GetCharPosition(_archetype.Title, ranges[i].EndIndex);
                        _highlights.Add(new Rectangle(start.X + 2, 0, end.X - start.X, Height));
                    }
                    Visible = true;
                }
                else if (_archetype.AlternativeTitles?.Any(filterText.Equals) == true)
                {
                    // Update highlights
                    if (_highlights == null)
                    {
                        _highlights = new List <Rectangle>(1);
                    }
                    else
                    {
                        _highlights.Clear();
                    }
                    var style = Style.Current;
                    var font  = style.FontSmall;
                    var start = font.GetCharPosition(_archetype.Title, 0);
                    var end   = font.GetCharPosition(_archetype.Title, _archetype.Title.Length - 1);
                    _highlights.Add(new Rectangle(start.X + 2, 0, end.X - start.X, Height));
                    Visible = true;
                }
                else if (NodeArchetype.TryParseText != null && NodeArchetype.TryParseText(filterText, out data))
                {
                    // Update highlights
                    if (_highlights == null)
                    {
                        _highlights = new List <Rectangle>(1);
                    }
                    else
                    {
                        _highlights.Clear();
                    }
                    var style = Style.Current;
                    var font  = style.FontSmall;
                    var start = font.GetCharPosition(_archetype.Title, 0);
                    var end   = font.GetCharPosition(_archetype.Title, _archetype.Title.Length - 1);
                    _highlights.Add(new Rectangle(start.X + 2, 0, end.X - start.X, Height));
                    Visible = true;

                    Data = data;
                }
                else
                {
                    // Hide
                    _highlights?.Clear();
                    Visible = false;
                }
            }
        }
Exemplo n.º 9
0
 /// <inheritdoc />
 public SurfaceNodeParamsGetVisualScript(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch)
     : base(id, context, nodeArch, groupArch)
 {
     Prototypes = null;
 }
Exemplo n.º 10
0
 /// <inheritdoc />
 public ParticleAttributeNode(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch)
     : base(id, context, nodeArch, groupArch)
 {
 }
Exemplo n.º 11
0
 /// <inheritdoc />
 public ParticleEmitterFunctionNode(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch)
     : base(id, context, nodeArch, groupArch)
 {
 }
Exemplo n.º 12
0
 /// <inheritdoc />
 public ColorGradientNode(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch)
     : base(id, context, nodeArch, groupArch)
 {
 }
Exemplo n.º 13
0
        /// <summary>
        /// Updates the surface parameters group.
        /// </summary>
        private void UpdateSurfaceParametersGroup()
        {
            Profiler.BeginEvent("VisjectCM.UpdateSurfaceParametersGroup");

            // Remove the old one
            if (_surfaceParametersGroup != null)
            {
                _groups.Remove(_surfaceParametersGroup);
                _surfaceParametersGroup.Dispose();
                _surfaceParametersGroup = null;
            }

            // Check if surface has any parameters
            var parameters = _parametersGetter?.Invoke();
            int count      = parameters?.Count(x => x.IsPublic) ?? 0;

            if (count > 0)
            {
                // TODO: cache the allocated memory to reduce dynamic allocations
                if (_parameterSetNodeArchetype != null)
                {
                    count *= 2;
                }
                var archetypes     = new NodeArchetype[count];
                int archetypeIndex = 0;

                // ReSharper disable once PossibleNullReferenceException
                for (int i = 0; i < parameters.Count; i++)
                {
                    var param = parameters[i];
                    if (!param.IsPublic)
                    {
                        continue;
                    }

                    var node = (NodeArchetype)_parameterGetNodeArchetype.Clone();
                    node.Title                   = "Get " + param.Name;
                    node.DefaultValues[0]        = param.ID;
                    archetypes[archetypeIndex++] = node;

                    if (_parameterSetNodeArchetype != null)
                    {
                        node                         = (NodeArchetype)_parameterSetNodeArchetype.Clone();
                        node.Title                   = "Set " + param.Name;
                        node.DefaultValues[0]        = param.ID;
                        node.DefaultValues[1]        = TypeUtils.GetDefaultValue(param.Type);
                        archetypes[archetypeIndex++] = node;
                    }
                }

                var groupArchetype = new GroupArchetype
                {
                    GroupID    = 6,
                    Name       = "Surface Parameters",
                    Color      = new Color(52, 73, 94),
                    Archetypes = archetypes
                };

                var group = new VisjectCMGroup(this, groupArchetype)
                {
                    HeaderText = groupArchetype.Name
                };

                group.Close(false);
                archetypeIndex = 0;
                for (int i = 0; i < parameters.Count; i++)
                {
                    var param = parameters[i];
                    if (!param.IsPublic)
                    {
                        continue;
                    }

                    var item = new VisjectCMItem(group, groupArchetype, archetypes[archetypeIndex++])
                    {
                        Parent = group
                    };

                    if (_parameterSetNodeArchetype != null)
                    {
                        item = new VisjectCMItem(group, groupArchetype, archetypes[archetypeIndex++])
                        {
                            Parent = group
                        };
                    }
                }
                group.SortChildren();
                group.UnlockChildrenRecursive();
                group.Parent = _groupsPanel;
                _groups.Add(group);
                _surfaceParametersGroup = group;
            }

            Profiler.EndEvent();
        }
Exemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VisjectCM"/> class.
        /// </summary>
        /// <param name="info">The initialization info data.</param>
        public VisjectCM(InitInfo info)
        {
            if (info.Groups == null)
            {
                throw new ArgumentNullException(nameof(info.Groups));
            }
            if (info.CanSpawnNode == null)
            {
                throw new ArgumentNullException(nameof(info.CanSpawnNode));
            }
            _parametersGetter          = info.ParametersGetter;
            _parameterGetNodeArchetype = info.ParameterGetNodeArchetype ?? Archetypes.Parameters.Nodes[0];
            if (info.CanSetParameters)
            {
                _parameterSetNodeArchetype = info.ParameterSetNodeArchetype ?? Archetypes.Parameters.Nodes[3];
            }

            // Context menu dimensions
            Size = new Vector2(320, 220);

            // Search box
            _searchBox = new TextBox(false, 1, 1)
            {
                Width         = Width - 3,
                WatermarkText = "Search...",
                Parent        = this
            };
            _searchBox.TextChanged += OnSearchFilterChanged;

            // Create first panel (for scrollbar)
            var panel1 = new Panel(ScrollBars.Vertical)
            {
                Bounds = new Rectangle(0, _searchBox.Bottom + 1, Width, Height - _searchBox.Bottom - 2),
                Parent = this
            };

            _panel1 = panel1;

            // Create second panel (for groups arrangement)
            var panel2 = new VerticalPanel
            {
                Parent       = panel1,
                AnchorPreset = AnchorPresets.HorizontalStretchTop,
                IsScrollable = true,
            };

            _groupsPanel = panel2;

            // Init groups
            var nodes = new List <NodeArchetype>();

            foreach (var groupArchetype in info.Groups)
            {
                // Get valid nodes
                nodes.Clear();
                foreach (var nodeArchetype in groupArchetype.Archetypes)
                {
                    if ((nodeArchetype.Flags & NodeFlags.NoSpawnViaGUI) == 0 && info.CanSpawnNode(nodeArchetype))
                    {
                        nodes.Add(nodeArchetype);
                    }
                }

                // Check if can create group for them
                if (nodes.Count > 0)
                {
                    var group = new VisjectCMGroup(this, groupArchetype)
                    {
                        HeaderText = groupArchetype.Name
                    };

                    group.Close(false);
                    for (int i = 0; i < nodes.Count; i++)
                    {
                        var item = new VisjectCMItem(group, groupArchetype, nodes[i])
                        {
                            Parent = group
                        };
                    }
                    group.SortChildren();
                    group.Parent = panel2;

                    _groups.Add(group);
                }
            }

            // Add custom nodes (special handling)
            if (info.CustomNodesGroup?.Archetypes != null)
            {
                foreach (var nodeArchetype in info.CustomNodesGroup.Archetypes)
                {
                    if ((nodeArchetype.Flags & NodeFlags.NoSpawnViaGUI) != 0)
                    {
                        continue;
                    }

                    var groupName = Archetypes.Custom.GetNodeGroup(nodeArchetype);

                    // Find group to reuse
                    VisjectCMGroup group = null;
                    for (int j = 0; j < _groups.Count; j++)
                    {
                        if (string.Equals(_groups[j].Archetype.Name, groupName, StringComparison.OrdinalIgnoreCase))
                        {
                            group = _groups[j];
                            break;
                        }
                    }

                    // Create new group if name is unique
                    if (group == null)
                    {
                        group = new VisjectCMGroup(this, info.CustomNodesGroup)
                        {
                            HeaderText = groupName
                        };

                        group.Close(false);
                        group.Parent = _groupsPanel;
                        _groups.Add(group);
                    }

                    // Add new item
                    var item = new VisjectCMItem(group, info.CustomNodesGroup, nodeArchetype)
                    {
                        Parent = group
                    };

                    // Order items
                    group.SortChildren();
                }
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Updates the surface parameters group.
        /// </summary>
        private void UpdateSurfaceParametersGroup()
        {
            // Remove the old one
            if (_surfaceParametersGroup != null)
            {
                _groups.Remove(_surfaceParametersGroup);
                _surfaceParametersGroup.Dispose();
                _surfaceParametersGroup = null;
            }

            // Check if surface has any parameters
            var parameters = _parametersGetter();
            int count      = parameters?.Count(x => x.IsPublic) ?? 0;

            if (count > 0)
            {
                // TODO: cache the allocated memory to reduce dynamic allocations
                var archetypes     = new NodeArchetype[count];
                int archetypeIndex = 0;
                for (int i = 0; i < parameters.Count; i++)
                {
                    if (!parameters[i].IsPublic)
                    {
                        continue;
                    }

                    archetypes[archetypeIndex++] = new NodeArchetype
                    {
                        TypeID        = 1,
                        Create        = Archetypes.Parameters.CreateGetNode,
                        Title         = "Get " + parameters[i].Name,
                        Description   = "Parameter value getter",
                        Size          = new Vector2(140, 60),
                        DefaultValues = new object[]
                        {
                            parameters[i].ID
                        },
                        Elements = new[]
                        {
                            NodeElementArchetype.Factory.ComboBox(2, 0, 116)
                        }
                    };
                }
                var groupArchetype = new GroupArchetype
                {
                    GroupID    = 6,
                    Name       = "Surface Parameters",
                    Color      = new Color(52, 73, 94),
                    Archetypes = archetypes
                };
                var group = new VisjectCMGroup(this, groupArchetype);
                group.Close(false);
                archetypeIndex = 0;
                for (int i = 0; i < parameters.Count; i++)
                {
                    if (!parameters[i].IsPublic)
                    {
                        continue;
                    }

                    var item = new VisjectCMItem(group, archetypes[archetypeIndex++]);
                    item.Parent = group;
                }
                group.SortChildren();
                group.UnlockChildrenRecursive();
                group.Parent = _panel2;
                _groups.Add(group);
                _surfaceParametersGroup = group;
            }
        }
Exemplo n.º 16
0
 /// <inheritdoc />
 public SurfaceNodeParamsSet(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch)
     : base(id, context, nodeArch, groupArch)
 {
 }
Exemplo n.º 17
0
 /// <inheritdoc />
 public SurfaceNodeParamsGet(uint id, VisjectSurface surface, NodeArchetype nodeArch, GroupArchetype groupArch)
     : base(id, surface, nodeArch, groupArch)
 {
 }
Exemplo n.º 18
0
 /// <inheritdoc />
 public MaterialFunctionNode(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch)
     : base(id, context, nodeArch, groupArch)
 {
 }