private ItemsCanvas GetItemsCanvas(Node node)
        {
            // First try get existing items canvas
            if (node.ItemsCanvas != null)
            {
                return(node.ItemsCanvas);
            }

            // The node does not yet have a canvas. So we need to get the parent canvas and
            // then create a child canvas for this node.
            ItemsCanvas parentCanvas = GetItemsCanvas(node.Parent);

            // Creating the child canvas to be the children canvas of the node
            node.ItemsCanvas = new ItemsCanvas(node.ViewModel, parentCanvas);
            node.ViewModel.ItemsViewModel = new ItemsViewModel(
                node.ItemsCanvas, node.ViewModel);

            if (Math.Abs(node.ScaleFactor) > 0.0000001)
            {
                node.ItemsCanvas.ScaleFactor = node.ScaleFactor;
            }

            //if (node.Offset != PointEx.Zero)
            //{
            //	node.ItemsCanvas.SetMoveOffset(node.Offset);
            //}

            return(node.ItemsCanvas);
        }
        private static void Zoom(ItemsCanvas itemsCanvas, MouseWheelEventArgs e)
        {
            double zoomFactor = ZoomFactor(e);
            Point  zoomCenter = ZoomCenter(itemsCanvas, e);

            Zoom(itemsCanvas, zoomFactor, zoomCenter, true);
        }
        public void ZoomRoot(double zoomFactor)
        {
            ItemsCanvas rootCanvas = itemsCanvas.RootCanvas;
            Point       zoomCenter = ZoomCenter(rootCanvas);

            Zoom(rootCanvas, zoomFactor, zoomCenter, false);
        }
        /// <summary>
        ///     Returns the visual area after all ancestors view areas have been intersected
        /// </summary>
        private static Rect GetHierarchicalVisualArea(ItemsCanvas canvas)
        {
            if (canvas.IsRoot)
            {
                // Reached root, return the root canvas view area
                return(GetItemsCanvasViewArea(canvas));
            }

            if (null == PresentationSource.FromVisual(canvas.ZoomableCanvas))
            {
                // This canvas is not showing
                return(Rect.Empty);
            }

            Rect parentArea = GetHierarchicalVisualArea(canvas.ParentCanvas);

            Point parentCanvasPoint = parentArea.Location;

            Point childCanvasPoint = ParentToChildCanvasPoint(canvas, parentCanvasPoint);

            Size parentSizeInChildCanvasSize     = (Size)((Vector)parentArea.Size / canvas.ScaleFactor);
            Rect parentViewAreaInChildCanvasArea = new Rect(childCanvasPoint, parentSizeInChildCanvasSize);

            // Intersect parent area with child(this) area
            Rect viewArea = GetItemsCanvasViewArea(canvas);

            viewArea.Intersect(parentViewAreaInChildCanvasArea);
            return(viewArea);
        }
        private static void UpdateAndNotifyAll(ItemsCanvas itemsCanvas)
        {
            IReadOnlyList <ItemViewModel> items = itemsCanvas.ItemsSource.GetAllItems().Cast <ItemViewModel>().ToList();

            itemsCanvas.ItemsSource.Update(items);

            items.ForEach(item => item.NotifyAll());
        }
Esempio n. 6
0
 public Operation(
     Node targetNode,
     ItemsCanvas rootCanvas,
     Point rootScreenCenter)
 {
     RootScreenCenter = rootScreenCenter;
     TargetNode       = targetNode;
     RootCanvas       = rootCanvas;
 }
 private static void ZoomDescendants(ItemsCanvas itemsCanvas)
 {
     itemsCanvas.Descendants()
     .Where(item => item.IsShowing && item.CanShow && item.ZoomableCanvas != null)
     .ForEach(item =>
     {
         SetZoomableCanvasScale(item);
         NotifyAllItems(item);
     });
 }
Esempio n. 8
0
        private static Point GetRootScreenCenter(Node rootNode)
        {
            // Returns the center of the root screen
            ItemsCanvas rootCanvas = rootNode.ItemsCanvas;
            Rect        rootArea   = rootCanvas.ItemsCanvasBounds;
            Point       rootCenter = new Point(
                rootArea.Left + rootArea.Width / 2.0,
                rootArea.Top + rootArea.Height / 2.0);

            return(rootCanvas.CanvasToScreenPoint(rootCenter));
        }
        private static void SetZoomableCanvasScale(ItemsCanvas itemsCanvas, Point zoomCenter)
        {
            // Adjust the offset to make the point at the center of zoom area stay still
            double zoomFactor = itemsCanvas.Scale / itemsCanvas.ZoomableCanvas.Scale;
            Vector position   = (Vector)zoomCenter;

            Vector moveOffset = position * zoomFactor - position;

            itemsCanvas.MoveAllItems(-moveOffset);

            itemsCanvas.ZoomableCanvas.Scale = itemsCanvas.Scale;
        }
Esempio n. 10
0
        public ModelViewModel(
            IModelViewModelService modelViewModelService,
            ModelMetadata modelMetadata)
        {
            this.modelViewModelService = modelViewModelService;
            this.modelMetadata         = modelMetadata;

            ItemsCanvas rootCanvas = new ItemsCanvas();

            ItemsViewModel = new ItemsViewModel(rootCanvas);

            modelViewModelService.SetRootCanvas(rootCanvas);
        }
Esempio n. 11
0
    void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
        }

        else if (Instance != this)
        {
            Destroy(gameObject);
        }

        DontDestroyOnLoad(gameObject);
    }
        private static Point ZoomCenter(ItemsCanvas itemsCanvas)
        {
            ZoomableCanvas zoomableCanvas = itemsCanvas.ZoomableCanvas;
            Point          viewCenter     = new Point(zoomableCanvas.ActualWidth / 2.0, zoomableCanvas.ActualHeight / 2.0);
            Point          zoomCenter     = viewCenter + (Vector)zoomableCanvas.Offset;

            if (itemsCanvas.IsRoot)
            {
                // Compensate for root center offset to windows
                zoomCenter -= new Vector(10, 10);
            }

            return(zoomCenter);
        }
        public void RemoveAll()
        {
            ItemsCanvas rootCanvas = Root.ItemsCanvas;

            nodes.Clear();

            AddRoot();
            Root.ItemsCanvas = rootCanvas;

            if (IsChangeMonitored)
            {
                DataModified?.Invoke(this, EventArgs.Empty);
            }
        }
Esempio n. 14
0
        public void OnMouseWheel(
            NodeViewModel nodeViewModel,
            UIElement uiElement,
            MouseWheelEventArgs e)
        {
            ItemsCanvas itemsCanvas = nodeViewModel.ItemsViewModel?.ItemsCanvas ?? nodeViewModel.Node.Root.ItemsCanvas;

            if (nodeViewModel.IsInnerSelected)
            {
                itemsCanvas.Zoom(e);
            }
            else
            {
                itemsCanvas.RootCanvas.Zoom(e);
            }
        }
        private static Point ScreenToCanvasPoint(ItemsCanvas canvas, Point screenPoint)
        {
            try
            {
                Point localScreenPoint = canvas.ZoomableCanvas.PointFromScreen(screenPoint);

                Point canvasPoint = canvas.ZoomableCanvas.GetCanvasPoint(localScreenPoint);

                return(canvasPoint);
            }
            catch (Exception e)
            {
                Log.Exception(e, $"Node {canvas}");
                throw;
            }
        }
        private void AddNodeToParentCanvas(Node node, Node parentNode)
        {
            try
            {
                layoutService.SetLayout(node.ViewModel);

                ItemsCanvas parentCanvas = parentNode.ItemsCanvas;

                parentCanvas.AddItem(node.ViewModel);
            }
            catch (Exception e)
            {
                Log.Exception(e, $"Failed adding {node} to parent {parentNode}");
                throw;
            }
        }
        private static void Zoom(
            ItemsCanvas itemsCanvas, double zoomFactor, Point zoomCenter, bool isManual)
        {
            double newScale = itemsCanvas.Scale * zoomFactor;

            if (isManual && !IsValidZoomScale(zoomFactor, newScale))
            {
                return;
            }

            if (itemsCanvas.IsRoot)
            {
                itemsCanvas.RootScale = newScale;
            }
            else
            {
                itemsCanvas.ScaleFactor = newScale / itemsCanvas.ParentCanvas.Scale;
            }

            UpdateScale(itemsCanvas, zoomCenter);
        }
        private static Rect GetItemsCanvasViewArea(ItemsCanvas canvas)
        {
            double scale       = canvas.Scale;
            double parentScale = canvas.ParentCanvas?.Scale ?? scale;

            Size renderSize = (Size)((Vector)canvas.ItemsCanvasBounds.Size * parentScale);

            double x = 0;
            double y = 0;

            if (canvas.IsRoot)
            {
                x = canvas.ZoomableCanvas.Offset.X;
                y = canvas.ZoomableCanvas.Offset.Y;
            }

            Rect value = new Rect(
                x / scale,
                y / scale,
                renderSize.Width / scale,
                renderSize.Height / scale);

            return(value);
        }
 public void SetRootCanvas(ItemsCanvas rootCanvas) => Root.ItemsCanvas = rootCanvas;
 public VisualAreaHandler(ItemsCanvas itemsCanvas)
 {
     this.itemsCanvas = itemsCanvas;
 }
 private static void UpdateScale(ItemsCanvas itemsCanvas, Point zoomCenter)
 {
     SetZoomableCanvasScale(itemsCanvas, zoomCenter);
     UpdateAndNotifyAll(itemsCanvas);
     ZoomDescendants(itemsCanvas);
 }
        private static Point ParentToChildCanvasPoint(ItemsCanvas canvas, Point parentCanvasPoint)
        {
            Point parentScreenPoint = canvas.ParentCanvas.CanvasToScreenPoint(parentCanvasPoint);

            return(ScreenToCanvasPoint(canvas, parentScreenPoint));
        }
 public ItemsCanvasZoom(ItemsCanvas itemsCanvas)
 {
     this.itemsCanvas = itemsCanvas;
 }
Esempio n. 24
0
 public void SetRootCanvas(ItemsCanvas rootCanvas)
 {
     rootNodeCanvas = rootCanvas;
     modelHandlingService.SetRootCanvas(rootCanvas);
 }
        private static Point ZoomCenter(ItemsCanvas itemsCanvas, MouseWheelEventArgs e)
        {
            Point viewPosition = e.GetPosition(itemsCanvas.ZoomableCanvas);

            return(viewPosition + (Vector)itemsCanvas.ZoomableCanvas.Offset);
        }
 private static void NotifyAllItems(ItemsCanvas itemsCanvas) =>
 itemsCanvas.ItemsSource.GetAllItems().Cast <ItemViewModel>().ForEach(item => item.NotifyAll());
 private static void SetZoomableCanvasScale(ItemsCanvas itemsCanvas) =>
 itemsCanvas.ZoomableCanvas.Scale = itemsCanvas.Scale;