Пример #1
0
		public static Item ValueItems (RightClickExpose expose, Generator gen, Graph graph, int priority=2)
		/// chNum is a channel for vector fields
		{
			Item valItems = new Item("Value");
			valItems.onDraw = RightClick.DrawItem;
			valItems.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Value");
			valItems.color =  RightClick.defaultColor;
			valItems.subItems = new List<Item>();
			valItems.priority = priority;

			valItems.disabled = expose==null || gen==null;

			Item exposeItem = new Item("Expose", onDraw:RightClick.DrawItem, priority:6); 
			exposeItem.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/Expose");
			if (expose != null) exposeItem.onClick =
				() => { ExposeWindow.ShowWindow(graph, expose.id, expose.fieldName, expose.fieldType, expose.channel, expose.arrIndex); UI.current.editorWindow.Close(); };
			valItems.subItems.Add(exposeItem);

			Item unExposeItem = new Item("UnExpose", onDraw:RightClick.DrawItem, priority:6); 
			unExposeItem.icon = RightClick.texturesCache.GetTexture("MapMagic/Popup/UnExpose");
			if (expose != null) unExposeItem.onClick = //() => { if (gen.exposed==null) gen.exposed=new Exposed(); gen.exposed.ExposeField(valField); };
				() => 
				{
					//graph.exposed.Unexpose(gen, valField);
					graph.exposed.Remove(gen.id, expose.fieldName, expose.channel);
					GraphWindow.current.Focus();
					GraphWindow.current.Repaint();
				};
			valItems.subItems.Add(unExposeItem);

			return valItems;
		}
Пример #2
0
        public static bool ClickedNear(UI ui, Vector2 mousePos,
                                       out Group clickedGroup,
                                       out Generator clickedGen,
                                       out IInlet <object> clickedLink,
                                       out IInlet <object> clickedInlet,
                                       out IOutlet <object> clickedOutlet,
                                       out RightClickExpose clickedExpose)
        /// Returns the top clicked object (or null) in clickedGroup-to-clickedField priority
        {
            clickedGroup  = null;
            clickedGen    = null;
            clickedLink   = null;
            clickedInlet  = null;
            clickedOutlet = null;
            clickedExpose = null;

            List <Cell> cellsUnderCursor = new List <Cell>();

            ui.rootCell.FillCellsUnderCursor(cellsUnderCursor, mousePos);

            //checking cells
            for (int i = 0; i < cellsUnderCursor.Count; i++)
            {
                Cell cell = cellsUnderCursor[i];

                //GeneratorDraw.genCellLut.TryGetValue(cell, out clickedGen);  //TryGet will overwrite to null if not found

                if (ui.cellObjs.TryGetObject(cell, "Generator", out Generator gen))
                {
                    clickedGen = gen;
                }
                if (ui.cellObjs.TryGetObject(cell, "Group", out Group group))
                {
                    clickedGroup = group;
                }
                if (ui.cellObjs.TryGetObject(cell, "Inlet", out IInlet <object> inlet))
                {
                    clickedInlet = inlet;
                }
                if (ui.cellObjs.TryGetObject(cell, "Outlet", out IOutlet <object> outlet))
                {
                    clickedOutlet = outlet;
                }
                if (ui.cellObjs.TryGetObject(cell, "Expose", out RightClickExpose field))
                {
                    clickedExpose = field;
                }

                if (clickedGen != null && clickedOutlet == null && clickedGen is IOutlet <object> o)
                {
                    clickedOutlet = o;
                }
                //assigning outlet if clicked on single-outlet gen
            }

            //checking links
            float minDist = 10;             //10 pixels is max dist to link

            if (UI.current.scrollZoom != null)
            {
                minDist /= UI.current.scrollZoom.zoom;
            }
            foreach (var kvp in GraphWindow.current.graph.links)
            {
                float dist = GeneratorDraw.DistToLink(mousePos, kvp.Value, kvp.Key);
                if (dist < minDist)
                {
                    minDist = dist; clickedLink = kvp.Key;
                }
            }

            return(clickedGroup != null || clickedGen != null || clickedLink != null || clickedInlet != null || clickedOutlet != null || clickedExpose != null);
        }