Inheritance: Drawer, IInputHandler
Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 2
0
 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 void NextScreenshot()
    {
        if (_currentScreenshotIndex >= _screenshots.Count)
        {
            _capturing = false;
            _currentScreenshotIndex = 0;
            if (_exitOnComplete)
            {
                _exitOnComplete = false;
                this.Close();
                return;
            }
            Repaint();
            return;
        }
        drawer = DiagramDrawer(_screenshots[_currentScreenshotIndex]);

        _currentScreenshotIndex++;
        if (drawer == null)
        {
            NextScreenshot();
            return;
        }
        Repaint();
    }
    private DiagramDrawer DiagramDrawer(GraphNode node)
    {
        var window = InvertGraphEditor.DesignerWindow as ElementsDesigner;

        var diagramViewModel = new DiagramViewModel(node.Graph);
        diagramViewModel.NavigateTo(node.Identifier);


    
        var drawer = new DiagramDrawer(diagramViewModel);
        drawer.Refresh(InvertGraphEditor.PlatformDrawer);

        var screenshotVM = diagramViewModel.AllViewModels.OfType<DiagramNodeViewModel>().FirstOrDefault(p => p.GraphItemObject.Identifier == node.Identifier);


        if (screenshotVM == null)
            return null;
        this.position = new Rect(this.position.x, this.position.y, screenshotVM.Bounds.width + 20f, screenshotVM.Bounds.height + 20f);
        var position = screenshotVM.Position - new Vector2(10f,10f);
        Debug.Log(diagramViewModel.GraphData.CurrentFilter.Name + " " + position.x + ": " + position.y);
        foreach (var item in drawer.Children.OrderBy(p => p.ZOrder))
        {
           
            
            //item.Refresh(InvertGraphEditor.PlatformDrawer, new Vector2(item.Bounds.x - screenshotVM.Bounds.x, item.Bounds.y - screenshotVM.Bounds.y));
            if (item == null) continue;
            if (item.ViewModelObject != null)
            {
                item.IsSelected = false;
                item.ViewModelObject.ShowHelp = true;
            }
            

            item.Bounds = new Rect(item.Bounds.x - position.x, item.Bounds.y - position.y,
                item.Bounds.width, item.Bounds.height);

            foreach (var child in item.Children)
            {
                if (child == null) continue;
                child.Bounds = new Rect(child.Bounds.x - position.x, child.Bounds.y - position.y,
                    child.Bounds.width, child.Bounds.height);
                if (child.ViewModelObject != null)
                {
                    var cb = child.ViewModelObject.ConnectorBounds;

                    child.ViewModelObject.ConnectorBounds = new Rect(cb.x - position.x, cb.y - position.y,
                        cb.width, cb.height);
                }

                //child.Refresh(InvertGraphEditor.PlatformDrawer, new Vector2(item.Bounds.x - screenshotVM.Bounds.x, item.Bounds.y - screenshotVM.Bounds.y));
            }
        }
        return drawer;
    }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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());
        }
Ejemplo n.º 7
0
        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");
            }
        }