void PaintLayout(System.Drawing.Graphics g, Layoutable l)
        {
            if (l == mouseover)
            {
                g.FillRectangle(new SolidBrush(Color.FromArgb(50, l.Color)), l.AbsolutePosition.X, l.AbsolutePosition.Y, l.Size.X, l.Size.Y);

                if (mouseoverScaleCorner)
                {
                    g.FillRectangle(new SolidBrush(l.Color), l.AbsolutePosition.X + l.Size.X - scaleCornerSize.Width,
                                    l.AbsolutePosition.Y + l.Size.Y - scaleCornerSize.Height,
                                    scaleCornerSize.Width, scaleCornerSize.Height);
                }
            }
            if (l == selected)
            {
                g.DrawRectangle(new Pen(Color.White)
                {
                    DashStyle = System.Drawing.Drawing2D.DashStyle.Dash
                },
                                l.AbsolutePosition.X - 1, l.AbsolutePosition.Y - 1, l.Size.X + 2, l.Size.Y + 2);
            }
            g.DrawRectangle(new Pen(l.Color), l.AbsolutePosition.X, l.AbsolutePosition.Y, l.Size.X, l.Size.Y);
            foreach (Layoutable v in l.Children)
            {
                PaintLayout(g, v);
            }
        }
 public TestLayoutEditorControl()
 {
     InitializeComponent();
     SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
     Root = new Layoutable {
         Color = Color.Red
     };
 }
 public TestLayoutEditorControl()
 {
     InitializeComponent();
     SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
     Root = new Layoutable { Color = Color.Red };
 }
        void PaintLayout(System.Drawing.Graphics g, Layoutable l)
        {
            if (l == mouseover)
            {
                g.FillRectangle(new SolidBrush(Color.FromArgb(50, l.Color)), l.AbsolutePosition.X, l.AbsolutePosition.Y, l.Size.X, l.Size.Y);

                if(mouseoverScaleCorner)
                    g.FillRectangle(new SolidBrush(l.Color), l.AbsolutePosition.X + l.Size.X - scaleCornerSize.Width,
                        l.AbsolutePosition.Y + l.Size.Y - scaleCornerSize.Height,
                        scaleCornerSize.Width, scaleCornerSize.Height);
            }
            if (l == selected)
            {
                g.DrawRectangle(new Pen(Color.White) { DashStyle = System.Drawing.Drawing2D.DashStyle.Dash },
                    l.AbsolutePosition.X - 1, l.AbsolutePosition.Y - 1, l.Size.X + 2, l.Size.Y + 2);
            }
            g.DrawRectangle(new Pen(l.Color), l.AbsolutePosition.X, l.AbsolutePosition.Y, l.Size.X, l.Size.Y);
            foreach (Layoutable v in l.Children)
                PaintLayout(g, v);
        }
 protected override void OnMouseUp(MouseEventArgs e)
 {
     base.OnMouseUp(e);
     moving = null;
     scaling = null;
 }
 protected override void OnMouseDown(MouseEventArgs e)
 {
     base.OnMouseDown(e);
     if (mouseoverScaleCorner)
         scaling = mouseover;
     else
         moving = mouseover;
 }
 protected override void OnMouseClick(MouseEventArgs e)
 {
     base.OnMouseClick(e);
     if (e.Button == MouseButtons.Left)
     {
         Selected = mouseover;
         if (SelectedChanged != null) SelectedChanged(this, null);
     }
     else
     {
         mouseover.Children.Add(new Layoutable
         {
             Color = Color.FromArgb(100 + r.Next(156),100 + r.Next(156),100 + r.Next(156)),
             Size = new Vector2(50, 50),
             Position = new Vector2(5, 5),
             Parent = mouseover
         });
         mouseover.PerformLayout();
     }
 }