Example #1
0
        protected virtual void SelectLassoComponents(Rectangle lasso)//TODO: make hit test strategy pluggable
        {
            double left   = lasso.GetValue <double>(Canvas.LeftProperty);
            double top    = lasso.GetValue <double>(Canvas.TopProperty);
            double width  = lasso.Width;
            double height = lasso.Height;
            Rect   r      = new Rect(left, top, width, height);
            List <IDesignableControl> selection = new List <IDesignableControl>();

            foreach (var u in LayoutRoot.Children)
            {
                if (u is IDesignableControl)
                {
                    IDesignableControl test    = (IDesignableControl)u;
                    Point[]            corners = test.Visual.GetCanvasCorners();
                    for (int i = 0; i < corners.Length; ++i)
                    {
                        if (r.Contains(corners[i]))
                        {
                            selection.Add(test);
                            break;
                        }
                    }
                }
            }

            SelectionSvc.Select(selection);
        }
Example #2
0
 private void LayoutRoot_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     SelectionSvc.Select(null);
     _isSelecting          = true;
     SelectDrawingBehavior = new RectangleDrawingBehavior(LayoutRoot);
     LayoutRoot.CaptureMouse();
     _localMousePos = e.GetPosition(this);
     _selectingRect = (Rectangle)SelectDrawingBehavior.StartDrawing(_localMousePos);
 }
Example #3
0
        /// <summary>
        /// Get left,top, width,height of the entirety of all selected components
        /// </summary>
        /// <returns></returns>
        public virtual Rect GetSelectionBounds()
        {
            double left, top, width, height;

            left   = int.MaxValue;
            top    = int.MaxValue;
            width  = 0.0;
            height = 0.0;

            IList <IDesignableControl> selection = SelectionSvc.GetSelection();

            foreach (var idt in selection)
            {
                double l = idt.Visual.GetValue <double>(Canvas.LeftProperty);
                double t = idt.Visual.GetValue <double>(Canvas.TopProperty);

                if (l < left)
                {
                    left = l;
                }
                if (t < top)
                {
                    top = t;
                }
            }

            foreach (var idt in selection)
            {
                double l = idt.Visual.GetValue <double>(Canvas.LeftProperty);
                double t = idt.Visual.GetValue <double>(Canvas.TopProperty);
                //Using RenderSize takes transforms into account
                double w = idt.Visual.RenderSize.Width;
                double h = idt.Visual.RenderSize.Height;

                if (l + w > width)
                {
                    width = l + w - left;
                }
                if (t + h > height)
                {
                    height = t + h - top;
                }
            }

            Rect r = new Rect(left, top, width, height);

            return(r);
        }