Esempio n. 1
0
        public override void Visit(ref CCAffineTransform parentWorldTransform)
        {
            if (Stencil == null || !Stencil.Visible)
            {
                if (Inverted)
                {
                    // draw everything
                    base.Visit(ref parentWorldTransform);
                }
                return;
            }

            if (Window.DrawManager.BeginDrawMask(Viewport.ViewportInPixels, Inverted, AlphaThreshold))
            {
                Window.DrawManager.PushMatrix();;

                Stencil.Visit(ref parentWorldTransform);

                Window.DrawManager.PopMatrix();

                Window.DrawManager.EndDrawMask();

                base.Visit(ref parentWorldTransform);

                Window.DrawManager.EndMask();
            }
            else
            {
                base.Visit(ref parentWorldTransform);
            }
        }
Esempio n. 2
0
        void Update()
        {
            if (m_Store == null)
            {
                return;
            }

            m_Store.GetState().EditorDataModel.UpdateCounter++;
            m_Store.Update();

            IGraphModel currentGraphModel             = m_Store.GetState().CurrentGraphModel;
            Stencil     currentStencil                = currentGraphModel?.Stencil;
            bool        stencilRecompilationRequested = currentStencil != null && currentStencil.RecompilationRequested;

            if (stencilRecompilationRequested ||
                Preferences.GetBool(VSPreferences.BoolPref.AutoRecompile) &&
                _compilationTimer.ElapsedMilliseconds >= (EditorApplication.isPlaying
                                                          ? k_IdleTimeBeforeCompilationSecondsPlayMode
                                                          : k_IdleTimeBeforeCompilationSeconds) * 1000)
            {
                if (currentStencil != null && stencilRecompilationRequested)
                {
                    currentStencil.RecompilationRequested = false;
                }

                _compilationTimer.Stop(DataModel);
                m_CompilationPendingLabel.EnableInClassList(k_CompilationPendingClassName, false);

                OnCompilationRequest(RequestCompilationOptions.Default);
            }
        }
        public void TestWithConstants()
        {
            var filter = new SearcherFilter(SearcherContext.Graph).WithConstants();
            var data   = new TypeSearcherItemData(Stencil.GenerateTypeHandle(typeof(string)), SearcherItemTarget.Constant);

            Assert.IsTrue(filter.ApplyFilters(data));
        }
Esempio n. 4
0
        public static Type InferReturnType(Stencil stencil, MethodBase methodBase, Type[] genericTypes, TypeHandle[] solvedTypeArguments, Type dataType)
        {
            Type returnType = methodBase.GetReturnType();

            if (returnType == typeof(void) || !returnType.ContainsGenericParameters)
            {
                return(null);
            }

            Type       genericType   = genericTypes.SingleOrDefault();
            TypeHandle solvedType    = solvedTypeArguments.SingleOrDefault();
            Type       newOutputType = null;

            if (returnType == genericType) // T F<T>() == T
            {
                newOutputType = solvedType.Resolve(stencil);
            }
            else if (returnType.IsGenericType)                                                                  // List<T> F<T>()
            {
                if (returnType.IsConstructedGenericType && returnType.GenericTypeArguments[0] == genericType || // class C<T> { List<T> F() }
                    !returnType.IsConstructedGenericType && returnType.GetGenericArguments()[0] == genericType) // class C { List<T> F<T>() }
                {
                    newOutputType = dataType.GetGenericTypeDefinition().MakeGenericType(solvedType.Resolve(stencil));
                }
            }

            return(newOutputType);
        }
Esempio n. 5
0
        public CompilationResult Compile(AssemblyType assemblyType, ITranslator translator, CompilationOptions compilationOptions, IEnumerable <IPluginHandler> pluginHandlers = null)
        {
            Stencil.PreProcessGraph(this);
            CompilationResult result;

            try
            {
                result = translator.TranslateAndCompile(this, assemblyType, compilationOptions);

                if (result.status == CompilationStatus.Failed)
                {
                    Stencil.OnCompilationFailed(this, result);
                }
                else
                {
                    Stencil.OnCompilationSucceeded(this, result);
                }
            }
            catch (Exception e)
            {
                result = null;
                Debug.LogException(e);
            }

            return(result);
        }
Esempio n. 6
0
 static EcsSearcherFilter GetComponentsSearcherFilter(Stencil stencil)
 {
     return(new EcsSearcherFilter(SearcherContext.Type)
            .WithComponentData(stencil)
            .WithGameObjectComponents(stencil)
            .WithSharedComponentData(stencil));
 }
        public static void TypeEditor(this Stencil stencil, TypeHandle typeHandle, Action <TypeHandle, int> onSelection,
                                      SearcherFilter filter = null, TypeOptions options = TypeOptions.None)
        {
            var missingTypeReference = TypeHandle.MissingType;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Type");

            var selected = EditorGUILayout.DropdownButton(new GUIContent(typeHandle != missingTypeReference ? typeHandle.GetMetadata(stencil).FriendlyName : "<unknown type>"), FocusType.Passive, GUI.skin.button);

            if (Event.current.type == EventType.Repaint)
            {
                s_ButtonRect = GUILayoutUtility.GetLastRect();
            }

            if (selected)
            {
                SearcherService.ShowTypes(
                    stencil,
                    EditorWindow.focusedWindow.rootVisualElement.LocalToWorld(s_ButtonRect.center),
                    onSelection,
                    filter
                    );
            }
            EditorGUILayout.EndHorizontal();
        }
Esempio n. 8
0
        public void SetUp()
        {
            m_Window  = EditorWindow.GetWindowWithRect <VseWindow>(new Rect(Vector2.zero, new Vector2(800, 600)));
            m_Stencil = new ClassStencil();

            var assetModel = ScriptableObject.CreateInstance <VSGraphAssetModel>();
            var graphModel = assetModel.CreateGraph <VSGraphModel>("test", typeof(ClassStencil), false);

            var portModelMock = new Mock <IPortModel>();

            portModelMock.Setup(x => x.GraphModel).Returns(graphModel);
            portModelMock.Setup(x => x.PortType).Returns(PortType.Event);
            portModelMock.Setup(x => x.Direction).Returns(Direction.Input);
            portModelMock.Setup(x => x.Name).Returns("port");
            portModelMock.Setup(x => x.DataType).Returns(typeof(float).GenerateTypeHandle(m_Stencil));
            m_Port = Port.Create(portModelMock.Object, m_Window.Store, Orientation.Horizontal);

            VariableDeclarationModel intVariableModel = graphModel.CreateGraphVariableDeclaration(
                "int", typeof(int).GenerateTypeHandle(m_Stencil), false
                );
            VariableDeclarationModel stringVariableModel = graphModel.CreateGraphVariableDeclaration(
                "string", typeof(string).GenerateTypeHandle(m_Stencil), false
                );

            m_IntField    = new BlackboardVariableField(m_Window.Store, intVariableModel, m_Window.GraphView);
            m_StringField = new BlackboardVariableField(m_Window.Store, stringVariableModel, m_Window.GraphView);

            m_IntTokenModel = Activator.CreateInstance <VariableNodeModel>();
            m_IntTokenModel.DeclarationModel = intVariableModel;
            m_IntTokenModel.AssetModel       = assetModel;

            m_StringTokenModel = Activator.CreateInstance <VariableNodeModel>();
            m_StringTokenModel.DeclarationModel = stringVariableModel;
            m_StringTokenModel.AssetModel       = assetModel;
        }
Esempio n. 9
0
        void Update()
        {
            if (m_Store == null)
            {
                return;
            }

            m_Store.GetState().EditorDataModel.UpdateCounter++;
            m_Store.Update();

            IGraphModel currentGraphModel             = m_Store.GetState().CurrentGraphModel;
            Stencil     currentStencil                = currentGraphModel?.Stencil;
            bool        stencilRecompilationRequested = currentStencil && currentStencil.RecompilationRequested;

            if (stencilRecompilationRequested ||
                m_IdleTimer != null && Preferences.GetBool(VSPreferences.BoolPref.AutoRecompile) &&
                m_IdleTimer.ElapsedMilliseconds >= k_IdleTimeBeforeCompilationSeconds * 1000)
            {
                if (currentStencil && stencilRecompilationRequested)
                {
                    currentStencil.RecompilationRequested = false;
                }

                m_IdleTimer?.Stop();

                m_IdleTimer = null;
                OnCompilationRequest(RequestCompilationOptions.Default);
            }

            if (EditorApplication.isPlaying && !EditorApplication.isPaused)
            {
                m_Store.GetState().currentTracingFrame = Time.frameCount;
                m_Menu.UpdateUI();
            }
        }
        public static void ConstantEditorGUI(SerializedObject o, GUIContent label, Stencil stencil,
                                             ConstantEditorMode mode = ConstantEditorMode.ValueOnly, Action onChange = null)
        {
//            if (!(o.targetObject is AbstractNodeAsset asset))
//                return;

//            switch (asset.Model)
//            {
//                case ConstantNodeModel constantNodeModel when constantNodeModel.IsLocked:
//                    return;
//
//                case EnumConstantNodeModel enumModel:
//                {
//                    if (mode != ConstantEditorMode.ValueOnly)
//                    {
//                        var filter = new SearcherFilter(SearcherContext.Type).WithEnums(stencil);
//                        stencil.TypeEditor(enumModel.value.EnumType,
//                            (type, index) =>
//                            {
//                                enumModel.value.EnumType = type;
//                                onChange?.Invoke();
//                            }, filter);
//                    }
//                    enumModel.value.Value = Convert.ToInt32(EditorGUILayout.EnumPopup("Value", enumModel.EnumValue));
//                    break;
//                }
//
//                default:
//                    EditorGUILayout.PropertyField(o.FindProperty("m_NodeModel.value"), label, true);
//                    break;
//            }
        }
Esempio n. 11
0
 public TypeSearcherDatabase(Stencil stencil, List <ITypeMetadata> typesMetadata)
 {
     m_Stencil           = stencil;
     m_TypesMetadata     = typesMetadata;
     m_Registrations     = new List <Action <List <SearcherItem> > >();
     m_MetaRegistrations = new List <Func <List <SearcherItem>, ITypeMetadata, bool> >();
 }
Esempio n. 12
0
        public void InitBasicGraph(VSGraphModel graph)
        {
            Stencil stencil = graph.Stencil;

            AssetDatabase.SaveAssets();

            var method = graph.CreateFunction("method", Vector2.left * 200);

            method.CreateFunctionVariableDeclaration("l", typeof(int).GenerateTypeHandle(stencil));
            method.CreateAndRegisterFunctionParameterDeclaration("a", typeof(int).GenerateTypeHandle(stencil));

            var log = method.CreateFunctionCallNode(TypeSystem.GetMethod(typeof(Debug), nameof(Debug.Log), true));
            var abs = graph.CreateFunctionCallNode(TypeSystem.GetMethod(typeof(Mathf), "Abs", true), new Vector2(-350, 100));

            graph.CreateEdge(log.GetParameterPorts().First(), abs.OutputPort);

            var xDecl  = graph.CreateGraphVariableDeclaration("x", typeof(float).GenerateTypeHandle(stencil), true);
            var xUsage = graph.CreateVariableNode(xDecl, new Vector2(-450, 100));

            graph.CreateEdge(abs.GetParameterPorts().First(), xUsage.OutputPort);

            var stack001 = graph.CreateStack(string.Empty, new Vector2(-200, 300));

            stack001.CreateFunctionCallNode(TypeSystem.GetMethod(typeof(Debug), "Log", true));

            var method2 = graph.CreateFunction("method2", Vector2.left * 800);

            method2.CreateFunctionRefCallNode(method);
        }
        static IPortModel GetFirstPortModelOfType(TypeHandle typeHandle, IEnumerable <IPortModel> portModels, bool fallbackToFirstPort)
        {
            Stencil    stencil          = portModels.First().VSGraphModel.Stencil;
            IPortModel unknownPortModel = null;

            // Return the first matching Input portModel
            // If no match was found, return the first Unknown typed portModel
            // Else return null.
            foreach (IPortModel portModel in portModels)
            {
                if (portModel.DataTypeHandle == TypeHandle.Unknown && unknownPortModel == null)
                {
                    unknownPortModel = portModel;
                }

                if (typeHandle.IsAssignableFrom(portModel.DataTypeHandle, stencil))
                {
                    return(portModel);
                }
            }

            if (unknownPortModel != null)
            {
                return(unknownPortModel);
            }
            return(fallbackToFirstPort ? portModels.FirstOrDefault() : null);
        }
Esempio n. 14
0
        public void TestFunctionMembers(string query, Type type, SpawnFlags mode)
        {
            var funcModel = GraphModel.CreateFunction("TestFunc", Vector2.zero);

            funcModel.CreateFunctionVariableDeclaration("var", typeof(int).GenerateTypeHandle(GraphModel.Stencil));
            funcModel.CreateAndRegisterFunctionParameterDeclaration("par", typeof(string).GenerateTypeHandle(GraphModel.Stencil));

            var db = new GraphElementSearcherDatabase(Stencil)
                     .AddFunctionMembers(funcModel)
                     .Build();

            var results = db.Search(query, out _);

            Assert.AreEqual(1, results.Count);

            var item = (GraphNodeModelSearcherItem)results[0];
            var data = (TypeSearcherItemData)item.Data;

            Assert.AreEqual(SearcherItemTarget.Variable, data.Target);
            Assert.AreEqual(Stencil.GenerateTypeHandle(type), data.Type);

            CreateNodesAndValidateGraphModel(item, mode, initialNodes =>
            {
                var node = GraphModel.NodeModels.OfType <VariableNodeModel>().FirstOrDefault();
                Assert.IsNotNull(node);
                Assert.AreEqual(initialNodes.Count + 1, GraphModel.NodeModels.Count);
                Assert.AreEqual(type, node.DataType.Resolve(Stencil));
            });
        }
        public BlackboardVariablePropertyView(Store store, IVariableDeclarationModel variableDeclarationModel,
                                              Blackboard.RebuildCallback rebuildCallback, Stencil stencil)
            : base(variableDeclarationModel, rebuildCallback)
        {
            m_Store   = store;
            m_Stencil = stencil;

            RegisterCallback <AttachToPanelEvent>(OnAttachToPanel);
            RegisterCallback <DetachFromPanelEvent>(OnDetachFromPanel);

            if (variableDeclarationModel.VariableType != VariableType.FunctionVariable &&
                variableDeclarationModel.VariableType != VariableType.GraphVariable)
            {
                return;
            }

            if (!variableDeclarationModel.InitializationModel?.NodeAssetReference)
            {
                if (stencil.GetVariableInitializer().RequiresInitialization(variableDeclarationModel))
                {
                    m_InitializationElement = new Button(OnInitializationButton)
                    {
                        text = "Create Init value"
                    };
                    m_InitializationElement.AddToClassList("rowButton");
                }
            }
            else
            {
                m_InitializationObject = new SerializedObject(variableDeclarationModel.InitializationModel.NodeAssetReference);
                m_InitializationObject.Update();
                m_InitializationElement = new IMGUIContainer(OnInitializationGUI);
            }
        }
        public void AnimateShowForm(string caption, int x, int y, Stencil stencil)
        {
            if (stencil.rgImages.Count > 0)
            {
                this.Left		= x;
                this.Top		= y;
                this.Width		= 204;
                this.Height		= ((int)Math.Ceiling((float)(stencil.rgImages.Count / 5.0))) * 40 + 3 + this.Font.Height;
                this.m_caption	= caption;
                this.m_stencil	= stencil;
                this.m_MouseX	= 0;
                this.m_MouseY	= 0;

                if (this.Bottom > Screen.PrimaryScreen.Bounds.Bottom)
                {
                    this.Top = Screen.PrimaryScreen.Bounds.Bottom - this.Height;
                }

                if (this.Right > Screen.PrimaryScreen.Bounds.Right)
                {
                    this.Left = Screen.PrimaryScreen.Bounds.Right - this.Width;
                }

                this.Refresh();

                if (this.HideOnDeactivated)
                {
                    this.Activate();
                }
            }
            else
            {
                HideForm();
            }
        }
Esempio n. 17
0
        public CriteriaSubSection(Stencil stencil,
                                  IReadOnlyCollection <ComponentQueryDeclarationModel> componentQueryDeclarationModels,
                                  Blackboard blackboard)
            : base("Criteria",
                   graphElementModel: null,
                   store: blackboard.Store,
                   parentElement: null,
                   rebuildCallback: null,
                   canAcceptDrop: null)
        {
            m_Stencil    = stencil;
            m_Blackboard = blackboard;

            name     = "criteriaSection";
            userData = name;

            AddToClassList("subSection");

            int nbRows = 0;

            foreach (var componentQueryDeclarationModel in componentQueryDeclarationModels)
            {
                BuildCriteriaForComponentQuery(componentQueryDeclarationModel, ref nbRows, blackboard);
            }

            viewDataKey = "BlackboardCriteriaSection";

            OnExpanded = e => Store.GetState().EditorDataModel?.ExpandBlackboardRowsUponCreation(
                new[] { $"{ComponentQueriesRow.BlackboardEcsProviderTypeName}/{GetType().Name}" }, e);

            SectionTitle.text += " (" + nbRows + ")";
        }
Esempio n. 18
0
        private IStencil Parse(IToken token)
        {
            var stencil = new Stencil();

            _currentSpace = stencil;
            var streamReader = new StreamReader(TemplateStream);

            var buffer = new StringBuilder();

            Reset(buffer, token);

            while (!streamReader.EndOfStream)
            {
                var currentCharacter = (char)streamReader.Read();
                buffer.Append(currentCharacter);

                var result = ProcessBuffer(buffer);

                switch (result.Type)
                {
                case TokenType.Simple:
                case TokenType.Interpolation:
                    AddPositiveSpace(_currentSpace, result.Payload);
                    _currentSpace.Add(result.Token.CreateSpace());
                    Reset(buffer);
                    break;

                case TokenType.Complex:
                    AddPositiveSpace(_currentSpace, result.Payload);
                    var complexSpace = result.Token.CreateSpace();
                    _currentSpace.Add(complexSpace);
                    TokenStack.Push(result);
                    SpaceStack.Push(complexSpace);
                    _currentSpace = complexSpace;
                    Reset(buffer, result.Token);
                    break;

                case TokenType.Terminator:
                    AddPositiveSpace(_currentSpace, result.Payload);
                    TokenStack.Pop();
                    SpaceStack.Pop();
                    _currentSpace = (object)SpaceStack.FirstOrDefault() ?? stencil;
                    Reset(buffer, TokenStack.Select(t => t.Token).FirstOrDefault() ?? token);
                    break;

                default:
                    break;
                }
            }

            AddPositiveSpace(stencil, buffer.ToString());

            TemplateStream     = null;
            TokenStack         = null;
            SpaceStack         = null;
            _prospectiveTokens = null;

            return(stencil);
        }
Esempio n. 19
0
        public void TestTypeSearcherItemUnityObject()
        {
            Stencil stencil = ScriptableObject.CreateInstance <TestStencil>();
            var     item    = new TypeSearcherItem(typeof(Object).GenerateTypeHandle(stencil), "UnityEngine.Object");

            Assert.AreEqual(item.Type, typeof(Object).GenerateTypeHandle(stencil));
            Assert.AreEqual(item.Name, "UnityEngine.Object");
        }
Esempio n. 20
0
 public virtual void AddStencil(Stencil stencil)
 {
     Suspend();
     AddStencilImplementation(stencil);
     ArrangeImplementation(50, 50);
     Resume();
     Invalidate();
 }
Esempio n. 21
0
        public void TestTypeSearcherItemString()
        {
            Stencil stencil = ScriptableObject.CreateInstance <TestStencil>();
            var     item    = new TypeSearcherItem(typeof(string).GenerateTypeHandle(stencil), typeof(string).FriendlyName());

            Assert.AreEqual(item.Type, typeof(string).GenerateTypeHandle(stencil));
            Assert.AreEqual(item.Name, typeof(string).FriendlyName());
        }
Esempio n. 22
0
 public override void OnExit()
 {
     if (Stencil != null)
     {
         Stencil.OnExit();
     }
     base.OnExit();
 }
Esempio n. 23
0
 public static MemberInfoValue ToMemberInfoValue(this MemberInfo mi, Stencil stencil)
 {
     return(new MemberInfoValue(
                mi.DeclaringType.GenerateTypeHandle(stencil),
                mi.GetUnderlyingType().GenerateTypeHandle(stencil),
                mi.Name,
                mi.MemberType));
 }
        public void TearDown()
        {
            if (m_Window != null)
            {
                m_Window.Close();
            }

            m_Stencil = null;
        }
Esempio n. 25
0
        public void TestHasValidOperationForInput(Type dataType, UnaryOperatorKind kind, bool result)
        {
            var node = Activator.CreateInstance <UnaryOperatorNodeModel>();

            node.GraphModel = GraphModel;
            node.kind       = kind;

            Assert.AreEqual(result, node.HasValidOperationForInput(null, Stencil.GenerateTypeHandle(dataType)));
        }
Esempio n. 26
0
        public override void OnEnterTransitionDidFinish()
        {
            base.OnEnterTransitionDidFinish();

            if (Stencil != null)
            {
                Stencil.OnEnterTransitionDidFinish();
            }
        }
Esempio n. 27
0
        public override void OnExitTransitionDidStart()
        {
            if (Stencil != null)
            {
                Stencil.OnExitTransitionDidStart();
            }

            base.OnExitTransitionDidStart();
        }
Esempio n. 28
0
        public override void OnEnter()
        {
            base.OnEnter();

            if (Stencil != null)
            {
                Stencil.OnEnter();
            }
        }
Esempio n. 29
0
 public SearcherFilter WithTypesInheriting(Stencil stencil, Type type, Type attributeType = null)
 {
     this.RegisterType(data =>
     {
         var dataType = data.Type.Resolve(stencil);
         return(type.IsAssignableFrom(dataType) && (attributeType == null || dataType.GetCustomAttribute(attributeType) != null));
     });
     return(this);
 }
Esempio n. 30
0
 public virtual void AddStencil(Stencil stencil)
 {
     Suspend();
     CreateRenderList(new RectangleF(), true);
     AddStencilImplementation(stencil);
     ArrangeImplementation(50, 50);
     Resume();
     Invalidate();
 }
Esempio n. 31
0
        public TokenDeclaration(Store store, IVariableDeclarationModel model, GraphView graphView)
        {
            m_Pill = new Pill();
            Add(m_Pill);

            if (model is IObjectReference modelReference)
            {
                if (modelReference is IExposeTitleProperty titleProperty)
                {
#if UNITY_2019_3_OR_NEWER
                    m_TitleLabel = m_Pill.Q <Label>("title-label");
#else
                    m_TitleLabel = m_Pill.Q <Label>("title-label").ReplaceWithBoundLabel();
#endif
                    m_TitleLabel.bindingPath = titleProperty.TitlePropertyName;
                }
            }

            styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(UICreationHelper.templatePath + "Token.uss"));

            Declaration = model;
            m_Store     = store;
            m_GraphView = graphView;

            m_Pill.icon = Declaration.IsExposed
                ? VisualScriptingIconUtility.LoadIconRequired("GraphView/Nodes/BlackboardFieldExposed.png")
                : null;

            m_Pill.text = Declaration.Title;

            if (model != null)
            {
                capabilities = VseUtility.ConvertCapabilities(model);
            }

            var     variableModel = model as VariableDeclarationModel;
            Stencil stencil       = store.GetState().CurrentGraphModel?.Stencil;
            if (variableModel != null && stencil != null && variableModel.DataType.IsValid)
            {
                string friendlyTypeName = variableModel.DataType.GetMetadata(stencil).FriendlyName;
                Assert.IsTrue(!string.IsNullOrEmpty(friendlyTypeName));
                tooltip = $"{variableModel.VariableString} declaration of type {friendlyTypeName}";
                if (!string.IsNullOrEmpty(variableModel.Tooltip))
                {
                    tooltip += "\n" + variableModel.Tooltip;
                }
            }

            SetClasses();

            this.EnableRename();

            if (model != null)
            {
                viewDataKey = model.GetId();
            }
        }
Esempio n. 32
0
        public void TestNoneSingletons()
        {
            var options = new Options { UseSingletons = false };
            options.Assemblies.Add(typeof(StencilTest).Assembly);

            var stencil = new Stencil();
            stencil.Initilize(options);

            var one = stencil.Resolve<IBar>();
            var two = stencil.Resolve<IBar>();

            Assert.AreNotEqual(one, two);
        }
        public FloatSelectionForm()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            this.Left		= 0;
            this.Top		= 0;
            this.Width		= 0;
            this.Height		= 0;
            this.m_caption	= "";
            this.m_stencil	= null;

            this.HideOnDeactivated	= false;
            this.TemplateSelected	= null;
        }
        public void InitializeStencil(Stencil stencil)
        {
            ListViewItem item;

            lvStencil.Items.Clear();
            imgsStencil.Images.Clear();

            for (int i = 0; i < stencil.rgImages.Count; i++)
            {
                imgsStencil.Images.Add((Image)stencil.rgImages[i]);

                item			= new ListViewItem();
                item.Text		= stencil.rgTemplates[i].id;
                item.Tag		= stencil.rgTemplates[i];
                item.ImageIndex	= i;

                lvStencil.Items.Add(item);
            }

            m_stencil = stencil;
        }
Esempio n. 35
0
        private void m_catalog_StencilSelected(Stencil selectedStencil, string caption)
        {
            FloatControlLib.FloatItem	item;
            StencilForm					frmStencil;

            frmStencil			= new StencilForm();
            frmStencil.TopLevel = false;

            frmStencil.InitializeStencil(selectedStencil);
            frmStencil.TemplateSelected +=new TemplateSelectedEvent(frmStencil_TemplateSelected);

            item = fbMain.AddFloatWindow(frmStencil, imgsToolbox.Images[1], caption, 160, 100, true);

            if (fbMain.Width == 0)
            {
                fbMain.Width = m_floatBarWidth;
            }

            fbMain.AnimateShowFloatWindow(item);
        }
Esempio n. 36
0
		public virtual void AddStencil(Stencil stencil)
		{
			Suspend();
			CreateRenderList(new RectangleF(),true);
			AddStencilImplementation(stencil);
			ArrangeImplementation(50,50);
			Resume();
			Invalidate();
		}
Esempio n. 37
0
        /// <summary>
        /// Configures the rendering pipeline.
        /// </summary>
        /// <param name="cull">The polygon culling options.</param>
        /// <param name="depth">The depth processing options.</param>
        /// <param name="stencil">The stenciling mode.</param>
        /// <param name="blend">The blending mode.</param>
        public static void Use(Cull cull, Depth depth, Stencil stencil, Blend blend)
        {
            if (gl.HasPendingPops)
            {
                throw new InvalidOperationException("Cannot change GPU state while the attribute stack is active.");
            }

            if (currentCull != cull)
            {
                if (cull == Cull.None)
                {
                    gl.Disable(GL.CULL_FACE);
                }
                else
                {
                    gl.Enable(GL.CULL_FACE);

                    switch (cull)
                    {
                        case Cull.Front:
                            gl.CullFace(GL.FRONT);
                            break;

                        case Cull.Back:
                            gl.CullFace(GL.BACK);
                            break;

                        case Cull.Front | Cull.Back:
                            gl.CullFace(GL.FRONT_AND_BACK);
                            break;
                    }
                }

                currentCull = cull;
            }

            if (currentDepth != depth)
            {
                if (depth == Depth.None)
                {
                    gl.Disable(GL.DEPTH_TEST);
                }
                else
                {
                    gl.Enable(GL.DEPTH_TEST);

                    if ((depth & Depth.Test) == Depth.Test)
                    {
                        if ((depth & Depth.TestReversed) == Depth.TestReversed)
                        {
                            gl.DepthFunc(GL.GREATER);
                        }
                        else
                        {
                            gl.DepthFunc(GL.LEQUAL);
                        }
                    }
                    else
                    {
                        gl.DepthFunc(GL.ALWAYS);
                    }

                    if ((depth & Depth.Write) == Depth.Write)
                    {
                        gl.DepthMask(true);
                    }
                    else
                    {
                        gl.DepthMask(false);
                    }

                    if ((depth & Depth.Clamp) == Depth.Clamp)
                    {
                        gl.Enable(GL.DEPTH_CLAMP);
                    }
                    else
                    {
                        gl.Disable(GL.DEPTH_CLAMP);
                    }

                    if ((depth & Depth.Offset) == Depth.Offset)
                    {
                        gl.Enable(GL.POLYGON_OFFSET_FILL);
                        gl.PolygonOffset(0.02f, 0);
                    }
                    else
                    {
                        gl.Disable(GL.POLYGON_OFFSET_FILL);
                    }
                }

                currentDepth = depth;
            }

            if (currentStencil != stencil)
            {
                if (stencil == Stencil.None)
                {
                    gl.Disable(GL.STENCIL_TEST);
                }
                else
                {
                    gl.Enable(GL.STENCIL_TEST);

                    switch (stencil)
                    {
                        case Stencil.Shadows:
                            gl.StencilFunc(GL.FRONT_AND_BACK, GL.ALWAYS, 0, 0xFF);
                            gl.StencilOp(GL.FRONT, GL.KEEP, GL.INCR_WRAP, GL.KEEP); // <- increase when going in
                            gl.StencilOp(GL.BACK, GL.KEEP, GL.DECR_WRAP, GL.KEEP);  // <- decrease when going out
                            break;

                        case Stencil.Light:
                            gl.StencilFunc(GL.FRONT_AND_BACK, GL.EQUAL, 0, 0xFF);   // <- if (stencil != 0) { in shadow }
                            gl.StencilOp(GL.FRONT_AND_BACK, GL.KEEP, GL.KEEP, GL.KEEP);
                            break;
                    }
                }

                currentStencil = stencil;
            }

            if (currentBlend != blend)
            {
                if (blend == Blend.None)
                {
                    gl.Disable(GL.BLEND);
                }
                else
                {
                    gl.Enable(GL.BLEND);

                    switch (blend)
                    {
                        case Blend.Additive:
                            gl.BlendFunc(GL.ONE, GL.ONE, GL.ONE, GL.ONE);
                            break;

                        case Blend.Alpha:
                            gl.BlendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA, GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA);
                            break;
                    }
                }

                currentBlend = blend;
            }
        }
Esempio n. 38
0
		private void AddStencilImplementation(Stencil stencil)
		{
			Suspend();
			foreach(StencilItem item in stencil.Values)
			{
				Shape shape = new Shape(item);
				shape.Label = new TextLabel(item.Key);
				
				Shapes.Add(Shapes.CreateKey(),shape);
			}
			Resume();
		}