public void RefreshContent() { if (Workspace == null) { return; } if (Workspace.CurrentGraph == null) { return; } if (Workspace.CurrentGraph != DiagramDrawer.DiagramViewModel.DataObject) { LoadDiagram(Workspace.CurrentGraph); } else { if (DiagramViewModel != null) { //TODO Micah, please check if it is valid to refresh it here //Doing this on Load does not handle shit like renaming DiagramViewModel.NavigationViewModel.Refresh(); } if (DiagramDrawer != null) { DiagramDrawer.Refresh(InvertGraphEditor.PlatformDrawer); } } }
public void LoadDiagram(IGraphData diagram) { InvertGraphEditor.DesignerWindow = this; if (diagram == null) { return; } try { DiagramDrawer = new DiagramDrawer(new DiagramViewModel(diagram)); DiagramDrawer.Dirty = true; //DiagramDrawer.Data.ApplyFilter(); DiagramDrawer.Refresh(InvertGraphEditor.PlatformDrawer); } catch (Exception ex) { InvertApplication.LogException(ex); InvertApplication.Log("Either a plugin isn't installed or the file could no longer be found. See Exception error"); } }
private bool DrawDiagram(IPlatformDrawer drawer, Vector2 scrollPosition, float scale, Rect diagramRect) { var screen = new Vector2(Screen.width, Screen.height); if (DiagramDrawer == null) { if (Workspace != null) { if (Workspace.CurrentGraph != null) { LoadDiagram(Workspace.CurrentGraph); } } } if (DiagramDrawer != null && DiagramViewModel != null && InvertGraphEditor.Settings.UseGrid) { if (_cachedLines == null || _cachedScroll != scrollPosition || _cachedScreen != screen) { var lines = new List <CachedLineItem>(); var softColor = InvertGraphEditor.Settings.GridLinesColor; var hardColor = InvertGraphEditor.Settings.GridLinesColorSecondary; var x = -scrollPosition.x; var every10 = 0; while (x < DiagramRect.x + DiagramRect.width + scrollPosition.x) { var color = softColor; if (every10 == 10) { color = hardColor; every10 = 0; } if (x > diagramRect.x) { lines.Add(new CachedLineItem() { Lines = new[] { new Vector3(x, diagramRect.y), new Vector3(x, diagramRect.x + diagramRect.height + scrollPosition.y + 85) }, Color = color }); } x += DiagramViewModel.Settings.SnapSize * scale; every10++; } var y = -scrollPosition.y + 80; every10 = 10; while (y < DiagramRect.y + DiagramRect.height + scrollPosition.y) { var color = softColor; if (every10 == 10) { color = hardColor; every10 = 0; } if (y > diagramRect.y) { lines.Add(new CachedLineItem() { Lines = new[] { new Vector3(diagramRect.x, y), new Vector3(diagramRect.x + diagramRect.width + scrollPosition.x, y) }, Color = color }); } y += DiagramViewModel.Settings.SnapSize * scale; every10++; } _cachedLines = lines.ToArray(); _cachedScreen = screen; _cachedScroll = scrollPosition; } for (int i = 0; i < _cachedLines.Length; i++) { Drawer.DrawLine(_cachedLines[i].Lines, _cachedLines[i].Color); } } if (DiagramDrawer != null) { InvertApplication.SignalEvent <IDesignerWindowEvents>(_ => _.BeforeDrawGraph(diagramRect)); DiagramDrawer.Bounds = new Rect(0f, 0f, diagramRect.width, diagramRect.height); DiagramDrawer.Draw(drawer, 1f); if (_shouldProcessInputFromDiagram) { InvertApplication.SignalEvent <IDesignerWindowEvents>(_ => _.ProcessInput()); } InvertApplication.SignalEvent <IDesignerWindowEvents>(_ => _.AfterDrawGraph(DiagramDrawer.Bounds)); } return(false); }
public void Draw(float width, float height, Vector2 scrollPosition, float scale) { DiagramDrawer.IsEditingField = false; if (Drawer == null) { InvertApplication.Log("DRAWER IS NULL"); return; } var diagramRect = new Rect(); if (DrawToolbar) { var toolbarTopRect = new Rect(0, 0, width, 18); var tabsRect = new Rect(0, toolbarTopRect.height, width, 31); var breadCrumbsRect = new Rect(0, tabsRect.y + tabsRect.height, width, 30); diagramRect = new Rect(0f, breadCrumbsRect.y + breadCrumbsRect.height, width, height - ((toolbarTopRect.height * 2)) - breadCrumbsRect.height - 31); var toolbarBottomRect = new Rect(0f, diagramRect.y + diagramRect.height, width, toolbarTopRect.height); List <DesignerWindowModalContent> modalItems = new List <DesignerWindowModalContent>(); Signal <IQueryDesignerWindowModalContent>(_ => _.QueryDesignerWindowModalContent(modalItems)); List <DesignerWindowOverlayContent> overlayItems = new List <DesignerWindowOverlayContent>(); Signal <IQueryDesignerWindowOverlayContent>(_ => _.QueryDesignerWindowOverlayContent(overlayItems)); //Disable diagram input if any modal content presents or if mouse is over overlay content _shouldProcessInputFromDiagram = !modalItems.Any() && overlayItems.All(i => !i.Drawer.CalculateBounds(diagramRect).Contains(Event.current.mousePosition)); Drawer.DrawStretchBox(toolbarTopRect, CachedStyles.Toolbar, 0f); Drawer.DoToolbar(toolbarTopRect, this, ToolbarPosition.Left); //drawer.DoToolbar(toolbarTopRect, this, ToolbarPosition.Right); Drawer.DrawRect(tabsRect, InvertGraphEditor.Settings.GridLinesColor); //Drawer.DoTabs(Drawer,tabsRect, this); DiagramRect = diagramRect; /* * DRAW DIAGRAM * Using GUI.color hack to avoid transparent diagram on disabled input (Thanks Unity :( ) */ if (!_shouldProcessInputFromDiagram) { Drawer.DisableInput(); } if (DiagramDrawer != null) { DiagramDrawer.DrawTabs(Drawer, tabsRect); DiagramDrawer.DrawBreadcrumbs(Drawer, breadCrumbsRect.y); } var fpsCounterRect = tabsRect.WithWidth(80).RightOf(tabsRect).Translate(-100, 0); if (ShowFPS) { if ((DateTime.Now - _lastFpsUpdate).TotalMilliseconds > 1000) { _fpsShown = _framesLastSec; _lastFpsUpdate = DateTime.Now; _framesLastSec = 0; } else { _framesLastSec++; } Drawer.DrawLabel(fpsCounterRect, string.Format("FPS: {0}", _fpsShown), CachedStyles.WizardSubBoxTitleStyle); } Drawer.DrawRect(diagramRect, InvertGraphEditor.Settings.BackgroundColor); DiagramRect = diagramRect; DrawDiagram(Drawer, scrollPosition, scale, diagramRect); Drawer.EnableInput(); /* * DRAW OVERLAY CONTENT */ if (modalItems.Any()) { Drawer.DisableInput(); } foreach (var item in overlayItems) { var bounds = item.Drawer.CalculateBounds(diagramRect); var isMouseOver = bounds.Contains(Event.current.mousePosition); var colorCache = GUI.color; if (!isMouseOver && !item.DisableTransparency) { GUI.color = new Color(colorCache.r, colorCache.g, colorCache.b, colorCache.a / 4); } item.Drawer.Draw(bounds); GUI.color = colorCache; } Drawer.EnableInput(); /* * DRAW MODAL CONTENT */ if (modalItems.Any()) { var modalBackgroundRect = new Rect().Cover(breadCrumbsRect, tabsRect, diagramRect); var modalContentRect = new Rect().WithSize(800, 500).CenterInsideOf(modalBackgroundRect); var activeModal = modalItems.OrderBy(i => i.ZIndex).Last(); Drawer.DisableInput(); foreach (var source in modalItems.OrderBy(i => i.ZIndex).Except(new[] { activeModal })) { source.Drawer(modalContentRect); } Drawer.EnableInput(); Drawer.DrawRect(modalBackgroundRect, new Color(0, 0, 0, 0.8f)); activeModal.Drawer(modalContentRect); } DrawToolip(breadCrumbsRect); Drawer.DoToolbar(toolbarBottomRect, this, ToolbarPosition.BottomLeft); //drawer.DoToolbar(toolbarBottomRect, this, ToolbarPosition.BottomRight); } else { diagramRect = new Rect(0f, 0f, width, height); DiagramRect = diagramRect; DrawDiagram(Drawer, scrollPosition, scale, diagramRect); } InvertApplication.SignalEvent <IDesignerWindowEvents>(_ => _.AfterDrawDesignerWindow(new Rect(0, 0, width, height))); InvertApplication.SignalEvent <IDesignerWindowEvents>(_ => _.DrawComplete()); }