Exemplo n.º 1
0
        private void control_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            Keys keyData   = e.KeyData;
            Keys modifiers = keyData & Keys.Modifiers;

            keyData &= ~Keys.Modifiers;

            if (keyData == Keys.Up ||
                keyData == Keys.Right ||
                keyData == Keys.Down ||
                keyData == Keys.Left)
            {
                TNode startElement = Adapters.As <TNode>(m_selectionContext.LastSelected);
                if (startElement != null)
                {
                    Rectangle nearestRect;
                    TNode     nearest = FindNearestElement(startElement, keyData, out nearestRect);
                    if (nearest != null)
                    {
                        var selection = new List <TNode>(m_selectionContext.SelectionCount);
                        selection.AddRange(m_selectionContext.GetSelection <TNode>());
                        KeysUtil.Select <TNode>(selection, nearest, modifiers);
                        m_selectionContext.Selection = selection.Cast <object>();
                        var transformAdapter = AdaptedControl.As <ITransformAdapter>();
                        if (transformAdapter != null)
                        {
                            transformAdapter.PanToRect(nearestRect);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public Rectangle GetBounds(IEnumerable <object> items)
        {
            float minX = float.MaxValue, minY = float.MaxValue;
            float maxX = -float.MaxValue, maxY = -float.MaxValue;

            foreach (var o in items)
            {
                var n = o as HyperGraph.Node;
                if (n != null)
                {
                    minX = System.Math.Min(minX, n.bounds.Left);
                    minY = System.Math.Min(minY, n.bounds.Top);
                    maxX = System.Math.Max(maxX, n.bounds.Right);
                    maxY = System.Math.Max(maxY, n.bounds.Bottom);
                }
            }

            // interface wants the result in client coords, so we need to transform through
            // the canvas transformation.
            var graphControl = AdaptedControl.As <NodeEditorCore.GraphControl>();

            if (graphControl != null)
            {
                var pts = new PointF[] { new PointF(minX, minY), new PointF(maxX, maxY) };
                graphControl.Transform.TransformPoints(pts);
                return(new Rectangle((int)pts[0].X, (int)pts[0].Y, (int)(pts[1].X - pts[0].X), (int)(pts[1].Y - pts[0].Y)));
            }
            return(new Rectangle((int)minX, (int)minY, (int)(maxX - minX), (int)(maxY - minY)));
        }