示例#1
0
        public static Surface AddChild(Surface parent)
        {
            if (parent.Frame == null)
            {
                throw new ArgumentException("Illegal surface provided.");
            }

            Surface child = new Surface();

            child.Frame = parent.Frame;

            if (parent.Layout == SurfaceLayout.HORIZONTAL)
            {
                child.Layout = SurfaceLayout.VERTICAL;
            }
            else
            {
                child.Layout = SurfaceLayout.HORIZONTAL;
            }

            child.Model.Bounds = new RectangleF(parent.Model.X, parent.Model.Y, parent.Model.Width, parent.Model.Height);
            parent.AddChild(child);

            child.Model.SurfaceParent = parent;

            return(child);
        }
示例#2
0
        private static Surface Divide(Surface surface, PointF position, MullionType mullionType)
        {
            if (surface.Frame == null)
            {
                throw new ArgumentException("Illegal surface provided.");
            }

            Surface parent = (Surface)surface.Parent;

            if (!surface.Bounds.Contains(position))
            {
                return(null);
            }


            Surface    next = new Surface(surface.Layout);
            Mullion    mullion;
            RectangleF parentBounds  = parent.Model.Bounds;
            RectangleF nextBounds    = next.Bounds;
            RectangleF surfaceBounds = surface.Model.Bounds;

            if (parent.Layout == SurfaceLayout.VERTICAL)
            {
                mullion                   = new Mullion(Orientation.Horizontal, mullionType);
                mullion.Frame             = surface.Frame;
                mullion.Model.MiddlePoint = position.Y - surface.Frame.Y;
                mullion.Model.X           = surfaceBounds.X;
                mullion.Model.Length      = surface.Width;

                nextBounds.X      = surfaceBounds.X;
                nextBounds.Y      = mullion.Model.Y + mullion.Thickness;
                nextBounds.Width  = surfaceBounds.Width;
                nextBounds.Height = surfaceBounds.Height + surfaceBounds.Y - mullion.Model.Y - mullion.Thickness;

                surfaceBounds.Height = mullion.Model.Y - surfaceBounds.Y;
            }
            else if (parent.Layout == SurfaceLayout.HORIZONTAL)
            {
                mullion                   = new Mullion(Orientation.Vertical, mullionType);
                mullion.Frame             = surface.Frame;
                mullion.Model.MiddlePoint = position.X - surface.Frame.X;
                mullion.Model.Y           = surfaceBounds.Y;
                mullion.Model.Length      = surfaceBounds.Height;

                nextBounds.X      = mullion.Model.X + mullion.Thickness;
                nextBounds.Y      = surfaceBounds.Y;
                nextBounds.Width  = surfaceBounds.Width + surfaceBounds.X - mullion.Model.X - mullion.Thickness;
                nextBounds.Height = surfaceBounds.Height;

                surfaceBounds.Width = mullion.Model.X - surfaceBounds.X;
            }
            else
            {
                throw new ArgumentException("Illegal surface layout value.");
            }


            next.Model.SurfaceParent = parent;
            next.Frame        = surface.Frame;
            next.Model.Bounds = nextBounds;

            int index = surface.Index();

            parent.AddChild(index + 1, mullion);
            parent.AddChild(index + 2, next);

            mullion.Frame.AddMullion(mullion);

            // Because after setting bounds the surface will update herself with
            // her next mullion, So this setting MUST happen after adding mullion
            // and the next surface
            if (parent.Layout == SurfaceLayout.VERTICAL)
            {
                surface.Model.Height = mullion.Model.Y - surface.Model.Y;
            }
            else
            {
                surface.Model.Width = mullion.Model.X - surface.Model.X;
            }

            return(next);
        }