Esempio n. 1
0
		private void DrawGraph () 
//			{using (Timer.Start("DrawGraph"))
		{
				//background
				#if MM_DOC
					float gridColor = 0.25f;
					float gridBackgroundColor = 0.25f;
				#else
					float gridColor = !StylesCache.isPro ? 0.45f : 0.14f; //0.135f; 
					float gridBackgroundColor = !StylesCache.isPro ? 0.5f : 0.16f; //0.16f;
				#endif

				Draw.StaticGrid(
					displayRect: new Rect(0, 0, Screen.width, Screen.height-toolbarSize),
					cellSize:32,
					color:new Color(gridColor,gridColor,gridColor), 
					background:new Color(gridBackgroundColor,gridBackgroundColor,gridBackgroundColor),
					fadeWithZoom:true);


				//drawing groups
				foreach (Group group in graph.groups)
					using (Cell.Custom(group.guiPos.x, group.guiPos.y, group.guiSize.x, group.guiSize.y))
					{
						GroupDraw.DragGroup(group, graph.generators);
						GroupDraw.DrawGroup(group);
					}


				//dragging nodes
				foreach (Generator gen in graph.generators)
					GeneratorDraw.DragGenerator(gen, selected);


				//drawing links
				//using (Timer.Start("Links"))
				if (!UI.current.layout)
				{
					List<(IInlet<object> inlet, IOutlet<object> outlet)> linksToRemove = null;
					foreach (var kvp in graph.links)
					{
						IInlet<object> inlet = kvp.Key;
						IOutlet<object> outlet = kvp.Value;

						Cell outletCell = UI.current.cellObjs.GetCell(outlet, "Outlet");
						Cell inletCell = UI.current.cellObjs.GetCell(inlet, "Inlet");

						if (outletCell == null || inletCell == null)
						{
							Debug.LogError("Could not find a cell for inlet/outlet. Removing link");
							if (linksToRemove == null) linksToRemove = new List<(IInlet<object> inlet, IOutlet<object> outlet)>();
							linksToRemove.Add((inlet,outlet));
							continue;
						}

						GeneratorDraw.DrawLink(
							GeneratorDraw.StartCellLinkpos(outletCell),
							GeneratorDraw.EndCellLinkpos(inletCell), 
							GeneratorDraw.GetLinkColor(inlet) );
					}

					if (linksToRemove != null)
						foreach ((IInlet<object> inlet, IOutlet<object> outlet) in linksToRemove)
						{
							graph.UnlinkInlet(inlet);
							graph.UnlinkOutlet(outlet);
						}
				}

				//removing null generators (for test purpose)
				for (int n=graph.generators.Length-1; n>=0; n--)
				{
					if (graph.generators[n] == null)
						ArrayTools.RemoveAt(ref graph.generators, n);
				}

				//drawing generators
				//using (Timer.Start("Generators"))
				foreach (Generator gen in graph.generators)
					using (Cell.Custom(gen.guiPosition.x, gen.guiPosition.y, GeneratorDraw.nodeWidth, 0))
					{
						if (gen is IPortalEnter<object> || gen is IPortalExit<object> || gen is IFunctionInput<object> || gen is IFunctionOutput<object>) 
							GeneratorDraw.DrawPortal(gen, graph, selected:selected.Contains(gen));

						else
						{
							try { GeneratorDraw.DrawGenerator(gen, graph, selected:selected.Contains(gen)); }
							catch (ExitGUIException)
								{ } //ignoring
							catch (Exception e) 
								{ Debug.LogError("Draw Graph Window failed: " + e); }
						}
					}

				//de-selecting nodes (after dragging and drawing since using drag obj)
				if (!UI.current.layout)
				{
					GeneratorDraw.SelectGenerators(selected);
					GeneratorDraw.DeselectGenerators(selected);
				}
				
				//add/remove button
				//using (Timer.Start("AddRemove"))
				using (Cell.Full)
					DragDrawAddRemove();

				//right click menu (should have access to cellObjs)
				if (!UI.current.layout  &&  Event.current.type == EventType.MouseDown  &&  Event.current.button == 1)
					RightClick.DrawRightClickItems(graphUI, graphUI.mousePos, graph);

				//create menu on space
				if (!UI.current.layout  &&  Event.current.type == EventType.KeyDown  &&  Event.current.keyCode == KeyCode.Space  && !Event.current.shift)
					CreateRightClick.DrawCreateItems(graphUI.mousePos, graph);

				//delete selected generators
				if (selected!=null  &&  selected.Count!=0  &&  Event.current.type==EventType.KeyDown  &&  Event.current.keyCode==KeyCode.Delete)
					GraphEditorActions.RemoveGenerators(graph, selected);
		}
Esempio n. 2
0
		private void DrawGraph ()
		{
			bool isMini = IsMini;

			//background
			float gridColor = !StylesCache.isPro ? 0.45f : 0.12f;
			float gridBackgroundColor = !StylesCache.isPro ? 0.5f : 0.15f;

			#if MM_DEBUG
				if (!graph.debugGraphBackground)
				{
					gridColor = graph.debugGraphBackColor;
					gridBackgroundColor = graph.debugGraphBackColor;
				}
			#endif

			Draw.StaticGrid(
				displayRect: new Rect(0, 0, Screen.width, Screen.height-toolbarSize),
				cellSize:32,
				color:new Color(gridColor,gridColor,gridColor), 
				background:new Color(gridBackgroundColor,gridBackgroundColor,gridBackgroundColor),
				fadeWithZoom:true);

			#if MM_DEBUG
				if (graph.drawInSceneView)
				{
					using (Cell.Full)
						DrawSceneView();
				}
			#endif

			//drawing groups
			foreach (Group group in graph.groups)
				using (Cell.Custom(group.guiPos.x, group.guiPos.y, group.guiSize.x, group.guiSize.y))
				{
					GroupDraw.DragGroup(group, graph.generators);
					GroupDraw.DrawGroup(group, isMini:isMini);
				}


			//dragging nodes
			foreach (Generator gen in graph.generators)
				GeneratorDraw.DragGenerator(gen, selected);


			//drawing links
			//using (Timer.Start("Links"))
			if (!UI.current.layout)
			{
				List<(IInlet<object> inlet, IOutlet<object> outlet)> linksToRemove = null;
				foreach (var kvp in graph.links)
				{
					IInlet<object> inlet = kvp.Key;
					IOutlet<object> outlet = kvp.Value;

					Cell outletCell = UI.current.cellObjs.GetCell(outlet, "Outlet");
					Cell inletCell = UI.current.cellObjs.GetCell(inlet, "Inlet");

					if (outletCell == null || inletCell == null)
					{
						Debug.LogError("Could not find a cell for inlet/outlet. Removing link");
						if (linksToRemove == null) linksToRemove = new List<(IInlet<object> inlet, IOutlet<object> outlet)>();
						linksToRemove.Add((inlet,outlet));
						continue;
					}

					GeneratorDraw.DrawLink(
						GeneratorDraw.StartCellLinkpos(outletCell),
						GeneratorDraw.EndCellLinkpos(inletCell), 
						GeneratorDraw.GetLinkColor(inlet),
						width:!isMini ? 4f : 6f );
				}

				if (linksToRemove != null)
					foreach ((IInlet<object> inlet, IOutlet<object> outlet) in linksToRemove)
					{
						graph.UnlinkInlet(inlet);
						graph.UnlinkOutlet(outlet);
					}
			}

			//removing null generators (for test purpose)
			for (int n=graph.generators.Length-1; n>=0; n--)
			{
				if (graph.generators[n] == null)
					ArrayTools.RemoveAt(ref graph.generators, n);
			}

			//drawing generators
			//using (Timer.Start("Generators"))
			float nodeWidth = !isMini ? GeneratorDraw.nodeWidth : GeneratorDraw.miniWidth;
			foreach (Generator gen in graph.generators)
				using (Cell.Custom(gen.guiPosition.x, gen.guiPosition.y, nodeWidth, 0))
					GeneratorDraw.DrawGeneratorOrPortal(gen, graph, isMini:isMini, selected.Contains(gen));


			//de-selecting nodes (after dragging and drawing since using drag obj)
			if (!UI.current.layout)
			{
				GeneratorDraw.SelectGenerators(selected, shiftForSingleSelect:!isMini);
				GeneratorDraw.DeselectGenerators(selected); //and deselected always without shift
			}
				
			//add/remove button
			//using (Timer.Start("AddRemove"))
			using (Cell.Full)
				DragDrawAddRemove();

			//right click menu (should have access to cellObjs)
			if (!UI.current.layout  &&  Event.current.type == EventType.MouseDown  &&  Event.current.button == 1)
				RightClick.DrawRightClickItems(graphUI, graphUI.mousePos, graph);

			//create menu on space
			if (!UI.current.layout  &&  Event.current.type == EventType.KeyDown  &&  Event.current.keyCode == KeyCode.Space  && !Event.current.shift)
				CreateRightClick.DrawCreateItems(graphUI.mousePos, graph);

			//delete selected generators
			if (selected!=null  &&  selected.Count!=0  &&  Event.current.type==EventType.KeyDown  &&  Event.current.keyCode==KeyCode.Delete)
				GraphEditorActions.RemoveGenerators(graph, selected);
		}