public Image Render(LayoutElement element) { var canvas = new GDICanvas(element.Presentation.RequiredSpace); this.Render(element, canvas); return(canvas.Picture); }
private void CloseGDICanvas(GDICanvas canvas) { bool doSave = EditorUtility.DisplayDialog("Do you want to save.", "Do you want to save the graph " + canvas.Graph.OriginFile + " ?", "Yes", "No"); if (doSave) { if (canvas.Graph.OriginFile == null) { OpenSaveDialog(); } else { Launcher.Instance.SaveGraph(canvas.Graph, canvas.Graph.OriginFile); } } EventManager.TriggerOnCloseGraph(canvas.Graph); Launcher.Instance.RemoveGraph(canvas.Graph, false); _canvasList.Remove(canvas); if (_canvasList.Count > 0) { SetCurrentGDICanvas(_canvasList[0]); } else { SetCurrentGDICanvas(null); } }
private void Render(LayoutElement element, ICanvas canvas) { try { var innerBoundaries = element.Presentation.Render(canvas); if (innerBoundaries == null) { return; } var innerCanvasPosition = innerBoundaries.GetBounds(); if (innerCanvasPosition.IsEmpty) { return; } var innerCanvas = new GDICanvas(innerCanvasPosition.Size); innerCanvas.Boundaries = TransformBoundariesToTopLeft(innerBoundaries); foreach (var child in element.Children) { Render(child, innerCanvas); var picture = innerCanvas.Picture; canvas.DrawImage(picture, new RectangleF(innerCanvasPosition.Left, innerCanvasPosition.Top, innerCanvasPosition.Width, innerCanvasPosition.Height), new RectangleF(0, 0, picture.Width, picture.Height)); } } catch (Exception ex) { var failedImage = GetFailedRenderImage(canvas.Boundaries.GetBounds().Size); canvas.DrawImage(failedImage, new RectangleF(0, 0, failedImage.Width, failedImage.Height), new RectangleF(0, 0, failedImage.Width, failedImage.Height)); LogPolicy.LogException(ex); } }
/// <summary> /// Caches the eidtor state and resets it for play mode. ///</summary> private void BeforePlay() { // cache the edit mode graphs _clonedEditModeGraphs = Launcher.Instance.CloneGraphs(); // clear the edit mode grahps Launcher.Instance.ClearGraphs(false); _canvasList.Clear(); _currentGDICanvas = null; }
private void SetCurrentGDICanvas(GDICanvas canvas) { UpdateGraphs(); Repaint(); if (canvas != null) { EventManager.TriggerOnFocusGraph(canvas.Graph); } _currentGDICanvas = canvas; }
/// <summary> /// Sets the editor state to the editor mode. ///</summary> private void OnStop() { // clear the playmode graphs _canvasList.Clear(); _currentGDICanvas = null; Launcher.Instance.ClearGraphs(false); // load the edit mode gtaphs for (int i = 0; i < _clonedEditModeGraphs.Count; i++) { Graph g = _clonedEditModeGraphs[i]; Launcher.Instance.AddGraph(g, false); } LoadGDICanvas(Launcher.Instance); }
private void CreateGDICanvas(string path) { GDICanvas canvas; if (path != null) { canvas = new GDICanvas(Launcher.Instance.LoadGraph(path, false)); } else { Graph g = new Graph(); canvas = new GDICanvas(g); Launcher.Instance.AddGraph(g, false); } canvas.Graph.OriginFile = path; _canvasList.Add(canvas); SetCurrentGDICanvas(canvas); }
public void Init() { EventManager.OnGraphRemovedByScript += OnGraphRemovedByScript; EventManager.OnGraphAddedByScript += OnGraphAddedByScript; EditorApplication.playmodeStateChanged += OnPlaymodeStateChanged; // create GameObject and the Component if it is not added to the scene titleContent = new GUIContent(Config.WindowName); wantsMouseMove = true; EventManager.TriggerOnWindowOpen(); _menuEntryToNodeType = CreateMenuEntries(); _menu = CreateNodeMenu(); _canvasList.Clear(); _currentGDICanvas = null; if (Launcher.Instance.GetGraphCount() > 0) { LoadGDICanvas(Launcher.Instance); } UpdateGraphs(); Repaint(); }
private void HandleTabButtons() { Color standardBackgroundColor = GUI.backgroundColor; int tabIndex = 0; GDICanvas canvasToClose = null; _hoveringTabIndex = -1; float xOffset = 0; for (int index = 0; index < _canvasList.Count; index++) { GDICanvas tmpGDICanvas = _canvasList[index]; string tabName; if (string.IsNullOrEmpty(tmpGDICanvas.Graph.OriginFile)) { tabName = Config.DefaultGraphName; } else { tabName = Path.GetFileName(tmpGDICanvas.Graph.OriginFile); } float textWidth = GUI.skin.label.CalcSize(new GUIContent(tabName)).x + 10; float width = textWidth + TabButtonMargin + TabCloseButtonSize; tmpGDICanvas.TabButton.Set(xOffset, TopMenuHeight + TabButtonMargin, textWidth, TopMenuHeight); tmpGDICanvas.CloseTabButton.Set(xOffset + width - TabCloseButtonSize - TabButtonMargin - 4, TopMenuHeight + TabButtonMargin, TabCloseButtonSize, TabCloseButtonSize); xOffset = xOffset + width; bool isSelected = _currentGDICanvas == tmpGDICanvas; EditorGUI.DrawRect(tmpGDICanvas.TabButton, isSelected ? Config.SelectedTabColor : Config.TabColor); GUI.Label(tmpGDICanvas.TabButton, tabName); EditorGUI.DrawRect(tmpGDICanvas.CloseTabButton, isSelected ? Config.SelectedTabColor : Config.TabColor); GUI.Label(tmpGDICanvas.CloseTabButton, "X"); if (tmpGDICanvas.TabButton.Contains(Event.current.mousePosition)) { _hoveringTabIndex = index; if (Event.current.type == EventType.MouseUp) { SetCurrentGDICanvas(tmpGDICanvas); } } if (Event.current.type == EventType.MouseUp && tmpGDICanvas.CloseTabButton.Contains(Event.current.mousePosition)) { canvasToClose = tmpGDICanvas; } tabIndex++; } GUI.backgroundColor = standardBackgroundColor; if (canvasToClose != null) { CloseGDICanvas(canvasToClose); } }
private void LoadGDICanvas(Graph graph) { _currentGDICanvas = new GDICanvas(graph); _canvasList.Add(_currentGDICanvas); }